sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1495425 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gts/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/ sis-utility/src/...
Date Fri, 21 Jun 2013 13:10:43 GMT
Author: desruisseaux
Date: Fri Jun 21 13:10:43 2013
New Revision: 1495425

URL: http://svn.apache.org/r1495425
Log:
Marshal the userDefinedMaintenanceFrequency property.

Added:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gts/TM_PeriodDuration.java
  (with props)
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/XmlUtilities.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/package-info.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/TemporalUtilities.java

Added: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gts/TM_PeriodDuration.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gts/TM_PeriodDuration.java?rev=1495425&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gts/TM_PeriodDuration.java
(added)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gts/TM_PeriodDuration.java
[UTF-8] Fri Jun 21 13:10:43 2013
@@ -0,0 +1,181 @@
+/*
+ * 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.gts;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import javax.xml.datatype.Duration;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.datatype.DatatypeConfigurationException;
+import org.opengis.temporal.PeriodDuration;
+import org.opengis.temporal.TemporalFactory;
+import org.opengis.util.InternationalString;
+import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.internal.jaxb.XmlUtilities;
+import org.apache.sis.internal.jaxb.gco.PropertyType;
+import org.apache.sis.internal.util.TemporalUtilities;
+import org.apache.sis.util.iso.SimpleInternationalString;
+
+
+/**
+ * Wraps a {@code gts:TM_PeriodDuration} element.
+ *
+ * @todo The work done in the {@link #getElement()} and {@link #setElement(Duration)} methods
should move
+ *       to {@link org.apache.sis.xml.ValueConverter}. However they rely on the {@link org.opengis.temporal}
+ *       API in geoapi-pending, which is not very clear... We prefer to hide this for now.
+ *
+ * @author  Guilhem Legal (Geomatys)
+ * @since   0.3 (derived from geotk-3.21)
+ * @version 0.3
+ * @module
+ */
+public final class TM_PeriodDuration extends PropertyType<TM_PeriodDuration, PeriodDuration>
{
+    /**
+     * Empty constructor for JAXB.
+     */
+    public TM_PeriodDuration() {
+    }
+
+    /**
+     * Wraps a Temporal Period Duration value at marshalling-time.
+     *
+     * @param metadata The metadata value to marshal.
+     */
+    private TM_PeriodDuration(final PeriodDuration metadata) {
+        super(metadata);
+    }
+
+    /**
+     * Returns the Period Duration value wrapped by a {@code gts:TM_PeriodDuration} element.
+     *
+     * @param value The value to marshal.
+     * @return The adapter which wraps the metadata value.
+     */
+    @Override
+    protected TM_PeriodDuration wrap(final PeriodDuration value) {
+        return new TM_PeriodDuration(value);
+    }
+
+    /**
+     * Returns the GeoAPI interface which is bound by this adapter.
+     */
+    @Override
+    protected Class<PeriodDuration> getBoundType() {
+        return PeriodDuration.class;
+    }
+
+    /**
+     * Returns the {@link Duration} generated from the metadata value.
+     * This method is systematically called at marshalling time by JAXB.
+     *
+     * @return The time period, or {@code null}.
+     */
+    @XmlElement(name = "TM_PeriodDuration")
+    public Duration getElement() {
+        if (!skip()) try {
+            /*
+             * Get the DatatypeFactory first because if not available, then we don't need
to parse
+             * the calendar fields. This has the side effect of not validating the calendar
fields
+             * syntax (which should be integer values), but maybe this is what the user wants.
+             */
+            final DatatypeFactory factory = XmlUtilities.getDatatypeFactory();
+            final PeriodDuration metadata = this.metadata;
+            InternationalString value;
+            BigInteger years = null;
+            if ((value = metadata.getYears()) != null) {
+                years = new BigInteger(value.toString());
+            }
+            BigInteger months = null;
+            if ((value = metadata.getMonths()) != null) {
+                months = new BigInteger(value.toString());
+            }
+            BigInteger days = null;
+            if ((value = metadata.getDays()) != null) {
+                days = new BigInteger(value.toString());
+            }
+            BigInteger hours = null;
+            if ((value = metadata.getHours()) != null) {
+                hours = new BigInteger(value.toString());
+            }
+            BigInteger minutes = null;
+            if ((value = metadata.getMinutes()) != null) {
+                minutes = new BigInteger(value.toString());
+            }
+            BigDecimal seconds = null;
+            if ((value = metadata.getSeconds()) != null) {
+                seconds = new BigDecimal(value.toString());
+            }
+            return factory.newDuration(true, years, months, days, hours, minutes, seconds);
+        } catch (DatatypeConfigurationException e) {
+            warningOccured("getElement", e);
+        }
+        return null;
+    }
+
+    /**
+     * Sets the value from the {@link Duration}.
+     * This method is called at unmarshalling time by JAXB.
+     *
+     * @param duration The adapter to set.
+     */
+    public void setElement(final Duration duration) {
+        metadata = null; // Cleaned first in case of failure.
+        if (duration != null) try {
+            final TemporalFactory factory = TemporalUtilities.getTemporalFactory();
+            InternationalString years = null;
+            int value;
+            if ((value = duration.getYears()) != 0) {
+                years = new SimpleInternationalString(Integer.toString(value));
+            }
+            InternationalString months = null;
+            if ((value = duration.getMonths()) != 0) {
+                months = new SimpleInternationalString(Integer.toString(value));
+            }
+            InternationalString weeks = null; // no weeks in javax.xml.datatype.Duration
+            InternationalString days = null;
+            if ((value = duration.getDays()) != 0) {
+                days = new SimpleInternationalString(Integer.toString(value));
+            }
+            InternationalString hours = null;
+            if ((value = duration.getHours()) != 0) {
+                hours = new SimpleInternationalString(Integer.toString(value));
+            }
+            InternationalString minutes = null;
+            if ((value = duration.getMinutes()) != 0) {
+                minutes = new SimpleInternationalString(Integer.toString(value));
+            }
+            InternationalString seconds = null;
+            if ((value = duration.getSeconds()) != 0) {
+                seconds = new SimpleInternationalString(Integer.toString(value));
+            }
+            metadata = factory.createPeriodDuration(years, months, weeks, days, hours, minutes,
seconds);
+        } catch (UnsupportedOperationException e) {
+            warningOccured("setElement", e);
+        }
+    }
+
+    /**
+     * Reports a failure to execute the operation because of missing {@code sis-temporal}
module.
+     *
+     * @param methodName The method name.
+     * @param e The exception.
+     */
+    private void warningOccured(final String methodName, final Exception e) {
+        Context.warningOccured(Context.current(), this, TM_PeriodDuration.class, methodName,
e, true);
+    }
+}

