activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r690331 - in /activemq/sandbox/activemq-protobuf: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/activemq/ src/main/java/org/apache/activemq/protobuf/ src/main/java/org/apache/activemq...
Date Fri, 29 Aug 2008 16:53:02 GMT
Author: chirino
Date: Fri Aug 29 09:53:00 2008
New Revision: 690331

URL: http://svn.apache.org/viewvc?rev=690331&view=rev
Log:
Adding first pass of the proto generator

Added:
    activemq/sandbox/activemq-protobuf/README.txt
    activemq/sandbox/activemq-protobuf/pom.xml
    activemq/sandbox/activemq-protobuf/src/
    activemq/sandbox/activemq-protobuf/src/main/
    activemq/sandbox/activemq-protobuf/src/main/java/
    activemq/sandbox/activemq-protobuf/src/main/java/org/
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumDescriptor.java
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumFieldDescriptor.java
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtendDescriptor.java
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtensionsDescriptor.java
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/FieldDescriptor.java
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MethodDescriptor.java
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/OptionDescriptor.java
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ParserSupport.java
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoDescriptor.java
    activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ServiceDescriptor.java
    activemq/sandbox/activemq-protobuf/src/main/javacc/
    activemq/sandbox/activemq-protobuf/src/main/javacc/proto-parser.jj
    activemq/sandbox/activemq-protobuf/src/test/
    activemq/sandbox/activemq-protobuf/src/test/java/

Added: activemq/sandbox/activemq-protobuf/README.txt
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/README.txt?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/README.txt (added)
+++ activemq/sandbox/activemq-protobuf/README.txt Fri Aug 29 09:53:00 2008
@@ -0,0 +1,25 @@
+=======================================================================
+The AcitveMQ Protocol Buffers Java Implementation
+=======================================================================
+
+Protocol Buffers is a data interchange format developed by 
+Google.  You can get more information about Protocol Buffers
+at:
+
+ http://code.google.com/apis/protocolbuffers/
+
+
+Unfortunately the the main Protocol Buffer's project made the 
+Java API cumbersome to use since the messages are immutable.  They
+Justify this decision by highlighting the fact it reduces end user
+error that occur with Mutable messages.
+
+This module brings you a slimmed down lean and mean API to accessing
+Protocol Buffer data structures.  It provides little protection
+from end users 'hurting themselves', but it does give power user
+and easier to use API.
+
+In addition, this module provides a Java based code generator so 
+that it's easier to code generate your Protocol Buffer classes in 
+a java based build system like Ant or Maven.
+

