Package org.eclipse.persistence.oxm.mappings

Examples of org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping


        entityResultsMapping.setSetMethodName("setEntityResults");
        entityResultsMapping.setReferenceClass(EntityResultMetadata.class);
        entityResultsMapping.setXPath("orm:entity-result");
        descriptor.addMapping(entityResultsMapping);
       
        XMLCompositeDirectCollectionMapping columnResultsMapping = new XMLCompositeDirectCollectionMapping();
        columnResultsMapping.setAttributeName("m_columnResults");
        columnResultsMapping.setGetMethodName("getColumnResults");
        columnResultsMapping.setSetMethodName("setColumnResults");
        columnResultsMapping.setXPath("orm:column-result/@name");
        descriptor.addMapping(columnResultsMapping);
       
        descriptor.addMapping(getNameAttributeMapping());
       
        return descriptor;
View Full Code Here


     */
    protected ClassDescriptor buildUniqueConstraintDescriptor() {
        XMLDescriptor descriptor = new XMLDescriptor();
        descriptor.setJavaClass(UniqueConstraintMetadata.class);
       
        XMLCompositeDirectCollectionMapping uniqueConstraintsMapping = new XMLCompositeDirectCollectionMapping();
        uniqueConstraintsMapping.setAttributeName("m_columnNames");
        uniqueConstraintsMapping.setGetMethodName("getColumnNames");
        uniqueConstraintsMapping.setSetMethodName("setColumnNames");
        uniqueConstraintsMapping.setXPath("orm:column-name");
        descriptor.addMapping(uniqueConstraintsMapping);
       
        return descriptor;
    }
View Full Code Here

        descriptor.setDefaultRootElement("event-policy");

        descriptor.getInheritancePolicy().setClassIndicatorField(new XMLField("@xsi:type"));
        descriptor.getInheritancePolicy().addClassIndicator(DescriptorEventManager.class, getPrimaryNamespaceXPath() + "event-policy");

        XMLCompositeDirectCollectionMapping eventListenersMapping = new XMLCompositeDirectCollectionMapping();
        eventListenersMapping.setAttributeName("eventListeners");
        eventListenersMapping.setGetMethodName("getEventListeners");
        eventListenersMapping.setSetMethodName("setEventListeners");
        eventListenersMapping.useCollectionClass(org.eclipse.persistence.internal.helper.NonSynchronizedVector.class);
        eventListenersMapping.setValueConverter(new ClassInstanceConverter());
        eventListenersMapping.setXPath(getSecondaryNamespaceXPath() + "event-listeners/" + getSecondaryNamespaceXPath() + "event-listener/text()");
        descriptor.addMapping(eventListenersMapping);

        XMLDirectMapping postBuildSelectorMapping = new XMLDirectMapping();
        postBuildSelectorMapping.setAttributeName("getPostBuildSelector");
        postBuildSelectorMapping.setGetMethodName("getPostBuildSelector");
