sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1511423 - in /sis/branches/JDK7: core/sis-utility/src/main/java/org/apache/sis/util/logging/ storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/ storage/sis-storage/src/main/resources/ storage/sis-storage/src/main/resour...
Date Wed, 07 Aug 2013 18:03:54 GMT
Author: desruisseaux
Date: Wed Aug  7 18:03:54 2013
New Revision: 1511423

URL: http://svn.apache.org/r1511423
Log:
Added a XMLStore implementation, in internal package.

Added:
    sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/
    sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStore.java
  (with props)
    sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStoreProvider.java
  (with props)
    sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/package-info.java
  (with props)
    sis/branches/JDK7/storage/sis-storage/src/main/resources/
    sis/branches/JDK7/storage/sis-storage/src/main/resources/META-INF/
    sis/branches/JDK7/storage/sis-storage/src/main/resources/META-INF/services/
    sis/branches/JDK7/storage/sis-storage/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider
  (with props)
    sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/
    sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreProviderTest.java
  (with props)
    sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java
    sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java?rev=1511423&r1=1511422&r2=1511423&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/WarningListeners.java
[UTF-8] Wed Aug  7 18:03:54 2013
@@ -46,7 +46,7 @@ import org.apache.sis.util.resources.Err
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  *
  * @see WarningListener
@@ -257,4 +257,15 @@ public class WarningListeners<S> impleme
         }
         throw new NoSuchElementException(Errors.format(Errors.Keys.NoSuchElement_1, listener));
     }
+
+    /**
+     * Returns {@code true} if this object contains at least one listener.
+     *
+     * @return {@code true} if this object contains at least one listener, {@code false}
otherwise.
+     *
+     * @since 0.4
+     */
+    public synchronized boolean hasListeners() {
+        return listeners != null;
+    }
 }