Added: activemq/sandbox/activemq-protobuf/pom.xml
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/pom.xml?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/pom.xml (added)
+++ activemq/sandbox/activemq-protobuf/pom.xml Fri Aug 29 09:53:00 2008
@@ -0,0 +1,79 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  
+  <modelVersion>4.0.0</modelVersion>
+  
+  <groupId>org.apache.activemq.protobuf</groupId>
+  <artifactId>activemq-protobuf</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <name>A Simple Protocol Buffer Java API</name>
+
+  <description>
+    A Simpler Protocol Buffer Java API.  Comes with a built in proto file compiler and Java source code generator.
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.4</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.protobuf</groupId>
+      <artifactId>protobuf-java</artifactId>
+      <version>2.0.1rc1</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/*Test.java</include>
+          </includes>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>javacc-maven-plugin</artifactId>
+        <version>2.4.1</version>
+         <executions>
+          <execution>
+            <id>javacc</id>
+            <goals>
+              <goal>javacc</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  
+</project>

Added: activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumDescriptor.java?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumDescriptor.java (added)
+++ activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumDescriptor.java Fri Aug 29 09:53:00 2008
@@ -0,0 +1,57 @@
+/**
+ * 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.List;
+import java.util.Map;
+
+public class EnumDescriptor {
+
+    private String name;
+    private Map<String,EnumFieldDescriptor> fields;
+    private final ProtoDescriptor protoDescriptor;
+
+    public EnumDescriptor(ProtoDescriptor protoDescriptor) {
+        this.protoDescriptor = protoDescriptor;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public Map<String,EnumFieldDescriptor> getFields() {
+        return fields;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setFields(Map<String,EnumFieldDescriptor> fields) {
+        this.fields = fields;
+    }
+    public ProtoDescriptor getProtoDescriptor() {
+        return protoDescriptor;
+    }
+
+    public void validate(List<String> errors) {
+        // TODO Auto-generated method stub
+        
+    }
+
+
+}

Added: activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumFieldDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumFieldDescriptor.java?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumFieldDescriptor.java (added)
+++ activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/EnumFieldDescriptor.java Fri Aug 29 09:53:00 2008
@@ -0,0 +1,54 @@
+/**
+ * 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 class EnumFieldDescriptor {
+
+    private String name;
+    private int value;
+    private final ProtoDescriptor protoDescriptor;
+
+    public EnumFieldDescriptor(ProtoDescriptor protoDescriptor) {
+        this.protoDescriptor = protoDescriptor;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setValue(int value) {
+        this.value = value;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public int getValue() {
+        return value;
+    }
+
+    public ProtoDescriptor getProtoDescriptor() {
+        return protoDescriptor;
+    }
+
+    public String geName() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Added: activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtendDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtendDescriptor.java?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtendDescriptor.java (added)
+++ activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtendDescriptor.java Fri Aug 29 09:53:00 2008
@@ -0,0 +1,56 @@
+/**
+ * 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.List;
+import java.util.Map;
+
+public class ExtendDescriptor {
+
+    private String name;
+    private Map<String,FieldDescriptor> fields;
+    private final ProtoDescriptor protoDescriptor;
+
+    public ExtendDescriptor(ProtoDescriptor protoDescriptor) {
+        this.protoDescriptor = protoDescriptor;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setFields(Map<String,FieldDescriptor> fields) {
+        this.fields = fields;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public Map<String,FieldDescriptor> getFields() {
+        return fields;
+    }
+
+    public ProtoDescriptor getProtoDescriptor() {
+        return protoDescriptor;
+    }
+
+    public void validate(List<String> errors) {
+    }
+
+
+}

Added: activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtensionsDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtensionsDescriptor.java?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtensionsDescriptor.java (added)
+++ activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ExtensionsDescriptor.java Fri Aug 29 09:53:00 2008
@@ -0,0 +1,49 @@
+/**
+ * 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 class ExtensionsDescriptor {
+
+    private int first;
+    private int last;
+    private final ProtoDescriptor protoDescriptor;
+
+    public ExtensionsDescriptor(ProtoDescriptor protoDescriptor) {
+        this.protoDescriptor = protoDescriptor;
+    }
+
+    public void setFirst(int first) {
+        this.first = first;
+    }
+
+    public void setLast(int last) {
+        this.last = last;
+    }
+
+    public int getFirst() {
+        return first;
+    }
+
+    public int getLast() {
+        return last;
+    }
+
+    public ProtoDescriptor getProtoDescriptor() {
+        return protoDescriptor;
+    }
+
+}

Added: activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/FieldDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/FieldDescriptor.java?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/FieldDescriptor.java (added)
+++ activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/FieldDescriptor.java Fri Aug 29 09:53:00 2008
@@ -0,0 +1,170 @@
+/**
+ * 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;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class FieldDescriptor {
+
+    public static final String STRING_TYPE = "string".intern();
+    public static final String BOOL_TYPE = "bool".intern();
+    public static final String BYTES_TYPE = "bytes".intern();
+    public static final String DOUBLE_TYPE = "double".intern();
+    public static final String FLOAT_TYPE = "float".intern();
+    
+    public static final String INT32_TYPE = "int32".intern();
+    public static final String INT64_TYPE = "int64".intern();
+    public static final String UINT32_TYPE = "uint32".intern();
+    public static final String UINT64_TYPE = "uint64".intern();
+    public static final String SINT32_TYPE = "sint32".intern();
+    public static final String SINT64_TYPE = "sint64".intern();
+    public static final String FIXED32_TYPE = "fixed32".intern();
+    public static final String FIXED64_TYPE = "fixed64".intern();
+    public static final String SFIXED32_TYPE = "sfixed32".intern();
+    public static final String SFIXED64_TYPE = "sfixed64".intern();
+    
+    public static final String REQUIRED_RULE = "required".intern();
+    public static final String OPTIONAL_RULE= "optional".intern();
+    public static final String REPEATED_RULE = "repeated".intern();
+    
+    public static final Set<String> INT32_TYPES = new HashSet<String>();
+    public static final Set<String> INT64_TYPES = new HashSet<String>();    
+    public static final Set<String> INTEGER_TYPES = new HashSet<String>();
+    public static final Set<String> NUMBER_TYPES = new HashSet<String>();
+    public static final Set<String> SCALAR_TYPES = new HashSet<String>();
+    
+    static {
+        INT32_TYPES.add(INT32_TYPE);
+        INT32_TYPES.add(UINT32_TYPE);
+        INT32_TYPES.add(SINT32_TYPE);
+        INT32_TYPES.add(FIXED32_TYPE);
+        INT32_TYPES.add(SFIXED32_TYPE);
+
+        INT64_TYPES.add(INT64_TYPE);
+        INT64_TYPES.add(UINT64_TYPE);
+        INT64_TYPES.add(SINT64_TYPE);
+        INT64_TYPES.add(FIXED64_TYPE);
+        INT64_TYPES.add(SFIXED64_TYPE);
+        
+        INTEGER_TYPES.addAll(INT32_TYPES);
+        INTEGER_TYPES.addAll(INT64_TYPES);
+        
+        NUMBER_TYPES.addAll(INTEGER_TYPES);
+        NUMBER_TYPES.add(DOUBLE_TYPE);
+        NUMBER_TYPES.add(FLOAT_TYPE);
+        
+        SCALAR_TYPES.addAll(NUMBER_TYPES);
+        SCALAR_TYPES.add(STRING_TYPE);
+        SCALAR_TYPES.add(BOOL_TYPE);
+        SCALAR_TYPES.add(BYTES_TYPE);
+    }
+    
+    
+    private String name;
+    private String type;
+    private String rule;
+    private int tag;
+    private Map<String,OptionDescriptor> options;
+    private final ProtoDescriptor protoDescriptor;
+
+    public FieldDescriptor(ProtoDescriptor protoDescriptor) {
+        this.protoDescriptor = protoDescriptor;
+    }
+    
+    public ProtoDescriptor getProtoDescriptor() {
+        return protoDescriptor;
+    }
+
+
+    public String getName() {
+        return name;
+    }
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getRule() {
+        return rule;
+    }
+    public void setRule(String rule) {
+        this.rule = rule.intern();
+    }
+    
+    public boolean isOptional() {
+        return this.rule == OPTIONAL_RULE;
+    }
+    public boolean isRequired() {
+        return this.rule == REQUIRED_RULE;
+    }
+    public boolean isRepeated() {
+        return this.rule == REPEATED_RULE;
+    }
+
+    public int getTag() {
+        return tag;
+    }
+    public void setTag(int tag) {
+        this.tag = tag;
+    }
+
+    public Map<String,OptionDescriptor> getOptions() {
+        return options;
+    }
+    public void setOptions(Map<String,OptionDescriptor> options) {
+        this.options = options;
+    }
+
+    public String getType() {
+        return type;
+    }
+    public void setType(String type) {
+        this.type = type.intern();
+    }
+
+    public boolean isMessageType() {
+        return !SCALAR_TYPES.contains(type);
+    }
+
+    public boolean isScalarType() {
+        return SCALAR_TYPES.contains(type);
+    }
+
+    public boolean isNumberType() {
+        return NUMBER_TYPES.contains(type);
+    }
+    
+    public boolean isIntegerType() {
+        return INTEGER_TYPES.contains(type);
+    }
+
+    public boolean isInteger32Type() {
+        return INT32_TYPES.contains(type);
+    }
+
+    public boolean isInteger64Type() {
+        return INT64_TYPES.contains(type);
+    }
+
+    public boolean isStringType() {
+        return type==STRING_TYPE;
+    }
+
+}

Added: activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java (added)
+++ activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java Fri Aug 29 09:53:00 2008
@@ -0,0 +1,493 @@
+/**
+ * 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.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.activemq.protobuf.compiler.parser.ParseException;
+import org.apache.activemq.protobuf.compiler.parser.ProtoParser;
+
+public class JavaGenerator {
+
+    private File outputDirectory = 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;
+
+    public static void main(String[] args) throws ParseException, CompilerException, IOException {
+
+        JavaGenerator generator = new JavaGenerator();
+        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]));
+        }
+
+    }
+
+    static public class CompilerException extends Exception {
+        private final List<String> errors;
+
+        public CompilerException(List<String> errors) {
+            this.errors = errors;
+        }
+
+        public List<String> getErrors() {
+            return errors;
+        }
+    }
+
+    public void compile(File file) throws ParseException, CompilerException, IOException {
+
+        // Parse the proto file
+        FileInputStream is = new FileInputStream(file);
+        try {
+            ProtoParser parser = new ProtoParser(is);
+            proto = parser.ProtoDescriptor();
+        } finally {
+            is.close();
+        }
+
+        // Check for errors in the proto definition
+        List<String> errors = new ArrayList<String>();
+        proto.validate(errors);
+        if (!errors.isEmpty()) {
+            throw new CompilerException(errors);
+        }
+
+        // Load the options..
+        javaPackage = getOption(proto, "java_package", null);
+        outerClassName = getOption(proto, "java_outer_classname", uCamel(removeFileExtension(file.getName())));
+        optimizeFor = getOption(proto, "optimize_for", "SPEED");
+
+        // Figure out the java file name..
+        outputFile = outputDirectory;
+        if (javaPackage != null) {
+            String packagePath = javaPackage.replace('.', '/');
+            outputFile = new File(outputFile, packagePath);
+        }
+        outputFile = new File(outputFile, outerClassName + ".java");
+
+        // Start writing the output file..
+        outputFile.getParentFile().mkdirs();
+        fos = new FileOutputStream(outputFile);
+        try {
+            w = new PrintWriter(fos);
+            generateProtoFile();
+            w.flush();
+        } finally {
+            fos.close();
+        }
+    }
+
+
+    private void generateProtoFile() {
+        generateFileHeader();
+        if (javaPackage != null) {
+            p("package " + javaPackage + ";");
+            p("");
+        }
+
+        p("public class " + outerClassName + " {");
+        indent();
+
+        for (MessageDescriptor m : proto.getMessages().values()) {
+            generateMessageBean(m);
+        }
+
+        unindent();
+        p("}");
+    }
+
+    private void generateFileHeader() {
+        p("//");
+        p("// Generated by protoc, do not edit by hand.");
+        p("//");
+    }
+
+    private void generateMessageBean(MessageDescriptor m) {
+        
+        String className = uCamel(m.getName());
+        p();
+        p("public static final class " + className + " {");
+        p();
+        p("private int memoizedSerializedSize = -1;");
+        p();
+
+        indent();
+        for (MessageDescriptor subMessage : m.getMessages().values()) {
+            generateMessageBean(subMessage);
+        }
+
+        for (FieldDescriptor field : m.getFields().values()) {
+            generateFieldAccessor(field);
+        }
+        
+        for (EnumDescriptor enumType : m.getEnums().values()) {
+            generateEnum(enumType);
+        }
+
+        p("public final boolean isInitialized() {");
+        indent();
+        for (FieldDescriptor field : m.getFields().values()) {
+            String uname = uCamel(field.getName());
+            if( field.isRequired() ) {
+                p("if(  !has" + uname + "() ) {");
+                p("   return false;");
+                p("}");
+            }
+        }
+        p("return true;");
+        unindent();
+        p("}");
+        p();
+
+        
+        p("public final void clear() {");
+        indent();
+        p("memoizedSerializedSize=-1;");
+        for (FieldDescriptor field : m.getFields().values()) {
+            String uname = uCamel(field.getName());
+            p("clear" + uname + "();");
+        }
+        unindent();
+        p("}");
+        p();
+        
+        
+        p("public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException {");
+        indent();
+        for (FieldDescriptor field : m.getFields().values()) {
+            String uname = uCamel(field.getName());
+            p("if (has"+uname+"()) {");
+            indent();
+            if( field.isStringType() ) {
+                p("output.writeString("+field.getTag()+", get"+uname+"());");
+            } else if(field.isInteger32Type()) {
+            }
+            //TODO: finish this up.
+            unindent();
+            p("}");
+        }
+        // TODO: handle unknown fields
+        // getUnknownFields().writeTo(output);
+        p("}");
+        p();
+        
+        p("public int getSerializedSize() {");
+        indent();
+        p("if (memoizedSerializedSize != -1)");
+        p("   return memoizedSerializedSize;");
+        p();
+        p("int size = 0;");
+        for (FieldDescriptor field : m.getFields().values()) {
+            String uname = uCamel(field.getName());
+            p("if (has"+uname+"()) {");
+            indent();
+            if( field.isStringType() ) {
+                p("size += com.google.protobuf.CodedOutputStream.computeStringSize("+field.getTag()+", get"+uname+"());");;
+            } else if(field.isInteger32Type()) {
+            }
+            //TODO: finish this up.
+            unindent();
+            p("}");
+        }
+        // TODO: handle unknown fields
+        // size += getUnknownFields().getSerializedSize();");
+        p("memoizedSerializedSize = size;");
+        p("return size;");
+        unindent();
+        p("}");
+        p();
+        
+        p("public "+className+" clone() {");
+        p("   return new "+className+"().mergeFrom(this);");
+        p("}");
+        p();
+
+        p("public "+className+" mergeFrom("+className+" other) {");
+        indent();
+        for (FieldDescriptor field : m.getFields().values()) {
+            String uname = uCamel(field.getName());
+            p("if (has"+uname+"()) {");
+            indent();
+            p("set"+uname+"(other.get"+uname+"());");
+            unindent();
+            p("}");
+        }
+        unindent();
+        p("}");
+        p();
+
+        p("public "+className+" mergeFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException {");
+        p("    return mergeFrom(input, com.google.protobuf.ExtensionRegistry.getEmptyRegistry());");
+        p("}");
+
+        p("public "+className+" mergeFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistry extensionRegistry) throws java.io.IOException {");
+        indent(); {
+          //TODO: handle unknown fields
+          // UnknownFieldSet.Builder unknownFields = com.google.protobuf.UnknownFieldSet.newBuilder(this.unknownFields);
+            
+          p("while (true) {");
+          indent(); {
+              p("int tag = input.readTag();");
+              p("switch (tag) {");
+              p("case 0:");
+              p("   this.setUnknownFields(unknownFields.build());");
+              p("   return this;");
+              p("default: {");
+              
+              //TODO: handle unknown field types.
+//              p("   if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) {");
+//              p("       this.setUnknownFields(unknownFields.build());");
+//              p("       return this;");
+//              p("   }");
+              
+              p("   break;");
+              p("}");
+              for (FieldDescriptor field : m.getFields().values()) {
+                  String uname = uCamel(field.getName());
+                  p("case "+field.getTag()+":");
+                  indent();
+                  if( field.isStringType() ) {
+                      p("set"+uname+"(input.readString());");
+                  }
+                  //TODO: do the rest of the types...
+                  p("break;");
+                  unindent();
+              }              
+              p("}");
+          } unindent();
+          p("}"); 
+        } unindent();
+        p("}");
+
+
+        unindent();
+        p("}");
+        p();
+    }
+
+    /**
+     * @param field
+     */
+    private void generateFieldAccessor(FieldDescriptor field) {
+        String lname = lCamel(field.getName());
+        String uname = uCamel(field.getName());
+        String type = javaType(field);
+        String typeDefault = javaTypeDefault(field);
+        boolean primitive = isPrimitive(field);
+
+        // Create the fields..
+        p("// " + field.getRule() + " " + field.getType() + " " + field.getName() + " = " + field.getTag() + ";");
+        p("private " + type + " f_" + lname + ";");
+        if (primitive) {
+            p("private boolean b_" + lname + ";");
+        }
+        p();
+
+        // Create the field accessors
+        p("public boolean has" + uname + "() {");
+        indent();
+        if (primitive) {
+            p("return this.b_" + lname + ";");
+        } else {
+            p("return this.f_" + lname + "!=null;");
+        }
+        unindent();
+        p("}");
+        p();
+
+        p("public " + type + " get" + uname + "() {");
+        indent();
+        p("return this.f_" + lname + ";");
+        unindent();
+        p("}");
+        p();
+
+        p("public void set" + uname + "(" + type + " " + lname + ") {");
+        indent();
+        if (primitive) {
+            p("this.b_" + lname + " = true;");
+        }
+        p("this.f_" + lname + " = lname;");
+        unindent();
+        p("}");
+
+        p("public void clear" + uname + "() {");
+        indent();
+        if (primitive) {
+            p("this.b_" + lname + " = false;");
+        }
+        p("this.f_" + lname + " = " + typeDefault + ";");
+        unindent();
+        p("}");
+    }
+
+    private String javaTypeDefault(FieldDescriptor field) {
+//        OptionDescriptor defaultOption = field.getOptions().get("default");
+        if( field.isNumberType() ) {
+            return "0";
+        }
+        if( field.getType() == FieldDescriptor.BOOL_TYPE ) {
+            return "false";
+        }
+        return "null";
+    }
+    
+    private void generateEnum(EnumDescriptor ed) {
+        String uname = uCamel(ed.getName());
+
+        // TODO Auto-generated method stub
+        p();
+        p("public static enum " +uname + " {");
+        indent();
+        
+        
+        p();
+        int counter=0;
+        for (EnumFieldDescriptor field : ed.getFields().values()) {
+            boolean last = counter+1 == ed.getFields().size();
+            p(field.getName()+"("+counter+", "+field.getValue()+")"+(last?";":",")); 
+            counter++;
+        }
+        p();
+        p("private final int index;");
+        p("private final int value;");
+        p();
+        p("private "+uname+"(int index, int value) {");
+        p("   this.index = index;");
+        p("   this.value = value;");
+        p("}");
+        p();
+        p("public final int getNumber() {");
+        p("   return value;");
+        p("}");
+        p();
+        p("public static "+uname+" valueOf(int value) {");
+        p("   switch (value) {");
+        for (EnumFieldDescriptor field : ed.getFields().values()) {
+            p("   case "+field.getValue()+":");
+            p("      return "+field.getName()+";");
+        }
+        p("   default:");
+        p("      return null;");
+        p("   }");
+        p("}");
+        
+        
+        unindent();
+        p("}");
+        p();
+    }
+
+
+    private boolean isPrimitive(FieldDescriptor field) {
+        return field.isNumberType() || field.getType()==FieldDescriptor.BOOL_TYPE;
+    }
+
+    private String javaType(FieldDescriptor field) {
+        if( field.isInteger32Type() ) {
+            return "int";
+        }
+        if( field.isInteger64Type() ) {
+            return "long";
+        }
+        if( field.getType() == FieldDescriptor.DOUBLE_TYPE ) {
+            return "double";
+        }
+        if( field.getType() == FieldDescriptor.FLOAT_TYPE ) {
+            return "float";
+        }
+        if( field.getType() == FieldDescriptor.STRING_TYPE ) {
+            return "java.lang.String";
+        }
+        if( field.getType() == FieldDescriptor.BYTES_TYPE ) {
+            return "com.google.protobuf.ByteString";
+        }
+        if( field.getType() == FieldDescriptor.BOOL_TYPE ) {
+            return "boolean";
+        }
+        return field.getType();
+    }
+
+    // ----------------------------------------------------------------
+    // Internal Helper methods
+    // ----------------------------------------------------------------
+
+    private void indent() {
+        indent++;
+    }
+
+    private void unindent() {
+        indent--;
+    }
+
+    private void p(String line) {
+        // Indent...
+        for (int i = 0; i < indent; i++) {
+            w.print("   ");
+        }
+        // Then print.
+        w.println(line);
+    }
+
+    private void p() {
+        w.println();
+    }
+
+    private String getOption(ProtoDescriptor proto, String optionName, String defaultValue) {
+        OptionDescriptor optionDescriptor = proto.getOptions().get(optionName);
+        if (optionDescriptor == null) {
+            return defaultValue;
+        }
+        return optionDescriptor.getValue();
+    }
+
+    static private String removeFileExtension(String name) {
+        return name;
+    }
+
+    static private String uCamel(String name) {
+        return name;
+    }
+
+    static private String lCamel(String name) {
+        return name;
+    }
+
+    public File getOutputDirectory() {
+        return outputDirectory;
+    }
+
+    public void setOutputDirectory(File outputDirectory) {
+        this.outputDirectory = outputDirectory;
+    }
+}

