You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2007/04/07 18:01:46 UTC

svn commit: r526446 [6/6] - in /incubator/qpid/trunk/qpid/gentools: src/org/apache/qpid/gentools/ templ.cpp/ templ.cpp/class/ templ.cpp/field/ templ.cpp/method/ templ.cpp/model/ templ.java/ templ.java/class/ templ.java/field/ templ.java/method/ templ.j...

Modified: incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/LanguageConverter.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/LanguageConverter.java?view=diff&rev=526446&r1=526445&r2=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/LanguageConverter.java (original)
+++ incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/LanguageConverter.java Sat Apr  7 09:01:43 2007
@@ -22,18 +22,21 @@
 
 public interface LanguageConverter
 {
-	public void setDomainMap(AmqpDomainMap domainMap);
-	public AmqpDomainMap getDomainMap();
 
-    public void setConstantSet(AmqpConstantSet constantSet);
-    public AmqpConstantSet getConstantSet();
-	
-	public void setModel(AmqpModel model);
-	public AmqpModel getModel();
-	
-	public String prepareClassName(String className);
-	public String prepareMethodName(String methodName);
-	public String prepareDomainName(String domainName);
-	public String getDomainType(String domainName, AmqpVersion version) throws AmqpTypeMappingException;
-	public String getGeneratedType(String domainName, AmqpVersion version) throws AmqpTypeMappingException;
+//	public AmqpDomainMap getDomainMap();
+//    public AmqpConstantSet getConstantSet();
+//	public AmqpModel getModel();
+
+    //
+    public String prepareClassName(String className);
+
+    public String prepareMethodName(String methodName);
+
+    public String prepareDomainName(String domainName);
+
+    public String getDomainType(String domainName, AmqpVersion version);
+
+    public String getGeneratedType(String domainName, AmqpVersion version);
+
+    public String prepareConstantName(String constantName);
 }