Added: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStore.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStore.java?rev=1511423&view=auto
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStore.java
(added)
+++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStore.java
[UTF-8] Wed Aug  7 18:03:54 2013
@@ -0,0 +1,182 @@
+/*
+ * 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.storage.xml;
+
+import java.util.Map;
+import java.util.Collections;
+import java.util.logging.LogRecord;
+import java.io.Closeable;
+import java.io.Reader;
+import java.io.InputStream;
+import java.io.IOException;
+import javax.xml.bind.JAXBException;
+import javax.xml.transform.stream.StreamSource;
+import org.opengis.metadata.Metadata;
+import org.apache.sis.xml.XML;
+import org.apache.sis.storage.DataStore;
+import org.apache.sis.storage.StorageConnector;
+import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.util.logging.WarningListener;
+import org.apache.sis.util.resources.Errors;
+
+
+/**
+ * A data store which creates data objects from a XML file.
+ * This {@code DataStore} implementation is basically a facade for the {@link XML#unmarshal(Source,
Map)} method.
+ * The current implementation recognizes the following objects:
+ *
+ * <ul>
+ *   <li>{@link Metadata}, typically built from the {@code <gmd:MD_Metadata>}
XML element.</li>
+ * </ul>
+ *
+ * The above list may be extended in any future SIS version.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public class XMLStore extends DataStore {
+    /**
+     * The file name.
+     */
+    private final String name;
+
+    /**
+     * The input stream or reader, set by the constructor and cleared when no longer needed.
+     */
+    private StreamSource source;
+
+    /**
+     * The unmarshalled object, initialized only when first needed.
+     * May still {@code null} if the unmarshalling failed.
+     */
+    private Object object;
+
+    /**
+     * Creates a new XML store from the given file, URL or stream.
+     *
+     * @param  connector Information about the storage (URL, stream, <i>etc</i>).
+     * @throws DataStoreException If an error occurred while opening the stream.
+     */
+    public XMLStore(final StorageConnector connector) throws DataStoreException {
+        name = connector.getStorageName();
+        final InputStream in = connector.getStorageAs(InputStream.class);
+        if (in != null) {
+            source = new StreamSource(in);
+        } else {
+            final Reader reader = connector.getStorageAs(Reader.class);
+            if (reader != null) {
+                source = new StreamSource(reader);
+            }
+        }
+        final Closeable c = input(source);
+        connector.closeAllExcept(c);
+        if (c == null) {
+            throw new DataStoreException(Errors.format(Errors.Keys.CanNotOpen_1, name));
+        }
+    }
+
+    /**
+     * Returns the input stream or reader set in the given source, or {@code null} if none.
+     */
+    private static Closeable input(final StreamSource source) {
+        Closeable in = null;
+        if (source != null) {
+            in = source.getInputStream();
+            if (in == null) {
+                in = source.getReader();
+            }
+        }
+        return in;
+    }
+
+    /**
+     * Returns the properties to give to the (un)marshaller.
+     */
+    private Map<String,?> properties() {
+        if (listeners.hasListeners()) {
+            return Collections.singletonMap(XML.WARNING_LISTENER, new WarningListener<Object>()
{
+                /** Returns the type of objects that emit warnings of interest for this listener.
*/
+                @Override public Class<Object> getSourceClass() {
+                    return Object.class;
+                }
+
+                /** Reports the occurrence of a non-fatal error during XML unmarshalling.
*/
+                @Override public void warningOccured(final Object source, final LogRecord
warning) {
+                    listeners.warning(warning);
+                }
+            });
+        }
+        return null;
+    }
+
+    /**
+     * Unmarshal the object, if not already done. Note that {@link #object} may still be
null
+     * if an exception has been thrown at this invocation time or in previous invocation.
+     *
+     * @throws DataStoreException If an error occurred during the unmarshalling process.
+     */
+    private void unmarshal() throws DataStoreException {
+        final StreamSource s = source;
+        final Closeable in = input(s);
+        source = null; // Cleared first in case of error.
+        if (in != null) try {
+            try {
+                object = XML.unmarshal(s, properties());
+            } finally {
+                in.close();
+            }
+        } catch (JAXBException | IOException e) {
+            throw new DataStoreException(Errors.format(Errors.Keys.CanNotRead_1, name), e);
+        }
+    }
+
+    /**
+     * Returns the metadata associated to the unmarshalled object, or {@code null} if none.
+     * The current implementation performs the following choice:
+     *
+     * <ul>
+     *   <li>If the unmarshalled object implements the {@link Metadata} interface,
then it is returned directly.</li>
+     * </ul>
+     *
+     * Other cases may be added in any future SIS version.
+     *
+     * @return The metadata associated to the unmarshalled object, or {@code null} if none.
+     * @throws DataStoreException If an error occurred during the unmarshalling process.
+     */
+    @Override
+    public Metadata getMetadata() throws DataStoreException {
+        unmarshal();
+        return (object instanceof Metadata) ? (Metadata) object : null;
+    }
+
+    /**
+     * Closes this data store and releases any underlying resources.
+     */
+    @Override
+    public void close() throws DataStoreException {
+        object = null;
+        final Closeable in = input(source);
+        source = null; // Cleared first in case of failure.
+        if (in != null) try {
+            in.close();
+        } catch (IOException e) {
+            throw new DataStoreException(e);
+        }
+    }
+}

Propchange: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStore.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStoreProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStoreProvider.java?rev=1511423&view=auto
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStoreProvider.java
(added)
+++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStoreProvider.java
[UTF-8] Wed Aug  7 18:03:54 2013
@@ -0,0 +1,105 @@
+/*
+ * 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.storage.xml;
+
+import java.io.Reader;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import org.apache.sis.storage.DataStore;
+import org.apache.sis.storage.DataStoreProvider;
+import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.StorageConnector;
+import org.apache.sis.storage.ProbeResult;
+
+
+/**
+ * The provider of {@link XMLStore} instances.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public class XMLStoreProvider extends DataStoreProvider {
+    /**
+     * The expected XML header. According XML specification, this declaration is required
to appear
+     * at the document beginning (no space allowed before the declaration).
+     */
+    private static final byte[] HEADER = {'<','?','x','m','l',' '};
+
+    /**
+     * Creates a new provider.
+     */
+    public XMLStoreProvider() {
+    }
+
+    /**
+     * Returns {@link ProbeResult#SUPPORTED} if the given storage appears to be supported
by {@link XMLStore}.
+     * Returning {@code SUPPORTED} from this method does not guarantee that reading or writing
will succeed,
+     * only that there appears to be a reasonable chance of success based on a brief inspection
of the storage
+     * header.
+     */
+    @Override
+    public ProbeResult canOpen(final StorageConnector storage) throws DataStoreException
{
+        /*
+         * Usual case. This include InputStream, DataInput, File, Path, URL, URI.
+         */
+        final ByteBuffer buffer = storage.getStorageAs(ByteBuffer.class);
+        if (buffer != null) {
+            if (buffer.remaining() < HEADER.length) {
+                return ProbeResult.INSUFFICIENT_BYTES;
+            }
+            for (int i=0; i<HEADER.length; i++) {
+                if (buffer.get(i) != HEADER[i]) {
+                    return ProbeResult.UNSUPPORTED_STORAGE;
+                }
+            }
+            return ProbeResult.SUPPORTED;
+        }
+        /*
+         * We should enter in this block only if the user gave us explicitely a Reader.
+         * A common case is a StringReader wrapping a String object.
+         */
+        final Reader reader = storage.getStorageAs(Reader.class);
+        if (reader != null) try {
+            reader.mark(HEADER.length);
+            for (int i=0; i<HEADER.length; i++) {
+                if (reader.read() != HEADER[i]) {
+                    reader.reset();
+                    return ProbeResult.UNSUPPORTED_STORAGE;
+                }
+            }
+            reader.reset();
+            return ProbeResult.SUPPORTED;
+        } catch (IOException e) {
+            throw new DataStoreException(e);
+        }
+        return ProbeResult.UNSUPPORTED_STORAGE;
+    }
+
+    /**
+     * Returns a {@link XMLStore} implementation associated with this provider.
+     *
+     * @param  storage Information about the storage (URL, stream, <i>etc</i>).
+     * @return A data store implementation associated with this provider for the given storage.
+     * @throws DataStoreException If an error occurred while creating the data store instance.
+     */
+    @Override
+    public DataStore open(final StorageConnector storage) throws DataStoreException {
+        return new XMLStore(storage);
+    }
+}