Added: activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java (added)
+++ activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MessageDescriptor.java Fri Aug 29 09:53:00 2008
@@ -0,0 +1,93 @@
+/**
+ * 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.List;
+import java.util.Map;
+
+
+public class MessageDescriptor {
+
+    private String name;
+    private ExtensionsDescriptor extensions;
+    private Map<String,FieldDescriptor> fields;
+    private Map<String,MessageDescriptor> messages;
+    private Map<String,EnumDescriptor> enums;
+    private final ProtoDescriptor protoDescriptor;
+    private List<ExtendDescriptor> extendsList;
+
+    public MessageDescriptor(ProtoDescriptor protoDescriptor) {
+        this.protoDescriptor = protoDescriptor;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setExtensions(ExtensionsDescriptor extensions) {
+        this.extensions = extensions;
+    }
+
+    public void setExtends(List<ExtendDescriptor> extendsList) {
+        this.extendsList = extendsList;
+    }
+    public List<ExtendDescriptor> getExtends() {
+        return extendsList;
+    }
+
+    public void setFields(Map<String,FieldDescriptor> fields) {
+        this.fields = fields;
+    }
+
+    public void setMessages(Map<String,MessageDescriptor> messages) {
+        this.messages = messages;
+    }
+
+    public void setEnums(Map<String,EnumDescriptor> enums) {
+        this.enums = enums;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public ExtensionsDescriptor getExtensions() {
+        return extensions;
+    }
+
+    public Map<String,FieldDescriptor> getFields() {
+        return fields;
+    }
+
+    public Map<String,MessageDescriptor> getMessages() {
+        return messages;
+    }
+
+    public Map<String,EnumDescriptor> getEnums() {
+        return enums;
+    }
+
+    public ProtoDescriptor getProtoDescriptor() {
+        return protoDescriptor;
+    }
+
+    public void validate(List<String> errors) {
+        // TODO Auto-generated method stub
+        
+    }
+
+}

Added: activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MethodDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MethodDescriptor.java?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MethodDescriptor.java (added)
+++ activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/MethodDescriptor.java Fri Aug 29 09:53:00 2008
@@ -0,0 +1,58 @@
+/**
+ * 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 class MethodDescriptor {
+
+    private final ProtoDescriptor protoDescriptor;
+    private String name;
+    private String parameter;
+    private String returns;
+
+    public MethodDescriptor(ProtoDescriptor protoDescriptor) {
+        this.protoDescriptor = protoDescriptor;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setParameter(String parameter) {
+        this.parameter = parameter;
+    }
+
+    public void setReturns(String returns) {
+        this.returns = returns;
+    }
+
+    public ProtoDescriptor getProtoDescriptor() {
+        return protoDescriptor;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getParameter() {
+        return parameter;
+    }
+
+    public String getReturns() {
+        return returns;
+    }
+
+}

Added: activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/OptionDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/OptionDescriptor.java?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/OptionDescriptor.java (added)
+++ activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/OptionDescriptor.java Fri Aug 29 09:53:00 2008
@@ -0,0 +1,56 @@
+/**
+ * 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.List;
+
+public class OptionDescriptor {
+
+    private String name;
+    private String value;
+    private final ProtoDescriptor protoDescriptor;
+
+    public OptionDescriptor(ProtoDescriptor protoDescriptor) {
+        this.protoDescriptor = protoDescriptor;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public ProtoDescriptor getProtoDescriptor() {
+        return protoDescriptor;
+    }
+
+    public void validate(List<String> errors) {
+        // TODO Auto-generated method stub
+        
+    }
+
+}

Added: activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ParserSupport.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ParserSupport.java?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ParserSupport.java (added)
+++ activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ParserSupport.java Fri Aug 29 09:53:00 2008
@@ -0,0 +1,54 @@
+/**
+ * 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 class ParserSupport {
+
+    public static String decodeString(String value) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 1; i < value.length() - 1; i++) {
+            char c = value.charAt(i);
+            if (c == '\'') {
+                if( i+1 < (value.length() - 1) ) {
+                    char e = value.charAt(i+1);
+                    switch(e) {
+                    case 'n': 
+                        sb.append("\n");
+                        break;
+                    case 'r':
+                        sb.append("\r");
+                        break;
+                    case 't':
+                        sb.append("\t");
+                        break;
+                    case 'b':
+                        sb.append("\b");
+                        break;
+                    default:
+                        sb.append(e);
+                        break;
+                    }
+                } else {
+                    throw new RuntimeException("Invalid string litteral: "+value);
+                }
+            }
+            sb.append(c);
+        }
+        return sb.toString();
+    }
+
+}

Added: activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoDescriptor.java?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoDescriptor.java (added)
+++ activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoDescriptor.java Fri Aug 29 09:53:00 2008
@@ -0,0 +1,103 @@
+/**
+ * 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.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;
+
+    public void setPackageName(String packageName) {
+        this.packageName = packageName;
+    }
+
+    public void setOptions(Map<String,OptionDescriptor> options) {
+        this.options = options;
+    }
+
+    public void setMessages(Map<String,MessageDescriptor> messages) {
+        this.messages = messages;
+    }
+
+    public void setEnums(Map<String,EnumDescriptor> enums) {
+        this.enums = enums;
+    }
+
+    public void setExtends(List<ExtendDescriptor> extendsList) {
+        this.extendsList = extendsList;
+    }
+
+    public List<ExtendDescriptor> getExtends() {
+        return extendsList;
+    }
+
+    public String getPackageName() {
+        return packageName;
+    }
+
+    public Map<String, OptionDescriptor> getOptions() {
+        return options;
+    }
+
+    public Map<String,MessageDescriptor> getMessages() {
+        return messages;
+    }
+
+    public Map<String,EnumDescriptor> getEnums() {
+        return enums;
+    }
+
+    public void setServices(Map<String,ServiceDescriptor> services) {
+        this.services = services;
+    }
+
+    public Map<String,ServiceDescriptor> getServices() {
+        return services;
+    }
+
+    /**
+     * Checks for validation errors in the proto definition and fills them 
+     * into the errors list.
+     * 
+     * @return
+     */
+    public void validate(List<String> errors) {
+        for (OptionDescriptor o : options.values()) {
+            o.validate(errors);
+        }
+        for (MessageDescriptor o : messages.values()) {
+            o.validate(errors);
+        }
+        for (EnumDescriptor o : enums.values()) {
+            o.validate(errors);
+        }
+        for (ExtendDescriptor o : extendsList) {
+            o.validate(errors);
+        }
+        for (ServiceDescriptor o : services.values()) {
+            o.validate(errors);
+        }
+    }
+
+}

