Package org.apache.ws.jaxme.js

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


    }
   
    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


    jm.addLine("return super.getPreferredPrefix(", pURI, ");");
    return jm;
  }

  protected JavaMethod getXMLSerializersMarshalChildsMethod(ComplexTypeSG pController, JavaSource pSource) throws SAXException {
      JavaMethod jm = pSource.newJavaMethod("marshalChilds", void.class, JavaSource.PUBLIC);
      jm.addThrows(SAXException.class);
      Parameter pData = jm.addParam(JMXmlSerializer.Data.class, "pData");
      Parameter pElement = jm.addParam(Object.class, "pElement");
      JavaQName elementInterface = pController.getClassContext().getXMLInterfaceName();
      LocalJavaField element = jm.newJavaField(elementInterface);
      element.addLine("(", elementInterface, ") ", pElement);
      LocalJavaField chars = jm.newJavaField(String.class);
      SimpleContentSG simpleContent = pController.getSimpleContentSG();
      Object value = simpleContent.getPropertySG().getValue(element);
      chars.addLine(simpleContent.getContentTypeSG().getSimpleTypeSG().getCastToString(jm, value, pData));
        jm.addIf(chars, ".length() > 0");
      LocalJavaField charArray = jm.newJavaField(char[].class);
      charArray.addLine(chars, ".toCharArray()");
      jm.addLine(pData, ".getContentHandler().characters(", charArray, ", 0, ", charArray, ".length);");
        jm.addEndIf();
      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 = createSetOfExplicitURIs(myAttributes);
    boolean first = true;
    for (Iterator iter = uris.iterator();  iter.hasNext()) {
      String uri = (String) iter.next();
      jm.addIf(first, JavaSource.getQuoted(uri), ".equals(", pURI, ")");
      first = false;
        boolean firstInNamespace = true;
      for (int i = 0;  i < myAttributes.length;  i++) {
        AttributeSG attr = myAttributes[i];
        if (attr.isWildcard()) {
          continue;
        }
        String jUri = attr.getName().getNamespaceURI();
        if (jUri == null) { jUri = ""; }
        if (!uri.equals(jUri)) {
          continue;
        }
       
        jm.addIf(firstInNamespace, JavaSource.getQuoted(attr.getName().getLocalName()), ".equals(", pLocalName, ")");
        firstInNamespace = false;
        Object v = myAttributes[i].getTypeSG().getSimpleTypeSG().getCastFromString(jm, pValue, "getData()");
        attr.getPropertySG().setValue(jm, result, v, null);
        jm.addLine("return;");
      }
      if (!firstInNamespace) {
          jm.addEndIf();
      }
    }
    if (!first) {
      jm.addEndIf();
    }

    AttributeSG wildcard = null;
    for (int i = 0;  i < myAttributes.length;  i++) {
        if (myAttributes[i].isWildcard()) {
            wildcard = myAttributes[i];
            break;
        }
    }
    if (wildcard == null) {
        jm.addLine("super.addAttribute(", pURI, ", ", pLocalName, ", ", pValue, ");");
    } else {
        jm.addTry();
        jm.addLine(result, ".", wildcard.getPropertySG().getXMLSetMethodName(), "(new ",
                QName.class, "(", pURI, ", ", pLocalName, "), ", pValue, ");");
        jm.addCatch(IllegalArgumentException.class);
        jm.addLine("validationEvent(", ValidationEvent.class, ".ERROR, ",
                JavaSource.getQuoted("Invalid namespace for anyAttribute: '"),
                " + ", pURI, " + ", JavaSource.getQuoted("', attribute name is '"),
          " + ", pLocalName, " + ", JavaSource.getQuoted("'"),
          ", ", ValidationEvents.class, ".EVENT_UNKNOWN_ANY_ATTRIBUTE);");
        jm.addEndTry();
    }
    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 getInterfaceMethod(JavaSource pSource,
                     ProxyGenerator.InterfaceDescription pDescription,
                     java.lang.reflect.Method pMethod) {
       JavaMethod jm = pSource.newJavaMethod(pMethod);
       Parameter[] parameters = jm.getParams();
       JavaQName controllerInterfaceQName = JavaQNameImpl.getInstance(getControllerInterface());
       jm.clearParams();
       jm.addParam(controllerInterfaceQName, "pController");
       for (int i = 0;  i < parameters.length;  i++) {
         jm.addParam(parameters[i]);
       }
       List callParameters = new ArrayList();
       callParameters.add("pController");
       for (int i = 0;  i < parameters.length;  i++) {
         Parameter parameter = parameters[i];
         callParameters.add(", ");
         callParameters.add(parameter.getName());
       }
       jm.addLine((Void.TYPE.equals(pMethod.getReturnType()) ? "" : " return "),
           "backingObject.",
           pMethod.getName(), "(", callParameters, ");");
       return jm;
     }
View Full Code Here

       return jcon;
     }
     public JavaMethod getInterfaceMethod(JavaSource pSource,
                     ProxyGenerator.InterfaceDescription pDescription,
                     java.lang.reflect.Method pMethod) {
       JavaMethod jm = pSource.newJavaMethod(pMethod);
       Parameter[] parameters = jm.getParams();
       List callParameters = new ArrayList();
       callParameters.add("this");
       for (int i = 0;  i < parameters.length;  i++) {
         Parameter parameter = parameters[i];
         callParameters.add(", ");
         callParameters.add(parameter.getName());
       }
       jm.addLine((Void.TYPE.equals(pMethod.getReturnType()) ? "" : " return "),
           "backingObject.",
           pMethod.getName(), "(", callParameters, ");");
       return jm;
     }
