Package org.apache.ws.jaxme.js

Examples of org.apache.ws.jaxme.js.JavaMethod


   }

   private JavaSource getPlaceHolderSource(boolean pAutoMode) {
     JavaSourceFactory factory = new JavaSourceFactory();
     JavaSource js = factory.newJavaSource(JavaQNameImpl.getInstance("com.foo", "Bar"), JavaSource.PUBLIC);
     JavaMethod main = js.newJavaMethod("main", JavaQNameImpl.VOID, JavaSource.PUBLIC);
     main.addParam(String[].class, "pArgs");
     main.setStatic(true);
     main.addThrows(Exception.class);
     main.addFor(int.class, " i = 1;  i < 10;  i++");
     main.newPlaceHolder("test", pAutoMode);
     main.addEndFor();
     js.setDynamicImports(true);
     return js;
   }
View Full Code Here


         }
         assertTrue(gotException);
       }

       js = getPlaceHolderSource(autoMode);
       JavaMethod main = js.getMethod("main", new JavaQName[]{JavaQNameImpl.getInstance(String[].class)});
       PlaceHolder test = main.getPlaceHolder("test");
       assertNotNull(test);
       test.remove();
       main.addLine("// I am here");

       String expect = "package com.foo;\n" +
                       "\n" +
                       "public class Bar {\n" +
                       "  public static void main(java.lang.String[] pArgs) throws java.lang.Exception {\n" +
View Full Code Here

//    this.addItemer("values", "get", itemType);
//    this.addSizer("values", "size");
//  }
 
  protected void addGetter(String propertyName, String methodName, JavaQName propertyType) {
    JavaMethod getMethod = source.newJavaMethod(methodName, propertyType, JavaSource.PUBLIC);
    getMethod.addLine("return this.", propertyName, ";");   
  }
View Full Code Here

    JavaMethod getMethod = source.newJavaMethod(methodName, propertyType, JavaSource.PUBLIC);
    getMethod.addLine("return this.", propertyName, ";");   
  }
 
  protected void addSetter(String propertyName, String methodName, JavaQName propertyType) {
    JavaMethod setMethod = source.newJavaMethod(methodName, JavaQNameImpl.VOID, JavaSource.PUBLIC);
    setMethod.addParam(propertyType, propertyName);
    setMethod.addLine("this.", propertyName, " = ", propertyName, ";");
  }
View Full Code Here

    setMethod.addParam(propertyType, propertyName);
    setMethod.addLine("this.", propertyName, " = ", propertyName, ";");
  }
 
  protected void addAdder(String propertyName, String methodName, JavaQName arrayType) {
    JavaMethod addMethod = source.newJavaMethod(methodName, JavaQNameImpl.VOID, JavaSource.PUBLIC);
    addMethod.addParam(arrayType, propertyName);
    if(!options.isListAsPlainArray()) {
      addMethod.addLine("if(this."+propertyName+"==null) this."+propertyName
        +" = new "+JavaQNameImpl.getInstance(options.getListImplementation())+"();");
      addMethod.addLine("this.", propertyName, ".add(", propertyName, ");");
    } else {
      addMethod.addLine(arrayType.getClassName()+"[] tmp = new "+arrayType.getClassName()
        +"[this."+propertyName+"==null?1:this."+propertyName+".length+1];");
      addMethod.addLine("System.arraycopy(this."+propertyName+", 0, tmp, 0, tmp.length-1);");
      addMethod.addLine("tmp[tmp.length-1] = "+propertyName+";");
      addMethod.addLine("this."+propertyName+" = tmp;");
    }
  }
View Full Code Here

      addMethod.addLine("this."+propertyName+" = tmp;");
    }
  }
 
  protected void addSizer(String propertyName, String methodName) {
    JavaMethod addMethod = source.newJavaMethod(methodName, JavaQNameImpl.INT, JavaSource.PUBLIC);
    addMethod.addLine("if(this."+propertyName+"==null) return 0;");
    if(options.isListAsPlainArray()) {
      addMethod.addLine("return this."+propertyName+".length;");
    } else {
      addMethod.addLine("return this."+propertyName+".size();");
    }
  }
View Full Code Here

      addMethod.addLine("return this."+propertyName+".size();");
    }
  }
 
  protected void addItemer(String propertyName, String methodName, JavaQName arrayType) {
    JavaMethod itemMethod = source.newJavaMethod(methodName, arrayType, JavaSource.PUBLIC);
    itemMethod.addParam(JavaQNameImpl.INT, "num");
    if(options.isListAsPlainArray()) {
      itemMethod.addLine("return this."+propertyName+"[num];");
    } else {
      itemMethod.addLine("return ("+arrayType.getClassName()+")this."+propertyName+".get(num);");
    }
  }
