Search in sources :

Example 56 with XmlElement

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;
}
Also used : Telephone(org.opengis.metadata.citation.Telephone) InternationalString(org.opengis.util.InternationalString) XmlElement(javax.xml.bind.annotation.XmlElement) Dependencies(org.apache.sis.internal.metadata.Dependencies)

Example 57 with XmlElement

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));
}
Also used : Field(java.lang.reflect.Field) XmlElement(javax.xml.bind.annotation.XmlElement) Test(org.junit.jupiter.api.Test)

Example 58 with XmlElement

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;
}
Also used : DefaultScope(org.apache.sis.metadata.iso.maintenance.DefaultScope) Scope(org.opengis.metadata.quality.Scope) MD_Scope(org.apache.sis.internal.jaxb.metadata.MD_Scope) DefaultScope(org.apache.sis.metadata.iso.maintenance.DefaultScope) XmlElement(javax.xml.bind.annotation.XmlElement) Dependencies(org.apache.sis.internal.metadata.Dependencies)

Example 59 with XmlElement

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();
    }
}
Also used : XmlAttribute(javax.xml.bind.annotation.XmlAttribute) XmlMixed(javax.xml.bind.annotation.XmlMixed) IOException(java.io.IOException) XmlList(javax.xml.bind.annotation.XmlList) XmlElements(javax.xml.bind.annotation.XmlElements) MetaClass(groovy.lang.MetaClass) XmlElement(javax.xml.bind.annotation.XmlElement) ArrayList(java.util.ArrayList) List(java.util.List) XmlList(javax.xml.bind.annotation.XmlList) MetaClass(groovy.lang.MetaClass) MetaProperty(groovy.lang.MetaProperty) XmlElementWrapper(javax.xml.bind.annotation.XmlElementWrapper)

Example 60 with XmlElement

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;
}
Also used : XmlRootElement(javax.xml.bind.annotation.XmlRootElement) XmlSchema(javax.xml.bind.annotation.XmlSchema) XmlNs(javax.xml.bind.annotation.XmlNs) XmlElement(javax.xml.bind.annotation.XmlElement)

Aggregations

XmlElement (javax.xml.bind.annotation.XmlElement)85 Test (org.junit.Test)31 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)29 Element (com.zimbra.common.soap.Element)28 JSONElement (com.zimbra.common.soap.Element.JSONElement)28 XMLElement (com.zimbra.common.soap.Element.XMLElement)28 FilterTest (com.zimbra.soap.mail.type.FilterTest)26 Field (java.lang.reflect.Field)17 ArrayList (java.util.ArrayList)14 Method (java.lang.reflect.Method)13 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)13 XmlElementWrapper (javax.xml.bind.annotation.XmlElementWrapper)13 XmlElements (javax.xml.bind.annotation.XmlElements)10 XmlElementRef (javax.xml.bind.annotation.XmlElementRef)8 KeyValuePair (com.zimbra.soap.type.KeyValuePair)7 Annotation (java.lang.annotation.Annotation)6 Type (java.lang.reflect.Type)6 ParameterizedType (java.lang.reflect.ParameterizedType)4 List (java.util.List)4 XmlList (javax.xml.bind.annotation.XmlList)4