Author: desruisseaux
Date: Fri Sep 4 15:39:12 2015
New Revision: 1701283
URL: http://svn.apache.org/r1701283
Log:
More liberal use of afterUnmarshal(Unmarshaller, Object parent) when needed.
Experience suggests that the JVM does not load JAXB dependencies as
aggressively as we feared.
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentification.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentification.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentification.java?rev=1701283&r1=1701282&r2=1701283&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentification.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultServiceIdentification.java
[UTF-8] Fri Sep 4 15:39:12 2015
@@ -462,7 +462,7 @@ public class DefaultServiceIdentificatio
/**
* Invoked after JAXB has unmarshalled this object.
*/
- private void afterUnmarshal(final Unmarshaller u, final Object parent) {
+ private void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
if (containsOperations != null && coupledResources != null) {
OperationName.resolve(containsOperations, coupledResources);
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1701283&r1=1701282&r2=1701283&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] Fri Sep 4 15:39:12 2015
@@ -21,6 +21,7 @@ import javax.measure.unit.SI;
import javax.measure.unit.Unit;
import javax.measure.quantity.Length;
import javax.measure.converter.UnitConverter;
+import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@@ -707,15 +708,10 @@ public class DefaultEllipsoid extends Ab
* been defined, it is now possible to calculate the value of the missing
parameter
* using the values of those that are set.
*
- * <div class="note"><b>Note:</b>
- * we use a method invoked from setter methods rather than defining an
{@code afterUnmarshal(Unmarshaller, Object)}
- * method (automatically invoked by JAXB) in order to avoid a dependency
to the {@link javax.xml.bind.Unmarshaller}
- * interface when the user does not want to read GML documents.</div>
- *
* @see #setSemiMajorAxisMeasure(Measure)
* @see #setSecondDefiningParameter(SecondDefiningParameter)
*/
- private void afterUnmarshal() {
+ private void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
if (ivfDefinitive) {
if (semiMinorAxis == 0) {
semiMinorAxis = Formulas.getSemiMinor(semiMajorAxis,
inverseFlattening);
@@ -744,7 +740,7 @@ public class DefaultEllipsoid extends Ab
* This method is invoked by JAXB at unmarshalling time only.
*
* @see #setSecondDefiningParameter(SecondDefiningParameter)
- * @see #afterUnmarshal()
+ * @see #afterUnmarshal(Unmarshaller, Object)
*/
private void setSemiMajorAxisMeasure(final Measure measure) {
if (semiMajorAxis != 0) {
@@ -754,9 +750,6 @@ public class DefaultEllipsoid extends Ab
ensureStrictlyPositive("semiMajorAxis", semiMajorAxis =
measure.value);
unit = measure.getUnit(Length.class);
harmonizeAxisUnits(uom);
- if ((ivfDefinitive ? inverseFlattening : semiMinorAxis) != 0) {
- afterUnmarshal();
- }
}
}
@@ -776,7 +769,7 @@ public class DefaultEllipsoid extends Ab
* second defining parameter given. This is for JAXB unmarshalling process
only.
*
* @see #setSemiMajorAxisMeasure(Measure)
- * @see #afterUnmarshal()
+ * @see #afterUnmarshal(Unmarshaller, Object)
*/
private void setSecondDefiningParameter(SecondDefiningParameter second) {
while (second.secondDefiningParameter != null) {
@@ -799,9 +792,6 @@ public class DefaultEllipsoid extends Ab
ensureStrictlyPositive("semiMinorAxis", semiMinorAxis =
value);
harmonizeAxisUnits(measure.getUnit(Length.class));
}
- if (semiMajorAxis != 0) {
- afterUnmarshal();
- }
}
}
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java?rev=1701283&r1=1701282&r2=1701283&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] Fri Sep 4 15:39:12 2015
@@ -19,23 +19,23 @@ package org.apache.sis.referencing.opera
import java.util.Map;
import java.util.Collection;
import java.util.Collections;
+import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.opengis.util.InternationalString;
+import org.opengis.metadata.Identifier;
import org.opengis.metadata.extent.Extent;
import org.opengis.metadata.quality.PositionalAccuracy;
+import org.opengis.referencing.crs.GeneralDerivedCRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.CoordinateOperation;
import org.opengis.referencing.operation.OperationMethod;
import org.opengis.referencing.operation.MathTransform;
-import org.opengis.metadata.Identifier;
-import org.apache.sis.parameter.Parameterized;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.parameter.ParameterDescriptorGroup;
import org.opengis.parameter.ParameterValueGroup;
-import org.opengis.referencing.crs.GeneralDerivedCRS;
import org.apache.sis.io.wkt.Formatter;
import org.apache.sis.io.wkt.FormattableObject;
import org.apache.sis.util.iso.Types;
@@ -44,6 +44,7 @@ import org.apache.sis.util.ComparisonMod
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.collection.Containers;
import org.apache.sis.util.UnsupportedImplementationException;
+import org.apache.sis.parameter.Parameterized;
import org.apache.sis.referencing.AbstractIdentifiedObject;
import org.apache.sis.referencing.operation.transform.PassThroughTransform;
import org.apache.sis.internal.referencing.PositionalAccuracyConstant;
@@ -167,7 +168,7 @@ public class AbstractCoordinateOperation
* to positions in the {@linkplain #getTargetCRS target coordinate
reference system}.
*
* <p><b>Consider this field as final!</b>
- * This field is modified only at unmarshalling time by {@link
#afterUnmarshal()}</p>
+ * This field is modified only at unmarshalling time by {@link
#afterUnmarshal(Unmarshaller, Object)}</p>
*/
private MathTransform transform;
@@ -856,7 +857,6 @@ check: for (int isTarget=0; ; isTar
private void setSource(final CoordinateReferenceSystem crs) {
if (sourceCRS == null) {
sourceCRS = crs;
- afterUnmarshal();
} else {
ReferencingUtilities.propertyAlreadySet(AbstractCoordinateOperation.class,
"setSource", "sourceCRS");
}
@@ -876,22 +876,24 @@ check: for (int isTarget=0; ; isTar
private void setTarget(final CoordinateReferenceSystem crs) {
if (targetCRS == null) {
targetCRS = crs;
- afterUnmarshal();
} else {
ReferencingUtilities.propertyAlreadySet(AbstractCoordinateOperation.class,
"setTarget", "targetCRS");
}
}
/**
- * Invoked by setter methods for computing the math transform as soon as
we can.
- * It is okay to invoke this method more than once.
+ * Invoked by JAXB after unmarshalling. This method needs information
provided by:
+ *
+ * <ul>
+ * <li>{@link #setSource(CoordinateReferenceSystem)}</li>
+ * <li>{@link #setTarget(CoordinateReferenceSystem)}</li>
+ * <li>{@link
AbstractSingleOperation#setParameters(GeneralParameterValue[])}</li>
+ * </ul>
*
- * <div class="note"><b>Note:</b>
- * we use a method invoked from setter methods rather than defining an
{@code afterUnmarshal(Unmarshaller, Object)}
- * method (automatically invoked by JAXB) in order to avoid a dependency
to the {@link javax.xml.bind.Unmarshaller}
- * interface when the user does not want to read GML documents.</div>
+ * Note that the later method is defined in a subclass, but experience
suggests that it still works
+ * at least with the JAXB implementation provided in JDK.
*/
- final void afterUnmarshal() {
+ private void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
if (transform == null && sourceCRS != null && targetCRS != null) {
transform = createMathTransform();
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java?rev=1701283&r1=1701282&r2=1701283&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
[UTF-8] Fri Sep 4 15:39:12 2015
@@ -468,6 +468,9 @@ class AbstractSingleOperation extends Ab
*/
private void setParameters(final GeneralParameterValue[] values) {
if (parameters == null) {
+ if (!(method instanceof DefaultOperationMethod)) { // May be a
non-null proxy if defined only by xlink:href.
+ throw new
IllegalStateException(Errors.format(Errors.Keys.MissingValueForProperty_1,
"method"));
+ }
/*
* The descriptors in the <gml:method> element do not know the
class of parameter value
* (String, Integer, Double, double[], etc.) because this
information is not part of GML.
@@ -489,6 +492,7 @@ class AbstractSingleOperation extends Ab
for (int i=0; i<merged.length; i++) {
if (merged[i] != values[i].getDescriptor()) {
((DefaultOperationMethod)
method).updateDescriptors(merged);
+ // At this point, method.getParameters() may have changed.
break;
}
}
@@ -500,7 +504,6 @@ class AbstractSingleOperation extends Ab
*/
parameters = new
DefaultParameterValueGroup(method.getParameters());
CC_OperationMethod.store(values, parameters.values(),
replacements);
- afterUnmarshal(); // For creating the math transform.
} else {
ReferencingUtilities.propertyAlreadySet(AbstractSingleOperation.class,
"setParameters", "parameterValue");
}