View Full Code Here

    protected ClassDescriptor buildInterfacePolicyDescriptor() {
        XMLDescriptor descriptor = new XMLDescriptor();
        descriptor.setJavaClass(InterfacePolicy.class);
        descriptor.setDefaultRootElement("interfaces");

        XMLCompositeDirectCollectionMapping parentInterfacesMapping = new XMLCompositeDirectCollectionMapping();
        parentInterfacesMapping.setAttributeElementClass(Class.class);
        parentInterfacesMapping.setAttributeName("parentInterfaces");
        parentInterfacesMapping.setGetMethodName("getParentInterfaces");
        parentInterfacesMapping.setSetMethodName("setParentInterfaces");
        parentInterfacesMapping.setXPath(getPrimaryNamespaceXPath() + "interface/text()");
        descriptor.addMapping(parentInterfacesMapping);

        XMLDirectMapping implementorDescriptorMapping = new XMLDirectMapping();
        implementorDescriptorMapping.setAttributeName("implementorDescriptor");
        implementorDescriptorMapping.setGetMethodName("getImplementorDescriptor");
View Full Code Here

        XMLDescriptor descriptor = new XMLDescriptor();

        descriptor.setJavaClass(XMLDescriptor.class);
        descriptor.descriptorIsAggregate();
        descriptor.getInheritancePolicy().setParentClass(ClassDescriptor.class);
        XMLCompositeDirectCollectionMapping defaultRootElementMapping = new XMLCompositeDirectCollectionMapping();
        defaultRootElementMapping.setAttributeName("defaultRootElement");
        defaultRootElementMapping.setGetMethodName("getTableNames");
        defaultRootElementMapping.setSetMethodName("setTableNames");
        defaultRootElementMapping.setXPath(getPrimaryNamespaceXPath() + "default-root-element/text()");
        descriptor.addMapping(defaultRootElementMapping);

        XMLDirectMapping shouldPreserveDocument = new XMLDirectMapping();
        shouldPreserveDocument.setAttributeName("shouldPreserveDocument");
        shouldPreserveDocument.setGetMethodName("shouldPreserveDocument");
View Full Code Here

        singleNodeMapping.setSetMethodName("setUsesSingleNode");
        singleNodeMapping.setXPath(getPrimaryNamespaceXPath() + "single-node/text()");
        singleNodeMapping.setNullValue(Boolean.FALSE);
        descriptor.addMapping(singleNodeMapping);

        XMLCompositeDirectCollectionMapping schemaTypeMapping = new XMLCompositeDirectCollectionMapping();
        schemaTypeMapping.setAttributeName("schemaTypes");
        schemaTypeMapping.setGetMethodName("getSchemaTypes");
        schemaTypeMapping.setSetMethodName("setSchemaTypes");
        schemaTypeMapping.useCollectionClass(ArrayList.class);
        schemaTypeMapping.setAttributeElementClass(QName.class);
        schemaTypeMapping.setXPath(getPrimaryNamespaceXPath() + "schema-type/text()");
        descriptor.addMapping(schemaTypeMapping);

        XMLCompositeCollectionMapping xmlToJavaPairsMapping = new XMLCompositeCollectionMapping();
        xmlToJavaPairsMapping.setXPath(getPrimaryNamespaceXPath() + "xml-to-java-conversion-pair");
        xmlToJavaPairsMapping.setReferenceClass(XMLConversionPair.class);
View Full Code Here

            tableHelper.nestedIsComplex();
        }
        else  {
            if (!itemsMappingFound) {
                if (!next.isComplex()) {
                    XMLCompositeDirectCollectionMapping itemsMapping = new XMLCompositeDirectCollectionMapping();
                    itemsMapping.setAttributeElementClass(
                        attributeClassFromDatabaseType((DefaultListenerHelper)next));
                    itemsMapping.setAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME);
                    itemsMapping.setUsesSingleNode(true);
                    itemsMapping.setXPath("item/text()");
                    XMLField xField = (XMLField)itemsMapping.getField();
                    xField.setRequired(true);
                    itemsMapping.useCollectionClassName("java.util.ArrayList");
                    AbstractNullPolicy nullPolicy = itemsMapping.getNullPolicy();
                    nullPolicy.setNullRepresentedByEmptyNode(false);
                    nullPolicy.setMarshalNullRepresentation(XSI_NIL);
                    nullPolicy.setNullRepresentedByXsiNil(true);
                    itemsMapping.setNullPolicy(nullPolicy);
                    xdesc.getNamespaceResolver().put(SCHEMA_INSTANCE_PREFIX,
                        W3C_XML_SCHEMA_INSTANCE_NS_URI); // to support xsi:nil policy
                    xdesc.addMapping(itemsMapping);
                }
                else {
                    XMLCompositeCollectionMapping itemsMapping = new XMLCompositeCollectionMapping();
                    itemsMapping.setAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME);
                    itemsMapping.setXPath("item");
                    XMLField xField = (XMLField)itemsMapping.getField();
                    xField.setRequired(true);
                    itemsMapping.useCollectionClassName("java.util.ArrayList");
                    itemsMapping.setReferenceClassName(((TableHelper)next).tableName().toLowerCase() +
                        COLLECTION_WRAPPER_SUFFIX);
                    xdesc.addMapping(itemsMapping);
                }
            }
            if (next.isTable()) {
View Full Code Here

        return generateDirectCollectionMapping(property, descriptor, namespaceInfo);
    }

    public XMLCompositeDirectCollectionMapping generateEnumCollectionMapping(Property property, XMLDescriptor descriptor, NamespaceInfo namespaceInfo, EnumTypeInfo info) {
     
      XMLCompositeDirectCollectionMapping mapping = generateDirectCollectionMapping(property, descriptor, namespaceInfo);
      mapping.setValueConverter(buildJAXBEnumTypeConverter(mapping, info));
      return mapping;
    }
