Search in sources :

Example 6 with XmlTransient

use of javax.xml.bind.annotation.XmlTransient in project entando-core by entando.

the class JAXBGuiFragment method getGuiFragment.

@XmlTransient
public GuiFragment getGuiFragment() {
    GuiFragment guiFragment = new GuiFragment();
    guiFragment.setCode(this.getCode());
    guiFragment.setWidgetTypeCode(this.getWidgetTypeCode());
    guiFragment.setPluginCode(this.getPluginCode());
    guiFragment.setGui(this.getGui());
    guiFragment.setDefaultGui(this.getDefaultGui());
    guiFragment.setLocked(this.isLocked());
    return guiFragment;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) XmlTransient(javax.xml.bind.annotation.XmlTransient)

Example 7 with XmlTransient

use of javax.xml.bind.annotation.XmlTransient in project zm-mailbox by Zimbra.

the class JaxbInfo method gatherInfo.

private void gatherInfo() {
    XmlAccessorType accessorType;
    rootElementName = null;
    XmlAccessType accessType = null;
    XmlRootElement rootE = jaxbClass.getAnnotation(XmlRootElement.class);
    if (rootE != null) {
        rootElementName = rootE.name();
    }
    xmlType = jaxbClass.getAnnotation(XmlType.class);
    accessorType = jaxbClass.getAnnotation(XmlAccessorType.class);
    if (accessorType == null) {
        Package pkg = jaxbClass.getPackage();
        accessorType = pkg.getAnnotation(XmlAccessorType.class);
    }
    if (accessorType != null) {
        accessType = accessorType.value();
    }
    if (accessType == null) {
        // Default value for JAXB
        accessType = XmlAccessType.PUBLIC_MEMBER;
    }
    Field[] fields = jaxbClass.getDeclaredFields();
    for (Field field : fields) {
        XmlTransient xmlTransient = field.getAnnotation(XmlTransient.class);
        if (xmlTransient != null) {
            continue;
        }
        Annotation[] fAnnots = field.getAnnotations();
        if ((fAnnots == null) || (fAnnots.length == 0)) {
            boolean autoFields = (accessType.equals(XmlAccessType.PUBLIC_MEMBER) || accessType.equals(XmlAccessType.FIELD));
            if (!autoFields) {
                continue;
            }
        }
        processFieldRelatedAnnotations(fAnnots, field.getName(), field.getGenericType());
    }
    Method[] methods = jaxbClass.getDeclaredMethods();
    for (Method method : methods) {
        XmlTransient xmlTransient = method.getAnnotation(XmlTransient.class);
        if (xmlTransient != null) {
            continue;
        }
        if (!isGetterOrSetter(method)) {
            continue;
        }
        Annotation[] mAnnots = method.getAnnotations();
        if ((mAnnots == null) || (mAnnots.length == 0)) {
            boolean autoGettersSetters = (accessType.equals(XmlAccessType.PUBLIC_MEMBER) || accessType.equals(XmlAccessType.PROPERTY));
            if (!autoGettersSetters) {
                continue;
            }
        }
        processFieldRelatedAnnotations(mAnnots, guessFieldNameFromGetterOrSetter(method.getName()), method.getGenericReturnType());
    }
}
Also used : XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Method(java.lang.reflect.Method) XmlTransient(javax.xml.bind.annotation.XmlTransient) Annotation(java.lang.annotation.Annotation) XmlType(javax.xml.bind.annotation.XmlType) Field(java.lang.reflect.Field) XmlAccessorType(javax.xml.bind.annotation.XmlAccessorType) XmlAccessType(javax.xml.bind.annotation.XmlAccessType)

Example 8 with XmlTransient

use of javax.xml.bind.annotation.XmlTransient in project tomee by apache.

the class JAXBContextInitializer method isMethodAccepted.

/**
 * Checks if the method is accepted as a JAXB property getter.
 */
static boolean isMethodAccepted(Method method, XmlAccessType accessType) {
    // We only accept non static property getters which are not marked @XmlTransient
    if (Modifier.isStatic(method.getModifiers()) || method.isAnnotationPresent(XmlTransient.class) || !Modifier.isPublic(method.getModifiers()) || "getClass".equals(method.getName())) {
        return false;
    }
    // must not have parameters and return type must not be void
    if (method.getReturnType() == Void.class || method.getReturnType() == Void.TYPE || method.getParameterTypes().length != 0 || (method.getDeclaringClass().equals(Throwable.class) && !("getMessage".equals(method.getName()))) || !(method.getName().startsWith("get") || method.getName().startsWith("is"))) {
        return false;
    }
    int beginIndex = 3;
    if (method.getName().startsWith("is")) {
        beginIndex = 2;
    }
    Method setter = null;
    try {
        setter = method.getDeclaringClass().getMethod("set" + method.getName().substring(beginIndex), new Class[] { method.getReturnType() });
    } catch (Exception e) {
    // getter, but no setter
    }
    if (setter != null) {
        if (setter.isAnnotationPresent(XmlTransient.class) || !Modifier.isPublic(setter.getModifiers())) {
            return false;
        }
    } else if (!Collection.class.isAssignableFrom(method.getReturnType()) && !Throwable.class.isAssignableFrom(method.getDeclaringClass())) {
        // not an Exception,
        return false;
    }
    if (accessType == XmlAccessType.NONE || accessType == XmlAccessType.FIELD) {
        return checkJaxbAnnotation(method.getAnnotations());
    }
    return true;
}
Also used : Collection(java.util.Collection) Method(java.lang.reflect.Method) XmlTransient(javax.xml.bind.annotation.XmlTransient)

Aggregations

XmlTransient (javax.xml.bind.annotation.XmlTransient)8 Method (java.lang.reflect.Method)3 Collection (java.util.Collection)2 LinkedList (java.util.LinkedList)2 StringTokenizer (java.util.StringTokenizer)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 XmlAccessType (javax.xml.bind.annotation.XmlAccessType)1 XmlAccessorType (javax.xml.bind.annotation.XmlAccessorType)1 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)1 XmlType (javax.xml.bind.annotation.XmlType)1 Permission (org.candlepin.auth.permissions.Permission)1 PermissionFactory (org.candlepin.auth.permissions.PermissionFactory)1 WinerysPropertiesDefinition (org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition)1 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)1