Package org.codehaus.jam

Examples of org.codehaus.jam.JProperty


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

        List properties = getProperties();
        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty)iter.next();
            String value = toCppDefaultValue(property.getType());
            String propertyName = property.getSimpleName();
            String parameterName = decapitalize(propertyName);
            out.println("    this->" + parameterName + " = " + value + " ;");
        }
        out.println("}");
        out.println("");
        out.println("" + className + "::~" + className + "()");
        out.println("{");
        out.println("}");
        out.println("");
        out.println("unsigned char " + className + "::getDataStructureType()");
        out.println("{");
        out.println("    return " + className + "::TYPE ; ");
        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);
            out.println("");
            out.println("        ");
            out.println("" + type + " " + className + "::get" + propertyName + "()");
            out.println("{");
            out.println("    return " + parameterName + " ;");
            out.println("}");
            out.println("");
            out.println("void " + className + "::set" + propertyName + "(" + type + " " + parameterName + ")");
            out.println("{");
            out.println("    this->" + parameterName + " = " + parameterName + " ;");
            out.println("}");
        }
        out.println("");
        out.println("int " + className + "::marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException)");
        out.println("{");
        out.println("    int size = 0 ;");
        out.println("");
        out.println("    size += " + baseClass + "::marshal(marshaller, mode, ostream) ; ");

        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty)iter.next();
            String marshalMethod = toMarshalMethodName(property.getType());
            String propertyName = decapitalize(property.getSimpleName());
            out.println("    size += marshaller->" + marshalMethod + "(" + propertyName + ", mode, ostream) ; ");
        }
        out.println("    return size ;");
        out.println("}");
        out.println("");
        out.println("void " + className + "::unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException)");
        out.println("{");
        out.println("    " + baseClass + "::unmarshal(marshaller, mode, istream) ; ");
        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty)iter.next();
            String cast = toUnmarshalCast(property.getType());
            String unmarshalMethod = toUnmarshalMethodName(property.getType());
            String propertyName = decapitalize(property.getSimpleName());
            out.println("    " + propertyName + " = " + cast + "(marshaller->" + unmarshalMethod + "(mode, istream)) ; ");
        }
        out.println("}");
    }
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.getSimpleName();

            if (type.equals("boolean")) {
                out.println("        bs.WriteBoolean(" + getter + ");");
            } else if (type.equals("byte")) {
                baseSize += 1;
View Full Code Here

    }

    protected void generateTightMarshal2Body(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.getSimpleName();

            if (type.equals("boolean")) {
                out.println("        bs.ReadBoolean();");
            } else if (type.equals("byte")) {
                out.println("        dataOut.Write(" + getter + ");");
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.getSimpleName();

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

        TestDataGenerator generator = new TestDataGenerator();

        List properties = getProperties();
        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty)iter.next();

            JAnnotation annotation = property.getAnnotation("openwire:property");
            String size = stringValue(annotation, "size");
            String testSize = stringValue(annotation, "testSize");
            String type = property.getType().getSimpleName();
//            boolean cached = isCachedProperty(property);
            String propertyName = property.getSimpleName();
            if ("-1".equals(testSize)) {
                continue;
            }

            String setterName = property.getSetter().getSimpleName();

            if (type.equals("boolean")) {
                out.println("        info." + setterName + "(" + generator.createBool() + ");");
            } else if (type.equals("byte")) {
                out.println("        info." + setterName + "(" + generator.createByte() + ");");
            } else if (type.equals("char")) {
                out.println("        info." + setterName + "(" + generator.createChar() + ");");
            } else if (type.equals("short")) {
                out.println("        info." + setterName + "(" + generator.createShort() + ");");
            } else if (type.equals("int")) {
                out.println("        info." + setterName + "(" + generator.createInt() + ");");
            } else if (type.equals("long")) {
                out.println("        info." + setterName + "(" + generator.createLong() + ");");
            } else if (type.equals("byte[]")) {
                out.println("        info." + setterName + "(" + generator.createByteArray(propertyName) + ");");
            } else if (type.equals("String")) {
                out.println("        info." + setterName + "(\"" + generator.createString(propertyName) + "\");");
            } else if (type.equals("ByteSequence")) {
                out.println("        {");
                out.println("            byte data[] = " + generator.createByteArray(propertyName) + ";");
                out.println("            info." + setterName + "(new org.apache.activemq.util.ByteSequence(data,0,data.length));");
                out.println("}");
            } else if (type.equals("Throwable")) {
                out.println("        info." + setterName + "(createThrowable(\"" + generator.createString(propertyName) + "\"));");
            } else {
                if (property.getType().isArrayType()) {
                    String arrayType = property.getType().getArrayComponentType().getSimpleName();
                    if (size == null) {
                        size = "2";
                    }
                    if (arrayType == jclass.getSimpleName()) {
                        size = "0";
View Full Code Here

     */
    public List<JProperty> getProperties() {
        List<JProperty> answer = new ArrayList<JProperty>();
        JProperty[] properties = jclass.getDeclaredProperties();
        for (int i = 0; i < properties.length; i++) {
            JProperty property = properties[i];
            if (isValidProperty(property)) {
                answer.add(property);
            }
        }
        return answer;
View Full Code Here

        List properties = getProperties();
        String type;
        Object name;
        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty)iter.next();
            type = toCSharpType(property.getType());
            name = decapitalize(property.getSimpleName());
            out.println("        " + type + " " + name + ";");
        }

        String text = makeHashCodeBody();
        if (text != null) {
            out.println("");
            out.println("        public override int GetHashCode() {");
            out.println("" + text + "");
            out.println("        }");
        }

        text = makeEqualsBody();
        if (text != null) {
            out.println("");
            out.println("        public override bool Equals(object that) {");
            out.println("            if (that is " + className + ") {");
            out.println("                return Equals((" + className + ") that);");
            out.println("            }");
            out.println("            return false;");
            out.println("        }");
            out.println("");
            out.println("        public virtual bool Equals(" + className + " that) {");
            out.println("" + text + "");
            out.println("        }");
        }

        text = makeToStringBody();
        if (text != null) {
            out.println("");
            out.println("        public override string ToString() {");
            out.println("" + text + "");
            out.println("        }");
        }

        out.println("");
        out.println("        public override byte GetDataStructureType() {");
        out.println("            return ID_" + jclass.getSimpleName() + ";");
        out.println("        }");
        out.println("");
        out.println("");
        out.println("        // Properties");

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

            out.println("");
            out.println("        public " + type + " " + propertyName + "");
            out.println("        {");
            out.println("            get { return " + name + "; }");
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(className+"* "+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 decaf::lang::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("}");

   if( className.equals( "Message" ) ) {
out.println("");
out.println("////////////////////////////////////////////////////////////////////////////////");
out.println("unsigned int "+className+"::getSize() const {");
out.println("");
out.println("    unsigned int size = DEFAULT_MESSAGE_SIZE;");
out.println("");
out.println("    size += (unsigned int)this->getContent().size();");
out.println("    size += (unsigned int)this->getMarshalledProperties().size();");
out.println("");
out.println("    return size;");
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

                                            "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

  //    }
     
      JProperty[] properties = (JProperty[]) propertiesSet.toArray(new JProperty[0]);
            Arrays.sort(properties);
            for (int i = 0; i < properties.length; i++) {
                JProperty property = properties[i];
                String propertyName = getQualifiedName(property.getType());
                boolean isArryType = property.getType().isArrayType();
               
                String propname = getCorrectName(property.getSimpleName()) ;
               
                propertiesNames.add(propname) ;
               
                this.generateSchemaforFieldsandProperties(xmlSchema, sequence, property.getType(),
                                                          propname, isArryType);
               
            }
           
            // AXIS2-2116 support for fields
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.