View Full Code Here

        }
        return mapping;
    }

    public XMLCompositeDirectCollectionMapping generateDirectCollectionMapping(Property property, XMLDescriptor descriptor, NamespaceInfo namespaceInfo) {
        XMLCompositeDirectCollectionMapping mapping = new XMLCompositeDirectCollectionMapping();
        mapping.setAttributeName(property.getPropertyName());
        mapping.setReuseContainer(true);
        // handle read-only set via metadata
        if (property.isSetReadOnly()) {
            mapping.setIsReadOnly(property.isReadOnly());
        }
        // handle write-only set via metadata
        if (property.isSetWriteOnly()) {
            mapping.setIsWriteOnly(property.isWriteOnly());
        }
        if (property.isMethodProperty()) {
            if (property.getGetMethodName() == null) {
                // handle case of set with no get method
                String paramTypeAsString = property.getType().getName();
                mapping.setAttributeAccessor(new JAXBSetMethodAttributeAccessor(paramTypeAsString, helper.getClassLoader()));
                mapping.setIsReadOnly(true);
                mapping.setSetMethodName(property.getSetMethodName());
            } else if (property.getSetMethodName() == null) {
                mapping.setGetMethodName(property.getGetMethodName());
                mapping.setIsWriteOnly(true);
            } else {
                mapping.setSetMethodName(property.getSetMethodName());
                mapping.setGetMethodName(property.getGetMethodName());
            }
        }
        JavaClass collectionType = property.getType();

        if (collectionType.isArray()){
            JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), helper.getClassLoader());
            String componentClassName = collectionType.getComponentType().getQualifiedName();
            if (collectionType.getComponentType().isPrimitive()){
                Class primitiveClass = XMLConversionManager.getDefaultManager().convertClassNameToClass(componentClassName);
                accessor.setComponentClass(primitiveClass);
                mapping.setAttributeAccessor(accessor);

                Class declaredClass = XMLConversionManager.getDefaultManager().getObjectClass(primitiveClass);
                mapping.setAttributeElementClass(declaredClass);
            } else {
                accessor.setComponentClassName(componentClassName);
                mapping.setAttributeAccessor(accessor);

                JavaClass componentType = collectionType.getComponentType();
                try{
                    Class declaredClass = PrivilegedAccessHelper.getClassForName(componentType.getRawName(), false, helper.getClassLoader());
                    mapping.setAttributeElementClass(declaredClass);
                }catch (Exception e) {}
            }
        collectionType = jotArrayList;
        } else if (isCollectionType(collectionType)){
          if (collectionType.hasActualTypeArguments()){
            JavaClass itemType = (JavaClass)collectionType.getActualTypeArguments().toArray()[0];
            try {
              Class declaredClass = PrivilegedAccessHelper.getClassForName(itemType.getRawName(), false, helper.getClassLoader());
              mapping.setAttributeElementClass(declaredClass);
            } catch (Exception e) {}
          }
        }
        if (areEquals(collectionType, Collection.class) || areEquals(collectionType, List.class)) {
            collectionType = jotArrayList;
        } else if (areEquals(collectionType, Set.class)) {
            collectionType = jotHashSet;
        }
        mapping.useCollectionClassName(collectionType.getRawName());

        // if the XPath is set (via xml-path) use it; otherwise figure it out
        XMLField xmlField = getXPathForField(property, namespaceInfo, true);
        mapping.setField(xmlField);

        if (helper.isAnnotationPresent(property.getElement(), XmlMixed.class)) {
            xmlField.setXPath("text()");
        }

        if (XMLConstants.QNAME_QNAME.equals(property.getSchemaType())){
            ((XMLField) mapping.getField()).setSchemaType(XMLConstants.QNAME_QNAME);
        }

        // handle null policy set via xml metadata
        if (property.isSetNullPolicy()) {
            mapping.setNullPolicy(getNullPolicyFromProperty(property, namespaceInfo.getNamespaceResolverForDescriptor()));
        } else if (property.isNillable()){
            mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
            mapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
        }
        mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);

        if (property.isRequired()) {
            ((XMLField) mapping.getField()).setRequired(true);
        }

        if (property.isXmlElementType() && property.getGenericType()!=null ){
          Class theClass = helper.getClassForJavaClass(property.getGenericType());
          mapping.setAttributeElementClass(theClass);
        }

        if (xmlField.getXPathFragment().isAttribute() || property.isXmlList() || xmlField.getXPathFragment().nameIsText()){
            mapping.setUsesSingleNode(true);
        }
        // handle cdata set via metadata
        if (property.isSetCdata()) {
            mapping.setIsCDATA(property.isCdata());
        }
        return mapping;
    }
