Search in sources :

Example 1 with JavaAttribute

use of org.eclipse.persistence.jaxb.xmlmodel.JavaAttribute in project eclipselink by eclipse-ee4j.

the class XMLProcessor method mergeJavaAttributes.

private static void mergeJavaAttributes(JavaAttributes attributes, JavaAttributes overrideAttributes, JavaType javaType) {
    List<JAXBElement<? extends JavaAttribute>> attributeList = attributes.getJavaAttribute();
    Map<String, JAXBElement> attributeMap = new HashMap<String, JAXBElement>(attributeList.size());
    for (JAXBElement next : attributeList) {
        attributeMap.put(((JavaAttribute) next.getValue()).getJavaAttribute(), next);
    }
    for (JAXBElement next : overrideAttributes.getJavaAttribute()) {
        JAXBElement existingAttribute = attributeMap.get(((JavaAttribute) next.getValue()).getJavaAttribute());
        if (existingAttribute != null) {
            attributes.getJavaAttribute().remove(existingAttribute);
        }
        attributes.getJavaAttribute().add(next);
    }
}
Also used : HashMap(java.util.HashMap) JAXBElement(jakarta.xml.bind.JAXBElement) JavaAttribute(org.eclipse.persistence.jaxb.xmlmodel.JavaAttribute)

Example 2 with JavaAttribute

use of org.eclipse.persistence.jaxb.xmlmodel.JavaAttribute in project eclipselink by eclipse-ee4j.

the class XMLProcessor method processJavaType.

/**
 * Process a given JavaType's attributes.
 */
private void processJavaType(JavaType javaType, TypeInfo typeInfo, NamespaceInfo nsInfo) {
    // process field/property overrides
    if (null != javaType.getJavaAttributes()) {
        List<String> processedPropertyNames = new ArrayList<String>();
        for (JAXBElement jaxbElement : javaType.getJavaAttributes().getJavaAttribute()) {
            JavaAttribute javaAttribute = (JavaAttribute) jaxbElement.getValue();
            Property originalProperty = typeInfo.getOriginalProperties().get(javaAttribute.getJavaAttribute());
            if (javaAttribute.getXmlAccessorType() != null) {
                originalProperty = processPropertyForAccessorType(typeInfo, javaAttribute, originalProperty);
            }
            if (originalProperty == null) {
                if (typeInfo.getXmlVirtualAccessMethods() != null) {
                    Property newProperty = new Property(this.aProcessor.getHelper());
                    newProperty.setPropertyName(javaAttribute.getJavaAttribute());
                    newProperty.setExtension(true);
                    String attributeType = null;
                    if (javaAttribute instanceof XmlElement) {
                        attributeType = ((XmlElement) javaAttribute).getType();
                    } else if (javaAttribute instanceof XmlAttribute) {
                        attributeType = ((XmlAttribute) javaAttribute).getType();
                    }
                    if (attributeType != null && attributeType.equals("DEFAULT")) {
                        newProperty.setType(jModelInput.getJavaModel().getClass(attributeType));
                    } else {
                        newProperty.setType(jModelInput.getJavaModel().getClass(Helper.STRING));
                    }
                    originalProperty = newProperty;
                    typeInfo.addProperty(javaAttribute.getJavaAttribute(), newProperty);
                } else {
                    getLogger().logWarning(JAXBMetadataLogger.NO_PROPERTY_FOR_JAVA_ATTRIBUTE, new Object[] { javaAttribute.getJavaAttribute(), javaType.getName() });
                    continue;
                }
            }
            boolean alreadyProcessed = processedPropertyNames.contains(javaAttribute.getJavaAttribute());
            Property propToProcess;
            // separate Map; otherwise, update the property as per usual
            if (alreadyProcessed) {
                propToProcess = (Property) originalProperty.clone();
            } else {
                propToProcess = typeInfo.getProperties().get(javaAttribute.getJavaAttribute());
            }
            processJavaAttribute(typeInfo, javaAttribute, propToProcess, nsInfo, javaType);
            // (Bug 346081) if discover a transient attribute apply same behavior as transient annotation and remove
            if (propToProcess.isTransient()) {
                typeInfo.getPropertyList().remove(propToProcess);
            }
            // property as-is and update the additionalProperties list on the owning TypeInfo
            if (alreadyProcessed) {
                List<Property> additionalProps = null;
                if (typeInfo.hasAdditionalProperties()) {
                    additionalProps = typeInfo.getAdditionalProperties().get(javaAttribute.getJavaAttribute());
                }
                if (additionalProps == null) {
                    additionalProps = new ArrayList<Property>();
                }
                additionalProps.add(propToProcess);
                typeInfo.getAdditionalProperties().put(javaAttribute.getJavaAttribute(), additionalProps);
            } else {
                // single mapping case; update the TypeInfo as per usual
                typeInfo.getProperties().put(javaAttribute.getJavaAttribute(), propToProcess);
                // keep track of processed property names
                processedPropertyNames.add(javaAttribute.getJavaAttribute());
            }
        }
    }
}
Also used : XmlAttribute(org.eclipse.persistence.jaxb.xmlmodel.XmlAttribute) ArrayList(java.util.ArrayList) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) JAXBElement(jakarta.xml.bind.JAXBElement) JavaAttribute(org.eclipse.persistence.jaxb.xmlmodel.JavaAttribute) XmlProperty(org.eclipse.persistence.jaxb.xmlmodel.XmlProperties.XmlProperty)

Example 3 with JavaAttribute

use of org.eclipse.persistence.jaxb.xmlmodel.JavaAttribute in project eclipselink by eclipse-ee4j.

