incubator-yoko-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r526131 - in /incubator/yoko/trunk/tools/src: main/java/org/apache/yoko/tools/processors/idl/ test/java/org/apache/yoko/tools/processors/ test/resources/idl/
Date Fri, 06 Apr 2007 12:09:11 GMT
Author: bravi
Date: Fri Apr  6 05:09:10 2007
New Revision: 526131

URL: http://svn.apache.org/viewvc?view=rev&rev=526131
Log:
[YOKO-320] - A initial version of the IDL Preprocessor.

Added:
    incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/IDLPreProcessor.java
  (with props)
    incubator/yoko/trunk/tools/src/test/resources/idl/expected_Included.wsdl   (with props)
    incubator/yoko/trunk/tools/src/test/resources/idl/include.idl
    incubator/yoko/trunk/tools/src/test/resources/idl/included.idl
Modified:
    incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/IDLToWSDLProcessor.java
    incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/IDLToWSDLGenerationTest.java

Added: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/IDLPreProcessor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/IDLPreProcessor.java?view=auto&rev=526131
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/IDLPreProcessor.java
(added)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/IDLPreProcessor.java
Fri Apr  6 05:09:10 2007
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.yoko.tools.processors.idl;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class IDLPreProcessor {
+
+    private static final String IFNDEF = "#ifndef";
+    private static final String DEFINE = "#define";
+    private static final String ENDIF = "#endif";
+    private static final String INCLUDE = "#include";
+
+    private List<String> defines;
+    private ByteArrayOutputStream os;
+    private PrintWriter writer;
+
+    public IDLPreProcessor() {
+        this(null);
+    }
+
+    public IDLPreProcessor(List<String> definesList) {
+        if (definesList == null) {
+            defines = new ArrayList<String>();
+        } else {
+            defines = definesList;
+        }
+        os = new ByteArrayOutputStream();
+        writer = new PrintWriter(os);   
+    }
+
+    public byte[] process(File file) throws Exception {
+        FileInputStream stream = new FileInputStream(file);
+        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
+        String line = reader.readLine();
+        while (line != null) {
+            line = processLine(file, line);
+            if (line == null) {
+                break;
+            } else {
+                writer.println(line);
+                writer.flush();
+            }
+            line = reader.readLine();
+        }
+        stream.close();
+        return os.toByteArray();
+    }
+
+    private String processLine(File file, String line) throws Exception {
+        String result = null;
+        if (line.toLowerCase().startsWith(IFNDEF)) {
+            String define = line.substring(IFNDEF.length()).trim();
+            if (!defines.contains(define)) {
+                result = "";
+            }
+        } else if (line.toLowerCase().startsWith(DEFINE)) {
+            String define = line.substring(DEFINE.length()).trim();
+            defines.add(define);
+            result = "";
+        } else if (line.toLowerCase().startsWith(INCLUDE)) {
+            String fileName = line.substring(INCLUDE.length()).trim();
+            fileName = fileName.substring(1, fileName.length() - 1);        
+            File includeFile = new File(file.getParent(), fileName);
+            if (!includeFile.exists()) {
+                throw new RuntimeException("Couldn't find included file " + fileName);
+            }
+            IDLPreProcessor preprocessor = new IDLPreProcessor(defines);
+            byte[] bytes = preprocessor.process(includeFile);
+            result = new String(bytes);
+        } else if (line.toLowerCase().startsWith(ENDIF)) {
+            result = "";
+        } else {
+            result = line;
+        }
+        return result;
+    }
+
+    public static void main(String[] args) throws Exception {
+        if (args.length != 1) {
+            System.err.println("Error: Specify a file name to pre-process");
+            return;
+        }
+        IDLPreProcessor processor = new IDLPreProcessor();
+        File file = new File(args[0]);
+        if (file.exists()) {
+            System.out.println(new String(processor.process(file)));
+        } else {
+            System.err.println("File doesn't exist " + args[0]);
+        }
+    }
+
+}

Propchange: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/IDLPreProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/IDLPreProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/IDLToWSDLProcessor.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/IDLToWSDLProcessor.java?view=diff&rev=526131&r1=526130&r2=526131
==============================================================================
--- incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/IDLToWSDLProcessor.java
(original)
+++ incubator/yoko/trunk/tools/src/main/java/org/apache/yoko/tools/processors/idl/IDLToWSDLProcessor.java
Fri Apr  6 05:09:10 2007
@@ -20,8 +20,9 @@
 package org.apache.yoko.tools.processors.idl;
 
 import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
 import java.io.File;
-import java.io.FileInputStream;
+//import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.InputStream;
 import java.io.Writer;
@@ -72,7 +73,13 @@
     }
 
     public void parseIDL() throws Exception {
-        InputStream stream = new FileInputStream(env.get(ToolCorbaConstants.CFG_IDLFILE).toString());
+        IDLPreProcessor preProcessor = new IDLPreProcessor();
+        File file = new File(env.get(ToolCorbaConstants.CFG_IDLFILE).toString());
+        if (!file.exists()) {
+            throw new Exception("IDL file " + file.getName() + " doesn't exist");
+        }
+        byte[] bytes = preProcessor.process(file);
+        InputStream stream = new ByteArrayInputStream(bytes);
         IDLParser parser = new IDLParser(new IDLLexer(stream));
         parser.specification();
         AST idlTree = parser.getAST();

Modified: incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/IDLToWSDLGenerationTest.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/IDLToWSDLGenerationTest.java?view=diff&rev=526131&r1=526130&r2=526131
==============================================================================
--- incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/IDLToWSDLGenerationTest.java
(original)
+++ incubator/yoko/trunk/tools/src/test/java/org/apache/yoko/tools/processors/IDLToWSDLGenerationTest.java
Fri Apr  6 05:09:10 2007
@@ -160,4 +160,8 @@
         testWSDLGeneration("/idl/ObjectRef.idl", "/idl/expected_ObjectRef.wsdl");
     }
 
