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);
}
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();
}
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);
}
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;
}
}
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();
}
}
Aggregations