Added: activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ServiceDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ServiceDescriptor.java?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ServiceDescriptor.java (added)
+++ activemq/sandbox/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ServiceDescriptor.java Fri Aug 29 09:53:00 2008
@@ -0,0 +1,54 @@
+/**
+ * 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.List;
+
+public class ServiceDescriptor {
+
+    private final ProtoDescriptor protoDescriptor;
+    private List<MethodDescriptor> methods;
+    private String name;
+
+    public ServiceDescriptor(ProtoDescriptor protoDescriptor) {
+        this.protoDescriptor = protoDescriptor;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setMethods(List<MethodDescriptor> methods) {
+        this.methods = methods;
+    }
+
+    public ProtoDescriptor getProtoDescriptor() {
+        return protoDescriptor;
+    }
+
+    public List<MethodDescriptor> getMethods() {
+        return methods;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void validate(List<String> errors) {
+    }
+
+}

Added: activemq/sandbox/activemq-protobuf/src/main/javacc/proto-parser.jj
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/src/main/javacc/proto-parser.jj?rev=690331&view=auto
==============================================================================
--- activemq/sandbox/activemq-protobuf/src/main/javacc/proto-parser.jj (added)
+++ activemq/sandbox/activemq-protobuf/src/main/javacc/proto-parser.jj Fri Aug 29 09:53:00 2008
@@ -0,0 +1,506 @@
+/**
+ * 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.
+ */
+options {
+STATIC=false;
+}
+
+PARSER_BEGIN(ProtoParser)
+/**
+ * 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.parser;
+
+import org.apache.activemq.protobuf.compiler.*;
+import java.util.LinkedHashMap;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+/**
+ * This class is generated with JavaCC. Do not modify manually.
+ */
+public class ProtoParser {
+}
+
+PARSER_END(ProtoParser)
+
+SKIP :
+{
+  " "
+| "\t"
+| "\n"
+| "\r"
+}
+
+SPECIAL_TOKEN :
+{
+  "//" : COMMENT
+}
+
+<COMMENT> SPECIAL_TOKEN :
+{
+  <("\n" | "\r" | "\r\n" )> : DEFAULT
+}
+
+<COMMENT> MORE :
+{
+  <~[]>
+}
+
+TOKEN :
+{
+    <IMPORT:"import">
+  | <PACKAGE:"package">
+  | <SERVICE:"service">
+  | <RPC:"rpc">
+  | <OPTION:"option">
+  | <MESSAGE:"message">
+  | <EXTENSIONS:"extensions">
+  | <EXTEND:"extend">
+  | <ENUM:"enum">
+  | <GROUP:"group">
+  | <REQURIED:"required">
+  | <OPTIONAL:"optional">
+  | <REPEATED:"repeated">
+  | <RETURNS:"returns">
+  | <TO:"to">
+
+  | <LBRACE: "{">
+  | <RBRACE: "}">
+  | <EQUALS: "=">
+  | <SEMICOLON: ";">
+  | <LBRACKET: "[">
+  | <RBRACKET: "]">
+  | <LPAREN: "(">
+  | <RPAREN: ")">
+  | <PERIOD: ".">
+  | <COMMA: ",">
+  
+  | <NUMBER: (["0"-"9"])+>
+  | <STRING: "\"" ( ~["\""] )+ "\"">
+  | <ID: ["A"-"Z","a"-"z"] (["a"-"z","A"-"Z","0"-"9","_"])*>
+}
+
+ProtoDescriptor ProtoDescriptor() :
+{
+  	ProtoDescriptor proto = new ProtoDescriptor();
+	String packageName=null;
+    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>();
+    LinkedHashMap<String,ServiceDescriptor> services = new LinkedHashMap<String,ServiceDescriptor>();
+    ArrayList<String> imports = new ArrayList<String>();
+    
+    OptionDescriptor optionD;
+    MessageDescriptor messageD;
+    EnumDescriptor enumD;
+    ServiceDescriptor serviceD;
+    ExtendDescriptor extendD;
+    String o;
+}
+{
+	(
+		<PACKAGE> packageName=PackageID() <SEMICOLON>
+	)?
+    (
+        <OPTION> optionD = OptionDescriptor(proto) <SEMICOLON>
+        { opts.put(optionD.getName(),optionD); }
+    |   
+        <IMPORT> 
+        o = StringLitteral()
+        <SEMICOLON>
+        { imports.add((String)o); }
+    |   
+        messageD = MessageDescriptor(proto) (<SEMICOLON>)?
+        { messages.put(messageD.getName(),messageD); }
+        
+    |   
+        enumD = EnumDescriptor(proto) (<SEMICOLON>)?
+        { enums.put(enumD.getName(),enumD); }
+    |   
+        serviceD = ServiceDescriptor(proto) (<SEMICOLON>)?
+        { services.put(serviceD.getName(),serviceD); }
+    |   
+        extendD = ExtendDescriptor(proto) (<SEMICOLON>)?
+        { extendsList.add(extendD); }
+    )+
+    <EOF>
+    { 
+    	proto.setPackageName(packageName);
+    	proto.setOptions(opts);
+    	proto.setMessages(messages);
+    	proto.setEnums(enums);
+    	proto.setServices(services);
+    	proto.setExtends(extendsList);
+    	return proto; 
+    }
+}
+
+ServiceDescriptor ServiceDescriptor(ProtoDescriptor proto) :
+{
+    String name;
+    ArrayList<MethodDescriptor> methods = new ArrayList<MethodDescriptor>();
+    MethodDescriptor method;
+}
+{
+    <SERVICE> name = ID() <LBRACE>
+    (
+    	method = MethodDescriptor(proto) <SEMICOLON>
+    	{
+    		methods.add(method);
+    	}
+    )*
+    <RBRACE> 
+    {
+    	ServiceDescriptor rc = new ServiceDescriptor(proto);
+    	rc.setName(name);
+    	rc.setMethods(methods);
+    	return rc;
+    }
+}
+
+MethodDescriptor MethodDescriptor(ProtoDescriptor proto) :
+{
+    String name;
+    String input;
+    String output;
+}
+{
+    <RPC> name = ID() <LPAREN> input = PackageID() <RPAREN> <RETURNS> <LPAREN> output = PackageID() <RPAREN>    
+    {
+    	MethodDescriptor rc = new MethodDescriptor(proto);
+    	rc.setName(name);
+    	rc.setParameter(input);
+    	rc.setReturns(output);
+    	return rc;
+    }
+}
+
+OptionDescriptor OptionDescriptor(ProtoDescriptor proto) :
+{
+    String name;
+    String value;
+}
+{
+    name = ID() 
+    <EQUALS> 
+    value=Value() 
+    {
+    	OptionDescriptor rc = new OptionDescriptor(proto);
+    	rc.setName(name);
+    	rc.setValue(value);
+    	return rc;
+    }
+}
+
+ExtendDescriptor ExtendDescriptor(ProtoDescriptor proto) :
+{
+    String name;
+    LinkedHashMap<String, FieldDescriptor> fields = new LinkedHashMap<String,FieldDescriptor>();
+    FieldDescriptor fieldD;
+}
+{
+    <EXTEND> name = ID() <LBRACE>
+    (
+    	fieldD = FieldDescriptor(proto)
+    	{ fields.put(fieldD.getName(), fieldD); }
+    )*
+    <RBRACE>
+    {
+    	ExtendDescriptor rc = new ExtendDescriptor(proto);
+    	rc.setName(name);
+    	rc.setFields(fields);
+    	return rc;
+    }
+}
+
+MessageDescriptor MessageDescriptor(ProtoDescriptor proto) :
+{
+    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>();
+
+    ExtensionsDescriptor extensionsD=null;
+	FieldDescriptor fieldD;
+	MessageDescriptor messageD;
+	EnumDescriptor enumD;
+	ExtendDescriptor extendD;
+}
+{
+    <MESSAGE> name = ID() <LBRACE>
+    (
+    	fieldD = FieldDescriptor(proto) <SEMICOLON>
+    	{ fields.put(fieldD.getName(), fieldD); }
+    |   
+        messageD = MessageDescriptor(proto) (<SEMICOLON>)?
+        { messages.put(messageD.getName(),messageD); }
+    |   
+        enumD = EnumDescriptor(proto) (<SEMICOLON>)?
+        { enums.put(enumD.getName(), enumD); }
+    |   
+        extensionsD = ExtensionsDescriptor(proto) <SEMICOLON>
+    |   
+        extendD = ExtendDescriptor(proto) (<SEMICOLON>)?
+        { extendsList.add(extendD); }
+    )*
+    <RBRACE>
+    {
+    	MessageDescriptor rc = new MessageDescriptor(proto);
+    	rc.setName(name);
+    	rc.setFields(fields);
+    	rc.setMessages(messages);
+    	rc.setEnums(enums);
+    	rc.setExtensions(extensionsD);
+    	return rc;
+    }
+}
+
+ExtensionsDescriptor ExtensionsDescriptor(ProtoDescriptor proto) :
+{
+	int first;
+	int last;
+}
+{
+    <EXTENSIONS> 
+    first = Integer() 
+    <TO> 
+    last = Integer() 
+    {
+    	ExtensionsDescriptor rc = new ExtensionsDescriptor(proto);
+    	rc.setFirst(first);
+    	rc.setLast(last);
+    	return rc;
+    }
+}
+
+EnumDescriptor EnumDescriptor(ProtoDescriptor proto) :
+{
+    Token name;
+    LinkedHashMap<String,EnumFieldDescriptor> fields = new LinkedHashMap<String,EnumFieldDescriptor>();
+    EnumFieldDescriptor enumD;
+}
+{
+    <ENUM> name = <ID> <LBRACE>
+    (
+    	enumD = EnumFieldDescriptor(proto) <SEMICOLON>
+    	{
+    		fields.put(enumD.getName(),enumD);
+    	}
+    )*
+    <RBRACE>
+    {
+    	EnumDescriptor rc = new EnumDescriptor(proto);
+    	rc.setName(name.image);
+    	rc.setFields(fields);
+    	return rc;
+    }
+}
+
+/**
+ * Parses something like:
+ * optional string foo = 1;
+ */
+EnumFieldDescriptor EnumFieldDescriptor(ProtoDescriptor proto) :
+{
+    String name;
+    int value=0;
+}
+{
+
+    name = ID()
+    <EQUALS>
+    value = Integer()
+    {
+    	EnumFieldDescriptor rc = new EnumFieldDescriptor(proto);
+    	rc.setName(name);
+    	rc.setValue(value);
+    	return rc;
+    }
+}
+
+/**
+ * Parses something like:
+ * optional string foo = 1;
+ */
+FieldDescriptor FieldDescriptor(ProtoDescriptor proto) :
+{
+    String rule;
+    String type;
+    String name;
+    int tag;
+    LinkedHashMap<String,OptionDescriptor> opts = new LinkedHashMap<String,OptionDescriptor>();
+    OptionDescriptor optionD;
+}
+{
+
+    rule = Rule()
+    type = PackageID()
+    name = ID()
+    <EQUALS>
+    tag = Integer()
+    (
+    	<LBRACKET>
+    	optionD = OptionDescriptor(proto)
+    	{
+    		opts.put(optionD.getName(), optionD);
+    	}
+    	(
+    		<COMMA>
+	    	optionD = OptionDescriptor(proto)
+	    	{
+    			opts.put(optionD.getName(), optionD);
+    		}
+    	)*
+    	<RBRACKET>
+    )?    
+    {
+    	FieldDescriptor rc = new FieldDescriptor(proto);
+    	rc.setName(name);
+    	rc.setType(type);
+    	rc.setRule(rule);
+    	rc.setTag(tag);
+    	rc.setOptions(opts);
+    	return rc;
+    }
+}
+
+int Integer() :
+{
+    Token t;
+}
+{
+  	t = <NUMBER>
+    {
+    	return Integer.parseInt(t.image);
+    }
+}
+
+
+String Rule() :
+{
+    Token t;
+}
+{
+    (
+    	t = <REQURIED>
+    	|
+    	t = <OPTIONAL>
+    	|
+    	t = <REPEATED>
+    )
+    {
+    	return t.image;
+    }
+}
+
+String Value() :
+{
+    String value=null;
+}
+{
+    (
+    	value = StringLitteral()
+    	|
+  		value = ID()
+    )
+    {
+    	return value;
+    }
+}
+
+String ID() :
+{
+    Token t;
+}
+{
+    (
+          t = <ID>
+        | t = <IMPORT>
+        | t = <PACKAGE>
+        | t = <SERVICE>
+        | t = <RPC>
+        | t = <OPTION>
+        | t = <MESSAGE>
+        | t = <EXTENSIONS>
+        | t = <EXTEND>
+        | t = <ENUM>
+        | t = <GROUP>
+        | t = <REQURIED>
+        | t = <OPTIONAL>
+        | t = <REPEATED>
+        | t = <RETURNS>
+        | t = <TO>
+    )
+    {
+    	return t.image;
+    }
+}
+
+String PackageID() :
+{
+    String t;
+    StringBuffer sb = new StringBuffer();
+}
+{
+    t = ID()
+    {
+    	sb.append(t);
+    }
+    (
+    	<PERIOD>
+    	t=ID()
+    	{
+    		sb.append(".");
+    		sb.append(t);
+    	}
+    )* 
+    {
+	    return sb.toString();
+    }    
+}
+
+
+String StringLitteral() :
+{
+    Token t;
+}
+{
+    t = <STRING> 
+    {
+	    return ParserSupport.decodeString(t.image);
+    }    
+}



Mime
View raw message