Package com.thoughtworks.qdox.model

Examples of com.thoughtworks.qdox.model.JavaMethod


        if (!shouldGenerate(metadata)) {
            return null;
        }

        JavaField field;
        JavaMethod method;
        JavaClass retVal = createDynamicJavaClass(getDestinationClassname(metadata), getDestinationPackage(metadata), null, getMetadataProvider());
        retVal.setInterface(true);
        retVal.setModifiers(new String[]{"public"});
        String[] extendz = getExtends(metadata);
        Type[] extendzTypes = new Type[extendz.length];
        for (int j = 0; j < extendz.length; j++) {
            extendzTypes[j] = new Type(extendz[j]);
        }
        retVal.setImplementz(extendzTypes);

        field = new JavaField(new Type("java.lang.String"), ejbHomeUtils.getCompleteNameConst());
        field.setModifiers(new String[]{"public","static","final"});
        retVal.addField(field);

        field = new JavaField(new Type("java.lang.String"), ejbHomeUtils.getJndiNameConst());
        field.setModifiers(new String[]{"public","static","final"});
        retVal.addField(field);

        Collection methods = getCreateMethods(metadata);
        for (Iterator iter = methods.iterator(); iter.hasNext();) {
            method = new DuplicatedJavaMethod((JavaMethod)iter.next());
            method.setModifiers(new String[0]);
            retVal.addMethod(method);
        }

        if (ejbUtils.isEntityBean(metadata)) {
            methods = getFinderMethods(metadata);
            for (Iterator iter = methods.iterator(); iter.hasNext();) {
                method = new DuplicatedJavaMethod((JavaMethod)iter.next());
                method.setModifiers(new String[0]);
                retVal.addMethod(method);
            }
        }
        methods = getHomeMethods(metadata);
        for (Iterator iter = methods.iterator(); iter.hasNext();) {
            method = new DuplicatedJavaMethod((JavaMethod)iter.next());
            method.setModifiers(new String[0]);
            retVal.addMethod(method);
        }

        return new JavaClass[]{retVal};
    }