the class OXMJavaClassImpl method getDeclaredFields.

/**
 * Return all of the declared <code>JavaFields</code> for this <code>JavaClass</code>.
 *
 * @return A <code>Collection</code> containing this <code>JavaClass'</code> <code>JavaFields</code>.
 */
@Override
public Collection<JavaField> getDeclaredFields() {
    List<JavaField> fieldsToReturn = new ArrayList<JavaField>();
    if (this.enumValues != null) {
        for (Iterator<String> iterator = this.enumValues.iterator(); iterator.hasNext(); ) {
            fieldsToReturn.add(new OXMJavaFieldImpl(iterator.next(), JAVA_LANG_OBJECT, this));
        }
    } else {
        JavaAttributes javaAttributes = this.javaType.getJavaAttributes();
        if (null != javaAttributes) {
            List<JAXBElement<? extends JavaAttribute>> fields = javaAttributes.getJavaAttribute();
            for (Iterator<JAXBElement<? extends JavaAttribute>> iterator = fields.iterator(); iterator.hasNext(); ) {
                JAXBElement<? extends JavaAttribute> jaxbElement = iterator.next();
                JavaAttribute att = jaxbElement.getValue();
                if (att instanceof XmlElement) {
                    XmlElement xme = (XmlElement) att;
                    String fieldName = xme.getJavaAttribute();
                    String fieldType = xme.getType();
                    fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
                } else if (att instanceof XmlElements) {
                    XmlElements xmes = (XmlElements) att;
                    String fieldName = xmes.getJavaAttribute();
                    String fieldType = JAVA_LANG_OBJECT;
                    fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
                } else if (att instanceof XmlElementRef) {
                    XmlElementRef xmer = (XmlElementRef) att;
                    String fieldName = xmer.getJavaAttribute();
                    String fieldType = xmer.getType();
                    fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
                } else if (att instanceof XmlAttribute) {
                    XmlAttribute xma = (XmlAttribute) att;
                    String fieldName = xma.getJavaAttribute();
                    String fieldType = xma.getType();
                    fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
                } else if (att instanceof XmlValue) {
                    XmlValue xmv = (XmlValue) att;
                    String fieldName = xmv.getJavaAttribute();
                    String fieldType = xmv.getType();
                    fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
                } else if (att instanceof XmlAnyElement) {
                    XmlAnyElement xmae = (XmlAnyElement) att;
                    String fieldName = xmae.getJavaAttribute();
                    String fieldType = JAVA_LANG_OBJECT;
                    fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
                } else if (att instanceof XmlAnyAttribute) {
                    XmlAnyAttribute xmaa = (XmlAnyAttribute) att;
                    String fieldName = xmaa.getJavaAttribute();
                    String fieldType = JAVA_UTIL_MAP;
                    fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
                } else if (att instanceof XmlJoinNodes) {
                    XmlJoinNodes xmjn = (XmlJoinNodes) att;
                    String fieldName = xmjn.getJavaAttribute();
                    String fieldType = xmjn.getType();
                    fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
                } else if (att instanceof XmlInverseReference) {
                    XmlInverseReference xmir = (XmlInverseReference) att;
                    String fieldName = xmir.getJavaAttribute();
                    String fieldType = xmir.getType();
                    fieldsToReturn.add(new OXMJavaFieldImpl(fieldName, fieldType, this));
                }
            }
        }
    }
    return fieldsToReturn;
}
Also used : XmlElementRef(org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef) XmlAttribute(org.eclipse.persistence.jaxb.xmlmodel.XmlAttribute) XmlAnyElement(org.eclipse.persistence.jaxb.xmlmodel.XmlAnyElement) ArrayList(java.util.ArrayList) XmlJoinNodes(org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes) JAXBElement(jakarta.xml.bind.JAXBElement) XmlInverseReference(org.eclipse.persistence.jaxb.xmlmodel.XmlInverseReference) JavaAttributes(org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes) XmlElements(org.eclipse.persistence.jaxb.xmlmodel.XmlElements) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) XmlAnyAttribute(org.eclipse.persistence.jaxb.xmlmodel.XmlAnyAttribute) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) XmlValue(org.eclipse.persistence.jaxb.xmlmodel.XmlValue) JavaAttribute(org.eclipse.persistence.jaxb.xmlmodel.JavaAttribute)

Aggregations

JAXBElement (jakarta.xml.bind.JAXBElement)3 JavaAttribute (org.eclipse.persistence.jaxb.xmlmodel.JavaAttribute)3 ArrayList (java.util.ArrayList)2 XmlAttribute (org.eclipse.persistence.jaxb.xmlmodel.XmlAttribute)2 XmlElement (org.eclipse.persistence.jaxb.xmlmodel.XmlElement)2 HashMap (java.util.HashMap)1 JavaField (org.eclipse.persistence.jaxb.javamodel.JavaField)1 JavaAttributes (org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes)1 XmlAnyAttribute (org.eclipse.persistence.jaxb.xmlmodel.XmlAnyAttribute)1 XmlAnyElement (org.eclipse.persistence.jaxb.xmlmodel.XmlAnyElement)1 XmlElementRef (org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef)1 XmlElements (org.eclipse.persistence.jaxb.xmlmodel.XmlElements)1 XmlInverseReference (org.eclipse.persistence.jaxb.xmlmodel.XmlInverseReference)1 XmlJoinNodes (org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes)1 XmlProperty (org.eclipse.persistence.jaxb.xmlmodel.XmlProperties.XmlProperty)1 XmlValue (org.eclipse.persistence.jaxb.xmlmodel.XmlValue)1