Package org.apache.ws.jaxme.js

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


    return jm;
  }

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

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

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

    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.getPrimaryKey().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 getPMClassSelectMethod(TypeSG pController, JavaSource pSource, CustomTableData pData)
      throws SAXException {
    JavaMethod jm = pSource.newJavaMethod("select", JavaQNameImpl.VOID, JavaSource.PUBLIC);
    Parameter pObserver = jm.addParam(Observer.class, "pObserver");
    Parameter pQuery = jm.addParam(String.class, "pQuery");
    Parameter pParams = jm.addParam(PMParams.class, "pParams");
    jm.addThrows(PMException.class);
    Table table = pData.getTable();

    JavaQName qName = pController.getComplexTypeSG().getClassContext().getXMLInterfaceName();
    StringBuffer sb = new StringBuffer();
    for (Iterator iter = table.getColumns();  iter.hasNext()) {
      Column col = (Column) iter.next();
      if (sb.length() > 0) sb.append(", ");
      sb.append(col.getName().getName());
    }
    LocalJavaField query = jm.newJavaField(String.class);
    jm.addIf(pParams, " != null  &&  pParams.isDistinct()");
    jm.addLine(query, " = ", JavaSource.getQuoted("SELECT DISTINCT"), ";");
    jm.addElse();
    jm.addLine(query, " = ", JavaSource.getQuoted("SELECT"), ";");
    jm.addEndIf();
    jm.addLine(query, " += ", JavaSource.getQuoted(" " + sb + " FROM " + table.getQName()), ";");
    jm.addIf(pQuery, " != null");
    jm.addLine(query, " += ", JavaSource.getQuoted(" WHERE "), " + ", pQuery, ";");
    jm.addEndIf();

    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();
    LocalJavaField rs = jm.newJavaField(ResultSet.class);
    rs.addLine(stmt, ".executeQuery();");
    jm.addTry();
    jm.addWhile(rs, ".next()");
    LocalJavaField elem = jm.newJavaField(qName);
    elem.addLine("(", qName, ") create()");
    getResultSet(jm, rs, elem, table.getColumns(), 0);
    jm.addLine(pObserver, ".notify(", elem, ");");
    jm.addEndWhile();

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

    jcon.addThrows(JAXBException.class);
    jcon.addLine(jf, " = (", JAXBContextImpl.class, ") ",
                 JAXBContext.class, ".newInstance(",
                 JavaSource.getQuoted(pPackageName), ");");

    JavaMethod newInstanceMethod = js.newJavaMethod("newInstance", Object.class, "public");
    newInstanceMethod.addThrows(JAXBException.class);
    Parameter pElementInterface = newInstanceMethod.addParam(Class.class, "pElementInterface");
    newInstanceMethod.addLine("return ", jf, ".getElement(", pElementInterface, ");");

    {
      JavaMethod getPropertyMethod = js.newJavaMethod("getProperty", Object.class, "public");
      Parameter pName = getPropertyMethod.addParam(String.class, "pName");
      getPropertyMethod.addIf(properties, " == null");
      getPropertyMethod.addLine("return null;");
      getPropertyMethod.addEndIf();
      getPropertyMethod.addLine("return ", properties, ".get(", pName, ");");
    }

    {
      JavaMethod setPropertyMethod = js.newJavaMethod("setProperty", void.class, "public");
      Parameter pName = setPropertyMethod.addParam(String.class, "pName");
      Parameter pValue = setPropertyMethod.addParam(Object.class, "pValue");
      setPropertyMethod.addIf(properties, " == null");
      setPropertyMethod.addLine(properties, " = new ", HashMap.class, "();");
      setPropertyMethod.addEndIf();
      setPropertyMethod.addLine(properties, ".put(", pName, ", ", pValue, ");");
    }

    Set contextSet = new HashSet();
    for (Iterator iter = pContextList.iterator();  iter.hasNext()) {
      Object o = iter.next();
View Full Code Here

   */
  private void generateCreateMethod(JavaSource pSource, Context pContext) {
    JavaQName resultName = pContext.getXMLInterfaceName();
    String className = resultName.getClassName();
    String methodName = "create" + Character.toUpperCase(className.charAt(0)) + className.substring(1);
    JavaMethod createMethod = pSource.newJavaMethod(methodName, resultName, "public");
    createMethod.addThrows(JAXBException.class);
    createMethod.addLine("return (", resultName, ") newInstance(", resultName, ".class);");
  }
View Full Code Here

  public JavaMethod getXMLSetMethod(SimpleTypeSG pController, JavaSource pSource,
                                     String pFieldName, String pMethodName) throws SAXException {
    if (pController.hasSetMethod()) {
      String pName = "p" + Character.toUpperCase(pFieldName.charAt(0)) + pFieldName.substring(1);
      JavaMethod jm = pSource.newJavaMethod(pMethodName, JavaQNameImpl.VOID, JavaSource.PUBLIC);
      DirectAccessible param = jm.addParam(pController.getRuntimeType(), pName);
      if (!pSource.isInterface()) {
        pController.addValidation(jm, param);
        jm.addLine(pFieldName, " = ", param, ";");
      }
      return jm;
    } else {
      return null;
    }                                
View Full Code Here

          pMethod.addEndIf();
      }
  }

  public JavaMethod getXMLGetMethod(PropertySG pController, JavaSource pSource) throws SAXException {
      JavaMethod jm = pSource.newJavaMethod(pController.getXMLGetMethodName(), String.class, JavaSource.PUBLIC);
      JavaComment jc = jm.newComment();
      jc.addLine("<p>Returns the value of the 'anyAttribute' named <code>pName</code>.</p>");
      jc.addLine("@return Attribute value or null, if the attribute is not set.");
      jc.addLine("@throws NullPointerException The <code>pName</code> argument is null.");
      if (!namespaceList.isAny()) {
          jc.addLine("@throws IllegalArgumentException The namespace <code>pName.getNamespaceURI()</code> is invalid.");
      }
      Parameter pName = jm.addParam(QName.class, "pName");
      if (!pSource.isInterface()) {
        jm.addIf(pName, " == null");
        jm.addThrowNew(NullPointerException.class, JavaSource.getQuoted("The pName argument must not be null."));
        jm.addEndIf();
        getValidNamespaceCheck(pController, jm, pName);
        jm.addLine("return (", String.class, ") ", pController.getXMLFieldName(), ".get(", pName, ");");
      }
      return jm;
  }
View Full Code Here

      }
      return jm;
  }

  public JavaMethod getXMLSetMethod(PropertySG pController, JavaSource pSource) throws SAXException {
      JavaMethod jm = pSource.newJavaMethod(pController.getXMLSetMethodName(), void.class, JavaSource.PUBLIC);
      JavaComment jc = jm.newComment();
      jc.addLine("<p>Sets the 'anyAttribute' named <code>pName</code> to the value <code>pValue</code>.</p>");
      if (!namespaceList.isAny()) {
          jc.addLine("@throws IllegalArgumentException The namespace <code>pName.getNamespaceURI()</code> is invalid.");
      }
      jc.addLine("@throws NullPointerException Either of the arguments <code>pName</code> or <code>pValue</code> is null.");
      Parameter pName = jm.addParam(QName.class, "pName");
      Parameter pValue = jm.addParam(String.class, "pValue");
      if (!pSource.isInterface()) {
        jm.addIf(pName, " == null");
        jm.addThrowNew(NullPointerException.class, JavaSource.getQuoted("The pName argument must not be null."));
        jm.addEndIf();
        jm.addIf(pValue, " == null");
        jm.addThrowNew(NullPointerException.class, JavaSource.getQuoted("The pValue argument must not be null."));
        jm.addEndIf();
        getValidNamespaceCheck(pController, jm, pName);
        jm.addLine(pController.getXMLFieldName(), ".put(", pName, ", ", pValue, ");");
      }
      return jm;
  }
