use of org.apache.sis.internal.jaxb.lan.PT_FreeText in project sis by apache.
the class CharSequenceAdapter method wrap.
/**
* Converts a {@linkplain CharSequence character sequence} to the object to be marshalled
* in a XML file or stream.
*
* @param value the character representation of the object being marshalled.
* @return the wrapper for the given character sequence, or {@code null}.
*/
static GO_CharacterString wrap(CharSequence value) {
if (value instanceof String) {
// Slightly more efficient variant of this method.
return wrap(Context.current(), value, (String) value);
}
/*
* <mdb:someElement xsi:type="lan:PT_FreeText_PropertyType">
* <gco:CharacterString>...</gco:CharacterString>
* <lan:PT_FreeText>
* ... see PT_FreeText ...
* </lan:PT_FreeText>
* </mdb:someElement>
*/
if (value instanceof InternationalString) {
final PT_FreeText ft = PT_FreeText.create((InternationalString) value);
if (ft != null) {
return ft;
}
}
/*
* Invoking (indirectly) CharSequence.subSequence(…) may change the kind of object.
* We know that Anchor is safe, and that most InternationalString implementations
* lost the localized strings. This is why we trim the white spaces only here.
*/
value = CharSequences.trimWhitespaces(value);
if (value == null || value.length() == 0) {
return null;
}
/*
* Substitute <gco:CharacterString> by <gcx:Anchor> if a linkage is found.
*/
if (!(value instanceof Anchor)) {
final String key = CharSequences.trimWhitespaces(value.toString());
if (key != null && !key.isEmpty()) {
final Context context = Context.current();
final XLink linkage = Context.resolver(context).anchor(context, value, key);
if (linkage != null) {
if (linkage instanceof Anchor) {
value = (Anchor) linkage;
} else {
value = new Anchor(linkage, key);
}
}
}
}
/*
* At this stage, the value (typically a String or InternationalString) may
* have been replaced by an Anchor. The output will be one of the following:
*
* ┌──────────────────────────────────────────────────┬────────────────────────────────┐
* │ <mdb:someElement> │ <mdb:someElement> │
* │ <gco:CharacterString>...</gco:CharacterString> │ <gcx:Anchor>...</gcx:Anchor> │
* │ </mdb:someElement> │ </mdb:someElement> │
* └──────────────────────────────────────────────────┴────────────────────────────────┘
*/
return new GO_CharacterString(value);
}
Aggregations