activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r690550 - in /activemq/sandbox/activemq-protobuf: activemq-protobuf-test/src/main/proto/ activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ activemq-protobuf/src/main/javacc/
Date Sat, 30 Aug 2008 18:54:28 GMT
Author: chirino
Date: Sat Aug 30 11:54:28 2008
New Revision: 690550

URL: http://svn.apache.org/viewvc?rev=690550&view=rev
Log:
- We are now fully parsing the proto examples in the test module including imports
- Type resolution is in place, works even across imports.
- Generating all the mesage, enum, and group classes, and references between them are properly qualifed.

Still need to work on repeatable fields/groups and generate proper marshalling for all the types.


Added:
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/CommandLineSupport.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/IntrospectionSupport.java   (with props)
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/TypeDescriptor.java
Removed:
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtendDescriptor.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/GroupDescriptor.java
Modified:
    activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest.proto
    activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest_embed_optimize_for.proto
    activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest_optimize_for.proto
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumDescriptor.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumFieldDescriptor.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtensionsDescriptor.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/FieldDescriptor.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/OptionDescriptor.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoDescriptor.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ServiceDescriptor.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/javacc/proto-parser.jj

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest.proto
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest.proto?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest.proto (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest.proto Sat Aug 30 11:54:28 2008
@@ -21,7 +21,7 @@
 // A proto file we will use for unit testing.
 
 
-import "google/protobuf/unittest_import.proto";
+import "unittest_import.proto";
 
 // We don't put this in a package within proto2 because we need to make sure
 // that the generated code doesn't depend on being in the proto2 namespace.

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest_embed_optimize_for.proto
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest_embed_optimize_for.proto?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest_embed_optimize_for.proto (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest_embed_optimize_for.proto Sat Aug 30 11:54:28 2008
@@ -20,7 +20,7 @@
 //
 // A proto file which imports a proto file that uses optimize_for = CODE_SIZE.
 
-import "google/protobuf/unittest_optimize_for.proto";
+import "unittest_optimize_for.proto";
 
 package protobuf_unittest;
 

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest_optimize_for.proto
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest_optimize_for.proto?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest_optimize_for.proto (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/main/proto/unittest_optimize_for.proto Sat Aug 30 11:54:28 2008
@@ -20,7 +20,7 @@
 //
 // A proto file which uses optimize_for = CODE_SIZE.
 
-import "google/protobuf/unittest.proto";
+import "unittest.proto";
 
 package protobuf_unittest;
 

Added: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/CommandLineSupport.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/CommandLineSupport.java?rev=690550&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/CommandLineSupport.java (added)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/CommandLineSupport.java Sat Aug 30 11:54:28 2008
@@ -0,0 +1,115 @@
+/**
+ *
+ * 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.activemq.protobuf.compiler;
+
+import java.util.ArrayList;
+
+/**
+ * Support utility that can be used to set the properties on any object
+ * using command line arguments.
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public class CommandLineSupport {
+	
+	/**
+	 * Sets the properties of an object given the command line args.
+	 * 
+	 * if args contains: --ack-mode=AUTO --url=tcp://localhost:61616 --persistent 
+	 * 
+	 * then it will try to call the following setters on the target object.
+	 * 
+	 * target.setAckMode("AUTO");
+	 * target.setURL(new URI("tcp://localhost:61616") );
+	 * target.setPersistent(true);
+	 * 
+	 * Notice the the proper conversion for the argument is determined by examining the 
+	 * setter argument type.  
+	 * 
+	 * @param target the object that will have it's properties set
+	 * @param args the command line options
+	 * @return any arguments that are not valid options for the target
+	 */
+	static public String[] setOptions(Object target, String []args) {
+		ArrayList rc = new ArrayList();
+		
+		for (int i = 0; i < args.length; i++) {
+			if( args[i] == null )
+				continue;
+			
+			if( args[i].startsWith("--") ) {
+				
+				// --options without a specified value are considered boolean flags that are enabled.
+				String value="true";
+				String name = args[i].substring(2);
+				
+				// if --option=value case
+				int p = name.indexOf("=");
+				if( p > 0 ) {
+					value = name.substring(p+1);
+					name = name.substring(0,p);
+				}
+				
+				// name not set, then it's an unrecognized option
+				if( name.length()==0 ) {
+					rc.add(args[i]);
+					continue;
+				}
+				
+				String propName = convertOptionToPropertyName(name);
+				if( !IntrospectionSupport.setProperty(target, propName, value) ) {					
+					rc.add(args[i]);
+					continue;
+				}
+			} else {
+                            rc.add(args[i]);
+			}
+			
+		}
+		
+		String r[] = new String[rc.size()];
+		rc.toArray(r);
+		return r;
+	}
+
+	/**
+	 * converts strings like: test-enabled to testEnabled
+	 * @param name
+	 * @return
+	 */
+	private static String convertOptionToPropertyName(String name) {
+		String rc="";
+		
+		// Look for '-' and strip and then convert the subsequent char to uppercase
+		int p = name.indexOf("-");
+		while( p > 0 ) {
+			// strip
+			rc += name.substring(0, p);
+			name = name.substring(p+1);
+			
+			// can I convert the next char to upper?
+			if( name.length() >0 ) {
+				rc += name.substring(0,1).toUpperCase();
+				name = name.substring(1);
+			}
+			
+			p = name.indexOf("-");
+		}
+		return rc+name;
+	}
+}

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumDescriptor.java?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumDescriptor.java (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumDescriptor.java Sat Aug 30 11:54:28 2008
@@ -16,17 +16,20 @@
  */
 package org.apache.activemq.protobuf.compiler;
 
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
-public class EnumDescriptor {
+public class EnumDescriptor implements TypeDescriptor {
 
     private String name;
-    private Map<String,EnumFieldDescriptor> fields;
+    private Map<String,EnumFieldDescriptor> fields= new LinkedHashMap<String, EnumFieldDescriptor>();
     private final ProtoDescriptor protoDescriptor;
+    private final MessageDescriptor parent;
 
-    public EnumDescriptor(ProtoDescriptor protoDescriptor) {
+    public EnumDescriptor(ProtoDescriptor protoDescriptor, MessageDescriptor parent) {
         this.protoDescriptor = protoDescriptor;
+        this.parent = parent;
     }
 
     public String getName() {
@@ -53,5 +56,17 @@
         
     }
 
+    public MessageDescriptor getParent() {
+        return parent;
+    }
+
+    public String getQName() {
+        if( parent==null ) {
+            return name;
+        } else {
+            return parent.getQName()+"."+name;
+        }
+    }
+
 
 }

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumFieldDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumFieldDescriptor.java?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumFieldDescriptor.java (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumFieldDescriptor.java Sat Aug 30 11:54:28 2008
@@ -20,10 +20,10 @@
 
     private String name;
     private int value;
-    private final ProtoDescriptor protoDescriptor;
+    private final EnumDescriptor parent;
 
-    public EnumFieldDescriptor(ProtoDescriptor protoDescriptor) {
-        this.protoDescriptor = protoDescriptor;
+    public EnumFieldDescriptor(EnumDescriptor parent) {
+        this.parent = parent;
     }
 
     public void setName(String name) {
@@ -42,13 +42,8 @@
         return value;
     }
 
-    public ProtoDescriptor getProtoDescriptor() {
-        return protoDescriptor;
-    }
-
-    public String geName() {
-        // TODO Auto-generated method stub
-        return null;
+    public EnumDescriptor getParent() {
+        return parent;
     }
 
 }

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtensionsDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtensionsDescriptor.java?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtensionsDescriptor.java (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtensionsDescriptor.java Sat Aug 30 11:54:28 2008
@@ -20,10 +20,10 @@
 
     private int first;
     private int last;
-    private final ProtoDescriptor protoDescriptor;
+    private final MessageDescriptor parent;
 
-    public ExtensionsDescriptor(ProtoDescriptor protoDescriptor) {
-        this.protoDescriptor = protoDescriptor;
+    public ExtensionsDescriptor(MessageDescriptor parent) {
+        this.parent = parent;
     }
 
     public void setFirst(int first) {
@@ -42,8 +42,9 @@
         return last;
     }
 
-    public ProtoDescriptor getProtoDescriptor() {
-        return protoDescriptor;
+    public MessageDescriptor getParent() {
+        return parent;
     }
 
+
 }

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/FieldDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/FieldDescriptor.java?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/FieldDescriptor.java (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/FieldDescriptor.java Sat Aug 30 11:54:28 2008
@@ -83,16 +83,36 @@
     private String rule;
     private int tag;
     private Map<String,OptionDescriptor> options;
-    private final ProtoDescriptor protoDescriptor;
+    private TypeDescriptor typeDescriptor;
+    private final MessageDescriptor parent;
+    private MessageDescriptor group;
 
-    public FieldDescriptor(ProtoDescriptor protoDescriptor) {
-        this.protoDescriptor = protoDescriptor;
+    public FieldDescriptor(MessageDescriptor parent) {
+        this.parent = parent;
     }
     
-    public ProtoDescriptor getProtoDescriptor() {
-        return protoDescriptor;
+    public void validate(List<String> errors) {
+        if( group!=null ) {
+            typeDescriptor=group;
+        }
+        if( !SCALAR_TYPES.contains(type) ) {
+            // Find the type def for that guy..
+            if( typeDescriptor==null ) {
+                typeDescriptor = parent.getType(type);
+            }
+            if( typeDescriptor == null ) {
+                typeDescriptor = parent.getProtoDescriptor().getType(type);
+            }
+            if( typeDescriptor == null ) {
+                typeDescriptor = parent.getProtoDescriptor().getType(type);
+                errors.add("Field type not found: "+type);
+            }
+        }
     }
 
+    public boolean isGroup() {
+        return group!=null;
+    }
 
     public String getName() {
         return name;
@@ -167,4 +187,19 @@
         return type==STRING_TYPE;
     }
 
+    public TypeDescriptor getTypeDescriptor() {
+        return typeDescriptor;
+    }
+
+    public void setTypeDescriptor(TypeDescriptor typeDescriptor) {
+        this.typeDescriptor = typeDescriptor;
+    }
+
+    public MessageDescriptor getGroup() {
+        return group;
+    }
+    public void setGroup(MessageDescriptor group) {
+        this.group = group;        
+    }
+
 }

Added: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/IntrospectionSupport.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/IntrospectionSupport.java?rev=690550&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/IntrospectionSupport.java (added)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/IntrospectionSupport.java Sat Aug 30 11:54:28 2008
@@ -0,0 +1,324 @@
+/**
+ * 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.activemq.protobuf.compiler;
+
+import java.beans.PropertyEditor;
+import java.beans.PropertyEditorManager;
+import java.io.File;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.Map.Entry;
+
+/**
+ * Support class used to do introspection/reflection based setting and getting of properties on a Java Bean.
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public final class IntrospectionSupport {
+    
+    private IntrospectionSupport() {
+    }
+
+    public static boolean getProperties(Object target, Map props, String optionPrefix) {
+
+        boolean rc = false;
+        if (target == null) {
+            throw new IllegalArgumentException("target was null.");
+        }
+        if (props == null) {
+            throw new IllegalArgumentException("props was null.");
+        }
+
+        if (optionPrefix == null) {
+            optionPrefix = "";
+        }
+
+        Class clazz = target.getClass();
+        Method[] methods = clazz.getMethods();
+        for (int i = 0; i < methods.length; i++) {
+            Method method = methods[i];
+            String name = method.getName();
+            Class type = method.getReturnType();
+            Class params[] = method.getParameterTypes();
+            if (name.startsWith("get") && params.length == 0 && type != null && isSettableType(type)) {
+
+                try {
+
+                    Object value = method.invoke(target, new Object[] {});
+                    if (value == null) {
+                        continue;
+                    }
+
+                    String strValue = convertToString(value, type);
+                    if (strValue == null) {
+                        continue;
+                    }
+
+                    name = name.substring(3, 4).toLowerCase() + name.substring(4);
+                    props.put(optionPrefix + name, strValue);
+                    rc = true;
+
+                } catch (Throwable ignore) {
+                }
+
+            }
+        }
+
+        return rc;
+    }
+
+    public static boolean setProperties(Object target, Map<String, ?> props, String optionPrefix) {
+        boolean rc = false;
+        if (target == null) {
+            throw new IllegalArgumentException("target was null.");
+        }
+        if (props == null) {
+            throw new IllegalArgumentException("props was null.");
+        }
+
+        for (Iterator<String> iter = props.keySet().iterator(); iter.hasNext();) {
+            String name = iter.next();
+            if (name.startsWith(optionPrefix)) {
+                Object value = props.get(name);
+                name = name.substring(optionPrefix.length());
+                if (setProperty(target, name, value)) {
+                    iter.remove();
+                    rc = true;
+                }
+            }
+        }
+        return rc;
+    }
+
+    public static Map<String, Object> extractProperties(Map props, String optionPrefix) {
+        if (props == null) {
+            throw new IllegalArgumentException("props was null.");
+        }
+
+        HashMap<String, Object> rc = new HashMap<String, Object>(props.size());
+
+        for (Iterator iter = props.keySet().iterator(); iter.hasNext();) {
+            String name = (String)iter.next();
+            if (name.startsWith(optionPrefix)) {
+                Object value = props.get(name);
+                name = name.substring(optionPrefix.length());
+                rc.put(name, value);
+                iter.remove();
+            }
+        }
+
+        return rc;
+    }
+
+    public static boolean setProperties(Object target, Map props) {
+        boolean rc = false;
+
+        if (target == null) {
+            throw new IllegalArgumentException("target was null.");
+        }
+        if (props == null) {
+            throw new IllegalArgumentException("props was null.");
+        }
+
+        for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) {
+            Map.Entry entry = (Entry)iter.next();
+            if (setProperty(target, (String)entry.getKey(), entry.getValue())) {
+                iter.remove();
+                rc = true;
+            }
+        }
+
+        return rc;
+    }
+
+    public static boolean setProperty(Object target, String name, Object value) {
+        try {
+            Class clazz = target.getClass();
+            Method setter = findSetterMethod(clazz, name);
+            if (setter == null) {
+                return false;
+            }
+
+            // If the type is null or it matches the needed type, just use the
+            // value directly
+            if (value == null || value.getClass() == setter.getParameterTypes()[0]) {
+                setter.invoke(target, new Object[] {value});
+            } else {
+                // We need to convert it
+                setter.invoke(target, new Object[] {convert(value, setter.getParameterTypes()[0])});
+            }
+            return true;
+        } catch (Throwable ignore) {
+            return false;
+        }
+    }
+
+    private static Object convert(Object value, Class type) throws URISyntaxException {
+        PropertyEditor editor = PropertyEditorManager.findEditor(type);
+        if (editor != null) {
+            editor.setAsText(value.toString());
+            return editor.getValue();
+        }
+        if (type == URI.class) {
+            return new URI(value.toString());
+        }
+        if (type == File.class) {
+            return new File(value.toString());
+        }
+        if (type == File[].class) {
+            ArrayList<File> files = new ArrayList<File>();
+            StringTokenizer st = new StringTokenizer(value.toString(), ":");
+            while(st.hasMoreTokens()) {
+                String t = st.nextToken();
+                if( t!=null && t.trim().length()>0 ) {
+                    files.add(new File(t.trim()));
+                }
+            }
+            File rc[] = new File[files.size()];
+            files.toArray(rc);
+            return rc;
+        }
+        return null;
+    }
+
+    private static String convertToString(Object value, Class type) throws URISyntaxException {
+        PropertyEditor editor = PropertyEditorManager.findEditor(type);
+        if (editor != null) {
+            editor.setValue(value);
+            return editor.getAsText();
+        }
+        if (type == URI.class) {
+            return ((URI)value).toString();
+        }
+        return null;
+    }
+
+    private static Method findSetterMethod(Class clazz, String name) {
+        // Build the method name.
+        name = "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
+        Method[] methods = clazz.getMethods();
+        for (int i = 0; i < methods.length; i++) {
+            Method method = methods[i];
+            Class params[] = method.getParameterTypes();
+            if (method.getName().equals(name) && params.length == 1 && isSettableType(params[0])) {
+                return method;
+            }
+        }
+        return null;
+    }
+
+    private static boolean isSettableType(Class clazz) {
+        if (PropertyEditorManager.findEditor(clazz) != null) {
+            return true;
+        }
+        if (clazz == URI.class) {
+            return true;
+        }
+        if (clazz == File.class) {
+            return true;
+        }
+        if (clazz == File[].class) {
+            return true;
+        }
+        if (clazz == Boolean.class) {
+            return true;
+        }
+        return false;
+    }
+
+    public static String toString(Object target) {
+        return toString(target, Object.class);
+    }
+
+    public static String toString(Object target, Class stopClass) {
+        LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
+        addFields(target, target.getClass(), stopClass, map);
+        StringBuffer buffer = new StringBuffer(simpleName(target.getClass()));
+        buffer.append(" {");
+        Set entrySet = map.entrySet();
+        boolean first = true;
+        for (Iterator iter = entrySet.iterator(); iter.hasNext();) {
+            Map.Entry entry = (Map.Entry)iter.next();
+            if (first) {
+                first = false;
+            } else {
+                buffer.append(", ");
+            }
+            buffer.append(entry.getKey());
+            buffer.append(" = ");
+            appendToString(buffer, entry.getValue());
+        }
+        buffer.append("}");
+        return buffer.toString();
+    }
+
+    protected static void appendToString(StringBuffer buffer, Object value) {
+        buffer.append(value);
+    }
+
+    public static String simpleName(Class clazz) {
+        String name = clazz.getName();
+        int p = name.lastIndexOf(".");
+        if (p >= 0) {
+            name = name.substring(p + 1);
+        }
+        return name;
+    }
+
+    private static void addFields(Object target, Class startClass, Class<Object> stopClass, LinkedHashMap<String, Object> map) {
+
+        if (startClass != stopClass) {
+            addFields(target, startClass.getSuperclass(), stopClass, map);
+        }
+
+        Field[] fields = startClass.getDeclaredFields();
+        for (int i = 0; i < fields.length; i++) {
+            Field field = fields[i];
+            if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())
+                || Modifier.isPrivate(field.getModifiers())) {
+                continue;
+            }
+
+            try {
+                field.setAccessible(true);
+                Object o = field.get(target);
+                if (o != null && o.getClass().isArray()) {
+                    try {
+                        o = Arrays.asList((Object[])o);
+                    } catch (Throwable e) {
+                    }
+                }
+                map.put(field.getName(), o);
+            } catch (Throwable e) {
+                e.printStackTrace();
+            }
+        }
+
+    }
+
+}

Propchange: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/IntrospectionSupport.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java Sat Aug 30 11:54:28 2008
@@ -18,10 +18,12 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 
 import org.apache.activemq.protobuf.compiler.parser.ParseException;
@@ -29,25 +31,40 @@
 
 public class JavaGenerator {
 
-    private File outputDirectory = new File(".");
+    private File out = new File(".");
+    private File[] path = new File[]{new File(".")};
 
     private ProtoDescriptor proto;
     private String javaPackage;
     private String outerClassName;
     private File outputFile;
-    private FileOutputStream fos;
     private PrintWriter w;
     private int indent;
     private String optimizeFor;
+    private ArrayList<String> errors = new ArrayList<String>();
 
-    public static void main(String[] args) throws ParseException, CompilerException, IOException {
-
+    public static void main(String[] args) {
+        
         JavaGenerator generator = new JavaGenerator();
+        args = CommandLineSupport.setOptions(generator, args);
+        
         if (args.length == 0) {
             System.out.println("No proto files specified.");
         }
         for (int i = 0; i < args.length; i++) {
-            generator.compile(new File(args[i]));
+            try {
+                System.out.println("Compiling: "+args[i]);
+                generator.compile(new File(args[i]));
+            } catch (CompilerException e) {
+                System.out.println("Protocol Buffer Compiler failed with the following error(s):");
+                for (String error : e.getErrors() ) {
+                    System.out.println("");
+                    System.out.println(error);
+                }
+                System.out.println("");
+                System.out.println("Compile failed.  For more details see error messages listed above.");
+                return;
+            }
         }
 
     }
@@ -64,47 +81,95 @@
         }
     }
 
-    public void compile(File file) throws ParseException, CompilerException, IOException {
+    public void compile(File file) throws CompilerException {
 
         // Parse the proto file
-        FileInputStream is = new FileInputStream(file);
+        FileInputStream is=null;
         try {
+            is = new FileInputStream(file);
             ProtoParser parser = new ProtoParser(is);
             proto = parser.ProtoDescriptor();
+            proto.setName(file.getName());
+            loadImports(proto, file.getParentFile());
+            proto.validate(errors);
+        } catch (FileNotFoundException e) {
+            errors.add("Failed to open: "+file.getPath()+":"+e.getMessage());
+        } catch (ParseException e) {
+            errors.add("Failed to parse: "+file.getPath()+":"+e.getMessage());
         } finally {
-            is.close();
+            try { is.close(); } catch (Throwable ignore){}
         }
 
-        // Check for errors in the proto definition
-        List<String> errors = new ArrayList<String>();
-        proto.validate(errors);
-        if (!errors.isEmpty()) {
+        // This would be too fatal to continue..
+        if (proto==null) {
             throw new CompilerException(errors);
         }
 
         // Load the options..
-        javaPackage = getOption(proto, "java_package", null);
-        outerClassName = getOption(proto, "java_outer_classname", uCamel(removeFileExtension(file.getName())));
+        javaPackage = javaPackage(proto);
+        outerClassName = javaClassName(proto);
         optimizeFor = getOption(proto, "optimize_for", "SPEED");
 
         // Figure out the java file name..
-        outputFile = outputDirectory;
+        outputFile = out;
         if (javaPackage != null) {
             String packagePath = javaPackage.replace('.', '/');
             outputFile = new File(outputFile, packagePath);
         }
         outputFile = new File(outputFile, outerClassName + ".java");
 
+        
+        if (!errors.isEmpty()) {
+            throw new CompilerException(errors);
+        }
         // Start writing the output file..
         outputFile.getParentFile().mkdirs();
-        fos = new FileOutputStream(outputFile);
+        
+        FileOutputStream fos=null;
         try {
+            fos = new FileOutputStream(outputFile);
             w = new PrintWriter(fos);
             generateProtoFile();
             w.flush();
+        } catch (FileNotFoundException e) {
+            errors.add("Failed to write to: "+outputFile.getPath()+":"+e.getMessage());
         } finally {
-            fos.close();
+            try { fos.close(); } catch (Throwable ignore){}
+        }
+        if (!errors.isEmpty()) {
+            throw new CompilerException(errors);
+        }
+
+    }
+
+    private void loadImports(ProtoDescriptor proto, File protoDir) {
+        LinkedHashMap<String,ProtoDescriptor> children = new LinkedHashMap<String,ProtoDescriptor>(); 
+        for (String imp : proto.getImports()) {
+            File file = new File(protoDir, imp);
+            for (int i = 0; i < path.length && !file.exists(); i++) {
+                file = new File(path[i], imp);
+            } 
+            if ( !file.exists() ) {
+                errors.add("Cannot load import: "+imp);
+            }
+            
+            FileInputStream is=null;
+            try {
+                is = new FileInputStream(file);
+                ProtoParser parser = new ProtoParser(is);
+                ProtoDescriptor child = parser.ProtoDescriptor();
+                child.setName(file.getName());
+                loadImports(child, file.getParentFile());
+                children.put(imp, child);
+            } catch (ParseException e) {
+                errors.add("Failed to parse: "+file.getPath()+":"+e.getMessage());
+            } catch (FileNotFoundException e) {
+                errors.add("Failed to open: "+file.getPath()+":"+e.getMessage());
+            } finally {
+                try { is.close(); } catch (Throwable ignore){}
+            }
         }
+        proto.setImportProtoDescriptors(children);
     }
 
 
@@ -118,6 +183,9 @@
         p("public class " + outerClassName + " {");
         indent();
 
+        for (EnumDescriptor enumType : proto.getEnums().values()) {
+            generateEnum(enumType);
+        }
         for (MessageDescriptor m : proto.getMessages().values()) {
             generateMessageBean(m);
         }
@@ -142,17 +210,28 @@
         p();
 
         indent();
+        
+        for (EnumDescriptor enumType : m.getEnums().values()) {
+            generateEnum(enumType);
+        }
+
+        // Generate the Nested Messages.
         for (MessageDescriptor subMessage : m.getMessages().values()) {
             generateMessageBean(subMessage);
         }
 
+        // Generate the Group Messages
         for (FieldDescriptor field : m.getFields().values()) {
-            generateFieldAccessor(field);
+            if( field.isGroup() ) {
+                generateMessageBean(field.getGroup());
+            }
         }
-        
-        for (EnumDescriptor enumType : m.getEnums().values()) {
-            generateEnum(enumType);
+
+        // Generate the field accessors..
+        for (FieldDescriptor field : m.getFields().values()) {
+            generateFieldAccessor(className, field);
         }
+        
 
         p("public final boolean isInitialized() {");
         indent();
@@ -181,7 +260,6 @@
         p("}");
         p();
         
-        
         p("public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException {");
         indent();
         for (FieldDescriptor field : m.getFields().values()) {
@@ -198,10 +276,11 @@
         }
         // TODO: handle unknown fields
         // getUnknownFields().writeTo(output);
+        unindent();
         p("}");
         p();
         
-        p("public int getSerializedSize() {");
+        p("public int serializedSize() {");
         indent();
         p("if (memoizedSerializedSize != -1)");
         p("   return memoizedSerializedSize;");
@@ -242,6 +321,7 @@
             unindent();
             p("}");
         }
+        p("return this;");
         unindent();
         p("}");
         p();
@@ -260,7 +340,7 @@
               p("int tag = input.readTag();");
               p("switch (tag) {");
               p("case 0:");
-              p("   this.setUnknownFields(unknownFields.build());");
+//              p("   this.setUnknownFields(unknownFields.build());");
               p("   return this;");
               p("default: {");
               
@@ -297,8 +377,9 @@
 
     /**
      * @param field
+     * @param className 
      */
-    private void generateFieldAccessor(FieldDescriptor field) {
+    private void generateFieldAccessor(String className, FieldDescriptor field) {
         String lname = lCamel(field.getName());
         String uname = uCamel(field.getName());
         String type = javaType(field);
@@ -332,12 +413,13 @@
         p("}");
         p();
 
-        p("public void set" + uname + "(" + type + " " + lname + ") {");
+        p("public "+className+" set" + uname + "(" + type + " " + lname + ") {");
         indent();
         if (primitive) {
             p("this.b_" + lname + " = true;");
         }
-        p("this.f_" + lname + " = lname;");
+        p("this.f_" + lname + " = " + lname + ";");
+        p("return this;");
         unindent();
         p("}");
 
@@ -393,9 +475,17 @@
         p();
         p("public static "+uname+" valueOf(int value) {");
         p("   switch (value) {");
+        
+        // It's possible to define multiple ENUM fields with the same value.. 
+        //   we only want to put the first one into the switch statement.
+        HashSet<Integer> values = new HashSet<Integer>();
         for (EnumFieldDescriptor field : ed.getFields().values()) {
-            p("   case "+field.getValue()+":");
-            p("      return "+field.getName()+";");
+            if( !values.contains(field.getValue()) ) {
+                p("   case "+field.getValue()+":");
+                p("      return "+field.getName()+";");
+                values.add(field.getValue());
+            }
+            
         }
         p("   default:");
         p("      return null;");
@@ -435,9 +525,49 @@
         if( field.getType() == FieldDescriptor.BOOL_TYPE ) {
             return "boolean";
         }
-        return field.getType();
+        
+        TypeDescriptor descriptor = field.getTypeDescriptor();
+        return javaType(descriptor);
+    }
+
+    private String javaType(TypeDescriptor descriptor) {
+        ProtoDescriptor p = descriptor.getProtoDescriptor();
+        if( p != proto ) {
+            // Try to keep it short..
+            String othePackage = javaPackage(p);
+            if( equals(othePackage,javaPackage(proto) ) ) {
+                return javaClassName(p)+"."+descriptor.getQName();
+            }
+            // Use the fully qualified class name.
+            return othePackage+"."+javaClassName(p)+"."+descriptor.getQName();
+        }
+        return descriptor.getQName();
+    }
+    
+    private boolean equals(String o1, String o2) {
+        if( o1==o2 )
+            return true;
+        if( o1==null || o2==null )
+            return false;
+        return o1.equals(o2);
+    }
+
+    private String javaClassName(ProtoDescriptor proto) {
+        return getOption(proto, "java_outer_classname", uCamel(removeFileExtension(proto.getName())));
+    }
+
+
+    private String javaPackage(ProtoDescriptor proto) {
+        String name = proto.getPackageName();
+        if( name!=null ) {
+            name = name.replace('_', '.');
+            name = name.replace('-', '.');
+            name = name.replace('/', '.');
+        }
+        return getOption(proto, "java_package", name);
     }
 
+
     // ----------------------------------------------------------------
     // Internal Helper methods
     // ----------------------------------------------------------------
@@ -472,22 +602,47 @@
     }
 
     static private String removeFileExtension(String name) {
-        return name;
+        return name.replaceAll("\\..*", "");
     }
 
     static private String uCamel(String name) {
-        return name;
+        boolean upNext=true;
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < name.length(); i++) {
+            char c = name.charAt(i);
+            if( Character.isJavaIdentifierPart(c) && Character.isLetterOrDigit(c)) {
+                if( upNext ) {
+                    c = Character.toUpperCase(c);
+                    upNext=false;
+                }
+                sb.append(c);
+            } else {
+                upNext=true;
+            }
+        }
+        return sb.toString();
     }
 
     static private String lCamel(String name) {
-        return name;
+        if( name == null || name.length()<1 )
+            return name;
+        return uCamel(name.substring(0,1).toLowerCase()+name.substring(1));
+    }
+
+    public File getOut() {
+        return out;
     }
 
-    public File getOutputDirectory() {
-        return outputDirectory;
+    public void setOut(File outputDirectory) {
+        this.out = outputDirectory;
     }
 
-    public void setOutputDirectory(File outputDirectory) {
-        this.outputDirectory = outputDirectory;
+    public File[] getPath() {
+        return path;
     }
+
+    public void setPath(File[] path) {
+        this.path = path;
+    }
+    
 }

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java Sat Aug 30 11:54:28 2008
@@ -16,23 +16,39 @@
  */
 package org.apache.activemq.protobuf.compiler;
 
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 
-public class MessageDescriptor {
+public class MessageDescriptor implements TypeDescriptor {
 
     private String name;
     private ExtensionsDescriptor extensions;
-    private Map<String,FieldDescriptor> fields;
-    private Map<String,MessageDescriptor> messages;
-    private Map<String,EnumDescriptor> enums;
+    private Map<String,FieldDescriptor> fields = new LinkedHashMap<String, FieldDescriptor>();
+    private Map<String,MessageDescriptor> messages = new LinkedHashMap<String,MessageDescriptor>();
+    private Map<String,EnumDescriptor> enums = new LinkedHashMap<String, EnumDescriptor>();
     private final ProtoDescriptor protoDescriptor;
-    private List<ExtendDescriptor> extendsList;
-    private Map<String, OptionDescriptor> options;
+    private List<MessageDescriptor> extendsList = new ArrayList<MessageDescriptor>();
+    private Map<String, OptionDescriptor> options = new LinkedHashMap<String, OptionDescriptor>();
+    private final MessageDescriptor parent;
 
-    public MessageDescriptor(ProtoDescriptor protoDescriptor) {
+    public MessageDescriptor(ProtoDescriptor protoDescriptor, MessageDescriptor parent) {
         this.protoDescriptor = protoDescriptor;
+        this.parent = parent;
+    }
+    
+    public void validate(List<String> errors) {
+        for (FieldDescriptor field : fields.values()) {
+            field.validate(errors);
+        }
+        for (EnumDescriptor o : enums.values()) {
+            o.validate(errors);
+        }
+        for (MessageDescriptor o : messages.values()) {
+            o.validate(errors);
+        }
     }
 
     public void setName(String name) {
@@ -43,10 +59,10 @@
         this.extensions = extensions;
     }
 
-    public void setExtends(List<ExtendDescriptor> extendsList) {
+    public void setExtends(List<MessageDescriptor> extendsList) {
         this.extendsList = extendsList;
     }
-    public List<ExtendDescriptor> getExtends() {
+    public List<MessageDescriptor> getExtends() {
         return extendsList;
     }
 
@@ -66,6 +82,14 @@
         return name;
     }
 
+    public String getQName() {
+        if( parent==null ) {
+            return name;
+        } else {
+            return parent.getQName()+"."+name;
+        }
+    }
+
     public ExtensionsDescriptor getExtensions() {
         return extensions;
     }
@@ -86,11 +110,6 @@
         return protoDescriptor;
     }
 
-    public void validate(List<String> errors) {
-        // TODO Auto-generated method stub
-        
-    }
-
     public Map<String, OptionDescriptor> getOptions() {
         return options;
     }
@@ -99,4 +118,25 @@
         this.options = options;
     }
 
+    public MessageDescriptor getParent() {
+        return parent;
+    }
+
+    public TypeDescriptor getType(String t) {
+        for (MessageDescriptor o : messages.values()) {
+            if( t.equals(o.getName()) ) {
+                return o;
+            }
+            if( t.startsWith(o.getName()+".") ) {
+                return o.getType( t.substring(o.getName().length()+1) );
+            }
+        }
+        for (EnumDescriptor o : enums.values()) {
+            if( t.equals(o.getName()) ) {
+                return o;
+            }
+        }
+        return null;
+    }
+
 }

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/OptionDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/OptionDescriptor.java?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/OptionDescriptor.java (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/OptionDescriptor.java Sat Aug 30 11:54:28 2008
@@ -22,10 +22,8 @@
 
     private String name;
     private String value;
-    private final ProtoDescriptor protoDescriptor;
 
-    public OptionDescriptor(ProtoDescriptor protoDescriptor) {
-        this.protoDescriptor = protoDescriptor;
+    public OptionDescriptor() {
     }
 
     public String getName() {
@@ -44,10 +42,6 @@
         this.value = value;
     }
 
-    public ProtoDescriptor getProtoDescriptor() {
-        return protoDescriptor;
-    }
-
     public void validate(List<String> errors) {
         // TODO Auto-generated method stub
         

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoDescriptor.java?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoDescriptor.java (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoDescriptor.java Sat Aug 30 11:54:28 2008
@@ -16,18 +16,23 @@
  */
 package org.apache.activemq.protobuf.compiler;
 
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 public class ProtoDescriptor {
 
     private String packageName;
-    private Map<String, OptionDescriptor> options;
-    private Map<String, MessageDescriptor> messages;
-    private Map<String, EnumDescriptor> enums;
-    private List<ExtendDescriptor> extendsList;
-    private Map<String, ServiceDescriptor> services;
-
+    private Map<String, OptionDescriptor> options = new LinkedHashMap<String, OptionDescriptor>();
+    private Map<String, MessageDescriptor> messages = new LinkedHashMap<String, MessageDescriptor>();
+    private Map<String, EnumDescriptor> enums = new LinkedHashMap<String, EnumDescriptor>();
+    private List<MessageDescriptor> extendsList = new ArrayList<MessageDescriptor>();
+    private Map<String, ServiceDescriptor> services = new LinkedHashMap<String, ServiceDescriptor>();
+    List<String> imports = new ArrayList<String>();
+    Map<String,ProtoDescriptor> importProtoDescriptors = new LinkedHashMap<String, ProtoDescriptor>();
+    private String name;
+    
     public void setPackageName(String packageName) {
         this.packageName = packageName;
     }
@@ -44,11 +49,11 @@
         this.enums = enums;
     }
 
-    public void setExtends(List<ExtendDescriptor> extendsList) {
+    public void setExtends(List<MessageDescriptor> extendsList) {
         this.extendsList = extendsList;
     }
 
-    public List<ExtendDescriptor> getExtends() {
+    public List<MessageDescriptor> getExtends() {
         return extendsList;
     }
 
@@ -83,6 +88,9 @@
      * @return
      */
     public void validate(List<String> errors) {
+        for (ProtoDescriptor o : importProtoDescriptors.values()) {
+            o.validate(errors);
+        }
         for (OptionDescriptor o : options.values()) {
             o.validate(errors);
         }
@@ -92,7 +100,7 @@
         for (EnumDescriptor o : enums.values()) {
             o.validate(errors);
         }
-        for (ExtendDescriptor o : extendsList) {
+        for (MessageDescriptor o : extendsList) {
             o.validate(errors);
         }
         for (ServiceDescriptor o : services.values()) {
@@ -100,4 +108,57 @@
         }
     }
 
+    public List<String> getImports() {
+        return imports;
+    }
+
+    public void setImports(List<String> imports) {
+        this.imports = imports;
+    }
+
+    public Map<String, ProtoDescriptor> getImportProtoDescriptors() {
+        return importProtoDescriptors;
+    }
+
+    public void setImportProtoDescriptors(Map<String, ProtoDescriptor> importProtoDescriptors) {
+        this.importProtoDescriptors = importProtoDescriptors;
+    }
+
+    public TypeDescriptor getType(String type) {
+        for (MessageDescriptor o : messages.values()) {
+            if( type.equals(o.getName()) ) {
+                return o;
+            }
+            if( type.startsWith(o.getName()+".") ) {
+                return o.getType( type.substring(o.getName().length()+1) );
+            }
+        }
+        for (EnumDescriptor o : enums.values()) {
+            if( type.equals(o.getName()) ) {
+                return o;
+            }
+        }
+        // Check to see if the type was qualified with the package name...
+        for (ProtoDescriptor o : importProtoDescriptors.values()) {
+            if( o.getPackageName()!=null && type.startsWith(o.getPackageName()+".") ) {
+                return o.getType( type.substring(o.getPackageName().length()+1) );
+            }
+        }
+        for (ProtoDescriptor o : importProtoDescriptors.values()) {
+            TypeDescriptor rc = o.getType(type);
+            if (rc != null) {
+                return rc;
+            }
+        }
+        return null;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
 }

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java Sat Aug 30 11:54:28 2008
@@ -79,14 +79,16 @@
             try {
                 getLog().info("Compiling: "+file.getPath());
                 JavaGenerator generator = new JavaGenerator();
-                generator.setOutputDirectory(outputDirectory);
+                generator.setOut(outputDirectory);
                 generator.compile(file);
-            } catch (ParseException e) {
-                throw new MojoExecutionException("Parse failed: "+file.getPath()+"\n"+ e.getMessage(), e);
             } catch (CompilerException e) {
-                throw new MojoExecutionException("Compile failed", e);
-            } catch (IOException e) {
-                throw new MojoExecutionException("IO Error occured: " + e.getMessage(), e);
+                getLog().error("Protocol Buffer Compiler failed with the following error(s):");
+                for (String error : e.getErrors() ) {
+                    getLog().error("");
+                    getLog().error(error);
+                }
+                getLog().error("");
+                throw new MojoExecutionException("Compile failed.  For more details see error messages listed above.", e);
             }
         }
 

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ServiceDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ServiceDescriptor.java?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ServiceDescriptor.java (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ServiceDescriptor.java Sat Aug 30 11:54:28 2008
@@ -16,12 +16,13 @@
  */
 package org.apache.activemq.protobuf.compiler;
 
+import java.util.ArrayList;
 import java.util.List;
 
 public class ServiceDescriptor {
 
     private final ProtoDescriptor protoDescriptor;
-    private List<MethodDescriptor> methods;
+    private List<MethodDescriptor> methods=new ArrayList<MethodDescriptor>();
     private String name;
 
     public ServiceDescriptor(ProtoDescriptor protoDescriptor) {

Added: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/TypeDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/TypeDescriptor.java?rev=690550&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/TypeDescriptor.java (added)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/TypeDescriptor.java Sat Aug 30 11:54:28 2008
@@ -0,0 +1,26 @@
+/**
+ * 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.activemq.protobuf.compiler;
+
+public interface TypeDescriptor {
+    public String getName();
+    
+    public String getQName();
+
+    public ProtoDescriptor getProtoDescriptor();
+
+}

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/javacc/proto-parser.jj
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/javacc/proto-parser.jj?rev=690550&r1=690549&r2=690550&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/javacc/proto-parser.jj (original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/javacc/proto-parser.jj Sat Aug 30 11:54:28 2008
@@ -145,7 +145,7 @@
     LinkedHashMap<String,OptionDescriptor> opts = new LinkedHashMap<String,OptionDescriptor>();
     LinkedHashMap<String,MessageDescriptor> messages = new LinkedHashMap<String,MessageDescriptor>();
     LinkedHashMap<String,EnumDescriptor> enums = new LinkedHashMap<String,EnumDescriptor>();
-    ArrayList<ExtendDescriptor> extendsList = new ArrayList<ExtendDescriptor>();
+    ArrayList<MessageDescriptor> extendsList = new ArrayList<MessageDescriptor>();
     LinkedHashMap<String,ServiceDescriptor> services = new LinkedHashMap<String,ServiceDescriptor>();
     ArrayList<String> imports = new ArrayList<String>();
     
@@ -153,14 +153,14 @@
     MessageDescriptor messageD;
     EnumDescriptor enumD;
     ServiceDescriptor serviceD;
-    ExtendDescriptor extendD;
+    MessageDescriptor extendD;
     String o;
 }
 {
     (
 		<PACKAGE> packageName=PackageID() <SEMICOLON>
 	|	
-        <OPTION> optionD = OptionDescriptor(proto) <SEMICOLON>
+        <OPTION> optionD = OptionDescriptor() <SEMICOLON>
         { opts.put(optionD.getName(),optionD); }
     |   
         <IMPORT> 
@@ -168,22 +168,23 @@
         <SEMICOLON>
         { imports.add((String)o); }
     |   
-        messageD = MessageDescriptor(proto) (<SEMICOLON>)?
+        messageD = MessageDescriptor(proto, null) (<SEMICOLON>)?
         { messages.put(messageD.getName(),messageD); }
         
     |   
-        enumD = EnumDescriptor(proto) (<SEMICOLON>)?
+        enumD = EnumDescriptor(proto, null) (<SEMICOLON>)?
         { enums.put(enumD.getName(),enumD); }
     |   
         serviceD = ServiceDescriptor(proto) (<SEMICOLON>)?
         { services.put(serviceD.getName(),serviceD); }
     |   
-        extendD = ExtendDescriptor(proto) (<SEMICOLON>)?
+        extendD = ExtendDescriptor(proto, null) (<SEMICOLON>)?
         { extendsList.add(extendD); }
     )+
     <EOF>
     { 
     	proto.setPackageName(packageName);
+    	proto.setImports(imports);
     	proto.setOptions(opts);
     	proto.setMessages(messages);
     	proto.setEnums(enums);
@@ -194,45 +195,45 @@
 }
 
 
-MessageDescriptor MessageDescriptor(ProtoDescriptor proto) :
+MessageDescriptor MessageDescriptor(ProtoDescriptor proto, MessageDescriptor parent) :
 {
     String name;
     LinkedHashMap<String,FieldDescriptor> fields = new LinkedHashMap<String,FieldDescriptor>();
     LinkedHashMap<String,MessageDescriptor> messages = new LinkedHashMap<String,MessageDescriptor>();
     LinkedHashMap<String,EnumDescriptor> enums = new LinkedHashMap<String,EnumDescriptor>();
-    ArrayList<ExtendDescriptor> extendsList = new ArrayList<ExtendDescriptor>();
+    ArrayList<MessageDescriptor> extendsList = new ArrayList<MessageDescriptor>();
     LinkedHashMap<String,OptionDescriptor> opts = new LinkedHashMap<String,OptionDescriptor>();
 
+  	MessageDescriptor rc = new MessageDescriptor(proto, parent);
     OptionDescriptor optionD;
     ExtensionsDescriptor extensionsD=null;
 	FieldDescriptor fieldD;
 	MessageDescriptor messageD;
 	EnumDescriptor enumD;
-	ExtendDescriptor extendD;
+	MessageDescriptor extendD;
 }
 {
     <MESSAGE> name = ID() <LBRACE>
     (
-        <OPTION> optionD = OptionDescriptor(proto) <SEMICOLON>
+        <OPTION> optionD = OptionDescriptor() <SEMICOLON>
         { opts.put(optionD.getName(),optionD); }
 	|	
-    	fieldD = FieldDescriptor(proto)
+    	fieldD = FieldDescriptor(rc)
     	{ fields.put(fieldD.getName(), fieldD); }
     |   
-        messageD = MessageDescriptor(proto) (<SEMICOLON>)?
+        messageD = MessageDescriptor(proto, rc) (<SEMICOLON>)?
         { messages.put(messageD.getName(),messageD); }
     |   
-        enumD = EnumDescriptor(proto) (<SEMICOLON>)?
+        enumD = EnumDescriptor(proto, rc) (<SEMICOLON>)?
         { enums.put(enumD.getName(), enumD); }
     |   
-        extensionsD = ExtensionsDescriptor(proto) <SEMICOLON>
+        extensionsD = ExtensionsDescriptor(rc) <SEMICOLON>
     |   
-        extendD = ExtendDescriptor(proto) (<SEMICOLON>)?
+        extendD = ExtendDescriptor(proto, rc) (<SEMICOLON>)?
         { extendsList.add(extendD); }
     )*
     <RBRACE>
     {
-    	MessageDescriptor rc = new MessageDescriptor(proto);
     	rc.setName(name);
     	rc.setFields(fields);
     	rc.setMessages(messages);
@@ -247,7 +248,7 @@
  * Parses something like:
  * optional string foo = 1;
  */
-FieldDescriptor FieldDescriptor(ProtoDescriptor proto) :
+FieldDescriptor FieldDescriptor(MessageDescriptor parent) :
 {
     String rule;
     String type;
@@ -257,7 +258,8 @@
     LinkedHashMap<String,FieldDescriptor> fields = new LinkedHashMap<String,FieldDescriptor>();
     OptionDescriptor optionD;
 	FieldDescriptor fieldD;
-	FieldDescriptor rc;
+	FieldDescriptor rc = new FieldDescriptor(parent);
+   	MessageDescriptor group = new MessageDescriptor(parent.getProtoDescriptor(), parent);
 }
 {
 
@@ -274,13 +276,13 @@
 	    tag = Integer()
 	    (
 	    	<LBRACKET>
-	    	optionD = OptionDescriptor(proto)
+	    	optionD = OptionDescriptor()
 	    	{
 	    		opts.put(optionD.getName(), optionD);
 	    	}
 	    	(
 	    		<COMMA>
-		    	optionD = OptionDescriptor(proto)
+		    	optionD = OptionDescriptor()
 		    	{
 	    			opts.put(optionD.getName(), optionD);
 	    		}
@@ -288,39 +290,35 @@
 	    	<RBRACKET>
 	    )?
 	    <SEMICOLON>    
+    	|
 	    {
-	    	FieldDescriptor t = new FieldDescriptor(proto);
-	    	t.setName(name);
-	    	t.setType(type);
-	    	t.setRule(rule);
-	    	t.setTag(tag);
-	    	t.setOptions(opts);
-	    	rc=t;
 	    }
-    	|
 		<GROUP>
 	    name = ID()
 	    <EQUALS>
 	    tag = Integer()
 	    <LBRACE>
 	    (
-	       	fieldD = FieldDescriptor(proto)
-	    	{ fields.put(fieldD.getName(), fieldD); }
+	       	fieldD = FieldDescriptor(group)
+	    	{
+	    		fields.put(fieldD.getName(), fieldD); 
+	    	}
 	    )*
 	    <RBRACE> 
 	    ( <SEMICOLON> )?  
 	    {
-	    	GroupDescriptor t = new GroupDescriptor(proto);
-	    	t.setName(name);
-	    	t.setType("group");
-	    	t.setRule(rule);
-	    	t.setTag(tag);
-	    	t.setOptions(opts);
-	    	t.setFields(fields);
-	    	rc=t;
+	    	type = name;    	
+	    	group.setName(name);
+	    	group.setFields(fields);
+	    	rc.setGroup(group);
 	    }
     )
     {
+    	rc.setName(name);
+    	rc.setType(type);
+    	rc.setRule(rule);
+    	rc.setTag(tag);
+    	rc.setOptions(opts);
 		return rc;
     }
 }
@@ -365,7 +363,7 @@
     }
 }
 
-OptionDescriptor OptionDescriptor(ProtoDescriptor proto) :
+OptionDescriptor OptionDescriptor() :
 {
     String name;
     String value;
@@ -375,35 +373,35 @@
     <EQUALS> 
     value=Value() 
     {
-    	OptionDescriptor rc = new OptionDescriptor(proto);
+    	OptionDescriptor rc = new OptionDescriptor();
     	rc.setName(name);
     	rc.setValue(value);
     	return rc;
     }
 }
 
-ExtendDescriptor ExtendDescriptor(ProtoDescriptor proto) :
+MessageDescriptor ExtendDescriptor(ProtoDescriptor proto, MessageDescriptor parent) :
 {
     String name;
     LinkedHashMap<String, FieldDescriptor> fields = new LinkedHashMap<String,FieldDescriptor>();
+  	MessageDescriptor rc = new MessageDescriptor(proto, parent);
     FieldDescriptor fieldD;
 }
 {
     <EXTEND> name = ID() <LBRACE>
     (
-    	fieldD = FieldDescriptor(proto)
+    	fieldD = FieldDescriptor(rc)
     	{ fields.put(fieldD.getName(), fieldD); }
     )*
     <RBRACE>
     {
-    	ExtendDescriptor rc = new ExtendDescriptor(proto);
     	rc.setName(name);
     	rc.setFields(fields);
     	return rc;
     }
 }
 
-ExtensionsDescriptor ExtensionsDescriptor(ProtoDescriptor proto) :
+ExtensionsDescriptor ExtensionsDescriptor(MessageDescriptor parent) :
 {
 	int first;
 	int last;
@@ -421,30 +419,30 @@
     	}
     )
     {
-    	ExtensionsDescriptor rc = new ExtensionsDescriptor(proto);
+    	ExtensionsDescriptor rc = new ExtensionsDescriptor(parent);
     	rc.setFirst(first);
     	rc.setLast(last);
     	return rc;
     }
 }
 
-EnumDescriptor EnumDescriptor(ProtoDescriptor proto) :
+EnumDescriptor EnumDescriptor(ProtoDescriptor proto, MessageDescriptor parent) :
 {
     Token name;
     LinkedHashMap<String,EnumFieldDescriptor> fields = new LinkedHashMap<String,EnumFieldDescriptor>();
+   	EnumDescriptor rc = new EnumDescriptor(proto, parent);
     EnumFieldDescriptor enumD;
 }
 {
     <ENUM> name = <ID> <LBRACE>
     (
-    	enumD = EnumFieldDescriptor(proto) <SEMICOLON>
+    	enumD = EnumFieldDescriptor(rc) <SEMICOLON>
     	{
     		fields.put(enumD.getName(),enumD);
     	}
     )*
     <RBRACE>
     {
-    	EnumDescriptor rc = new EnumDescriptor(proto);
     	rc.setName(name.image);
     	rc.setFields(fields);
     	return rc;
@@ -455,7 +453,7 @@
  * Parses something like:
  * optional string foo = 1;
  */
-EnumFieldDescriptor EnumFieldDescriptor(ProtoDescriptor proto) :
+EnumFieldDescriptor EnumFieldDescriptor(EnumDescriptor parent) :
 {
     String name;
     int value=0;
@@ -466,7 +464,7 @@
     <EQUALS>
     value = Integer()
     {
-    	EnumFieldDescriptor rc = new EnumFieldDescriptor(proto);
+    	EnumFieldDescriptor rc = new EnumFieldDescriptor(parent);
     	rc.setName(name);
     	rc.setValue(value);
     	return rc;



Mime
View raw message