View Full Code Here

      }
      return jm;
  }

  public JavaMethod getXMLUnsetMethod(PropertySG pController, JavaSource pSource) throws SAXException {
      JavaMethod jm = pSource.newJavaMethod("un" + pController.getXMLSetMethodName(), boolean.class, JavaSource.PUBLIC);
      JavaComment jc = jm.newComment();
      jc.addLine("<p>Removes the 'anyAttribute' named <code>pName</code>.</p>");
      if (!namespaceList.isAny()) {
          jc.addLine("@throws IllegalArgumentException The namespace <code>pName.getNamespaceURI()</code> is invalid.");
      }
      jc.addLine("@throws NullPointerException Either of the arguments <code>pName</code> or <code>pValue</code> is null.");
      jc.addLine("@return True, if the attribute was set, otherwise false.");
      Parameter pName = jm.addParam(QName.class, "pName");
      if (!pSource.isInterface()) {
        jm.addIf(pName, " == null");
        jm.addThrowNew(NullPointerException.class, JavaSource.getQuoted("The pName argument must not be null."));
        jm.addEndIf();
        getValidNamespaceCheck(pController, jm, pName);
        jm.addLine("return ", pController.getXMLFieldName(), ".remove(", pName, ") != null;");
      }
      return jm;
  }
