Author: azeez
Date: Mon Dec 10 03:19:20 2007
New Revision: 10832

Log:

Handle any input parameter



Modified:
   trunk/commons/utils/src/main/java/org/wso2/utils/codegen/CodegenHelper.java

Modified: 
trunk/commons/utils/src/main/java/org/wso2/utils/codegen/CodegenHelper.java
==============================================================================
--- trunk/commons/utils/src/main/java/org/wso2/utils/codegen/CodegenHelper.java 
(original)
+++ trunk/commons/utils/src/main/java/org/wso2/utils/codegen/CodegenHelper.java 
Mon Dec 10 03:19:20 2007
@@ -15,39 +15,21 @@
  */
 package org.wso2.utils.codegen;
 
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axis2.wsdl.WSDL2Java;
 
 import javax.xml.namespace.QName;
-import java.io.InputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.util.Iterator;
+import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 public class CodegenHelper {
 
-    private static String WSDL_URI = "uri";
-    private static String OUTPUT_DIR = "o";
-    private static String PACKAGE = "p";
-    private static String D = "d";
-    private static String GENERATE_ALL = "g";
-    private static String SS = "ss";
-    private static String SD = "sd";
-    private static String NS2P = "ns2p";
-    private static String SET = "set";
-    private static String ASYNC = "a";
-    private static String SYNC = "s";
-    private static String UNPACK = "u";
-    private static String FLATTEN_OUTPUT = "f";
-    private static String E_MAPPER = "Emp";
-    private static String SSI = "ssi";
-    private static String UW = "uw";
-    private static String PN = "pn";
-    private static String SN ="sn";
-    private static String WV ="wv";
+    private static final String SET = "set";
 
     private OMElement loadCodegenXML(String codegenXML) throws Exception {
         InputStream inStream =
@@ -59,7 +41,7 @@
             File inFile = new File(codegenXML);
             if (!inFile.exists()) {
                 throw new Exception("Null input stream. Codegen XML " + 
codegenXML +
-                                " file not found.");
+                                    " file not found.");
 
             }
             inStream = new FileInputStream(inFile);
@@ -70,123 +52,19 @@
 
     private List parse(OMElement document) {
         List mainList = new ArrayList();
-        for (Iterator childrenWithNameSetIte =
-                document.getChildrenWithName(new QName(SET));
+        for (Iterator childrenWithNameSetIte = 
document.getChildrenWithName(new QName(SET));
              childrenWithNameSetIte.hasNext();) {
             OMElement setElement = (OMElement) childrenWithNameSetIte.next();
             ArrayList arrayList = new ArrayList();
 
-            // Text Options
-            String txtURI =
-                    setElement.getFirstChildWithName(new 
QName(WSDL_URI)).getText();
-            String txtOutputDir =
-                    setElement.getFirstChildWithName(new 
QName(OUTPUT_DIR)).getText();
-            String txtPackage =
-                    setElement.getFirstChildWithName(new 
QName(PACKAGE)).getText();
-            String txtd =
-                    setElement.getFirstChildWithName(new QName(D)).getText();
-            String txtNS2P = null;
-            String txtEmp = null;
-            String txtPN = null;
-            String txtSN = null;
-            String txtWV = null;
-            // Element Options
-            OMElement eleFlattenOutput =
-                    setElement.getFirstChildWithName(new 
QName(FLATTEN_OUTPUT));
-            OMElement eleUnpack = setElement.getFirstChildWithName(new 
QName(UNPACK));
-            OMElement eleGenerateAll = setElement.getFirstChildWithName(new 
QName(GENERATE_ALL));
-            OMElement eleSync = setElement.getFirstChildWithName(new 
QName(SYNC));
-            OMElement eleAsync = setElement.getFirstChildWithName(new 
QName(ASYNC));
-            OMElement eleSS = setElement.getFirstChildWithName(new QName(SS));
-            OMElement eleSD = setElement.getFirstChildWithName(new QName(SD));
-            OMElement eleEmp = setElement.getFirstChildWithName(new 
QName(E_MAPPER));
-            OMElement eleSSI = setElement.getFirstChildWithName(new 
QName(SSI));
-            OMElement eleUW = setElement.getFirstChildWithName(new QName(UW));
-            OMElement elePN = setElement.getFirstChildWithName(new QName(PN));
-            OMElement eleSN = setElement.getFirstChildWithName(new QName(SN));
-            OMElement eleWV = setElement.getFirstChildWithName(new QName(WV));
-
-            //Text Options need to check for null
-            OMElement eleNS2P =
-                    setElement.getFirstChildWithName(new QName(NS2P));
-            if (eleNS2P != null) {
-                txtNS2P = eleNS2P.getText();
-            }
-            if (eleEmp !=null) {
-                txtEmp = eleEmp.getText();
-            }
-            if (elePN != null) {
-                txtPN = elePN.getText();
-            }
-            if (eleSN != null)  {
-                txtSN = eleSN.getText();
-            }
-            if (eleWV != null) {
-                txtWV = eleWV.getText();
-            }
-
-            arrayList.add("-" + WSDL_URI);
-            arrayList.add(txtURI);
-
-            arrayList.add("-" + OUTPUT_DIR);
-            arrayList.add(txtOutputDir);
-
-            arrayList.add("-" + PACKAGE);
-            arrayList.add(txtPackage);
-
-            arrayList.add("-" + D);
-            arrayList.add(txtd);
-
-            if (eleGenerateAll != null) {
-                arrayList.add("-" + GENERATE_ALL);
-            }
-            if (eleSync != null) {
-                arrayList.add("-" + SYNC);
-            }
-            if (eleAsync != null) {
-                arrayList.add("-" + ASYNC);
-            }
-            if (eleUnpack != null) {
-                arrayList.add("-" + UNPACK);
-            }
-            if (eleFlattenOutput != null) {
-                arrayList.add("-" + FLATTEN_OUTPUT);
-            }
-            if (eleSS != null) {
-                arrayList.add("-" + SS);
-            }
-            if (eleSD != null) {
-                arrayList.add("-" + SD);
-            }
-            if (eleNS2P != null) {
-                arrayList.add("-" + NS2P);
-                arrayList.add(txtNS2P);
-            }
-            if (eleEmp != null) {
-                arrayList.add("-"+E_MAPPER);
-                arrayList.add(txtEmp);
-            }
-            if (eleSSI != null) {
-                arrayList.add("-"+SSI);
-            }
-            if (eleUW != null) {
-                arrayList.add("-"+UW);
-            }
-            if (elePN != null) {
-                arrayList.add("-"+PN);
-                arrayList.add(txtPN);
-            }
-            if (eleSN != null) {
-                arrayList.add("-"+SN);
-                arrayList.add(txtSN);
-            }
-            if (eleWV != null) {
-                arrayList.add("-"+WV);
-                if (txtWV != null) {
-                    arrayList.add(txtWV);
+            for (Iterator iter = setElement.getChildElements(); 
iter.hasNext();) {
+                OMElement ele = (OMElement) iter.next();
+                arrayList.add("-" + ele.getLocalName());
+                String value = ele.getText().trim();
+                if (value.length() != 0) {
+                    arrayList.add(value);
                 }
             }
-
             mainList.add(arrayList);
         }
         return mainList;
@@ -203,20 +81,15 @@
             String[] wsdl2JavaArgs =
                     (String[]) setList.toArray(new String[setList.size()]);
 
-//            System.out.println(setArrayList.get(i) + " processing...");
-//            
System.out.println("------------------------------------------------");
-//            for (int j = 0; j < wsdl2JavaArgs.length; j++) {
-//                String wsdl2JavaArg = wsdl2JavaArgs[j];
-//                System.out.println("ARG" + j + "=" + wsdl2JavaArg);
-//            }
             generateCode(wsdl2JavaArgs);
             System.out.println(setArrayList.get(i) + " processed 
successfully.");
         }
     }
 
-    private static synchronized void generateCode(String[] wsdl2JavaArgs) 
throws Exception{
+    private static synchronized void generateCode(String[] wsdl2JavaArgs) 
throws Exception {
         WSDL2Java.main(wsdl2JavaArgs);
     }
+
     public static void main(String[] args) {
         System.out.println("Starting Codegen ...");
         if (args.length < 1) {

_______________________________________________
Commons-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/commons-dev

Reply via email to