Package org.codehaus.jam

Examples of org.codehaus.jam.JProperty


            //  typeTable.addComplexScheam(name, complexType.getQName());
            typeTable.addComplexSchema(name, eltOuter.getQName());

            JProperty [] properties = javaType.getDeclaredProperties();
            for (int i = 0; i < properties.length; i++) {
                JProperty property = properties[i];
                String propertyName = property.getType().getQualifiedName();
                boolean isArryType = property.getType().isArrayType();
                if (isArryType) {
                    propertyName = property.getType().getArrayComponentType().getQualifiedName();
                }
                if (typeTable.isSimpleType(propertyName)) {
                    XmlSchemaElement elt1 = new XmlSchemaElement();
                    elt1.setName(getCorrectName(property.getSimpleName()));
                    elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(propertyName));
                    sequence.getItems().add(elt1);
                    if (isArryType) {
                        elt1.setMaxOccurs(Long.MAX_VALUE);
                        elt1.setMinOccurs(0);
                    }
                } else {
                    if (isArryType) {
                        generateSchema(property.getType().getArrayComponentType());
                    } else {
                        generateSchema(property.getType());
                    }
                    XmlSchemaElement elt1 = new XmlSchemaElement();
                    elt1.setName(getCorrectName(property.getSimpleName()));
                    elt1.setSchemaTypeName(typeTable.getComplexSchemaType(propertyName));
                    sequence.getItems().add(elt1);
                    if (isArryType) {
                        elt1.setMaxOccurs(Long.MAX_VALUE);
                        elt1.setMinOccurs(0);
View Full Code Here


            while (jClassIter.hasNext()) {
                jClass = (JClass) jClassIter.next();

            }
            // properties from JAM
            JProperty properties [] = jClass.getDeclaredProperties();

            BeanInfo beanInfo = Introspector.getBeanInfo(beanObject.getClass());
            PropertyDescriptor [] propDescs = beanInfo.getPropertyDescriptors();
            HashMap propertMap = new HashMap();
            for (int i = 0; i < propDescs.length; i++) {
                PropertyDescriptor propDesc = propDescs[i];
                propertMap.put(propDesc.getName(), propDesc);
            }
            ArrayList object = new ArrayList();
            for (int i = 0; i < properties.length; i++) {
                JProperty property = properties[i];
                PropertyDescriptor propDesc = (PropertyDescriptor) propertMap.get(
                        SchemaGenerator.getCorrectName(property.getSimpleName()));
                if (propDesc == null) {
                    // JAM does bad thing so I need to add this
                    continue;
                }
                Class ptype = propDesc.getPropertyType();
View Full Code Here

                                                   XmlSchemaComplexType complexType,
                                                   XmlSchema xmlSchema) throws Exception {
        JProperty[] properties = javaType.getDeclaredProperties();

        for (int i = 0; i < properties.length; i++) {
            JProperty property = properties[i];
            String propertyName = property.getType().getQualifiedName();
            boolean isArryType = property.getType().isArrayType();
            if (isArryType) {
                propertyName = property.getType().getArrayComponentType().getQualifiedName();
            }

            if (typeTable.isSimpleType(propertyName)) {
                XmlSchemaElement elt1 = new XmlSchemaElement();
                elt1.setName(getCorrectName(property.getSimpleName()));
                elt1.setSchemaTypeName(typeTable.getSimpleSchemaTypeName(propertyName));
                ((XmlSchemaGroupBase) complexType.getParticle()).getItems().add(elt1);
                if (isArryType) {
                    elt1.setMaxOccurs(Long.MAX_VALUE);
                    elt1.setMinOccurs(0);
                }
            } else {
                QName schemaTypeName = null;
                if (isArryType) {
                    schemaTypeName = generateSchema(property.getType().getArrayComponentType());
                } else {
                    schemaTypeName = generateSchema(property.getType());
                }

                XmlSchemaElement elt1 = new XmlSchemaElement();
                elt1.setName(getCorrectName(property.getSimpleName()));
                elt1.setSchemaTypeName(schemaTypeName);
                ((XmlSchemaGroupBase) complexType.getParticle()).getItems().add(elt1);

                if (isArryType) {
                    elt1.setMaxOccurs(Long.MAX_VALUE);
View Full Code Here

                                            "elementName");
            }

            // properties from JAM
            ArrayList propertyList = new ArrayList();
            JProperty properties [] = jClass.getDeclaredProperties();
            for (int i = 0; i < properties.length; i++) {
                JProperty property = properties[i];
                propertyList.add(property);
            }
            JClass supClass = jClass.getSuperclass();
            while (!"java.lang.Object".equals(supClass.getQualifiedName())) {
                properties = supClass.getDeclaredProperties();
                for (int i = 0; i < properties.length; i++) {
                    JProperty property = properties[i];
                    propertyList.add(property);
                }
                supClass = supClass.getSuperclass();
            }
            properties = new JProperty[propertyList.size()];
            for (int i = 0; i < propertyList.size(); i++) {
                JProperty jProperty = (JProperty)propertyList.get(i);
                properties[i] = jProperty;
            }
            Arrays.sort(properties);
            BeanInfo beanInfo = Introspector.getBeanInfo(beanObject.getClass());
            PropertyDescriptor [] propDescs = beanInfo.getPropertyDescriptors();
            HashMap propertMap = new HashMap();
            for (int i = 0; i < propDescs.length; i++) {
                PropertyDescriptor propDesc = propDescs[i];
                propertMap.put(propDesc.getName(), propDesc);
            }
            ArrayList object = new ArrayList();
            for (int i = 0; i < properties.length; i++) {
                JProperty property = properties[i];
                PropertyDescriptor propDesc = (PropertyDescriptor)propertMap.get(
                        getCorrectName(property.getSimpleName()));
                if (propDesc == null) {
                    // JAM does bad thing so I need to add this
                    continue;
                }
                Class ptype = propDesc.getPropertyType();
View Full Code Here

            return true;
        }

        List properties = getProperties();
        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty) iter.next();
            JClass propertyType = property.getType();
            String type = propertyType.getSimpleName();

            if( !( type.equals("byte") ) &&
                !( type.equals("char") ) &&
                !( type.equals("short") ) &&
View Full Code Here

            return true;
        }

        List properties = getProperties();
        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty) iter.next();
            JClass propertyType = property.getType();
            String type = propertyType.getSimpleName();

            if( !type.equals("boolean") ) {

                return true;
View Full Code Here

    protected int generateTightMarshal1Body(PrintWriter out) {
        List properties = getProperties();
        int baseSize = 0;
        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty) iter.next();
            JAnnotation annotation = property.getAnnotation("openwire:property");
            JAnnotationValue size = annotation.getValue("size");
            JClass propertyType = property.getType();
            String type = propertyType.getSimpleName();
            String getter = "info->" + property.getGetter().getSimpleName() + "()";

            if (type.equals("boolean")) {
                out.println("        bs->writeBoolean( " + getter + " );");
            }
            else if (type.equals("byte")) {
View Full Code Here

    protected void generateTightMarshal2Body(PrintWriter out) {
        List properties = getProperties();
        int count = 0;
        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty) iter.next();
            JAnnotation annotation = property.getAnnotation("openwire:property");
            JAnnotationValue size = annotation.getValue("size");
            JClass propertyType = property.getType();
            String type = propertyType.getSimpleName();
            String getter = "info->" + property.getGetter().getSimpleName() + "()";
            count++;

            if (type.equals("boolean")) {
                out.println("        bs->readBoolean();");
            }
View Full Code Here


    protected void generateLooseMarshalBody(PrintWriter out) {
        List properties = getProperties();
        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty) iter.next();
            JAnnotation annotation = property.getAnnotation("openwire:property");
            JAnnotationValue size = annotation.getValue("size");
            JClass propertyType = property.getType();
            String type = propertyType.getSimpleName();
            String getter = "info->" + property.getGetter().getSimpleName() + "()";

            if( type.equals( "boolean" ) ) {
                out.println("        dataOut->writeBoolean( " + getter + " );");
            }
            else if( type.equals("byte") ) {
View Full Code Here

out.println(""+className+"::"+className+"()");
out.println("{");

        List properties = getProperties();
        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty) iter.next();
            String type = toCppType(property.getType());
            String value = toCppDefaultValue(property.getType());
            String propertyName = property.getSimpleName();
            String parameterName = decapitalize(propertyName);

            if( !type.startsWith("std::vector") ) {
out.println("    this->"+parameterName+" = "+value+";");
            }
        }
out.println("}");
out.println("");
out.println("////////////////////////////////////////////////////////////////////////////////");
out.println(""+className+"::~"+className+"()");
out.println("{");

    for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
        JProperty property = (JProperty) iter.next();
        String type = toCppType(property.getType());
        String propertyName = property.getSimpleName();
        String parameterName = decapitalize(propertyName);

        if( property.getType().isPrimitiveType() ||
            property.getType().getSimpleName().equals("String") ) {
            continue;
        }

        if( !type.startsWith("std::vector" ) ) {
out.println("    delete this->" + parameterName + ";");
        } else if( type.contains( "*" ) ) {
out.println("    for( size_t i" + parameterName + " = 0; i" + parameterName + " < " + parameterName + ".size(); ++i" + parameterName + " ) {");
out.println("        delete " + parameterName + "[i" + parameterName + "];");
out.println("    }");
        }
    }
out.println("}");

out.println("");
out.println("////////////////////////////////////////////////////////////////////////////////");
out.println("DataStructure* "+className+"::cloneDataStructure() const {");

    String newInstance = decapitalize( className );

out.println("    "+className+"* "+newInstance+" = new "+className+"();");
out.println("");
out.println("    // Copy the data from the base class or classes");
out.println("    "+newInstance+"->copyDataStructure( this );");
out.println("");
out.println("    return "+newInstance+";");
out.println("}");

out.println("");
out.println("////////////////////////////////////////////////////////////////////////////////");
out.println("void "+className+"::copyDataStructure( const DataStructure* src ) {");
out.println("");

        if( baseClass != null ) {
out.println("    // Copy the data of the base class or classes");
out.println("    "+getProperBaseClassName( className, baseClass )+"::copyDataStructure( src );");
out.println("");
        }

out.println("    const "+className+"* srcPtr = dynamic_cast<const "+className+"*>( src );");
out.println("");
out.println("    if( srcPtr == NULL || src == NULL ) {");
out.println("    ");
out.println("        throw exceptions::NullPointerException(");
out.println("            __FILE__, __LINE__,");
out.println("            \""+className+"::copyDataStructure - src is NULL or invalid\" );");
out.println("    }");

    for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
        JProperty property = (JProperty) iter.next();
        String type = toCppType(property.getType());
        String propertyName = property.getSimpleName();
        String parameterName = decapitalize(propertyName);
        String constNess = "";
        String getter = property.getGetter().getSimpleName();
        String setter = property.getSetter().getSimpleName();

        if( property.getType().isPrimitiveType() ||
            type.equals("std::string") ||
            property.getType().getSimpleName().equals("ByteSequence") ){
    out.println("    this->"+setter+"( srcPtr->"+getter+"() );");
        } else if( property.getType().isArrayType() &&
                   !property.getType().getArrayComponentType().isPrimitiveType() ) {

            String arrayType = property.getType().getArrayComponentType().getSimpleName();

    out.println("    for( size_t i" + parameterName + " = 0; i" + parameterName + " < srcPtr->"+getter+"().size(); ++i" + parameterName + " ) {");
    out.println("        if( srcPtr->"+getter+"()[i"+parameterName+"] != NULL ) {");
    out.println("            this->"+getter+"().push_back( ");
    out.println("                dynamic_cast<"+arrayType+"*>( ");
    out.println("                    srcPtr->"+getter+"()[i"+parameterName+"]->cloneDataStructure() ) );");
    out.println("        } else {");
    out.println("            this->"+getter+"().push_back( NULL );");
    out.println("        }");
    out.println("    }");
        } else if( property.getType().isArrayType() &&
                   property.getType().getArrayComponentType().isPrimitiveType() ) {
    out.println("    this->"+setter+"( srcPtr->"+getter+"() );");
        } else {
    out.println("    if( srcPtr->"+getter+"() != NULL ) {");
    out.println("        this->"+setter+"( ");
    out.println("            dynamic_cast<"+type+"*>( ");
    out.println("                srcPtr->"+getter+"()->cloneDataStructure() ) );");
    out.println("    }");
        }
    }

out.println("}");


// getDataStructureType

out.println("");
out.println("////////////////////////////////////////////////////////////////////////////////");
out.println("unsigned char "+className+"::getDataStructureType() const {");
out.println("    return "+className+"::ID_" + className.toUpperCase() + "; ");
out.println("}");

// toString

out.println("");
out.println("////////////////////////////////////////////////////////////////////////////////");
out.println("std::string "+className+"::toString() const {");
out.println("");

out.println("    ostringstream stream;" );
out.println("");
out.println("    stream << \"Begin Class = "+className+"\" << std::endl;" );
out.println("    stream << \" Value of "+className+"::ID_" + className.toUpperCase() + " = "+getOpenWireOpCode(jclass)+"\" << std::endl; ");

for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
    JProperty property = (JProperty) iter.next();
    String type = toCppType(property.getType());
    String propertyName = property.getSimpleName();
    String parameterName = decapitalize(propertyName);
    String constNess = "";
    String getter = property.getGetter().getSimpleName();
    String setter = property.getSetter().getSimpleName();

    if( property.getType().getSimpleName().equals("ByteSequence") ) {

out.println("    for( size_t i" + parameterName + " = 0; i" + parameterName + " < this->"+getter+"().size(); ++i" + parameterName + " ) {");
out.println("        stream << \" Value of "+propertyName+"[\" << i" + parameterName+" << \"] = \" << this->"+getter+"()[i"+parameterName+"] << std::endl;" );
out.println("    }" );

    } else if( type.equals("unsigned char") ){

out.println("    stream << \" Value of "+propertyName+" = \" << (int)this->"+getter+"() << std::endl;");

    } else if( property.getType().isPrimitiveType() ||
               type.equals("std::string") ){

out.println("    stream << \" Value of "+propertyName+" = \" << this->"+getter+"() << std::endl;");

    } else if( property.getType().isArrayType() &&
               !property.getType().getArrayComponentType().isPrimitiveType() ) {

        String arrayType = property.getType().getArrayComponentType().getSimpleName();

out.println("    for( size_t i" + parameterName + " = 0; i" + parameterName + " < this->"+getter+"().size(); ++i" + parameterName + " ) {");
out.println("        stream << \" Value of "+propertyName+"[\" << i" + parameterName+" << \"] is Below:\" << std::endl;" );
out.println("        if( this->"+getter+"()[i"+parameterName+"] != NULL ) {");
out.println("            stream << this->"+getter+"()[i"+parameterName+"]->toString() << std::endl;");
out.println("        } else {");
out.println("            stream << \"   Object is NULL\" << std::endl;");
out.println("        }");
out.println("    }");
    } else if( property.getType().isArrayType() &&
               property.getType().getArrayComponentType().isPrimitiveType() ) {
out.println("    for( size_t i" + parameterName + " = 0; i" + parameterName + " < this->"+getter+"().size(); ++i" + parameterName + " ) {");
out.println("        stream << \" Value of "+propertyName+"[\" << i"+parameterName+" << \"] = \" << this->"+getter+"()[i"+parameterName+"] << std::endl;");
out.println("    }");
    } else {
out.println("    stream << \" Value of "+propertyName+" is Below:\" << std::endl;" );
out.println("    if( this->"+getter+"() != NULL ) {");
out.println("        stream << this->"+getter+"()->toString() << std::endl;");
out.println("    } else {");
out.println("        stream << \"   Object is NULL\" << std::endl;");
out.println("    }");
    }
}

    if( baseClass != null ) {
out.println("    stream << "+getProperBaseClassName( className, baseClass )+"::toString();");
    }