View Full Code Here

           "backingObject.",
           pMethod.getName(), "(", callParameters, ");");
       return jm;
     }
     protected JavaMethod getGetHeadOfChainMethod(JavaSource pSource) {
       JavaMethod jm = pSource.newJavaMethod("getHeadOfChain",
           getChainInterface(),
           JavaSource.PUBLIC);
       jm.addLine("return backingObject;");
       return jm;
     }
View Full Code Here

   * {@link Method}.</p>
   */
  protected JavaMethod getInterfaceMethod(JavaSource pJs,
                                            InterfaceDescription pInterfaceDescription,
                                            Method pMethod) {
     JavaMethod jm = pJs.newJavaMethod(pMethod);
      Parameter[] parameters = jm.getParams();
    List callParameters = new ArrayList();
      for (int i = 0;  i < parameters.length;  i++) {
      Parameter parameter = parameters[i];
        if (callParameters.size() > 0) {
          callParameters.add(", ");
        }
        callParameters.add(parameter.getName());
      }
    jm.addLine((Void.TYPE.equals(pMethod.getReturnType()) ? "" : " return "),
            "((", pInterfaceDescription.getInterface(), ") backingObject).",
            pMethod.getName(), "(", callParameters, ");");
    return jm;
  }
View Full Code Here

                                                  JavaSource.PRIVATE);
   allInstances.setStatic(true);
   allInstances.setFinal(true);
   allInstances.addLine("new ", arrayType, "{", instanceList, "}");

   JavaMethod getName = pSource.newJavaMethod("getName", String.class,
                                               JavaSource.PUBLIC);
   getName.newComment().addLine("The enumeration items name.");
   getName.addLine("return ", name, ";");

   JavaMethod getValue = pSource.newJavaMethod("getValue", String.class,
                                              JavaSource.PUBLIC);
   getValue.newComment().addLine("The enumeration items value.");
   getValue.addLine("return ", value, ";");

   JavaMethod getInstances = pSource.newJavaMethod("getInstances", arrayType,
                                                  JavaSource.PUBLIC);
   getInstances.setStatic(true);
   getInstances.addLine("return ", allInstances, ";");

   JavaMethod getInstanceByName = pSource.newJavaMethod("getInstanceByName",
                                                       pSource.getQName(),
                                                       JavaSource.PUBLIC);
    getInstanceByName.setStatic(true);
   getInstanceByName.addParam(String.class, "pName");
   JavaComment jc = getInstanceByName.newComment();
   jc.addLine("Returns the item with the given name.</p>");
   jc.addThrows(IllegalArgumentException.class.getName() +
               " The name <code>pName</code> is invalid and no such item exists.");
   getInstanceByName.addLine(String.class, " s = pName.intern();");
   boolean first = true;
   for (int i = 0;  i < pItems.length;  i++) {
    Item item = pItems[i];
    Object[] args = new Object[]{JavaSource.getQuoted(item.getName()), " == s"};
     getInstanceByName.addIf(first, args);
     getInstanceByName.addLine("return ", item.getName(), ";");
     first = false;
   }
   getInstanceByName.addElse();
   getInstanceByName.addLine("throw new ", IllegalArgumentException.class, "(",
                             JavaSource.getQuoted("Invalid name: "),
                              " + pName);");
   getInstanceByName.addEndIf();

   JavaMethod getInstanceByValue = pSource.newJavaMethod("getInstanceByValue",
                                       pSource.getQName(),
                                       JavaSource.PUBLIC);
   getInstanceByValue.setStatic(true);
   getInstanceByValue.addParam(String.class, "pValue");
   jc = getInstanceByValue.newComment();
   jc.addLine("Returns the item with the given value.</p>");
   jc.addThrows(IllegalArgumentException.class.getName() +
            " The name <code>pValue</code> is invalid and no such item exists.");
   getInstanceByValue.addLine(String.class, " s = pValue.intern();");
   first = true;
   for (int i = 0;  i < pItems.length;  i++) {
    Item item = pItems[i];
    Object[] args = new Object[]{JavaSource.getQuoted(item.getValue()), " == s"};
    getInstanceByValue.addIf(first, args);
    getInstanceByValue.addLine("return ", item.getName(), ";");
    first = false;
   }
   getInstanceByValue.addElse();
   getInstanceByValue.addLine("throw new ", IllegalArgumentException.class, "(",
                      JavaSource.getQuoted("Invalid name: "),
                      " + pValue);");
   getInstanceByValue.addEndIf();

   if (isAddingEquals()) {
     JavaMethod equals = pSource.newJavaMethod("equals", JavaQNameImpl.BOOLEAN,
                                               JavaSource.PUBLIC);
     equals.addParam(Object.class, "o");
     equals.addIf("o == null  ||  !(o instanceof ", pSource.getQName(), ")");
     equals.addLine("return false;");
     equals.addEndIf();
     equals.addLine("return name.equals(((", pSource.getQName(), ") o).name);");

      JavaMethod hashCode = pSource.newJavaMethod("hashCode", JavaQNameImpl.INT,
                                                  JavaSource.PUBLIC);
      hashCode.addLine("return name.hashCode();");
   }
  }
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.