Search in sources :

Example 1 with XmlProperties

use of org.eclipse.persistence.oxm.annotations.XmlProperties in project eclipselink by eclipse-ee4j.

the class AnnotationsProcessor method processPropertyAnnotations.

private void processPropertyAnnotations(TypeInfo info, JavaClass cls, JavaHasAnnotations propertyElement, Property property) {
    // Check for mixed context
    if (helper.isAnnotationPresent(propertyElement, XmlMixed.class)) {
        info.setMixed(true);
        property.setMixedContent(true);
        findAndProcessObjectFactory(cls);
    }
    if (helper.isAnnotationPresent(propertyElement, XmlInverseReference.class)) {
        XmlInverseReference inverseReference = (XmlInverseReference) helper.getAnnotation(propertyElement, XmlInverseReference.class);
        property.setInverseReferencePropertyName(inverseReference.mappedBy());
        TypeInfo targetInfo = this.getTypeInfos().get(property.getActualType().getName());
        if (targetInfo != null && targetInfo.getXmlAccessType() == XmlAccessType.PROPERTY) {
            String propName = property.getPropertyName();
            propName = Character.toUpperCase(propName.charAt(0)) + propName.substring(1);
            property.setInverseReferencePropertyGetMethodName(GET_STR + propName);
            property.setInverseReferencePropertySetMethodName(SET_STR + propName);
        }
        property.setInverseReference(true, helper.isAnnotationPresent(propertyElement, XmlElement.class));
    }
    processXmlJavaTypeAdapter(property, info, cls);
    if (helper.isAnnotationPresent(propertyElement, XmlAttachmentRef.class) && areEquals(property.getActualType(), JAVAX_ACTIVATION_DATAHANDLER)) {
        property.setIsSwaAttachmentRef(true);
        property.setSchemaType(Constants.SWA_REF_QNAME);
    }
    processXmlElement(property, info);
    // JavaClass ptype = property.getActualType();
    if (!(property.isSwaAttachmentRef()) && isMtomAttachment(property)) {
        property.setIsMtomAttachment(true);
        property.setSchemaType(Constants.BASE_64_BINARY_QNAME);
    }
    if (helper.isAnnotationPresent(propertyElement, XmlMimeType.class)) {
        property.setMimeType(((XmlMimeType) helper.getAnnotation(propertyElement, XmlMimeType.class)).value());
    }
    // non-binary data type won't have any affect
    if (helper.isAnnotationPresent(propertyElement, XmlInlineBinaryData.class) || info.isBinaryDataToBeInlined()) {
        property.setisInlineBinaryData(true);
    }
    // later use:
    if (helper.isAnnotationPresent(propertyElement, XmlSchemaType.class)) {
        XmlSchemaType schemaType = (XmlSchemaType) helper.getAnnotation(propertyElement, XmlSchemaType.class);
        QName schemaTypeQname = new QName(schemaType.namespace(), schemaType.name());
        property.setSchemaType(schemaTypeQname);
    }
    if (helper.isAnnotationPresent(propertyElement, XmlAttribute.class)) {
        property.setIsAttribute(true);
        property.setIsRequired(((XmlAttribute) helper.getAnnotation(propertyElement, XmlAttribute.class)).required());
    }
    if (helper.isAnnotationPresent(propertyElement, XmlAnyAttribute.class)) {
        if (info.isSetAnyAttributePropertyName() && !info.getAnyAttributePropertyName().equals(property.getPropertyName())) {
            throw org.eclipse.persistence.exceptions.JAXBException.multipleAnyAttributeMapping(cls.getName());
        }
        if (!helper.isMapType(property.getType())) {
            throw org.eclipse.persistence.exceptions.JAXBException.anyAttributeOnNonMap(property.getPropertyName());
        }
        property.setIsAnyAttribute(true);
        info.setAnyAttributePropertyName(property.getPropertyName());
    }
    // Make sure XmlElementWrapper annotation is on a collection or array
    if (helper.isAnnotationPresent(propertyElement, XmlElementWrapper.class)) {
        XmlElementWrapper wrapper = (XmlElementWrapper) helper.getAnnotation(propertyElement, XmlElementWrapper.class);
        org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper xmlEltWrapper = new org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper();
        String wrapperName = wrapper.name();
        if (wrapperName.equals(XMLProcessor.DEFAULT)) {
            wrapperName = info.getXmlNameTransformer().transformElementName(property.getPropertyName());
        }
        xmlEltWrapper.setName(wrapperName);
        xmlEltWrapper.setNamespace(wrapper.namespace());
        xmlEltWrapper.setNillable(wrapper.nillable());
        xmlEltWrapper.setRequired(wrapper.required());
        property.setXmlElementWrapper(xmlEltWrapper);
    }
    if (helper.isAnnotationPresent(propertyElement, XmlList.class)) {
        // Make sure XmlList annotation is on a collection or array
        if (!helper.isCollectionType(property.getType()) && !property.getType().isArray()) {
            throw JAXBException.invalidList(property.getPropertyName());
        }
        property.setIsXmlList(true);
    }
    if (helper.isAnnotationPresent(propertyElement, XmlValue.class)) {
        property.setIsXmlValue(true);
        info.setXmlValueProperty(property);
    }
    if (helper.isAnnotationPresent(propertyElement, XmlReadOnly.class)) {
        property.setReadOnly(true);
    }
    if (helper.isAnnotationPresent(propertyElement, XmlWriteOnly.class)) {
        property.setWriteOnly(true);
    }
    if (helper.isAnnotationPresent(propertyElement, XmlCDATA.class)) {
        property.setCdata(true);
    }
    if (helper.isAnnotationPresent(propertyElement, XmlAccessMethods.class)) {
        XmlAccessMethods accessMethods = (XmlAccessMethods) helper.getAnnotation(propertyElement, XmlAccessMethods.class);
        if (!(accessMethods.getMethodName().equals(EMPTY_STRING))) {
            property.setGetMethodName(accessMethods.getMethodName());
        }
        if (!(accessMethods.setMethodName().equals(EMPTY_STRING))) {
            property.setSetMethodName(accessMethods.setMethodName());
        }
        if (!(property.isMethodProperty())) {
            property.setMethodProperty(true);
        }
    }
    // handle user properties
    if (helper.isAnnotationPresent(propertyElement, XmlProperties.class)) {
        XmlProperties xmlProperties = (XmlProperties) helper.getAnnotation(propertyElement, XmlProperties.class);
        Map<Object, Object> propertiesMap = createUserPropertiesMap(xmlProperties.value());
        property.setUserProperties(propertiesMap);
    } else if (helper.isAnnotationPresent(propertyElement, XmlProperty.class)) {
        XmlProperty xmlProperty = (XmlProperty) helper.getAnnotation(propertyElement, XmlProperty.class);
        Map<Object, Object> propertiesMap = createUserPropertiesMap(new XmlProperty[] { xmlProperty });
        property.setUserProperties(propertiesMap);
    }
    // handle XmlKey
    if (helper.isAnnotationPresent(propertyElement, XmlKey.class)) {
        info.addXmlKeyProperty(property);
    }
    // handle XmlJoinNode(s)
    processXmlJoinNodes(property);
    processXmlNullPolicy(property, cls, info);
    // Handle XmlLocation
    JavaHasAnnotations elem = propertyElement;
    if (helper.isAnnotationPresent(elem, XmlLocation.class) || helper.isAnnotationPresent(elem, CompilerHelper.XML_LOCATION_ANNOTATION_CLASS) || helper.isAnnotationPresent(elem, CompilerHelper.OLD_XML_LOCATION_ANNOTATION_CLASS) || helper.isAnnotationPresent(elem, CompilerHelper.INTERNAL_XML_LOCATION_ANNOTATION_CLASS)) {
        if (!helper.getJavaClass(Constants.LOCATOR_CLASS).isAssignableFrom(property.getType())) {
            throw JAXBException.invalidXmlLocation(property.getPropertyName(), property.getType().getName());
        }
        property.setXmlLocation(true);
    }
}
Also used : XmlAccessMethods(org.eclipse.persistence.oxm.annotations.XmlAccessMethods) XmlProperties(org.eclipse.persistence.oxm.annotations.XmlProperties) XmlProperty(org.eclipse.persistence.oxm.annotations.XmlProperty) QName(javax.xml.namespace.QName) XmlLocation(org.eclipse.persistence.oxm.annotations.XmlLocation) XmlSchemaType(jakarta.xml.bind.annotation.XmlSchemaType) XmlInverseReference(org.eclipse.persistence.oxm.annotations.XmlInverseReference) XmlAttachmentRef(jakarta.xml.bind.annotation.XmlAttachmentRef) XmlElement(jakarta.xml.bind.annotation.XmlElement) XmlInlineBinaryData(jakarta.xml.bind.annotation.XmlInlineBinaryData) Map(java.util.Map) HashMap(java.util.HashMap) XmlElementWrapper(jakarta.xml.bind.annotation.XmlElementWrapper) JavaHasAnnotations(org.eclipse.persistence.jaxb.javamodel.JavaHasAnnotations)