out.println("    stream << \"End Class = "+className+"\" << std::endl;" );
out.println("");
out.println("    return stream.str();");
out.println("}");

// equals

out.println("");
out.println("////////////////////////////////////////////////////////////////////////////////");
out.println("bool "+className+"::equals( const DataStructure* value ) const {");

out.println("    const "+className+"* valuePtr = dynamic_cast<const "+className+"*>( value );");
out.println("");
out.println("    if( valuePtr == NULL || value == NULL ) {");
out.println("        return false;");
out.println("    }");

for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
    JProperty property = (JProperty) iter.next();
    String type = toCppType(property.getType());
    String propertyName = property.getSimpleName();
    String parameterName = decapitalize(propertyName);
    String constNess = "";
    String getter = property.getGetter().getSimpleName();
    String setter = property.getSetter().getSimpleName();

    if( property.getType().getSimpleName().equals("ByteSequence") ) {

out.println("    for( size_t i" + parameterName + " = 0; i" + parameterName + " < this->"+getter+"().size(); ++i" + parameterName + " ) {");
out.println("        if( this->"+getter+"()[i" + parameterName+"] != valuePtr->"+getter+"()[i"+parameterName+"] ) {" );
out.println("            return false;" );
out.println("        }" );
out.println("    }" );

    } else if( property.getType().isPrimitiveType() ||
               type.equals("std::string") ){

out.println("    if( this->"+getter+"() != valuePtr->"+getter+"() ) {");
out.println("        return false;" );
out.println("    }" );

    } else if( property.getType().isArrayType() &&
               !property.getType().getArrayComponentType().isPrimitiveType() ) {

        String arrayType = property.getType().getArrayComponentType().getSimpleName();

out.println("    for( size_t i" + parameterName + " = 0; i" + parameterName + " < this->"+getter+"().size(); ++i" + parameterName + " ) {");
out.println("        if( this->"+getter+"()[i"+parameterName+"] != NULL ) {" );
out.println("            if( !this->"+getter+"()[i"+parameterName+"]->equals( valuePtr->"+getter+"()[i"+parameterName+"] ) ) {" );
out.println("                return false;");
out.println("            }");
out.println("        } else if( valuePtr->"+getter+"()[i"+parameterName+"] != NULL ) {");
out.println("            return false;");
out.println("        }");
out.println("    }");
    } else if( property.getType().isArrayType() &&
               property.getType().getArrayComponentType().isPrimitiveType() ) {
out.println("    for( size_t i" + parameterName + " = 0; i" + parameterName + " < this->"+getter+"().size(); ++i" + parameterName + " ) {");
out.println("        if( this->"+getter+"()[i"+parameterName+"] != valuePtr->"+getter+"()[i"+parameterName+"] ) {");
out.println("            return false;");
out.println("        }");
out.println("    }");
    } else {
out.println("    if( this->"+getter+"() != NULL ) {");
out.println("        if( !this->"+getter+"()->equals( valuePtr->"+getter+"() ) ) {" );
out.println("            return false;");
out.println("        }");
out.println("    } else if( valuePtr->"+getter+"() != NULL ) {");
out.println("        return false;");
out.println("    }");
    }
}

    if( baseClass != null ) {
out.println("    if( !"+getProperBaseClassName( className, baseClass )+"::equals( value ) ) {");
out.println("        return false;");
out.println("    }");
    }

out.println("    return true;" );
out.println("}");

       for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
            JProperty property = (JProperty) iter.next();
            String type = toCppType(property.getType());
            String propertyName = property.getSimpleName();
            String parameterName = decapitalize(propertyName);
            String getter = property.getGetter().getSimpleName();
            String setter = property.getSetter().getSimpleName();
            String constNess = "";

            if( !property.getType().isPrimitiveType() &&
                !property.getType().getSimpleName().equals("ByteSequence") &&
                !property.getType().getSimpleName().equals("String") &&
                !type.startsWith("std::vector") ) {

                type = type + "*";
            } else if( property.getType().getSimpleName().equals("String") ||
                       type.startsWith( "std::vector") ) {
                type = type + "&";
                constNess = "const ";
            }


out.println("");

    if( property.getType().isPrimitiveType() ) {

out.println("////////////////////////////////////////////////////////////////////////////////");
out.println(type+" "+className+"::"+getter+"() const {");
out.println("    return "+parameterName+";");
out.println("}");
View Full Code Here

TOP

Related Classes of org.codehaus.jam.JProperty

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.