activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r379507 - in /incubator/activemq/trunk/activemq-core/src/gram: java/org/apache/activemq/openwire/tool/ script/
Date Tue, 21 Feb 2006 15:58:37 GMT
Author: jstrachan
Date: Tue Feb 21 07:58:36 2006
New Revision: 379507

URL: http://svn.apache.org/viewcvs?rev=379507&view=rev
Log:
refactored the C# code generation scripts to make them a little easier to work with 

Added:
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java
  (with props)
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
  (with props)
Modified:
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java
    incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy

Added: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java?rev=379507&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java
(added)
+++ incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java
Tue Feb 21 07:58:36 2006
@@ -0,0 +1,34 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.activemq.openwire.tool;
+
+import java.io.File;
+
+/**
+ *
+ * @version $Revision$
+ */
+public abstract class OpenWireCSharpClassesScript extends OpenWireClassesScript {
+
+    public Object run() {
+        filePostFix = ".cs";
+        destDir = new File("../openwire-dotnet/src/OpenWire.Client/Commands");
+        
+        return super.run();
+    }
+
+}

Propchange: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java?rev=379507&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
(added)
+++ incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
Tue Feb 21 07:58:36 2006
@@ -0,0 +1,119 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.activemq.openwire.tool;
+
+import mx4j.tools.adaptor.http.GetAttributeCommandProcessor;
+
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JamClassIterator;
+
+import java.io.File;
+import java.io.*;
+import java.util.*;
+
+/**
+ * 
+ * @version $Revision$
+ */
+public abstract class OpenWireClassesScript extends OpenWireScript {
+    protected Set manuallyMaintainedClasses = new HashSet();
+    protected File destDir = new File("target/generated/classes");
+    protected File destFile;
+    protected String filePostFix = "";
+
+    protected JClass jclass;
+    protected JClass superclass;
+    protected String simpleName;
+    protected String className;
+    protected String baseClass;
+    protected StringBuffer buffer;
+
+    public OpenWireClassesScript() {
+        String[] names = { "ActiveMQDestination", "ActiveMQTempDestination", "ActiveMQQueue",
"ActiveMQTopic", "ActiveMQTempQueue", "ActiveMQTempTopic",
+                "BaseCommand", "ActiveMQMessage", "ActiveMQTextMessage", "ActiveMQMapMessage",
"ActiveMQBytesMessage", "ActiveMQStreamMessage",
+                "ActiveMQStreamMessage", "DataStructureSupport" };
+
+        for (int i = 0; i < names.length; i++) {
+            manuallyMaintainedClasses.add(names[i]);
+        }
+    }
+
+    public Object run() {
+        destDir.mkdirs();
+        buffer = new StringBuffer();
+
+        JamClassIterator iter = getClasses();
+        while (iter.hasNext()) {
+            jclass = iter.nextClass();
+            if (isValidClass(jclass)) {
+                processClass(jclass);
+            }
+        }
+        return null;
+    }
+
+    protected boolean isValidClass(JClass jclass) {
+        if (jclass.getAnnotation("openwire:marshaller") == null) {
+            return false;
+        }
+        return manuallyMaintainedClasses.contains(jclass.getSimpleName());
+    }
+
+    protected void processClass(JClass jclass) {
+        simpleName = jclass.getSimpleName();
+        superclass = jclass.getSuperclass();
+
+        System.out.println("Processing class: " + simpleName);
+
+        className = getClassName(jclass);
+
+        destFile = new File(destDir, className + filePostFix);
+
+        baseClass = getBaseClassName(jclass);
+
+        PrintWriter out = null;
+        try {
+            out = new PrintWriter(new FileWriter(destFile));
+        }
+        catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        finally {
+            if (out != null) {
+                out.close();
+            }
+        }
+    }
+
+    protected abstract void generateFile(PrintWriter out);
+
+    protected String getBaseClassName(JClass jclass) {
+        String answer = "AbstractCommand";
+        if (superclass != null) {
+            String name = superclass.getSimpleName();
+            if (name != null && !name.equals("Object")) {
+                answer = name;
+            }
+        }
+        return answer;
+    }
+
+    protected String getClassName(JClass jclass) {
+        return "AbstractCommand";
+    }
+
+}

Propchange: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java?rev=379507&r1=379506&r2=379507&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java
Tue Feb 21 07:58:36 2006
@@ -23,6 +23,8 @@
 import org.codehaus.jam.JField;
 import org.codehaus.jam.JMethod;
 import org.codehaus.jam.JProperty;
+import org.codehaus.jam.JamClassIterator;
+import org.codehaus.jam.JamService;
 
 /**
  * @version $Revision$
@@ -70,6 +72,14 @@
             }
         }
         return false; //j.getSuperclass()!=null && isMarshallAware(j.getSuperclass());
+    }
+    
+    public JamService getJam() {
+        return (JamService) getBinding().getVariable("jam");
+    }
+
+    public JamClassIterator getClasses() {
+        return getJam().getClasses();
     }
     
     /**

Modified: incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy?rev=379507&r1=379506&r2=379507&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy (original)
+++ incubator/activemq/trunk/activemq-core/src/gram/script/GenerateCSharpClasses.groovy Tue
Feb 21 07:58:36 2006
@@ -14,59 +14,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-import org.apache.activemq.openwire.tool.OpenWireScript
+import org.apache.activemq.openwire.tool.OpenWireCSharpClassesScript
 
 /**
  * Generates the C# marshalling code for the Open Wire Format
  *
  * @version $Revision$
  */
-class GenerateCSharpClasses extends OpenWireScript {
+class GenerateCSharpClasses extends OpenWireCSharpClassesScript {
 
-    Object run() {
-        def destDir = new File("../openwire-dotnet/src/OpenWire.Client/Commands")
-        destDir.mkdirs()
-
-        def messageClasses = classes.findAll {
-        		it.getAnnotation("openwire:marshaller")!=null
-        }
-
-			  def manuallyMaintainedClasses = ['ActiveMQDestination', 'ActiveMQTempDestination', 'ActiveMQQueue',
'ActiveMQTopic', 'ActiveMQTempQueue', 'ActiveMQTempTopic', 'BaseCommand',
-			  'ActiveMQMessage', 'ActiveMQTextMessage', 'ActiveMQMapMessage', 'ActiveMQBytesMessage',
'ActiveMQStreamMessage', 'ActiveMQStreamMessage']
-			  
-        println "Generating Java marshalling code to directory ${destDir}"
-
-        def buffer = new StringBuffer()
-
-        int counter = 0
-        Map map = [:]
-
-        for (jclass in messageClasses) {
-
-						if (manuallyMaintainedClasses.contains(jclass.simpleName)) continue
-						
-            println "Processing $jclass.simpleName"
-
-            def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
-            def file = new File(destDir, jclass.simpleName + ".cs")
-
-
-            String baseClass = jclass.superclass.simpleName
-            if (baseClass == "Object") {
-            		baseClass = "AbstractCommand"
-        		 }
-            /*
-            String baseClass = "AbstractCommand"
-            if (jclass.superclass?.simpleName == "ActiveMQMessage") {
-                baseClass = "ActiveMQMessage"
-            }
-            */
-
-            buffer << """
-${jclass.simpleName}.class
-"""
-
-            file.withWriter { out |
+	void generateFile(PrintWriter out) {
                 out << """//
 // Marshalling code for Open Wire Format for ${jclass.simpleName}
 //
@@ -133,7 +90,5 @@
     }
 }
 """
-            }
-        }
     }
 }



Mime
View raw message