Package org.codehaus.jam

Examples of org.codehaus.jam.JClass


                }
            }
        }

        //generating wrapper element for retuen element
        JClass methodReturnType = method.getReturnType();
        generateWrapperforReturnType(methodReturnType, methodName);

    }
View Full Code Here


        JamService service = factory.createService(jam_service_parms);

        JamClassIterator jClassIter = service.getClasses();
        // all most all the time the ittr will have only one class in it
        while (jClassIter.hasNext()) {
            JClass jclass = (JClass)jClassIter.next();
            // serviceName = jclass.getSimpleName();
            // todo in the future , when we support annotation we can use this
            // JAnnotation[] annotations = jclass.getAnnotations();

            /**
             * Schema generation done in two stage 1. Load all the methods and
             * create type for methods parameters (if the parameters are Bean
             * then it will create Complex types for those , and if the
             * parameters are simple type which describe in SimpleTypeTable
             * nothing will happen) 2. In the next stage for all the methods
             * messages and port types will be created
             */
            methods = jclass.getDeclaredMethods();

            // since we do not support overload
            HashMap uniqueMethods = new HashMap();
            XmlSchemaComplexType methodSchemaType = null;
            XmlSchemaSequence sequence = null;
            for (int i = 0; i < methods.length; i++) {
                String methodName = methods[i].getSimpleName();
                JMethod jMethod = methods[i];
                // no need to think about this method , since that is system
                // config method
                if (excludeMethods.contains(jMethod.getSimpleName())) {
                    continue;
                }
                // if (jMethod.getSimpleName().equals("init")
                // || "setOperationContext".equals(jMethod.getSimpleName())
                // || "destroy".equals(jMethod.getSimpleName()))
                // continue;
                if (uniqueMethods.get(jMethod.getSimpleName()) != null) {
                    throw new Exception(" Sorry we don't support methods overloading !!!! ");
                }

                if (!jMethod.isPublic()) {
                    // no need to generate Schema for non public methods
                    continue;
                }

                uniqueMethods.put(jMethod.getSimpleName(), jMethod);
                JParameter[] paras = jMethod.getParameters();
                String parameterNames[] = null;
                if (paras.length > 0) {
                    parameterNames = methodTable.getParameterNames(methodName);
                    sequence = new XmlSchemaSequence();

                    // create the schema type for the method wrapper
                    methodSchemaType = createSchemaTypeForMethodPart(jMethod.getSimpleName());
                    methodSchemaType.setParticle(sequence);
                }

                for (int j = 0; j < paras.length; j++) {
                    JParameter methodParameter = paras[j];
                    JClass paraType = methodParameter.getType();
                    generateSchemaForType(sequence, paraType, (parameterNames != null && parameterNames[j] != null)
                        ? parameterNames[j] : methodParameter.getSimpleName());
                }
                // for its return type
                JClass returnType = jMethod.getReturnType();
                if (!returnType.isVoidType()) {
                    methodSchemaType = createSchemaTypeForMethodPart(jMethod.getSimpleName() + RESPONSE);
                    sequence = new XmlSchemaSequence();
                    methodSchemaType.setParticle(sequence);
                    generateSchemaForType(sequence, returnType, "return");
                }
View Full Code Here

        JamService service = factory.createService(jam_service_parms);
        QName extraSchemaTypeName = null;
        JamClassIterator jClassIter = service.getClasses();
        // all most all the time the ittr will have only one class in it
        while (jClassIter.hasNext()) {
            JClass jclass = (JClass)jClassIter.next();
            // serviceName = jclass.getSimpleName();
            // todo in the future , when we support annotation we can use this
            // JAnnotation[] annotations = jclass.getAnnotations();

            if (jclass.getQualifiedName().equals(generationParams.getSourceClassName())) {
                /**
                 * Schema generation done in two stage 1. Load all the methods
                 * and create type for methods parameters (if the parameters are
                 * Bean then it will create Complex types for those , and if the
                 * parameters are simple type which describe in SimpleTypeTable
                 * nothing will happen) 2. In the next stage for all the methods
                 * messages and port types will be created
                 */
                methods = jclass.getDeclaredMethods();
                // short the elements in the array
                Arrays.sort(methods);

                // since we do not support overload
                HashMap uniqueMethods = new HashMap();
                XmlSchemaComplexType methodSchemaType;
                XmlSchemaSequence sequence = null;

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

                    String methodName = methods[i].getSimpleName();
                    // no need to think about this method , since that is system
                    // config method
                    if (excludeMethods.contains(jMethod.getSimpleName())) {
                        continue;
                    }

                    if (uniqueMethods.get(jMethod.getSimpleName()) != null) {
                        throw new Exception(" Sorry we don't support methods overloading !!!! ");
                    }

                    if (!jMethod.isPublic()) {
                        // no need to generate Schema for non public methods
                        continue;
                    }
                    uniqueMethods.put(jMethod.getSimpleName(), jMethod);
                    // create the schema type for the method wrapper

                    uniqueMethods.put(jMethod.getSimpleName(), jMethod);
                    JParameter[] paras = jMethod.getParameters();
                    String parameterNames[] = null;
                    // better to handle void types too
                    parameterNames = methodTable.getParameterNames(methodName);
                    sequence = new XmlSchemaSequence();

                    methodSchemaType = createSchemaTypeForMethodPart(jMethod.getSimpleName());
                    methodSchemaType.setParticle(sequence);

                    for (int j = 0; j < paras.length; j++) {
                        JParameter methodParameter = paras[j];
                        JClass paraType = methodParameter.getType();
                        generateSchemaForType(sequence, paraType, (parameterNames != null && parameterNames[j] != null)
                            ? parameterNames[j] : methodParameter.getSimpleName());
                    }
                    // for its return type
                    JClass returnType = jMethod.getReturnType();

                    // better to handle void types too
                    methodSchemaType = createSchemaTypeForMethodPart(jMethod.getSimpleName() + RESPONSE);
                    sequence = new XmlSchemaSequence();
                    methodSchemaType.setParticle(sequence);
View Full Code Here

out.println("import org.apache.activemq.command.*;");
out.println("");
    for (int i = 0; i < getJclass().getImportedPackages().length; i++) {
      JPackage pkg = getJclass().getImportedPackages()[i];
      for (int j = 0; j < pkg.getClasses().length; j++) {
        JClass clazz = pkg.getClasses()[j];
out.println("import " + clazz.getQualifiedName() + ";");
      }
    }

    boolean marshallerAware = isMarshallAware(jclass);

View Full Code Here

        }
       
    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+":");
      }           
    }
