Package com.thoughtworks.qdox.model

Examples of com.thoughtworks.qdox.model.BeanProperty


                            "). Have you forgot to set @ejb.bean \"primkey-field\" or @ejb.pk-field ? (" + pkMetadata +
                            ")");
                    }
                }
            } else {
                BeanProperty singleProp = pkMetadata.getProperties()[0];
                pkType = singleProp.getType();
                propName = singleProp.getName();
            }

            BeanProperty prop = null;

            if (pkType != null && propName != null) {
                prop = new BeanProperty(propName);
                prop.setType(pkType);
                JavaMethod getter = new JavaMethod(pkType, getGetterName(prop));
                JavaMethod setter = new JavaMethod(pkType, getSetterName(prop));
                setter.setParameters(new JavaParameter[] {new JavaParameter(pkType, prop.getName())});
                prop.setAccessor(getter);
                prop.setMutator(setter);
            }

            return prop;
        }
View Full Code Here


    private BeanProperty[] getPkProperties(JavaClass javaClass) {
        JavaMethod[] methods = javaClass.getMethods();
        JavaMethod method;
        SortedSet propSet = new TreeSet(new Comparator() {
                    public int compare(Object o1, Object o2) {
                        BeanProperty p1 = (BeanProperty) o1;
                        BeanProperty p2 = (BeanProperty) o2;
                        return p1.getName().compareTo(p2.getName());
                    }
                });

        for (int i = 0; i < methods.length; i++) {
            method = methods[i];
            int metaFlags = ejbUtils.getMethodMetadata(javaClass, method);

            if (EjbUtils.hasFlag(metaFlags, EjbUtils.METADATA_METHOD_PRIMARY_KEY_FIELD)) {
                BeanProperty beanProperty = javaClass.getBeanProperty(method.getPropertyName());

                if (beanProperty != null) {
                    if (propSet.add(beanProperty)) {
                        if (log.isDebugEnabled()) {
                            log.debug(beanProperty.getName() + " was added to the Set");
                        }
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug(beanProperty.getName() +
                                " wasn't added to the Set. There must be already a property with the same name");
                        }
                    }
                } else {
                    String errorMessage = "Unexpected null property for " + method.getPropertyName() + " in " +
View Full Code Here

            retBuf.append(type);
            retBuf.append(", properties=");
            retBuf.append('{');

            for (Iterator iter = propertiesLst.iterator(); iter.hasNext();) {
                BeanProperty prop = (BeanProperty) iter.next();
                retBuf.append(prop.getName());

                if (iter.hasNext()) {
                    retBuf.append(',');
                }
            }
View Full Code Here

            JavaClass metadata = expandedClasses[i];
            if (!shouldGenerate(metadata)) {
                continue;
            }
            ValueObjectMetadata metaVo = getMetaVO(metadata);
            BeanProperty pkProperty = metaVo.getPkProperty();

            JavaField field;
            JavaMethod method;
            JavaClass retVal = createDynamicJavaClass(getDestinationClassname(metadata), getDestinationPackage(metadata), null, getMetadataProvider());
            String[] modifiers = new String[isAbstract(metadata) ? 2 : 1];
            modifiers[0] = "public";
            if (isAbstract(metadata)) {
                modifiers[1] = "abstract";
            }
            retVal.setModifiers(modifiers);
            retVal.setSuperClass(new Type(getExtends(metadata)));

            String[] implementz = getImplements(metadata);
            Type[] implementzTypes = new Type[implementz.length];
            for (int j = 0; j < implementz.length; j++) {
                implementzTypes[j] = new Type(implementz[j]);
            }
            retVal.setImplementz(implementzTypes);

            if (getEjbUtils().isUseSoftLocking(metadata)) {
                field = new JavaField(new Type("int"), "_version");
                field.setModifiers(new String[] { "private" });
                retVal.addField(field);
            }

            ValueObjectFieldMetadata[] nonPkFields = metaVo.getNonPkFields();
            for (int j = 0; j < nonPkFields.length; j++) {
                ValueObjectFieldMetadata vField = nonPkFields[j];
                field = new JavaField(vField.getProperty().getType(), vField.getProperty().getName());
                field.setModifiers(new String[] { "private" });
                retVal.addField(field);
                field = new JavaField(new Type("boolean"), vField.getProperty().getName()+"HasBeenSet");
                field.setModifiers(new String[] { "private" });
                retVal.addField(field);
            }

            ValueObjectFieldMetadata[] pkFields = metaVo.getPkFields();
            for (int j = 0; j < pkFields.length; j++) {
                ValueObjectFieldMetadata vField = pkFields[j];
                field = new JavaField(vField.getProperty().getType(), vField.getProperty().getName());
                field.setModifiers(new String[] { "private" });
                retVal.addField(field);
                field = new JavaField(new Type("boolean"), vField.getProperty().getName()+"HasBeenSet");
                field.setModifiers(new String[] { "private" });
                retVal.addField(field);
            }

            ValueObjectRelationMetadata[] nonCollectionRel = metaVo.getNonCollectionRelations();
            for (int j = 0; j < nonCollectionRel.length; j++) {
                ValueObjectRelationMetadata vRelation = nonCollectionRel[j];
                field = new JavaField(vRelation.getProperty().getType(), vRelation.getProperty().getName());
                field.setModifiers(new String[] { "private" });
                retVal.addField(field);
                field = new JavaField(new Type("boolean"), vRelation.getProperty().getName()+"HasBeenSet");
                field.setModifiers(new String[] { "private" });
                retVal.addField(field);
            }
            ValueObjectRelationMetadata[] collectionRel = metaVo.getCollectionRelations();
            for (int j = 0; j < collectionRel.length; j++) {
                ValueObjectRelationMetadata vRelation = collectionRel[j];
                field = new JavaField(vRelation.getProperty().getType(), vRelation.getProperty().getName());
                field.setModifiers(new String[] { "private" });
                retVal.addField(field);
            }

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

            if (metaVo.isGeneratePKConstructor() && metaVo.hasPk()) {
                if(!isEmpty(nonPkFields) || !metaVo.isSimplePkProperty()) {
                    method = new JavaMethod(getDestinationClassname(metadata));
                    method.setConstructor(true);
                    method.setModifiers(new String[] { "public" });
                    method.setParameters(new JavaParameter[]{new JavaParameter(pkProperty.getType(), pkProperty.getName())});
                    retVal.addMethod(method);
                }
                if(!isEmpty(nonPkFields) && !metaVo.isSimplePkProperty()) {
                    method = new JavaMethod(getDestinationClassname(metadata));
                    method.setConstructor(true);
                    method.setModifiers(new String[] { "public" });
                    JavaParameter[] params = new JavaParameter[nonPkFields.length + 1];
                    params[0] = new JavaParameter(pkProperty.getType(), pkProperty.getName());
                    for (int j = 0; j < nonPkFields.length; j++) {
                        ValueObjectFieldMetadata nonPkField = nonPkFields[j];
                        params[j+1] = new JavaParameter(nonPkField.getProperty().getType(), nonPkField.getProperty().getName());
                    }
                    method.setParameters(params);
                    retVal.addMethod(method);
                }
            }

            ValueObjectFieldMetadata[] fields = metaVo.getFields();
            if (!isEmpty(fields)) {
                method = new JavaMethod(getDestinationClassname(metadata));
                method.setConstructor(true);
                method.setModifiers(new String[] { "public" });
                JavaParameter[] params = new JavaParameter[fields.length];
                for (int j = 0; j < fields.length; j++) {
                    ValueObjectFieldMetadata vField = fields[j];
                    params[j] = new JavaParameter(vField.getProperty().getType(), vField.getProperty().getName());
                }
                method.setParameters(params);
                retVal.addMethod(method);
            }

            if (metaVo.hasPk() && !metaVo.isSimplePkProperty()) {
                method = new JavaMethod(pkProperty.getType(), pkProperty.getAccessor().getName());
                modifiers = new String[metaVo.isFullSynchronization() ? 2 : 1];
                modifiers[0] = "public";
                if (metaVo.isFullSynchronization()) {
                    modifiers[1] = "synchronized";
                }
                method.setModifiers(modifiers);
                retVal.addMethod(method);

                method = new JavaMethod(pkProperty.getMutator().getName());
                modifiers = new String[metaVo.isFullSynchronization() ? 2 : 1];
                modifiers[0] = "public";
                if (metaVo.isFullSynchronization()) {
                    modifiers[1] = "synchronized";
                }
                method.setModifiers(modifiers);
                method.setParameters(new JavaParameter[]{new JavaParameter(pkProperty.getType(), pkProperty.getName())});
                retVal.addMethod(method);
            }

            if (getEjbUtils().isUseSoftLocking(metadata)) {
                method = new JavaMethod(new Type("int"), "getVersion");
View Full Code Here

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

                                            if (log.isDebugEnabled()) {
                                                log.debug(returnType + ": Is a Set or Collection. Using members='" +
                                                    members + "'");
                                            }

                                            if (members == null) {
                                                if (log.isWarnEnabled()) {
                                                    log.warn(EjbUtils.getMessageWithTagLocation(vTag,
                                                            "members is null. Skipping."));
                                                }

                                                continue;
                                            }

                                            relationType = new Type(members);
                                            collectionType = returnType.isA(COLLECTION_TYPE) ? COLLECTION_TYPE : SET_TYPE;
                                        } else {
                                            if (log.isDebugEnabled()) {
                                                log.debug(returnType + ": Using it to find it's match!");
                                            }

                                            relationType = returnType;
                                        }

                                        relationEjb = findBeanByInterface(getOriginalMetadata(), relationType);
                                    }

                                    if (relationEjb == null) {
                                        log.warn("Couldn't find the related Ejb! Skipping.");
                                        continue;
                                    }

                                    ValueObjectRelationMetadata vObjRelation = new ValueObjectRelationMetadata(relationEjb,
                                            collectionType, (vTag.getAggregate() != null), vTag);

                                    if (log.isDebugEnabled()) {
                                        log.debug("Relation is " + vObjRelation);
                                    }

                                    if (vObjRelation.getAggregateName() == null) {
                                        String aggName = vObjRelation.isAggregate() ? "aggregate" : "compose";

                                        if (log.isWarnEnabled()) {
                                            log.warn(EjbUtils.getMessageWithTagLocation(vTag,
                                                    aggName + "-name can't be null. Ignoring."));
                                        }

                                        // Ignore field
                                        continue;
                                    }

                                    // add it
                                    retVal.addRelation(vObjRelation);
                                } else {
                                    // It can only be an aggregate or a composition. Not both!
                                    if (vTag != null && log.isWarnEnabled()) {
                                        log.warn(EjbUtils.getMessageWithTagLocation(vTag,
                                                "Can't be an aggregate and a composition simultaneous! Skipping."));
                                    }

                                    // Skip to next method
                                    }
                            } else {
                                // Simple value-object property
                                ValueObjectFieldMetadata vObjField = new ValueObjectFieldMetadata(prop.getType(),
                                        prop.getName(), metaFlags);
                                retVal.addField(vObjField);
                            }
                        }
                    }
                }
View Full Code Here

            this.isAggregate = isAggregate;
            this.vTag = vTag;
        }

        public BeanProperty getProperty() {
            BeanProperty retVal;
            String propName;
            Type propType;

            if (isCollection()) {
                propName = getAggregateNamePlural();
                propType = getCollectionType();
            } else {
                propName = getAggregateName();
                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

        private final BeanProperty property;
        private final int metaFlags;

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

                }
            }
        }

        if (beanTag != null && beanTag.getPrimkeyField() != null) {
            BeanProperty prop = javaClass.getBeanProperty(beanTag.getPrimkeyField());

            try {
                if (prop == null || prop.getAccessor() == null) {
                    throw getErrorWithTagLocation(beanTag,
                        "Could not find getter for prim-key-field: " + beanTag.getPrimkeyField());
                }

                // Ok, now this must be that accessor for the key
                if (method == prop.getAccessor()) {
                    retVal |= METADATA_METHOD_PRIMARY_KEY_FIELD;
                }
            } catch (Error e) {
                log.error(e.getMessage());
                throw e;
View Full Code Here

TOP

Related Classes of com.thoughtworks.qdox.model.BeanProperty

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.