Package org.eclipse.persistence.jaxb.javamodel

Examples of org.eclipse.persistence.jaxb.javamodel.JavaMethod


    public JavaClass[] processObjectFactory(JavaClass objectFactoryClass, ArrayList<JavaClass> classes) {
        Collection methods = objectFactoryClass.getDeclaredMethods();
        Iterator methodsIter = methods.iterator();
        NamespaceInfo namespaceInfo = getNamespaceInfoForPackage(objectFactoryClass);
        while (methodsIter.hasNext()) {
            JavaMethod next = (JavaMethod) methodsIter.next();
            if (next.getName().startsWith("create")) {
                JavaClass type = next.getReturnType();
                if (type.getName().equals("javax.xml.bind.JAXBElement")) {
                    type = (JavaClass) next.getReturnType().getActualTypeArguments().toArray()[0];
                } else {
                    this.factoryMethods.put(next.getReturnType().getRawName(), next);
                }
                if (helper.isAnnotationPresent(next, XmlElementDecl.class)) {
                    XmlElementDecl elementDecl = (XmlElementDecl) helper.getAnnotation(next, XmlElementDecl.class);
                    String url = elementDecl.namespace();
                    if ("##default".equals(url)) {
View Full Code Here


        adapterClass = adapterCls;
        JavaClass newType  = helper.getJavaClass(Object.class);
               
        // look for marshal method
        for (Iterator<JavaMethod> methodIt = adapterClass.getDeclaredMethods().iterator(); methodIt.hasNext(); ) {
            JavaMethod method = methodIt.next();
            if (method.getName().equals("marshal")) {
              newType = (JavaClass) method.getReturnType();
                break;
            }
        }
        setType(newType);
    }
View Full Code Here

        JavaClass newType  = helper.getJavaClass(Object.class);
        ArrayList<JavaMethod> marshalMethods = new ArrayList<JavaMethod>();

        // Look for marshal method
        for (Iterator<JavaMethod> methodIt = adapterClass.getMethods().iterator(); methodIt.hasNext(); ) {
            JavaMethod method = methodIt.next();
            if (method.getName().equals(MARSHAL_METHOD_NAME)) {
                JavaClass returnType = method.getReturnType();
                // Try and find a marshal method where Object is not the return type,
                // to avoid processing an inherited default marshal method
                if (!returnType.getQualifiedName().equals(newType.getQualifiedName())) {
                    if (!returnType.isInterface()) {
                        newType = (JavaClass) method.getReturnType();
                        setTypeFromAdapterClass(newType, method.getParameterTypes()[0]);
                        return;
                    }
                }
                // Found a marshal method with an Object return type; add
                // it to the list in case we need to process it later
                marshalMethods.add(method);
            }
        }
        // If there are no marshal methods to process just set type
        // and original type, then return
        if (marshalMethods.size() == 0) {
            setTypeFromAdapterClass(newType, null);
            return;
        }
        // At this point we didn't find a marshal method with a non-Object return type
        for (JavaMethod method : marshalMethods) {
            JavaClass paramType = method.getParameterTypes()[0];
            // look for non-Object parameter type
            if (!paramType.getQualifiedName().equals(newType.getQualifiedName())) {
                setTypeFromAdapterClass(newType, paramType);
                return;
            }
View Full Code Here

            prop.setXmlPath(xpath);
            prop.setSchemaName(new QName(pname));
            // figure out the type based on transformer method return type
            JavaClass jType = null;
            JavaClass jClass = null;
            JavaMethod jMethod = null;
            String methodName;
            if (writeTransformer.isSetTransformerClass()) {
                // handle transformer class
                try {
                    jClass = helper.getJavaClass(writeTransformer.getTransformerClass());
                } catch (JAXBException x) {
                    throw JAXBException.transformerClassNotFound(writeTransformer.getTransformerClass());
                }
                methodName = BUILD_FIELD_VALUE_METHOD;
                jMethod = jClass.getDeclaredMethod(methodName, new JavaClass[] { helper.getJavaClass(Object.class), helper.getJavaClass(String.class), helper.getJavaClass(Session.class) });
                if (jMethod == null) {
                    throw JAXBException.noSuchWriteTransformationMethod(methodName);
                }
                jType = jMethod.getReturnType();
            } else {
                // handle method
                // here it is assumed that the JavaModel is aware of the TypeInfo's class, hence jClass cannot be null
                jClass = helper.getJavaClass(typeInfo.getJavaClassName());
                methodName = writeTransformer.getMethod();
                // the method can have 0 args or 1 arg (either AbstractSession or Session)
                // first check 0 arg
                jMethod = jClass.getDeclaredMethod(methodName, new JavaClass[] {});
                if (jMethod == null) {
                    // try AbstractSession
                    jMethod = jClass.getDeclaredMethod(methodName, new JavaClass[] { helper.getJavaClass(AbstractSession.class) });
                    if (jMethod == null) {
                        // try Session
                        jMethod = jClass.getDeclaredMethod(methodName, new JavaClass[] { helper.getJavaClass(Session.class) });
                        if (jMethod == null) {
                            throw JAXBException.noSuchWriteTransformationMethod(methodName);
                        }
                    }
                }
                jType = jMethod.getReturnType();
            }
            prop.setType(jType);
            props.add(prop);
        }
        addToSchemaType(typeInfo, props, compositor, type, schema);
View Full Code Here

                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;
                        }
                    }
View Full Code Here

     *
     * @param javaClass
     * @param info
     */
    private void processFactoryMethods(JavaClass javaClass, TypeInfo info) {
        JavaMethod factoryMethod = this.factoryMethods.get(javaClass.getRawName());
        if (factoryMethod != null) {
            // set up factory method info for mappings.
            info.setFactoryMethodName(factoryMethod.getName());
            info.setObjectFactoryClassName(factoryMethod.getOwningClass().getQualifiedName());
            JavaClass[] paramTypes = factoryMethod.getParameterTypes();
            if (paramTypes != null && paramTypes.length > 0) {
                String[] paramTypeNames = new String[paramTypes.length];
                for (int i = 0; i < paramTypes.length; i++) {
                  if(shouldGenerateTypeInfo(paramTypes[i])){
                           JavaClass[] jClassArray = new JavaClass[] { paramTypes[i] };
View Full Code Here

        if (factoryClassName.equals("javax.xml.bind.annotation.XmlType.DEFAULT")) {
            if (factoryMethodName != null && !factoryMethodName.equals(EMPTY_STRING)) {
                // factory method applies to the current class - verify method
                // exists
                JavaMethod method = javaClass.getDeclaredMethod(factoryMethodName, new JavaClass[] {});
                if (method == null) {
                    throw org.eclipse.persistence.exceptions.JAXBException.factoryMethodNotDeclared(factoryMethodName, javaClass.getName());
                }
                info.setFactoryMethodName(factoryMethodName);
            }
View Full Code Here

        // keep track of property names to avoid processing the same property
        // twice (for getter and setter)
        ArrayList<String> propertyNames = new ArrayList<String>();
        for (int i = 0; i < propertyMethods.size(); i++) {
            boolean isPropertyTransient = false;
            JavaMethod nextMethod = propertyMethods.get(i);
            String propertyName = EMPTY_STRING;

            JavaMethod getMethod;
            JavaMethod setMethod;

            JavaMethod propertyMethod = null;

            if (!nextMethod.getName().startsWith(SET_STR)) {
                if (nextMethod.getName().startsWith(GET_STR)) {
                    propertyName = nextMethod.getName().substring(3);
                } else if (nextMethod.getName().startsWith(IS_STR)) {
View Full Code Here

        Collection methods = objectFactoryClass.getDeclaredMethods();
        Iterator methodsIter = methods.iterator();
        PackageInfo packageInfo = getPackageInfoForPackage(objectFactoryClass);
        while (methodsIter.hasNext()) {
            JavaMethod next = (JavaMethod) methodsIter.next();
            if (next.getName().startsWith(CREATE)) {
                JavaClass type = next.getReturnType();
                if (JAVAX_XML_BIND_JAXBELEMENT.equals(type.getName())) {
                  Object[] actutalTypeArguments = type.getActualTypeArguments().toArray();
                    if (actutalTypeArguments.length == 0) {
                        type = helper.getJavaClass(Object.class);
                    } else {
                        type = (JavaClass) next.getReturnType().getActualTypeArguments().toArray()[0];
                    }
                    processXmlElementDecl(type, next, packageInfo, elemDecls);
                }else if (helper.getJavaClass(JAXBElement.class).isAssignableFrom(type)) {                                  
                  this.factoryMethods.put(next.getReturnType().getRawName(), next);
                  processXmlElementDecl(type, next, packageInfo, elemDecls);
                } else {
                    this.factoryMethods.put(next.getReturnType().getRawName(), next);
                }
                if (!helper.isBuiltInJavaType(type) && !helper.classExistsInArray(type, classes)) {
                    classes.add(type);
                }
            }
View Full Code Here

            mapping.getInverseReferenceMapping().setAttributeName(property.getInverseReferencePropertyName());
            JavaClass backPointerPropertyType = null;
            if (property.getInverseReferencePropertyGetMethodName() != null && property.getInverseReferencePropertySetMethodName() != null && !property.getInverseReferencePropertyGetMethodName().equals("") && !property.getInverseReferencePropertySetMethodName().equals("")) {
                mapping.getInverseReferenceMapping().setGetMethodName(property.getInverseReferencePropertySetMethodName());
                mapping.getInverseReferenceMapping().setSetMethodName(property.getInverseReferencePropertySetMethodName());
                JavaMethod getMethod = referenceClass.getDeclaredMethod(mapping.getInverseReferenceMapping().getGetMethodName(), new JavaClass[]{});
                if (getMethod != null) {
                    backPointerPropertyType = getMethod.getReturnType();
                }
            } else {
                JavaField backpointerField = referenceClass.getDeclaredField(property.getInverseReferencePropertyName());
                if (backpointerField != null) {
                    backPointerPropertyType = backpointerField.getResolvedType();
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.jaxb.javamodel.JavaMethod

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.