Search in sources :

Example 1 with JavaAttributes

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

the class DynamicXMLMetadataSource method createJAXBType.

/**
 * Create a javaType to be used by JAXB to map a particular class.
 * For static classes, JAXB annotations, xml and defaults will be used to map the class.
 * For Dynamic classes we create properties for each JPA mapping on the class
 * thing we create is a
 */
private JavaType createJAXBType(ClassDescriptor classDescriptor, ObjectFactory objectFactory) {
    JavaType javaType = new JavaType();
    String alias = classDescriptor.getAlias();
    if (alias == null || alias.isEmpty()) {
        alias = classDescriptor.getJavaClass().getSimpleName();
    }
    javaType.setName(alias);
    javaType.setJavaAttributes(new JavaAttributes());
    boolean isDynamic = DynamicEntity.class.isAssignableFrom(classDescriptor.getJavaClass());
    for (DatabaseMapping ormMapping : classDescriptor.getMappings()) {
        JAXBElement<XmlElement> element = createJAXBProperty(ormMapping, objectFactory, javaType, isDynamic);
        if (element != null) {
            javaType.getJavaAttributes().getJavaAttribute().add(element);
        }
    }
    // Embeddables don't need Rest adapters, return if the classDescriptor is an aggregate descriptor.
    if (classDescriptor.isAggregateDescriptor()) {
        return javaType;
    }
    // Set an adapter that is a subclass of ReferenceAdapter that can adapt the class to create a link for
    // the persistence_href field that has been weaved in.
    String name = RestAdapterClassWriter.constructClassNameForReferenceAdapter(classDescriptor.getJavaClassName());
    XmlJavaTypeAdapter adapter = new XmlJavaTypeAdapter();
    adapter.setValue(name);
    adapter.setValueType(classDescriptor.getJavaClassName());
    adapter.setType(classDescriptor.getJavaClassName());
    javaType.setXmlJavaTypeAdapter(adapter);
    return javaType;
}
Also used : JavaType(org.eclipse.persistence.jaxb.xmlmodel.JavaType) JavaAttributes(org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes) XmlJavaTypeAdapter(org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 2 with JavaAttributes

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

the class DynamicXmlV2MetadataSource method createJAXBType.

/**
 * Create a javaType to be used by JAXB to map a particular class.
 */
private JavaType createJAXBType(ClassDescriptor classDescriptor, ObjectFactory objectFactory) {
    JavaType javaType = new JavaType();
    String alias = classDescriptor.getAlias();
    if (alias == null || alias.isEmpty()) {
        alias = classDescriptor.getJavaClass().getSimpleName();
    }
    javaType.setName(alias);
    final JavaAttributes javaAttributes = new JavaAttributes();
    for (DatabaseMapping ormMapping : classDescriptor.getMappings()) {
        JAXBElement<XmlElement> element = null;
        if (ormMapping instanceof DirectCollectionMapping) {
            // Direct mapping -> no adapter
            continue;
        } else if (ormMapping.isCollectionMapping()) {
            // This is a collection mapping -> create collection adapter
            element = createCollectionProperty(ormMapping, objectFactory);
        } else if (ForeignReferenceMapping.class.isAssignableFrom(ormMapping.getClass())) {
            // FK mapping -> create reference adapter
            element = createProperty((ForeignReferenceMapping) ormMapping, objectFactory);
        }
        if (element != null) {
            javaAttributes.getJavaAttribute().add(element);
        }
    }
    if (!javaAttributes.getJavaAttribute().isEmpty()) {
        javaType.setJavaAttributes(javaAttributes);
    }
    return javaType;
}
Also used : JavaType(org.eclipse.persistence.jaxb.xmlmodel.JavaType) JavaAttributes(org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes) ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) DirectCollectionMapping(org.eclipse.persistence.mappings.DirectCollectionMapping)

Example 3 with JavaAttributes

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

the class XMLProcessor method mergeJavaType.

private static void mergeJavaType(JavaType existingType, JavaType next) {
    if (next.isSetXmlAccessorOrder()) {
        existingType.setXmlAccessorOrder(next.getXmlAccessorOrder());
    }
    if (next.isSetXmlAccessorType()) {
        existingType.setXmlAccessorType(next.getXmlAccessorType());
    }
    if (next.isSetXmlInlineBinaryData()) {
        existingType.setXmlInlineBinaryData(next.isXmlInlineBinaryData());
    }
    if (next.isSetXmlTransient()) {
        existingType.setXmlTransient(next.isXmlInlineBinaryData());
    }
    if (next.getXmlRootElement() != null) {
        existingType.setXmlRootElement(next.getXmlRootElement());
    }
    if (existingType.getXmlProperties() == null) {
        existingType.setXmlProperties(next.getXmlProperties());
    } else if (next.getXmlProperties() != null) {
        existingType.getXmlProperties().getXmlProperty().addAll(next.getXmlProperties().getXmlProperty());
    }
    if (next.getXmlType() != null) {
        existingType.setXmlType(next.getXmlType());
    }
    existingType.getXmlSeeAlso().addAll(next.getXmlSeeAlso());
    JavaAttributes attributes = existingType.getJavaAttributes();
    JavaAttributes overrideAttributes = next.getJavaAttributes();
    if (attributes == null) {
        existingType.setJavaAttributes(overrideAttributes);
    } else if (overrideAttributes != null) {
        mergeJavaAttributes(attributes, overrideAttributes, existingType);
    }
}
Also used : JavaAttributes(org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes)

