Package org.apache.ws.jaxme.js

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


    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];
      sgLet.setAttribute(attribute);
      attribute.forAllNonNullValues(jm, element, sgLet);
    }
    jm.addLine("return ", result, ";");
  }
View Full Code Here


    }

    if (uris.isEmpty()) {
      return null;
    }
    JavaMethod jm = pSource.newJavaMethod("getPreferredPrefix", String.class, JavaSource.PUBLIC);
    DirectAccessible pURI = jm.addParam(String.class, "pURI");
    jm.addIf(pURI, " == null");
    jm.addLine(pURI, " = \"\";");
    jm.addEndIf();
    boolean first = true;
    for (Iterator iter = uris.entrySet().iterator();  iter.hasNext()) {
      Map.Entry entry = (Map.Entry) iter.next();
      String uri = (String) entry.getKey();
      String prefix = (String) entry.getValue();
      jm.addIf(first, pURI, ".equals(", JavaSource.getQuoted(uri), ")");
      jm.addLine("return ", JavaSource.getQuoted(prefix), ";");     
      first = false;
    }
    jm.addEndIf();
    jm.addLine("return super.getPreferredPrefix(", pURI, ");");
    return jm;
  }
View Full Code Here

    }
  }

  private JavaMethod getXMLHandlersStartDocumentMethod(ComplexTypeSG pController, JavaSource pSource,
                                                        DirectAccessible pLevelVar) {
    JavaMethod jm = pSource.newJavaMethod("startDocument", JavaQNameImpl.VOID, JavaSource.PUBLIC);
    jm.addThrows(SAXException.class);
    jm.addLine(pLevelVar, " = 0;");
    return jm;
  }
View Full Code Here

    AttributeSG[] myAttributes = pController.getAttributes();
    if (myAttributes.length == 0) {
      return null;
    }

    JavaMethod jm = pSource.newJavaMethod("addAttribute", JavaQNameImpl.VOID, JavaSource.PUBLIC);
    DirectAccessible pURI = jm.addParam(String.class, "pURI");
    DirectAccessible pLocalName = jm.addParam(String.class, "pLocalName");
    DirectAccessible pValue = jm.addParam(String.class, "pValue");
    jm.addThrows(SAXException.class);
    jm.addIf(pURI, " == null");
    jm.addLine(pURI, " = \"\";");
    jm.addEndIf();

    JavaQName resultType = pController.getClassContext().getXMLInterfaceName();
    LocalJavaField result = jm.newJavaField(resultType);
    result.addLine("(", resultType, ") getResult()");

    Set uris = new HashSet();
    for (int i = 0;  i < myAttributes.length;  i++) {
      AttributeSG attr = myAttributes[i];
      String uri = attr.getName().getNamespaceURI();
      if (uri == null) { uri = ""; }

      // Skip, if this namespace was already processed.
      if (uris.contains(uri)) {
        continue;
      }

      jm.addIf(uris.isEmpty(), JavaSource.getQuoted(uri), ".equals(", pURI, ")");
      for (int j = i;  j < myAttributes.length;  j++) {
        attr = myAttributes[j];
        String jUri = attr.getName().getNamespaceURI();
        if (jUri == null) { jUri = ""; }
        if (!uri.equals(jUri)) {
          continue;
        }

        jm.addIf(j == i, JavaSource.getQuoted(attr.getName().getLocalName()), ".equals(", pLocalName, ")");
        Object v = myAttributes[j].getTypeSG().getSimpleTypeSG().getCastFromString(jm, pValue, "getData()");
        attr.getPropertySG().setValue(jm, result, v, null);
        jm.addLine("return;");
      }
      jm.addEndIf();
      uris.add(uri);
    }
    jm.addEndIf();
    jm.addLine("super.addAttribute(", pURI, ", ", pLocalName, ", ", pValue, ");");
    return jm;
  }
View Full Code Here

    return jm;
  }

  protected JavaMethod getXMLHandlersNewResultMethod(ComplexTypeSG pController, JavaSource pSource) {
    JavaQName elementInterfaceClass = pController.getClassContext().getXMLInterfaceName();
    JavaMethod jm = pSource.newJavaMethod("newResult", elementInterfaceClass, JavaSource.PROTECTED);
    jm.addThrows(SAXException.class);
    if (pController.getClassContext().isGlobal()) {
      jm.addTry();
      jm.addLine("return (", elementInterfaceClass, ") getData().getFactory().getElement(",
                 elementInterfaceClass, ".class);");
      DirectAccessible e = jm.addCatch(JAXBException.class);
      jm.addThrowNew(SAXException.class, e);
      jm.addEndTry();
    } else {
      JavaQName elementImplClass = pController.getClassContext().getXMLImplementationName();
      jm.addLine("return new ", elementImplClass, "();");
    }
    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();
    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

  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

    myName.setFinal(true);
    XsQName qName = pController.getName();
    myName.addLine("new ", QName.class, "(", JavaSource.getQuoted(qName.getNamespaceURI()),
                   ", ", JavaSource.getQuoted(qName.getLocalName()), ")");

    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

  }

  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

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.