Package org.eclipse.persistence.jaxb

Examples of org.eclipse.persistence.jaxb.TypeMappingInfo


    public void createElementsForTypeMappingInfo() {
        if (this.javaClassToTypeMappingInfos != null && !this.javaClassToTypeMappingInfos.isEmpty()) {
            Set<JavaClass> classes = this.javaClassToTypeMappingInfos.keySet();
            for (JavaClass nextClass : classes) {
                TypeMappingInfo nextInfo = this.javaClassToTypeMappingInfos.get(nextClass);
                if (nextInfo != null) {
                    boolean xmlAttachmentRef = false;
                    String xmlMimeType = null;
                    java.lang.annotation.Annotation[] annotations = getAnnotations(nextInfo);
                    Class adapterClass = this.typeMappingInfoToAdapterClasses.get(nextInfo);
                    Class declJavaType = null;
                    if (adapterClass != null) {
                        declJavaType = CompilerHelper.getTypeFromAdapterClass(adapterClass);
                    }
                    if (annotations != null) {
                        for (int j = 0; j < annotations.length; j++) {
                            java.lang.annotation.Annotation nextAnnotation = annotations[j];
                            if (nextAnnotation != null) {
                                if (nextAnnotation instanceof XmlMimeType) {
                                    XmlMimeType javaAnnotation = (XmlMimeType) nextAnnotation;
                                    xmlMimeType = javaAnnotation.value();
                                } else if (nextAnnotation instanceof XmlAttachmentRef) {
                                    xmlAttachmentRef = true;
                                    if (!this.hasSwaRef) {
                                        this.hasSwaRef = true;
                                    }
                                }
                            }
                        }
                    }

                    QName qname = null;

                    String nextClassName = nextClass.getQualifiedName();

                    if (declJavaType != null) {
                        nextClassName = declJavaType.getCanonicalName();
                    }

                    if (typeMappingInfoToGeneratedClasses != null) {
                        Class generatedClass = typeMappingInfoToGeneratedClasses.get(nextInfo);
                        if (generatedClass != null) {
                            nextClassName = generatedClass.getCanonicalName();
                        }
                    }

                    TypeInfo nextTypeInfo = typeInfo.get(nextClassName);
                    if (nextTypeInfo != null) {
                        qname = new QName(nextTypeInfo.getClassNamespace(), nextTypeInfo.getSchemaTypeName());
                    } else {
                        qname = getUserDefinedSchemaTypes().get(nextClassName);
                        if (qname == null) {
                            if (nextClassName.equals(ClassConstants.APBYTE.getName()) || nextClassName.equals(Image.class.getName()) || nextClassName.equals(Source.class.getName()) || nextClassName.equals("javax.activation.DataHandler")) {
                                if (xmlAttachmentRef) {
                                    qname = XMLConstants.SWA_REF_QNAME;
                                } else {
                                    qname = XMLConstants.BASE_64_BINARY_QNAME;
                                }
                            } else if (nextClassName.equals(ClassConstants.OBJECT.getName())) {
                                qname = XMLConstants.ANY_TYPE_QNAME;
                            } else if (nextClassName.equals(ClassConstants.XML_GREGORIAN_CALENDAR.getName())) {
                                qname = XMLConstants.ANY_SIMPLE_TYPE_QNAME;
                            } else {
                                Class theClass = helper.getClassForJavaClass(nextClass);
                                qname = (QName) XMLConversionManager.getDefaultJavaTypes().get(theClass);
                            }
                        }
                    }

                    if (qname != null) {
                        typeMappingInfoToSchemaType.put(nextInfo, qname);
                    }

                    if (nextInfo.getXmlTagName() != null) {
                        ElementDeclaration element = new ElementDeclaration(nextInfo.getXmlTagName(), nextClass, nextClass.getQualifiedName(), false);
                        element.setTypeMappingInfo(nextInfo);
                        element.setXmlMimeType(xmlMimeType);
                        element.setXmlAttachmentRef(xmlAttachmentRef);

                        if (declJavaType != null) {
                            element.setJavaType(helper.getJavaClass(declJavaType));
                        }
                        Class generatedClass = typeMappingInfoToGeneratedClasses.get(nextInfo);
                        if (generatedClass != null) {
                            element.setJavaType(helper.getJavaClass(generatedClass));
                        }
                        if (nextInfo.getElementScope() == TypeMappingInfo.ElementScope.Global) {
                            ElementDeclaration currentElement = this.getGlobalElements().get(element.getElementName());
                            if (currentElement == null) {
                                this.getGlobalElements().put(element.getElementName(), element);
                            } else {
                                //if(currentElement.getTypeMappingInfo() == null) {
View Full Code Here


        ArrayList<JavaClass> extraClasses = new ArrayList<JavaClass>();
        ArrayList<JavaClass> classesToProcess = new ArrayList<JavaClass>();
        for (JavaClass jClass : classes) {
            Class xmlElementType = null;
            JavaClass javaClass = jClass;
            TypeMappingInfo tmi = javaClassToTypeMappingInfos.get(javaClass);
            if (tmi != null) {
                Class adapterClass = this.typeMappingInfoToAdapterClasses.get(tmi);
                if (adapterClass != null) {
                    JavaClass adapterJavaClass = helper.getJavaClass(adapterClass);
                    JavaClass newType = helper.getJavaClass(Object.class);

                    // look for marshal method
                    for (Object nextMethod : adapterJavaClass.getDeclaredMethods()) {
                        JavaMethod method = (JavaMethod) nextMethod;
                        if (method.getName().equals("marshal")) {
                            JavaClass returnType = method.getReturnType();
                            if (!returnType.getQualifiedName().equals(newType.getQualifiedName())) {
                                newType = (JavaClass) returnType;
                                break;
                            }
                        }
                    }
                    javaClass = newType;
                }
                java.lang.annotation.Annotation[] annotations = getAnnotations(tmi);
                if (annotations != null) {
                    for (int j = 0; j < annotations.length; j++) {
                        java.lang.annotation.Annotation nextAnnotation = annotations[j];

                        if (nextAnnotation != null) {
                            if (nextAnnotation instanceof XmlElement) {
                                XmlElement javaAnnotation = (XmlElement) nextAnnotation;
                                if (javaAnnotation.type() != XmlElement.DEFAULT.class) {
                                    xmlElementType = javaAnnotation.type();
                                }
                            }
                        }
                    }
                }
            }

            if (areEquals(javaClass, byte[].class) || areEquals(javaClass, JAVAX_ACTIVATION_DATAHANDLER) || areEquals(javaClass, Source.class) || areEquals(javaClass, Image.class) || areEquals(javaClass, JAVAX_MAIL_INTERNET_MIMEMULTIPART)) {
                if (tmi == null || tmi.getXmlTagName() == null) {
                    ElementDeclaration declaration = new ElementDeclaration(null, javaClass, javaClass.getQualifiedName(), false, XmlElementDecl.GLOBAL.class);
                    declaration.setTypeMappingInfo(tmi);
                    getGlobalElements().put(null, declaration);
                }
            } else if (javaClass.isArray()) {
View Full Code Here

              if (namespaceUri == null || namespaceUri.equals(XMLProcessor.DEFAULT)) {
                  namespaceUri = "";
              }
        }

        TypeMappingInfo tmi = nextElement.getTypeMappingInfo();
        Class generatedClass = null;

        JaxbClassLoader loader = getJaxbClassLoader();

        if(tmi != null){
View Full Code Here

    static Class getExisitingGeneratedClass(TypeMappingInfo tmi, Map<TypeMappingInfo, Class> typeMappingInfoToGeneratedClasses, Map<TypeMappingInfo, Class> typeMappingInfoToAdapterClasses, ClassLoader loader) {

        Iterator<Map.Entry<TypeMappingInfo, Class>> iter = typeMappingInfoToGeneratedClasses.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<TypeMappingInfo, Class> next = iter.next();
            TypeMappingInfo nextTMI = next.getKey();
            if (CompilerHelper.generatesSameComplexType(tmi, nextTMI, loader)) {
                return next.getValue();
            }
        }
        return null;
View Full Code Here

                            (Class<T>) mappingInfo.getType(), object);
                    // marshaller.marshal(elt, result);
                    marshaller.marshal(elt, result, mappingInfo);
                }
            } else {
                TypeMappingInfo tmi = null;
                if (object instanceof JAXBElement) {
                    QName q = ((JAXBElement) object).getName();
                    JAXBContext ctx = (JAXBContext) parent.getJAXBContext();

                    Map<TypeMappingInfo, QName> mtq = ctx
View Full Code Here

    return new ArrayList<String>();
  }

  public QName getTypeName(TypeInfo tr) {
    if (typeNames == null) typeNames = jaxbContext.getTypeMappingInfoToSchemaType();
      TypeMappingInfo tmi = infoMap.get(tr);
      return typeNames.get(tmi);
  }
View Full Code Here

            typeSet.add(tmi.getType());
        }
        for (Class<?> clss : bi.contentClasses()) {
            if (!typeSet.contains(clss) && !WrapperComposite.class.equals(clss)) {
                typeSet.add(clss);
                TypeMappingInfo tmi = new TypeMappingInfo();
                tmi.setType(clss);
                typeList.add(tmi);
            }
        }
        TypeMappingInfo[] types = typeList.toArray(new TypeMappingInfo[typeList.size()]);
        properties.put(ECLIPSELINK_OXM_XML_KEY, extMapping);
View Full Code Here

            // one of the problem classes (see below).
            // First do the obvious check: is the instance already in the map?
            if (refs.get(e) != null) {
                continue;
            }
            TypeMappingInfo tmi = null;
            boolean forceLocal = false;
            for (TypeInfo ti : refs.keySet()) {
                // Workaround for runtime duplicates.
                if (e.tagName.equals(ti.tagName)) {
                    if (e.isGlobalElement() && ti.isGlobalElement()) {
                        if (e.type.equals(ti.type)) {
                            // TODO
                            // Eclipselink has issues reusing enums with
                            // multiple marshalers.  This still needs to
                            // be resolved adequately.
                            if (e.type instanceof Class<?>) {
                                Class<?> clz = (Class<?>) e.type;
                                if (clz.isEnum()) {
                                    forceLocal = true;
                                    break;
                                } else {
                                    tmi = refs.get(ti);
                                    break;
                                }
                            } else {
                                tmi = refs.get(ti);
                                break;
                            }
                        } else {
                            // Conflicting types on globals!  May not be
                            // a bullet-proof solution possible.
                            forceLocal = true;
                            break;
                        }
                    }
                }
            }

            if (tmi == null) {
                tmi = new TypeMappingInfo();
                tmi.setXmlTagName(e.tagName);
                tmi.setType((e.getGenericType() != null) ? e.getGenericType() : e.type);
                tmi.setNillable(e.isNillable());
                if (e.getGenericType() != null) {
                    String gts = e.getGenericType().toString();
                    if (gts.startsWith("javax.xml.ws.Holder")) {
                        tmi.setType(e.type);
                    } else if (gts.startsWith("javax.xml.ws.Response")) {
                        tmi.setType(e.type);
                    } else if (gts.startsWith("java.util.concurrent.Future")) {
                        tmi.setType(e.type);
                    }
                    if (Object.class.equals(e.type)) {
                        tmi.setType(e.type);
                        //System.out.println(e.getGenericType().getClass() + " "
                        //    + e.type);
                    }
                    if (tmi.getType() instanceof GenericArrayType) {
                        tmi.setType(typeToClass(tmi.getType(), null));
                    }
                }
                // Filter out non-JAXB annotations.
                Annotation[] aa = e.annotations;
                if (aa != null && aa.length != 0) {
                    List<Annotation> la = new ArrayList<Annotation>();
                    for (Annotation a : aa) {
                        for (Class<?> clz : a.getClass().getInterfaces()) {
                            if (clz.getName().startsWith(
                                    "javax.xml.bind.annotation.")) {
                                la.add(a);
                                break;
                            }
                        }
                    }
                    aa = la.toArray(new Annotation[la.size()]);
                    // System.out.println("filtered: " + la);
                }
                tmi.setAnnotations(aa);
                if (forceLocal) {
                    tmi.setElementScope(ElementScope.Local);
                } else {
                    tmi.setElementScope(e.isGlobalElement() ? ElementScope.Global
                            : ElementScope.Local);
                }
                tmi.setXmlElement(xmlElem);
            }
            refs.put(e, tmi);
        }
        return refs;
    }
View Full Code Here

        if (additionalGlobalElements != null) {
            ElementDeclaration declaration;
            for(Entry<QName, Type> entry : additionalGlobalElements.entrySet()) {
                QName key = entry.getKey();
                Type type = entry.getValue();
                TypeMappingInfo tmi = null;
                if(this.typeToTypeMappingInfo != null) {
                    tmi = this.typeToTypeMappingInfo.get(type);
                }

                if(tmi != null) {
View Full Code Here

              if (namespaceUri == null || namespaceUri.equals(XMLProcessor.DEFAULT)) {
                  namespaceUri = "";
              }
        }

        TypeMappingInfo tmi = nextElement.getTypeMappingInfo();
        Class generatedClass = null;

        JaxbClassLoader loader = getJaxbClassLoader();

        if(tmi != null){
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.jaxb.TypeMappingInfo

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.