View Full Code Here

out.println("");
out.println("ow_DataStructure *ow_create_object(ow_byte type, apr_pool_t *pool)");
out.println("{");
out.println("   switch( type ) {");
    for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
      JClass jclass = (JClass) iterator.next();
            String name = jclass.getSimpleName();
            String type = ("ow_"+name).toUpperCase()+"_TYPE";
            if( !isAbstract(jclass) ) {
out.println("      case "+type+": return (ow_DataStructure *)ow_"+name+"_create(pool);");
            }
         }
        
out.println("");
out.println("   }");
out.println("   return 0;");
out.println("}");
out.println("");
out.println("apr_status_t ow_marshal1_object(ow_bit_buffer *buffer, ow_DataStructure *object)");
out.println("{");
out.println("   switch( object->structType ) {");

    for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
      JClass jclass = (JClass) iterator.next();
            String name = jclass.getSimpleName();
            String type = ("ow_"+name).toUpperCase()+"_TYPE";
            if( !isAbstract(jclass) ) {
out.println("      case "+type+": return ow_marshal1_"+name+"(buffer, (ow_"+name+"*)object);");
            }
         }
        
out.println("");
out.println("   }");
out.println("   return APR_EGENERAL;");
out.println("}");
out.println("");
out.println("apr_status_t ow_marshal2_object(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object)");
out.println("{");
out.println("   switch( object->structType ) {");

    for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
      JClass jclass = (JClass) iterator.next();
            String name = jclass.getSimpleName();
            String type = ("ow_"+name).toUpperCase()+"_TYPE";
            if( !isAbstract(jclass) ) {
out.println("      case "+type+": return ow_marshal2_"+name+"(buffer, bitbuffer, (ow_"+name+"*)object);");
            }
         }

