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

  }

  public JavaMethod getXMLGetMethod(PropertySG pController, JavaSource pSource) throws SAXException {
    String fieldName = pController.getXMLFieldName();
    String methodName = pController.getXMLGetMethodName();
    JavaMethod result = pSource.newJavaMethod(methodName, List.class, JavaSource.PUBLIC);
    result.addLine("return ", fieldName, ";");
    return result;
  }
View Full Code Here

    DirectAccessible pLexicalValue = con.addParam(String.class, "pLexicalValue");
    con.addLine(name, " = ", pName, ";");
    con.addLine(value, " = ", pValue, ";");
    con.addLine(lexicalValue, " = ", pLexicalValue, ";");

    JavaMethod toStringMethod = js.newJavaMethod("toString", String.class, JavaSource.PUBLIC);
    toStringMethod.addLine("return ", lexicalValue, ";");

    JavaMethod getValueMethod = js.newJavaMethod("getValue", valueType, JavaSource.PUBLIC);
    getValueMethod.addLine("return ", value, ";");

    JavaMethod getNameMethod = js.newJavaMethod("getName", String.class, JavaSource.PUBLIC);
    getNameMethod.addLine("return ", name, ";");

    JavaMethod getInstancesMethod = js.newJavaMethod("getInstances", qNameArray, JavaSource.PUBLIC);
    getInstancesMethod.setStatic(true);
    getInstancesMethod.addLine("return ", instances, ";");

    JavaMethod fromValueMethod = js.newJavaMethod("fromValue", qName, JavaSource.PUBLIC);
    pValue = fromValueMethod.addParam(valueType, "pValue");
    fromValueMethod.setStatic(true);
    DirectAccessible i = fromValueMethod.addForArray(instances);
    fromValueMethod.addIf(pController.getEqualsCheck(fromValueMethod, new Object[]{instances, "[", i, "].value"}, pValue));
    fromValueMethod.addLine("return ", instances, "[", i, "];");
    fromValueMethod.addEndIf();
    fromValueMethod.addEndFor();
    fromValueMethod.addThrowNew(IllegalArgumentException.class, JavaSource.getQuoted("Invalid value: "),
                                " + ", pValue);

    JavaMethod fromNameMethod = js.newJavaMethod("fromName", qName, JavaSource.PUBLIC);
    pName = fromNameMethod.addParam(String.class, "pName");
    fromNameMethod.setStatic(true);
    i = fromNameMethod.addForArray(instances);
    fromNameMethod.addIf(instances, "[", i, "].name.equals(", pName, ")");
    fromNameMethod.addLine("return ", instances, "[", i, "];");
    fromNameMethod.addEndIf();
    fromNameMethod.addEndFor();
    fromNameMethod.addThrowNew(IllegalArgumentException.class, JavaSource.getQuoted("Invalid name: "),
                                " + ", pName);

    JavaMethod fromStringMethod = js.newJavaMethod("fromString", qName, JavaSource.PUBLIC);
    pValue = fromStringMethod.addParam(String.class, "pValue");
    fromStringMethod.setStatic(true);
    fromStringMethod.addLine("return ", fromValueMethod, "(",
                             super.getCastFromString(pController, fromStringMethod, pValue, null), ");");

    if (js.isImplementing(Serializable.class)) {
      JavaMethod readResolveMethod = js.newJavaMethod("readResolve", Object.class, JavaSource.PRIVATE);
      readResolveMethod.addLine("return ", fromValueMethod, "(", value, ");");
    }
    return js;
  }
View Full Code Here

        myName.addLine("new ", QName.class, "(", JavaSource.getQuoted(qName.getNamespaceURI()),
                     ", ", JavaSource.getQuoted(qName.getLocalName()), ", ",
             JavaSource.getQuoted(prefix), ")");
    }

    JavaMethod getQName = js.newJavaMethod("getQName", QName.class, JavaSource.PUBLIC);
    getQName.addLine("return ", myName, ";");

    return js;
  }
