Thanks Martin,

I think i would prefer the use of internal /Anchor,/ that indeed i realized later that i have been using it for keywords yet. For now i will stick with using a CharacterString, as i have seen the INSPIRE metadata validator is not taking into account /Anchor/ element for Reference System, and it's not solving the issue highlighted before on validating the metadata Reference System vs. INSPIRE. I have submit some test cases to INSPIRE team, to see if the INSPIRE metadata validator could be improved.

Best,
Emmanuel

Le 03/08/2015 10:15, Martin Desruisseaux a écrit :

Hello Emmanuel

The Anchor class is for internal SIS mechanic. Classes in "org.apache.sis.internal", while public, are more at risk to change in future SIS versions. The proposed public (non-internal) API uses a different strategy. Rather than assigning explicitly anchor values to the metadata properties, we create the metadata object without consideration for anchors, for example with the "4326" code value. Only at marshalling time, those values can be replaced on-the-fly by XLink. This replacement can be done by overriding the ReferenceResolver.anchor(...) method. The intend of this approach is to separate the metadata content from the XML representation of that metadata, if we consider XLink as a XML-specific thing. The XLink can often be constructed dynamically from the content.

Below is a code example doing that.

    final class Test extends ReferenceResolver {
         public static void main(String[] args) throws Exception {
             DefaultMetadata metadata = new DefaultMetadata();

             NamedIdentifier namedIdentifier = new NamedIdentifier(null, "EPSG", 
"4326", null, null);
             ReferenceSystemMetadata rsm = new 
ReferenceSystemMetadata(namedIdentifier);
             metadata.setReferenceSystemInfo(Arrays.asList(rsm));

             final Map<String,Object> properties = new HashMap<>();
             properties.put(XML.RESOLVER, new Test());

             XML.marshal(metadata, new StreamResult(System.out), properties);
         }

         @Override
         public XLink anchor(MarshalContext context, Object value, CharSequence 
text) {
             if ("4326".equals(text)) {
                 final XLink srsAnchor = new XLink();
                 
srsAnchor.setHRef(URI.create("http://www.opengis.net/def/crs/EPSG/0/4326";));
                 srsAnchor.setTitle(new SimpleInternationalString("WGS84"));
                 return srsAnchor;
             }
             return null;
         }
    }

Above example replaces all occurrences of <gco:CharacterString>4326</gco:CharacterString> by <gmx:Anchor ...> at marshalling time. This may be too aggressive, in which case it is possible to filter by enclosing type (in this example: Identifier) - that could be the subject of another email.

If nevertheless using directly the internal Anchor class is preferred, then the only thing needed for fixing the IllegalArgumentException is to replace:

    Anchor srsAnchor = new Anchor();
    srsAnchor.setHRef(new URI("http://www.opengis.net/def/crs/EPSG/0/4326";));
    srsAnchor.setTitle(new SimpleInternationalString("WGS84"));
    srsAnchor.setLabel("4326");

by:

    Anchor srsAnchor = new Anchor(new URI("http://www.opengis.net/def/crs/EPSG/0/4326";), 
"4326");
    srsAnchor.setTitle(new SimpleInternationalString("WGS84"));

Martin



--
*Emmanuel Blondel*
International Consultant | CEO
/Geographic Information Systems in Agronomy, Environment, Fishery & Marine Sciences/
41, Avenue du Vacayrial
81370 Saint Sulpice la Pointe, France
Tel: +33 (0) 6 45 97 87 52
Email: [email protected] <mailto:[email protected]>

Reply via email to