Package org.eclipse.persistence.oxm.mappings

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


        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

        XMLDirectMapping fetchGroupNameMapping = new XMLDirectMapping();
        fetchGroupNameMapping.setAttributeName("name");
        fetchGroupNameMapping.setXPath(getPrimaryNamespaceXPath() + "name");
        descriptor.addMapping(fetchGroupNameMapping);

        XMLCompositeDirectCollectionMapping fetchGroupAttributeMapping = new XMLCompositeDirectCollectionMapping();
        CollectionContainerPolicy containerPolicy = new CollectionContainerPolicy(TreeSet.class);
        fetchGroupAttributeMapping.setContainerPolicy(containerPolicy);
        fetchGroupAttributeMapping.setAttributeName("attributes");
        fetchGroupAttributeMapping.setXPath(getPrimaryNamespaceXPath() + "fetch-group-attributes/" + getPrimaryNamespaceXPath() + "fetch-group-attribute/text()");
        descriptor.addMapping(fetchGroupAttributeMapping);

        return descriptor;
    }
View Full Code Here

          
        return mapping;
    }

    public DirectCollectionMapping generateDirectCollectionMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo) {
        DirectCollectionMapping mapping = new XMLCompositeDirectCollectionMapping();
        initializeXMLMapping((XMLMapping)mapping, property);

        initializeXMLContainerMapping(mapping, property.getType().isArray());
    
        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) {}
            }
        } else if (helper.isCollectionType(collectionType)){
            Collection args = collectionType.getActualTypeArguments();
          if (args.size() >0){
            JavaClass itemType = (JavaClass)args.iterator().next();
            try {
              Class declaredClass = PrivilegedAccessHelper.getClassForName(itemType.getRawName(), false, helper.getClassLoader());
              if(declaredClass != String.class){
                  mapping.setAttributeElementClass(declaredClass);
              }
            } catch (Exception e) {}
          }
        }
        collectionType = containerClassImpl(collectionType);
        mapping.useCollectionClassName(collectionType.getRawName());

        if (property.getDefaultValue() != null) {
            mapping.setNullValue(property.getDefaultValue());
        }
       
        // if the XPath is set (via xml-path) use it; otherwise figure it out
        Field xmlField = getXPathForField(property, namespaceInfo, true, false);
        mapping.setField(xmlField);

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

        if (Constants.QNAME_QNAME.equals(property.getSchemaType())){
            ((Field) mapping.getField()).setSchemaType(Constants.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.isSetXmlElementWrapper()) {
            mapping.setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
        }

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

        if (property.isXmlElementType() && property.getGenericType()!=null ){
          Class theClass = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(property.getGenericType().getQualifiedName(), helper.getClassLoader());
          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()){
                DirectCollectionMapping 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;")) {
                   ((Field)mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
                }
                else if(nextClassName.equals("javax.xml.namespace.QName")){
                    ((Field)mapping.getField()).setSchemaType(Constants.QNAME_QNAME);
                }
                desc.addMapping((CoreMapping)mapping);
            } else{
                if(nextElement.getJavaTypeName().equals(OBJECT_CLASS_NAME)){
                    CompositeObjectMapping mapping = new XMLCompositeObjectMapping();
                    mapping.setAttributeName("value");
                    mapping.setSetMethodName("setValue");
                    mapping.setGetMethodName("getValue");
                    mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
                    mapping.setXPath(".");
                    setTypedTextField((Field)mapping.getField());

                    desc.addMapping((CoreMapping)mapping);                  
                }else if(isBinaryData(nextElement.getJavaType())){
                    BinaryDataMapping mapping = new XMLBinaryDataMapping();
                    mapping.setAttributeName("value");
                    mapping.setXPath(".");
                    ((Field)mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
                    mapping.setSetMethodName("setValue");
                    mapping.setGetMethodName("getValue");
                    mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
                    mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);

                    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((CoreMapping)mapping);

                }else{
                  DirectMapping mapping = new XMLDirectMapping();
                    mapping.setNullValueMarshalled(true);
                    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;")) {
                        ((Field)mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
                    }
                    else if(nextClassName.equals("javax.xml.namespace.QName")){
                        ((Field)mapping.getField()).setSchemaType(Constants.QNAME_QNAME);
                    }

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

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

    private XMLCompositeDirectCollectionMapping mapping;
    private Class objectClass = null;
    private String objectClassName = null;

    public Object convertDataValueToObjectValue(Object dataValue, Session session) {
        XMLCompositeDirectCollectionMapping dcMapping = (XMLCompositeDirectCollectionMapping) this.mapping;
        return this.conversionManager.convertStringToList(dataValue, getObjectClass(), dcMapping.getContainerPolicy());
    }
View Full Code Here

        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 buildStructDescriptor() {
        XMLDescriptor descriptor = new XMLDescriptor();
        descriptor.setJavaClass(StructMetadata.class);
       
        // Element mappings - must remain in order of definition in XML.
        XMLCompositeDirectCollectionMapping fieldsMapping = new XMLCompositeDirectCollectionMapping();
        fieldsMapping.setAttributeName("m_fields");
        fieldsMapping.setGetMethodName("getFields");
        fieldsMapping.setSetMethodName("setFields");
        fieldsMapping.setXPath("orm:field");
        descriptor.addMapping(fieldsMapping);
       
        // Attribute mappings.
        descriptor.addMapping(getNameAttributeMapping());
       
View Full Code Here

   
    /**
     * INTERNAL:
     */
    protected XMLCompositeDirectCollectionMapping getColumnNamesMapping() {
        XMLCompositeDirectCollectionMapping columnNamesMapping = new XMLCompositeDirectCollectionMapping();
        columnNamesMapping.setAttributeName("m_columnNames");
        columnNamesMapping.setGetMethodName("getColumnNames");
        columnNamesMapping.setSetMethodName("setColumnNames");
        columnNamesMapping.setXPath("orm:column-name");
        return columnNamesMapping;
    }
View Full Code Here

   
    /**
     * INTERNAL:
     */
    protected XMLCompositeDirectCollectionMapping getConnectionPoolsMapping() {
        XMLCompositeDirectCollectionMapping mapping = new XMLCompositeDirectCollectionMapping();
        mapping.setAttributeName("connectionPools");
        mapping.setGetMethodName("getConnectionPools");
        mapping.setSetMethodName("setConnectionPools");
        mapping.setXPath("orm:connection-pool");
        return 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.