View Full Code Here

            desc = new XMLDescriptor();
            desc.setJavaClass(generatedClass);


            if(nextElement.isList()){
                XMLCompositeDirectCollectionMapping mapping = new XMLCompositeDirectCollectionMapping();
                mapping.setAttributeName("value");
                mapping.setXPath("text()");
                mapping.setUsesSingleNode(true);
                mapping.setReuseContainer(true);

                if(type != null && type.isEnumerationType()){
                    mapping.setValueConverter(buildJAXBEnumTypeConverter(mapping, (EnumTypeInfo)type));
                }else{
                    try{
                        Class fieldElementClass = PrivilegedAccessHelper.getClassForName(nextClassName, false, helper.getClassLoader());
                        mapping.setFieldElementClass(fieldElementClass);
                    }catch(ClassNotFoundException e){
                    }
                }

                if(nextClassName.equals("[B") || nextClassName.equals("[Ljava.lang.Byte;")) {
                   ((XMLField)mapping.getField()).setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
                }
                else if(nextClassName.equals("javax.xml.namespace.QName")){
                    ((XMLField)mapping.getField()).setSchemaType(XMLConstants.QNAME_QNAME);
                }
                desc.addMapping(mapping);
            } else{
                if(nextElement.getJavaTypeName().equals(OBJECT_CLASS_NAME)){
                    XMLCompositeObjectMapping mapping = new XMLCompositeObjectMapping();
                    mapping.setAttributeName("value");
                    mapping.setSetMethodName("setValue");
                    mapping.setGetMethodName("getValue");
                    mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
                    mapping.setXPath(".");
                    ((XMLField)mapping.getField()).setIsTypedTextField(true);
                    ((XMLField)mapping.getField()).setSchemaType(XMLConstants.ANY_TYPE_QNAME);
                    desc.addMapping(mapping);                  
                }else if(isBinaryData(nextElement.getJavaType())){
                    XMLBinaryDataMapping mapping = new XMLBinaryDataMapping();
                    mapping.setAttributeName("value");
                    mapping.setXPath(".");
                    ((XMLField)mapping.getField()).setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
                    mapping.setSetMethodName("setValue");
                    mapping.setGetMethodName("getValue");

                    Class attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(attributeTypeName, getClass().getClassLoader());
                    mapping.setAttributeClassification(attributeClassification);

                    mapping.setShouldInlineBinaryData(false);
                    if(nextElement.getTypeMappingInfo() != null) {
                        mapping.setSwaRef(nextElement.isXmlAttachmentRef());
                        mapping.setMimeType(nextElement.getXmlMimeType());
                    }
                    desc.addMapping(mapping);

                }else{
                    XMLDirectMapping mapping = new XMLDirectMapping();
                    mapping.setAttributeName("value");
                    mapping.setXPath("text()");
                    mapping.setSetMethodName("setValue");
                    mapping.setGetMethodName("getValue");
                    if(nextElement.getDefaultValue() != null) {
                        mapping.setNullValue(nextElement.getDefaultValue());
                        mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
                    }
                   

                    if(helper.isBuiltInJavaType(nextElement.getJavaType())){
                        Class attributeClassification = null;
                        if(nextElement.getJavaType().isPrimitive()) {
                            attributeClassification = XMLConversionManager.getDefaultManager().convertClassNameToClass(attributeTypeName);
                        } else {
                            attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(attributeTypeName, getClass().getClassLoader());
                        }
                        mapping.setAttributeClassification(attributeClassification);
                    }

                    IsSetNullPolicy nullPolicy = new IsSetNullPolicy("isSetValue", false, true, XMLNullRepresentationType.ABSENT_NODE);
                    //nullPolicy.setNullRepresentedByEmptyNode(true);
                    mapping.setNullPolicy(nullPolicy);

                    if(type != null && type.isEnumerationType()){
                        mapping.setConverter(buildJAXBEnumTypeConverter(mapping, (EnumTypeInfo)type));
                    }
                    if(nextClassName.equals("[B") || nextClassName.equals("[Ljava.lang.Byte;")) {
                        ((XMLField)mapping.getField()).setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
                    }
                    else if(nextClassName.equals("javax.xml.namespace.QName")){
                        ((XMLField)mapping.getField()).setSchemaType(XMLConstants.QNAME_QNAME);
                    }

                    if (nextElement.getJavaTypeAdapterClass() != null) {
                        mapping.setConverter(new XMLJavaTypeConverter(nextElement.getJavaTypeAdapterClass()));
                    }

                    desc.addMapping(mapping);
                }
            }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.