+    public void testIncludeGeneration() throws Exception {
+        testWSDLGeneration("/idl/included.idl", "/idl/expected_Included.wsdl");
+    }
+
 }

Added: incubator/yoko/trunk/tools/src/test/resources/idl/expected_Included.wsdl
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/test/resources/idl/expected_Included.wsdl?view=auto&rev=526131
==============================================================================
--- incubator/yoko/trunk/tools/src/test/resources/idl/expected_Included.wsdl (added)
+++ incubator/yoko/trunk/tools/src/test/resources/idl/expected_Included.wsdl Fri Apr  6 05:09:10
2007
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<wsdl:definitions targetNamespace="http://schemas.apache.org/yoko/idl/included" xmlns:tns="http://schemas.apache.org/yoko/idl/included"
xmlns:corba="http://schemas.apache.org/yoko/bindings/corba" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+  <corba:typeMapping targetNamespace="http://schemas.apache.org/yoko/idl/included/typemap">
+    <corba:struct xmlns:ns4="http://schemas.apache.org/yoko/idl/included" xmlns="http://schemas.apache.org/yoko/idl/included/typemap"
repositoryID="IDL:yoko/Employee:1.0" name="yoko.Employee" type="ns4:yoko.Employee">
+      <corba:member name="name" idltype="corba:string" />
+      <corba:member name="dept" idltype="corba:string" />
+    </corba:struct>
+  </corba:typeMapping>
+  <wsdl:types>
+    <xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://schemas.apache.org/yoko/idl/included"
xmlns="http://schemas.apache.org/yoko/idl/included" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+      <xs:complexType name="yoko.Employee">
+        <xs:sequence>
+          <xs:element name="name" type="xs:string">
+          </xs:element>
+          <xs:element name="dept" type="xs:string">
+          </xs:element>
+        </xs:sequence>
+      </xs:complexType>
+      <xs:element name="add">
+        <xs:complexType>
+          <xs:sequence>
+            <xs:element name="emp" type="yoko.Employee">
+            </xs:element>
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+      <xs:element name="addResponse">
+        <xs:complexType>
+          <xs:sequence>
+            <xs:element name="return" type="xs:boolean">
+            </xs:element>
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+    </xs:schema>
+  </wsdl:types>
+  <wsdl:message name="addResponse">
+    <wsdl:part name="outparameter" element="tns:addResponse">
+    </wsdl:part>
+  </wsdl:message>
+  <wsdl:message name="add">
+    <wsdl:part name="inparameter" element="tns:add">
+    </wsdl:part>
+  </wsdl:message>
+  <wsdl:portType name="yoko.org.EmployeeTest">
+    <wsdl:operation name="add">
+      <wsdl:input name="addRequest" message="tns:add">
+    </wsdl:input>
+      <wsdl:output name="addResponse" message="tns:addResponse">
+    </wsdl:output>
+    </wsdl:operation>
+  </wsdl:portType>
+  <wsdl:binding name="yoko.org.EmployeeTestCORBABinding" type="tns:yoko.org.EmployeeTest">
+    <corba:binding repositoryID="IDL:yoko/org/EmployeeTest:1.0" />
+    <wsdl:operation name="add">
+      <corba:operation name="add">
+        <corba:param xmlns="http://schemas.apache.org/yoko/idl/included/typemap" mode="in"
name="emp" idltype="yoko.Employee" />
+        <corba:return name="return" idltype="corba:boolean" />
+      </corba:operation>
+      <wsdl:input name="addRequest">
+      </wsdl:input>
+      <wsdl:output name="addResponse">
+      </wsdl:output>
+    </wsdl:operation>
+  </wsdl:binding>
+  <wsdl:service name="yoko.org.EmployeeTestCORBAService">
+    <wsdl:port name="yoko.org.EmployeeTestCORBAPort" binding="tns:yoko.org.EmployeeTestCORBABinding">
+      <corba:address location="IOR:" />
+    </wsdl:port>
+  </wsdl:service>
+</wsdl:definitions>

Propchange: incubator/yoko/trunk/tools/src/test/resources/idl/expected_Included.wsdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/yoko/trunk/tools/src/test/resources/idl/expected_Included.wsdl
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/yoko/trunk/tools/src/test/resources/idl/expected_Included.wsdl
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/yoko/trunk/tools/src/test/resources/idl/include.idl
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/test/resources/idl/include.idl?view=auto&rev=526131
==============================================================================
--- incubator/yoko/trunk/tools/src/test/resources/idl/include.idl (added)
+++ incubator/yoko/trunk/tools/src/test/resources/idl/include.idl Fri Apr  6 05:09:10 2007
@@ -0,0 +1,25 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/ 
+
+module yoko {
+     struct Employee {
+         string name;
+         string dept;
+     };
+};

Added: incubator/yoko/trunk/tools/src/test/resources/idl/included.idl
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/tools/src/test/resources/idl/included.idl?view=auto&rev=526131
==============================================================================
--- incubator/yoko/trunk/tools/src/test/resources/idl/included.idl (added)
+++ incubator/yoko/trunk/tools/src/test/resources/idl/included.idl Fri Apr  6 05:09:10 2007
@@ -0,0 +1,30 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/ 
+
+#include "include.idl"
+
+module yoko {
+
+    module org {
+
+       interface EmployeeTest {
+          boolean add(in Employee emp);
+       };
+	};
+};
\ No newline at end of file



Mime
View raw message