use of javax.xml.bind.annotation.XmlElement in project sis by apache.
the class DefaultContact method getPhone.
/**
* Returns telephone numbers at which the organization or individual may be contacted.
* This method returns the first telephone number associated to {@code TelephoneType.VOICE}
* or {@code TelephoneType.FACSIMILE FACSIMILE}.
*
* @return telephone numbers at which the organization or individual may be contacted, or {@code null}.
*
* @deprecated As of ISO 19115:2014, replaced by {@link #getPhones()}.
*/
@Override
@Deprecated
@Dependencies("getPhones")
@XmlElement(name = "phone", namespace = LegacyNamespaces.GMD)
public Telephone getPhone() {
Telephone phone = null;
if (FilterByVersion.LEGACY_METADATA.accept()) {
final Collection<Telephone> phones = getPhones();
if (phones != null) {
// May be null on marshalling.
CodeList<?> ignored = null;
for (final Telephone c : phones) {
if (c instanceof DefaultTelephone) {
String name;
final CodeList<?> type = ((DefaultTelephone) c).numberType;
if (type != null && ("VOICE".equals(name = type.name()) || "FACSIMILE".equals(name))) {
if (phone == null) {
phone = c;
}
} else if (ignored == null) {
ignored = type;
}
}
}
if (ignored != null) {
Context.warningOccured(Context.current(), DefaultContact.class, "getPhone", Messages.class, Messages.Keys.IgnoredPropertyAssociatedTo_1, ignored);
}
}
}
return phone;
}
use of javax.xml.bind.annotation.XmlElement in project siesta by cadenzauk.
the class FieldUtilTest method annotationPresent.
@Test
void annotationPresent() {
Field field = ClassUtil.getDeclaredField(ClassWithStringField.class, "stringField");
Optional<XmlElement> result = FieldUtil.annotation(XmlElement.class, field);
assertThat(result.isPresent(), is(true));
}
use of javax.xml.bind.annotation.XmlElement in project sis by apache.
the class DefaultSource method getSourceExtents.
/**
* Returns the information about the spatial, vertical and temporal extent of the source data.
* This method fetches the values from the {@linkplain #getScope() scope}.
*
* @return information about the extent of the source data.
*
* @deprecated As of ISO 19115:2014, moved to {@link DefaultScope#getExtents()}.
*/
@Override
@Deprecated
@Dependencies("getScope")
@XmlElement(name = "sourceExtent", namespace = LegacyNamespaces.GMD)
public Collection<Extent> getSourceExtents() {
if (FilterByVersion.LEGACY_METADATA.accept()) {
Scope scope = getScope();
if (!(scope instanceof DefaultScope)) {
if (isModifiable()) {
scope = new DefaultScope(scope);
this.scope = scope;
} else {
return Collections.singleton(scope.getExtent());
}
}
}
return null;
}
use of javax.xml.bind.annotation.XmlElement in project groovity by disney.
the class ModelXmlWriter method visitObjectField.
public void visitObjectField(String name, Object value) throws Exception {
if (inAttribute) {
writer.write(" ");
writer.write(name);
writer.write("=\"");
super.visitObjectField(name, value);
writer.write("\"");
return;
}
boolean writeTag = true;
Object currentObject = getCurrentObject();
MetaClass mc = GroovySystem.getMetaClassRegistry().getMetaClass(currentObject.getClass());
MetaProperty mp = mc.hasProperty(currentObject, name);
XmlAttribute xa = getAnnotation(mp, XmlAttribute.class);
if (xa != null) {
// attributes are written with open tag
return;
}
String listElementName = null;
if (value instanceof List || (value != null && value.getClass().isArray()) || (mp != null && (mp.getType().isArray() || List.class.isAssignableFrom(mp.getType())))) {
writeTag = false;
listElementName = name;
Map<Class<?>, String> listTypedNames = NO_NAMES;
XmlElementWrapper xew = getAnnotation(mp, XmlElementWrapper.class);
if (xew != null) {
writeTag = true;
if (!"##default".equals(xew.name())) {
name = xew.name();
}
name = getTagName(xew.namespace(), name);
}
XmlElement xe = getAnnotation(mp, XmlElement.class);
if (xe != null) {
if (!"##default".equals(xe.name())) {
listElementName = xe.name();
}
listElementName = getTagName(xe.namespace(), listElementName);
}
if (xe == null) {
XmlElements xes = getAnnotation(mp, XmlElements.class);
if (xes != null) {
listTypedNames = new HashMap<>();
for (int i = 0; i < xes.value().length; i++) {
XmlElement e = xes.value()[i];
listTypedNames.put(e.type(), e.name());
}
}
}
XmlList xel = getAnnotation(mp, XmlList.class);
if (xel != null) {
writeTag = true;
name = listElementName;
value = transformField(mp, value);
}
XmlMixed xm = getAnnotation(mp, XmlMixed.class);
if (xm != null) {
listTypedNames = SKIP_TAG;
}
listElementNames.push(listElementName);
listTypedElementNames.push(listTypedNames);
} else {
XmlElement xe = getAnnotation(mp, XmlElement.class);
if (xe != null) {
if (!"##default".equals(xe.name())) {
name = xe.name();
}
name = getTagName(xe.namespace(), name);
}
}
doDelimit = true;
if (writeTag) {
final String n = name;
writeTag(name, value, o -> {
try {
super.visitObjectField(n, o);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
});
} else {
super.visitObjectField(name, value);
}
if (listElementName != null) {
listElementNames.pop();
listTypedElementNames.pop();
}
}
use of javax.xml.bind.annotation.XmlElement in project groovity by disney.
the class ModelXmlWriter method getElementName.
protected String getElementName(Object o) {
Class<?> c = o.getClass();
String name = ELEMENT_NAME_CACHE.get(c);
if (name != null) {
return name;
}
XmlRootElement xre = c.getAnnotation(XmlRootElement.class);
String namespace = null;
if (xre != null) {
Package p = c.getPackage();
if (p != null) {
XmlSchema schema = p.getAnnotation(XmlSchema.class);
if (schema != null && schema.xmlns() != null) {
if (usedNamespacePrefixs == null) {
usedNamespacePrefixs = new HashMap<>();
}
for (XmlNs xns : schema.xmlns()) {
if (!usedNamespacePrefixs.containsKey(xns.namespaceURI())) {
usedNamespacePrefixs.put(xns.namespaceURI(), xns.prefix());
}
}
}
}
namespace = xre.namespace();
if (!"##default".equals(xre.name())) {
name = getTagName(namespace, xre.name());
}
} else {
XmlElement x = c.getAnnotation(XmlElement.class);
if (x != null) {
namespace = x.namespace();
if (!"##default".equals(x.name())) {
name = getTagName(namespace, x.name());
}
}
}
if (name == null) {
String oname = o.getClass().getSimpleName();
if (oname.endsWith("[]")) {
oname = oname.substring(0, oname.length() - 2);
}
if (Character.isUpperCase(oname.charAt(0))) {
char[] namechars = oname.toCharArray();
int stop = 1;
for (int i = 1; i < namechars.length; i++) {
if (Character.isUpperCase(namechars[i])) {
stop++;
continue;
}
if (stop > 1) {
stop--;
}
break;
}
for (int i = 0; i < stop; i++) {
namechars[i] = Character.toLowerCase(namechars[i]);
}
oname = new String(namechars);
}
name = getTagName(namespace, oname);
}
ELEMENT_NAME_CACHE.put(c, name);
return name;
}
Aggregations