View Full Code Here


                // Lets start rolling
                //            retVal.setUpdatable(valueTag.isUpdatable());
                // TODO: Are we supporting hierarchaly generated files
                // similar to PrimaryKeys ?
                JavaMethod[] methods = javaClass.getMethods(true);
                JavaMethod method;

                for (int i = 0; i < methods.length; i++) {
                    method = methods[i];

                    if (log.isTraceEnabled()) {
                        // log.trace(method.getName() + " = " + method);
                        log.trace(method.getName() + " seeing if this is a value-object-field");
                    }

                    // Obtain extra method flags
                    int metaFlags = ejbUtils.getMethodMetadata(javaClass, method);

                    if (EjbUtils.hasFlag(metaFlags, EjbUtils.METADATA_METHOD_PRIMARY_KEY_FIELD) ||
                            EjbUtils.hasFlag(metaFlags, EjbUtils.METADATA_METHOD_PERSISTENCE_FIELD) ||
                            EjbUtils.hasFlag(metaFlags, EjbUtils.METADATA_METHOD_RELATION_FIELD)) {
                        if (log.isDebugEnabled()) {
                            log.debug(method.getName() +
                                " is candidate for checking. It's a persistence field, relation field or primary key field");
                        }

                        // Por aqui o resto das valida��es e l�gica
                        boolean isValueObjectField = isSelectedValueObjectField(valueTag.getMatch(), method);

                        // Primary key field must ALLWAYS be included ! (or then they must be checked if ....)
                        isValueObjectField = isValueObjectField ||
                            EjbUtils.hasFlag(metaFlags, EjbUtils.METADATA_METHOD_PRIMARY_KEY_FIELD);

                        if (isValueObjectField) {
                            EjbValueObjectFieldTag vTag = findMatchedTag(valueTag.getMatch(), method);
                            BeanProperty prop = javaClass.getBeanProperty(method.getPropertyName(), true);

                            if (log.isDebugEnabled()) {
                                log.debug(method.getName() + " is a value-object-field: matches or is a pk-field.");
                            }

                            // XXX: Todo, if we have a relation found by the RelationManager, then we must have
                            // it's treatment as such, or should be ignored
                            // Maybe just check if is a EjbUtils.METADATA_METHOD_RELATION_FIELD
                            Relation relation = getRelationManager().getRelationFor(method, javaClass);

                            if ((relation != null) ||
                                    ((vTag != null) && ((vTag.getAggregate() != null) || (vTag.getCompose() != null)))) {
                                // This is a value-object relation
                                // vTag must be non-null, because we need values from it
                                if ((vTag != null) && ((vTag.getAggregate() != null) ^ (vTag.getCompose() != null))) {
                                    JavaClass relationEjb = null;
                                    Type collectionType = null;

                                    if (relation != null) {
                                        if (!method.equals(relation.getLeftMethod())) {
                                            log.debug(
                                                "Current method doesn't match relations' left method. Reversing relation");
                                            relation = relation.reverse();

                                            if (log.isDebugEnabled()) {
                                                log.debug("Reversed relation is relation=" + relation);
                                            }
                                        }

                                        if (log.isDebugEnabled()) {
                                            log.debug("Using relation information. relation=" + relation);
                                            log.debug("1# Left bean=" +
                                                ((relation.getLeftBean() != null)
                                                ? relation.getLeftBean().getFullyQualifiedName() : null));
                                            log.debug("1# Rigth bean=" +
                                                ((relation.getRightBean() != null)
                                                ? relation.getRightBean().getFullyQualifiedName() : null));
                                        }

                                        String relationEjbName = relation.getRightEJBName();
                                        relationEjb = getBeanResolver().findEjbByName(relationEjbName);
                                        collectionType = relation.getLeftMethod().getReturns();
                                    } else {
                                        log.debug("We don't have relation information for this method");
                                        Type returnType = method.getReturns();
                                        Type relationType = null;

                                        if (returnType.isA(COLLECTION_TYPE) || returnType.isA(SET_TYPE)) {
                                            String members = vTag.getMembers();
View Full Code Here

                propType = new Type(getAggregate());
            }

            retVal = new BeanProperty(propName);
            retVal.setType(propType);
            JavaMethod getter = new JavaMethod(propType, getGetterName(retVal));
            JavaMethod setter = new JavaMethod(propType, getSetterName(retVal));
            setter.setParameters(new JavaParameter[] {new JavaParameter(propType, propName)});
            retVal.setAccessor(getter);
            retVal.setMutator(setter);
            return retVal;
        }
View Full Code Here

        public ValueObjectFieldMetadata(Type propertyType, String propertyName, int metaFlags) {
            this.metaFlags = metaFlags;
            this.property = new BeanProperty(propertyName);
            this.property.setType(propertyType);
            JavaMethod getter = new JavaMethod(propertyType, getGetterName(this.property));
            JavaMethod setter = new JavaMethod(propertyType, getSetterName(this.property));
            setter.setParameters(new JavaParameter[] {new JavaParameter(propertyType, propertyName)});
            this.property.setAccessor(getter);
            this.property.setMutator(setter);
        }
View Full Code Here

        if (!shouldGenerate(metadata)) {
            return null;
        }

        JavaField field;
        JavaMethod method;
        JavaClass retVal = createDynamicJavaClass(getDestinationClassname(metadata),
                getDestinationPackage(metadata), null, getMetadataProvider());
        retVal.setModifiers(new String[] { "public" });
        if (getEjbUtils().isMessageDrivenBean(metadata)) {
            field = new JavaField(new Type(String.class.getName()), "DESTINATION_JNDI_NAME");
            field.setModifiers(new String[] { "private", "final", "static" });
            retVal.addField(field);
            field = new JavaField(new Type(String.class.getName()), "CONNECTION_FACTORY_JNDI_NAME");
            field.setModifiers(new String[] { "private", "final", "static" });
            retVal.addField(field);
        }
        if (isCachehomes()) {
            if (getEjbUtils().isMessageDrivenBean(metadata)) {
                field = new JavaField(new Type("javax.jms.Queue"), "cachedQueue");
                field.setModifiers(new String[] { "private", "static" });
                retVal.addField(field);
                field = new JavaField(new Type("javax.jms.QueueConnectionFactory"), "cachedConnectionFactory");
                field.setModifiers(new String[] { "private", "static" });
                retVal.addField(field);
            } else {
                if (hasRemoteView(metadata)) {
                    field = new JavaField(new Type(getRemoteHomeInterfacePlugin().getVirtualType(metadata)
                            .toString()), "cachedRemoteHome");
                    field.setModifiers(new String[] { "private", "static" });
                    retVal.addField(field);
                }
                if (hasLocalView(metadata)) {
                    field = new JavaField(new Type(getLocalHomeInterfacePlugin().getVirtualType(metadata)
                            .toString()), "cachedHome");
                    field.setModifiers(new String[] { "private", "static" });
                    retVal.addField(field);
                }
            }
        }

        method = new JavaMethod(getDestinationClassname(metadata));
        method.setConstructor(true);
        method.setModifiers(new String[] { "private" });
        retVal.addMethod(method);

        if (getEjbUtils().isMessageDrivenBean(metadata)) {
            method = new JavaMethod("getQueue");
            method.setModifiers(new String[] { "public", "static" });
            method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
            method.setReturns(new Type("javax.jms.Queue"));
            retVal.addMethod(method);
            method = new JavaMethod("getQueue");
            method.setModifiers(new String[] { "public", "static" });
            method.setParameters(new JavaParameter[] { new JavaParameter(new Type("java.util.Hashtable"),
                    "environment") });
            method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
            method.setReturns(new Type("javax.jms.Queue"));
            retVal.addMethod(method);
            method = new JavaMethod("getQueueConnection");
            method.setModifiers(new String[] { "public", "static" });
            method.setExceptions(new Type[] { new Type("javax.naming.NamingException"),
                    new Type("javax.jms.JMSException") });
            method.setReturns(new Type("javax.jms.QueueConnection"));
            retVal.addMethod(method);
            method = new JavaMethod("getQueueConnection");
            method.setModifiers(new String[] { "public", "static" });
            method.setParameters(new JavaParameter[] { new JavaParameter(new Type("java.util.Hashtable"),
                    "environment") });
            method.setExceptions(new Type[] { new Type("javax.naming.NamingException"),
                    new Type("javax.jms.JMSException") });
            method.setReturns(new Type("javax.jms.QueueConnection"));
            retVal.addMethod(method);
        } else {
            if (hasRemoteView(metadata)) {
                method = new JavaMethod("getHome");
                method.setModifiers(new String[] { "public", "static" });
                method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
                method
                        .setReturns(new Type(getRemoteHomeInterfacePlugin().getVirtualType(metadata)
                                .toString()));
                retVal.addMethod(method);
                method = new JavaMethod("getHome");
                method.setModifiers(new String[] { "public", "static" });
                method.setParameters(new JavaParameter[] { new JavaParameter(new Type("java.util.Hashtable"),
                        "env") });
                method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
                method
                        .setReturns(new Type(getRemoteHomeInterfacePlugin().getVirtualType(metadata)
                                .toString()));
                retVal.addMethod(method);
            }
            if (hasLocalView(metadata)) {
                method = new JavaMethod("getLocalHome");
                method.setModifiers(new String[] { "public", "static" });
                method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
                method
                        .setReturns(new Type(getLocalHomeInterfacePlugin().getVirtualType(metadata)
                                .toString()));
                retVal.addMethod(method);
                method = new JavaMethod("getLocalHome");
                method.setModifiers(new String[] { "public", "static" });
                method.setParameters(new JavaParameter[] { new JavaParameter(new Type("java.util.Hashtable"),
                        "env") });
                method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
                method
                        .setReturns(new Type(getLocalHomeInterfacePlugin().getVirtualType(metadata)
                                .toString()));
                retVal.addMethod(method);
            }
            method = new JavaMethod("lookupHome");
            method.setModifiers(new String[] { "private", "static" });
            method.setParameters(new JavaParameter[] {
                    new JavaParameter(new Type("java.util.Hashtable"), "env"),
                    new JavaParameter(new Type("java.lang.String"), "jndiName"),
                    new JavaParameter(new Type("java.lang.Class"), "narrowTo") });
            method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
            method.setReturns(new Type("java.lang.Object"));
            retVal.addMethod(method);
        }

        method = new JavaMethod("lookup");
        method.setModifiers(new String[] { "public", "static" });
        method.setParameters(new JavaParameter[] { new JavaParameter(new Type("java.util.Hashtable"), "env"),
                new JavaParameter(new Type("java.lang.String"), "jndiName") });
        method.setExceptions(new Type[] { new Type("javax.naming.NamingException") });
        method.setReturns(new Type("java.lang.Object"));
        retVal.addMethod(method);

        if (isIncludeGUID()) {
            method = new JavaMethod("generateGUID");
            method.setModifiers(new String[] { "public", "final", "static" });
            method.setParameters(new JavaParameter[] {

            new JavaParameter(new Type("java.lang.Object"), "o") });

            method.setReturns(new Type("java.lang.String"));
            retVal.addMethod(method);
            field = new JavaField(new Type("java.lang.String"), "hexServerIP");
            field.setModifiers(new String[] { "private", "static" });
            retVal.addField(field);
            field = new JavaField(new Type("java.security.SecureRandom"), "seeder");
            field.setModifiers(new String[] { "private", "final", "static" });
            retVal.addField(field);
            method = new JavaMethod("hexFormat");
            method.setModifiers(new String[] { "private", "static" });
            method.setParameters(new JavaParameter[] {

            new JavaParameter(new Type("byte", 1), "value"), new JavaParameter(new Type("int"), "length") });

            method.setReturns(new Type("java.lang.String"));
            retVal.addMethod(method);
            method = new JavaMethod("hexFormat");
            method.setModifiers(new String[] { "private", "static" });
            method.setParameters(new JavaParameter[] {

            new JavaParameter(new Type("int"), "value"), new JavaParameter(new Type("int"), "length") });

            method.setReturns(new Type("java.lang.String"));
            retVal.addMethod(method);
        }

        return new JavaClass[] { retVal };
    }
View Full Code Here

        // Select all public abstract methods started by "ejbSelect" with a non-void
        // return type
        return CollectionUtils.select(Arrays.asList(clazz.getMethods(true)),
            new Predicate() {
                public boolean evaluate(Object object) {
                    JavaMethod method = (JavaMethod) object;
                    int methodType = getMethodType(method);
                    boolean retVal = hasFlag(methodType, IFACE_METHOD_SELECT);
                    retVal = retVal && method.isAbstract();
                    retVal = retVal && method.isPublic();
                    return retVal;
                }
            });
    }
View Full Code Here

    public JavaMethod getMethodBySignature(String signature) {
        Matcher matcher = methodPattern.matcher(signature);

        if (matcher.matches()) {
            JavaMethod method = new JavaMethod(new Type(matcher.group(1)), matcher.group(2));

            // Now let's find out the arguments
            matcher = paramPattern.matcher(matcher.group(3));
            int beginIdx = 0;
            int count = 0;
            String paramType = null;
            String paramName = null;
            List paramLst = new ArrayList();

            while (matcher.find(beginIdx)) {
                int paramDim = 0;

                if (matcher.group(1) != null) {
                    paramType = matcher.group(2) + (matcher.group(4) != null ? matcher.group(4) : "");
                    paramName = matcher.group(3);
                } else {
                    paramType = matcher.group(6);
                    paramName = "_arg" + (count++);
                }

                // Now we need to parse paramType for it's dimensions
                Matcher dMatcher = dimensionPattern.matcher(paramType);

                if (dMatcher.find()) {
                    paramType = paramType.substring(0, dMatcher.start());
                    paramDim = 1;

                    while (dMatcher.find(dMatcher.end())) {
                        paramDim++;
                    }
                }

                paramLst.add(new JavaParameter(new Type(paramType, paramDim), paramName));
                beginIdx = matcher.end();
            }

            method.setParameters((JavaParameter[]) paramLst.toArray(new JavaParameter[0]));
            return method;
        }

        throw new Error("Invalid finder signature '" + signature + "'");
    }
View Full Code Here

            case IFACE_METHOD_HOME:
                removeString = "ejbHome";
                break;
        }

        JavaMethod retVal = method;

        if (removeString != null) {
            retVal = removeFromMethodName(method, removeString);
        }
View Full Code Here

            retLst.addAll(MethodPermission.unroll(permType, permTag.getRoleNames()));
        }

        // Now let's dig into method level ejb.permission tags
        JavaMethod[] methods = javaClass.getMethods();
        JavaMethod method;

        for (int j = 0; j < methods.length; j++) {
            tags = (method = methods[j]).getTagsByName(TagLibrary.EJB_PERMISSION);

            for (int k = 0; k < tags.length; k++) {
View Full Code Here

        throws Exception
    {
        final DNAAttributeInterceptor interceptor = new DNAAttributeInterceptor();
        final Attribute attribute = new Attribute( "ignored" );
        final Attribute result =
            interceptor.processMethodAttribute( new JavaMethod(), attribute );
        assertNotNull( "attribute", result );
        assertEquals( "attribute.name", "ignored", result.getName() );
        assertEquals( "attribute.value", null, result.getValue() );
        assertEquals( "attribute.parameterCount", 0, result.getParameterCount() );
    }
View Full Code Here

TOP

Related Classes of com.thoughtworks.qdox.model.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.