Example 4 with JavaAttributes

use of org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes 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)

Example 5 with JavaAttributes

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

the class XMLBindingsPopulatedTestCases method getControlObject.

@Override
protected Object getControlObject() {
    XmlBindings xmlBindings = new XmlBindings();
    xmlBindings.setPackageName("test.model");
    xmlBindings.setXmlAccessorType(XmlAccessType.PUBLIC_MEMBER);
    xmlBindings.setXmlAccessorOrder(org.eclipse.persistence.jaxb.xmlmodel.XmlAccessOrder.ALPHABETICAL);
    XmlEnums enums = new XmlEnums();
    XmlEnum e1 = new XmlEnum();
    e1.setJavaEnum("A");
    e1.setValue("A_Value");
    XmlEnum e2 = new XmlEnum();
    e2.setJavaEnum("B");
    e2.setValue("B_Value");
    enums.getXmlEnum().add(e1);
    enums.getXmlEnum().add(e2);
    xmlBindings.setXmlEnums(enums);
    xmlBindings.setXmlNameTransformer("test.someNameTransformer");
    XmlSchema xmlSchema = new XmlSchema();
    xmlSchema.setAttributeFormDefault(XmlNsForm.UNQUALIFIED);
    xmlSchema.setElementFormDefault(XmlNsForm.UNQUALIFIED);
    xmlSchema.setLocation("someLocation");
    xmlSchema.setNamespace("testnamespace");
    xmlBindings.setXmlSchema(xmlSchema);
    XmlSchemaTypes xmlSchemaTypes = new XmlSchemaTypes();
    XmlSchemaType xmlSchemaType = new XmlSchemaType();
    xmlSchemaType.setName("someSchemaType");
    xmlSchemaType.setNamespace("someSchemaTypeNamespace");
    xmlSchemaType.setType("someSchemaType");
    XmlSchemaType xmlSchemaType2 = new XmlSchemaType();
    xmlSchemaType2.setName("someSchemaType2");
    xmlSchemaType2.setNamespace("someSchemaTypeNamespace2");
    xmlSchemaType2.setType("someSchemaType2");
    xmlSchemaTypes.getXmlSchemaType().add(xmlSchemaType);
    xmlSchemaTypes.getXmlSchemaType().add(xmlSchemaType2);
    xmlBindings.setXmlSchemaTypes(xmlSchemaTypes);
    xmlBindings.setXmlMappingMetadataComplete(Boolean.FALSE);
    XmlRegistries xmlRegistries = new XmlRegistries();
    XmlRegistry r1 = new XmlRegistry();
    r1.setName("someRegistry");
    xmlRegistries.getXmlRegistry().add(r1);
    xmlBindings.setXmlRegistries(xmlRegistries);
    XmlJavaTypeAdapters xmlJavaTypeAdapters = new XmlJavaTypeAdapters();
    XmlJavaTypeAdapter a1 = new XmlJavaTypeAdapter();
    a1.setType("someAdapterType");
    a1.setValue("someAdapterValue");
    a1.setValueType("somValueType");
    a1.setJavaAttribute("someJavaAttribute");
    xmlJavaTypeAdapters.getXmlJavaTypeAdapter().add(a1);
    xmlBindings.setXmlJavaTypeAdapters(xmlJavaTypeAdapters);
    JavaTypes types = new JavaTypes();
    JavaType javaType = new JavaType();
    javaType.setName("myType");
    javaType.setXmlTransient(Boolean.FALSE);
    javaType.setXmlAccessorOrder(org.eclipse.persistence.jaxb.xmlmodel.XmlAccessOrder.ALPHABETICAL);
    XmlProperties xmlProperties = new XmlProperties();
    XmlProperty p1 = new XmlProperty();
    p1.setName("prop1");
    p1.setValue("propValue");
    p1.setValueType("propValueType");
    xmlProperties.getXmlProperty().add(p1);
    javaType.setXmlProperties(xmlProperties);
    javaType.setXmlDiscriminatorNode("descriminator node");
    javaType.setXmlDiscriminatorValue("discriminator value");
    XmlClassExtractor extractor = new XmlClassExtractor();
    extractor.setClazz("a.b.c.someClass");
    javaType.setXmlClassExtractor(extractor);
    javaType.setXmlInlineBinaryData(Boolean.FALSE);
    XmlRootElement root = new XmlRootElement();
    root.setName("someRoot");
    root.setNamespace("someNamespace");
    javaType.setXmlRootElement(root);
    XmlType xmlType = new XmlType();
    xmlType.setFactoryClass("somepackage.someFactoryclass");
    xmlType.setName("someName");
    xmlType.setFactoryMethod("someMethod");
    xmlType.getPropOrder().add("p2");
    xmlType.getPropOrder().add("p1");
    javaType.setXmlType(xmlType);
    JavaAttributes javaAttributes = new JavaAttributes();
    XmlElement javaAttribute = new XmlElement();
    javaAttribute.setName("elementName");
    javaAttribute.setJavaAttribute("theJavaAttributeValue");
    JAXBElement<XmlElement> jbe = new JAXBElement<XmlElement>(new QName("http://www.eclipse.org/eclipselink/xsds/persistence/oxm", "xml-element"), XmlElement.class, javaAttribute);
    XmlElement javaAttribute2 = new XmlElement();
    javaAttribute2.setName("elementName2");
    javaAttribute2.setJavaAttribute("theJavaAttributeValue2");
    JAXBElement<XmlElement> jbe2 = new JAXBElement<XmlElement>(new QName("http://www.eclipse.org/eclipselink/xsds/persistence/oxm", "xml-element"), XmlElement.class, javaAttribute2);
    XmlAttribute javaAttribute3 = new XmlAttribute();
    javaAttribute3.setContainerType("someContainerType");
    javaAttribute3.setJavaAttribute("javaAttribute");
    javaAttribute3.setNamespace("somenamespace");
    javaAttribute3.setName("attributename1");
    javaAttribute3.setReadOnly(Boolean.TRUE);
    javaAttribute3.setRequired(Boolean.TRUE);
    JAXBElement<XmlAttribute> jbe3 = new JAXBElement<XmlAttribute>(new QName("http://www.eclipse.org/eclipselink/xsds/persistence/oxm", "xml-attribute"), XmlAttribute.class, javaAttribute3);
    javaAttributes.getJavaAttribute().add(jbe);
    javaAttributes.getJavaAttribute().add(jbe3);
    javaAttributes.getJavaAttribute().add(jbe2);
    javaType.setJavaAttributes(javaAttributes);
    types.getJavaType().add(javaType);
    xmlBindings.setJavaTypes(types);
    return xmlBindings;
}
Also used : JavaTypes(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.JavaTypes) XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) XmlEnums(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.XmlEnums) XmlRootElement(org.eclipse.persistence.jaxb.xmlmodel.XmlRootElement) XmlProperties(org.eclipse.persistence.jaxb.xmlmodel.XmlProperties) XmlAttribute(org.eclipse.persistence.jaxb.xmlmodel.XmlAttribute) XmlProperty(org.eclipse.persistence.jaxb.xmlmodel.XmlProperties.XmlProperty) QName(javax.xml.namespace.QName) XmlJavaTypeAdapter(org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter) JAXBElement(jakarta.xml.bind.JAXBElement) XmlSchemaType(org.eclipse.persistence.jaxb.xmlmodel.XmlSchemaType) XmlRegistry(org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry) XmlSchemaTypes(org.eclipse.persistence.jaxb.xmlmodel.XmlSchemaTypes) XmlEnum(org.eclipse.persistence.jaxb.xmlmodel.XmlEnum) XmlClassExtractor(org.eclipse.persistence.jaxb.xmlmodel.XmlClassExtractor) XmlType(org.eclipse.persistence.jaxb.xmlmodel.XmlType) JavaType(org.eclipse.persistence.jaxb.xmlmodel.JavaType) JavaAttributes(org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes) XmlSchema(org.eclipse.persistence.jaxb.xmlmodel.XmlSchema) XmlRegistries(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.XmlRegistries) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) XmlJavaTypeAdapters(org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapters)

