Author: desruisseaux
Date: Mon Feb 19 13:51:06 2018
New Revision: 1824746
URL: http://svn.apache.org/viewvc?rev=1824746&view=rev
Log:
Fix DefaultVerticalDatumTest by using automatically ISO 19139:2007 metadata
when marshalling GML 3.2.
This is an incomplete hack - see https://issues.apache.org/jira/browse/SIS-401
Added:
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/UseLegacyMetadata.java
(with props)
Modified:
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/MarshallingTest.java
sis/branches/ISO-19115-3/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java
Modified:
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/MarshallingTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/MarshallingTest.java?rev=1824746&r1=1824745&r2=1824746&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/MarshallingTest.java
[UTF-8] (original)
+++
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/MarshallingTest.java
[UTF-8] Mon Feb 19 13:51:06 2018
@@ -69,7 +69,10 @@ import static org.junit.Assert.*;
*
* @author Cullen Rombach (Image Matters)
* @version 1.0
- * @since 1.0
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/SIS-400">SIS-400</a>
+ *
+ * @since 1.0
* @module
*/
public final class MarshallingTest extends XMLTestCase implements
WarningListener<Object> {
@@ -303,7 +306,7 @@ public final class MarshallingTest exten
new Anchor(new
URI("http://example.com"), "alternateTitle")));
cit.getDates().add(new DefaultCitationDate(new Date(),
DateType.CREATION));
dataId.setCitation(cit);
- dataId.setTemporalResolutions(Collections.emptySet()); //
TODO
+ dataId.setTemporalResolutions(Collections.emptySet()); //
TODO: depends on sis-temporal
final Collection<MaintenanceInformation> resourceMaintenances;
{
// Resource maintenance
@@ -408,7 +411,7 @@ public final class MarshallingTest exten
final DefaultCoverageDescription coverageDescription;
{
coverageDescription = new DefaultCoverageDescription();
- // Attribute description TODO: this doesn't work properly.
+ // Attribute description
final DefaultRecordSchema schema = new
DefaultRecordSchema(null, null, "MySchema");
final Map<CharSequence,Class<?>> members = new
LinkedHashMap<>();
members.put("city", String.class);
@@ -451,9 +454,12 @@ public final class MarshallingTest exten
/**
* Tests marshalling of an ISO 19139:2007 document (based on ISO
19115:2003 model).
+ * Current implementation merely tests that marshalling does not produce
exception.
*
* @throws URISyntaxException if an error occurred while creating the
metadata object.
* @throws JAXBException if an error occurred while marshalling the
document.
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/SIS-400">SIS-400</a>
*/
@Test
public void testLegacySchema() throws URISyntaxException, JAXBException {
@@ -465,9 +471,12 @@ public final class MarshallingTest exten
/**
* Tests marshalling of an ISO 19115-3 document (based on ISO 19115:2014
model).
+ * Current implementation merely tests that marshalling does not produce
exception.
*
* @throws URISyntaxException if an error occurred while creating the
metadata object.
* @throws JAXBException if an error occurred while marshalling the
document.
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/SIS-400">SIS-400</a>
*/
@Test
public void testCurrentSchema() throws JAXBException, URISyntaxException {
Modified:
sis/branches/ISO-19115-3/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1824746&r1=1824745&r2=1824746&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] (original)
+++
sis/branches/ISO-19115-3/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
[UTF-8] Mon Feb 19 13:51:06 2018
@@ -42,6 +42,7 @@ import org.opengis.referencing.ObjectFac
import org.opengis.referencing.AuthorityFactory;
import org.opengis.referencing.IdentifiedObject;
import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.internal.jaxb.UseLegacyMetadata;
import org.apache.sis.internal.jaxb.referencing.Code;
import org.apache.sis.internal.util.Numerics;
import org.apache.sis.internal.util.UnmodifiableArrayList;
@@ -116,7 +117,7 @@ import static org.apache.sis.internal.ut
* objects and passed between threads without synchronization.
*
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 0.7
+ * @version 1.0
* @since 0.4
* @module
*/
@@ -133,6 +134,7 @@ import static org.apache.sis.internal.ut
org.apache.sis.referencing.datum.DefaultPrimeMeridian.class,
org.apache.sis.referencing.cs.AbstractCS.class
})
+@UseLegacyMetadata
public class AbstractIdentifiedObject extends FormattableObject implements
IdentifiedObject,
LenientComparable, Deprecable, Serializable
{
Modified:
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java?rev=1824746&r1=1824745&r2=1824746&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
[UTF-8] (original)
+++
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
[UTF-8] Mon Feb 19 13:51:06 2018
@@ -91,15 +91,15 @@ public final class Context extends Marsh
public static final int SUBSTITUTE_MIMETYPE = 0x10;
/**
- * Bit where to store whether {@link #finish()} shall invoke {@code
Semaphores.clear(Semaphores.NULL_COLLECTION)}.
+ * Whether we are (un)marshalling legacy metadata as defined in 2003 model
(ISO 19139:2007).
+ * If this flag is not set, then we assume latest metadata as defined in
2014 model (ISO 19115-3).
*/
- private static final int CLEAR_SEMAPHORE = 0x20;
+ public static final int LEGACY_METADATA = 0x20;
/**
- * Whether we are (un)marshalling legacy metadata as defined in 2003 model
(ISO 19139:2007).
- * If this flag is not set, then we assume latest metadata as defined in
2014 model (ISO 19115-3).
+ * Bit where to store whether {@link #finish()} shall invoke {@code
Semaphores.clear(Semaphores.NULL_COLLECTION)}.
*/
- public static final int LEGACY_METADATA = 0x40;
+ private static final int CLEAR_SEMAPHORE = 0x40;
/**
* The thread-local context. Elements are created in the constructor, and
removed in a
Added:
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/UseLegacyMetadata.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/UseLegacyMetadata.java?rev=1824746&view=auto
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/UseLegacyMetadata.java
(added)
+++
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/UseLegacyMetadata.java
[UTF-8] Mon Feb 19 13:51:06 2018
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.jaxb;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+
+/**
+ * Declares that marshalling the annotated object requires legacy ISO
19139:2007 metadata.
+ * This is a hopefully temporary hack for marshalling metadata in GML.
+ * May be deleted if we implement SIS-401.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/SIS-401">SIS-401</a>
+ *
+ * @since 1.0
+ * @module
+ */
+@Inherited
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface UseLegacyMetadata {
+}
Propchange:
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/UseLegacyMetadata.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/UseLegacyMetadata.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java?rev=1824746&r1=1824745&r2=1824746&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java
[UTF-8] (original)
+++
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java
[UTF-8] Mon Feb 19 13:51:06 2018
@@ -260,7 +260,7 @@ abstract class Pooled {
* 1: namespace replacement needed for GML
* 2: namespace replacement needed for metadata.
*/
- int combine = 0;
+ int combine = (specificBitMasks() & Context.LEGACY_METADATA) != 0 ? 2
: 0;
if (versionGML == null ? byDefault : versionGML
.compareTo(LegacyNamespaces.VERSION_3_2_1) < 0) combine = 1;
if (versionMetadata == null ? byDefault :
versionMetadata.compareTo(LegacyNamespaces.VERSION_2014) < 0) combine |= 2;
switch (combine) {
@@ -515,6 +515,20 @@ abstract class Pooled {
public abstract ValidationEventHandler getEventHandler() throws
JAXBException;
/**
+ * Returns bit masks specific to the object being marshalled. This mask
will be combined with the
+ * bit masks managed by the {@link Pooled} base class. This is used mostly
for mandating legacy
+ * metadata format (ISO 19139:2007) for some object to marshal.
+ *
+ * <p>This is a hopefully temporary hack for marshalling metadata in GML.
+ * May be deleted if we implement SIS-401.</p>
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/SIS-401">SIS-401</a>
+ */
+ int specificBitMasks() {
+ return 0;
+ }
+
+ /**
* Must be invoked by subclasses before a {@code try} block performing a
(un)marshalling
* operation. Must be followed by a call to {@code finish()} in a {@code
finally} block.
*
@@ -530,6 +544,7 @@ abstract class Pooled {
* @see Context#finish()
*/
final Context begin() {
- return new Context(bitMasks, locale, timezone, schemas, versionGML,
versionMetadata, resolver, converter, warningListener);
+ return new Context(bitMasks | specificBitMasks(), locale, timezone,
+ schemas, versionGML, versionMetadata, resolver, converter,
warningListener);
}
}
Modified:
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java?rev=1824746&r1=1824745&r2=1824746&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java
[UTF-8] (original)
+++
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java
[UTF-8] Mon Feb 19 13:51:06 2018
@@ -37,6 +37,7 @@ import org.xml.sax.ContentHandler;
import org.w3c.dom.Node;
import org.apache.sis.internal.jaxb.Context;
import org.apache.sis.internal.jaxb.TypeRegistration;
+import org.apache.sis.internal.jaxb.UseLegacyMetadata;
/**
@@ -64,6 +65,13 @@ final class PooledMarshaller extends Poo
private final Marshaller marshaller;
/**
+ * Bit masks specific to the object being marshalled. This mask will be
combined with the
+ * bit masks managed by the {@link Pooled} base class. This is used
mostly for mandating
+ * legacy metadata format (ISO 19139:2007) for some object to marshal.
+ */
+ private int specificBitMasks;
+
+ /**
* Creates a pooled marshaller wrapping the given one.
* Callers shall invoke {@link #reset(Pooled)} after construction for
completing the initialization.
*
@@ -115,11 +123,23 @@ final class PooledMarshaller extends Poo
}
/**
+ * Returns a non-zero bitmask if the object given in last call to {@link
#toImplementation(Object)} should use
+ * legacy metadata. This is a hack for marshalling metadata in GML. May be
deleted if we implement SIS-401.
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/SIS-401">SIS-401</a>
+ */
+ @Override
+ final int specificBitMasks() {
+ return specificBitMasks;
+ }
+
+ /**
* Converts the given arbitrary object to an implementation having JAXB
annotations.
* If the given object is not recognized or is already an instance of the
expected class,
* then it is returned unchanged.
*/
private Object toImplementation(final Object value) throws JAXBException {
+ specificBitMasks =
value.getClass().isAnnotationPresent(UseLegacyMetadata.class) ?
Context.LEGACY_METADATA : 0;
final TypeRegistration[] converters = getRootAdapters();
if (converters != null) {
for (final TypeRegistration t : converters) {
@@ -139,13 +159,13 @@ final class PooledMarshaller extends Poo
* @param output the writer created by SIS (<b>not</b> the writer given
by the user).
* @param version identifies the namespace substitutions to perform.
*/
- private void marshal(final Object object, XMLEventWriter output, final
TransformVersion version)
+ private void marshal(Object object, XMLEventWriter output, final
TransformVersion version)
throws XMLStreamException, JAXBException
{
output = new TransformingWriter(output, version);
final Context context = begin();
try {
- marshaller.marshal(toImplementation(object), output);
+ marshaller.marshal(object, output);
} finally {
context.finish();
}
@@ -156,7 +176,8 @@ final class PooledMarshaller extends Poo
* Delegates the marshalling to the wrapped marshaller.
*/
@Override
- public void marshal(final Object object, final Result output) throws
JAXBException {
+ public void marshal(Object object, final Result output) throws
JAXBException {
+ object = toImplementation(object); // Must be
call before getTransformVersion()
final TransformVersion version = getTransformVersion();
if (version != null) try {
marshal(object, OutputFactory.createXMLEventWriter(output),
version);
@@ -166,7 +187,7 @@ final class PooledMarshaller extends Poo
// Marshalling to the default GML version.
final Context context = begin();
try {
- marshaller.marshal(toImplementation(object), output);
+ marshaller.marshal(object, output);
} finally {
context.finish();
}
@@ -177,7 +198,8 @@ final class PooledMarshaller extends Poo
* Delegates the marshalling to the wrapped marshaller.
*/
@Override
- public void marshal(final Object object, final OutputStream output) throws
JAXBException {
+ public void marshal(Object object, final OutputStream output) throws
JAXBException {
+ object = toImplementation(object); // Must be
call before getTransformVersion()
final TransformVersion version = getTransformVersion();
if (version != null) try {
marshal(object, OutputFactory.createXMLEventWriter(output,
getEncoding()), version);
@@ -187,7 +209,7 @@ final class PooledMarshaller extends Poo
// Marshalling to the default GML version.
final Context context = begin();
try {
- marshaller.marshal(toImplementation(object), output);
+ marshaller.marshal(object, output);
} finally {
context.finish();
}
@@ -198,7 +220,8 @@ final class PooledMarshaller extends Poo
* Delegates the marshalling to the wrapped marshaller.
*/
@Override
- public void marshal(final Object object, final File output) throws
JAXBException {
+ public void marshal(Object object, final File output) throws JAXBException
{
+ object = toImplementation(object); // Must be
call before getTransformVersion()
final TransformVersion version = getTransformVersion();
if (version != null) try {
try (OutputStream s = new BufferedOutputStream(new
FileOutputStream(output))) {
@@ -210,7 +233,7 @@ final class PooledMarshaller extends Poo
// Marshalling to the default GML version.
final Context context = begin();
try {
- marshaller.marshal(toImplementation(object), output);
+ marshaller.marshal(object, output);
} finally {
context.finish();
}
@@ -221,7 +244,8 @@ final class PooledMarshaller extends Poo
* Delegates the marshalling to the wrapped marshaller.
*/
@Override
- public void marshal(final Object object, final Writer output) throws
JAXBException {
+ public void marshal(Object object, final Writer output) throws
JAXBException {
+ object = toImplementation(object); // Must be
call before getTransformVersion()
final TransformVersion version = getTransformVersion();
if (version != null) try {
marshal(object, OutputFactory.createXMLEventWriter(output),
version);
@@ -231,7 +255,7 @@ final class PooledMarshaller extends Poo
// Marshalling to the default GML version.
final Context context = begin();
try {
- marshaller.marshal(toImplementation(object), output);
+ marshaller.marshal(object, output);
} finally {
context.finish();
}
@@ -242,7 +266,8 @@ final class PooledMarshaller extends Poo
* Delegates the marshalling to the wrapped marshaller.
*/
@Override
- public void marshal(final Object object, final ContentHandler output)
throws JAXBException {
+ public void marshal(Object object, final ContentHandler output) throws
JAXBException {
+ object = toImplementation(object); // Must be
call before getTransformVersion()
final TransformVersion version = getTransformVersion();
if (version != null) try {
marshal(object, OutputFactory.createXMLEventWriter(output),
version);
@@ -252,7 +277,7 @@ final class PooledMarshaller extends Poo
// Marshalling to the default GML version.
final Context context = begin();
try {
- marshaller.marshal(toImplementation(object), output);
+ marshaller.marshal(object, output);
} finally {
context.finish();
}
@@ -263,7 +288,8 @@ final class PooledMarshaller extends Poo
* Delegates the marshalling to the wrapped marshaller.
*/
@Override
- public void marshal(final Object object, final Node output) throws
JAXBException {
+ public void marshal(Object object, final Node output) throws JAXBException
{
+ object = toImplementation(object); // Must be
call before getTransformVersion()
final TransformVersion version = getTransformVersion();
if (version != null) try {
marshal(object, OutputFactory.createXMLEventWriter(output),
version);
@@ -273,7 +299,7 @@ final class PooledMarshaller extends Poo
// Marshalling to the default GML version.
final Context context = begin();
try {
- marshaller.marshal(toImplementation(object), output);
+ marshaller.marshal(object, output);
} finally {
context.finish();
}
@@ -284,7 +310,8 @@ final class PooledMarshaller extends Poo
* Delegates the marshalling to the wrapped marshaller.
*/
@Override
- public void marshal(final Object object, final XMLStreamWriter output)
throws JAXBException {
+ public void marshal(Object object, final XMLStreamWriter output) throws
JAXBException {
+ object = toImplementation(object); // Must be
call before getTransformVersion()
final TransformVersion version = getTransformVersion();
if (version != null) try {
marshal(object, OutputFactory.createXMLEventWriter(output),
version);
@@ -294,7 +321,7 @@ final class PooledMarshaller extends Poo
// Marshalling to the default GML version.
final Context context = begin();
try {
- marshaller.marshal(toImplementation(object), output);
+ marshaller.marshal(object, output);
} finally {
context.finish();
}
@@ -305,14 +332,15 @@ final class PooledMarshaller extends Poo
* Delegates the marshalling to the wrapped marshaller.
*/
@Override
- public void marshal(final Object object, XMLEventWriter output) throws
JAXBException {
+ public void marshal(Object object, XMLEventWriter output) throws
JAXBException {
+ object = toImplementation(object); // Must be
call before getTransformVersion()
final TransformVersion version = getTransformVersion();
if (version != null) {
output = new TransformingWriter(output, version);
}
final Context context = begin();
try {
- marshaller.marshal(toImplementation(object), output);
+ marshaller.marshal(object, output);
} finally {
context.finish();
}
@@ -322,7 +350,8 @@ final class PooledMarshaller extends Poo
* Delegates the marshalling to the wrapped marshaller.
*/
@Override
- public Node getNode(final Object object) throws JAXBException {
+ public Node getNode(Object object) throws JAXBException {
+ object = toImplementation(object); // Must be
call before getTransformVersion()
final TransformVersion version = getTransformVersion();
if (version != null) {
// This exception is thrown by
javax.xml.bind.helpers.AbstractMarshallerImpl anyway.
@@ -330,7 +359,7 @@ final class PooledMarshaller extends Poo
} else {
final Context context = begin();
try {
- return marshaller.getNode(toImplementation(object));
+ return marshaller.getNode(object);
} finally {
context.finish();
}