Package org.codehaus.jam

Examples of org.codehaus.jam.JProperty


        }

        ArrayList<JProperty> properties = new ArrayList<JProperty>();
        jclass.getDeclaredProperties();
        for (int i = 0; i < jclass.getDeclaredProperties().length; i++) {
            JProperty p = jclass.getDeclaredProperties()[i];
            if (isValidProperty(p)) {
                properties.add(p);
            }
        }
        for (Iterator<JProperty> iter = properties.iterator(); iter.hasNext();) {
            JProperty property = iter.next();
            JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
//            JAnnotationValue size = annotation.getValue("size");
            String name = toPropertyCase(property.getSimpleName());
//            boolean cached = isCachedProperty(property);

            String type = property.getType().getQualifiedName();
            if (type.equals("boolean")) {
                out.println("   ow_" + type + " " + name + ";");
            } else if (type.equals("byte")) {
                out.println("   ow_" + type + " " + name + ";");
            } else if (type.equals("char")) {
                out.println("   ow_" + type + " " + name + ";");
            } else if (type.equals("short")) {
                out.println("   ow_" + type + " " + name + ";");
            } else if (type.equals("int")) {
                out.println("   ow_" + type + " " + name + ";");
            } else if (type.equals("long")) {
                out.println("   ow_" + type + " " + name + ";");
            } else if (type.equals("byte[]")) {
                out.println("   ow_byte_array *" + name + ";");
            } else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
                out.println("   ow_byte_array *" + name + ";");
            } else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
                out.println("   ow_byte_array *" + name + ";");
            } else if (type.equals("java.lang.String")) {
                out.println("   ow_string *" + name + ";");
            } else {
                if (property.getType().isArrayType()) {
                    out.println("   ow_DataStructure_array *" + name + ";");
                } else if (isThrowable(property.getType())) {
                    out.println("   ow_throwable *" + name + ";");
                } else {
                    out.println("   struct ow_" + property.getType().getSimpleName() + " *" + name + ";");
                }
            }
        }
    }
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

        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 void generateFile(PrintWriter out) throws Exception {

        ArrayList<JProperty> properties = new ArrayList<JProperty>();
        jclass.getDeclaredProperties();
        for (int i = 0; i < jclass.getDeclaredProperties().length; i++) {
            JProperty p = jclass.getDeclaredProperties()[i];
            if (isValidProperty(p)) {
                properties.add(p);
            }
        }

        String name = jclass.getSimpleName();
        String type = ("ow_" + name).toUpperCase() + "_TYPE";
        String baseName = "DataStructure";
        JClass superclass = jclass.getSuperclass();
        while (superclass.getSuperclass() != null) {
            if (sortedClasses.contains(superclass)) {
                baseName = superclass.getSimpleName();
                break;
            } else {
                superclass = superclass.getSuperclass();
            }
        }

        out.println("ow_boolean ow_is_a_" + name + "(ow_DataStructure *object) {");
        out.println("   if( object == 0 )");
        out.println("      return 0;");
        out.println("      ");
        out.println("   switch(object->structType) {");

        for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
            JClass sub = (JClass)iterator.next();
            String subtype = "OW_" + sub.getSimpleName().toUpperCase() + "_TYPE";
            if (jclass.isAssignableFrom(sub) && !isAbstract(sub)) {
                out.println("");
                out.println("   case " + subtype + ":");
            }
        }
        out.println("");
        out.println("      return 1;");
        out.println("   }");
        out.println("   return 0;");
        out.println("}");

        if (!isAbstract(jclass)) {
            out.println("");
            out.println("");
            out.println("ow_" + name + " *ow_" + name + "_create(apr_pool_t *pool) ");
            out.println("{");
            out.println("   ow_" + name + " *value = apr_pcalloc(pool,sizeof(ow_" + name + "));");
            out.println("   if( value!=0 ) {");
            out.println("      ((ow_DataStructure*)value)->structType = " + type + ";");
            out.println("   }");
            out.println("   return value;");
            out.println("}");
        }

        out.println("");
        out.println("");
        out.println("apr_status_t ow_marshal1_" + name + "(ow_bit_buffer *buffer, ow_" + name + " *object)");
        out.println("{");
        out.println("   ow_marshal1_" + baseName + "(buffer, (ow_" + baseName + "*)object);");

        for (Iterator<JProperty> iter = properties.iterator(); iter.hasNext();) {
            JProperty property = iter.next();
            String propname = toPropertyCase(property.getSimpleName());
            boolean cached = isCachedProperty(property);
            JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
            JAnnotationValue size = annotation.getValue("size");

            type = property.getType().getQualifiedName();
            if (type.equals("boolean")) {
                out.println("   ow_bit_buffer_append(buffer, object->" + propname + ");");
            } else if (type.equals("byte")) {
            } else if (type.equals("char")) {
            } else if (type.equals("short")) {
            } else if (type.equals("int")) {
            } else if (type.equals("long")) {
                out.println("   ow_marshal1_long(buffer, object->" + propname + ");");
            } else if (type.equals("byte[]")) {
                if (size == null) {
                    out.println("   ow_bit_buffer_append(buffer,  object->" + propname + "!=0 );");
                }
            } else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
                if (size == null) {
                    out.println("   ow_bit_buffer_append(buffer,  object->" + propname + "!=0 );");
                }
            } else if (type.equals("java.lang.String")) {
                out.println("   ow_marshal1_string(buffer, object->" + propname + ");");
            } else {
                if (property.getType().isArrayType()) {
                    if (size != null) {
                        out.println("   SUCCESS_CHECK(ow_marshal1_DataStructure_array_const_size(buffer, object->" + propname + ", " + size.asInt() + "));");
                    } else {
                        out.println("   SUCCESS_CHECK(ow_marshal1_DataStructure_array(buffer, object->" + propname + "));");
                    }
                } else if (isThrowable(property.getType())) {
                    out.println("   SUCCESS_CHECK(ow_marshal1_throwable(buffer, object->" + propname + "));");
                } else {
                    if (cached) {
                        out.println("   SUCCESS_CHECK(ow_marshal1_cached_object(buffer, (ow_DataStructure*)object->" + propname + "));");
                    } else {
                        out.println("   SUCCESS_CHECK(ow_marshal1_nested_object(buffer, (ow_DataStructure*)object->" + propname + "));");
                    }
                }
            }
            out.println("");
        }

        out.println("   ");
        out.println("   return APR_SUCCESS;");
        out.println("}");
        out.println("apr_status_t ow_marshal2_" + name + "(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_" + name + " *object)");
        out.println("{");
        out.println("   ow_marshal2_" + baseName + "(buffer, bitbuffer, (ow_" + baseName + "*)object);   ");

        for (Iterator<JProperty> iter = properties.iterator(); iter.hasNext();) {
            JProperty property = iter.next();
            JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
            JAnnotationValue size = annotation.getValue("size");
            Object propname = toPropertyCase(property.getSimpleName());
            boolean cached = isCachedProperty(property);

            type = property.getType().getQualifiedName();
            if (type.equals("boolean")) {
                out.println("   ow_bit_buffer_read(bitbuffer);");
            } else if (type.equals("byte")) {
                out.println("   SUCCESS_CHECK(ow_byte_buffer_append_" + type + "(buffer, object->" + propname + "));");
            } else if (type.equals("char")) {
                out.println("   SUCCESS_CHECK(ow_byte_buffer_append_" + type + "(buffer, object->" + propname + "));");
            } else if (type.equals("short")) {
                out.println("   SUCCESS_CHECK(ow_byte_buffer_append_" + type + "(buffer, object->" + propname + "));");
            } else if (type.equals("int")) {
                out.println("   SUCCESS_CHECK(ow_byte_buffer_append_" + type + "(buffer, object->" + propname + "));");
            } else if (type.equals("long")) {
                out.println("   SUCCESS_CHECK(ow_marshal2_long(buffer, bitbuffer, object->" + propname + "));");
            } else if (type.equals("byte[]")) {
                if (size != null) {
                    out.println("   SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->" + propname + ", " + size.asInt() + "));");
                } else {
                    out.println("   SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->" + propname + "));");
                }
            } else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
                if (size != null) {
                    out.println("   SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->" + propname + ", " + size.asInt() + "));");
                } else {
                    out.println("   SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->" + propname + "));");
                }
            } else if (type.equals("java.lang.String")) {
                out.println("   SUCCESS_CHECK(ow_marshal2_string(buffer, bitbuffer, object->" + propname + "));");
            } else {
                if (property.getType().isArrayType()) {
                    if (size != null) {
                        out.println("   SUCCESS_CHECK(ow_marshal2_DataStructure_array_const_size(buffer, bitbuffer, object->" + propname + ", " + size.asInt() + "));");
                    } else {
                        out.println("   SUCCESS_CHECK(ow_marshal2_DataStructure_array(buffer, bitbuffer, object->" + propname + "));");
                    }
                } else if (isThrowable(property.getType())) {
                    out.println("   SUCCESS_CHECK(ow_marshal2_throwable(buffer, bitbuffer, object->" + propname + "));");
                } else {
                    if (cached) {
                        out.println("   SUCCESS_CHECK(ow_marshal2_cached_object(buffer, bitbuffer, (ow_DataStructure*)object->" + propname + "));");
                    } else {
                        out.println("   SUCCESS_CHECK(ow_marshal2_nested_object(buffer, bitbuffer, (ow_DataStructure*)object->" + propname + "));");
                    }
                }
            }
            out.println("");
        }

        out.println("   ");
        out.println("   return APR_SUCCESS;");
        out.println("}");
        out.println("");
        out.println("apr_status_t ow_unmarshal_" + name + "(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_" + name + " *object, apr_pool_t *pool)");
        out.println("{");
        out.println("   ow_unmarshal_" + baseName + "(buffer, bitbuffer, (ow_" + baseName + "*)object, pool);   ");

        for (Iterator<JProperty> iter = properties.iterator(); iter.hasNext();) {
            JProperty property = iter.next();
            JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
            JAnnotationValue size = annotation.getValue("size");
            String propname = toPropertyCase(property.getSimpleName());
            boolean cached = isCachedProperty(property);

            type = property.getType().getQualifiedName();

            if (type.equals("boolean")) {
                out.println("   object->" + propname + " = ow_bit_buffer_read(bitbuffer);");
            } else if (type.equals("byte")) {
                out.println("   SUCCESS_CHECK(ow_byte_array_read_" + type + "(buffer, &object->" + propname + "));");
            } else if (type.equals("char")) {
                out.println("   SUCCESS_CHECK(ow_byte_array_read_" + type + "(buffer, &object->" + propname + "));");
            } else if (type.equals("short")) {
                out.println("   SUCCESS_CHECK(ow_byte_array_read_" + type + "(buffer, &object->" + propname + "));");
            } else if (type.equals("int")) {
                out.println("   SUCCESS_CHECK(ow_byte_array_read_" + type + "(buffer, &object->" + propname + "));");
            } else if (type.equals("long")) {
                out.println("   SUCCESS_CHECK(ow_unmarshal_long(buffer, bitbuffer, &object->" + propname + ", pool));");
            } else if (type.equals("byte[]")) {
                if (size != null) {
                    out.println("   SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->" + propname + ", " + size.asInt() + ", pool));");
                } else {
                    out.println("   SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->" + propname + ", pool));");
                }
            } else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
                if (size != null) {
                    out.println("   SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->" + propname + ", " + size.asInt() + ", pool));");
                } else {
                    out.println("   SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->" + propname + ", pool));");
                }
            } else if (type.equals("java.lang.String")) {
                out.println("   SUCCESS_CHECK(ow_unmarshal_string(buffer, bitbuffer, &object->" + propname + ", pool));");
            } else {
                if (property.getType().isArrayType()) {
                    if (size != null) {
                        out.println("   SUCCESS_CHECK(ow_unmarshal_DataStructure_array_const_size(buffer, bitbuffer, &object->" + propname + ", " + size.asInt() + ", pool));");
                    } else {
                        out.println("   SUCCESS_CHECK(ow_unmarshal_DataStructure_array(buffer, bitbuffer, &object->" + propname + ", pool));");
                    }
                } else if (isThrowable(property.getType())) {
                    out.println("   SUCCESS_CHECK(ow_unmarshal_throwable(buffer, bitbuffer, &object->" + propname + ", pool));");
                } else {
                    if (cached) {
                        out.println("   SUCCESS_CHECK(ow_unmarshal_cached_object(buffer, bitbuffer, (ow_DataStructure**)&object->" + propname + ", pool));");
                    } else {
View Full Code Here

    protected int generateMarshal1Body(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() + "()";

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

    }

    protected void generateMarshal2Body(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() + "()";

            out.print(indent);
            if (type.equals("boolean")) {
                out.println("bs.readBoolean();");
            } else if (type.equals("byte")) {
View Full Code Here

        out.println("#include <string>");
        out.println("#include \"activemq/command/" + baseClass + ".hpp\"");

        List properties = getProperties();
        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty)iter.next();
            if (!property.getType().isPrimitiveType() && !property.getType().getSimpleName().equals("String") && !property.getType().getSimpleName().equals("ByteSequence")) {
                String includeName = toCppType(property.getType());
                if (property.getType().isArrayType()) {
                    JClass arrayType = property.getType().getArrayComponentType();
                    if (arrayType.isPrimitiveType()) {
                        continue;
                    }
                }
                if (includeName.startsWith("array<")) {
                    includeName = includeName.substring(6, includeName.length() - 1);
                } else if (includeName.startsWith("p<")) {
                    includeName = includeName.substring(2, includeName.length() - 1);
                }
                if (includeName.equals("IDataStructure")) {
                    out.println("#include \"activemq/" + includeName + ".hpp\"");
                } else {
                    out.println("#include \"activemq/command/" + includeName + ".hpp\"");
                }
            }
        }
        out.println("");
        out.println("#include \"activemq/protocol/IMarshaller.hpp\"");
        out.println("#include \"ppr/io/IOutputStream.hpp\"");
        out.println("#include \"ppr/io/IInputStream.hpp\"");
        out.println("#include \"ppr/io/IOException.hpp\"");
        out.println("#include \"ppr/util/ifr/array\"");
        out.println("#include \"ppr/util/ifr/p\"");
        out.println("");
        out.println("namespace apache");
        out.println("{");
        out.println("  namespace activemq");
        out.println("  {");
        out.println("    namespace command");
        out.println("    {");
        out.println("      using namespace ifr;");
        out.println("      using namespace std;");
        out.println("      using namespace apache::activemq;");
        out.println("      using namespace apache::activemq::protocol;");
        out.println("      using namespace apache::ppr::io;");
        out.println("");
        out.println("/*");
        out.println(" *");
        out.println(" *  Command and marshalling code for OpenWire format for " + className + "");
        out.println(" *");
        out.println(" *");
        out.println(" *  NOTE!: This file is autogenerated - do not modify!");
        out.println(" *         if you need to make a change, please see the Groovy scripts in the");
        out.println(" *         activemq-core module");
        out.println(" *");
        out.println(" */");
        out.println("class " + className + " : public " + baseClass + "");
        out.println("{");
        out.println("protected:");

        for (Iterator iter = properties.iterator(); iter.hasNext();) {
            JProperty property = (JProperty)iter.next();
            String type = toCppType(property.getType());
            String name = decapitalize(property.getSimpleName());
            out.println("    " + type + " " + name + " ;");
        }
        out.println("");
        out.println("public:");
        out.println("    const static unsigned char TYPE = " + getOpenWireOpCode(jclass) + ";");
        out.println("");
        out.println("public:");
        out.println("    " + className + "() ;");
        out.println("    virtual ~" + className + "() ;");
        out.println("");
        out.println("    virtual unsigned char getDataStructureType() ;");

        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("    virtual " + type + " get" + propertyName + "() ;");
            out.println("    virtual void set" + propertyName + "(" + type + " " + parameterName + ") ;");
        }
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

            StringWriter buffer = new StringWriter();
            PrintWriter out = new PrintWriter(buffer);
            out.println("            int answer = 0;");
            Iterator iter = getProperties().iterator();
            while (iter.hasNext()) {
                JProperty property = (JProperty)iter.next();
                out.println("            answer = (answer * 37) + HashCode(" + property.getSimpleName() + ");");
            }
            out.println("            return answer;");
            return buffer.toString();
        }
        return null;
View Full Code Here

            StringWriter buffer = new StringWriter();
            PrintWriter out = new PrintWriter(buffer);

            Iterator iter = getProperties().iterator();
            while (iter.hasNext()) {
                JProperty property = (JProperty)iter.next();
                String name = property.getSimpleName();
                out.println("            if (! Equals(this." + name + ", that." + name + ")) return false;");
            }
            out.println("            return true;");
            return buffer.toString();
        }
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.