Search in sources :

Example 21 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class Measure method setUOM.

/**
 * Sets the unit of measure. This method is invoked by JAXB at unmarshalling time.
 *
 * @param  uom  the unit of measure as a string.
 * @throws URISyntaxException if the {@code uom} looks like a URI, but can not be parsed.
 */
public void setUOM(String uom) throws URISyntaxException {
    final Context context = Context.current();
    unit = Context.converter(context).toUnit(context, uom);
}
Also used : Context(org.apache.sis.internal.jaxb.Context)

Example 22 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class Measure method getUOM.

/**
 * Implementation of {@link #getUOM()} as a static method for use by classes that define their own
 * {@code uom} attribute, instead of letting the {@code uom} attribute on the measurement value.
 * The main example is {@link org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis}.
 *
 * @param  unit        the unit to format.
 * @param  asXPointer  {@code true} if the units shall be formatted as {@code xpointer}.
 * @param  inAxis      {@code true} for a unit used in Coordinate System Axis definition.
 * @return the string representation of the unit of measure.
 */
public static String getUOM(final Unit<?> unit, final boolean asXPointer, final boolean inAxis) {
    if (!asXPointer) {
        final Integer code = Units.getEpsgCode(unit, inAxis);
        if (code != null) {
            return DefinitionURI.PREFIX + ":uom:" + Constants.EPSG + "::" + code;
        }
    }
    if (unit == null || unit.equals(Units.UNITY)) {
        return "";
    }
    final StringBuilder link;
    final Context context = Context.current();
    /*
         * We have not yet found an ISO 19115-3 URL for units of measurement.
         * If we find one, we should use a block like below:
         *
         * if (Context.isFlagSet(context, Context.LEGACY_METADATA)) {
         *     link = ... new URL ...
         * } else {
         *     link = current code
         * }
         */
    link = Context.schema(context, "gmd", Schemas.METADATA_ROOT_LEGACY);
    link.append(Schemas.UOM_PATH).append("#xpointer(//*[@gml:id='");
    try {
        UCUM.format(unit, link);
    } catch (IOException e) {
        // Should never happen since we wrote to a StringBuilder.
        throw new AssertionError(e);
    }
    return link.append("'])").toString();
}
Also used : Context(org.apache.sis.internal.jaxb.Context) IOException(java.io.IOException)

Example 23 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class MeasureList method setUOM.

/**
 * Sets the unit of measure. This method is invoked by JAXB at unmarshalling time.
 *
 * @param  uom  the unit of measure as a string.
 * @throws URISyntaxException if the {@code uom} looks like a URI, but can not be parsed.
 */
public void setUOM(String uom) throws URISyntaxException {
    final Context context = Context.current();
    unit = Context.converter(context).toUnit(context, uom);
}
Also used : Context(org.apache.sis.internal.jaxb.Context)

Example 24 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class LocalisedCharacterString method setLocale.

/**
 * Sets the locale language, using a string formatted as {@code #locale-xxx},
 * where {@code xxx} are the two or three letters representing the language.
 *
 * @param  localeId  the new locale.
 * @see <a href="https://issues.apache.org/jira/browse/SIS-137">SIS-137</a>
 */
public void setLocale(final String localeId) {
    if (localeId != null) {
        final Context context = Context.current();
        locale = Context.converter(context).toLocale(context, localeId.substring(localeId.indexOf('-') + 1));
    } else {
        locale = null;
    }
}
Also used : Context(org.apache.sis.internal.jaxb.Context)

Example 25 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class AbstractIdentifiedObjectTest method testIdentifierCollision.

/**
 * Tests two {@code AbstractIdentifiedObject} declaring the same identifier in the same XML document.
 * The {@code getID()} method should detect the collision and select different identifier.
 *
 * @since 0.7
 */
@Test
@DependsOnMethod("testWithManyIdentifiers")
public void testIdentifierCollision() {
    final Map<String, Object> properties = new HashMap<>(4);
    assertNull(properties.put("name", "GRS 1980"));
    assertNull(properties.put("identifiers", new NamedIdentifier(EPSG, "7019")));
    final AbstractIdentifiedObject o1 = new AbstractIdentifiedObject(properties);
    final AbstractIdentifiedObject o2 = new AbstractIdentifiedObject(properties);
    final AbstractIdentifiedObject o3 = new AbstractIdentifiedObject(properties);
    final AbstractIdentifiedObject o4 = new AbstractIdentifiedObject(properties);
    final Context context = new Context(0, null, null, null, null, null, null, null, null);
    try {
        final String c1, c2, c3, c4;
        assertEquals("o1", "epsg-7019", c1 = o1.getID());
        assertEquals("o2", "GRS1980", c2 = o2.getID());
        assertEquals("o3", "GRS1980-1", c3 = o3.getID());
        assertEquals("o4", "GRS1980-2", c4 = o4.getID());
        // Verify that values are remembered.
        assertSame("o1", c1, o1.getID());
        assertSame("o2", c2, o2.getID());
        assertSame("o3", c3, o3.getID());
        assertSame("o4", c4, o4.getID());
    } finally {
        context.finish();
    }
}
Also used : Context(org.apache.sis.internal.jaxb.Context) HashMap(java.util.HashMap) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

Context (org.apache.sis.internal.jaxb.Context)32 JAXBException (javax.xml.bind.JAXBException)7 XMLStreamException (javax.xml.stream.XMLStreamException)6 Locale (java.util.Locale)2 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 DefaultInternationalString (org.apache.sis.util.iso.DefaultInternationalString)2 Test (org.junit.Test)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 XmlAdapter (javax.xml.bind.annotation.adapters.XmlAdapter)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 CodeListUID (org.apache.sis.internal.jaxb.cat.CodeListUID)1 GO_CharacterString (org.apache.sis.internal.jaxb.gco.GO_CharacterString)1 Anchor (org.apache.sis.internal.jaxb.gcx.Anchor)1