Propchange: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gts/TM_PeriodDuration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gts/TM_PeriodDuration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java?rev=1495425&r1=1495424&r2=1495425&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
[UTF-8] Fri Jun 21 13:10:43 2013
@@ -48,7 +48,7 @@ import static org.apache.sis.internal.me
 @XmlType(name = "MD_MaintenanceInformation_Type", propOrder = {
     "maintenanceAndUpdateFrequency",
     "dateOfNextUpdate",
-// TODO    "userDefinedMaintenanceFrequency",
+    "userDefinedMaintenanceFrequency",
     "updateScopes",
     "updateScopeDescriptions",
     "maintenanceNotes",
@@ -205,11 +205,9 @@ public class DefaultMaintenanceInformati
 
     /**
      * Returns the maintenance period other than those defined.
-     *
-     * @todo needs an implementation of org.opengis.temporal modules to anntote this parameter.
      */
     @Override
-    // TODO @XmlElement(name = "userDefinedMaintenanceFrequency")
+    @XmlElement(name = "userDefinedMaintenanceFrequency")
     public PeriodDuration getUserDefinedMaintenanceFrequency() {
         return userDefinedMaintenanceFrequency;
     }

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/package-info.java?rev=1495425&r1=1495424&r2=1495425&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/package-info.java
[UTF-8] Fri Jun 21 13:10:43 2013
@@ -75,7 +75,7 @@
     @XmlJavaTypeAdapter(MD_MaintenanceInformation.class),
     @XmlJavaTypeAdapter(MD_ScopeCode.class),
     @XmlJavaTypeAdapter(MD_ScopeDescription.class),
-//    @XmlJavaTypeAdapter(TM_PeriodDuration.class), // TODO
+    @XmlJavaTypeAdapter(TM_PeriodDuration.class),
 
     // Java types, primitive types and basic OGC types handling
 //    @XmlJavaTypeAdapter(GO_DateTime.class), // TODO
@@ -95,5 +95,5 @@ import javax.xml.bind.annotation.adapter
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.internal.jaxb.gco.*;
 import org.apache.sis.internal.jaxb.code.*;
-//import org.apache.sis.internal.jaxb.gts.TM_PeriodDuration; // TODO
+import org.apache.sis.internal.jaxb.gts.TM_PeriodDuration;
 import org.apache.sis.internal.jaxb.metadata.*;

Added: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/XmlUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/XmlUtilities.java?rev=1495425&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/XmlUtilities.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/XmlUtilities.java
[UTF-8] Fri Jun 21 13:10:43 2013
@@ -0,0 +1,81 @@
+/*
+ * 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 javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.DatatypeConfigurationException;
+import org.apache.sis.internal.system.SystemListener;
+import org.apache.sis.internal.system.Modules;
+
+/**
+ * Utilities methods related to XML.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.00)
+ * @version 0.3
+ * @module
+ */
+public final class XmlUtilities extends SystemListener {
+    /**
+     * The factory for creating {@link javax.xml.datatype} objects.
+     */
+    private static volatile DatatypeFactory factory;
+
+    /**
+     * Resets the {@link #factory} to {@code null} if the classpath changed.
+     */
+    static {
+        SystemListener.add(new XmlUtilities());
+    }
+
+    /**
+     * For internal usage only.
+     */
+    private XmlUtilities() {
+        super(Modules.UTILITIES);
+    }
+
+    /**
+     * Invoked when the classpath changed. This method resets the {@link #factory} to {@code
null}
+     * in order to force the search for a new instance.
+     */
+    @Override
+    protected void classpathChanged() {
+        synchronized (XmlUtilities.class) {
+            factory = null;
+        }
+    }
+
+    /**
+     * Returns the factory for creating {@link javax.xml.datatype} objects.
+     *
+     * @return The factory (never {@code null}).
+     * @throws DatatypeConfigurationException If the factory can not be created.
+     */
+    public static DatatypeFactory getDatatypeFactory() throws DatatypeConfigurationException
{
+        DatatypeFactory f = factory;
+        if (f == null) {
+            synchronized (XmlUtilities.class) {
+                f = factory;
+                if (f == null) {
+                    factory = f = DatatypeFactory.newInstance();
+                }
+            }
+        }
+        return f;
+    }
+}

Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/XmlUtilities.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/XmlUtilities.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/TemporalUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/TemporalUtilities.java?rev=1495425&r1=1495424&r2=1495425&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/TemporalUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/TemporalUtilities.java
[UTF-8] Fri Jun 21 13:10:43 2013
@@ -45,9 +45,10 @@ public final class TemporalUtilities ext
     /**
      * Returns a temporal factory if available.
      *
+     * @return The temporal factory.
      * @throws UnsupportedOperationException If the temporal factory is not available on
the classpath.
      */
-    private static TemporalFactory getTemporalFactory() throws UnsupportedOperationException
{
+    public static TemporalFactory getTemporalFactory() throws UnsupportedOperationException
{
         final TemporalFactory factory = DefaultFactories.forClass(TemporalFactory.class);
         if (factory != null) {
             return factory;



Mime
View raw message