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 2006/12/28 01:32:47 UTC
svn commit: r490614 [1/4] - in
/incubator/qpid/branches/new_persistence/gentools: org/ src/ src/org/
src/org/apache/ src/org/apache/qpid/ src/org/apache/qpid/gentools/
templ.java/
Author: rgreig
Date: Wed Dec 27 16:32:45 2006
New Revision: 490614
URL: http://svn.apache.org/viewvc?view=rev&rev=490614
Log:
Merge up to trunk rev 490505
Added:
incubator/qpid/branches/new_persistence/gentools/src/
incubator/qpid/branches/new_persistence/gentools/src/org/
incubator/qpid/branches/new_persistence/gentools/src/org/apache/
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpClass.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpClassMap.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpConstant.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpConstantSet.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomain.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomainMap.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomainVersionMap.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpField.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpFieldMap.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpMethod.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpMethodMap.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpModel.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpParseException.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpTemplateException.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpTypeMappingException.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpVersion.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpVersionSet.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/CppGenerator.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/Generator.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/JavaGenerator.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/LanguageConverter.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/Main.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/NodeAware.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/Printable.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/Utils.java (with props)
incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java (with props)
incubator/qpid/branches/new_persistence/gentools/templ.java/AmqpConstantsClass.tmpl
incubator/qpid/branches/new_persistence/gentools/templ.java/ProtocolVersionListClass.tmpl
Removed:
incubator/qpid/branches/new_persistence/gentools/org/
Modified:
incubator/qpid/branches/new_persistence/gentools/templ.java/MethodBodyClass.tmpl
incubator/qpid/branches/new_persistence/gentools/templ.java/MethodRegistryClass.tmpl
incubator/qpid/branches/new_persistence/gentools/templ.java/PropertyContentHeaderClass.tmpl
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpClass.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpClass.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpClass.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpClass.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,117 @@
+/*
+ *
+ * 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.io.PrintStream;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class AmqpClass implements Printable, NodeAware
+{
+ public LanguageConverter converter;
+ public AmqpVersionSet versionSet;
+ public AmqpFieldMap fieldMap;
+ public AmqpMethodMap methodMap;
+ public String name;
+ public AmqpOrdinalVersionMap indexMap;
+
+ public AmqpClass(String name, LanguageConverter converter)
+ {
+ this.name = name;
+ this.converter = converter;
+ versionSet = new AmqpVersionSet();
+ fieldMap = new AmqpFieldMap();
+ methodMap = new AmqpMethodMap();
+ indexMap = new AmqpOrdinalVersionMap();
+ }
+
+ public void addFromNode(Node classNode, int ordinal, AmqpVersion version)
+ throws AmqpParseException, AmqpTypeMappingException
+ {
+ versionSet.add(version);
+ int index = Utils.getNamedIntegerAttribute(classNode, "index");
+ AmqpVersionSet versionSet = indexMap.get(index);
+ if (versionSet != null)
+ versionSet.add(version);
+ else
+ {
+ versionSet = new AmqpVersionSet();
+ versionSet.add(version);
+ indexMap.put(index, versionSet);
+ }
+ NodeList nList = classNode.getChildNodes();
+ int fieldCntr = 0;
+ int methodCntr = 0;
+ for (int i=0; i<nList.getLength(); i++)
+ {
+ Node child = nList.item(i);
+ if (child.getNodeName().compareTo(Utils.ELEMENT_FIELD) == 0)
+ {
+ String fieldName = converter.prepareDomainName(Utils.getNamedAttribute(child, Utils.ATTRIBUTE_NAME));
+ AmqpField thisField = fieldMap.get(fieldName);
+ if (thisField == null)
+ {
+ thisField = new AmqpField(fieldName, converter);
+ fieldMap.put(fieldName, thisField);
+ }
+ thisField.addFromNode(child, fieldCntr, version);
+ fieldCntr++;
+ }
+ else if (child.getNodeName().compareTo(Utils.ELEMENT_METHOD) == 0)
+ {
+ String methodName = converter.prepareMethodName(Utils.getNamedAttribute(child, Utils.ATTRIBUTE_NAME));
+ AmqpMethod thisMethod = methodMap.get(methodName);
+ if (thisMethod == null)
+ {
+ thisMethod = new AmqpMethod(methodName, converter);
+ methodMap.put(methodName, thisMethod);
+ }
+ thisMethod.addFromNode(child, methodCntr++, version);
+ }
+ }
+ }
+
+ public void print(PrintStream out, int marginSize, int tabSize)
+ {
+ String margin = Utils.createSpaces(marginSize);
+ String tab = Utils.createSpaces(tabSize);
+ out.println(margin + "[C] " + name + ": " + versionSet);
+
+ for (Integer thisIndex : indexMap.keySet())
+ {
+ AmqpVersionSet indexVersionSet = indexMap.get(thisIndex);
+ out.println(margin + tab + "[I] " + thisIndex + indexVersionSet);
+ }
+
+ for (String thisFieldName : fieldMap.keySet())
+ {
+ AmqpField thisField = fieldMap.get(thisFieldName);
+ thisField.print(out, marginSize + tabSize, tabSize);
+ }
+
+ for (String thisMethodName : methodMap.keySet())
+ {
+ AmqpMethod thisMethod = methodMap.get(thisMethodName);
+ thisMethod.print(out, marginSize + tabSize, tabSize);
+ }
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpClass.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpClassMap.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpClassMap.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpClassMap.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpClassMap.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,29 @@
+/*
+ *
+ * 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.TreeMap;
+
+@SuppressWarnings("serial")
+public class AmqpClassMap extends TreeMap<String, AmqpClass>
+{
+
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpClassMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpConstant.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpConstant.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpConstant.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpConstant.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,205 @@
+/*
+ *
+ * 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.io.PrintStream;
+import java.util.TreeMap;
+
+/**
+ * @author kpvdr
+ * Class to represent the <constant> declaration within the AMQP specification.
+ * Currently, only integer values exist within the specification, however looking forward
+ * to other possible types in the future, string and double types are also supported.
+ *
+ * The <constant> declaration in the specification contains only two attributes:
+ * name and value.
+ *
+ * The value of the constant is mapped against the version(s) for which the name is defined.
+ * This allows for a change in the value rather than the name only from one version to the next.
+ */
+@SuppressWarnings("serial")
+public class AmqpConstant extends TreeMap<String, AmqpVersionSet>
+ implements Printable, VersionConsistencyCheck, Comparable<AmqpConstant>
+{
+ /**
+ * Constant name as defined by the name attribute of the <constant> declaration.
+ */
+ protected String name;
+
+ /**
+ * Set of versions for which this constant name is defined.
+ */
+ protected AmqpVersionSet versionSet;
+
+ /**
+ * Constructor
+ * @param name Constant name as defined by the name attribute of the <constant> declaration.
+ * @param value Constant value as defined by the value attribute of the <constant> declaration.
+ * @param version AMQP version for which this constant is defined
+ */
+ public AmqpConstant (String name, String value, AmqpVersion version)
+ {
+ this.name = name;
+ versionSet = new AmqpVersionSet(version);
+ AmqpVersionSet valueVersionSet = new AmqpVersionSet(version);
+ put(value, valueVersionSet);
+ }
+
+ /**
+ * Constructor
+ * @param name Constant name as defined by the name attribute of the <constant> declaration.
+ * @param value Constant value as defined by the value attribute of the <constant> declaration.
+ * @param version AMQP version for which this constant is defined
+ */
+ public AmqpConstant (String name, int value, AmqpVersion version)
+ {
+ this.name = name;
+ versionSet = new AmqpVersionSet(version);
+ AmqpVersionSet valueVersionSet = new AmqpVersionSet(version);
+ put(String.valueOf(value), valueVersionSet);
+ }
+
+ /**
+ * Constructor
+ * @param name Constant name as defined by the name attribute of the <constant> declaration.
+ * @param value Constant value as defined by the value attribute of the <constant> declaration.
+ * @param version AMQP version for which this constant is defined
+ */
+ public AmqpConstant (String name, double value, AmqpVersion version)
+ {
+ this.name = name;
+ versionSet = new AmqpVersionSet(version);
+ AmqpVersionSet valueVersionSet = new AmqpVersionSet(version);
+ put(String.valueOf(value), valueVersionSet);
+ }
+
+ /**
+ * Get the name of this constant.
+ * @return Name of this constant, being the name attribute of the <constant> declaration
+ * represented by this class.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Get the value of this constant as a String.
+ * @param version AMQP version for which this value is required.
+ * @return Value of this constant, being the value attribute of the <constant> declaration
+ * represented by this class.
+ * @throws AmqpTypeMappingException when a value is requested for a version for which it is not
+ * defined in the AMQP specifications.
+ */
+ public String getStringValue(AmqpVersion version)
+ throws AmqpTypeMappingException
+ {
+ for (String thisValue : keySet())
+ {
+ AmqpVersionSet versionSet = get(thisValue);
+ if (versionSet.contains(version))
+ return thisValue;
+ }
+ throw new AmqpTypeMappingException("Unable to find value for constant \"" + name +
+ "\" for version " + version.toString() + ".");
+ }
+
+ /**
+ * Get the value of this constant as an integer.
+ * @param version AMQP version for which this value is required.
+ * @return Value of this constant, being the value attribute of the <constant> declaration
+ * represented by this class.
+ * @throws AmqpTypeMappingException when a value is requested for a version for which it is not
+ * defined in the AMQP specifications.
+ */
+ public int getIntegerValue(AmqpVersion version)
+ throws AmqpTypeMappingException
+ {
+ return Integer.parseInt(getStringValue(version));
+ }
+
+ /**
+ * Get the value of this constant as a double.
+ * @param version AMQP version for which this value is required.
+ * @return Value of this constant, being the value attribute of the <constant> declaration
+ * represented by this class.
+ * @throws AmqpTypeMappingException when a value is requested for a version for which it is not
+ * defined in the AMQP specifications.
+ */
+ public double getDoubleValue(AmqpVersion version)
+ throws AmqpTypeMappingException
+ {
+ return Double.parseDouble(getStringValue(version));
+ }
+
+ /**
+ * Get the version set for this constant. It contains the all the versions for which this
+ * constant name exists.
+ * @return Set of versions for which this constant exists.
+ */
+ public AmqpVersionSet getVersionSet()
+ {
+ return versionSet;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+
+ public int compareTo(AmqpConstant other)
+ {
+ int res = name.compareTo(other.name);
+ if (res != 0)
+ return res;
+ return versionSet.compareTo(other.versionSet);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.qpid.gentools.VersionConsistencyCheck#isVersionConsistent(org.apache.qpid.gentools.AmqpVersionSet)
+ */
+ public boolean isVersionConsistent(AmqpVersionSet globalVersionSet)
+ {
+ if (size() != 1)
+ return false;
+ return get(firstKey()).equals(globalVersionSet);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.qpid.gentools.Printable#print(java.io.PrintStream, int, int)
+ */
+ public void print(PrintStream out, int marginSize, int tabSize)
+ {
+ String margin = Utils.createSpaces(marginSize);
+ String tab = Utils.createSpaces(tabSize);
+ if (size() == 1)
+ {
+ out.println(margin + tab + "[C] " + name + " = \"" + firstKey() + "\" " + versionSet);
+ }
+ else
+ {
+ out.println(margin + tab + "[C] " + name + ": " + versionSet);
+ for (String thisValue : keySet())
+ {
+ out.println(margin + tab + tab + "= \"" + thisValue + "\" " + get(thisValue));
+ }
+ }
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpConstant.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpConstantSet.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpConstantSet.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpConstantSet.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpConstantSet.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,132 @@
+/*
+ *
+ * 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.io.PrintStream;
+import java.util.Iterator;
+import java.util.TreeSet;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author kpvdr
+ * This class implements a set collection for {@link #AmqpConstant AmqpConstant} objects, being the collection
+ * of constants accumulated from various AMQP specification files processed. Each name occurs once only in the set.
+ * The {@link #AmqpConstant AmqpConstant} objects (derived from {@link java.util#TreeMap TreeMap}) keep track of
+ * the value and version(s) assigned to this name.
+ */
+@SuppressWarnings("serial")
+public class AmqpConstantSet extends TreeSet<AmqpConstant> implements Printable, NodeAware, Comparable<AmqpConstantSet>
+{
+ public LanguageConverter converter;
+
+ public AmqpConstantSet(LanguageConverter converter)
+ {
+ this.converter = converter;
+ this.converter.setConstantSet(this);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.qpid.gentools.NodeAware#addFromNode(org.w3c.dom.Node, int, org.apache.qpid.gentools.AmqpVersion)
+ */
+ public void addFromNode(Node node, int ordinal, AmqpVersion version)
+ throws AmqpParseException, AmqpTypeMappingException
+ {
+ NodeList nodeList = node.getChildNodes();
+ for (int i=0; i<nodeList.getLength(); i++)
+ {
+ Node childNode = nodeList.item(i);
+ if (childNode.getNodeName().compareTo(Utils.ELEMENT_CONSTANT) == 0)
+ {
+ String name = converter.prepareDomainName(Utils.getNamedAttribute(childNode, Utils.ATTRIBUTE_NAME));
+ String value = Utils.getNamedAttribute(childNode, Utils.ATTRIBUTE_VALUE);
+ // Find this name in the existing set of objects
+ boolean foundName = false;
+ Iterator<AmqpConstant> cItr = iterator();
+ while (cItr.hasNext() && !foundName)
+ {
+ AmqpConstant thisConstant = cItr.next();
+ if (name.compareTo(thisConstant.name) == 0)
+ {
+ foundName = true;
+ thisConstant.versionSet.add(version);
+ // Now, find the value in the map
+ boolean foundValue = false;
+ for (String thisValue : thisConstant.keySet())
+ {
+ if (value.compareTo(thisValue) == 0)
+ {
+ foundValue = true;
+ // Add this version to existing version set.
+ AmqpVersionSet versionSet = thisConstant.get(thisValue);
+ versionSet.add(version);
+ }
+ }
+ // Check that the value was found - if not, add it
+ if (!foundValue)
+ {
+ thisConstant.put(value, new AmqpVersionSet(version));
+ }
+ }
+ }
+ // Check that the name was found - if not, add it
+ if (!foundName)
+ {
+ add(new AmqpConstant(name, value, version));
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.qpid.gentools.Printable#print(java.io.PrintStream, int, int)
+ */
+ public void print(PrintStream out, int marginSize, int tabSize)
+ {
+ out.println(Utils.createSpaces(marginSize) + "Constants: ");
+ for (AmqpConstant thisAmqpConstant : this)
+ {
+ thisAmqpConstant.print(out, marginSize, tabSize);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(AmqpConstantSet other)
+ {
+ int res = size() - other.size();
+ if (res != 0)
+ return res;
+ Iterator<AmqpConstant> cItr = iterator();
+ Iterator<AmqpConstant> oItr = other.iterator();
+ while (cItr.hasNext() && oItr.hasNext())
+ {
+ AmqpConstant constant = cItr.next();
+ AmqpConstant oConstant = oItr.next();
+ res = constant.compareTo(oConstant);
+ if (res != 0)
+ return res;
+ }
+ return 0;
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpConstantSet.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomain.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomain.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomain.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomain.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,78 @@
+/*
+ *
+ * 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.io.PrintStream;
+import java.util.TreeMap;
+
+@SuppressWarnings("serial")
+public class AmqpDomain extends TreeMap<String, AmqpVersionSet> implements Printable
+{
+ public String domainName;
+
+ public AmqpDomain(String domainName)
+ {
+ this.domainName = domainName;
+ }
+
+ public void addDomain(String domainType, AmqpVersion version) throws AmqpParseException
+ {
+ AmqpVersionSet versionSet = get(domainType);
+ if (versionSet == null) // First time, create new entry
+ {
+ versionSet = new AmqpVersionSet();
+ put(domainType, versionSet);
+ }
+ versionSet.add(version);
+ }
+
+ public String getDomainType(AmqpVersion version)
+ throws AmqpTypeMappingException
+ {
+ for (String thisDomainType : keySet())
+ {
+ AmqpVersionSet versionSet = get(thisDomainType);
+ if (versionSet.contains(version))
+ return thisDomainType;
+ } throw new AmqpTypeMappingException("Unable to find version " + version + ".");
+ }
+
+ public boolean hasVersion(String type, AmqpVersion v)
+ {
+ AmqpVersionSet vs = get(type);
+ if (vs == null)
+ return false;
+ return vs.contains(v);
+ }
+
+ public void print(PrintStream out, int marginSize, int tabSize)
+ {
+ String margin = Utils.createSpaces(marginSize);
+ String tab = Utils.createSpaces(tabSize);
+ out.println(margin + domainName + ":");
+
+ for (String thisDomainType : keySet())
+ {
+ AmqpVersionSet vs = get(thisDomainType);
+ out.println(margin + tab + thisDomainType + " : " + vs.toString());
+ }
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomain.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomainMap.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomainMap.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomainMap.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomainMap.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,118 @@
+/*
+ *
+ * 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.io.PrintStream;
+import java.util.TreeMap;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+@SuppressWarnings("serial")
+public class AmqpDomainMap extends TreeMap<String, AmqpDomain> implements Printable, NodeAware
+{
+ public LanguageConverter converter;
+
+ public AmqpDomainMap(LanguageConverter converter)
+ {
+ this.converter = converter;
+ this.converter.setDomainMap(this);
+ }
+
+ public void addFromNode(Node n, int o, AmqpVersion v)
+ throws AmqpParseException, AmqpTypeMappingException
+ {
+ NodeList nl = n.getChildNodes();
+ for (int i=0; i<nl.getLength(); i++)
+ {
+ Node c = nl.item(i);
+ // All versions 0.9 and greater use <domain> for all domains
+ if (c.getNodeName().compareTo(Utils.ELEMENT_DOMAIN) == 0)
+ {
+ String domainName = converter.prepareDomainName(Utils.getNamedAttribute(c, Utils.ATTRIBUTE_NAME));
+ String type = Utils.getNamedAttribute(c, Utils.ATTRIBUTE_TYPE);
+ AmqpDomain thisDomain = get(domainName);
+ if (thisDomain == null)
+ {
+ thisDomain = new AmqpDomain(domainName);
+ put(domainName, thisDomain);
+ }
+ thisDomain.addDomain(type, v);
+ }
+ // Version(s) 0.8 and earlier use <domain> for all complex domains and use
+ // attribute <field type=""...> for simple types. Add these simple types to
+ // domain list - but beware of duplicates!
+ else if (c.getNodeName().compareTo(Utils.ELEMENT_FIELD) == 0)
+ {
+ try
+ {
+ String type = converter.prepareDomainName(Utils.getNamedAttribute(c, Utils.ATTRIBUTE_TYPE));
+ AmqpDomain thisDomain = get(type);
+ if (thisDomain == null)
+ {
+ thisDomain = new AmqpDomain(type);
+ put(type, thisDomain);
+ }
+ if (!thisDomain.hasVersion(type, v))
+ thisDomain.addDomain(type, v);
+ }
+ catch (AmqpParseException e) {} // Ignore fields without type attribute
+ }
+ else if (c.getNodeName().compareTo(Utils.ELEMENT_CLASS) == 0 ||
+ c.getNodeName().compareTo(Utils.ELEMENT_METHOD) == 0)
+ {
+ addFromNode(c, 0, v);
+ }
+ }
+ }
+
+ public String getDomainType(String domainName, AmqpVersion version)
+ throws AmqpTypeMappingException
+ {
+ AmqpDomain domainType = get(domainName);
+ // For AMQP 8.0, primitive types were not described as domains, so
+ // return itself as the type.
+ if (domainType == null)
+ {
+ return domainName;
+ }
+ try
+ {
+ return domainType.getDomainType(version);
+ }
+ catch (AmqpTypeMappingException e)
+ {
+ throw new AmqpTypeMappingException("Unable to find domain type for domain \"" + domainName +
+ "\" version " + version + ".");
+ }
+ }
+
+
+ public void print(PrintStream out, int marginSize, int tabSize)
+ {
+ out.println(Utils.createSpaces(marginSize) + "Domain Map:");
+ for (String thisDomainName : keySet())
+ {
+ AmqpDomain domain = get(thisDomainName);
+ domain.print(out, marginSize + tabSize, tabSize);
+ }
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomainMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomainVersionMap.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomainVersionMap.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomainVersionMap.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomainVersionMap.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,34 @@
+/*
+ *
+ * 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.TreeMap;
+
+@SuppressWarnings("serial")
+public class AmqpDomainVersionMap extends TreeMap<String, AmqpVersionSet> implements VersionConsistencyCheck
+{
+ public boolean isVersionConsistent(AmqpVersionSet globalVersionSet)
+ {
+ if (size() != 1)
+ return false;
+ return get(firstKey()).equals(globalVersionSet);
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpDomainVersionMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpField.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpField.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpField.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpField.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,136 @@
+/*
+ *
+ * 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.io.PrintStream;
+import java.util.ArrayList;
+
+import org.w3c.dom.Node;
+
+public class AmqpField implements Printable, NodeAware, VersionConsistencyCheck
+{
+ public LanguageConverter converter;
+ public AmqpVersionSet versionSet;
+ public AmqpDomainVersionMap domainMap;
+ public AmqpOrdinalVersionMap ordinalMap;
+ public String name;
+
+ public AmqpField(String name, LanguageConverter converter)
+ {
+ this.name = name;
+ this.converter = converter;
+ versionSet = new AmqpVersionSet();
+ domainMap = new AmqpDomainVersionMap();
+ ordinalMap = new AmqpOrdinalVersionMap();
+ }
+
+ public void addFromNode(Node fieldNode, int ordinal, AmqpVersion version)
+ throws AmqpParseException, AmqpTypeMappingException
+ {
+ versionSet.add(version);
+ String domainType;
+ // Early versions of the spec (8.0) used the "type" attribute instead of "domain" for some fields.
+ try
+ {
+ domainType = converter.prepareDomainName(Utils.getNamedAttribute(fieldNode, Utils.ATTRIBUTE_DOMAIN));
+ }
+ catch (AmqpParseException e)
+ {
+ domainType = converter.prepareDomainName(Utils.getNamedAttribute(fieldNode, Utils.ATTRIBUTE_TYPE));
+ }
+ AmqpVersionSet thisVersionList = domainMap.get(domainType);
+ if (thisVersionList == null) // First time, create new entry
+ {
+ thisVersionList = new AmqpVersionSet();
+ domainMap.put(domainType, thisVersionList);
+ }
+ thisVersionList.add(version);
+ thisVersionList = ordinalMap.get(ordinal);
+ if (thisVersionList == null) // First time, create new entry
+ {
+ thisVersionList = new AmqpVersionSet();
+ ordinalMap.put(ordinal, thisVersionList);
+ }
+ thisVersionList.add(version);
+ }
+
+ public boolean isCodeTypeConsistent(LanguageConverter converter)
+ throws AmqpTypeMappingException
+ {
+ if (domainMap.size() == 1)
+ return true; // By definition
+ ArrayList<String> codeTypeList = new ArrayList<String>();
+ for (String thisDomainName : domainMap.keySet())
+ {
+ AmqpVersionSet versionSet = domainMap.get(thisDomainName);
+ String codeType = converter.getGeneratedType(thisDomainName, versionSet.first());
+ if (!codeTypeList.contains(codeType))
+ codeTypeList.add(codeType);
+ }
+ return codeTypeList.size() == 1;
+ }
+
+ public boolean isConsistent(Generator generator)
+ throws AmqpTypeMappingException
+ {
+ if (!isCodeTypeConsistent(generator))
+ return false;
+ if (ordinalMap.size() != 1)
+ return false;
+ // Since the various doamin names map to the same code type, add the version occurrences
+ // across all domains to see we have all possible versions covered
+ int vCntr = 0;
+ for (String thisDomainName : domainMap.keySet())
+ {
+ vCntr += domainMap.get(thisDomainName).size();
+ }
+ return vCntr == generator.globalVersionSet.size();
+ }
+
+ public void print(PrintStream out, int marginSize, int tabSize)
+ {
+ String margin = Utils.createSpaces(marginSize);
+ out.println(margin + "[F] " + name + ": " + versionSet);
+
+ for (Integer thisOrdinal : ordinalMap.keySet())
+ {
+ AmqpVersionSet versionList = ordinalMap.get(thisOrdinal);
+ out.println(margin + " [O] " + thisOrdinal + " : " + versionList.toString());
+ }
+
+ for (String thisDomainName : domainMap.keySet())
+ {
+ AmqpVersionSet versionList = domainMap.get(thisDomainName);
+ out.println(margin + " [D] " + thisDomainName + " : " + versionList.toString());
+ }
+ }
+
+ public boolean isVersionConsistent(AmqpVersionSet globalVersionSet)
+ {
+ if (!versionSet.equals(globalVersionSet))
+ return false;
+ if (!domainMap.isVersionConsistent(globalVersionSet))
+ return false;
+ if (!ordinalMap.isVersionConsistent(globalVersionSet))
+ return false;
+ return true;
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpField.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpFieldMap.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpFieldMap.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpFieldMap.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpFieldMap.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,337 @@
+/*
+ *
+ * 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.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.TreeMap;
+
+@SuppressWarnings("serial")
+public class AmqpFieldMap extends TreeMap<String, AmqpField> implements VersionConsistencyCheck
+{
+ public AmqpFieldMap getFieldMapForOrdinal(int ordinal)
+ {
+ AmqpFieldMap newMap = new AmqpFieldMap();
+ for (String thisFieldName: keySet())
+ {
+ AmqpField field = get(thisFieldName);
+ TreeMap<Integer, AmqpVersionSet> ordinalMap = field.ordinalMap;
+ AmqpVersionSet ordinalVersions = ordinalMap.get(ordinal);
+ if (ordinalVersions != null)
+ {
+ newMap.put(field.name, field);
+ }
+ }
+ return newMap;
+ }
+
+ public AmqpOrdinalFieldMap getMapForVersion(AmqpVersion version, boolean codeTypeFlag,
+ LanguageConverter converter)
+ throws AmqpTypeMappingException
+ {
+ // TODO: REVIEW THIS! There may be a bug here that affects C++ generation (only with >1 version)...
+ // If version == null (a common scenario) then the version map is built up on the
+ // basis of first found item, and ignores other version variations.
+ // This should probably be disallowed by throwing an NPE, as AmqpOrdinalFieldMap cannot
+ // represent these possibilities.
+ // *OR*
+ // Change the structure of AmqpOrdianlFieldMap to allow for the various combinations that
+ // will result from version variation - but that is what AmqpFieldMap is... :-$
+ AmqpOrdinalFieldMap ordinalFieldMap = new AmqpOrdinalFieldMap();
+ for (String thisFieldName: keySet())
+ {
+ AmqpField field = get(thisFieldName);
+ if (version == null || field.versionSet.contains(version))
+ {
+ // 1. Search for domain name in field domain map with version that matches
+ String domain = "";
+ boolean dFound = false;
+ for (String thisDomainName : field.domainMap.keySet())
+ {
+ domain = thisDomainName;
+ AmqpVersionSet versionSet = field.domainMap.get(domain);
+ if (version == null || versionSet.contains(version))
+ {
+ if (codeTypeFlag)
+ domain = converter.getGeneratedType(domain, version);
+ dFound = true;
+ }
+ }
+
+ // 2. Search for ordinal in field ordianl map with version that matches
+ int ordinal = -1;
+ boolean oFound = false;
+ for (Integer thisOrdinal : field.ordinalMap.keySet())
+ {
+ ordinal = thisOrdinal;
+ AmqpVersionSet versionSet = field.ordinalMap.get(ordinal);
+ if (version == null || versionSet.contains(version))
+ oFound = true;
+ }
+
+ if (dFound && oFound)
+ {
+ String[] fieldDomainPair = {field.name, domain};
+ ordinalFieldMap.put(ordinal, fieldDomainPair);
+ }
+ }
+ }
+ return ordinalFieldMap;
+ }
+
+ public boolean isDomainConsistent(Generator generator, AmqpVersionSet versionSet)
+ throws AmqpTypeMappingException
+ {
+ if (size() != 1) // Only one field for this ordinal
+ return false;
+ return get(firstKey()).isConsistent(generator);
+ }
+
+ public int getNumFields(AmqpVersion version)
+ {
+ int fCntr = 0;
+ for (String thisFieldName : keySet())
+ {
+ AmqpField field = get(thisFieldName);
+ if (field.versionSet.contains(version))
+ fCntr++;
+ }
+ return fCntr;
+ }
+
+ public String parseFieldMap(Method commonGenerateMethod, Method mangledGenerateMethod,
+ int indentSize, int tabSize, LanguageConverter converter)
+ throws AmqpTypeMappingException, IllegalAccessException, InvocationTargetException
+ {
+ String indent = Utils.createSpaces(indentSize);
+ String cr = Utils.lineSeparator;
+ StringBuffer sb = new StringBuffer();
+
+ if (commonGenerateMethod == null)
+ {
+ // Generate warnings in code if required methods are null.
+ sb.append(indent + "/*********************************************************" + cr);
+ sb.append(indent + " * WARNING: Generated code could be missing." + cr);
+ sb.append(indent + " * In call to parseFieldMap(), generation method was null." + cr);
+ sb.append(indent + " * Check for NoSuchMethodException on startup." + cr);
+ sb.append(indent + " *********************************************************/" + cr);
+ }
+
+ Iterator<String> itr = keySet().iterator();
+ while (itr.hasNext())
+ {
+ String fieldName = itr.next();
+ AmqpField field = get(fieldName);
+ if (field.isCodeTypeConsistent(converter))
+ {
+ // All versions identical - Common declaration
+ String domainName = field.domainMap.firstKey();
+ AmqpVersionSet versionSet = field.domainMap.get(domainName);
+ String codeType = converter.getGeneratedType(domainName, versionSet.first());
+ if (commonGenerateMethod != null)
+ sb.append(commonGenerateMethod.invoke(converter, codeType, field, versionSet,
+ indentSize, tabSize, itr.hasNext()));
+ }
+ else if (mangledGenerateMethod != null) // Version-mangled
+ {
+ sb.append(mangledGenerateMethod.invoke(converter, field, indentSize, tabSize,
+ itr.hasNext()));
+ }
+ }
+ return sb.toString();
+ }
+
+ public String parseFieldMapOrdinally(Method generateMethod, Method bitGenerateMethod,
+ int indentSize, int tabSize, Generator codeGenerator)
+ throws AmqpTypeMappingException, IllegalAccessException, InvocationTargetException
+ {
+ String indent = Utils.createSpaces(indentSize);
+ String cr = Utils.lineSeparator;
+ StringBuffer sb = new StringBuffer();
+
+ // Generate warnings in code if required methods are null.
+ if (generateMethod == null || bitGenerateMethod == null)
+ {
+ sb.append(indent + "/***********************************************" + cr);
+ sb.append(indent + " * WARNING: In call to parseFieldMapOrdinally():" + cr);
+ if (generateMethod == null)
+ sb.append(indent + " * => generateMethod is null." + cr);
+ if (bitGenerateMethod == null)
+ sb.append(indent + " * => bitGenerateMethod is null." + cr);
+ sb.append(indent + " * Generated code could be missing." + cr);
+ sb.append(indent + " * Check for NoSuchMethodException on startup." + cr);
+ sb.append(indent + " ***********************************************/" + cr);
+ }
+
+ /* We must process elements in ordinal order because adjacent booleans (bits)
+ * must be combined into a single byte (in groups of up to 8). Start with shared
+ * declarations until an ordinal divergence is found. (For most methods where
+ * there is no difference between versions, this will simplify the generated
+ * code. */
+
+ ArrayList<String> bitFieldList = new ArrayList<String>();
+ boolean ordinalDivergenceFlag = false;
+ int ordinal = 0;
+ while (ordinal < size() && !ordinalDivergenceFlag)
+ {
+ /* Since the getFieldMapOrdinal() function may map more than one Field to
+ * an ordinal, the number of ordinals may be less than the total number of
+ * fields in the fieldMap. Check for empty fieldmaps... */
+ AmqpFieldMap ordinalFieldMap = getFieldMapForOrdinal(ordinal);
+ if (ordinalFieldMap.size() > 0)
+ {
+ if (ordinalFieldMap.isDomainConsistent(codeGenerator, codeGenerator.globalVersionSet))
+ {
+ String fieldName = ordinalFieldMap.firstKey();
+ String domain = ordinalFieldMap.get(fieldName).domainMap.firstKey();
+ String domainType = codeGenerator.getDomainType(domain,
+ codeGenerator.globalVersionSet.first());
+ if (domainType.compareTo("bit") == 0)
+ bitFieldList.add(fieldName);
+ else if (bitFieldList.size() > 0)
+ {
+ // End of bit types - handle deferred bit type generation
+ if (bitGenerateMethod != null)
+ sb.append(bitGenerateMethod.invoke(codeGenerator, bitFieldList, ordinal,
+ indentSize, tabSize));
+ bitFieldList.clear();
+ }
+ if (!ordinalDivergenceFlag)
+ {
+ // Defer generation of bit types until all adjacent bits have been
+ // accounted for.
+ if (bitFieldList.size() == 0 && generateMethod != null)
+ sb.append(generateMethod.invoke(codeGenerator, domainType, fieldName, ordinal,
+ indentSize, tabSize));
+ }
+ ordinal++;
+ }
+ else
+ {
+ ordinalDivergenceFlag = true;
+ }
+ }
+ }
+
+ // Check if there is still more to do under a version-specific breakout
+ if (ordinalDivergenceFlag && ordinal< size())
+ {
+ // 1. Cycle through all versions in order, create outer if(version) structure
+ AmqpVersion[] versionArray = new AmqpVersion[codeGenerator.globalVersionSet.size()];
+ codeGenerator.globalVersionSet.toArray(versionArray);
+ for (int v=0; v<versionArray.length; v++)
+ {
+ sb.append(indent);
+ if (v > 0)
+ sb.append("else ");
+ sb.append("if (major == " + versionArray[v].getMajor() + " && minor == " +
+ versionArray[v].getMinor() + ")" + cr);
+ sb.append(indent + "{" + cr);
+
+ // 2. Cycle though each ordinal from where we left off in the loop above.
+ ArrayList<String> bitFieldList2 = new ArrayList<String>(bitFieldList);
+ for (int o = ordinal; o<size(); o++)
+ {
+ AmqpFieldMap ordinalFieldMap = getFieldMapForOrdinal(o);
+ if (ordinalFieldMap.size() > 0)
+ {
+ // 3. Cycle through each of the fields that have this ordinal.
+ Iterator<String> i = ordinalFieldMap.keySet().iterator();
+ while (i.hasNext())
+ {
+ String fieldName = i.next();
+ AmqpField field = ordinalFieldMap.get(fieldName);
+
+ // 4. Some fields may have more than one ordinal - match by both
+ // ordinal and version.
+ Iterator<Integer> j = field.ordinalMap.keySet().iterator();
+ while (j.hasNext())
+ {
+ int thisOrdinal = j.next();
+ AmqpVersionSet v1 = field.ordinalMap.get(thisOrdinal);
+ if (thisOrdinal == o && v1.contains(versionArray[v]))
+ {
+ // 5. Now get the domain for this version
+ int domainCntr = 0;
+ Iterator<String> k = field.domainMap.keySet().iterator();
+ while (k.hasNext())
+ {
+ // Mangle domain-divergent field names
+ String mangledFieldName = fieldName;
+ if (field.domainMap.size() > 1)
+ mangledFieldName += "_" + (domainCntr++);
+ String domainName = k.next();
+ AmqpVersionSet v2 = field.domainMap.get(domainName);
+ if (v2.contains(versionArray[v]))
+ {
+ // 6. (Finally!!) write the declaration
+ String domainType = codeGenerator.getDomainType(domainName,
+ versionArray[v]);
+ if (domainType.compareTo("bit") == 0)
+ bitFieldList2.add(mangledFieldName);
+ else if (bitFieldList2.size() > 0)
+ {
+ // End of bit types - handle deferred bit type generation
+ if (bitGenerateMethod != null)
+ sb.append(bitGenerateMethod.invoke(codeGenerator,
+ bitFieldList2, o, indentSize + tabSize,
+ tabSize));
+ bitFieldList2.clear();
+ }
+ // Defer generation of bit types until all adjacent bits have
+ // been accounted for.
+ if (bitFieldList2.size() == 0 && generateMethod != null)
+ sb.append(generateMethod.invoke(codeGenerator, domainType,
+ mangledFieldName, o, indentSize + tabSize, tabSize));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ // Check for remaining deferred bits
+ if (bitFieldList2.size() > 0 && bitGenerateMethod != null)
+ sb.append(bitGenerateMethod.invoke(codeGenerator, bitFieldList2, size(),
+ indentSize + tabSize, tabSize));
+ sb.append(indent + "}" + cr);
+ }
+ }
+ // Check for remaining deferred bits
+ else if (bitFieldList.size() > 0 && bitGenerateMethod != null)
+ sb.append(bitGenerateMethod.invoke(codeGenerator, bitFieldList, size(),
+ indentSize, tabSize));
+ return sb.toString();
+ }
+
+ public boolean isVersionConsistent(AmqpVersionSet globalVersionSet)
+ {
+ for (String thisFieldName : keySet())
+ {
+ AmqpField field = get(thisFieldName);
+ if (!field.isVersionConsistent(globalVersionSet))
+ return false;
+ }
+ return true;
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpFieldMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,47 @@
+/*
+ *
+ * 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.TreeMap;
+
+@SuppressWarnings("serial")
+public class AmqpFlagMap extends TreeMap<Boolean, AmqpVersionSet> implements VersionConsistencyCheck
+{
+ public boolean isSet()
+ {
+ return containsKey(true);
+ }
+
+ public String toString()
+ {
+ AmqpVersionSet versionSet = get(true);
+ if (versionSet != null)
+ return versionSet.toString();
+ return "";
+ }
+
+ public boolean isVersionConsistent(AmqpVersionSet globalVersionSet)
+ {
+ if (size() != 1)
+ return false;
+ return get(firstKey()).equals(globalVersionSet);
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpMethod.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpMethod.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpMethod.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpMethod.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,174 @@
+/*
+ *
+ * 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.io.PrintStream;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class AmqpMethod implements Printable, NodeAware, VersionConsistencyCheck
+{
+ public LanguageConverter converter;
+ public AmqpVersionSet versionSet;
+ public AmqpFieldMap fieldMap;
+ public String name;
+ public AmqpOrdinalVersionMap indexMap;
+ public AmqpFlagMap clientMethodFlagMap; // Method called on client (<chassis name="server"> in XML)
+ public AmqpFlagMap serverMethodFlagMap; // Method called on server (<chassis name="client"> in XML)
+
+ public AmqpMethod(String name, LanguageConverter converter)
+ {
+ this.name = name;
+ this.converter = converter;
+ versionSet = new AmqpVersionSet();
+ fieldMap = new AmqpFieldMap();
+ indexMap = new AmqpOrdinalVersionMap();
+ clientMethodFlagMap = new AmqpFlagMap();
+ serverMethodFlagMap = new AmqpFlagMap();
+ }
+
+ public void addFromNode(Node methodNode, int ordinal, AmqpVersion version)
+ throws AmqpParseException, AmqpTypeMappingException
+ {
+ boolean serverChassisFlag = false;
+ boolean clientChassisFlag = false;
+ versionSet.add(version);
+ int index = Utils.getNamedIntegerAttribute(methodNode, "index");
+ AmqpVersionSet versionSet = indexMap.get(index);
+ if (versionSet != null)
+ versionSet.add(version);
+ else
+ {
+ versionSet = new AmqpVersionSet();
+ versionSet.add(version);
+ indexMap.put(index, versionSet);
+ }
+ NodeList nList = methodNode.getChildNodes();
+ int fieldCntr = 0;
+ for (int i=0; i<nList.getLength(); i++)
+ {
+ Node child = nList.item(i);
+ if (child.getNodeName().compareTo(Utils.ELEMENT_FIELD) == 0)
+ {
+ String fieldName = converter.prepareDomainName(Utils.getNamedAttribute(child, Utils.ATTRIBUTE_NAME));
+ AmqpField thisField = fieldMap.get(fieldName);
+ if (thisField == null)
+ {
+ thisField = new AmqpField(fieldName, converter);
+ fieldMap.put(fieldName, thisField);
+ }
+ thisField.addFromNode(child, fieldCntr++, version);
+ }
+ if (child.getNodeName().compareTo(Utils.ELEMENT_CHASSIS) == 0)
+ {
+ String chassisName = Utils.getNamedAttribute(child, Utils.ATTRIBUTE_NAME);
+ if (chassisName.compareTo("server") == 0)
+ serverChassisFlag = true;
+ else if (chassisName.compareTo("client") == 0)
+ clientChassisFlag = true;
+ }
+ }
+ processChassisFlags(serverChassisFlag, clientChassisFlag, version);
+ }
+
+ public void print(PrintStream out, int marginSize, int tabSize)
+ {
+ String margin = Utils.createSpaces(marginSize);
+ String tab = Utils.createSpaces(tabSize);
+ out.println(margin + "[M] " + name + " {" + (serverMethodFlagMap.isSet() ? "S " +
+ serverMethodFlagMap + (clientMethodFlagMap.isSet() ? ", " : "") : "") +
+ (clientMethodFlagMap.isSet() ? "C " + clientMethodFlagMap : "") + "}" + ": " + versionSet);
+
+ for (Integer thisIndex : indexMap.keySet())
+ {
+ AmqpVersionSet indexVersionSet = indexMap.get(thisIndex);
+ out.println(margin + tab + "[I] " + thisIndex + indexVersionSet);
+ }
+
+ for (String thisFieldName : fieldMap.keySet())
+ {
+ AmqpField thisField = fieldMap.get(thisFieldName);
+ thisField.print(out, marginSize + tabSize, tabSize);
+ }
+ }
+
+ protected void processChassisFlags(boolean serverFlag, boolean clientFlag, AmqpVersion version)
+ {
+ AmqpVersionSet versionSet = serverMethodFlagMap.get(serverFlag);
+ if (versionSet != null)
+ versionSet.add(version);
+ else
+ {
+ versionSet = new AmqpVersionSet();
+ versionSet.add(version);
+ serverMethodFlagMap.put(serverFlag, versionSet);
+ }
+
+ versionSet = clientMethodFlagMap.get(clientFlag);
+ if (versionSet != null)
+ versionSet.add(version);
+ else
+ {
+ versionSet = new AmqpVersionSet();
+ versionSet.add(version);
+ clientMethodFlagMap.put(clientFlag, versionSet);
+ }
+ }
+
+ public AmqpOverloadedParameterMap getOverloadedParameterLists(AmqpVersionSet globalVersionSet,
+ Generator generator)
+ throws AmqpTypeMappingException
+ {
+ AmqpOverloadedParameterMap parameterVersionMap = new AmqpOverloadedParameterMap();
+ for (AmqpVersion thisVersion : globalVersionSet)
+ {
+ AmqpOrdinalFieldMap ordinalFieldMap = fieldMap.getMapForVersion(thisVersion, true, generator);
+ AmqpVersionSet methodVersionSet = parameterVersionMap.get(ordinalFieldMap);
+ if (methodVersionSet == null)
+ {
+ methodVersionSet = new AmqpVersionSet();
+ methodVersionSet.add(thisVersion);
+ parameterVersionMap.put(ordinalFieldMap, methodVersionSet);
+ }
+ else
+ {
+ methodVersionSet.add(thisVersion);
+ }
+ }
+ return parameterVersionMap;
+ }
+
+ public boolean isVersionConsistent(AmqpVersionSet globalVersionSet)
+ {
+ if (!versionSet.equals(globalVersionSet))
+ return false;
+ if (!clientMethodFlagMap.isVersionConsistent(globalVersionSet))
+ return false;
+ if (!serverMethodFlagMap.isVersionConsistent(globalVersionSet))
+ return false;
+ if (!indexMap.isVersionConsistent(globalVersionSet))
+ return false;
+ if (!fieldMap.isVersionConsistent(globalVersionSet))
+ return false;
+ return true;
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpMethod.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpMethodMap.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpMethodMap.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpMethodMap.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpMethodMap.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,29 @@
+/*
+ *
+ * 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.TreeMap;
+
+@SuppressWarnings("serial")
+public class AmqpMethodMap extends TreeMap<String, AmqpMethod>
+{
+
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpMethodMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpModel.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpModel.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpModel.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpModel.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,74 @@
+/*
+ *
+ * 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.io.PrintStream;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class AmqpModel implements Printable, NodeAware
+{
+ public LanguageConverter converter;
+ public AmqpClassMap classMap;
+
+ public AmqpModel(LanguageConverter converter)
+ {
+ this.converter = converter;
+ this.converter.setModel(this);
+ classMap = new AmqpClassMap();
+ }
+
+ public void addFromNode(Node n, int o, AmqpVersion v)
+ throws AmqpParseException, AmqpTypeMappingException
+ {
+ NodeList nList = n.getChildNodes();
+ int eCntr = 0;
+ for (int i=0; i<nList.getLength(); i++)
+ {
+ Node c = nList.item(i);
+ if (c.getNodeName().compareTo(Utils.ELEMENT_CLASS) == 0)
+ {
+ String className = converter.prepareClassName(Utils.getNamedAttribute(c, Utils.ATTRIBUTE_NAME));
+ AmqpClass thisClass = classMap.get(className);
+ if (thisClass == null)
+ {
+ thisClass = new AmqpClass(className, converter);
+ classMap.put(className, thisClass);
+ }
+ thisClass.addFromNode(c, eCntr++, v);
+ }
+ }
+ }
+
+ public void print(PrintStream out, int marginSize, int tabSize)
+ {
+ out.println(Utils.createSpaces(marginSize) +
+ "[C]=class; [M]=method; [F]=field; [D]=domain; [I]=index; [O]=ordinal" + Utils.lineSeparator);
+ out.println(Utils.createSpaces(marginSize) + "Model:");
+
+ for (String thisClassName : classMap.keySet())
+ {
+ AmqpClass thisClass = classMap.get(thisClassName);
+ thisClass.print(out, marginSize + tabSize, tabSize);
+ }
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpModel.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,89 @@
+/*
+ *
+ * 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.Iterator;
+import java.util.Set;
+import java.util.TreeMap;
+
+@SuppressWarnings("serial")
+public class AmqpOrdinalFieldMap extends TreeMap<Integer, String[]> implements Comparable
+{
+ protected static final int FIELD_DOMAIN = 1;
+ protected boolean codeTypeFlag = false;
+
+ public int compareTo(Object obj)
+ {
+ AmqpOrdinalFieldMap o = (AmqpOrdinalFieldMap)obj;
+ Set<Integer> thisKeySet = keySet();
+ Set<Integer> oKeySet = o.keySet();
+ if (!thisKeySet.equals(oKeySet)) // Not equal, but why?
+ {
+ // Size difference
+ int sizeDiff = thisKeySet.size() - oKeySet.size(); // -ve if this < other
+ if (sizeDiff != 0)
+ return sizeDiff;
+ // Conetent difference
+ Iterator<Integer> itr = thisKeySet.iterator();
+ Iterator<Integer> oItr = oKeySet.iterator();
+ while (itr.hasNext() && oItr.hasNext())
+ {
+ int diff = itr.next() - oItr.next(); // -ve if this < other
+ if (diff != 0)
+ return diff;
+ }
+ // We should never get here...
+ System.err.println("AmqpOrdinalFieldMap.compareTo(): " +
+ "WARNING - unable to find cause of keySet difference.");
+ }
+ // Keys are equal, now check the String[]s
+ Iterator<Integer> itr = thisKeySet.iterator();
+ Iterator<Integer> oItr = oKeySet.iterator();
+ while (itr.hasNext() && oItr.hasNext())
+ {
+ String[] thisPair = get(itr.next());
+ String[] oPair = o.get(oItr.next());
+ // Size difference
+ int sizeDiff = thisPair.length - oPair.length; // -ve if this < other
+ if (sizeDiff != 0)
+ return sizeDiff;
+ // Conetent difference
+ for (int i=0; i<thisPair.length; i++)
+ {
+ int diff = thisPair[i].compareTo(oPair[i]);
+ if (diff != 0)
+ return diff;
+ }
+ }
+ return 0;
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ for (Integer thisOrdinal : keySet())
+ {
+ String[] pair = get(thisOrdinal);
+ sb.append("[" + thisOrdinal + "] " + pair[0] + " : " + pair[1] + Utils.lineSeparator);
+ }
+ return sb.toString();
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,46 @@
+/*
+ *
+ * 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.TreeMap;
+
+@SuppressWarnings("serial")
+public class AmqpOrdinalVersionMap extends TreeMap<Integer, AmqpVersionSet> implements VersionConsistencyCheck
+{
+ public boolean isVersionConsistent(AmqpVersionSet globalVersionSet)
+ {
+ if (size() != 1)
+ return false;
+ return get(firstKey()).equals(globalVersionSet);
+ }
+
+ public int getOrdinal(AmqpVersion version)
+ throws AmqpTypeMappingException
+ {
+ for (Integer thisOrdinal : keySet())
+ {
+ AmqpVersionSet versionSet = get(thisOrdinal);
+ if (versionSet.contains(version))
+ return thisOrdinal;
+ }
+ throw new AmqpTypeMappingException("Unable to locate version " + version + " in ordianl version map.");
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,29 @@
+/*
+ *
+ * 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.TreeMap;
+
+@SuppressWarnings("serial")
+public class AmqpOverloadedParameterMap extends TreeMap<AmqpOrdinalFieldMap, AmqpVersionSet>
+{
+
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpParseException.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpParseException.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpParseException.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpParseException.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,30 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.gentools;
+
+@SuppressWarnings("serial")
+public class AmqpParseException extends Exception
+{
+ public AmqpParseException(String msg)
+ {
+ super(msg);
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpParseException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpTemplateException.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpTemplateException.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpTemplateException.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpTemplateException.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,30 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.gentools;
+
+@SuppressWarnings("serial")
+public class AmqpTemplateException extends Exception
+{
+ public AmqpTemplateException(String msg)
+ {
+ super(msg);
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpTemplateException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpTypeMappingException.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpTypeMappingException.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpTypeMappingException.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpTypeMappingException.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,30 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.gentools;
+
+@SuppressWarnings("serial")
+public class AmqpTypeMappingException extends Exception
+{
+ public AmqpTypeMappingException(String msg)
+ {
+ super(msg);
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpTypeMappingException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpVersion.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpVersion.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpVersion.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpVersion.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,62 @@
+/*
+ *
+ * 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 AmqpVersion implements Comparable<AmqpVersion>
+{
+ private int major;
+ private int minor;
+
+ public AmqpVersion(int major, int minor)
+ {
+ this.major = major;
+ this.minor = minor;
+ }
+
+ public int getMajor()
+ {
+ return major;
+ }
+
+ public int getMinor()
+ {
+ return minor;
+ }
+
+ public int compareTo(AmqpVersion v)
+ {
+ if (major != v.major)
+ return major - v.major;
+ if (minor != v.minor)
+ return minor - v.minor;
+ return 0;
+ }
+
+ public String namespace()
+ {
+ return "ver_" + major + "_" + minor;
+ }
+
+ public String toString()
+ {
+ return major + "-" + minor;
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpVersion.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpVersionSet.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpVersionSet.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpVersionSet.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpVersionSet.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,62 @@
+/*
+ *
+ * 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.io.PrintStream;
+//import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.TreeSet;
+
+@SuppressWarnings("serial")
+public class AmqpVersionSet extends TreeSet<AmqpVersion> implements Printable, Comparable<AmqpVersionSet>
+{
+ public AmqpVersionSet()
+ {
+ }
+
+ public AmqpVersionSet(AmqpVersion version)
+ {
+ add(version);
+ }
+
+ public void print(PrintStream out, int marginSize, int tabSize)
+ {
+ out.print(Utils.createSpaces(marginSize) + "Version Set: " + toString() + Utils.lineSeparator);
+ }
+
+ public int compareTo(AmqpVersionSet other)
+ {
+ int res = size() - other.size();
+ if (res != 0)
+ return res;
+ Iterator<AmqpVersion> vItr = iterator();
+ Iterator<AmqpVersion> oItr = other.iterator();
+ while (vItr.hasNext() && oItr.hasNext())
+ {
+ AmqpVersion version = vItr.next();
+ AmqpVersion oVersion = oItr.next();
+ res = version.compareTo(oVersion);
+ if (res != 0)
+ return res;
+ }
+ return 0;
+ }
+}
Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/AmqpVersionSet.java
------------------------------------------------------------------------------
svn:eol-style = native