Package org.eclipse.persistence.internal.oxm.mappings

Examples of org.eclipse.persistence.internal.oxm.mappings.Descriptor


                }
            }else if(type != null && !type.isTransient()){
                if(next.getNamespaceURI() == null || next.getNamespaceURI().equals("")) {
                    type.getDescriptor().addRootElement(next.getLocalPart());
                } else {
                    Descriptor descriptor = type.getDescriptor();
                    String uri = next.getNamespaceURI();
                    String prefix = getPrefixForNamespace(uri, descriptor.getNamespaceResolver());
                    descriptor.addRootElement(getQualifiedString(prefix, next.getLocalPart()));
                }
            }
        }
    }
View Full Code Here


              this.qNamesToDeclaredClasses.put(next, declaredClass);
          }catch(Exception e){

          }

          Descriptor desc = (Descriptor)project.getDescriptor(generatedClass);

          if(desc == null){
            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);
                }
            }
            if(next != null){
                NamespaceInfo info = getNamespaceInfoForURI(namespaceUri);

          if(info != null) {
            NamespaceResolver resolver = info.getNamespaceResolverForDescriptor();
           
            String prefix = null;
            if(namespaceUri != Constants.EMPTY_STRING){
                prefix = resolver.resolveNamespaceURI(namespaceUri);
                if(prefix == null){
                  prefix = getPrefixForNamespace(namespaceUri, resolver);             
                }
            }
            desc.setNamespaceResolver(resolver);
            if(nextElement.isXmlRootElement()) {
                desc.setDefaultRootElement(getQualifiedString(prefix, next.getLocalPart()));
            } else {
                desc.setDefaultRootElement("");
                desc.addRootElement(getQualifiedString(prefix, next.getLocalPart()));
            }
                } else {
                    if(namespaceUri.equals("")) {
                        desc.setDefaultRootElement(next.getLocalPart());
                    } else {
                        NamespaceResolver resolver = new org.eclipse.persistence.oxm.NamespaceResolver();
                        String prefix = getPrefixForNamespace(namespaceUri, resolver);

                        desc.setNamespaceResolver(resolver);
                          if(nextElement.isXmlRootElement()) {
                              desc.setDefaultRootElement(getQualifiedString(prefix, next.getLocalPart()));
                          } else {
                              desc.setDefaultRootElement("");
                              desc.addRootElement(getQualifiedString(prefix, next.getLocalPart()));
                          }
            }
          }
            }
            project.addDescriptor((CoreDescriptor)desc);
View Full Code Here

                    if (generatedClass != null) {
                        classToLookup = generatedClass;
                    }
                }
                if (classToLookup != null && classToLookup.getClass() == Class.class) {
                    Descriptor xmlDescriptor = (Descriptor) proj.getDescriptor((Class) classToLookup);
                    typeMappingInfo.setXmlDescriptor(xmlDescriptor);
                }
            }

            return contextState;
View Full Code Here

            Collection descriptors = xmlContext.getSession().getDescriptors().values();
            Iterator iter = descriptors.iterator();

            while (iter.hasNext()) {
                Descriptor desc = (Descriptor) iter.next();
                processXMLDescriptor(new ArrayList<Descriptor>(), desc, desc.getNonNullNamespaceResolver());
            }

        }
View Full Code Here

        private void processRefClasses(List processed, Set refClasses, org.eclipse.persistence.internal.oxm.NamespaceResolver nr) {
            if (refClasses != null) {
                Iterator iter = refClasses.iterator();
                while (iter.hasNext()) {
                    Class nextClass = (Class) iter.next();
                    Descriptor desc = (Descriptor) xmlContext.getSession().getProject().getDescriptor(nextClass);
                    processXMLDescriptor(processed, desc, nr);
                }
            }
        }