View Full Code Here

      itemMethod.addLine("return ("+arrayType.getClassName()+")this."+propertyName+".get(num);");
    }
  }
 
  protected void addRemover(String propertyName, String methodName, JavaQName arrayType) {
    JavaMethod itemMethod = source.newJavaMethod(methodName, arrayType, JavaSource.PUBLIC);
    itemMethod.addParam(JavaQNameImpl.INT, "num");
    if(options.isListAsPlainArray()) {
      throw new IllegalStateException("remove method arent supported with plain arrays");
    } else {
      itemMethod.addLine("return ("+arrayType.getClassName()+")this."+propertyName+".remove(num);");
    }
  }
View Full Code Here

    return pParamNum;
  }

  protected JavaMethod getPMClassInsertMethod(TypeSG pController, JavaSource pSource, CustomTableData pData)
      throws SAXException {
    JavaMethod jm = pSource.newJavaMethod("insert", JavaQNameImpl.VOID, JavaSource.PUBLIC);
    Parameter pElement = jm.addParam(Element.class, "pElement");
    jm.addThrows(PMException.class);
    Table table = pData.getTable();

    String q = table.getSchema().getSQLFactory().newSQLGenerator().getQuery(table.getInsertStatement());
    LocalJavaField query = jm.newJavaField(String.class);
    query.setFinal(true);
    query.addLine(JavaSource.getQuoted(q));

    JavaQName qName = pController.getComplexTypeSG().getClassContext().getXMLInterfaceName();
    LocalJavaField elem = jm.newJavaField(qName);
    elem.addLine("(", qName, ") ", pElement);

    LocalJavaField connection = jm.newJavaField(Connection.class);
    connection.addLine("null");
    jm.addTry();
    jm.addLine(connection, " = getConnection();");
    LocalJavaField stmt = jm.newJavaField(PreparedStatement.class);
    stmt.addLine(connection, ".prepareStatement(", query, ")");
    jm.addTry();
    getPreparedStatementParameters(jm, stmt, elem, table.getColumns(), 0);
    jm.addLine(stmt, ".executeUpdate();");
    getFinally(jm, stmt, null, null);
    getFinally(jm, connection, new Object[]{JavaSource.getQuoted("Failed to execute query "),
                                            " + ", query}, null);
    return jm;
  }
View Full Code Here

    return jm;
  }

  protected JavaMethod getPMClassUpdateMethod(TypeSG pController, JavaSource pSource, CustomTableData pData)
      throws SAXException {
    JavaMethod jm = pSource.newJavaMethod("update", JavaQNameImpl.VOID, JavaSource.PUBLIC);
    Parameter pElement = jm.addParam(Element.class, "pElement");
    jm.addThrows(PMException.class);
    Table table = pData.getTable();

    String q = table.getSchema().getSQLFactory().newSQLGenerator().getQuery(table.getUpdateStatement());
    LocalJavaField query = jm.newJavaField(String.class);
    query.setFinal(true);
    query.addLine(JavaSource.getQuoted(q));

    JavaQName qName = pController.getComplexTypeSG().getClassContext().getXMLInterfaceName();
    LocalJavaField elem = jm.newJavaField(qName);
    elem.addLine("(", qName, ") ", pElement);

    LocalJavaField connection = jm.newJavaField(Connection.class);
    connection.addLine("null");
    jm.addTry();
    jm.addLine(connection, " = getConnection();");

    LocalJavaField stmt = jm.newJavaField(PreparedStatement.class);
    stmt.addLine(connection, ".prepareStatement(", query, ")");
    jm.addTry();

    List nonKeyColumns = new ArrayList();
    for (Iterator iter = table.getColumns();  iter.hasNext()) {
      Column col = (Column) iter.next();
      if (!col.isPrimaryKeyPart()) {
        nonKeyColumns.add(col);
      }
    }
    int i = 0;
    i = getPreparedStatementParameters(jm, stmt, elem, nonKeyColumns.iterator(), i);
    getPreparedStatementParameters(jm, stmt, elem, table.getPrimaryKey().getColumns(), i);
    jm.addLine(stmt, ".executeUpdate();");

    getFinally(jm, stmt, null, null);
    getFinally(jm, connection, new Object[]{JavaSource.getQuoted("Failed to execute query "),
                                            " + ", query}, null);
    return jm;
View Full Code Here

TOP

Related Classes of org.apache.ws.jaxme.js.JavaMethod

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.