out.println("");
out.println("   }");
out.println("   return APR_EGENERAL;");
out.println("}");
out.println("");
out.println("apr_status_t ow_unmarshal_object(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object, apr_pool_t *pool)");
out.println("{");
out.println("   switch( object->structType ) {");

    for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
      JClass jclass = (JClass) iterator.next();
            String name = jclass.getSimpleName();
            String type = ("ow_"+name).toUpperCase()+"_TYPE";
            if( !isAbstract(jclass) ) {
out.println("      case "+type+": return ow_unmarshal_"+name+"(buffer, bitbuffer, (ow_"+name+"*)object, pool);");
            }
         }
View Full Code Here

            out.println("        info." + propertyName + " = (" + type + ") TightUnmarshalNestedObject(wireFormat, dataIn, bs);");
        }
    }

    protected void generateTightUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
        JClass propertyType = property.getType();
        String arrayType = propertyType.getArrayComponentType().getSimpleName();
        String propertyName = property.getSimpleName();
        out.println();
        if (size != null) {
            out.println("        {");
            out.println("            " + arrayType + "[] value = new " + arrayType + "[" + size.asInt() + "];");
View Full Code Here

        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;
            }
            else if (type.equals("char")) {
                baseSize += 2;
            }
            else if (type.equals("short")) {
                baseSize += 2;
            }
            else if (type.equals("int")) {
                baseSize += 4;
            }
            else if (type.equals("long")) {
                out.println("        rc += TightMarshalLong1(wireFormat, " + getter + ", bs);");
            }
            else if (type.equals("String")) {
                out.print("");
                out.println("        rc += TightMarshalString1(" + getter + ", bs);");
            }
            else if (type.equals("byte[]") || type.equals("ByteSequence")) {
                if (size == null) {
                    out.println("        bs.WriteBoolean(" + getter + "!=null);");
                    out.println("        rc += " + getter + "==null ? 0 : " + getter + ".Length+4;");
                }
                else {
                    baseSize += size.asInt();
                }
            }
            else if (propertyType.isArrayType()) {
                if (size != null) {
                    out.println("        rc += TightMarshalObjectArrayConstSize1(wireFormat, " + getter + ", bs, " + size.asInt() + ");");
                }
                else {
                    out.println("        rc += TightMarshalObjectArray1(wireFormat, " + getter + ", bs);");
View Full Code Here

        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 + ");");
            }
            else if (type.equals("char")) {
                out.println("        dataOut.Write(" + getter + ");");
            }
            else if (type.equals("short")) {
                out.println("        dataOut.Write(" + getter + ");");
            }
            else if (type.equals("int")) {
                out.println("        dataOut.Write(" + getter + ");");
            }
            else if (type.equals("long")) {
                out.println("        TightMarshalLong2(wireFormat, " + getter + ", dataOut, bs);");
            }
            else if (type.equals("String")) {
                out.println("        TightMarshalString2(" + getter + ", dataOut, bs);");
            }
            else if (type.equals("byte[]") || type.equals("ByteSequence")) {
                if (size != null) {
                    out.println("        dataOut.Write(" + getter + ", 0, " + size.asInt() + ");");
                }
                else {
                    out.println("        if(bs.ReadBoolean()) {");
                    out.println("           dataOut.Write(" + getter + ".Length);");
                    out.println("           dataOut.Write(" + getter + ");");
                    out.println("        }");
                }
            }
            else if (propertyType.isArrayType()) {
                if (size != null) {
                    out.println("        TightMarshalObjectArrayConstSize2(wireFormat, " + getter + ", dataOut, bs, " + size.asInt() + ");");
                }
                else {
                    out.println("        TightMarshalObjectArray2(wireFormat, " + getter + ", dataOut, bs);");
View Full Code Here

            out.println("        info." + propertyName + " = (" + type + ") LooseUnmarshalNestedObject(wireFormat, dataIn);");
        }
    }

    protected void generateLooseUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
        JClass propertyType = property.getType();
        String arrayType = propertyType.getArrayComponentType().getSimpleName();
        String propertyName = property.getSimpleName();
        out.println();
        if (size != null) {
            out.println("        {");
            out.println("            " + arrayType + "[] value = new " + arrayType + "[" + size.asInt() + "];");
View Full Code Here

TOP

Related Classes of org.codehaus.jam.JClass

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.