Propchange: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStoreProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStoreProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/package-info.java?rev=1511423&view=auto
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/package-info.java
(added)
+++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/package-info.java
[UTF-8] Wed Aug  7 18:03:54 2013
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+/**
+ * {@link org.apache.sis.storage.DataStore} implementation for XML files.
+ * The kind of objects recognized by this package is listed in the
+ * {@link org.apache.sis.storage.xml.XMLStore} class.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+package org.apache.sis.internal.storage.xml;

Propchange: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/storage/sis-storage/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider?rev=1511423&view=auto
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider
(added)
+++ sis/branches/JDK7/storage/sis-storage/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider
[UTF-8] Wed Aug  7 18:03:54 2013
@@ -0,0 +1 @@
+org.apache.sis.internal.storage.xml.XMLStoreProvider

Propchange: sis/branches/JDK7/storage/sis-storage/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/storage/sis-storage/src/main/resources/META-INF/services/org.apache.sis.storage.DataStoreProvider
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreProviderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreProviderTest.java?rev=1511423&view=auto
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreProviderTest.java
(added)
+++ sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreProviderTest.java
[UTF-8] Wed Aug  7 18:03:54 2013
@@ -0,0 +1,50 @@
+/*
+ * 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.storage.xml;
+
+import java.io.StringReader;
+import org.apache.sis.storage.StorageConnector;
+import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.ProbeResult;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link XMLStoreProvider}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public final strictfp class XMLStoreProviderTest extends TestCase {
+    /**
+     * Tests {@link XMLStoreProvider#canOpen(StorageConnector)} method from a {@link Reader}
object.
+     *
+     * @throws DataStoreException Should never happen.
+     */
+    @Test
+    public void testCanOpenFromReader() throws DataStoreException {
+        final XMLStoreProvider p = new XMLStoreProvider();
+        final StorageConnector c = new StorageConnector(new StringReader(XMLStoreTest.XML));
+        assertEquals(ProbeResult.SUPPORTED, p.canOpen(c));
+        c.closeAllExcept(null);
+    }
+}