Modified: incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/Main.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/Main.java?view=diff&rev=526446&r1=526445&r2=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/Main.java (original)
+++ incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/Main.java Sat Apr  7 09:01:43 2007
@@ -20,143 +20,149 @@
  */
 package org.apache.qpid.gentools;
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
+import org.apache.velocity.app.Velocity;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Properties;
 
 public class Main
 {
-    private static final String defaultOutDir = ".." + Utils.fileSeparator + "gen";
-    private static final String defaultCppTemplateDir = ".." + Utils.fileSeparator + "templ.cpp";
-    private static final String defaultDotnetTemplateDir = ".." + Utils.fileSeparator + "templ.net";
-    private static final String defaultJavaTemplateDir = ".." + Utils.fileSeparator + "templ.java";
-    
-    private enum GeneratorLangEnum { CPP, DOTNET, JAVA }
-    
-	private DocumentBuilder docBuilder;
-	private AmqpVersionSet versionSet;
-	private Generator generator;
-    private AmqpConstantSet constants;
-	private AmqpDomainMap domainMap;
-	private AmqpModel model;
-    
+    private static final String DEFAULT_OUTPUT_DIR = ".." + Utils.FILE_SEPARATOR + "gen";
+    private static final String DEFAULT_TEMPLATE_DIR_BASE = ".." + Utils.FILE_SEPARATOR;
+
+    private enum GeneratedLanguage
+    {
+        CPP(".cpp", CppGenerator.getFactory()),
+        DOTNET(".net", DotnetGenerator.getFactory()),
+        JAVA(".java", JavaGenerator.getFactory());
+
+        private final String _suffix;
+        private final Generator.Factory _factory;
+
+
+        private final String _defaultTemplateDirectory;
+
+        GeneratedLanguage(String suffix, Generator.Factory factory)
+        {
+            _suffix = suffix;
+            _factory = factory;
+            _defaultTemplateDirectory = DEFAULT_TEMPLATE_DIR_BASE + "templ" + _suffix;
+        }
+
+        public String getSuffix()
+        {
+            return _suffix;
+        }
+
+        public Generator newGenerator()
+        {
+            return _factory.newInstance();
+        }
+
+        public String getDefaultTemplateDirectory()
+        {
+            return _defaultTemplateDirectory;
+        }
+    }
+
+    private Generator generator;
+
     private String outDir;
     private String tmplDir;
-    private GeneratorLangEnum generatorLang;
+    private GeneratedLanguage _generatorLang;
     private ArrayList<String> xmlFiles;
-    private File[] modelTemplateFiles;
-    private File[] classTemplateFiles;
-    private File[] methodTemplateFiles;
-    private File[] fieldTemplateFiles;
-	
-	public Main() throws ParserConfigurationException
-	{
-		docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
-		versionSet = new AmqpVersionSet();
+
+    public Main()
+    {
         xmlFiles = new ArrayList<String>();
-	}
-	
-	public void run(String[] args)
-		throws 	IOException,
-				SAXException,
-				AmqpParseException,
-				AmqpTypeMappingException,
-				AmqpTemplateException,
-				TargetDirectoryException,
-				IllegalAccessException,
-		    	InvocationTargetException
-	{
-		modelTemplateFiles = new File[]{};
-		classTemplateFiles = new File[]{};
-		methodTemplateFiles = new File[]{};
-		fieldTemplateFiles = new File[]{};
-        
+    }
+
+    public void run(String[] args)
+            throws Exception,
+                   SAXException,
+                   AmqpParseException,
+                   AmqpTypeMappingException,
+                   AmqpTemplateException,
+                   TargetDirectoryException,
+                   IllegalAccessException,
+                   InvocationTargetException, ParserConfigurationException
+    {
+
         // 0. Initialize
-        outDir = defaultOutDir;
+        outDir = DEFAULT_OUTPUT_DIR;
         tmplDir = null;
-        generatorLang = GeneratorLangEnum.CPP; // Default generation language
+        _generatorLang = GeneratedLanguage.CPP; // Default generation language
         xmlFiles.clear();
         processArgs(args);
-        switch (generatorLang)
+
+        if (tmplDir == null)
         {
-        case JAVA:
-        	prepareJava();
-        	break;
-        case DOTNET:
-        	prepareDotnet();
-        	break;
-        default:
-            prepareCpp();
+            tmplDir = _generatorLang.getDefaultTemplateDirectory();
         }
 
-		if (modelTemplateFiles.length == 0 && classTemplateFiles.length == 0 &&
-			methodTemplateFiles.length == 0 && fieldTemplateFiles.length == 0)
-			System.err.println("  WARNING: No template files.");
-		
-		// 1. Suck in all the XML spec files provided on the command line
+
+        generator = _generatorLang.newGenerator();
+        generator.setTemplateDirectory(tmplDir);
+        generator.setOutputDirectory(outDir);
+
+        // 1. Suck in all the XML spec files provided on the command line
         analyzeXML();
-		
-		// 2. Load up all templates
-        try
-        {
-		generator.initializeTemplates(modelTemplateFiles, classTemplateFiles,
-			methodTemplateFiles, fieldTemplateFiles);
-        }
-        catch (FileNotFoundException e)
-        {
-        	System.err.println("Error: Unable to load template file (check -t option on command-line):");
-        	System.err.println(e.getMessage());
-        	return;
-        }
-		
-		// 3. Generate output
-		generator.generate(new File(outDir));
-		
-		System.out.println("Files generated: " + generator.getNumberGeneratedFiles());
-		System.out.println("Done.");
-	}
+
+        Properties p = new Properties();
+        p.setProperty("file.resource.loader.path", tmplDir);
+
+        Velocity.init(p);
+
+        // 2. Load up all templates
+        generator.initializeTemplates();
+
+        // 3. Generate output
+        generator.generate();
+
+        System.out.println("Files generated: " + generator.getNumberGeneratedFiles());
+        System.out.println("Done.");
+    }
 
     private void processArgs(String[] args)
     {
         // Crude but simple...
-        for (int i=0; i<args.length; i++)
+        for (int i = 0; i < args.length; i++)
         {
             String arg = args[i];
             if (arg.charAt(0) == '-')
             {
                 switch (arg.charAt(1))
                 {
-                    case 'c':
-                    case 'C':
-                    	generatorLang = GeneratorLangEnum.CPP;
+                    case'c':
+                    case'C':
+                        _generatorLang = GeneratedLanguage.CPP;
                         break;
-                    case 'j':
-                    case 'J':
-                    	generatorLang = GeneratorLangEnum.JAVA;
+                    case'j':
+                    case'J':
+                        _generatorLang = GeneratedLanguage.JAVA;
                         break;
-                    case 'n':
-                    case 'N':
-                    	generatorLang = GeneratorLangEnum.DOTNET;
+                    case'n':
+                    case'N':
+                        _generatorLang = GeneratedLanguage.DOTNET;
                         break;
-                    case 'o':
-                    case 'O':
+                    case'o':
+                    case'O':
                         if (++i < args.length)
                         {
                             outDir = args[i];
                         }
-                       break;
-                    case 't':
-                    case 'T':
+                        break;
+                    case't':
+                    case'T':
                         if (++i < args.length)
                         {
                             tmplDir = args[i];
@@ -170,87 +176,12 @@
             }
         }
     }
-    
-    private void prepareJava()
-    {
-        if (tmplDir == null)
-            tmplDir = defaultJavaTemplateDir;
-        System.out.println("Java generation mode.");
-        generator = new JavaGenerator(versionSet);
-        constants = new AmqpConstantSet(generator);
-        domainMap = new AmqpDomainMap(generator);
-        model = new AmqpModel(generator);       
-        modelTemplateFiles = new File[]
-        {
-            new File(tmplDir + Utils.fileSeparator + "MethodRegistryClass.tmpl"),
-            new File(tmplDir + Utils.fileSeparator + "AmqpConstantsClass.tmpl"),
-            new File(tmplDir + Utils.fileSeparator + "ProtocolVersionListClass.tmpl")
-        };
-        classTemplateFiles = new File[]
-        {
-//            new File(tmplDir + Utils.fileSeparator + "PropertyContentHeaderClass.tmpl")
-        };
-        methodTemplateFiles = new File[]
-        {
-            new File(tmplDir + Utils.fileSeparator + "MethodBodyClass.tmpl")
-        };
-    }
-    
-    private void prepareDotnet()
-    {
-        if (tmplDir == null)
-            tmplDir = defaultDotnetTemplateDir;
-        System.out.println(".NET generation mode.");
-        generator = new DotnetGenerator(versionSet);
-        constants = new AmqpConstantSet(generator);
-        domainMap = new AmqpDomainMap(generator);
-        model = new AmqpModel(generator);       
-    	// TODO: Add templated that should be handled in here...
-       modelTemplateFiles = new File[]
-        {
-//          new File(tmplDir + Utils.fileSeparator + "XXXClass.tmpl"),
-        };
-        classTemplateFiles = new File[]
-        {
-//          new File(tmplDir + Utils.fileSeparator + "XXXClass.tmpl"),
-        };
-        methodTemplateFiles = new File[]
-        {
-//          new File(tmplDir + Utils.fileSeparator + "XXXClass.tmpl"),
-        };
-   }
-   
-    private void prepareCpp()
-    {
-        if (tmplDir == null)
-            tmplDir = defaultCppTemplateDir;
-        System.out.println("C++ generation mode.");
-        generator = new CppGenerator(versionSet);
-        constants = new AmqpConstantSet(generator);
-        domainMap = new AmqpDomainMap(generator);
-        model = new AmqpModel(generator);           
-        modelTemplateFiles = new File[]
-        {
-            new File(tmplDir + Utils.fileSeparator + "AMQP_ServerOperations.h.tmpl"),
-            new File(tmplDir + Utils.fileSeparator + "AMQP_ClientOperations.h.tmpl"),
-            new File(tmplDir + Utils.fileSeparator + "AMQP_ServerProxy.h.tmpl"),
-            new File(tmplDir + Utils.fileSeparator + "AMQP_ClientProxy.h.tmpl"),
-            new File(tmplDir + Utils.fileSeparator + "AMQP_ServerProxy.cpp.tmpl"),
-            new File(tmplDir + Utils.fileSeparator + "AMQP_ClientProxy.cpp.tmpl"),
-            new File(tmplDir + Utils.fileSeparator + "AMQP_Constants.h.tmpl"),
-            new File(tmplDir + Utils.fileSeparator + "AMQP_MethodVersionMap.h.tmpl"),
-            new File(tmplDir + Utils.fileSeparator + "AMQP_MethodVersionMap.cpp.tmpl"),
-            new File(tmplDir + Utils.fileSeparator + "AMQP_HighestVersion.h.tmpl")
-        };
-        methodTemplateFiles = new File[]
-        {
-            new File(tmplDir + Utils.fileSeparator + "MethodBodyClass.h.tmpl")
-        };        
-    }
 
     private void analyzeXML()
-        throws IOException, SAXException, AmqpParseException, AmqpTypeMappingException
+            throws IOException, SAXException, AmqpParseException, AmqpTypeMappingException, ParserConfigurationException
     {
+        DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+
         System.out.println("XML files: " + xmlFiles);
         for (String filename : xmlFiles)
         {
@@ -261,25 +192,21 @@
                 System.out.print("  \"" + filename + "\":");
                 Document doc = docBuilder.parse(new File(filename));
                 Node amqpNode = Utils.findChild(doc, Utils.ELEMENT_AMQP);
-                
+
                 // 1b. Extract version (major and minor) from the XML file
                 int major = Utils.getNamedIntegerAttribute(amqpNode, Utils.ATTRIBUTE_MAJOR);
                 int minor = Utils.getNamedIntegerAttribute(amqpNode, Utils.ATTRIBUTE_MINOR);
                 AmqpVersion version = new AmqpVersion(major, minor);
                 System.out.println(" Found version " + version.toString() + ".");
-                versionSet.add(version);
-                
-                // 1c. Extract domains
-                constants.addFromNode(amqpNode, 0, version);
-                
-                // 1d. Extract domains
-                domainMap.addFromNode(amqpNode, 0, version);
-                
-                // 1e. Extract class/method/field heirarchy
-                model.addFromNode(amqpNode, 0, version);
+                generator.addVersion(version);
+                generator.addFromNode(amqpNode, version);
+
+
             }
             else
+            {
                 System.err.println("ERROR: AMQP XML file \"" + filename + "\" not found.");
+            }
         }
 // *** DEBUG INFO ***  Uncomment bits from this block to see lots of stuff....
 //      System.out.println();
@@ -296,58 +223,79 @@
 //      System.out.println("*** End debug output ***");
 //      System.out.println();        
     }
-    
-	public static void main(String[] args)
-	{
-		int exitCode = 1;
-		// TODO: This is a simple and klunky way of hangling command-line args, and could be improved upon.
-		if (args.length < 2)
-		{
-			usage();
-		}
-		else
-		{
-			try
-			{
-				new Main().run(args);
-				exitCode = 0;
-			}
-			catch (IOException e) { e.printStackTrace(); }
-			catch (ParserConfigurationException e) { e.printStackTrace(); }
-			catch (SAXException e) { e.printStackTrace(); }
-			catch (AmqpParseException e) { e.printStackTrace(); }
-			catch (AmqpTypeMappingException e) { e.printStackTrace(); }
-			catch (AmqpTemplateException e) { e.printStackTrace(); }
-			catch (TargetDirectoryException e) { e.printStackTrace(); }
-			catch (IllegalAccessException e) { e.printStackTrace(); }
-			catch (InvocationTargetException e) { e.printStackTrace(); }
-		}
-		System.exit(exitCode);
-	}
-
-	public static void usage()
-	{
-		System.out.println("AMQP XML generator v.0.0");
-		System.out.println("Usage: Main -c|-j [-o outDir] [-t tmplDir] XMLfile [XMLfile ...]");
-		System.out.println("       where -c:         Generate C++.");
-		System.out.println("             -j:         Generate Java.");
-		System.out.println("             -n:         Generate .NET.");
-        System.out.println("             -o outDir:  Use outDir as the output dir (default=\"" + defaultOutDir + "\").");
+
+    public static void main(String[] args)
+    {
+        int exitCode = 1;
+        // TODO: This is a simple and klunky way of hangling command-line args, and could be improved upon.
+        if (args.length < 2)
+        {
+            usage();
+        }
+        else
+        {
+            try
+            {
+                new Main().run(args);
+                exitCode = 0;
+            }
+            catch (IOException e)
+            {
+                e.printStackTrace();
+            }
+            catch (ParserConfigurationException e)
+            {
+                e.printStackTrace();
+            }
+            catch (SAXException e)
+            {
+                e.printStackTrace();
+            }
+            catch (AmqpParseException e)
+            {
+                e.printStackTrace();
+            }
+            catch (AmqpTypeMappingException e)
+            {
+                e.printStackTrace();
+            }
+            catch (AmqpTemplateException e)
+            {
+                e.printStackTrace();
+            }
+            catch (TargetDirectoryException e)
+            {
+                e.printStackTrace();
+            }
+            catch (IllegalAccessException e)
+            {
+                e.printStackTrace();
+            }
+            catch (InvocationTargetException e)
+            {
+                e.printStackTrace();
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+        }
+        System.exit(exitCode);
+    }
+
+    public static void usage()
+    {
+        System.out.println("AMQP XML generator v.0.0");
+        System.out.println("Usage: Main -c|-j [-o outDir] [-t tmplDir] XMLfile [XMLfile ...]");
+        System.out.println("       where -c:         Generate C++.");
+        System.out.println("             -j:         Generate Java.");
+        System.out.println("             -n:         Generate .NET.");
+        System.out.println("             -o outDir:  Use outDir as the output dir (default=\"" + DEFAULT_OUTPUT_DIR + "\").");
         System.out.println("             -t tmplDir: Find templates in tmplDir.");
-        System.out.println("                         Defaults: \"" + defaultCppTemplateDir + "\" for C++;");
-        System.out.println("                                   \"" + defaultJavaTemplateDir + "\" for java.");
-		System.out.println("             XMLfile is a space-separated list of AMQP XML files to be parsed.");
-	}
-	
-	public static String ListTemplateList(File[] list)
-	{
-		StringBuffer sb = new StringBuffer();
-		for (int i=0; i<list.length; i++)
-		{
-			if (i != 0)
-				sb.append(", ");
-			sb.append(list[i].getName());
-		}
-		return sb.toString();
-	}
+        System.out.println("                         Defaults: \"" + GeneratedLanguage.CPP.getDefaultTemplateDirectory() + "\" for C++;");
+        System.out.println("                                   \"" + GeneratedLanguage.JAVA.getDefaultTemplateDirectory() + "\" for java.;");
+        System.out.println("                                   \"" + GeneratedLanguage.DOTNET.getDefaultTemplateDirectory() + "\" for .NET.");
+        System.out.println("             XMLfile is a space-separated list of AMQP XML files to be parsed.");
+    }
+
 }

Added: incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java?view=auto&rev=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java (added)
+++ incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java Sat Apr  7 09:01:43 2007
@@ -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.qpid.gentools;
+
+public interface MangledGenerateMethod
+{
+    String generate(AmqpField field, int indentSize, int tabSize, boolean notLast);
+}

Modified: incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/NodeAware.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/NodeAware.java?view=diff&rev=526446&r1=526445&r2=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/NodeAware.java (original)
+++ incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/NodeAware.java Sat Apr  7 09:01:43 2007
@@ -24,23 +24,24 @@
 
 /**
  * @author kpvdr
- * Interface allowing the addition of elements from a node in the
- * DOM of the AMQP specification. It is used by each of the model
- * elements in a recursive fashion to build the model.
+ *         Interface allowing the addition of elements from a node in the
+ *         DOM of the AMQP specification. It is used by each of the model
+ *         elements in a recursive fashion to build the model.
  */
 public interface NodeAware
 {
-	/**
-	 * Add a model element from the current DOM node. All model elements must implement
-	 * this interface. If the node contains children that are also a part of the model,
-	 * then this method is called on new instances of those model elements.
-	 * @param n Node from which the current model element is to be added.
-	 * @param o Ordinal value of the current model elemet.
-	 * @param v Verion of the DOM from which the node comes.
-	 * @throws AmqpParseException
-	 * @throws AmqpTypeMappingException
-	 * @returns true if a node was added, false if not
-	 */
-	public boolean addFromNode(Node n, int o, AmqpVersion v)
-		throws AmqpParseException, AmqpTypeMappingException;
+    /**
+     * Add a model element from the current DOM node. All model elements must implement
+     * this interface. If the node contains children that are also a part of the model,
+     * then this method is called on new instances of those model elements.
+     *
+     * @param n Node from which the current model element is to be added.
+     * @param o Ordinal value of the current model elemet.
+     * @param v Verion of the DOM from which the node comes.
+     * @throws AmqpParseException
+     * @throws AmqpTypeMappingException
+     * @returns true if a node was added, false if not
+     */
+    public boolean addFromNode(Node n, int o, AmqpVersion v)
+            throws AmqpParseException, AmqpTypeMappingException;
 }

Modified: incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/Printable.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/Printable.java?view=diff&rev=526446&r1=526445&r2=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/Printable.java (original)
+++ incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/Printable.java Sat Apr  7 09:01:43 2007
@@ -24,5 +24,5 @@
 
 public interface Printable
 {
-	public void print(PrintStream out, int marginSize, int tabSize);
+    public void print(PrintStream out, int marginSize, int tabSize);
 }

Added: incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java?view=auto&rev=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java (added)
+++ incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java Sat Apr  7 09:01:43 2007
@@ -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.qpid.gentools;
+
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Map.Entry;
+
+
+public class SingleVersionClass
+{
+    private final int _classId;
+
+
+    private final AmqpClass _amqpClass;
+    private final AmqpVersion _amqpVersion;
+    private final Generator _generator;
+    private final List<SingleVersionMethod> _methodList = new ArrayList<SingleVersionMethod>();
+
+    public SingleVersionClass(AmqpClass amqpClass, AmqpVersion amqpVersion, Generator generator)
+    {
+        _amqpClass = amqpClass;
+        _amqpVersion = amqpVersion;
+        _generator = generator;
+
+        AmqpOrdinalVersionMap indexMap = amqpClass.getIndexMap();
+        int classId = 0;
+        for(Entry<Integer, AmqpVersionSet> entry : indexMap.entrySet())
+        {
+            if(entry.getValue().contains(_amqpVersion))
+            {
+                classId = entry.getKey();
+                break;
+            }
+        }
+        _classId = classId;
+
+
+        Collection<AmqpMethod> methods = _amqpClass.getMethodMap().values();
+
+        for(AmqpMethod amqpMethod : methods)
+        {
+            _methodList.add(new SingleVersionMethod(amqpMethod, _amqpVersion, _generator));
+
+        }
+
+        Collections.sort(_methodList, new Comparator<SingleVersionMethod>(){
+            public int compare(SingleVersionMethod method1, SingleVersionMethod method2)
+            {
+                return method1.getMethodId() - method2.getMethodId();
+            }
+        });
+
+
+    }
+
+    public int getClassId()
+    {
+        return _classId;
+    }
+
+    public String getName()
+    {
+        return _amqpClass.getName();
+    }
+
+    
+
+
+
+    public List<SingleVersionMethod> getMethodList()
+    {
+        return _methodList;
+    }
+
+
+    public int getMaximumMethodId()
+    {
+        return _methodList.get(_methodList.size()-1).getMethodId();
+    }
+}

Added: incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionField.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionField.java?view=auto&rev=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionField.java (added)
+++ incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionField.java Sat Apr  7 09:01:43 2007
@@ -0,0 +1,68 @@
+/*
+ *
+ * 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.qpid.gentools;
+
+
+public class SingleVersionField
+{
+    private final AmqpField _field;
+    private final AmqpVersion _amqpVersion;
+    private final Generator _generator;
+
+    public SingleVersionField(AmqpField field, AmqpVersion amqpVersion, Generator generator)
+    {
+        _field = field;
+        _amqpVersion = amqpVersion;
+        _generator = generator;
+    }
+
+    public String getName()
+    {
+        return _field.getName();
+    }
+
+    public String getDomain()
+    {
+        return _field.getDomain(_amqpVersion);
+    }
+
+
+    public String getDomainType()
+    {
+        return _generator.getDomainType(_field.getDomain(_amqpVersion),_amqpVersion);
+    }
+
+    public String getNativeType()
+    {
+        return _generator.getNativeType(getDomainType());
+    }
+
+    public String getEncodingType()
+    {
+        return _generator.getEncodingType(getDomainType());
+    }
+
+
+    public int getPosition()
+    {
+        return _field.getOrdinal(_amqpVersion);
+    }
+}

Added: incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java?view=auto&rev=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java (added)
+++ incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java Sat Apr  7 09:01:43 2007
@@ -0,0 +1,144 @@
+/*
+ *
+ * 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.qpid.gentools;
+
+import java.util.Map.Entry;
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+public class SingleVersionMethod
+{
+    private final AmqpMethod _amqpMethod;
+    private final AmqpVersion _amqpVersion;
+    private final int _methodId;
+    private final List<SingleVersionField> _fieldList = new ArrayList<SingleVersionField>();
+    private final Generator _generator;
+    private final List<ConsolidatedField> _consolidatedFields = new ArrayList<ConsolidatedField>();
+    private final Map<String, ConsolidatedField> _fieldNameToConsolidatedFieldMap = new HashMap<String, ConsolidatedField>();
+
+
+    public SingleVersionMethod(AmqpMethod amqpMethod, AmqpVersion amqpVersion, Generator generator)
+    {
+        _amqpMethod = amqpMethod;
+        _amqpVersion = amqpVersion;
+        _generator = generator;
+
+        AmqpOrdinalVersionMap indexMap = amqpMethod.getIndexMap();
+        int methodId = 0;
+        for(Entry<Integer, AmqpVersionSet> entry : indexMap.entrySet())
+        {
+            if(entry.getValue().contains(_amqpVersion))
+            {
+                methodId = entry.getKey();
+                break;
+            }
+        }
+        _methodId = methodId;
+
+        Collection<AmqpField> fields = _amqpMethod.getFieldMap().values();
+
+        for(AmqpField field : fields)
+        {
+            _fieldList.add(new SingleVersionField(field, _amqpVersion, _generator));
+
+        }
+
+        Collections.sort(_fieldList, new Comparator<SingleVersionField>(){
+            public int compare(SingleVersionField field1, SingleVersionField field2)
+            {
+                return field1.getPosition() - field2.getPosition();
+            }
+        });
+
+
+
+        ConsolidatedField lastField = null;
+        int bitfieldNum = 0;
+        for(SingleVersionField field : _fieldList)
+        {
+            String domainType = field.getDomainType();
+            if(!domainType.equals("bit"))
+            {
+                lastField = new ConsolidatedField(_generator,
+                                                  field.getName(),
+                                                  field.getDomainType());
+                _consolidatedFields.add(lastField);
+            }
+            else if(lastField == null || !lastField.getType().equals("bitfield"))
+            {
+                lastField = new ConsolidatedField(_generator,
+                                                  domainType.equals("bit") ? "bitfield"+bitfieldNum++ : field.getName(),
+                                                  domainType.equals("bit") ? "bitfield" : field.getDomainType(),
+                                                  field.getName());
+                _consolidatedFields.add(lastField);
+            }
+            else
+            {
+                lastField.add(field.getName());
+            }
+            _fieldNameToConsolidatedFieldMap.put(field.getName(), lastField);
+
+        }
+    }
+
+    public int getMethodId()
+    {
+        return _methodId;
+    }
+
+    public String getName()
+    {
+        return _amqpMethod.getName();
+    }
+
+    public Collection<SingleVersionField> getFieldList()
+    {
+        return Collections.unmodifiableCollection(_fieldList);
+    }
+
+    public List<ConsolidatedField> getConsolidatedFields()
+    {
+        return _consolidatedFields;
+    }
+
+    public String getConsolidatedFieldName(String fieldName)
+    {
+        return _fieldNameToConsolidatedFieldMap.get(fieldName).getName();
+    }
+
+    public boolean isConsolidated(String fieldName)
+    {
+        return _fieldNameToConsolidatedFieldMap.get(fieldName).isConsolidated();
+    }
+
+    public int getPositionInBitField(String fieldName)
+    {
+        return _fieldNameToConsolidatedFieldMap.get(fieldName).getPosition(fieldName);
+    }
+
+
+
+}

Added: incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java?view=auto&rev=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java (added)
+++ incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java Sat Apr  7 09:01:43 2007
@@ -0,0 +1,71 @@
+/*
+ *
+ * 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.qpid.gentools;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
+
+public class SingleVersionModel
+{
+    private final AmqpModel _amqpModel;
+    private final AmqpVersion _amqpVersion;
+    private final Generator _generator;
+    private final List<SingleVersionClass> _classList = new ArrayList<SingleVersionClass>();
+
+    public SingleVersionModel(AmqpModel amqpModel, AmqpVersion amqpVersion, Generator generator)
+    {
+        _amqpModel = amqpModel;
+        _amqpVersion = amqpVersion;
+        _generator = generator;
+
+
+        Collection<AmqpClass> originalClasses = _amqpModel.getClassMap().values();
+
+        for(AmqpClass amqpClass : originalClasses)
+        {
+            _classList.add(new SingleVersionClass(amqpClass, _amqpVersion, _generator));
+
+        }
+
+        Collections.sort(_classList, new Comparator<SingleVersionClass>(){
+            public int compare(SingleVersionClass amqpClass1, SingleVersionClass amqpClass2)
+            {
+                return amqpClass1.getClassId() - amqpClass2.getClassId();
+            }
+        });
+
+
+    }
+
+    public Collection<SingleVersionClass> getClassList()
+    {
+        return Collections.unmodifiableCollection(_classList);
+    }
+
+    public int getMaximumClassId()
+    {
+        return _classList.get(_classList.size()-1).getClassId();
+    }
+}

Modified: incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java?view=diff&rev=526446&r1=526445&r2=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java (original)
+++ incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java Sat Apr  7 09:01:43 2007
@@ -21,10 +21,10 @@
 package org.apache.qpid.gentools;
 
 @SuppressWarnings("serial")
-public class TargetDirectoryException extends Exception
+public class TargetDirectoryException extends RuntimeException
 {
-	public TargetDirectoryException(String msg)
-	{
-		super(msg);
-	}
+    public TargetDirectoryException(String msg)
+    {
+        super(msg);
+    }
 }

Modified: incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/Utils.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/Utils.java?view=diff&rev=526446&r1=526445&r2=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/Utils.java (original)
+++ incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/Utils.java Sat Apr  7 09:01:43 2007
@@ -21,103 +21,114 @@
 package org.apache.qpid.gentools;
 
 import org.w3c.dom.Attr;
-//import org.w3c.dom.Document;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 public class Utils
 {
-	public final static String fileSeparator = System.getProperty("file.separator");
-	public final static String lineSeparator = System.getProperty("line.separator");
-	
-	public final static String ATTRIBUTE_NAME = "name";
-	public final static String ATTRIBUTE_MAJOR = "major";
-	public final static String ATTRIBUTE_MINOR = "minor";
-	public final static String ATTRIBUTE_INDEX = "index";
-	public final static String ATTRIBUTE_LABEL = "label";
-	public final static String ATTRIBUTE_SYNCHRONOUS = "synchronous";
-	public final static String ATTRIBUTE_CONTENT = "content";
-	public final static String ATTRIBUTE_HANDLER = "handler";
-	public final static String ATTRIBUTE_DOMAIN = "domain";
+    public final static String FILE_SEPARATOR = System.getProperty("file.separator");
+    public final static String LINE_SEPARATOR = System.getProperty("line.separator");
+
+    public final static String ATTRIBUTE_NAME = "name";
+    public final static String ATTRIBUTE_MAJOR = "major";
+    public final static String ATTRIBUTE_MINOR = "minor";
+    public final static String ATTRIBUTE_INDEX = "index";
+    public final static String ATTRIBUTE_LABEL = "label";
+    public final static String ATTRIBUTE_SYNCHRONOUS = "synchronous";
+    public final static String ATTRIBUTE_CONTENT = "content";
+    public final static String ATTRIBUTE_HANDLER = "handler";
+    public final static String ATTRIBUTE_DOMAIN = "domain";
     public final static String ATTRIBUTE_VALUE = "value";
-	public final static String ATTRIBUTE_TYPE = "type"; // For compatibility with AMQP 8.0
-	
-	public final static String ELEMENT_AMQP = "amqp";
-	public final static String ELEMENT_CHASSIS = "chassis";
-	public final static String ELEMENT_CLASS = "class";
-	public final static String ELEMENT_CODEGEN = "codegen";
+    public final static String ATTRIBUTE_TYPE = "type"; // For compatibility with AMQP 8.0
+
+    public final static String ELEMENT_AMQP = "amqp";
+    public final static String ELEMENT_CHASSIS = "chassis";
+    public final static String ELEMENT_CLASS = "class";
+    public final static String ELEMENT_CODEGEN = "codegen";
     public final static String ELEMENT_CONSTANT = "constant";
-	public final static String ELEMENT_DOMAIN = "domain";
-	public final static String ELEMENT_METHOD = "method";
-	public final static String ELEMENT_FIELD = "field";
-	public final static String ELEMENT_VERSION = "version";
-	
-	// Attribute functions
-	
-	public static String getNamedAttribute(Node n, String attrName) throws AmqpParseException
-	{
-		NamedNodeMap nnm = n.getAttributes();
-		if (nnm == null)
-			throw new AmqpParseException("Node \"" + n.getNodeName() + "\" has no attributes.");
-		Attr a = (Attr)nnm.getNamedItem(attrName);
-		if (a == null)
-			throw new AmqpParseException("Node \"" + n.getNodeName() + "\" has no attribute \"" + attrName + "\".");
-		return a.getNodeValue();
-	}
-	
-	public static int getNamedIntegerAttribute(Node n, String attrName) throws AmqpParseException
-	{
-		return Integer.parseInt(getNamedAttribute(n, attrName));
-	}
-	
-	// Element functions
-	
-	public static Node findChild(Node n, String eltName) throws AmqpParseException
-	{
-		NodeList nl = n.getChildNodes();
-		for (int i=0; i<nl.getLength(); i++)
-		{
-			Node cn = nl.item(i);
-			if (cn.getNodeName().compareTo(eltName) == 0)
-				return cn;
-		}
-		throw new AmqpParseException("Node \"" + n.getNodeName() +
-				"\" does not contain child element \"" + eltName + "\".");
-	}
-		
-	// String functions
-	
-	public static String firstUpper(String str)
-	{
-		if (!Character.isLowerCase(str.charAt(0)))
-			return str;
-		StringBuffer sb = new StringBuffer(str);
-		sb.setCharAt(0, Character.toUpperCase(str.charAt(0)));
-		return sb.toString();
-	}
-	
-	public static String firstLower(String str)
-	{
-		if (!Character.isUpperCase(str.charAt(0)))
-			return str;
-		StringBuffer sb = new StringBuffer(str);
-		sb.setCharAt(0, Character.toLowerCase(str.charAt(0)));
-		return sb.toString();
-	}
-	
-	public static String createSpaces(int cnt)
-	{
-		StringBuffer sb = new StringBuffer();
-		for (int i=0; i<cnt; i++)
-			sb.append(' ');
-		return sb.toString();
-	}
-    
+    public final static String ELEMENT_DOMAIN = "domain";
+    public final static String ELEMENT_METHOD = "method";
+    public final static String ELEMENT_FIELD = "field";
+    public final static String ELEMENT_VERSION = "version";
+
+    // Attribute functions
+
+    public static String getNamedAttribute(Node n, String attrName) throws AmqpParseException
+    {
+        NamedNodeMap nnm = n.getAttributes();
+        if (nnm == null)
+        {
+            throw new AmqpParseException("Node \"" + n.getNodeName() + "\" has no attributes.");
+        }
+        Attr a = (Attr) nnm.getNamedItem(attrName);
+        if (a == null)
+        {
+            throw new AmqpParseException("Node \"" + n.getNodeName() + "\" has no attribute \"" + attrName + "\".");
+        }
+        return a.getNodeValue();
+    }
+
+    public static int getNamedIntegerAttribute(Node n, String attrName) throws AmqpParseException
+    {
+        return Integer.parseInt(getNamedAttribute(n, attrName));
+    }
+
+    // Element functions
+
+    public static Node findChild(Node n, String eltName) throws AmqpParseException
+    {
+        NodeList nl = n.getChildNodes();
+        for (int i = 0; i < nl.getLength(); i++)
+        {
+            Node cn = nl.item(i);
+            if (cn.getNodeName().compareTo(eltName) == 0)
+            {
+                return cn;
+            }
+        }
+        throw new AmqpParseException("Node \"" + n.getNodeName() +
+                                     "\" does not contain child element \"" + eltName + "\".");
+    }
+
+    // String functions
+
+    public static String firstUpper(String str)
+    {
+        if (!Character.isLetter(str.charAt(0)) || !Character.isLowerCase(str.charAt(0)))
+        {
+            return str;
+        }
+        StringBuffer sb = new StringBuffer(str);
+        sb.setCharAt(0, Character.toUpperCase(str.charAt(0)));
+        return sb.toString();
+    }
+
+    public static String firstLower(String str)
+    {
+        if (!Character.isUpperCase(str.charAt(0)))
+        {
+            return str;
+        }
+        StringBuffer sb = new StringBuffer(str);
+        sb.setCharAt(0, Character.toLowerCase(str.charAt(0)));
+        return sb.toString();
+    }
+
+    public static String createSpaces(int cnt)
+    {
+        StringBuffer sb = new StringBuffer();
+        for (int i = 0; i < cnt; i++)
+        {
+            sb.append(' ');
+        }
+        return sb.toString();
+    }
+
     public static boolean containsOnlyDigits(String str)
     {
         boolean foundNonDigit = false;
-        for (int i=0; i<str.length() && !foundNonDigit; i++)
+        for (int i = 0; i < str.length() && !foundNonDigit; i++)
         {
             if (!Character.isDigit(str.charAt(i)))
             {
@@ -126,12 +137,12 @@
         }
         return !foundNonDigit;
     }
-    
+
     public static boolean containsOnlyDigitsAndDecimal(String str)
     {
         boolean foundNonDigit = false;
         int decimalCntr = 0;
-        for (int i=0; i<str.length() && !foundNonDigit && decimalCntr<2; i++)
+        for (int i = 0; i < str.length() && !foundNonDigit && decimalCntr < 2; i++)
         {
             char ch = str.charAt(i);
             if (!(Character.isDigit(ch) || ch == '.'))
@@ -139,8 +150,10 @@
                 foundNonDigit = true;
             }
             else if (ch == '.')
+            {
                 decimalCntr++;
+            }
         }
-        return !foundNonDigit && decimalCntr<2;
+        return !foundNonDigit && decimalCntr < 2;
     }
 }

Modified: incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java?view=diff&rev=526446&r1=526445&r2=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java (original)
+++ incubator/qpid/trunk/qpid/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java Sat Apr  7 09:01:43 2007
@@ -22,5 +22,5 @@
 
 public interface VersionConsistencyCheck
 {
-	public boolean isVersionConsistent(AmqpVersionSet globalVersionSet);
+    public boolean isVersionConsistent(AmqpVersionSet globalVersionSet);
 }

Added: incubator/qpid/trunk/qpid/gentools/templ.java/method/version/MethodBodyClass.vm
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/templ.java/method/version/MethodBodyClass.vm?view=auto&rev=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/templ.java/method/version/MethodBodyClass.vm (added)
+++ incubator/qpid/trunk/qpid/gentools/templ.java/method/version/MethodBodyClass.vm Sat Apr  7 09:01:43 2007
@@ -0,0 +1,190 @@
+#macro( UpperCamel $name )
+#set( $name = "${name.substring(0,1).toUpperCase()}${name.substring(1)}" )
+#end
+#macro( toUpperCamel $name )${name.substring(0,1).toUpperCase()}${name.substring(1)}#end
+
+
+
+#set( $amqp_ClassName = $amqpClass.Name) 
+#UpperCamel( $amqp_ClassName )
+#set( $amqp_MethodName = $amqpMethod.Name ) 
+#UpperCamel( $amqp_MethodName )
+#set( $javaClassName = "${amqp_ClassName}${amqp_MethodName}BodyImpl" )
+#set( $interfaceName = "${amqp_ClassName}${amqp_MethodName}Body" )
+#set( $amqpPackageName = "amqp_$version.getMajor()_$version.getMinor()" )
+
+#set( $filename = "${amqpPackageName}/${javaClassName}.java")
+/*
+ *
+ * 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.
+ *
+ */
+
+/*
+ * This file is auto-generated by ${generator} - do not modify.
+ * Supported AMQP version:
+ *   $version.getMajor()-$version.getMinor()
+ */
+ 
+#set( $clazz = $amqpClass.asSingleVersionClass( $version ) ) 
+#set( $method = $amqpMethod.asSingleVersionMethod( $version ) )
+ 
+package org.apache.qpid.framing.amqp_$version.getMajor()_$version.getMinor();
+
+import java.util.HashMap;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.qpid.framing.*;
+
+public class ${javaClassName} extends AMQMethodBody_$version.getMajor()_$version.getMinor() implements $interfaceName
+{
+    private static final AMQMethodBodyInstanceFactory FACTORY_INSTANCE = new AMQMethodBodyInstanceFactory()
+    {
+        public AMQMethodBody newInstance(ByteBuffer in, long size) throws AMQFrameDecodingException
+        {
+            return new ${javaClassName}(in);
+        }
+		
+ 
+    };
+    
+	
+    public static AMQMethodBodyInstanceFactory getFactory()
+    {
+        return FACTORY_INSTANCE;
+    }
+
+	public static int CLASS_ID =  $clazz.ClassId; 
+    
+    public static int METHOD_ID = $method.MethodId; 
+    
+
+	
+    // Fields declared in specification
+#foreach( $field in $method.ConsolidatedFields )
+    private final $field.NativeType _$field.getName(); // $field.UnderlyingFields
+#end
+
+    
+    // Constructor
+
+    public ${javaClassName}(ByteBuffer buffer) throws AMQFrameDecodingException
+    {
+#foreach( $field in $method.ConsolidatedFields )
+        _$field.Name = read$field.getEncodingType()( buffer );
+#end
+	}
+	
+    public ${javaClassName}(
+#foreach( $field in $method.FieldList )
+#if( $velocityCount == $method.getFieldList().size() )
+                                $field.NativeType $field.Name
+#else
+                                $field.NativeType $field.Name,
+#end
+#end)
+    {
+#set( $consolidatedFieldName = "" )
+#foreach( $field in $method.FieldList )
+#if( $method.isConsolidated( $field.Name ) )
+#if( !$method.getConsolidatedFieldName( $field.Name ).equals( $consolidatedFieldName ) )
+#if( !$consolidatedFieldName.equals("") )
+        _$consolidatedFieldName = $consolidatedFieldName; // 1
+#end
+#set( $consolidatedFieldName = $method.getConsolidatedFieldName( $field.Name ) )
+        byte $consolidatedFieldName = (byte)0;
+#end
+        if( $field.Name )
+		{		    
+            $consolidatedFieldName = (byte) (((int) $consolidatedFieldName) | (1 << $method.getPositionInBitField( $field.Name )));
+		}
+#if( $velocityCount == $method.getFieldList().size())
+        _$consolidatedFieldName = $consolidatedFieldName; 
+#else  
+ 
+#end 
+#else
+#if( !$consolidatedFieldName.equals("") )
+        _$consolidatedFieldName = $consolidatedFieldName; 
+#end
+#set( $consolidatedFieldName = "" )
+        _$field.Name = $field.Name;
+#end
+#end
+    }
+    
+    public int getClazz() 
+    { 
+        return CLASS_ID; 
+    }
+    
+    public int getMethod() 
+    { 
+        return METHOD_ID; 
+    }
+
+    
+#foreach( $field in $method.FieldList )
+    public final $field.NativeType get#toUpperCamel( ${field.Name} )()
+    {
+#if( $method.isConsolidated( $field.Name ) )
+        return (((int)(_$method.getConsolidatedFieldName( $field.Name ))) & ( 1 << $method.getPositionInBitField( $field.Name ))) != 0;
+#else
+        return _$field.Name;
+#end
+    }
+#end
+
+    protected int getBodySize()
+    {      
+        int size = 0;
+#foreach( $field in $method.ConsolidatedFields )
+#if( $field.isFixedSize() )        
+        size += $field.Size;
+#else
+        size += getSizeOf( _$field.Name );
+#end
+#end
+        return size;        
+    }
+
+    public void writeMethodPayload(ByteBuffer buffer)
+    {
+#foreach( $field in $method.ConsolidatedFields )
+
+        write$field.getEncodingType()( buffer, _$field.Name );
+#end
+    }
+
+
+    public String toString()
+    {
+        StringBuffer buf = new StringBuffer("[$javaClassName: ");
+#foreach( $field in $method.FieldList )
+        buf.append( "$field.Name=" );
+		buf.append( get#toUpperCamel( $field.Name )() );
+#if( $velocityCount	!= $method.FieldList.size() )
+		buf.append( ", " );		
+#end		
+#end
+        buf.append("]");
+        return buf.toString();
+    }
+
+
+}

Added: incubator/qpid/trunk/qpid/gentools/templ.java/model/ProtocolVersionListClass.vm
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/templ.java/model/ProtocolVersionListClass.vm?view=auto&rev=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/templ.java/model/ProtocolVersionListClass.vm (added)
+++ incubator/qpid/trunk/qpid/gentools/templ.java/model/ProtocolVersionListClass.vm Sat Apr  7 09:01:43 2007
@@ -0,0 +1,148 @@
+#set( $filename = "ProtocolVersion.java" )
+/*
+*
+* 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.
+*
+*/
+
+/*
+* This file is auto-generated by $generator - do not modify.
+* Supported AMQP versions:
+#foreach( $version in $model.getVersionSet() )
+* $version.getMajor()-$version.getMinor()
+#end
+*/
+
+package org.apache.qpid.framing;
+
+import java.util.SortedSet;
+import java.util.Collections;
+import java.util.TreeSet;
+
+
+public class ProtocolVersion  implements Comparable
+{
+    private final byte _majorVersion;
+    private final byte _minorVersion;
+
+
+    public ProtocolVersion(byte majorVersion, byte minorVersion)
+    {
+        _majorVersion = majorVersion;
+        _minorVersion = minorVersion;
+    }
+
+    public byte getMajorVersion()
+    {
+        return _majorVersion;
+    }
+
+    public byte getMinorVersion()
+    {
+        return _minorVersion;
+    }
+
+
+    public int compareTo(Object o)
+    {
+        ProtocolVersion pv = (ProtocolVersion) o;
+		
+		/* 
+		 * 0-8 has it's major and minor numbers the wrong way round (it's actually 8-0)...
+		 * so we need to deal with that case specially
+		 */
+		
+        if((_majorVersion == (byte) 8) && (_minorVersion == (byte) 0))
+		{
+		    ProtocolVersion fixedThis = new ProtocolVersion(_minorVersion, _majorVersion);
+			return fixedThis.compareTo(pv);
+		}
+		
+		if((pv.getMajorVersion() == (byte) 8) && (pv.getMinorVersion() == (byte) 0))
+		{
+			ProtocolVersion fixedOther = new ProtocolVersion(pv.getMinorVersion(), pv.getMajorVersion());
+		    return this.compareTo(fixedOther);    
+		}
+		
+        if(_majorVersion > pv.getMajorVersion())
+        {
+            return 1;
+        }
+        else if(_majorVersion < pv.getMajorVersion())
+        {
+            return -1;
+        }
+        else if(_minorVersion > pv.getMinorVersion())
+        {
+            return 1;
+        }
+        else if(getMinorVersion() < pv.getMinorVersion())
+        {
+            return -1;
+        }
+        else
+        {
+            return 0;
+        }
+
+    }
+
+    public boolean equals(Object o)
+    {
+        return o != null && (o == this || (compareTo(o) == 0));
+    }
+
+    public int hashCode()
+    {
+        return (0xFF & (int)_minorVersion) | ((0xFF & (int)_majorVersion) << 8);
+    }
+    
+    
+    public boolean isSupported()
+    {
+        return _supportedVersions.contains(this);
+    }
+    
+    public static ProtocolVersion getLatestSupportedVersion()
+    {
+        return _supportedVersions.last();
+    }
+    
+    private static final SortedSet<ProtocolVersion> _supportedVersions;
+
+    static
+    {
+        SortedSet<ProtocolVersion> versions = new TreeSet<ProtocolVersion>();
+
+#foreach( $version in $model.getVersionSet() )
+        versions.add(new ProtocolVersion((byte)$version.getMajor(),(byte)$version.getMinor()));
+#end
+        _supportedVersions = Collections.unmodifiableSortedSet(versions);
+    }
+
+    
+    public static SortedSet<ProtocolVersion> getSupportedProtocolVersions()
+    {
+        return _supportedVersions;
+    }
+    
+    
+    
+    
+
+}

Added: incubator/qpid/trunk/qpid/gentools/templ.java/model/version/AmqpConstantsClass.vm
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/templ.java/model/version/AmqpConstantsClass.vm?view=auto&rev=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/templ.java/model/version/AmqpConstantsClass.vm (added)
+++ incubator/qpid/trunk/qpid/gentools/templ.java/model/version/AmqpConstantsClass.vm Sat Apr  7 09:01:43 2007
@@ -0,0 +1,37 @@
+&{AmqpConstants.java}
+/*
+ *
+ * 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.
+ *
+ */
+
+/*
+ * This file is auto-generated by ${GENERATOR} - do not modify.
+ * Supported AMQP versions:
+%{VLIST} *   ${major}-${minor}
+ */
+ 
+package org.apache.qpid.framing;
+
+class AmqpConstants
+{
+ 	// Constant getValue methods
+ 	
+%{TLIST} ${const_get_method}
+	
+}

Added: incubator/qpid/trunk/qpid/gentools/templ.java/model/version/MethodRegistryClass.vm
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/gentools/templ.java/model/version/MethodRegistryClass.vm?view=auto&rev=526446
==============================================================================
--- incubator/qpid/trunk/qpid/gentools/templ.java/model/version/MethodRegistryClass.vm (added)
+++ incubator/qpid/trunk/qpid/gentools/templ.java/model/version/MethodRegistryClass.vm Sat Apr  7 09:01:43 2007
@@ -0,0 +1,145 @@
+#set( $filename = "amqp_$version.getMajor()_$version.getMinor()/MethodRegistry_${version.getMajor()}_${version.getMinor()}.java")
+/*
+ *
+ * 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.
+ *
+ */
+
+/*
+ * This file is auto-generated by $generator - do not modify.
+ * Supported AMQP version:
+ *   $version.getMajor()-$version.getMinor()
+ */
+ 
+package org.apache.qpid.framing.amqp_${version.getMajor()}_${version.getMinor()};
+
+import org.apache.qpid.framing.AMQMethodBodyInstanceFactory;
+import org.apache.qpid.framing.AMQFrameDecodingException;
+import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.MethodRegistry;
+import org.apache.qpid.framing.ProtocolVersion;
+
+
+import org.apache.log4j.Logger;
+import org.apache.mina.common.ByteBuffer;
+
+public class MethodRegistry_$version.getMajor()_$version.getMinor() extends MethodRegistry
+{
+	
+    private static final Logger _log = Logger.getLogger(MethodRegistry.class);
+
+#set( $specificModel = $model.asSingleVersionModel() )	
+	
+	
+	
+	private final AMQMethodBodyInstanceFactory[][] _factories = new AMQMethodBodyInstanceFactory[$specificModel.getMaximumClassId()+1][];
+
+	public MethodRegistry_$version.getMajor()_$version.getMinor()()
+	{
+	    this(new ProtocolVersion((byte)$version.getMajor(),(byte)$version.getMinor()));
+    }
+	
+	public MethodRegistry_$version.getMajor()_$version.getMinor()(ProtocolVersion pv)
+	{
+        super(pv);	
+#foreach( $amqpClass in $specificModel.getClassList() )
+#set( $amqpClassNameFirstChar = $amqpClass.getName().substring(0,1) )
+#set( $amqpClassNameFirstCharU = $amqpClassNameFirstChar.toUpperCase() )
+#set( $amqpClassNameUpperCamel = "$amqpClassNameFirstCharU$amqpClass.getName().substring(1)" )
+
+
+
+		// Register method body instance factories for the $amqpClassNameUpperCamel class.
+
+        _factories[$amqpClass.getClassId()] = new AMQMethodBodyInstanceFactory[$amqpClass.getMaximumMethodId()+1];
+		
+#foreach( $amqpMethod in $amqpClass.getMethodList() )
+#set( $amqpMethodNameFirstChar = $amqpMethod.getName().substring(0,1) )
+#set( $amqpMethodNameFirstCharU = $amqpMethodNameFirstChar.toUpperCase() )
+#set( $amqpMethodNameUpperCamel = "$amqpMethodNameFirstCharU$amqpMethod.getName().substring(1)" )
+        _factories[$amqpClass.getClassId()][$amqpMethod.getMethodId()] = ${amqpClassNameUpperCamel}${amqpMethodNameUpperCamel}BodyImpl.getFactory(); 
+#end		
+		
+#end
+		
+		
+	}
+
+
+    public AMQMethodBody convertToBody(ByteBuffer in, long size)
+        throws AMQFrameDecodingException
+    {
+	    int classId = in.getUnsignedShort();
+		int methodId = in.getUnsignedShort();
+	
+        AMQMethodBodyInstanceFactory bodyFactory;
+        try
+        {
+            bodyFactory = _factories[classId][methodId];
+        }
+        catch(NullPointerException e)
+        {
+            throw new AMQFrameDecodingException(_log,
+                "Class " + classId + " unknown in AMQP version $version.getMajor()-$version.getMinor()"
+                 + " (while trying to decode class " + classId + " method " + methodId + ".");
+        }
+        catch(IndexOutOfBoundsException e)
+        {
+            if(classId >= _factories.length)
+            {
+                throw new AMQFrameDecodingException(_log,
+                    "Class " + classId + " unknown in AMQP version $version.getMajor()-$version.getMinor()"
+                     + " (while trying to decode class " + classId + " method " + methodId + ".");
+
+            }
+            else
+            {
+                throw new AMQFrameDecodingException(_log,
+                    "Method " + methodId + " unknown in AMQP version $version.getMajor()-$version.getMinor()"
+                     + " (while trying to decode class " + classId + " method " + methodId + ".");
+
+            }
+        }
+
+
+        if (bodyFactory == null)
+        {
+            throw new AMQFrameDecodingException(_log,
+                "Method " + methodId + " unknown in AMQP version $version.getMajor()-$version.getMinor()"
+                 + " (while trying to decode class " + classId + " method " + methodId + ".");
+        }
+
+
+        return bodyFactory.newInstance(in, size);
+
+
+    }
+
+
+    public int getMaxClassId()
+	{
+	    return $specificModel.getMaximumClassId();
+	}
+    
+    public int getMaxMethodId(int classId)
+	{
+        return _factories[classId].length - 1;	
+	}
+	
+    
+}