Aggregations

JavaAttributes (org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes)7 XmlElement (org.eclipse.persistence.jaxb.xmlmodel.XmlElement)6 JavaType (org.eclipse.persistence.jaxb.xmlmodel.JavaType)5 JAXBElement (jakarta.xml.bind.JAXBElement)3 XmlAttribute (org.eclipse.persistence.jaxb.xmlmodel.XmlAttribute)3 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)3 QName (javax.xml.namespace.QName)2 XmlBindings (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings)2 JavaTypes (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.JavaTypes)2 XmlJavaTypeAdapter (org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter)2 XmlRootElement (org.eclipse.persistence.jaxb.xmlmodel.XmlRootElement)2 XmlType (org.eclipse.persistence.jaxb.xmlmodel.XmlType)2 ArrayList (java.util.ArrayList)1 JavaField (org.eclipse.persistence.jaxb.javamodel.JavaField)1 JavaAttribute (org.eclipse.persistence.jaxb.xmlmodel.JavaAttribute)1 XmlAnyAttribute (org.eclipse.persistence.jaxb.xmlmodel.XmlAnyAttribute)1 XmlAnyElement (org.eclipse.persistence.jaxb.xmlmodel.XmlAnyElement)1 XmlEnums (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.XmlEnums)1 XmlRegistries (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.XmlRegistries)1 XmlClassExtractor (org.eclipse.persistence.jaxb.xmlmodel.XmlClassExtractor)1