Propchange: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreProviderTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java?rev=1511423&view=auto
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java
(added)
+++ sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java
[UTF-8] Wed Aug  7 18:03:54 2013
@@ -0,0 +1,109 @@
+/*
+ * 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.storage.xml;
+
+import java.util.Locale;
+import java.io.StringReader;
+import org.opengis.metadata.Metadata;
+import org.opengis.metadata.citation.Role;
+import org.opengis.metadata.citation.OnLineFunction;
+import org.opengis.metadata.citation.OnlineResource;
+import org.opengis.metadata.citation.ResponsibleParty;
+import org.opengis.metadata.identification.CharacterSet;
+import org.apache.sis.xml.Namespaces;
+import org.apache.sis.storage.StorageConnector;
+import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.apache.sis.test.TestUtilities.getSingleton;
+
+
+/**
+ * Tests {@link XMLStore}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public final strictfp class XMLStoreTest extends TestCase {
+    /**
+     * The metadata to unmarshal.
+     */
+    static final String XML =
+            "<?xml version=\"1.0\" standalone=\"yes\"?>\n" +
+            "<gmd:MD_Metadata\n" +
+            "  xmlns:gmd = \"" + Namespaces.GMD + "\"\n"  +
+            "  xmlns:gco = \"" + Namespaces.GCO + "\"\n"  +
+            "  xmlns:xsi = \"" + Namespaces.XSI + "\"\n>" +
+            "  <gmd:language>\n" +
+            "    <gmd:LanguageCode codeListValue=\"eng\">English</gmd:LanguageCode>\n"
+
+            "  </gmd:language>\n" +
+            "  <gmd:characterSet>\n" +
+            "    <gmd:MD_CharacterSetCode codeListValue=\"utf8\">UTF-8</gmd:MD_CharacterSetCode>\n"
+
+            "  </gmd:characterSet>\n" +
+            "  <gmd:contact>\n" +
+            "    <gmd:CI_ResponsibleParty>\n" +
+            "      <gmd:organisationName>\n" +
+            "        <gco:CharacterString>Apache SIS</gco:CharacterString>\n"
+
+            "      </gmd:organisationName>\n" +
+            "      <gmd:contactInfo>\n" +
+            "        <gmd:CI_Contact>\n" +
+            "          <gmd:onlineResource>\n" +
+            "            <gmd:CI_OnlineResource>\n" +
+            "              <gmd:linkage>\n" +
+            "                <gmd:URL>http://sis.apache.org</gmd:URL>\n" +
+            "              </gmd:linkage>\n" +
+            "              <gmd:function>\n" +
+            "                <gmd:CI_OnLineFunctionCode codeListValue=\"information\"
codeSpace=\"fra\">Information</gmd:CI_OnLineFunctionCode>\n" +
+            "              </gmd:function>\n" +
+            "            </gmd:CI_OnlineResource>\n" +
+            "          </gmd:onlineResource>\n" +
+            "        </gmd:CI_Contact>\n" +
+            "      </gmd:contactInfo>\n" +
+            "      <gmd:role>\n" +
+            "        <gmd:CI_RoleCode codeListValue=\"principalInvestigator\">Principal
investigator</gmd:CI_RoleCode>\n" +
+            "      </gmd:role>\n" +
+            "    </gmd:CI_ResponsibleParty>\n" +
+            "  </gmd:contact>\n" +
+            "</gmd:MD_Metadata>\n";
+
+    /**
+     * Tests {@link XMLStore#getMetadata()}.
+     *
+     * @throws DataStoreException If an error occurred while reading the metadata.
+     */
+    @Test
+    public void testMetadata() throws DataStoreException {
+        final Metadata metadata;
+        try (XMLStore store = new XMLStore(new StorageConnector(new StringReader(XML))))
{
+            metadata = store.getMetadata();
+            assertSame("Expected cached value.", metadata, store.getMetadata());
+        }
+        final ResponsibleParty party  = getSingleton(metadata.getContacts());
+        final OnlineResource resource = party.getContactInfo().getOnlineResource();
+
+        assertEquals(Locale.ENGLISH,              metadata.getLanguage());
+        assertEquals(CharacterSet.UTF_8,          metadata.getCharacterSet());
+        assertEquals(Role.PRINCIPAL_INVESTIGATOR, party.getRole());
+        assertEquals("Apache SIS",                String.valueOf(party.getOrganisationName()));
+        assertEquals("http://sis.apache.org",     String.valueOf(resource.getLinkage()));
+        assertEquals(OnLineFunction.INFORMATION,  resource.getFunction());
+    }
+}

Propchange: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java?rev=1511423&r1=1511422&r2=1511423&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
[UTF-8] Wed Aug  7 18:03:54 2013
@@ -26,7 +26,7 @@ import org.junit.BeforeClass;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @Suite.SuiteClasses({
@@ -34,6 +34,8 @@ import org.junit.BeforeClass;
     org.apache.sis.internal.storage.ChannelDataInputTest.class,
     org.apache.sis.internal.storage.ChannelImageInputStreamTest.class,
     org.apache.sis.storage.StorageConnectorTest.class,
+    org.apache.sis.internal.storage.xml.XMLStoreProviderTest.class,
+    org.apache.sis.internal.storage.xml.XMLStoreTest.class,
     org.apache.sis.index.GeoHashCoderTest.class
 })
 public final strictfp class StorageTestSuite extends TestSuite {



Mime
View raw message