Author: desruisseaux Date: Tue Jun 25 08:15:34 2013 New Revision: 1496372 URL: http://svn.apache.org/r1496372 Log: Ported basic GML adapters, to be needed for TimePeriod. Added: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListAdapter.java (with props) sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListProxy.java (with props) sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java (with props) sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/package-info.java (with props) Added: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListAdapter.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListAdapter.java?rev=1496372&view=auto ============================================================================== --- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListAdapter.java (added) +++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListAdapter.java [UTF-8] Tue Jun 25 08:15:34 2013 @@ -0,0 +1,100 @@ +/* + * 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.gml; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import org.opengis.util.CodeList; +import org.apache.sis.util.iso.Types; + + +/** + * JAXB adapter for GML code lists, in order to integrate the value in an element + * complying with GML standard. A subclass shall exist for each code list. + * + * @param The code list being wrapped. + * + * @author Guilhem Legal (Geomatys) + * @author Martin Desruisseaux (Geomatys) + * @since 0.3 (derived from geotk-3.00) + * @version 0.3 + * @module + */ +public abstract class CodeListAdapter> extends XmlAdapter { + /** + * Empty constructor for subclasses only. + */ + protected CodeListAdapter() { + } + + /** + * Forces the initialization of the given code list class, since some + * calls to {@link CodeList#valueOf} are done whereas the constructor + * has not already been called. + * + * @param The code list type. + * @param type The code list class to initialize. + */ + protected static > void ensureClassLoaded(final Class type) { + final String name = type.getName(); + try { + Class.forName(name, true, type.getClassLoader()); + } catch (ClassNotFoundException ex) { + throw new TypeNotPresentException(name, ex); // Should never happen. + } + } + + /** + * Returns the class of code list wrapped by this adapter. + * + * @return The code list class. + */ + protected abstract Class getCodeListClass(); + + /** + * Returns the default code space for the wrapped code list. + * The default implementation returns {@code null}. + * + * @return The default code space, or {@code null}. + */ + protected String getCodeSpace() { + return null; + } + + /** + * Substitutes the adapter value read from an XML stream by the object which will + * contains the value. JAXB calls automatically this method at unmarshalling time. + * + * @param proxy The proxy for the GML value. + * @return A code list which represents the GML value. + */ + @Override + public final BoundType unmarshal(final CodeListProxy proxy) { + return (proxy != null) ? Types.forCodeName(getCodeListClass(), proxy.identifier, true) : null; + } + + /** + * Substitutes the code list by the proxy to be marshalled into an XML file + * or stream. JAXB calls automatically this method at marshalling time. + * + * @param value The code list value. + * @return The proxy for the given code list. + */ + @Override + public final CodeListProxy marshal(final BoundType value) { + return (value != null) ? new CodeListProxy(getCodeSpace(), value) : null; + } +} Propchange: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListAdapter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListAdapter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain;charset=UTF-8 Added: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListProxy.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListProxy.java?rev=1496372&view=auto ============================================================================== --- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListProxy.java (added) +++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListProxy.java [UTF-8] Tue Jun 25 08:15:34 2013 @@ -0,0 +1,60 @@ +/* + * 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.gml; + +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.XmlAttribute; +import org.opengis.util.CodeList; +import org.apache.sis.util.iso.Types; + + +/** + * JAXB adapter for {@link GMLCodeList}, in order to integrate the value in an element + * complying with OGC/ISO standard. + * + * @author Guilhem Legal (Geomatys) + * @since 0.3 (derived from geotk-3.00) + * @version 0.3 + * @module + */ +final class CodeListProxy { + /** + * The code space of the {@linkplain #identifier} as an URI, or {@code null}. + */ + @XmlAttribute + String codeSpace; + + /** + * The code list identifier. + */ + @XmlValue + String identifier; + + /** + * Empty constructor for JAXB only. + */ + public CodeListProxy() { + } + + /** + * Creates a new adapter for the given value. + */ + CodeListProxy(final String codeSpace, final CodeList value) { + this.codeSpace = codeSpace; + this.identifier = Types.getCodeName(value); + } +} Propchange: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListProxy.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/CodeListProxy.java ------------------------------------------------------------------------------ svn:mime-type = text/plain;charset=UTF-8 Added: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java?rev=1496372&view=auto ============================================================================== --- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java (added) +++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java [UTF-8] Tue Jun 25 08:15:34 2013 @@ -0,0 +1,116 @@ +/* + * Geotoolkit.org - An Open Source Java GIS Toolkit + * http://www.geotoolkit.org + * + * (C) 2011-2012, Open Source Geospatial Foundation (OSGeo) + * (C) 2011-2012, Geomatys + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package org.apache.sis.internal.jaxb.gml; + +import javax.xml.bind.annotation.XmlID; +import javax.xml.bind.annotation.XmlAttribute; +import org.apache.sis.util.Version; +import org.apache.sis.xml.Namespaces; +import org.apache.sis.xml.IdentifierMap; +import org.apache.sis.xml.IdentifierSpace; +import org.apache.sis.xml.IdentifiedObject; + + +/** + * Base class for GML objects that are wrappers around a GeoAPI implementation. + * Every GML object to be marshalled have an ID attribute, which is mandatory. + * If no ID is explicitely set, a default one will be created from the wrapped object. + * + * {@note This class is somewhat temporary. It assign the ID to the wrapped object. + * In a future SIS version, we should assign the ID to the object itself.} + * + * @author Guilhem Legal (Geomatys) + * @author Martin Desruisseaux (Geomatys) + * @since 0.3 (derived from geotk-3.18) + * @version 0.3 + * @module + */ +public abstract class GMLAdapter { + /** + * A GML version suitable for calls to {@link org.apache.sis.internal.jaxb.Context#isGMLVersion}. + */ + public static final Version GML_3_0 = new Version("3.0"), + GML_3_2 = new Version("3.2"); + + /** + * The period identifier, or {@code null} if undefined. + * This element is part of GML 3.1.1 specification. + * + * {@section Difference between gmd:uuid and gml:id} + *
    + *
  • {@code id} is a standard GML attribute available on every + * object-with-identity. It has type={@code "xs:ID"} - i.e. it is a fragment + * identifier, unique within document scope only, for internal cross-references. + * It is not useful by itself as a persistent unique identifier.
  • + *
  • {@code uuid} is an optional attribute available on every object-with-identity, + * provided in the GMD schemas that implement ISO 19115 in XML. + * May be used as a persistent unique identifier, but only available within GMD + * context.
  • + *