View Full Code Here

      if (myTypeSG.isGlobalClass()) {
        Context typeContext = myTypeSG.getComplexTypeSG().getClassContext();
        js.addExtends(typeContext.getXMLHandlerName());
        JavaQName xmlElementInterface = pController.getClassContext().getXMLInterfaceName();
        JavaQName resultInterface = typeContext.getXMLInterfaceName();
        JavaMethod jm = js.newJavaMethod("newResult", resultInterface, JavaSource.PROTECTED);
        jm.addThrows(SAXException.class);
        jm.addTry();
        jm.addLine("return (", resultInterface, ") getData().getFactory().getElement(",
                   xmlElementInterface, ".class);");
        DirectAccessible e = jm.addCatch(JAXBException.class);
        jm.addThrowNew(SAXException.class, e);
        jm.addEndTry();
      } else {
        myTypeSG.getComplexTypeSG().generateXMLHandlerMethods(js);
      }
      return js;
    }
View Full Code Here

                           DirectAccessible pLevelVar)
      throws SAXException {
      if (!pController.hasSimpleContent()  &&  pController.getComplexContentSG().getGroupSG() != null) {
          return null// GroupSG creates method
      }
      JavaMethod jm = pSource.newJavaMethod("endElement", void.class, JavaSource.PUBLIC);
      DirectAccessible pNamespaceURI = jm.addParam(String.class, "pNamespaceURI");
      DirectAccessible pLocalName = jm.addParam(String.class, "pLocalName");
      DirectAccessible pQName = jm.addParam(String.class, "pQName");
      jm.addThrows(SAXException.class);
      jm.addSwitch("--", pLevelVar);
      jm.addCase("0");
      if (pController.hasSimpleContent()) {
          JavaQName elementInterface = pController.getClassContext().getXMLInterfaceName();
          LocalJavaField element = jm.newJavaField(elementInterface);
          element.addLine("(", elementInterface, ") getResult()");

          SimpleContentSG simpleContent = pController.getSimpleContentSG();
          Object value = simpleContent.getContentTypeSG().getSimpleTypeSG().getCastFromString(jm, "__content.toString()", "getData()");
          simpleContent.getPropertySG().setValue(jm, element, value, null);
      }
      jm.addBreak();
      if (pController.hasSimpleContent()) {
          jm.addDefault();
          jm.addLine("super.endElement(pNamespaceURI, pLocalName, pQName);");
          jm.addBreak();
      } else {
          PlaceHolder placeHolder = jm.newPlaceHolder("GroupSG", true);
          placeHolder.setProperty("pNamespaceURI", pNamespaceURI);
          placeHolder.setProperty("pLocalName", pLocalName);
          placeHolder.setProperty("pQName", pQName);
      }
      jm.addEndSwitch();
      return jm;
  }
View Full Code Here

  }

  public JavaMethod getXMLHandlersStartElementMethod(ComplexTypeSG pController, JavaSource pSource,
                             DirectAccessible pLevelVar)
      throws SAXException {
    JavaMethod jm = pSource.newJavaMethod("startElement", void.class, JavaSource.PUBLIC);
    DirectAccessible pNamespaceURI = jm.addParam(String.class, "pNamespaceURI");
    DirectAccessible pLocalName = jm.addParam(String.class, "pLocalName");
    DirectAccessible pQName = jm.addParam(String.class, "pQName");
    DirectAccessible pAttr = jm.addParam(Attributes.class, "pAttr");
    jm.addThrows(SAXException.class);

    jm.addSwitch(pLevelVar, "++");
    jm.addCase("0");
   
    jm.addLine("setResult(newResult());");
    jm.addIf(pAttr, " != null");
   
    String iVar = jm.getLocalVariableName();
    jm.addFor("int ", iVar, " = 0;  ", iVar, " < pAttr.getLength();  ", iVar, "++");
    AttributeSG[] myAttributes = pController.getAttributes();
    if (myAttributes.length == 0) {
      jm.addLine("super.addAttribute(", pAttr, ".getURI(", iVar, "), ", pAttr, ".getLocalName(", iVar,
          "), ", pAttr, ".getValue(", iVar, "));");
    } else {
      jm.addLine("addAttribute(", pAttr, ".getURI(", iVar, "), ", pAttr, ".getLocalName(", iVar,
          "), ", pAttr, ".getValue(", iVar, "));");     
    }
    jm.addEndFor();
    jm.addEndIf();
    if (pController.hasSimpleContent()) {
        JavaField jf = pSource.newJavaField("__content", StringBuffer.class, JavaSource.PRIVATE);
        jm.addLine(jf, " = new ", StringBuffer.class, "();");
    }
    jm.addBreak();
   
    if (pController.hasSimpleContent()) {
      jm.addDefault();
      jm.addLine("super.startElement(pNamespaceURI, pLocalName, pQName, pAttr);");
      jm.addBreak();
    } else {
      PlaceHolder placeHolder = jm.newPlaceHolder("GroupSG", true);
      placeHolder.setProperty("pNamespaceURI", pNamespaceURI);
      placeHolder.setProperty("pLocalName", pLocalName);
      placeHolder.setProperty("pQName", pQName);
      placeHolder.setProperty("pAttr", pAttr);
    }
    jm.addEndSwitch();
   
    return jm;
  }