View Full Code Here

      }
      return jm;
  }

  public JavaMethod getXMLGetArrayMethod(PropertySG pController, JavaSource pSource) throws SAXException {
      JavaMethod jm = pSource.newJavaMethod(pController.getXMLGetMethodName() + "Array", WildcardAttribute[].class, JavaSource.PUBLIC);
      JavaComment jc = jm.newComment();
      jc.addLine("<p>Returns the array of 'anyAttributes'.</p>");
      LocalJavaField size = jm.newJavaField(int.class);
      size.addLine(pController.getXMLFieldName(), ".size()");
      LocalJavaField result = jm.newJavaField(jm.getType());
      result.addLine("new ", WildcardAttribute.class, "[", size, "]");
      DirectAccessible iter = jm.addForCollection(new Object[]{pController.getXMLFieldName(), ".entrySet()"});
      LocalJavaField entry = jm.newJavaField(Map.Entry.class);
      entry.addLine("(", Map.Entry.class, ") ", iter, ".next()");
      if (!pSource.isInterface()) {
        jm.addLine(result, "[--", size, "] = new ", WildcardAttribute.class, "((",
                   QName.class, ") ", entry, ".getKey(), (", String.class, ") ",
             entry, ".getValue());");
        jm.addEndFor();
        jm.addLine("return ", result, ";");
      }
      return jm;
  }
View Full Code Here

    return "__ser_" + pChild.getXMLFieldName();
  }

  private JavaMethod getXMLSerializersInitMethod(GroupSG pController, JavaSource pSource) throws SAXException {
    ParticleSG[] myParticles = pController.getParticles();
    JavaMethod jm = null;
    DirectAccessible pFactory = null;
    for (int i = 0;  i < myParticles.length;  i++) {
      ParticleSG particle = myParticles[i];
      if (!particle.isElement()) {
        continue;
      }
      ObjectSG child = particle.getObjectSG();
      if (!child.getTypeSG().isComplex()) {
        continue;
      }
      if (jm == null) {
        jm = pSource.newJavaMethod("init", JavaQNameImpl.VOID, JavaSource.PUBLIC);
        pFactory = jm.addParam(JAXBContextImpl.class, "pFactory");
        jm.addLine("super.init(", pFactory, ");");
        jm.addThrows(JAXBException.class);
      }
      String serializerName = getXMLSerializersFieldName(particle.getPropertySG());
      Context myClassContext = child.getTypeSG().getComplexTypeSG().getClassContext();
      JavaQName serializerClass = myClassContext.getXMLSerializerName();
      pSource.newJavaField(serializerName, serializerClass, JavaSource.PRIVATE);
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.