Example 2 with XmlProperties

use of org.eclipse.persistence.oxm.annotations.XmlProperties in project eclipselink by eclipse-ee4j.

the class AnnotationsProcessor method preBuildTypeInfo.

/**
 * Process class level annotations only. It is assumed that a call to init()
 * has been made prior to calling this method. After the types created via
 * this method have been modified (if necessary) postBuildTypeInfo and
 * processJavaClasses should be called to finish processing.
 */
public Map<String, TypeInfo> preBuildTypeInfo(JavaClass[] javaClasses) {
    for (JavaClass javaClass : javaClasses) {
        String qualifiedName = javaClass.getQualifiedName();
        TypeInfo info = typeInfos.get(qualifiedName);
        if (javaClass.isArray() || (info != null && info.isPreBuilt()) || !shouldGenerateTypeInfo(javaClass) || isXmlRegistry(javaClass)) {
            continue;
        }
        if (javaClass.isEnum()) {
            info = new EnumTypeInfo(helper, javaClass);
        } else {
            info = new TypeInfo(helper, javaClass);
        }
        info.setJavaClassName(qualifiedName);
        info.setPreBuilt(true);
        // handle @XmlTransient
        if (helper.isAnnotationPresent(javaClass, XmlTransient.class)) {
            info.setXmlTransient(true);
        }
        // handle @XmlElementNillable
        processXmlElementNillable(javaClass, info);
        // handle @XmlExtensible
        processXmlExtensible(javaClass, info);
        // handle @XmlInlineBinaryData
        if (helper.isAnnotationPresent(javaClass, XmlInlineBinaryData.class)) {
            info.setInlineBinaryData(true);
        }
        // handle @NamedObjectGraph
        processNamedObjectGraphs(javaClass, info);
        // handle @XmlRootElement
        processXmlRootElement(javaClass, info);
        // handle @XmlSeeAlso
        processXmlSeeAlso(javaClass, info);
        PackageInfo packageInfo = getPackageInfoForPackage(javaClass);
        if (packageInfo != null && packageInfo.getPackageLevelAdaptersByClass().size() > 0) {
            for (String adapterClass : packageInfo.getPackageLevelAdaptersByClass().keySet()) {
                JavaClass boundType = packageInfo.getPackageLevelAdaptersByClass().get(adapterClass);
                info.getPackageLevelAdaptersByClass().put(adapterClass, boundType);
            }
        }
        NamespaceInfo namespaceInfo = packageInfo.getNamespaceInfo();
        // handle @XmlType
        preProcessXmlType(javaClass, info, namespaceInfo);
        // handle @XmlAccessorType
        preProcessXmlAccessorType(javaClass, info, namespaceInfo);
        // handle @XmlAccessorOrder
        preProcessXmlAccessorOrder(javaClass, info, namespaceInfo);
        // handle package level @XmlJavaTypeAdapters
        processPackageLevelAdapters(javaClass, info);
        // handle Accessor Factory
        processAccessorFactory(javaClass, info);
        // handle class level @XmlJavaTypeAdapters
        processClassLevelAdapters(javaClass, info);
        // handle descriptor customizer
        preProcessCustomizer(javaClass, info);
        // handle package level @XmlSchemaType(s)
        processSchemaTypes(javaClass, info);
        // handle class extractor
        if (helper.isAnnotationPresent(javaClass, XmlClassExtractor.class)) {
            XmlClassExtractor classExtractor = (XmlClassExtractor) helper.getAnnotation(javaClass, XmlClassExtractor.class);
            info.setClassExtractorName(classExtractor.value().getName());
        }
        // handle user properties
        if (helper.isAnnotationPresent(javaClass, XmlProperties.class)) {
            XmlProperties xmlProperties = (XmlProperties) helper.getAnnotation(javaClass, XmlProperties.class);
            Map<Object, Object> propertiesMap = createUserPropertiesMap(xmlProperties.value());
            info.setUserProperties(propertiesMap);
        } else if (helper.isAnnotationPresent(javaClass, XmlProperty.class)) {
            XmlProperty xmlProperty = (XmlProperty) helper.getAnnotation(javaClass, XmlProperty.class);
            Map<Object, Object> propertiesMap = createUserPropertiesMap(new XmlProperty[] { xmlProperty });
            info.setUserProperties(propertiesMap);
        }
        // handle class indicator field name
        if (helper.isAnnotationPresent(javaClass, XmlDiscriminatorNode.class)) {
            XmlDiscriminatorNode xmlDiscriminatorNode = (XmlDiscriminatorNode) helper.getAnnotation(javaClass, XmlDiscriminatorNode.class);
            info.setXmlDiscriminatorNode(xmlDiscriminatorNode.value());
        }
        // handle class indicator
        if (helper.isAnnotationPresent(javaClass, XmlDiscriminatorValue.class)) {
            XmlDiscriminatorValue xmlDiscriminatorValue = (XmlDiscriminatorValue) helper.getAnnotation(javaClass, XmlDiscriminatorValue.class);
            info.setXmlDiscriminatorValue(xmlDiscriminatorValue.value());
        }
        typeInfoClasses.add(javaClass);
        typeInfos.put(info.getJavaClassName(), info);
    }
    return typeInfos;
}
Also used : XmlProperties(org.eclipse.persistence.oxm.annotations.XmlProperties) XmlProperty(org.eclipse.persistence.oxm.annotations.XmlProperty) XmlDiscriminatorValue(org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue) XmlClassExtractor(org.eclipse.persistence.oxm.annotations.XmlClassExtractor) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) Map(java.util.Map) HashMap(java.util.HashMap) XmlDiscriminatorNode(org.eclipse.persistence.oxm.annotations.XmlDiscriminatorNode)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 XmlProperties (org.eclipse.persistence.oxm.annotations.XmlProperties)2 XmlProperty (org.eclipse.persistence.oxm.annotations.XmlProperty)2 XmlAttachmentRef (jakarta.xml.bind.annotation.XmlAttachmentRef)1 XmlElement (jakarta.xml.bind.annotation.XmlElement)1 XmlElementWrapper (jakarta.xml.bind.annotation.XmlElementWrapper)1 XmlInlineBinaryData (jakarta.xml.bind.annotation.XmlInlineBinaryData)1 XmlSchemaType (jakarta.xml.bind.annotation.XmlSchemaType)1 QName (javax.xml.namespace.QName)1 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)1 JavaHasAnnotations (org.eclipse.persistence.jaxb.javamodel.JavaHasAnnotations)1 XmlAccessMethods (org.eclipse.persistence.oxm.annotations.XmlAccessMethods)1 XmlClassExtractor (org.eclipse.persistence.oxm.annotations.XmlClassExtractor)1 XmlDiscriminatorNode (org.eclipse.persistence.oxm.annotations.XmlDiscriminatorNode)1 XmlDiscriminatorValue (org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue)1 XmlInverseReference (org.eclipse.persistence.oxm.annotations.XmlInverseReference)1 XmlLocation (org.eclipse.persistence.oxm.annotations.XmlLocation)1