+ * + * @see GML identifiers + * @see org.apache.sis.internal.jaxb.gco.ObjectReference#getUUIDREF() + */ + @XmlID + @XmlAttribute(required = true, namespace = Namespaces.GML) + private String id; + + /** + * Creates a new GML object with no ID. + * This constructor is typically invoked at unmarshalling time. + * The {@link #id} value will then be set by JAXB. + * + * @see #copyIdTo(Object) + */ + protected GMLAdapter() { + } + + /** + * Creates a new GML object wrapping the given GeoAPI implementation. + * The ID will be determined from the given object. + * + *

This constructor is typically invoked at marshalling time. The {@link #id} + * value set by this constructor will be used by JAXB for producing the XML.

+ * + * @param wrapped An instance of a GeoAPI interface to be wrapped. + */ + protected GMLAdapter(final Object wrapped) { + if (wrapped instanceof IdentifiedObject) { + final IdentifierMap map = ((IdentifiedObject) wrapped).getIdentifierMap(); + if (map != null) { // Should not be null, but let be safe. + id = map.get(IdentifierSpace.ID); + } + } + } + + /** + * Assign the {@link #id} value (if non-null) to the given object. This method + * is typically invoked at unmarshalling time in order to assign the ID of this + * temporary wrapper to the "real" GeoAPI implementation instance. + * + * @param wrapped The GeoAPI implementation for which to assign the ID. + */ + public final void copyIdTo(final Object wrapped) { + if (id != null && wrapped instanceof IdentifiedObject) { + final IdentifierMap map = ((IdentifiedObject) wrapped).getIdentifierMap(); + if (map != null) { // Should not be null, but let be safe. + map.put(IdentifierSpace.ID, id); + } + } + } +} Propchange: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain;charset=UTF-8 Added: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/package-info.java URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/package-info.java?rev=1496372&view=auto ============================================================================== --- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/package-info.java (added) +++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/package-info.java [UTF-8] Tue Jun 25 08:15:34 2013 @@ -0,0 +1,40 @@ +/* + * 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. + */ + +/** + * Miscellaneous objects and adapters defined in the {@code "gml"} namespace. + * + * @author Guilhem Legal (Geomatys) + * @author Martin Desruisseaux (Geomatys) + * @since 0.3 (derived from geotk-3.18) + * @version 0.3 + * @module + * + * @see javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter + */ +@XmlSchema(elementFormDefault = XmlNsForm.QUALIFIED, namespace = Namespaces.GML, xmlns = { + @XmlNs(prefix = "gml", namespaceURI = Namespaces.GML) +}) +@XmlAccessorType(XmlAccessType.NONE) +package org.apache.sis.internal.jaxb.gml; + +import javax.xml.bind.annotation.XmlNs; +import javax.xml.bind.annotation.XmlNsForm; +import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import org.apache.sis.xml.Namespaces; Propchange: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/package-info.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/package-info.java ------------------------------------------------------------------------------ svn:mime-type = text/plain;charset=UTF-8