Package com.volantis.mcs.build.javadoc

Examples of com.volantis.mcs.build.javadoc.FieldInfo


    // Write the copyright statement.
    GenerateUtilities.writeCopyright (out);

    // Write the fields.
    for (Iterator i = identityFields.iterator (); i.hasNext ();) {
      FieldInfo field = (FieldInfo) i.next ();
      String fieldName = field.getName ();

      GenerateUtilities.writeJavaDocComment (out, "  ", field.getComment ());
      out.println ("  private " + field.getTypeName ()
                   + " " + fieldName + ";");
    }

    // Write the initialisation of the base class.
    List baseConstructors = identityBaseClassInfo.getConstructors();
    System.err.println("base constructors = " + baseConstructors);

    // Based on two constructors in the absolute base class of all assets
    if (baseConstructors.size () != 2) {
      throw new IllegalStateException ("Identity base class has wrong number"
                                       + " of constructors\n" +
              "identityBaseClassInfo = " + identityBaseClassInfo.getName());
    }

    // Iterate over all constructors and replicate them in this class
    for (Iterator i = baseConstructors.iterator(); i.hasNext(); /* No ++ */) {

        ConstructorInfo baseConstructor = (ConstructorInfo)i.next();

        // Write the constructor comment.
        GenerateUtilities.openJavaDocComment(out, "  ");
        GenerateUtilities.addJavaDocComment(out, "  ", "Create a new <code>"
                + identityClassName + "</code>.");
        List constructorParameters = baseConstructor.getParameters();
        for (Iterator innerI = constructorParameters.iterator();
                                            innerI.hasNext(); /* No ++ */) {
            ParameterInfo param = (ParameterInfo)innerI.next();
            String paramName = param.getName();
            comment = "@param " + paramName + " " +
                    identityBaseClassInfo.getField(paramName, true).getComment();

            GenerateUtilities.addJavaDocComment(out, "  ", comment);
        }
        GenerateUtilities.closeJavaDocComment(out, "  ");

        // Write the constructor method declaration.
        String startLine = "  public " + identityClassName + " (";
        out.print(startLine);
        separator = null;
        for (Iterator innerI = constructorParameters.iterator();
                                            innerI.hasNext(); /* No ++ */) {
            ParameterInfo param = (ParameterInfo)innerI.next();

            // Output a parameter declaration.
            if (separator == null) {
                separator = ",\n" +
                        GenerateUtilities.getIndent(startLine.length());
            } else {
                out.print(separator);
            }
            out.print (param.getTypeName() + " " + param.getName());
        }
        if (identityFields.size () != 0) {
            for (Iterator fieldsIterator = identityFields.iterator();
                 fieldsIterator.hasNext(); /**/) {
                FieldInfo field = (FieldInfo)fieldsIterator.next();

                if (separator == null){
                    separator = ",\n" +
                             GenerateUtilities.getIndent(startLine.length());
                } else {
                    out.print(separator);
                }

                out.print (field.getTypeName() + " " + field.getName());
            }
        }
        out.println(") {");



        List parameters = baseConstructor.getParameters();
        ParameterInfo firstParam = (ParameterInfo) parameters.get(0);
       
        // If the Project is the first parameter, call the superclass
        // constructor.  If it isn't, call the superclass constructor with
        // null for the project.
        if (!GenerateUtilities.isProjectField(firstParam)) {
            out.print("    super(null, ");
        } else {
            // Write the call to the superclass
             out.print("    super(");
        }
       
        separator = "";
        for (Iterator innerI = parameters.iterator();
                                            innerI.hasNext(); /* No ++ */) {
            ParameterInfo parameter = (ParameterInfo)innerI.next();

           
            out.print(separator);
            out.print(parameter.getName());
            separator = ", ";
        }

        out.println (");");

        // Write the initialisation of the fields.
        if (identityFields.size () != 0) {
            out.println ();
            for (Iterator innerI = identityFields.iterator ();
                 innerI.hasNext ();) {
                FieldInfo field = (FieldInfo) innerI.next ();
                String fieldName = field.getName ();

                /* Uncomment this to validate arguments.
                if (typeName.equals ("String")) {
                    out.println ("    if (" + fieldName + " == null) {");
                    out.println ("      throw new IllegalArgumentException (\""
                       + fieldName + " is null\");");
                    out.println ("    }");
                }
                */
                out.println ("    this." + fieldName + " = " + fieldName + ";");
            }
        }

        out.println ("  }");
    }

    // Write out the getter methods if any.
    for (Iterator i = identityFields.iterator (); i.hasNext ();) {
      FieldInfo field = (FieldInfo) i.next ();

      String fieldName = field.getName ();

      MethodInfo method = objectClassInfo.getGetterMethod (fieldName, true);

      // Make sure that the method has no extra parameters.
      List parameters = method.getParameters ();
      if (parameters.size () != 0) {
        throw new IllegalStateException ("Getter method has wrong number"
                                         + " of parameters");
      }

      // Write the getter method comment.
      GenerateUtilities.writeJavaDocComment (out, "  ", method.getComment ());

      // Write the getter method declaration.
      out.println ("  public " + method.getReturnTypeName () + " "
                   + method.getName () + " () {");

      // Write the method body.
      out.println ("    return " + fieldName + ";");

      // Write the method close.
      out.println ("  }");
    }

    // Write the getObjectClass method.
    out.println ();
    out.println ("  // Javadoc inherited from super class.");
    out.println ("  public Class getObjectClass () {");
    out.println ("    return " + objectClassName + ".class;");
    out.println ("  }");

    if (identityFields.size () != 0) {

      // Write the equals method.
      out.println ();
      out.println ("  // Javadoc inherited from super class.");
      out.println ("  public boolean equals (Object object) {");
      out.println ();
      GenerateUtilities.formatParagraph (out, "    // ",
                                         "Call the super class to check"
                                         + " whether this object and the other"
                                         + " object are of the same type and"
                                         + " have the same name.");
      out.println ("    if (!super.equals (object)) {");
      out.println ("      return false;");
      out.println ("    }");
      out.println ();
      out.println ("    " + identityClassName
                   + " identity = (" + identityClassName + ") object;");
      out.print ("    return ");
      separator = "";
      for (Iterator i = identityFields.iterator (); i.hasNext ();) {
        FieldInfo field = (FieldInfo) i.next ();
        String fieldName = field.getName ();
        String typeName = field.getTypeName ();

        out.print (separator);
        if (typeName.equals ("String")) {
          out.print ("equals (" + fieldName + ", identity." + fieldName + ")");
        } else {
          out.print (fieldName + " == identity." + fieldName);
        }
        separator = "      && ";

        if (i.hasNext ()) {
          out.println ();
        } else {
          out.println (";");
        }
      }
      out.println ("  }");

      // Write a hashCode method.
      out.println ();
      out.println ("  // Javadoc inherited from super class.");
      out.println ("  public int hashCode () {");
      out.println ("    return super.hashCode ()");
      for (Iterator i = identityFields.iterator (); i.hasNext ();) {
        FieldInfo field = (FieldInfo) i.next ();
        String fieldName = field.getName ();
        String typeName = field.getTypeName ();

        out.print ("      + ");
        if (typeName.equals ("boolean")) {
          out.println ("(" + fieldName + " ? 1 : 0)");
        } else if (typeName.equals ("int")) {
          out.println (fieldName);
        } else {
          out.println ("hashCode (" + fieldName + ")");
        }
        if (i.hasNext ()) {
          out.println ();
        } else {
          out.println (";");
        }
      }
      out.println ("  }");

      // Write the compareTo method.
      out.println ();
      out.println ("  // Javadoc inherited from super class.");
      out.println ("  public int compareTo (Object object) {");
      out.println ();
      GenerateUtilities.formatParagraph (out, "    // ",
                                         "Call the super class to check"
                                         + " whether this object and the other"
                                         + " object are of the same type and"
                                         + " have the same name.");
      out.println ("    int result;");
      out.println ("    if ((result = super.compareTo (object)) != 0) {");
      out.println ("      return result;");
      out.println ("    }");
      out.println ();
      out.println ("    " + identityClassName
                   + " identity = (" + identityClassName + ") object;");

      for (Iterator i = identityFields.iterator (); i.hasNext ();) {
        FieldInfo field = (FieldInfo) i.next ();
        String fieldName = field.getName ();

        out.println ();
        out.println ("    // Compare the " + fieldName);
        out.println ("    if ((result = compare (" + fieldName
                     + ", identity." + fieldName + ")) != 0) {");
        out.println ("      return result;");
        out.println ("    }");


      }
      out.println ();
      out.println ("    // The identities are equal.");
      out.println ("    return 0;");
      out.println ("  }");

      // Write a paramString method.
      out.println ();
      out.println ("  // Javadoc inherited from super class.");
      out.println ("  protected String paramString () {");
      out.println ("    return super.paramString ()");
      for (Iterator i = identityFields.iterator (); i.hasNext ();) {
        FieldInfo field = (FieldInfo) i.next ();
        String fieldName = field.getName ();

        out.print ("      + \", " + fieldName + "=\" + " + fieldName);
        if (i.hasNext ()) {
          out.println ();
        } else {
View Full Code Here


    // write the code which obtains the resolved field names
    if (info.insertRevision()) {
      writeGetResolvedFieldName("REVISION");
    }
    for (Iterator i = allObjectFields.iterator(); i.hasNext();) {
      FieldInfo field = (FieldInfo) i.next();
      String fieldName = field.getName();
      writeGetResolvedFieldName(fieldName);
    }

    // Write the code which creates the SQL statement.
    out.println ();
    out.println ("    String sql = \"insert into \" + tableName");
    StringBuffer buffer = new StringBuffer ();
    String separator = "";
    String concatOperator = " + ";
    int remaining = 60;

    // it is safe to always add the comma here since the table is guaranteed to have other columns
    //buffer.append( "PROJECT, " );

    // If we need to add revision to the list of columns to insert.
     if (info.insertRevision ()) {
       buffer.append (concatOperator);
       buffer.append ("revisionField");
       separator = " + \" , \" ";
     }

    for (Iterator i = allObjectFields.iterator (); i.hasNext ();) {
      FieldInfo field = (FieldInfo) i.next ();
      String fieldName =  field.getName ();

      buffer.append (separator);

      remaining -= separator.length () + fieldName.length () + concatOperator.length();
      if (remaining < 0) {
        buffer.append ("\n     ");
        remaining = 60;
      }
      buffer.append (concatOperator);
      buffer.append (fieldName.toLowerCase() + "Field");
      separator = " + \" , \" ";
    }
    out.println ("      + \" (\" "  + buffer + " + \") \"");

    out.println ("      + \"values (\"");

    // it is safe to always add the comma here since the table is guaranteed to have other columns
    //out.println ("      + JDBCAccessorHelper.quoteValue ( projectName ) + \" , \"" );

    // If we need to add revision to the list of values to insert.
    if (info.insertRevision ()) {
      out.println ("      + JDBCAccessorHelper.UNKNOWN_REVISION + \" , \"");
    }

    for (Iterator i = allObjectFields.iterator (); i.hasNext ();) {
      FieldInfo field = (FieldInfo) i.next ();
      if (GenerateUtilities.isProjectField(field)) {
          out.print ("      + JDBCAccessorHelper.quoteValue ( projectName )" );
      } else {
          MethodInfo getter =
            objectClassInfo.getGetterMethod (field.getName (), true);
          String value = "o." + getter.getName () + " ()";
          out.print ("      + " + getJDBCQuoteValue (field, value));
      }
      if (i.hasNext ()) {
        out.println (" + \" , \"");
View Full Code Here

    writeGetJDBCConnection();

    // write the code which resolves the field names
    for (Iterator i = allIdentityFields.iterator (); i.hasNext ();) {
      FieldInfo field = (FieldInfo) i.next ();
      if (!GenerateUtilities.isProjectField(field)) {
        String fieldName = field.getName ();
        writeGetResolvedFieldName(fieldName);
      }
    }

    out.println ();
    writeGetProjectName(false);

    // Write the code which creates the SQL statement.
    out.println ();
    out.println ("    String sql = \"delete from \" + tableName");
    out.println ("      + \" where PROJECT = \" + "
            + "JDBCAccessorHelper.quoteValue( projectName ) + \" and \"" );
    for (Iterator i = allIdentityFields.iterator (); i.hasNext ();) {
      FieldInfo field = (FieldInfo) i.next ();
      if (!GenerateUtilities.isProjectField(field)) {
        String fieldName = field.getName ();
        MethodInfo getter = identityClassInfo.getGetterMethod (fieldName,
                                                               true);
        out.println ("      + " + fieldName.toLowerCase () +"Field" + " + \" = \"");
        String value = "id." + getter.getName () + " ()";
        out.print ("      + " + getJDBCQuoteValue (field, value));
View Full Code Here

    // Initialise the object from the result set.
    int index = 1;
    for (Iterator i = extraObjectFields.iterator (); i.hasNext ();
         index += 1) {
      FieldInfo field = (FieldInfo) i.next ();
      String fieldName = field.getName ();
      MethodInfo setter = objectClassInfo.getSetterMethod (fieldName, true);

      out.println ("      object." + setter.getName () + " ("
                   + getResultSetValue (field, "rs", index) + ");");
    }
View Full Code Here

    // get the resolved field name for the project field
    writeGetResolvedFieldName("project");

    // get the resolved field names for the remaining fields
    for (Iterator i = allIdentityFields.iterator(); i.hasNext();) {
      FieldInfo field = (FieldInfo) i.next();
      if (!GenerateUtilities.isProjectField(field)) {
        String fieldName = field.getName();
        writeGetResolvedFieldName(fieldName);
      }
    }



    // Write the code which creates the SQL statement.
    out.println ();
    out.println ("    String sql = \"update \" + tableName");
    out.println ("      + \" set \"");
    out.println ("      + nameField + \" = \"");
    out.println ("      + JDBCAccessorHelper.quoteValue (newName)");
    out.println ("      + \" where \" + projectField + \" = \" "
            + "+ JDBCAccessorHelper.quoteValue( projectName ) + \" and \"" );

    for (Iterator i = allIdentityFields.iterator (); i.hasNext ();) {
      FieldInfo field = (FieldInfo) i.next ();
      if (!GenerateUtilities.isProjectField(field)) {
        String fieldName = field.getName ();
        MethodInfo getter = identityClassInfo.getGetterMethod (fieldName,
                                                               true);

        out.println ("      + " + fieldName.toLowerCase()+"Field" + " + \" =\"");
        String value = "id." + getter.getName () + " ()";
View Full Code Here

    ArrayList resolvedFields = new ArrayList(); // stores fields which have been resolved

    // write the code which gets the resolved field names for the update string
    for (Iterator i = extraObjectFields.iterator(); i.hasNext();) {
      FieldInfo field = (FieldInfo) i.next();
      String fieldName = field.getName();
      writeGetResolvedFieldName(fieldName);
      resolvedFields.add(field);
    }

    // write the code which gets the resolved field names for the query string
    writeGetResolvedFieldNamesForQueryString(allIdentityFields, resolvedFields);

    // Write the code which creates the SQL statement.
    out.println ();
    out.println ("    String sql = \"update \" + tableName");
    out.println ("      + \" set \"");

    for (Iterator i = extraObjectFields.iterator (); i.hasNext ();) {
      FieldInfo field = (FieldInfo) i.next ();
      String fieldName = field.getName ();

      MethodInfo getter = objectClassInfo.getGetterMethod (fieldName, true);
      String value = "o." + getter.getName () + " ()";

      out.println ("      + " + fieldName.toLowerCase()+"Field" + " + \" = \"");
View Full Code Here

      out.println ("    " + objectClassName + "Identity id = ("
                   + objectClassName + "Identity) identity;");
      out.println ("    StringBuffer fields = new StringBuffer();");

      for (Iterator i = allIdentityFields.iterator (); i.hasNext ();) {
        FieldInfo field = (FieldInfo) i.next ();
        String fieldName = field.getName ();
        // name is already used in locking
        if ("name".equals(fieldName)) {
          continue;
        }
        MethodInfo getter =
View Full Code Here

    out.println ("    // get resolved field names for select string ");
    if (selectFields.size () == 0) {
      if (queryFields.size () == 0) {
        throw new IllegalArgumentException ("Not sure what to do");
      } else {
        FieldInfo field = (FieldInfo) queryFields.get (0);
        writeGetResolvedFieldName(field.getName ());
        resolvedFields.add(field);
      }
    } else {
      for (Iterator i = selectFields.iterator (); i.hasNext ();) {
        FieldInfo field = (FieldInfo) i.next ();
        writeGetResolvedFieldName(field.getName ());
        resolvedFields.add(field);
      }
    }

    // write code which will resolve the field names for the query
    writeGetResolvedFieldNamesForQueryString(queryFields, resolvedFields);

    // write the query
    out.println ("    String sql = \"select \"");

    int remaining = 60;

    if (selectFields.size() == 0) {
      if (queryFields.size() == 0) {
        throw new IllegalArgumentException("Not sure what to do");
      } else {
        FieldInfo field = (FieldInfo) queryFields.get(0);
        out.println("      + " + field.getName().toLowerCase() + "Field");
      }
    } else {
      StringBuffer buffer = new StringBuffer();
      String separator = "";
      String concactonator = " + ";
      for (Iterator i = selectFields.iterator(); i.hasNext();) {
        FieldInfo field = (FieldInfo) i.next();
        remaining -= separator.length() + field.getName().length() + concactonator.length();
        if (remaining < 0) {
          buffer.append("\n     ");
          remaining = 60;
        }
        buffer.append(concactonator);
        buffer.append(field.getName().toLowerCase() + "Field");
        if(i.hasNext()) {
          separator = "+  \" , \" ";
        }
        else {
          separator = "";
View Full Code Here

      out.println (";");
    } else {
      out.println ();
      out.println ("      + \" where \"");
      for (Iterator i = queryFields.iterator (); i.hasNext ();) {
        FieldInfo field = (FieldInfo) i.next ();
        String fieldName = field.getName ();
        MethodInfo getter = queryClassInfo.getGetterMethod (fieldName,
                                                            true);

        out.println ("      + " + fieldName.toLowerCase()+"Field" + " + \" = \"");
        String value = queryObjectName + "." + getter.getName () + " ()";
View Full Code Here

      } else {
        out.println ();
        out.println ("      + \" " + sqlOperation + "\"");
        String value;
        for (Iterator i = queryFields.iterator (); i.hasNext ();) {
          FieldInfo field = (FieldInfo) i.next ();
          String fieldName = field.getName ();
          MethodInfo getter = queryClassInfo.getGetterMethod(fieldName,
                                                             true);

          out.println("      +  " + fieldName.toLowerCase()+"Field" + " + \" = \" ");
          if (!GenerateUtilities.isProjectField(field)) {
View Full Code Here

TOP

Related Classes of com.volantis.mcs.build.javadoc.FieldInfo

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.