Author: desruisseaux
Date: Wed Dec 5 08:04:23 2012
New Revision: 1417304
URL: http://svn.apache.org/viewvc?rev=1417304&view=rev
Log:
Initial commit of a few JAXB adapters.
Added:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
(with props)
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java
(with props)
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java
(with props)
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Real.java
(with props)
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/package-info.java
Added:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java?rev=1417304&view=auto
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
(added)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
Wed Dec 5 08:04:23 2012
@@ -0,0 +1,97 @@
+/*
+ * 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.gco;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+
+/**
+ * Surrounds boolean value by {@code <gco:Boolean>}.
+ * The ISO-19139 standard specifies that primitive types have to be surrounded
by an element
+ * which represents the type of the value, using the namespace {@code gco}
linked to the
+ * {@code http://www.isotc211.org/2005/gco} URL. The JAXB default behavior is
to marshal
+ * primitive Java types directly "as is", without wrapping the value in the
required element.
+ * The role of this class is to add such wrapping.
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ */
+public final class GO_Boolean extends XmlAdapter<GO_Boolean, Boolean> {
+ /**
+ * Wraps the {@link Boolean#TRUE} value.
+ */
+ private static final GO_Boolean TRUE = new GO_Boolean(Boolean.TRUE);
+
+ /**
+ * Wraps the {@link Boolean#FALSE} value.
+ */
+ private static final GO_Boolean FALSE = new GO_Boolean(Boolean.FALSE);
+
+ /**
+ * The boolean value to handle.
+ */
+ @XmlElement(name = "Boolean")
+ public Boolean value;
+
+ /**
+ * Empty constructor used only by JAXB.
+ */
+ public GO_Boolean() {
+ }
+
+ /**
+ * Constructs an adapter for the given value.
+ *
+ * @param value The value.
+ */
+ private GO_Boolean(final Boolean value) {
+ this.value = value;
+ }
+
+ /**
+ * Allows JAXB to generate a Boolean object using the value found in the
adapter.
+ *
+ * @param value The value wrapped in an adapter.
+ * @return The boolean value extracted from the adapter.
+ */
+ @Override
+ public Boolean unmarshal(final GO_Boolean value) {
+ return (value != null) ? value.value : null;
+ }
+
+ /**
+ * Allows JAXB to change the result of the marshalling process, according
to the
+ * ISO-19139 standard and its requirements about primitive types.
+ *
+ * @param value The boolean value we want to surround by an element
representing its type.
+ * @return An adaptation of the boolean value, that is to say a boolean
value surrounded
+ * by {@code <gco:Boolean>} element.
+ */
+ @Override
+ public GO_Boolean marshal(final Boolean value) {
+ if (value == null) {
+ return null;
+ }
+ final GO_Boolean c = value ? TRUE : FALSE;
+ assert value.equals(c.value) : value;
+ return c;
+ }
+}
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Boolean.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java?rev=1417304&view=auto
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java
(added)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java
Wed Dec 5 08:04:23 2012
@@ -0,0 +1,188 @@
+/*
+ * 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.gco;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+
+/**
+ * Surrounds double values by {@code <gco:Decimal>}.
+ * The ISO-19139 standard specifies that primitive types have to be surrounded
by an element
+ * which represents the type of the value, using the namespace {@code gco}
linked to the
+ * {@code http://www.isotc211.org/2005/gco} URL. The JAXB default behavior is
to marshal
+ * primitive Java types directly "as is", without wrapping the value in the
required element.
+ * The role of this class is to add such wrapping.
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ *
+ * @see GO_Real
+ * @see AsFloat
+ */
+public final class GO_Decimal extends XmlAdapter<GO_Decimal, Double> {
+ /**
+ * Frequently used constants.
+ */
+ private static final GO_Decimal
+ P0 = new GO_Decimal( 0.0),
+ P1 = new GO_Decimal( 1.0),
+ N1 = new GO_Decimal( -1.0),
+ P45 = new GO_Decimal( 45.0),
+ N45 = new GO_Decimal( -45.0),
+ P90 = new GO_Decimal( 90.0),
+ N90 = new GO_Decimal( -90.0),
+ P180 = new GO_Decimal( 180.0),
+ N180 = new GO_Decimal(-180.0),
+ P360 = new GO_Decimal( 360.0),
+ N360 = new GO_Decimal(-360.0);
+
+ /**
+ * The double value to handle.
+ */
+ @XmlElement(name = "Decimal")
+ public Double value;
+
+ /**
+ * Empty constructor used only by JAXB.
+ */
+ public GO_Decimal() {
+ }
+
+ /**
+ * Constructs an adapter for the given value.
+ *
+ * @param value The value.
+ */
+ private GO_Decimal(final Double value) {
+ this.value = value;
+ }
+
+ /**
+ * Allows JAXB to generate a Double object using the value found in the
adapter.
+ *
+ * @param value The value wrapped in an adapter.
+ * @return The double value extracted from the adapter.
+ */
+ @Override
+ public Double unmarshal(final GO_Decimal value) {
+ return (value != null) ? value.value : null;
+ }
+
+ /**
+ * Allows JAXB to change the result of the marshalling process, according
to the
+ * ISO-19139 standard and its requirements about primitive types.
+ *
+ * @param value The double value we want to surround by an element
representing its type.
+ * @return An adaptation of the double value, that is to say a double
value surrounded
+ * by {@code <gco:Decimal>} element.
+ */
+ @Override
+ public GO_Decimal marshal(final Double value) {
+ if (value == null) {
+ return null;
+ }
+ final GO_Decimal c;
+ final int index = value.intValue();
+ if (index == value.doubleValue()) {
+ switch (index) {
+ case 0: c = P0; break;
+ case 1: c = P1; break;
+ case -1: c = N1; break;
+ case 45: c = P45; break;
+ case -45: c = N45; break;
+ case 90: c = P90; break;
+ case -90: c = N90; break;
+ case 180: c = P180; break;
+ case -180: c = N180; break;
+ case 360: c = P360; break;
+ case -360: c = N360; break;
+ default: c = new GO_Decimal(value);
+ }
+ } else {
+ c = new GO_Decimal(value);
+ }
+ assert value.equals(c.value) : value;
+ return c;
+ }
+
+
+
+
+ /**
+ * Surrounds float values by {@code <gco:Decimal>}.
+ * The ISO-19139 standard specifies that primitive types have to be
surrounded by an element
+ * which represents the type of the value, using the namespace {@code gco}
linked to the
+ * {@code http://www.isotc211.org/2005/gco} URL. The JAXB default behavior
is to marshal
+ * primitive Java types directly "as is", without wrapping the value in
the required element.
+ * The role of this class is to add such wrapping.
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @since 0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ */
+ public static final class AsFloat extends XmlAdapter<AsFloat, Float> {
+ /**
+ * The float value to handle.
+ */
+ @XmlElement(name = "Decimal")
+ public Float value;
+
+ /**
+ * Empty constructor used only by JAXB.
+ */
+ public AsFloat() {
+ }
+
+ /**
+ * Constructs an adapter for the given value.
+ *
+ * @param value The value.
+ */
+ private AsFloat(final Float value) {
+ this.value = value;
+ }
+
+ /**
+ * Allows JAXB to generate a Float object using the value found in the
adapter.
+ *
+ * @param value The value wrapped in an adapter.
+ * @return The float value extracted from the adapter.
+ */
+ @Override
+ public Float unmarshal(final AsFloat value) {
+ return (value != null) ? value.value : null;
+ }
+
+ /**
+ * Allows JAXB to change the result of the marshalling process,
according to the
+ * ISO-19139 standard and its requirements about primitive types.
+ *
+ * @param value The float value we want to surround by an element
representing its type.
+ * @return An adaptation of the float value, that is to say a float
value surrounded
+ * by {@code <gco:Decimal>} element.
+ */
+ @Override
+ public AsFloat marshal(final Float value) {
+ return (value != null) ? new AsFloat(value) : null;
+ }
+ }
+}
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Decimal.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java?rev=1417304&view=auto
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java
(added)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java
Wed Dec 5 08:04:23 2012
@@ -0,0 +1,163 @@
+/*
+ * 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.gco;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+
+/**
+ * Surrounds integer values by {@code <gco:Integer>}.
+ * The ISO-19139 standard specifies that primitive types have to be surrounded
by an element
+ * which represents the type of the value, using the namespace {@code gco}
linked to the
+ * {@code http://www.isotc211.org/2005/gco} URL. The JAXB default behavior is
to marshal
+ * primitive Java types directly "as is", without wrapping the value in the
required element.
+ * The role of this class is to add such wrapping.
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ *
+ * @see AsLong
+ */
+public final class GO_Integer extends XmlAdapter<GO_Integer, Integer> {
+ /**
+ * Frequently used constants.
+ */
+ private static final GO_Integer[] CONSTANTS = new GO_Integer[5];
+ static {
+ for (int i=0; i<CONSTANTS.length; i++) {
+ CONSTANTS[i] = new GO_Integer(i);
+ }
+ }
+
+ /**
+ * The integer value to handle.
+ */
+ @XmlElement(name = "Integer")
+ public Integer value;
+
+ /**
+ * Empty constructor used only by JAXB.
+ */
+ public GO_Integer() {
+ }
+
+ /**
+ * Constructs an adapter for the given value.
+ *
+ * @param value The value.
+ */
+ private GO_Integer(final Integer value) {
+ this.value = value;
+ }
+
+ /**
+ * Allows JAXB to generate an Integer object using the value found in the
adapter.
+ *
+ * @param value The value wrapped in an adapter.
+ * @return The integer value extracted from the adapter.
+ */
+ @Override
+ public Integer unmarshal(final GO_Integer value) {
+ return (value != null) ? value.value : null;
+ }
+
+ /**
+ * Allows JAXB to change the result of the marshalling process, according
to the
+ * ISO-19139 standard and its requirements about primitive types.
+ *
+ * @param value The integer value we want to surround by an element
representing its type.
+ * @return An adaptation of the integer value, that is to say an integer
value surrounded
+ * by {@code <gco:Integer>} element.
+ */
+ @Override
+ public GO_Integer marshal(final Integer value) {
+ if (value == null) {
+ return null;
+ }
+ final int i = value;
+ final GO_Integer c = (i >= 0 && i < CONSTANTS.length) ? CONSTANTS[i] :
new GO_Integer(value);
+ assert value.equals(c.value) : value;
+ return c;
+ }
+
+
+
+
+ /**
+ * Surrounds long values by {@code <gco:Integer>}.
+ * The ISO-19139 standard specifies that primitive types have to be
surrounded by an element
+ * which represents the type of the value, using the namespace {@code gco}
linked to the
+ * {@code http://www.isotc211.org/2005/gco} URL. The JAXB default behavior
is to marshal
+ * primitive Java types directly "as is", without wrapping the value in
the required element.
+ * The role of this class is to add such wrapping.
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @since 0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ */
+ public static final class AsLong extends XmlAdapter<AsLong, Long> {
+ /**
+ * The long value to handle.
+ */
+ @XmlElement(name = "Integer")
+ public Long value;
+
+ /**
+ * Empty constructor used only by JAXB.
+ */
+ public AsLong() {
+ }
+
+ /**
+ * Constructs an adapter for the given value.
+ *
+ * @param value The value.
+ */
+ private AsLong(final Long value) {
+ this.value = value;
+ }
+
+ /**
+ * Allows JAXB to generate a Long object using the value found in the
adapter.
+ *
+ * @param value The value wrapped in an adapter.
+ * @return The long value extracted from the adapter.
+ */
+ @Override
+ public Long unmarshal(final AsLong value) {
+ return (value != null) ? value.value : null;
+ }
+
+ /**
+ * Allows JAXB to change the result of the marshalling process,
according to the
+ * ISO-19139 standard and its requirements about primitive types.
+ *
+ * @param value The integer value we want to surround by an element
representing its type.
+ * @return An adaptation of the integer value, that is to say a
integer value surrounded
+ * by {@code <gco:Integer>} element.
+ */
+ @Override
+ public AsLong marshal(final Long value) {
+ return (value != null) ? new AsLong(value) : null;
+ }
+ }
+}
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Integer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Real.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Real.java?rev=1417304&view=auto
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Real.java
(added)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Real.java
Wed Dec 5 08:04:23 2012
@@ -0,0 +1,83 @@
+/*
+ * 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.gco;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+
+/**
+ * Surrounds double values by {@code <gco:Real>}.
+ * The ISO-19139 standard specifies that primitive types have to be surrounded
by an element
+ * which represents the type of the value, using the namespace {@code gco}
linked to the
+ * {@code http://www.isotc211.org/2005/gco} URL. The JAXB default behavior is
to marshal
+ * primitive Java types directly "as is", without wrapping the value in the
required element.
+ * The role of this class is to add such wrapping.
+ *
+ * @author Cédric Briançon (Geomatys)
+ * @since 0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ *
+ * @see GO_Decimal
+ */
+public final class GO_Real extends XmlAdapter<GO_Real, Double> {
+ /**
+ * The double value to handle.
+ */
+ @XmlElement(name = "Real")
+ public Double value;
+
+ /**
+ * Empty constructor used only by JAXB.
+ */
+ public GO_Real() {
+ }
+
+ /**
+ * Constructs an adapter for this value.
+ *
+ * @param value The value.
+ */
+ private GO_Real(final Double value) {
+ this.value = value;
+ }
+
+ /**
+ * Allows JAXB to generate a Double object using the value found in the
adapter.
+ *
+ * @param value The value extract from the adapter.
+ * @return A double object.
+ */
+ @Override
+ public Double unmarshal(final GO_Real value) {
+ return (value != null) ? value.value : null;
+ }
+
+ /**
+ * Allows JAXB to change the result of the marshalling process, according
to the
+ * ISO-19139 standard and its requirements about primitive types.
+ *
+ * @param value The double value we want to surround by an element
representing its type.
+ * @return An adaptation of the double value, that is to say a double
value surrounded
+ * by {@code <gco:Real>} element.
+ */
+ @Override
+ public GO_Real marshal(final Double value) {
+ return (value != null) ? new GO_Real(value) : null;
+ }
+}
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Real.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_Real.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/package-info.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/package-info.java?rev=1417304&r1=1417303&r2=1417304&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/package-info.java
(original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/package-info.java
Wed Dec 5 08:04:23 2012
@@ -42,7 +42,7 @@
* </ul>
*
* Classes prefixed by two letters, like {@code "GO_Decimal"}, are also
wrappers around the actual
- * object to be marshalled. See the {@link
org.geotoolkit.internal.jaxb.metadata} package for more
+ * object to be marshalled. See the {@link
org.apache.sis.internal.jaxb.metadata} package for more
* explanation about wrappers. Note that the two-letters prefixes used in this
package (not to be
* confused with the three-letters prefixes used in XML documents) are not
defined by OGC/ISO
* specifications; they are used only for consistency with current practice in