View Full Code Here

  protected JavaMethod getXMLHandlersCharactersMethod(ComplexTypeSG pController, JavaSource pSource,
                            JavaField pLevelVar) throws SAXException {
      if (!pController.hasSimpleContent()) {
          return null;
      }
      JavaMethod jm = pSource.newJavaMethod("characters", void.class, JavaSource.PUBLIC);
      Parameter buffer = jm.addParam(char[].class, "pChars");
      Parameter offset = jm.addParam(int.class, "pOffset");
      Parameter length = jm.addParam(int.class, "pLength");
      jm.addThrows(SAXException.class);
      jm.addIf(pLevelVar, " == 1");
      jm.addLine("__content.append(", buffer, ", ", offset, ", ", length, ");");
      jm.addEndIf();
      return jm;
  }
View Full Code Here

    if (!pController.hasAttributes()) {
      log.finest(mName, "<-");
      return;
    }
   
    JavaMethod jm = pSource.newJavaMethod("getAttributes", AttributesImpl.class, "protected");
    DirectAccessible pData = jm.addParam(JavaQNameImpl.getInstance(JMXmlSerializer.Data.class), "pData");
    DirectAccessible pElement = jm.addParam(Object.class, "pElement");
    jm.addThrows(SAXException.class);
    LocalJavaField result = jm.newJavaField(AttributesImpl.class);
    result.addLine("super.getAttributes(", pData, ", ", pElement, ")");
    JavaQName elementInterface = pController.getClassContext().getXMLInterfaceName();
    LocalJavaField element = jm.newJavaField(elementInterface);
    element.addLine("(", elementInterface, ") ", pElement);
   
    AttributeSG[] myAttributes = pController.getAttributes();
    XMLSerializerAttributeSGlet sgLet = new XMLSerializerAttributeSGlet(result, pData);
    for (int i = 0;  i < attributes.length;  i++) {
      AttributeSG attribute = myAttributes[i];
      if (attribute.isWildcard()) {
          LocalJavaField anyAttributes = jm.newJavaField(WildcardAttribute[].class);
          anyAttributes.addLine(element, ".", attribute.getPropertySG().getXMLGetMethodName() + "Array", "()");
          DirectAccessible index = jm.addForArray(anyAttributes);
          LocalJavaField wildcardAttribute = jm.newJavaField(WildcardAttribute.class);
          wildcardAttribute.addLine(anyAttributes, "[", index, "]");
        LocalJavaField qName = jm.newJavaField(QName.class);
        qName.addLine(wildcardAttribute, ".getName()");
        LocalJavaField uri = jm.newJavaField(String.class);
        uri.addLine(qName, ".getNamespaceURI()");
        LocalJavaField localPart = jm.newJavaField(String.class);
        localPart.addLine(qName, ".getLocalPart()");
        jm.addLine(result, ".addAttribute(", uri, ", ", localPart,
               ", getAttributeQName(pData, ", uri, ", ", localPart,
                           "), \"CDATA\", ", wildcardAttribute, ".getValue());");
        jm.addEndFor();
      } else {
        sgLet.setAttribute(attribute);
        attribute.forAllNonNullValues(jm, element, sgLet);
      }
    }
    jm.addLine("return ", result, ";");
  }
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.