use of org.apache.sis.internal.jaxb.cat.CodeListUID in project sis by apache.
the class GO_CharacterString method getCodeList.
/**
* Returns the code list wrapped in a JAXB element, or {@code null} if the {@link #text} is not a wrapper for
* a code list. Only one of {@link #getValue()} and {@code getCodeList()} should return a non-null value.
*
* <div class="note"><b>Note:</b>
* we have to rely on a somewhat complicated mechanism because the code lists implementations in GeoAPI
* do not have JAXB annotations. If those annotations are added in a future GeoAPI implementation, then
* we could replace this mechanism by a simple property annotated with {@code XmlElementRef}.</div>
*
* @since 0.7
*/
@XmlAnyElement
@Workaround(library = "GeoAPI", version = "3.0")
private Object getCodeList() {
if (type != ENUM) {
return null;
}
final CodeList<?> code = Types.forCodeTitle(text);
final String name = Types.getListName(code);
/*
* The namespace has have various value like CIT, SRV, MDQ, MRI, MSR, LAN, etc.
* The real namespace is declared in the @XmlElement annotation of the getElement
* method in the JAXB adapter. We could use reflection, but we do not in order to
* avoid potential class loading issue and also because not all CodeList are in the
* same package.
*/
String namespace = Namespaces.guessForType(name);
if (namespace == null) {
namespace = XMLConstants.NULL_NS_URI;
}
return new JAXBElement<>(new QName(namespace, name), CodeListUID.class, new CodeListUID(Context.current(), code));
}
use of org.apache.sis.internal.jaxb.cat.CodeListUID in project sis by apache.
the class MD_CharacterSetCode method marshal.
/**
* Substitutes the code list by the adapter 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 adapter for the given code list.
*/
@Override
public final MD_CharacterSetCode marshal(final Charset value) {
final Context context = Context.current();
final ValueConverter converter = Context.converter(context);
final String code = converter.toCharsetCode(context, value);
if (code != null) {
final Locale locale = context.getLocale();
final MD_CharacterSetCode c = new MD_CharacterSetCode();
c.identifier = new CodeListUID(context, "MD_CharacterSetCode", code, (locale != null) ? converter.toLanguageCode(context, locale) : null, (locale != null) ? value.displayName(locale) : value.displayName());
return c;
}
return null;
}
use of org.apache.sis.internal.jaxb.cat.CodeListUID in project sis by apache.
the class UnsupportedCodeListAdapter method marshal.
/**
* Substitutes the code list by the adapter 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 adapter for the given code list.
*/
@Override
public final ValueType marshal(final CodeList<?> value) {
if (value == null) {
return null;
}
final String name = value.name();
final int length = name.length();
final StringBuilder buffer = new StringBuilder(length);
final String codeListValue = toIdentifier(name, buffer, false);
buffer.setLength(0);
return wrap(new CodeListUID(Context.current(), getCodeListName(), codeListValue, null, toIdentifier(name, buffer, true)));
}
use of org.apache.sis.internal.jaxb.cat.CodeListUID in project sis by apache.
the class Country method getLocale.
/**
* Returns the locale for the given language and country (which may be null), or {@code null} if none.
*
* @param context the current (un)marshalling context, or {@code null} if none.
* @param language the wrapper for the language value.
* @param country the wrapper for the country value.
* @param caller the class which is invoking this method, used only in case of warning.
* @return a locale which represents the language and country value.
*/
public static Locale getLocale(final Context context, final LanguageCode language, final Country country, final Class<?> caller) {
String code = null;
if (language != null) {
code = language.getLanguage();
}
if (country != null) {
final CodeListUID identifier = country.identifier;
final String c = CharSequences.trimWhitespaces((identifier != null ? identifier : country).toString());
if (c != null && !c.isEmpty()) {
if (code == null) {
code = "";
}
int i = code.indexOf('_');
if (i < 0) {
code = code + '_' + c;
} else {
final int length = code.length();
if (++i == code.length() || code.charAt(i) == '_') {
code = new StringBuilder().append(code, 0, i).append(c).append(code, i, length).toString();
} else if (!c.equals(CharSequences.token(code, i))) {
Context.warningOccured(context, caller, "unmarshal", Errors.class, Errors.Keys.IncompatiblePropertyValue_1, "country");
}
}
}
}
return Context.converter(context).toLocale(context, code);
}
Aggregations