View Full Code Here

            for (int i = 0; i < mappings.size(); i++) {
                DatabaseMapping nextMapping = (DatabaseMapping) mappings.get(i);
                Vector fields = nextMapping.getFields();
                updateResolverForFields(fields, nr);
                Descriptor refDesc = (Descriptor) ((DatabaseMapping) nextMapping).getReferenceDescriptor();
                if (refDesc != null && !processed.contains(refDesc)) {
                    processXMLDescriptor(processed, refDesc, nr);
                }

                if (nextMapping instanceof ChoiceObjectMapping) {
View Full Code Here

            Iterator descriptors = xmlContext.getSession().getProject().getOrderedDescriptors().iterator();

            //Add schema types generated for mapped domain classes
            while (descriptors.hasNext()) {
                Descriptor next = (Descriptor) descriptors.next();
                Class javaClass = next.getJavaClass();

                if (next.getSchemaReference() != null) {
                    QName schemaType = next.getSchemaReference().getSchemaContextAsQName(next.getNamespaceResolver());
                    Type type = null;
                    if (generator != null) {

                        type = generator.getAnnotationsProcessor().getGeneratedClassesToCollectionClasses().get(javaClass);

                        if (type == null) {
                            JavaClass arrayClass = (JavaClass) generator.getAnnotationsProcessor().getGeneratedClassesToArrayClasses().get(javaClass);
                            if (arrayClass != null) {
                                String arrayClassName = arrayClass.getName();
                                try {
                                    type = PrivilegedAccessHelper.getClassForName(arrayClassName);
                                } catch (Exception ex) {
                                }
                            }

                            if (type == null && getTypeMappingInfoToGeneratedType() != null) {
                                Iterator<Map.Entry<TypeMappingInfo, Class>> iter = getTypeMappingInfoToGeneratedType().entrySet().iterator();
                                while (iter.hasNext()) {
                                    Map.Entry<TypeMappingInfo, Class> entry = iter.next();
                                    if (entry.getValue().equals(javaClass)) {
                                        type = entry.getKey().getType();
                                        break;
                                    }
                                }
                            }
                        }
                        if (type == null) {
                            type = javaClass;
                        }

                    } else {
                        type = javaClass;
                    }
                    this.typeToSchemaType.put(type, schemaType);
                }
            }

            //Add any types that we didn't generate descriptors for (built in types)
            if (boundTypes != null) {
                for (TypeMappingInfo next : this.boundTypes) {
                    if (this.typeToSchemaType.get(next) == null) {
                        Type nextType = next.getType();
                        QName name = getSchemaTypeForTypeMappingInfo(nextType);
                        if (name != null) {
                            this.typeToSchemaType.put(nextType, name);
                        }
                    }
View Full Code Here

        if (javaClass.getSuperclass() != null && javaClass.getSuperclass().getName().equals("javax.xml.bind.JAXBElement")) {
            generateDescriptorForJAXBElementSubclass(javaClass, project, namespaceInfo.getNamespaceResolverForDescriptor());
            return;
        }

        Descriptor descriptor = new XMLDescriptor();
        org.eclipse.persistence.jaxb.xmlmodel.XmlRootElement rootElem = info.getXmlRootElement();
        if (rootElem == null) {
           try{               
             elementName = info.getXmlNameTransformer().transformRootElementName(javaClass.getName());
             }catch (Exception ex){
                throw org.eclipse.persistence.exceptions.JAXBException.exceptionDuringNameTransformation(javaClass.getName(), info.getXmlNameTransformer().getClass().getName(), ex);
            
           
            namespace = packageNamespace;
            descriptor.setResultAlwaysXMLRoot(true);
        } else {
            elementName = rootElem.getName();
            if (elementName.equals(XMLProcessor.DEFAULT)) {
                try{               
                    elementName = info.getXmlNameTransformer().transformRootElementName(javaClass.getName());
                }catch (Exception ex){
                   throw org.eclipse.persistence.exceptions.JAXBException.exceptionDuringNameTransformation(javaClass.getName(), info.getXmlNameTransformer().getClass().getName(), ex);
               
            }
            namespace = rootElem.getNamespace();
            descriptor.setResultAlwaysXMLRoot(false);
        }

        descriptor.setJavaClassName(jClassName);

        if (info.getFactoryMethodName() != null) {
            descriptor.getInstantiationPolicy().useFactoryInstantiationPolicy(info.getObjectFactoryClassName(), info.getFactoryMethodName());
        }

        if (namespace.equals(XMLProcessor.DEFAULT)) {
            namespace = namespaceInfo.getNamespace();
        }

        JavaClass manyValueJavaClass = helper.getJavaClass(ManyValue.class);
        if (!manyValueJavaClass.isAssignableFrom(javaClass)){
            if(namespace.length() != 0) {
                if(isDefaultNamespaceAllowed && globalNamespaceResolver.getDefaultNamespaceURI() == null && namespace.length() != 0) {
                    if (!namespaceInfo.getNamespaceResolverForDescriptor().getPrefixesToNamespaces().containsValue(namespace)) {
                        globalNamespaceResolver.setDefaultNamespaceURI(namespace);
                        namespaceInfo.getNamespaceResolverForDescriptor().setDefaultNamespaceURI(namespace);
                    }
                }
            }
            if (rootElem == null) {
                descriptor.setDefaultRootElement("");
            } else {
                if (namespace.length() == 0) {
                    descriptor.setDefaultRootElement(elementName);
                } else {
                    descriptor.setDefaultRootElement(getQualifiedString(getPrefixForNamespace(namespace, namespaceInfo.getNamespaceResolverForDescriptor()), elementName));
              }
            }
        }

        descriptor.setNamespaceResolver(namespaceInfo.getNamespaceResolverForDescriptor());
       
        setSchemaContext(descriptor, info);
        // set the ClassExtractor class name if necessary
        if (info.isSetClassExtractorName()) {
            descriptor.getInheritancePolicy().setClassExtractorName(info.getClassExtractorName());
        }
        // set any user-defined properties
        if (info.getUserProperties() != null) {
            descriptor.setProperties(info.getUserProperties());
        }

        if (info.isLocationAware()) {
            Property locProp = null;
            Iterator<Property> i = info.getPropertyList().iterator();
            while (i.hasNext()) {
                Property p = i.next();
                if (p.getType().getName().equals(Constants.LOCATOR_CLASS_NAME)) {
                    locProp = p;
                }
            }
            if (locProp != null && locProp.isTransient()) {
                // build accessor
                // don't make a mapping
                if (locProp.isMethodProperty()) {
                    MethodAttributeAccessor aa = new MethodAttributeAccessor();
                    aa.setAttributeName(locProp.getPropertyName());
                    aa.setSetMethodName(locProp.getSetMethodName());
                    aa.setGetMethodName(locProp.getGetMethodName());
                    descriptor.setLocationAccessor(aa);
                } else {
                    // instance variable property
                    InstanceVariableAttributeAccessor aa = new InstanceVariableAttributeAccessor();
                    aa.setAttributeName(locProp.getPropertyName());
                    descriptor.setLocationAccessor(aa);
                }
            }
        }
       
        if(!info.getObjectGraphs().isEmpty()) {
View Full Code Here

    public void generateDescriptorForJAXBElementSubclass(JavaClass javaClass, CoreProject project, NamespaceResolver nsr) {
        String jClassName = javaClass.getQualifiedName();
        TypeInfo info = typeInfo.get(jClassName);

        Descriptor xmlDescriptor = new XMLDescriptor();
        xmlDescriptor.setJavaClassName(jClassName);

        String[] factoryMethodParamTypes = info.getFactoryMethodParamTypes();

        MultiArgInstantiationPolicy policy = new MultiArgInstantiationPolicy();
        policy.useFactoryInstantiationPolicy(info.getObjectFactoryClassName(), info.getFactoryMethodName());
        policy.setParameterTypeNames(factoryMethodParamTypes);
        policy.setDefaultValues(new String[]{null});

        xmlDescriptor.setInstantiationPolicy(policy);
        JavaClass paramClass = helper.getJavaClass(factoryMethodParamTypes[0]);
        boolean isObject = paramClass.getName().equals("java.lang.Object");       
        if(helper.isBuiltInJavaType(paramClass) && !isObject ){
            if(isBinaryData(paramClass)){
                BinaryDataMapping mapping = new XMLBinaryDataMapping();
                mapping.setAttributeName("value");
                mapping.setXPath(".");
                ((Field)mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
                mapping.setSetMethodName("setValue");
                mapping.setGetMethodName("getValue");

                Class attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(factoryMethodParamTypes[0], getClass().getClassLoader());
                mapping.setAttributeClassification(attributeClassification);
                mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);

                mapping.setShouldInlineBinaryData(false);
                if(mapping.getMimeType() == null) {
                    if(areEquals(paramClass, javax.xml.transform.Source.class)) {
                        mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/xml"));
                    } else {
                        mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/octet-stream"));
                    }                      
                }
                xmlDescriptor.addMapping((CoreMapping)mapping);
            } else {
                DirectMapping mapping = new XMLDirectMapping();
                mapping.setNullValueMarshalled(true);
                mapping.setAttributeName("value");
                mapping.setGetMethodName("getValue");
                mapping.setSetMethodName("setValue");
                mapping.setXPath("text()");
                Class attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(factoryMethodParamTypes[0], getClass().getClassLoader());
                mapping.setAttributeClassification(attributeClassification);
                xmlDescriptor.addMapping((CoreMapping)mapping);
            }
        }else if(paramClass.isEnum()){
             EnumTypeInfo enumInfo = (EnumTypeInfo)typeInfo.get(paramClass.getQualifiedName());
         
             DirectMapping mapping = new XMLDirectMapping();
             mapping.setConverter(buildJAXBEnumTypeConverter(mapping, enumInfo));
             mapping.setNullValueMarshalled(true);
             mapping.setAttributeName("value");
             mapping.setGetMethodName("getValue");
             mapping.setSetMethodName("setValue");
             mapping.setXPath("text()");
             Class attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(factoryMethodParamTypes[0], getClass().getClassLoader());
             mapping.setAttributeClassification(attributeClassification);
             xmlDescriptor.addMapping((CoreMapping)mapping);
            
        }else{
       
            CompositeObjectMapping mapping = new XMLCompositeObjectMapping();
            mapping.setAttributeName("value");
            mapping.setGetMethodName("getValue");
            mapping.setSetMethodName("setValue");
            mapping.setXPath(".");
            if(isObject){
              mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);               
            }else{
              mapping.setReferenceClassName(factoryMethodParamTypes[0]);
            }
            xmlDescriptor.addMapping((CoreMapping)mapping);
        }
        xmlDescriptor.setNamespaceResolver(nsr);
        setSchemaContext(xmlDescriptor, info);
        project.addDescriptor((CoreDescriptor)xmlDescriptor);
        info.setDescriptor(xmlDescriptor);
    }
View Full Code Here

      Class generatedClass = getGeneratedMapEntryClasses().get(mapKey);

        if(generatedClass == null){
            generatedClass = generateMapEntryClass(mapEntryClassName, keyType.getQualifiedName(), valueType.getQualifiedName());
            getGeneratedMapEntryClasses().put(mapKey, generatedClass);
            Descriptor desc = new XMLDescriptor();
            desc.setJavaClass(generatedClass);

            desc.addMapping((CoreMapping)generateMappingForType(keyType, Property.DEFAULT_KEY_NAME));
            desc.addMapping((CoreMapping)generateMappingForType(valueType, Property.DEFAULT_VALUE_NAME));
            desc.setNamespaceResolver(nr);
            project.addDescriptor((CoreDescriptor)desc);
        }
        return generatedClass;
    }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.internal.oxm.mappings.Descriptor

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.