diff options
author | Kim van der Riet <kpvdr@apache.org> | 2006-11-21 19:55:21 +0000 |
---|---|---|
committer | Kim van der Riet <kpvdr@apache.org> | 2006-11-21 19:55:21 +0000 |
commit | b6467c35980d26c81a9bb875151c9b3d912323d9 (patch) | |
tree | 5ffc4135a7b905c0e45280fdeac455a4cdce7d1f /qpid/gentools | |
parent | 40a369245fe1f71f59dadb1318a9ae01ec70ddc2 (diff) | |
download | qpid-python-b6467c35980d26c81a9bb875151c9b3d912323d9.tar.gz |
Directory reorganization
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@477853 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/gentools')
31 files changed, 0 insertions, 6255 deletions
diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpClass.java b/qpid/gentools/org/apache/qpid/gentools/AmqpClass.java deleted file mode 100644 index b8a7769bbc..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpClass.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * - * 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 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); - - Iterator<Integer> iItr = indexMap.keySet().iterator(); - while (iItr.hasNext()) - { - int index = iItr.next(); - AmqpVersionSet indexVersionSet = indexMap.get(index); - out.println(margin + tab + "[I] " + index + indexVersionSet); - } - - Iterator<String> sItr = fieldMap.keySet().iterator(); - while (sItr.hasNext()) - { - AmqpField thisField = fieldMap.get(sItr.next()); - thisField.print(out, marginSize + tabSize, tabSize); - } - - sItr = methodMap.keySet().iterator(); - while (sItr.hasNext()) - { - AmqpMethod thisMethod = methodMap.get(sItr.next()); - thisMethod.print(out, marginSize + tabSize, tabSize); - } - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpClassMap.java b/qpid/gentools/org/apache/qpid/gentools/AmqpClassMap.java deleted file mode 100644 index 01d4df283b..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpClassMap.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * - * 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> -{ - -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpConstant.java b/qpid/gentools/org/apache/qpid/gentools/AmqpConstant.java deleted file mode 100644 index 9ff69600bb..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpConstant.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * - * 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.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 - { - Iterator<String> sItr = keySet().iterator(); - while (sItr.hasNext()) - { - String value = sItr.next(); - AmqpVersionSet versionSet = get(value); - if (versionSet.contains(version)) - return value; - } - 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); - Iterator<String> sItr = keySet().iterator(); - while (sItr.hasNext()) - { - String value = sItr.next(); - out.println(margin + tab + tab + "= \"" + value + "\" " + get(value)); - } - } - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpConstantSet.java b/qpid/gentools/org/apache/qpid/gentools/AmqpConstantSet.java deleted file mode 100644 index 93e2d5a7ee..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpConstantSet.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * - * 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; - Iterator<String> vItr = thisConstant.keySet().iterator(); - while (vItr.hasNext() && !foundValue) - { - String thisValue = vItr.next(); - 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: "); - Iterator<AmqpConstant> cItr = iterator(); - while (cItr.hasNext()) - { - cItr.next().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; - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpDomain.java b/qpid/gentools/org/apache/qpid/gentools/AmqpDomain.java deleted file mode 100644 index ecb1285ef2..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpDomain.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * - * 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.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 - { - Iterator<String> i = keySet().iterator(); - while (i.hasNext()) - { - String type = i.next(); - AmqpVersionSet versionSet = get(type); - if (versionSet.contains(version)) - return type; - } 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 + ":"); - - Iterator<String> i = keySet().iterator(); - while (i.hasNext()) - { - String type = i.next(); - AmqpVersionSet vs = get(type); - out.println(margin + tab + type + " : " + vs.toString()); - } - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpDomainMap.java b/qpid/gentools/org/apache/qpid/gentools/AmqpDomainMap.java deleted file mode 100644 index d653bd5fed..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpDomainMap.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * - * 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.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:"); - Iterator<String> i = keySet().iterator(); - while (i.hasNext()) - { - String domainName = i.next(); - AmqpDomain domain = get(domainName); - domain.print(out, marginSize + tabSize, tabSize); - } - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpDomainVersionMap.java b/qpid/gentools/org/apache/qpid/gentools/AmqpDomainVersionMap.java deleted file mode 100644 index 6cd632a9d6..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpDomainVersionMap.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * 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); - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpField.java b/qpid/gentools/org/apache/qpid/gentools/AmqpField.java deleted file mode 100644 index 02ac7a7599..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpField.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * - * 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 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>(); - Iterator<String> itr = domainMap.keySet().iterator(); - while (itr.hasNext()) - { - String domainName = itr.next(); - AmqpVersionSet versionSet = domainMap.get(domainName); - String codeType = converter.getGeneratedType(domainName, 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; - Iterator<String> itr = domainMap.keySet().iterator(); - while (itr.hasNext()) - vCntr += domainMap.get(itr.next()).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); - - Iterator<Integer> iItr = ordinalMap.keySet().iterator(); - while (iItr.hasNext()) - { - Integer ordinalValue = iItr.next(); - AmqpVersionSet versionList = ordinalMap.get(ordinalValue); - out.println(margin + " [O] " + ordinalValue + " : " + versionList.toString()); - } - - Iterator<String> sItr = domainMap.keySet().iterator(); - while (sItr.hasNext()) - { - String domainKey = sItr.next(); - AmqpVersionSet versionList = domainMap.get(domainKey); - out.println(margin + " [D] " + domainKey + " : " + 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; - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpFieldMap.java b/qpid/gentools/org/apache/qpid/gentools/AmqpFieldMap.java deleted file mode 100644 index adb5793b44..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpFieldMap.java +++ /dev/null @@ -1,332 +0,0 @@ -/* - * - * 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(); - Iterator<String> fItr = keySet().iterator(); - while (fItr.hasNext()) - { - AmqpField field = get(fItr.next()); - 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 - { - AmqpOrdinalFieldMap ordinalFieldMap = new AmqpOrdinalFieldMap(); - Iterator<String> fItr = keySet().iterator(); - while (fItr.hasNext()) - { - AmqpField field = get(fItr.next()); - if (version == null || field.versionSet.contains(version)) - { - String domain = ""; - boolean dFound = false; - Iterator<String> dItr = field.domainMap.keySet().iterator(); - while (dItr.hasNext() && !dFound) - { - domain = dItr.next(); - AmqpVersionSet versionSet = field.domainMap.get(domain); - if (version == null || versionSet.contains(version)) - { - if (codeTypeFlag) - domain = converter.getGeneratedType(domain, version); - dFound = true; - } - } - - int ordinal = -1; - boolean oFound = false; - Iterator<Integer> oItr = field.ordinalMap.keySet().iterator(); - while (oItr.hasNext() && !oFound) - { - ordinal = oItr.next(); - 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; - Iterator<String> fItr = keySet().iterator(); - while (fItr.hasNext()) - { - AmqpField field = get(fItr.next()); - 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) -// int indentSize, int tabSize, AmqpVersionSet versionSet, AmqpDomainMap globalDomainMap) - 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) - { - Iterator<String> fItr = keySet().iterator(); - while (fItr.hasNext()) - { - AmqpField field = get(fItr.next()); - if (!field.isVersionConsistent(globalVersionSet)) - return false; - } - return true; - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpFlagMap.java b/qpid/gentools/org/apache/qpid/gentools/AmqpFlagMap.java deleted file mode 100644 index 88f337cbe3..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpFlagMap.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * - * 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); - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpMethod.java b/qpid/gentools/org/apache/qpid/gentools/AmqpMethod.java deleted file mode 100644 index 5a8a9db50e..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpMethod.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * - * 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 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); - - Iterator<Integer> iItr = indexMap.keySet().iterator(); - while (iItr.hasNext()) - { - int index = iItr.next(); - AmqpVersionSet indexVersionSet = indexMap.get(index); - out.println(margin + tab + "[I] " + index + indexVersionSet); - } - - Iterator<String> sItr = fieldMap.keySet().iterator(); - while (sItr.hasNext()) - { - AmqpField thisField = fieldMap.get(sItr.next()); - 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(); - Iterator<AmqpVersion> vItr = globalVersionSet.iterator(); - while (vItr.hasNext()) - { - AmqpVersion version = vItr.next(); - AmqpOrdinalFieldMap ordinalFieldMap = fieldMap.getMapForVersion(version, true, generator); - AmqpVersionSet methodVersionSet = parameterVersionMap.get(ordinalFieldMap); - if (methodVersionSet == null) - { - methodVersionSet = new AmqpVersionSet(); - methodVersionSet.add(version); - parameterVersionMap.put(ordinalFieldMap, methodVersionSet); - } - else - { - methodVersionSet.add(version); - } - } - 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; - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpMethodMap.java b/qpid/gentools/org/apache/qpid/gentools/AmqpMethodMap.java deleted file mode 100644 index 25a41df131..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpMethodMap.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * - * 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> -{ - -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpModel.java b/qpid/gentools/org/apache/qpid/gentools/AmqpModel.java deleted file mode 100644 index 7143c4e8ca..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpModel.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * - * 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 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:"); - - Iterator<String> i = classMap.keySet().iterator(); - while (i.hasNext()) - { - String className = i.next(); - AmqpClass thisClass = classMap.get(className); - thisClass.print(out, marginSize + tabSize, tabSize); - } - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java b/qpid/gentools/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java deleted file mode 100644 index e1495cda5a..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * - * 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(); - Iterator<Integer> itr = keySet().iterator(); - while (itr.hasNext()) - { - int ordinal = itr.next(); - String[] pair = get(ordinal); - sb.append("[" + ordinal + "] " + pair[0] + " : " + pair[1] + Utils.lineSeparator); - } - return sb.toString(); - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java b/qpid/gentools/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java deleted file mode 100644 index 234e3452a2..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * 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.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 - { - Iterator<Integer> itr = keySet().iterator(); - while (itr.hasNext()) - { - int ordinal = itr.next(); - AmqpVersionSet versionSet = get(ordinal); - if (versionSet.contains(version)) - return ordinal; - } - throw new AmqpTypeMappingException("Unable to locate version " + version + " in ordianl version map."); - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java b/qpid/gentools/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java deleted file mode 100644 index 10978d0e4a..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * - * 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> -{ - -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpParseException.java b/qpid/gentools/org/apache/qpid/gentools/AmqpParseException.java deleted file mode 100644 index 4d9f495390..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpParseException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * 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); - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpTemplateException.java b/qpid/gentools/org/apache/qpid/gentools/AmqpTemplateException.java deleted file mode 100644 index b1e6f3d712..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpTemplateException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * 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); - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpTypeMappingException.java b/qpid/gentools/org/apache/qpid/gentools/AmqpTypeMappingException.java deleted file mode 100644 index 1053543fdd..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpTypeMappingException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * 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); - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpVersion.java b/qpid/gentools/org/apache/qpid/gentools/AmqpVersion.java deleted file mode 100644 index 0c0c5a5cbf..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpVersion.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * - * 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; - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/AmqpVersionSet.java b/qpid/gentools/org/apache/qpid/gentools/AmqpVersionSet.java deleted file mode 100644 index 06b10cfda6..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/AmqpVersionSet.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * - * 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; - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/CppGenerator.java b/qpid/gentools/org/apache/qpid/gentools/CppGenerator.java deleted file mode 100644 index f6dea0f669..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/CppGenerator.java +++ /dev/null @@ -1,1726 +0,0 @@ -/* - * - * 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.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.TreeMap; - -public class CppGenerator extends Generator -{ - protected static final String versionNamespaceStartToken = "${version_namespace_start}"; - protected static final String versionNamespaceEndToken = "${version_namespace_end}"; - protected static final int FIELD_NAME = 0; - protected static final int FIELD_DOMAIN = 1; - - /** - * A complete list of C++ reserved words. The names of varous XML elements within the AMQP - * specification file are used for C++ identifier names in the generated code. Each proposed - * name is checked against this list and is modified (by adding an '_' to the end of the - * name - see function parseForReservedWords()) if found to be present. - */ - protected static final String[] cppReservedWords = {"and", "and_eq", "asm", "auto", "bitand", - "bitor", "bool", "break", "case", "catch", "char", "class", "compl", "const", "const_cast", - "continue", "default", "delete", "do", "DomainInfo", "double", "dynamic_cast", "else", - "enum", "explicit", "extern", "false", "float", "for", "friend", "goto", "if", "inline", - "int", "long", "mutable", "namespace", "new", "not", "not_eq", "operator", "or", "or_eq", - "private", "protected", "public", "register", "reinterpret_cast", "return", "short", - "signed", "sizeof", "static", "static_cast", "struct", "switch", "template", "this", - "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", - "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq"}; - - /** - * Although not reserved words, the following list of variable names that may cause compile - * problems within a C++ environment because they clash with common #includes. The names of - * varous XML elements within the AMQP specification file are used for C++ identifier names - * in the generated code. Each proposed name is checked against this list and is modified - * (by adding an '_' to the end of the name - see function parseForReservedWords()) if found - * to be present. This list is best added to on an as-needed basis. - */ - protected static final String[] cppCommonDefines = {"string"}; - - // TODO: Move this to the Generator superclass? - protected boolean quietFlag; // Supress warning messages to the console - - private class DomainInfo - { - public String type; - public String size; - public String encodeExpression; - public String decodeExpression; - public DomainInfo(String domain, String size, String encodeExpression, - String decodeExpression) - { - this.type = domain; - this.size = size; - this.encodeExpression = encodeExpression; - this.decodeExpression = decodeExpression; - } - } - - private static TreeMap<String, DomainInfo> typeMap = new TreeMap<String, DomainInfo>(); - - public CppGenerator(AmqpVersionSet versionList) - { - super(versionList); - quietFlag = true; - // Load C++ type and size maps. - // Adjust or add to these lists as new types are added/defined. - // The char '#' will be replaced by the field variable name (any type). - // The char '~' will be replaced by the compacted bit array size (type bit only). - typeMap.put("bit", new DomainInfo( - "bool", // type - "~", // size - "", // encodeExpression - "")); // decodeExpression - typeMap.put("long", new DomainInfo( - "u_int32_t", // type - "4", // size - "buffer.putLong(#)", // encodeExpression - "# = buffer.getLong()")); // decodeExpression - typeMap.put("longlong", new DomainInfo( - "u_int64_t", // type - "8", // size - "buffer.putLongLong(#)", // encodeExpression - "# = buffer.getLongLong()")); // decodeExpression - typeMap.put("longstr", new DomainInfo( - "string", // type - "4 + #.length()", // size - "buffer.putLongString(#)", // encodeExpression - "buffer.getLongString(#)")); // decodeExpression - typeMap.put("octet", new DomainInfo( - "u_int8_t", // type - "1", // size - "buffer.putOctet(#)", // encodeExpression - "# = buffer.getOctet()")); // decodeExpression - typeMap.put("short", new DomainInfo( - "u_int16_t", // type - "2", // size - "buffer.putShort(#)", // encodeExpression - "# = buffer.getShort()")); // decodeExpression - typeMap.put("shortstr", new DomainInfo( - "string", // type - "1 + #.length()", // size - "buffer.putShortString(#)", // encodeExpression - "buffer.getShortString(#)")); // decodeExpression - typeMap.put("table", new DomainInfo( - "FieldTable", // type - "#.size()", // size - "buffer.putFieldTable(#)", // encodeExpression - "buffer.getFieldTable(#)")); // decodeExpression - typeMap.put("timestamp", new DomainInfo( - "u_int64_t", // type - "8", // size - "buffer.putLongLong(#)", // encodeExpression - "buffer.getLongLong(#)")); // decodeExpression - } - - public boolean isQuietFlag() - { - return quietFlag; - } - - public void setQuietFlag(boolean quietFlag) - { - this.quietFlag = quietFlag; - } - - // === Start of methods for Interface LanguageConverter === - - public String prepareClassName(String className) - { - return camelCaseName(className, true); - } - - public String prepareMethodName(String methodName) - { - return camelCaseName(methodName, false); - } - - public String prepareDomainName(String domainName) - { - return camelCaseName(domainName, false); - } - - public String getDomainType(String domainName, AmqpVersion version) - throws AmqpTypeMappingException - { - if (version == null) - version = globalVersionSet.first(); - return globalDomainMap.getDomainType(domainName, version); - } - - public String getGeneratedType(String domainName, AmqpVersion version) - throws AmqpTypeMappingException - { - String domainType = getDomainType(domainName, version); - if (domainType == null) - throw new AmqpTypeMappingException("Domain type \"" + domainName + - "\" not found in C++ typemap."); - return typeMap.get(domainType).type; - } - - // === Abstract methods from class Generator - C++-specific implementation === - - @Override - protected String prepareFilename(String filenameTemplate, AmqpClass thisClass, AmqpMethod method, - AmqpField field) - { - StringBuffer sb = new StringBuffer(filenameTemplate); - if (thisClass != null) - replaceToken(sb, "${CLASS}", thisClass.name); - if (method != null) - replaceToken(sb, "${METHOD}", method.name); - if (field != null) - replaceToken(sb, "${FIELD}", field.name); - return sb.toString(); - } - - @Override - protected void processTemplateA(String[] template) - throws IOException, AmqpTemplateException, AmqpTypeMappingException, - IllegalAccessException, InvocationTargetException - { - processTemplateD(template, null, null, null); - } - - @Override - protected void processTemplateB(String[] template, AmqpClass thisClass) - throws IOException, AmqpTemplateException, AmqpTypeMappingException, - IllegalAccessException, InvocationTargetException - { - processTemplateD(template, thisClass, null, null); - } - - @Override - protected void processTemplateC(String[] template, AmqpClass thisClass, - AmqpMethod method) - throws IOException, AmqpTemplateException, AmqpTypeMappingException, - IllegalAccessException, InvocationTargetException - { - StringBuffer sb = new StringBuffer(template[templateStringIndex]); - String filename = prepareFilename(getTemplateFileName(sb), thisClass, method, null); - boolean templateProcessedFlag = false; - - // If method is not version consistent, create a namespace for each version - // i.e. copy the bit between the versionNamespaceStartToken and versionNamespaceEndToken - // once for each namespace. - if (method != null) - { - if (!method.isVersionConsistent(globalVersionSet)) - { - int namespaceStartIndex = sb.indexOf(versionNamespaceStartToken); - int namespaceEndIndex = sb.indexOf(versionNamespaceEndToken) + - versionNamespaceEndToken.length(); - if (namespaceStartIndex >= 0 && namespaceEndIndex >= 0 && - namespaceStartIndex <= namespaceEndIndex) - { - String namespaceSpan = sb.substring(namespaceStartIndex, namespaceEndIndex) + cr; - sb.delete(namespaceStartIndex, namespaceEndIndex); - Iterator<AmqpVersion> vItr = method.versionSet.iterator(); - while (vItr.hasNext()) - { - AmqpVersion version = vItr.next(); - StringBuffer nssb = new StringBuffer(namespaceSpan); - processTemplate(nssb, thisClass, method, null, template[templateFileNameIndex], - version); - sb.insert(namespaceStartIndex, nssb); - } - // Process all tokens *not* within the namespace span prior to inserting namespaces - processTemplate(sb, thisClass, method, null, template[templateFileNameIndex], null); - } - templateProcessedFlag = true; - } - } - // Remove any remaining namespace tags - int nsTokenIndex = sb.indexOf(versionNamespaceStartToken); - while (nsTokenIndex > 0) - { - sb.delete(nsTokenIndex, nsTokenIndex + versionNamespaceStartToken.length()); - nsTokenIndex = sb.indexOf(versionNamespaceStartToken); - } - nsTokenIndex = sb.indexOf(versionNamespaceEndToken); - while (nsTokenIndex > 0) - { - sb.delete(nsTokenIndex, nsTokenIndex + versionNamespaceEndToken.length()); - nsTokenIndex = sb.indexOf(versionNamespaceEndToken); - } - - if (!templateProcessedFlag) - { - processTemplate(sb, thisClass, method, null, template[templateFileNameIndex], null); - } - writeTargetFile(sb, new File(genDir + Utils.fileSeparator + filename)); - generatedFileCounter ++; - } - - @Override - protected void processTemplateD(String[] template, AmqpClass thisClass, AmqpMethod method, - AmqpField field) - throws IOException, AmqpTemplateException, AmqpTypeMappingException, IllegalAccessException, - InvocationTargetException - { - StringBuffer sb = new StringBuffer(template[templateStringIndex]); - String filename = prepareFilename(getTemplateFileName(sb), thisClass, method, field); - processTemplate(sb, thisClass, method, field, template[templateFileNameIndex], null); - writeTargetFile(sb, new File(genDir + Utils.fileSeparator + filename)); - generatedFileCounter ++; - } - - protected void processTemplate(StringBuffer sb, AmqpClass thisClass, AmqpMethod method, - AmqpField field, String templateFileName, AmqpVersion version) - throws InvocationTargetException, IllegalAccessException, AmqpTypeMappingException - { - try { processAllLists(sb, thisClass, method, version); } - catch (AmqpTemplateException e) - { - System.out.println("ERROR: " + templateFileName + ": " + e.getMessage()); - } - try { processAllTokens(sb, thisClass, method, field, version); } - catch (AmqpTemplateException e) - { - System.out.println("ERROR: " + templateFileName + ": " + e.getMessage()); - } - } - - @Override - protected String processToken(String token, AmqpClass thisClass, AmqpMethod method, AmqpField field, - AmqpVersion version) - throws AmqpTemplateException, AmqpTypeMappingException - { - if (token.compareTo("${GENERATOR}") == 0) - return generatorInfo; - if (token.compareTo("${CLASS}") == 0 && thisClass != null) - return thisClass.name; - if (token.compareTo("${CLASS_ID_INIT}") == 0 && thisClass != null) - { - if (version == null) - return String.valueOf(thisClass.indexMap.firstKey()); - return getIndex(thisClass.indexMap, version); - } - if (token.compareTo("${METHOD}") == 0 && method != null) - return method.name; - if (token.compareTo("${METHOD_ID_INIT}") == 0 && method != null) - { - if (version == null) - return String.valueOf(method.indexMap.firstKey()); - return getIndex(method.indexMap, version); - } - if (token.compareTo("${FIELD}") == 0 && field != null) - return field.name; - if (token.compareTo(versionNamespaceStartToken) == 0 && version != null) - return "namespace " + version.namespace() + cr + "{"; - if (token.compareTo(versionNamespaceEndToken) == 0 && version != null) - return "} // namespace " + version.namespace(); - if (token.compareTo("${mb_constructor_with_initializers}") == 0) - return generateConstructor(thisClass, method, version, 4, 4); - if (token.compareTo("${mb_server_operation_invoke}") == 0) - return generateServerOperationsInvoke(thisClass, method, version, 4, 4); - if (token.compareTo("${mb_buffer_param}") == 0) - return method.fieldMap.size() > 0 ? " buffer" : ""; - - throw new AmqpTemplateException("Template token " + token + " unknown."); - } - - @Override - protected void processClassList(StringBuffer sb, int listMarkerStartIndex, int listMarkerEndIndex, - AmqpModel model) - throws AmqpTemplateException, AmqpTypeMappingException - { - String codeSnippet; - int lend = sb.indexOf(cr, listMarkerStartIndex) + 1; // Include cr at end of line - String tline = sb.substring(listMarkerEndIndex, lend); // Line excluding line marker, including cr - int tokxStart = tline.indexOf('$'); - String token = tline.substring(tokxStart).trim(); - sb.delete(listMarkerStartIndex, lend); - - // ClientOperations.h - if (token.compareTo("${coh_method_handler_get_method}") == 0) - { - codeSnippet = generateOpsMethodHandlerGetMethods(model, false, 4); - } - else if (token.compareTo("${coh_inner_class}") == 0) - { - codeSnippet = generateOpsInnerClasses(model, false, 4, 4); - } - - // ServerOperations.h - else if (token.compareTo("${soh_method_handler_get_method}") == 0) - { - codeSnippet = generateOpsMethodHandlerGetMethods(model, true, 4); - } - else if (token.compareTo("${soh_inner_class}") == 0) - { - codeSnippet = generateOpsInnerClasses(model, true, 4, 4); - } - - // ClientProxy.h/cpp - else if (token.compareTo("${cph_inner_class_instance}") == 0) - { - codeSnippet = generateProxyInnerClassInstances(model, false, 4); - } - else if (token.compareTo("${cph_inner_class_get_method}") == 0) - { - codeSnippet = generateProxyInnerClassGetMethodDecls(model, false, 4); - } - else if (token.compareTo("${cph_inner_class_defn}") == 0) - { - codeSnippet = generateProxyInnerClassDefinitions(model, false, 4, 4); - } - else if (token.compareTo("${cpc_constructor_initializer}") == 0) - { - codeSnippet = generateProxyConstructorInitializers(model, false, 4); - } - else if (token.compareTo("${cpc_inner_class_get_method}") == 0) - { - codeSnippet = generateProxyInnerClassGetMethodImpls(model, false, 0, 4); - } - else if (token.compareTo("${cpc_inner_class_impl}") == 0) - { - codeSnippet = generateProxyInnerClassImpl(model, false, 0, 4); - } - else if (token.compareTo("${cph_handler_pointer_defn}") == 0) - { - codeSnippet = generateHandlerPointerDefinitions(model, false, 4); - } - else if (token.compareTo("${cph_handler_pointer_get_method}") == 0) - { - codeSnippet = generateHandlerPointerGetMethods(model, false, 4); - } - - // SerrverProxy.h/cpp - else if (token.compareTo("${sph_inner_class_instance}") == 0) - { - codeSnippet = generateProxyInnerClassInstances(model, true, 4); - } - else if (token.compareTo("${sph_inner_class_get_method}") == 0) - { - codeSnippet = generateProxyInnerClassGetMethodDecls(model, true, 4); - } - else if (token.compareTo("${sph_inner_class_defn}") == 0) - { - codeSnippet = generateProxyInnerClassDefinitions(model, true, 4, 4); - } - else if (token.compareTo("${spc_constructor_initializer}") == 0) - { - codeSnippet = generateProxyConstructorInitializers(model, true, 4); - } - else if (token.compareTo("${spc_inner_class_get_method}") == 0) - { - codeSnippet = generateProxyInnerClassGetMethodImpls(model, true, 0, 4); - } - else if (token.compareTo("${spc_inner_class_impl}") == 0) - { - codeSnippet = generateProxyInnerClassImpl(model, true, 0, 4); - } - else if (token.compareTo("${sph_handler_pointer_defn}") == 0) - { - codeSnippet = generateHandlerPointerDefinitions(model, true, 4); - } - else if (token.compareTo("${sph_handler_pointer_get_method}") == 0) - { - codeSnippet = generateHandlerPointerGetMethods(model, true, 4); - } - - // amqp_methods.h/cpp - else if (token.compareTo("${mh_method_body_class_indlude}") == 0) - { - codeSnippet = generateMethodBodyIncludeList(model, 0); - } - else if (token.compareTo("${mh_method_body_class_instance}") == 0) - { - codeSnippet = generateMethodBodyInstances(model, 0); - } - else if (token.compareTo("${mc_create_method_body_map_entry}") == 0) - { - codeSnippet = generateMethodBodyMapEntry(model, 4); - } - - else // Oops! - { - throw new AmqpTemplateException("Template token \"" + token + "\" unknown."); - } - sb.insert(listMarkerStartIndex, codeSnippet); - } - - @Override - protected void processMethodList(StringBuffer sb, int listMarkerStartIndex, int listMarkerEndIndex, - AmqpClass thisClass) - throws AmqpTemplateException, AmqpTypeMappingException - { - String codeSnippet; - int lend = sb.indexOf(cr, listMarkerStartIndex) + 1; // Include cr at end of line - String tline = sb.substring(listMarkerEndIndex, lend); // Line excluding line marker, including cr - int tokxStart = tline.indexOf('$'); - String token = tline.substring(tokxStart).trim(); - sb.delete(listMarkerStartIndex, lend); - - if (token.compareTo("${cpc_method_body_include}") == 0) - { - codeSnippet = generateMethodBodyIncludes(thisClass, 0); - } - else if (token.compareTo("${spc_method_body_include}") == 0) - { - codeSnippet = generateMethodBodyIncludes(thisClass, 0); - } - else if (token.compareTo("${mc_method_body_include}") == 0) - { - codeSnippet = generateMethodBodyIncludes(thisClass, 0); - } - - else // Oops! - { - throw new AmqpTemplateException("Template token " + token + " unknown."); - } - sb.insert(listMarkerStartIndex, codeSnippet); - } - - @Override - protected void processFieldList(StringBuffer sb, int listMarkerStartIndex, int listMarkerEndIndex, - AmqpFieldMap fieldMap, AmqpVersion version) - throws AmqpTypeMappingException, AmqpTemplateException, IllegalAccessException, - InvocationTargetException - { - String codeSnippet; - int lend = sb.indexOf(cr, listMarkerStartIndex) + 1; // Include cr at end of line - String tline = sb.substring(listMarkerEndIndex, lend); // Line excluding line marker, including cr - int tokxStart = tline.indexOf('$'); - String token = tline.substring(tokxStart).trim(); - sb.delete(listMarkerStartIndex, lend); - - if (token.compareTo("${mb_field_declaration}") == 0) - { - codeSnippet = generateFieldDeclarations(fieldMap, version, 4); - } - else if (token.compareTo("${mb_field_get_method}") == 0) - { - codeSnippet = generateFieldGetMethods(fieldMap, version, 4); - } - else if (token.compareTo("${mb_field_print}") == 0) - { - codeSnippet = generatePrintMethodContents(fieldMap, version, 8); - } - else if (token.compareTo("${mb_body_size}") == 0) - { - codeSnippet = generateBodySizeMethodContents(fieldMap, version, 8); - } - else if (token.compareTo("${mb_encode}") == 0) - { - codeSnippet = generateEncodeMethodContents(fieldMap, version, 8); - } - else if (token.compareTo("${mb_decode}") == 0) - { - codeSnippet = generateDecodeMethodContents(fieldMap, version, 8); - } -// else if (token.compareTo("${mb_field_list_initializer}") == 0) -// { -// codeSnippet = generateFieldList(fieldMap, version, false, true, 8); -// } -// else if (token.compareTo("${mb_field_list_declare}") == 0) -// { -// codeSnippet = generateFieldList(fieldMap, version, true, false, 8); -// } - - else // Oops! - { - throw new AmqpTemplateException("Template token " + token + " unknown."); - } - sb.insert(listMarkerStartIndex, codeSnippet); - } - - @Override - protected void processConstantList(StringBuffer sb, int listMarkerStartIndex, int listMarkerEndIndex, - AmqpConstantSet constantSet) - throws AmqpTemplateException, AmqpTypeMappingException - { - String codeSnippet; - int lend = sb.indexOf(cr, listMarkerStartIndex) + 1; // Include cr at end of line - String tline = sb.substring(listMarkerEndIndex, lend); // Line excluding line marker, including cr - int tokxStart = tline.indexOf('$'); - String token = tline.substring(tokxStart).trim(); - sb.delete(listMarkerStartIndex, lend); - - if (token.compareTo("${ch_get_value_method}") == 0) - { - codeSnippet = generateConstantGetMethods(constantSet, 4, 4); - } - - else // Oops! - { - throw new AmqpTemplateException("Template token " + token + " unknown."); - } - sb.insert(listMarkerStartIndex, codeSnippet); - } - - // === Protected and private helper functions unique to C++ implementation === - - // Methods for generation of code snippets for AMQP_Constants.h file - - protected String generateConstantGetMethods(AmqpConstantSet constantSet, - int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - Iterator<AmqpConstant> cItr = constantSet.iterator(); - while (cItr.hasNext()) - { - AmqpConstant constant = cItr.next(); - if (constant.isVersionConsistent(globalVersionSet)) - { - // return a constant - String value = constant.firstKey(); - sb.append(indent + "static const char* " + constant.name + "() { return \"" + - constant.firstKey() + "\"; }" + cr); -// sb.append(indent + "std::string " + constant.name + "Str(\"" + -// constant.firstKey() + "\");" + cr); -// sb.append(indent + "static const std::string& " + constant.name + "AsString() { return " + -// constant.name + "Str; }" + cr); - if (Utils.containsOnlyDigits(value)) - { - sb.append(indent + "static int " + constant.name + "AsInt() { return " + - constant.firstKey() + "; }" + cr); - } - if (Utils.containsOnlyDigitsAndDecimal(value)) - { - sb.append(indent + "static double " + constant.name + "AsDouble() { return (double)" + - constant.firstKey() + "; }" + cr); - } - sb.append(cr); - } - else - { - // Return version-specific constant - sb.append(generateVersionDependentGet(constant, "const char*", "", "\"", "\"", indentSize, tabSize)); -// sb.append(generateVersionDependentGet(constant, "const string&", "AsString", "string(\"", "\")", indentSize, tabSize)); - sb.append(generateVersionDependentGet(constant, "int", "AsInt", "", "", indentSize, tabSize)); - sb.append(generateVersionDependentGet(constant, "double", "AsDouble", "(double)", "", indentSize, tabSize)); - sb.append(cr); - } - } - return sb.toString(); - } - - protected String generateVersionDependentGet(AmqpConstant constant, String methodReturnType, - String methodNameSuffix, String returnPrefix, String returnPostfix, int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - sb.append(indent + methodReturnType + " " + constant.name + methodNameSuffix + - "() const" + cr); - sb.append(indent + "{" + cr); - boolean first = true; - Iterator<String> sItr = constant.keySet().iterator(); - while (sItr.hasNext()) - { - String value = sItr.next(); - AmqpVersionSet versionSet = constant.get(value); - sb.append(indent + tab + (first ? "" : "else ") + "if (" + generateVersionCheck(versionSet) + - ")" + cr); - sb.append(indent + tab + "{" + cr); - if (methodReturnType.compareTo("int") == 0 && !Utils.containsOnlyDigits(value)) - { - sb.append(generateConstantDeclarationException(constant.name, methodReturnType, - indentSize + (2*tabSize), tabSize)); - } - else if (methodReturnType.compareTo("double") == 0 && !Utils.containsOnlyDigitsAndDecimal(value)) - { - sb.append(generateConstantDeclarationException(constant.name, methodReturnType, - indentSize + (2*tabSize), tabSize)); - } - else - { - sb.append(indent + tab + tab + "return " + returnPrefix + value + returnPostfix + ";" + cr); - } - sb.append(indent + tab + "}" + cr); - first = false; - } - sb.append(indent + tab + "else" + cr); - sb.append(indent + tab + "{" + cr); - sb.append(indent + tab + tab + "std::stringstream ss;" + cr); - sb.append(indent + tab + tab + "ss << \"Constant \\\"" + constant.name + - "\\\" is undefined for AMQP version \" <<" + cr); - sb.append(indent + tab + tab + tab + "version.toString() << \".\";" + cr); - sb.append(indent + tab + tab + "throw ProtocolVersionException(ss.str());" + cr); - sb.append(indent + tab + "}" + cr); - sb.append(indent + "}" + cr); - return sb.toString(); - } - - protected String generateConstantDeclarationException(String name, String methodReturnType, - int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - sb.append(indent + "std::stringstream ss;" + cr); - sb.append(indent + "ss << \"Constant \\\"" + name + "\\\" cannot be converted to type " + - methodReturnType + " for AMQP version \" <<" + cr); - sb.append(indent + tab + "version.toString() << \".\";" + cr); - sb.append(indent + "throw ProtocolVersionException(ss.str());" + cr); - return sb.toString(); - } - - // Methods used for generation of code snippets for Server/ClientOperations class generation - - protected String generateOpsMethodHandlerGetMethods(AmqpModel model, boolean serverFlag, int indentSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - // Only generate for this class if there is at least one method of the - // required chassis (server/client flag). - boolean chassisFoundFlag = false; - Iterator<String> mItr = thisClass.methodMap.keySet().iterator(); - while (mItr.hasNext() && !chassisFoundFlag) - { - AmqpMethod method = thisClass.methodMap.get(mItr.next()); - boolean clientChassisFlag = method.clientMethodFlagMap.isSet(); - boolean serverChassisFlag = method.serverMethodFlagMap.isSet(); - if ((serverFlag && serverChassisFlag) || (!serverFlag && clientChassisFlag)) - chassisFoundFlag = true; - } - if (chassisFoundFlag) - sb.append(indent + "virtual AMQP_" + (serverFlag ? "Server" : "Client") + "Operations::" + - thisClass.name + "Handler* get" + thisClass.name + "Handler() = 0;" + cr); - } - return sb.toString(); - } - - protected String generateOpsInnerClasses(AmqpModel model, boolean serverFlag, int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - boolean first = true; - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - String className = thisClass.name + "Handler"; - if (!first) - sb.append(cr); - sb.append(indent + "// ==================== class " + className + - " ====================" + cr); - sb.append(indent + "class " + className); - if (thisClass.versionSet.size() != globalVersionSet.size()) - sb.append(" // AMQP Version(s) " + thisClass.versionSet + cr); - else - sb.append(cr); - sb.append(indent + "{" + cr); - sb.append(indent + "private:" + cr); - sb.append(indent + tab + "ProtocolVersion version;" + cr); - sb.append(cr); - sb.append(indent + tab + "// Constructors and destructors" + cr); - sb.append(cr); - sb.append(indent + "protected:" + cr); - sb.append(indent + tab + className + "() {}" + cr); - sb.append(indent + "public:" + cr); - sb.append(indent + tab + className + - "(u_int8_t major, u_int8_t minor) : version(major, minor) {}" + cr); - sb.append(indent + tab + className + - "(ProtocolVersion version) : version(version) {}" + cr); - sb.append(indent + tab + "virtual ~" + className + "() {}" + cr); - sb.append(cr); - sb.append(indent + tab + "// Protocol methods" + cr); - sb.append(cr); - sb.append(generateInnerClassMethods(thisClass, serverFlag, true, indentSize + tabSize, tabSize)); - sb.append(indent + "}; // class " + className + cr); - first = false; - } - return sb.toString(); - } - - protected String generateInnerClassMethods(AmqpClass thisClass, boolean serverFlag, - boolean abstractMethodFlag, int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - String outerClassName = "AMQP_" + (serverFlag ? "Server" : "Client") + (abstractMethodFlag ? "Operations" : "Proxy"); - boolean first = true; - Iterator<String> mItr = thisClass.methodMap.keySet().iterator(); - while (mItr.hasNext()) - { - AmqpMethod method = thisClass.methodMap.get(mItr.next()); - boolean clientChassisFlag = method.clientMethodFlagMap.isSet(); - boolean serverChassisFlag = method.serverMethodFlagMap.isSet(); - if ((serverFlag && serverChassisFlag) || (!serverFlag && clientChassisFlag)) - { - String methodName = parseForReservedWords(method.name, outerClassName + "." + thisClass.name); - AmqpOverloadedParameterMap overloadededParameterMap = - method.getOverloadedParameterLists(thisClass.versionSet, this); - Iterator<AmqpOrdinalFieldMap> ofmItr = overloadededParameterMap.keySet().iterator(); - while (ofmItr.hasNext()) - { - AmqpOrdinalFieldMap fieldMap = ofmItr.next(); - AmqpVersionSet versionSet = overloadededParameterMap.get(fieldMap); - if (!first) - sb.append(cr); - sb.append(indent + "virtual void " + methodName + "( u_int16_t channel"); - sb.append(generateMethodParameterList(fieldMap, indentSize + (5*tabSize), true, true, true)); - sb.append(" )"); - if (abstractMethodFlag) - sb.append(" = 0"); - sb.append(";"); - if (versionSet.size() != globalVersionSet.size()) - sb.append(" // AMQP Version(s) " + versionSet); - sb.append(cr); - first = false; - } - } - } - return sb.toString(); - } - - // Methods used for generation of code snippets for Server/ClientProxy class generation - - protected String generateHandlerPointerDefinitions(AmqpModel model, boolean serverFlag, - int indentSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - String outerClassName = "AMQP_" + (serverFlag ? "Server" : "Client") + "Operations"; - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - sb.append(indent + outerClassName + "::" + thisClass.name + "Handler* " + - thisClass.name + "HandlerPtr;" + cr); - } - return sb.toString(); - } - - protected String generateHandlerPointerGetMethods(AmqpModel model, boolean serverFlag, - int indentSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - String outerClassName = "AMQP_" + (serverFlag ? "Server" : "Client") + "Operations"; - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - sb.append(indent + "virtual inline " + outerClassName + "::" + thisClass.name + "Handler* get" + - thisClass.name + "Handler() { return &" + Utils.firstLower(thisClass.name) + ";}" + cr); - } - return sb.toString(); - } - - protected String generateProxyInnerClassInstances(AmqpModel model, boolean serverFlag, - int indentSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - String outerClassName = "AMQP_" + (serverFlag ? "Server" : "Client") + "Proxy"; - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - String instanceName = parseForReservedWords(Utils.firstLower(thisClass.name), outerClassName); - String className = parseForReservedWords(thisClass.name, null); - sb.append(indent + className + " " + instanceName + ";"); - if (thisClass.versionSet.size() != globalVersionSet.size()) - sb.append(" // AMQP Version(s) " + thisClass.versionSet + cr); - else - sb.append(cr); - } - return sb.toString(); - } - - protected String generateProxyInnerClassGetMethodDecls(AmqpModel model, boolean serverFlag, - int indentSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - String outerClassName = "AMQP_" + (serverFlag ? "Server" : "Client") + "Proxy"; - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - String className = parseForReservedWords(thisClass.name, outerClassName); - sb.append(indent + className + "& get" + className + "();"); - if (thisClass.versionSet.size() != globalVersionSet.size()) - sb.append(" // AMQP Version(s) " + thisClass.versionSet + cr); - else - sb.append(cr); - } - return sb.toString(); - } - - protected String generateProxyInnerClassDefinitions(AmqpModel model, boolean serverFlag, - int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - boolean first = true; - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - String className = thisClass.name; - String superclassName = "AMQP_" + (serverFlag ? "Server" : "Client") + "Operations::" + - thisClass.name + "Handler"; - if (!first) - sb.append(cr); - sb.append(indent + "// ==================== class " + className + - " ====================" + cr); - sb.append(indent + "class " + className + " : virtual public " + superclassName); - if (thisClass.versionSet.size() != globalVersionSet.size()) - sb.append(" // AMQP Version(s) " + thisClass.versionSet + cr); - else - sb.append(cr); - sb.append(indent + "{" + cr); - sb.append(indent + "private:" + cr); - sb.append(indent + tab + "OutputHandler* out;" + cr); - sb.append(indent + tab + "ProtocolVersion version;" + cr); - sb.append(cr); - sb.append(indent + "public:" + cr); - sb.append(indent + tab + "// Constructors and destructors" + cr); - sb.append(cr); - sb.append(indent + tab + className + "(OutputHandler* out, u_int8_t major, u_int8_t minor) : " + cr); - sb.append(indent + tab + tab + "out(out), version(major, minor) {}" + cr); - sb.append(indent + tab + className + "(OutputHandler* out, ProtocolVersion version) : " + cr); - sb.append(indent + tab + tab + "out(out), version(version) {}" + cr); - sb.append(indent + tab + "virtual ~" + className + "() {}" + cr); - sb.append(cr); - sb.append(indent + tab + "// Protocol methods" + cr); - sb.append(cr); - sb.append(generateInnerClassMethods(thisClass, serverFlag, false, indentSize + tabSize, tabSize)); - sb.append(indent + "}; // class " + className + cr); - first = false; - } - return sb.toString(); - } - - protected String generateProxyConstructorInitializers(AmqpModel model, boolean serverFlag, - int indentSize) - { - String outerClassName = "AMQP_" + (serverFlag ? "Server" : "Client") + "Proxy"; - String superclassName = "AMQP_" + (serverFlag ? "Server" : "Client") + "Operations"; - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(indent + superclassName + "(major, minor)," + cr); - sb.append(indent + "out(out)"); - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - String instanceName = parseForReservedWords(Utils.firstLower(thisClass.name), outerClassName); - sb.append("," + cr); - sb.append(indent + instanceName + "(out, major, minor)"); - if (!cItr.hasNext()) - sb.append(cr); - } - return sb.toString(); - } - - protected String generateProxyInnerClassGetMethodImpls(AmqpModel model, boolean serverFlag, - int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - String outerClassName = "AMQP_" + (serverFlag ? "Server" : "Client") + "Proxy"; - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - String className = thisClass.name; - String instanceName = parseForReservedWords(Utils.firstLower(thisClass.name), outerClassName); - sb.append(indent + outerClassName + "::" + className + "& " + - outerClassName + "::get" + className + "()" + cr); - sb.append(indent + "{" + cr); - if (thisClass.versionSet.size() != globalVersionSet.size()) - { - sb.append(indent + tab + "if (!" + generateVersionCheck(thisClass.versionSet) + ")" + cr); - sb.append(indent + tab + tab + "throw new ProtocolVersionException();" + cr); - } - sb.append(indent + tab + "return " + instanceName + ";" + cr); - sb.append(indent + "}" + cr); - if (cItr.hasNext()) - sb.append(cr); - } - return sb.toString(); - } - - protected String generateProxyInnerClassImpl(AmqpModel model, boolean serverFlag, - int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - boolean firstClassFlag = true; - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - String className = thisClass.name; - if (!firstClassFlag) - sb.append(cr); - sb.append(indent + "// ==================== class " + className + - " ====================" + cr); - sb.append(generateInnerClassMethodImpls(thisClass, serverFlag, indentSize, tabSize)); - firstClassFlag = false; - } - return sb.toString(); - } - - protected String generateInnerClassMethodImpls(AmqpClass thisClass, boolean serverFlag, - int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - String outerclassName = "AMQP_" + (serverFlag ? "Server" : "Client") + "Proxy"; - boolean first = true; - Iterator<String> mItr = thisClass.methodMap.keySet().iterator(); - while (mItr.hasNext()) - { - AmqpMethod method = thisClass.methodMap.get(mItr.next()); - String methodBodyClassName = thisClass.name + Utils.firstUpper(method.name) + "Body"; - boolean clientChassisFlag = method.clientMethodFlagMap.isSet(); - boolean serverChassisFlag = method.serverMethodFlagMap.isSet(); - boolean versionConsistentFlag = method.isVersionConsistent(globalVersionSet); - if ((serverFlag && serverChassisFlag) || (!serverFlag && clientChassisFlag)) - { - String methodName = parseForReservedWords(method.name, outerclassName + "." + thisClass.name); - AmqpOverloadedParameterMap overloadededParameterMap = - method.getOverloadedParameterLists(thisClass.versionSet, this); - Iterator<AmqpOrdinalFieldMap> ofmItr = overloadededParameterMap.keySet().iterator(); - while (ofmItr.hasNext()) - { - AmqpOrdinalFieldMap fieldMap = ofmItr.next(); - AmqpVersionSet versionSet = overloadededParameterMap.get(fieldMap); -// boolean versionConsistentFlag = versionSet.size() == globalVersionSet.size(); - if (!first) - sb.append(cr); - sb.append(indent + "void " + outerclassName + "::" + thisClass.name + "::" + - methodName + "( u_int16_t channel"); - sb.append(generateMethodParameterList(fieldMap, indentSize + (5*tabSize), true, true, true)); - sb.append(" )"); - if (versionSet.size() != globalVersionSet.size()) - sb.append(" // AMQP Version(s) " + versionSet); - sb.append(cr); - sb.append(indent + "{" + cr); - sb.append(generateMethodBodyCallContext(fieldMap, outerclassName, methodBodyClassName, - versionConsistentFlag, versionSet, indentSize + tabSize, tabSize)); - sb.append(indent + "}" + cr); - sb.append(cr); - first = false; - } - } - } - return sb.toString(); - } - - protected String generateMethodBodyCallContext(AmqpOrdinalFieldMap fieldMap, String outerclassName, - String methodBodyClassName, boolean versionConsistentFlag, AmqpVersionSet versionSet, - int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - if (versionConsistentFlag) - { - sb.append(generateMethodBodyCall(fieldMap, methodBodyClassName, null, indentSize, tabSize)); - } - else - { - boolean firstOverloadedMethodFlag = true; - Iterator<AmqpVersion> vItr = versionSet.iterator(); - while (vItr.hasNext()) - { - AmqpVersion version = vItr.next(); - sb.append(indent); - if (!firstOverloadedMethodFlag) - sb.append("else "); - sb.append("if (" + generateVersionCheck(version) + ")" + cr); - sb.append(indent + "{" + cr); - sb.append(generateMethodBodyCall(fieldMap, methodBodyClassName, version, - indentSize + tabSize, tabSize)); - sb.append(indent + "}" + cr); - firstOverloadedMethodFlag = false; - } - sb.append(indent + "else" + cr); - sb.append(indent + "{" + cr); - sb.append(indent + tab + "std::stringstream ss;" + cr); - sb.append(indent + tab + "ss << \"Call to " + outerclassName + "::" + methodBodyClassName + - "(u_int16_t" + generateMethodParameterList(fieldMap, 0, true, true, false) + ")\"" + cr); - sb.append(indent + tab + tab + "<< \" is invalid for AMQP version \" << version.toString() << \".\";" + cr); - sb.append(indent + tab + "throw new ProtocolVersionException(ss.str());" + cr); - sb.append(indent + "}" + cr); - } - return sb.toString(); - } - - protected String generateMethodBodyCall(AmqpOrdinalFieldMap fieldMap, String methodBodyClassName, - AmqpVersion version, int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - String namespace = version != null ? version.namespace() + "::" : ""; - StringBuffer sb = new StringBuffer(indent + "out->send( new AMQFrame( channel," + cr); - sb.append(indent + tab + "new " + namespace + methodBodyClassName + "( version"); - sb.append(generateMethodParameterList(fieldMap, indentSize + (5*tabSize), true, false, true)); - sb.append(" )));" + cr); - return sb.toString(); - } - - protected String generateMethodBodyIncludes(AmqpClass thisClass, int indentSize) - { - StringBuffer sb = new StringBuffer(); - if (thisClass != null) - { - sb.append(generateClassMethodBodyInclude(thisClass, indentSize)); - } - else - { - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - thisClass = model.classMap.get(cItr.next()); - sb.append(generateClassMethodBodyInclude(thisClass, indentSize)); - } - } - return sb.toString(); - } - - protected String generateClassMethodBodyInclude(AmqpClass thisClass, int indentSize) - { - StringBuffer sb = new StringBuffer(); - String indent = Utils.createSpaces(indentSize); - Iterator<String> mItr = thisClass.methodMap.keySet().iterator(); - while (mItr.hasNext()) - { - AmqpMethod method = thisClass.methodMap.get(mItr.next()); - sb.append(indent + "#include <qpid/framing/" + thisClass.name + - Utils.firstUpper(method.name) + "Body.h>" + cr); - } - return sb.toString(); - } - - // Methods used for generation of code snippets for MethodBody class generation - - protected String getIndex(AmqpOrdinalVersionMap indexMap, AmqpVersion version) - throws AmqpTemplateException - { - Iterator<Integer> iItr = indexMap.keySet().iterator(); - while (iItr.hasNext()) - { - int index = iItr.next(); - AmqpVersionSet versionSet = indexMap.get(index); - if (versionSet.contains(version)) - return String.valueOf(index); - } - throw new AmqpTemplateException("Unable to find index for version " + version); - } - - protected String generateFieldDeclarations(AmqpFieldMap fieldMap, AmqpVersion version, int indentSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - - if (version == null) - version = globalVersionSet.first(); - AmqpOrdinalFieldMap ordinalFieldMap = fieldMap.getMapForVersion(version, true, this); - Iterator<Integer> oItr = ordinalFieldMap.keySet().iterator(); - while (oItr.hasNext()) - { - String[] fieldDomainPair = ordinalFieldMap.get(oItr.next()); - sb.append(indent + fieldDomainPair[FIELD_DOMAIN] + " " + fieldDomainPair[FIELD_NAME] + ";" + cr); - } - // TODO: Replace the pattern below with that above in the JavaGenerator and elsewhere here. -// Iterator<String> fItr = fieldMap.keySet().iterator(); -// while(fItr.hasNext()) -// { -// AmqpField fieldDetails = fieldMap.get(fItr.next()); -// if (version == null) // Version consistent - there *should* be only one domain -// { -// String domainName = fieldDetails.domainMap.firstKey(); -// String codeType = getGeneratedType(domainName, globalVersionSet.first()); -// sb.append(indent + codeType + " " + fieldDetails.name + ";" + cr); -// } -// else -// { -// Iterator<String> dItr = fieldDetails.domainMap.keySet().iterator(); -// while (dItr.hasNext()) -// { -// String domainName = dItr.next(); -// AmqpVersionSet versionSet = fieldDetails.domainMap.get(domainName); -// if (versionSet.contains(version)) -// { -// String codeType = getGeneratedType(domainName, version); -// sb.append(indent + codeType + " " + fieldDetails.name + ";" + cr); -// } -// } -// } -// } - return sb.toString(); - } - - protected String generateFieldGetMethods(AmqpFieldMap fieldMap, AmqpVersion version, int indentSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - Iterator<String> fItr = fieldMap.keySet().iterator(); - while(fItr.hasNext()) - { - AmqpField fieldDetails = fieldMap.get(fItr.next()); - if (version == null) // Version consistent - there *should* be only one domain - { - String domainName = fieldDetails.domainMap.firstKey(); - String codeType = getGeneratedType(domainName, globalVersionSet.first()); - sb.append(indent + "inline " + setRef(codeType) + " get" + - Utils.firstUpper(fieldDetails.name) + "() { return " + - fieldDetails.name + "; }" + cr); - } - else - { - Iterator<String> dItr = fieldDetails.domainMap.keySet().iterator(); - while (dItr.hasNext()) - { - String domainName = dItr.next(); - AmqpVersionSet versionSet = fieldDetails.domainMap.get(domainName); - if (versionSet.contains(version)) - { - String codeType = getGeneratedType(domainName, version); - sb.append(indent + "inline " + setRef(codeType) + " get" + - Utils.firstUpper(fieldDetails.name) + "() { return " + - fieldDetails.name + "; }" + cr); - } - } - } - } - return sb.toString(); - } - - protected String generatePrintMethodContents(AmqpFieldMap fieldMap, AmqpVersion version, int indentSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - Iterator<String> fItr = fieldMap.keySet().iterator(); - boolean firstFlag = true; - while(fItr.hasNext()) - { - AmqpField fieldDetails = fieldMap.get(fItr.next()); - if (version == null) // Version consistent - there *should* be only one domain - { - String domainName = fieldDetails.domainMap.firstKey(); - String codeType = getGeneratedType(domainName, globalVersionSet.first()); - String cast = codeType.compareTo("u_int8_t") == 0 ? "(int)" : ""; - sb.append(indent + "out << \""); - if (!firstFlag) - sb.append("; "); - sb.append(fieldDetails.name + "=\" << " + cast + fieldDetails.name + ";" + cr); - firstFlag = false; - } - else - { - Iterator<String> dItr = fieldDetails.domainMap.keySet().iterator(); - while (dItr.hasNext()) - { - String domainName = dItr.next(); - AmqpVersionSet versionSet = fieldDetails.domainMap.get(domainName); - if (versionSet.contains(version)) - { - String codeType = getGeneratedType(domainName, version); - String cast = codeType.compareTo("u_int8_t") == 0 ? "(int)" : ""; - sb.append(indent + "out << \""); - if (!firstFlag) - sb.append("; "); - sb.append(fieldDetails.name + "=\" << " + cast + fieldDetails.name + ";" + cr); - firstFlag = false; - } - } - } - } - return sb.toString(); - } - - protected String generateBodySizeMethodContents(AmqpFieldMap fieldMap, AmqpVersion version, - int indentSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - ArrayList<String> bitFieldList = new ArrayList<String>(); - AmqpOrdinalFieldMap ordinalFieldMap = fieldMap.getMapForVersion(version, false, this); - Iterator<Integer> oItr = ordinalFieldMap.keySet().iterator(); - int ordinal = 0; - while (oItr.hasNext()) - { - ordinal = oItr.next(); - String[] fieldDomainPair = ordinalFieldMap.get(ordinal); - AmqpVersion thisVersion = version == null ? globalVersionSet.first() : version; - String domainType = getDomainType(fieldDomainPair[FIELD_DOMAIN], thisVersion); - - // Defer bit types by adding them to an array. When the first subsequent non-bit - // type is encountered, then handle the bits. This allows consecutive bits to be - // placed into the same byte(s) - 8 bits to the byte. - if (domainType.compareTo("bit") == 0) - { - bitFieldList.add(fieldDomainPair[FIELD_NAME]); - } - else - { - if (bitFieldList.size() > 0) // Handle accumulated bit types (if any) - { - sb.append(generateBitArrayBodySizeMethodContents(bitFieldList, ordinal, indentSize)); - } - sb.append(indent + "size += " + - typeMap.get(domainType).size.replaceAll("#", fieldDomainPair[FIELD_NAME]) + - "; /* " + fieldDomainPair[FIELD_NAME] + ": " + - domainType + " */" + cr); - } - } - if (bitFieldList.size() > 0) // Handle any remaining accumulated bit types - { - sb.append(generateBitArrayBodySizeMethodContents(bitFieldList, ordinal, indentSize)); - } - return sb.toString(); - } - - protected String generateBitArrayBodySizeMethodContents(ArrayList<String> bitFieldList, - int ordinal, int indentSize) - { - int numBytes = ((bitFieldList.size() - 1) / 8) + 1; - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - String comment = bitFieldList.size() == 1 ? - bitFieldList.get(0) + ": bit" : - "Combinded bits: " + bitFieldList; - sb.append(indent + "size += " + - typeMap.get("bit").size.replaceAll("~", String.valueOf(numBytes)) + - "; /* " + comment + " */" + cr); - bitFieldList.clear(); - return sb.toString(); - } - - protected String generateEncodeMethodContents(AmqpFieldMap fieldMap, AmqpVersion version, - int indentSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - ArrayList<String> bitFieldList = new ArrayList<String>(); - AmqpOrdinalFieldMap ordinalFieldMap = fieldMap.getMapForVersion(version, false, this); - Iterator<Integer> oItr = ordinalFieldMap.keySet().iterator(); - int ordinal = 0; - while (oItr.hasNext()) - { - ordinal = oItr.next(); - String[] fieldDomainPair = ordinalFieldMap.get(ordinal); - AmqpVersion thisVersion = version == null ? globalVersionSet.first() : version; - String domainType = getDomainType(fieldDomainPair[FIELD_DOMAIN], thisVersion); - - // Defer bit types by adding them to an array. When the first subsequent non-bit - // type is encountered, then handle the bits. This allows consecutive bits to be - // placed into the same byte(s) - 8 bits to the byte. - if (domainType.compareTo("bit") == 0) - { - bitFieldList.add(fieldDomainPair[FIELD_NAME]); - } - else - { - if (bitFieldList.size() > 0) // Handle accumulated bit types (if any) - { - sb.append(generateBitEncodeMethodContents(bitFieldList, ordinal, indentSize)); - } - sb.append(indent + - typeMap.get(domainType).encodeExpression.replaceAll("#", fieldDomainPair[FIELD_NAME]) + - "; /* " + fieldDomainPair[FIELD_NAME] + ": " + domainType + " */"+ cr); - } - } - if (bitFieldList.size() > 0) // Handle any remaining accumulated bit types - { - sb.append(generateBitEncodeMethodContents(bitFieldList, ordinal, indentSize)); - } - - return sb.toString(); - } - - protected String generateBitEncodeMethodContents(ArrayList<String> bitFieldList, int ordinal, - int indentSize) - { - int numBytes = ((bitFieldList.size() - 1) / 8) + 1; - String indent = Utils.createSpaces(indentSize); - String bitArrayName = "flags_" + ordinal; - StringBuffer sb = new StringBuffer(indent + "u_int8_t " + bitArrayName + - "[" + numBytes + "] = {0};" + - (numBytes != 1 ? " /* All array elements will be initialized to 0 */" : "") + - cr); - for (int i=0; i<bitFieldList.size(); i++) - { - int bitIndex = i%8; - int byteIndex = i/8; - sb.append(indent + bitArrayName + "[" + byteIndex + "] |= " + bitFieldList.get(i) + - " << " + bitIndex + "; /* " + bitFieldList.get(i) + ": bit */" + cr); - } - for (int i=0; i<numBytes; i++) - { - sb.append(indent + "buffer.putOctet(" + bitArrayName + "[" + i + "]);" + cr); - } - bitFieldList.clear(); - return sb.toString(); - } - - protected String generateDecodeMethodContents(AmqpFieldMap fieldMap, AmqpVersion version, - int indentSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - ArrayList<String> bitFieldList = new ArrayList<String>(); - AmqpOrdinalFieldMap ordinalFieldMap = fieldMap.getMapForVersion(version, false, this); - Iterator<Integer> oItr = ordinalFieldMap.keySet().iterator(); - int ordinal = 0; - while (oItr.hasNext()) - { - ordinal = oItr.next(); - String[] fieldDomainPair = ordinalFieldMap.get(ordinal); - AmqpVersion thisVersion = version == null ? globalVersionSet.first() : version; - String domainType = getDomainType(fieldDomainPair[FIELD_DOMAIN], thisVersion); - - // Defer bit types by adding them to an array. When the first subsequent non-bit - // type is encountered, then handle the bits. This allows consecutive bits to be - // placed into the same byte(s) - 8 bits to the byte. - if (domainType.compareTo("bit") == 0) - { - bitFieldList.add(fieldDomainPair[FIELD_NAME]); - } - else - { - if (bitFieldList.size() > 0) // Handle accumulated bit types (if any) - { - sb.append(generateBitDecodeMethodContents(bitFieldList, ordinal, indentSize)); - } - sb.append(indent + - typeMap.get(domainType).decodeExpression.replaceAll("#", fieldDomainPair[FIELD_NAME]) + - "; /* " + fieldDomainPair[FIELD_NAME] + ": " + domainType + " */" + cr); - } - } - if (bitFieldList.size() > 0) // Handle any remaining accumulated bit types - { - sb.append(generateBitDecodeMethodContents(bitFieldList, ordinal, indentSize)); - } - - return sb.toString(); - } - - protected String generateBitDecodeMethodContents(ArrayList<String> bitFieldList, int ordinal, - int indentSize) - { - int numBytes = ((bitFieldList.size() - 1) / 8) + 1; - String indent = Utils.createSpaces(indentSize); - String bitArrayName = "flags_" + ordinal; - StringBuffer sb = new StringBuffer(indent + "u_int8_t " + bitArrayName + - "[" + numBytes + "];" + cr); - for (int i=0; i<numBytes; i++) - { - sb.append(indent + bitArrayName + "[" + i + "] = buffer.getOctet();" + cr); - } - for (int i=0; i<bitFieldList.size(); i++) - { - int bitIndex = i%8; - int byteIndex = i/8; - sb.append(indent + bitFieldList.get(i) + " = (1 << " + bitIndex + ") & " + - bitArrayName + "[" + byteIndex + "]; /* " + bitFieldList.get(i) + - ": bit */" + cr); - } - bitFieldList.clear(); - return sb.toString(); - } - - protected String generateFieldList(AmqpFieldMap fieldMap, AmqpVersion version, boolean defineFlag, - boolean initializerFlag, int indentSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - AmqpOrdinalFieldMap ordinalFieldMap = fieldMap.getMapForVersion(version, true, this); - Iterator<Integer> oItr = ordinalFieldMap.keySet().iterator(); - while (oItr.hasNext()) - { - int ordinal = oItr.next(); - String[] fieldDomainPair = ordinalFieldMap.get(ordinal); - sb.append(indent + (defineFlag ? fieldDomainPair[FIELD_DOMAIN] + " " : "") + - fieldDomainPair[FIELD_NAME] + (initializerFlag ? "(" + fieldDomainPair[FIELD_NAME] + ")" : "") + - (oItr.hasNext() ? "," : "") + cr); - } - return sb.toString(); - } - - protected String generateMethodParameterList(AmqpOrdinalFieldMap fieldMap, int indentSize, - boolean leadingCommaFlag, boolean fieldTypeFlag, boolean fieldNameFlag) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - boolean first = true; - Iterator<Integer> pItr = fieldMap.keySet().iterator(); - while(pItr.hasNext()) - { - String[] field = fieldMap.get(pItr.next()); - if (first && leadingCommaFlag) - { - sb.append("," + (fieldNameFlag ? cr : " ")); - } - if (!first || leadingCommaFlag) - { - sb.append(indent); - } - sb.append( - (fieldTypeFlag ? setRef(field[FIELD_DOMAIN]) : "") + - (fieldNameFlag ? " " + field[FIELD_NAME] : "") + - (pItr.hasNext() ? "," + (fieldNameFlag ? cr : " ") : "")); - first = false; - } - return sb.toString(); - } - - protected String generateConstructor(AmqpClass thisClass, AmqpMethod method, - AmqpVersion version, int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - if (method.fieldMap.size() > 0) - { - sb.append(indent + thisClass.name + Utils.firstUpper(method.name) + "Body(ProtocolVersion version," + cr); - sb.append(generateFieldList(method.fieldMap, version, true, false, 8)); - sb.append(indent + tab + ") :" + cr); - sb.append(indent + tab + "AMQMethodBody(version)," + cr); - sb.append(generateFieldList(method.fieldMap, version, false, true, 8)); - sb.append(indent + "{ }" + cr); - } - return sb.toString(); - } - - protected String generateServerOperationsInvoke(AmqpClass thisClass, AmqpMethod method, - AmqpVersion version, int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - - if (method.serverMethodFlagMap.size() > 0) // At least one AMQP version defines this method as a server method - { - Iterator<Boolean> bItr = method.serverMethodFlagMap.keySet().iterator(); - while (bItr.hasNext()) - { - if (bItr.next()) // This is a server operation - { - boolean fieldMapNotEmptyFlag = method.fieldMap.size() > 0; - sb.append(indent + "inline void invoke(AMQP_ServerOperations& target, u_int16_t channel)" + cr); - sb.append(indent + "{" + cr); - sb.append(indent + tab + "target.get" + thisClass.name + "Handler()->" + - parseForReservedWords(Utils.firstLower(method.name), - thisClass.name + Utils.firstUpper(method.name) + "Body.invoke()") + "(channel"); - if (fieldMapNotEmptyFlag) - { - sb.append("," + cr); - sb.append(generateFieldList(method.fieldMap, version, false, false, indentSize + 4*tabSize)); - sb.append(indent + tab + tab + tab + tab); - } - sb.append(");" + cr); - sb.append(indent + "}" + cr); - } - } - } - return sb.toString(); - } - - // Methods for generation of code snippets for amqp_methods.h/cpp files - - protected String generateMethodBodyIncludeList(AmqpModel model, int indentSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - Iterator<String> mItr = thisClass.methodMap.keySet().iterator(); - while (mItr.hasNext()) - { - AmqpMethod method = thisClass.methodMap.get(mItr.next()); - sb.append(indent + "#include \"" + thisClass.name + Utils.firstUpper(method.name) + "Body.h\"" + cr); - } - } - - return sb.toString(); - } - - protected String generateMethodBodyInstances(AmqpModel model, int indentSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - Iterator<String> mItr = thisClass.methodMap.keySet().iterator(); - while (mItr.hasNext()) - { - AmqpMethod method = thisClass.methodMap.get(mItr.next()); - sb.append(indent + "const " + thisClass.name + Utils.firstUpper(method.name) + "Body " + - Utils.firstLower(thisClass.name) + "_" + method.name + ";" + cr); - } - } - - return sb.toString(); - } - - protected String generateMethodBodyMapEntry(AmqpModel model, int indentSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - - Iterator<AmqpVersion> vItr = globalVersionSet.iterator(); - while (vItr.hasNext()) - { - AmqpVersion version = vItr.next(); - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - Iterator<String> mItr = thisClass.methodMap.keySet().iterator(); - while (mItr.hasNext()) - { - AmqpMethod method = thisClass.methodMap.get(mItr.next()); - String namespace = method.isVersionConsistent(globalVersionSet) ? "" : version.namespace() + "::"; - try - { - int classOrdinal = thisClass.indexMap.getOrdinal(version); - int methodOrdinal = method.indexMap.getOrdinal(version); - String methodModyClassName = namespace + thisClass.name + Utils.firstUpper(method.name) + "Body"; - sb.append(indent + "insert(std::make_pair(createMapKey(" + classOrdinal + ", " + - methodOrdinal + ", " + version.getMajor() + ", " + version.getMinor() + - "), &createMethodBodyFn<" + methodModyClassName + ">));" + cr); - } - catch (AmqpTypeMappingException e) {} // ignore - } - } - } - - return sb.toString(); - } - - - // Helper functions - - private String generateVersionCheck(AmqpVersion version) - { - return "version.equals(" + version.getMajor() + ", " + version.getMinor() + ")"; - } - - private String generateVersionCheck(AmqpVersionSet versionSet) - throws AmqpTypeMappingException - { - StringBuffer sb = new StringBuffer(); - AmqpVersion[] versionArray = new AmqpVersion[versionSet.size()]; - versionSet.toArray(versionArray); - for (int i=0; i<versionArray.length; i++) - { - if (i != 0) - sb.append(" || "); - if (versionArray.length > 1) - sb.append("("); - sb.append("version.equals(" + versionArray[i].getMajor() + ", " + versionArray[i].getMinor() + ")"); - if (versionArray.length > 1) - sb.append(")"); - } - return sb.toString(); - } - - private String parseForReservedWords(String name, String context) - { - for (int i=0; i<cppReservedWords.length; i++) - if (name.compareTo(cppReservedWords[i]) == 0) - { - if (!quietFlag) - { - System.out.println("WARNING: " + (context == null ? "" : context + ": ") + - "Found XML method \"" + name + "\", which is a C++ reserved word. " + - "Changing generated name to \"" + name + "_\"."); - } - return name + "_"; - } - - for (int i=0; i<cppCommonDefines.length; i++) - if (name.compareTo(cppCommonDefines[i]) == 0) - { - if (!quietFlag) - { - System.out.println("WARNING: " + (context == null ? "" : context + ": ") + - "Found XML method \"" + name + "\", which may clash with commonly used defines within C++. " + - "Changing generated name to \"" + name + "_\"."); - } - return name + "_"; - } - - return name; - } - - private String setRef(String codeType) - { - if (codeType.compareTo("string") == 0 || - codeType.compareTo("FieldTable") == 0) - return "const " + codeType + "&"; - return codeType; - } - - private String camelCaseName(String name, boolean upperFirstFlag) - { - StringBuffer ccn = new StringBuffer(); - String[] toks = name.split("[-_.\\ ]"); - for (int i=0; i<toks.length; i++) - { - StringBuffer b = new StringBuffer(toks[i]); - if (upperFirstFlag || i>0) - b.setCharAt(0, Character.toUpperCase(toks[i].charAt(0))); - ccn.append(b); - } - return ccn.toString(); - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/Generator.java b/qpid/gentools/org/apache/qpid/gentools/Generator.java deleted file mode 100644 index 8ed54a2387..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/Generator.java +++ /dev/null @@ -1,431 +0,0 @@ -/* - * - * 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.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.LineNumberReader; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Iterator; - -public abstract class Generator implements LanguageConverter -{ - protected static String cr = Utils.lineSeparator; - protected static enum EnumConstOutputTypes { OUTPUT_STRING, OUTPUT_INTEGER, OUTPUT_DOUBLE; }; - - // This string is reproduced in every generated file as a comment - // TODO: Tie the version info into the build system. - protected static final String generatorInfo = "Qpid Gentools v.0.1"; - protected static final int templateFileNameIndex = 0; - protected static final int templateStringIndex = 1; - - protected ArrayList<String[]> modelTemplateList; - protected ArrayList<String[]> classTemplateList; - protected ArrayList<String[]> methodTemplateList; - protected ArrayList<String[]> fieldTemplateList; - protected String genDir; - - protected AmqpVersionSet globalVersionSet; - protected AmqpDomainMap globalDomainMap; - protected AmqpConstantSet globalConstantSet; - protected AmqpModel model; - - protected int generatedFileCounter; - - public Generator(AmqpVersionSet versionList) - { - this.globalVersionSet = versionList; - modelTemplateList = new ArrayList<String[]>(); - classTemplateList = new ArrayList<String[]>(); - methodTemplateList = new ArrayList<String[]>(); - fieldTemplateList = new ArrayList<String[]>(); - generatedFileCounter = 0; - } - - public int getNumberGeneratedFiles() - { - return generatedFileCounter; - } - - public void setDomainMap(AmqpDomainMap domainMap) - { - this.globalDomainMap = domainMap; - } - - public AmqpDomainMap getDomainMap() - { - return globalDomainMap; - } - - public void setConstantSet(AmqpConstantSet constantSet) - { - this.globalConstantSet = constantSet; - } - - public AmqpConstantSet getConstantSet() - { - return globalConstantSet; - } - - public void setModel(AmqpModel model) - { - this.model = model; - } - - public AmqpModel getModel() - { - return model; - } - - public void initializeTemplates(File[] modelTemplateFiles, File[] classTemplatesFiles, - File[] methodTemplatesFiles, File[] fieldTemplatesFiles) - throws FileNotFoundException, IOException - { - if (modelTemplateFiles.length > 0) - { - System.out.println("Model template file(s):"); - for (int t=0; t<modelTemplateFiles.length; t++) - { - System.out.println(" " + modelTemplateFiles[t].getAbsolutePath()); - String template[] = {modelTemplateFiles[t].getName(), loadTemplate(modelTemplateFiles[t])}; - modelTemplateList.add(template); - } - } - if (classTemplatesFiles.length > 0) - { - System.out.println("Class template file(s):"); - for (int c=0; c<classTemplatesFiles.length; c++) - { - System.out.println(" " + classTemplatesFiles[c].getAbsolutePath()); - String template[] = {classTemplatesFiles[c].getName(), loadTemplate(classTemplatesFiles[c])}; - classTemplateList.add(template); - } - } - if (methodTemplatesFiles.length > 0) - { - System.out.println("Method template file(s):"); - for (int m=0; m<methodTemplatesFiles.length; m++) - { - System.out.println(" " + methodTemplatesFiles[m].getAbsolutePath()); - String template[] = {methodTemplatesFiles[m].getName(), loadTemplate(methodTemplatesFiles[m])}; - methodTemplateList.add(template); - } - } - if (fieldTemplatesFiles.length > 0) - { - System.out.println("Field template file(s):"); - for (int f=0; f<fieldTemplatesFiles.length; f++) - { - System.out.println(" " + fieldTemplatesFiles[f].getAbsolutePath()); - String template[] = {fieldTemplatesFiles[f].getName(), loadTemplate(fieldTemplatesFiles[f])}; - fieldTemplateList.add(template); - } - } - } - - abstract protected String prepareFilename(String filenameTemplate, AmqpClass thisClass, AmqpMethod method, - AmqpField field); - - abstract protected String processToken(String token, AmqpClass thisClass, AmqpMethod method, - AmqpField field, AmqpVersion version) - throws AmqpTemplateException, AmqpTypeMappingException; - - abstract protected void processClassList(StringBuffer sb, int listMarkerStartIndex, int listMarkerEndIndex, - AmqpModel model) - throws AmqpTemplateException, AmqpTypeMappingException; - - abstract protected void processMethodList(StringBuffer sb, int listMarkerStartIndex, int listMarkerEndIndex, - AmqpClass thisClass) - throws AmqpTemplateException, AmqpTypeMappingException; - - abstract protected void processFieldList(StringBuffer sb, int listMarkerStartIndex, int listMarkerEndIndex, - AmqpFieldMap fieldMap, AmqpVersion version) - throws AmqpTypeMappingException, AmqpTemplateException, IllegalAccessException, - InvocationTargetException; - - abstract protected void processConstantList(StringBuffer sb, int listMarkerStartIndex, int listMarkerEndIndex, - AmqpConstantSet constantSet) - throws AmqpTemplateException, AmqpTypeMappingException; - - public void generate(File genDir) - throws TargetDirectoryException, IOException, AmqpTypeMappingException, - AmqpTemplateException, IllegalAccessException, InvocationTargetException - { - prepareTargetDirectory(genDir, true); - System.out.println("Generation directory: " + genDir.getAbsolutePath()); - this.genDir = genDir.getAbsolutePath(); - - // Use all model-level templates - for (int t = 0; t < modelTemplateList.size(); t++) - { - processTemplateA(modelTemplateList.get(t)); - } - - // Cycle through classes - Iterator<String> citr = model.classMap.keySet().iterator(); - while (citr.hasNext()) - { - String className = citr.next(); - AmqpClass thisClass = model.classMap.get(className); - - // Use all class-level templates - for (int c = 0; c < classTemplateList.size(); c++) - { - processTemplateB(classTemplateList.get(c), thisClass); - } - - // Cycle through all methods - Iterator<String> mitr = thisClass.methodMap.keySet().iterator(); - while (mitr.hasNext()) - { - String methodName = mitr.next(); - AmqpMethod method = thisClass.methodMap.get(methodName); - - // Use all method-level templates - for (int m = 0; m < methodTemplateList.size(); m++) - { - processTemplateC(methodTemplateList.get(m), thisClass, method); - } - - // Cycle through all fields - Iterator<String> fitr = method.fieldMap.keySet().iterator(); - while (fitr.hasNext()) - { - String fieldName = fitr.next(); - AmqpField field = method.fieldMap.get(fieldName); - - // Use all field-level templates - for (int f = 0; f < fieldTemplateList.size(); f++) - { - processTemplateD(fieldTemplateList.get(f), thisClass, method, field); - } - } - } - } - } - - protected void processVersionList(StringBuffer sb, int tokStart, int tokEnd) - throws AmqpTypeMappingException - { - int lend = sb.indexOf(Utils.lineSeparator, tokStart) + 1; // Include cr at end of line - String tline = sb.substring(tokEnd, lend); // Line excluding line marker, including cr - sb.delete(tokStart, lend); - AmqpVersion[] versionArray = new AmqpVersion[globalVersionSet.size()]; - globalVersionSet.toArray(versionArray); - for (int i=0; i<versionArray.length; i++) - { - // Insert copy of target line - StringBuffer isb = new StringBuffer(tline); - replaceToken(isb, "${major}", String.valueOf(versionArray[i].getMajor())); - replaceToken(isb, "${minor}", String.valueOf(versionArray[i].getMinor())); - sb.insert(tokStart, isb.toString()); - tokStart += isb.length(); - } - } - - // Model-level template processing - abstract protected void processTemplateA(String[] template) - throws IOException, AmqpTemplateException, AmqpTypeMappingException, - IllegalAccessException, InvocationTargetException; - - // Class-level template processing - abstract protected void processTemplateB(String[] template, AmqpClass thisClass) - throws IOException, AmqpTemplateException, AmqpTypeMappingException, - IllegalAccessException, InvocationTargetException; - - // Method-level template processing - abstract protected void processTemplateC(String[] template, AmqpClass thisClass, - AmqpMethod method) - throws IOException, AmqpTemplateException, AmqpTypeMappingException, - IllegalAccessException, InvocationTargetException; - - // Field-level template processing - abstract protected void processTemplateD(String[] template, AmqpClass thisClass, - AmqpMethod method, AmqpField field) - throws IOException, AmqpTemplateException, AmqpTypeMappingException, - IllegalAccessException, InvocationTargetException; - - // Helper functions common to all generators - - protected static void prepareTargetDirectory(File dir, boolean createFlag) - throws TargetDirectoryException - { - if (dir.exists()) - { - if (!dir.isDirectory()) - throw new TargetDirectoryException("\"" + dir.getAbsolutePath() + - "\" exists, but is not a directory."); - } - else if (createFlag) // Create dir - { - if(!dir.mkdirs()) - throw new TargetDirectoryException("Unable to create directory \"" + - dir.getAbsolutePath() + "\"."); - } - else - throw new TargetDirectoryException("Directory \"" + dir.getAbsolutePath() + - "\" not found."); - - } - - protected void processAllLists(StringBuffer sb, AmqpClass thisClass, AmqpMethod method, AmqpVersion version) - throws AmqpTemplateException, AmqpTypeMappingException, IllegalAccessException, - InvocationTargetException - { - int lstart = sb.indexOf("%{"); - while (lstart != -1) - { - int lend = sb.indexOf("}", lstart + 2); - if (lend > 0) - { - String listToken = sb.substring(lstart + 2, lend); - if (listToken.compareTo("VLIST") == 0) - { - processVersionList(sb, lstart, lend + 1); - } - else if (listToken.compareTo("CLIST") == 0) - { - processClassList(sb, lstart, lend + 1, model); - } - else if (listToken.compareTo("MLIST") == 0) - { - processMethodList(sb, lstart, lend + 1, thisClass); - } - else if (listToken.compareTo("FLIST") == 0) - { - // Pass the FieldMap from either a class or a method. - // If this is called from a class-level template, we assume that the - // class field list is required. In this case, method will be null. - processFieldList(sb, lstart, lend + 1, - (method == null ? thisClass.fieldMap : method.fieldMap), - version); - } - else if (listToken.compareTo("TLIST") == 0) - { - processConstantList(sb, lstart, lend + 1, globalConstantSet); - } - else - { - throw new AmqpTemplateException("Unknown list token \"%{" + listToken + - "}\" found in template at index " + lstart + "."); - } - } - lstart = sb.indexOf("%{", lstart + 1); - } - } - - protected void processAllTokens(StringBuffer sb, AmqpClass thisClass, AmqpMethod method, AmqpField field, - AmqpVersion version) - throws AmqpTemplateException, AmqpTypeMappingException - { - int lstart = sb.indexOf("${"); - while (lstart != -1) - { - int lend = sb.indexOf("}", lstart + 2); - if (lend > 0) - { - String token = sb.substring(lstart, lend + 1); - replaceToken(sb, lstart, token, processToken(token, thisClass, method, field, version)); - } - lstart = sb.indexOf("${", lstart); - } - } - - protected static void writeTargetFile(StringBuffer sb, File f) - throws IOException - { - FileWriter fw = new FileWriter(f); - fw.write(sb.toString().toCharArray()); - fw.flush(); - fw.close(); - } - - protected static String getTemplateFileName(StringBuffer sb) - throws AmqpTemplateException - { - if (sb.charAt(0) != '&') - throw new AmqpTemplateException("No filename marker &{filename} found at start of template."); - int cr = sb.indexOf(Utils.lineSeparator); - if (cr < 0) - throw new AmqpTemplateException("Bad template structure - unable to find first line."); - String fileName = sb.substring(2, cr-1); - sb.delete(0, cr + 1); - return fileName; - } - - protected static void replaceToken(StringBuffer sb, String token, String replacement) - { - replaceToken(sb, 0, token, replacement); - } - - protected static void replaceToken(StringBuffer sb, int index, String token, String replacement) - { - if (replacement != null) - { - int start = sb.indexOf(token, index); - int len = token.length(); - // Find first letter in token and determine if it is capitalized - char firstTokenLetter = getFirstLetter(token); - if (firstTokenLetter != 0 && Character.isUpperCase(firstTokenLetter)) - sb.replace(start, start+len, Utils.firstUpper(replacement)); - else - sb.replace(start, start+len, replacement); - } - } - - private static char getFirstLetter(String str) - { - int len = str.length(); - int index = 0; - char tokChar = str.charAt(index); - while (!Character.isLetter(tokChar) && index<len-1) - tokChar = str.charAt(++index); - if (Character.isLetter(tokChar)) - return tokChar; - return 0; - } - - private static String loadTemplate(File f) - throws FileNotFoundException, IOException - { - StringBuffer sb = new StringBuffer(); - FileReader fr = new FileReader(f); - LineNumberReader lnr = new LineNumberReader(fr); - String line = lnr.readLine(); - while (line != null) - { - // Strip lines starting with '#' in template - treat these lines as template comments -// if (line.length() > 0 && line.charAt(0) != '#') // Bad idea - '#' used in C/C++ files (#include)! - if (line.length() > 0) - sb.append(line + Utils.lineSeparator); - else - sb.append(Utils.lineSeparator); - line = lnr.readLine(); - } - lnr.close(); - fr.close(); - return sb.toString(); - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/JavaGenerator.java b/qpid/gentools/org/apache/qpid/gentools/JavaGenerator.java deleted file mode 100644 index 4c168cd036..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/JavaGenerator.java +++ /dev/null @@ -1,1641 +0,0 @@ -/* - * - * 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.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.TreeMap; - -public class JavaGenerator extends Generator -{ - private class DomainInfo - { - public String type; - public String size; - public String encodeExpression; - public String decodeExpression; - public DomainInfo(String domain, String size, String encodeExpression, String decodeExpression) - { - this.type = domain; - this.size = size; - this.encodeExpression = encodeExpression; - this.decodeExpression = decodeExpression; - } - } - - private static TreeMap<String, DomainInfo> typeMap = new TreeMap<String, DomainInfo>(); - - // Methods used for generation of code snippets called from the field map parsers - - // Common methods - static private Method declarationGenerateMethod; - static private Method mangledDeclarationGenerateMethod; - - // Methods for MessageBody classes - static private Method mbGetGenerateMethod; - static private Method mbMangledGetGenerateMethod; - static private Method mbParamListGenerateMethod; - static private Method mbMangledParamListGenerateMethod; - static private Method mbBodyInitGenerateMethod; - static private Method mbMangledBodyInitGenerateMethod; - static private Method mbSizeGenerateMethod; - static private Method mbBitSizeGenerateMethod; - static private Method mbEncodeGenerateMethod; - static private Method mbBitEncodeGenerateMethod; - static private Method mbDecodeGenerateMethod; - static private Method mbBitDecodeGenerateMethod; - static private Method mbToStringGenerateMethod; - static private Method mbBitToStringGenerateMethod; - - // Methods for PropertyContentHeader classes - static private Method pchClearGenerateMethod; - static private Method pchMangledClearGenerateMethod; - static private Method pchGetGenerateMethod; - static private Method pchMangledGetGenerateMethod; - static private Method pchSetGenerateMethod; - static private Method pchMangledSetGenerateMethod; - static private Method pchSizeGenerateMethod; - static private Method pchBitSizeGenerateMethod; - static private Method pchEncodeGenerateMethod; - static private Method pchBitEncodeGenerateMethod; - static private Method pchDecodeGenerateMethod; - static private Method pchBitDecodeGenerateMethod; - static private Method pchGetPropertyFlagsGenerateMethod; - static private Method pchBitGetPropertyFlagsGenerateMethod; - static private Method pchSetPropertyFlagsGenerateMethod; - static private Method pchBitSetPropertyFlagsGenerateMethod; - - static - { - // ************** - // Common methods - // ************** - - // Methods for AmqpFieldMap.parseFieldMap() - - try { declarationGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateFieldDeclaration", String.class, AmqpField.class, - AmqpVersionSet.class, int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mangledDeclarationGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMangledFieldDeclaration", AmqpField.class, - int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - - // ******************************* - // Methods for MessageBody classes - // ******************************* - - // Methods for AmqpFieldMap.parseFieldMap() - - try { mbGetGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbGetMethod", String.class, AmqpField.class, - AmqpVersionSet.class, int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mbMangledGetGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbMangledGetMethod", AmqpField.class, - int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mbParamListGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbParamList", String.class, AmqpField.class, - AmqpVersionSet.class, int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mbMangledParamListGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbMangledParamList", AmqpField.class, - int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mbBodyInitGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbBodyInit", String.class, AmqpField.class, - AmqpVersionSet.class, int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mbMangledBodyInitGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbMangledBodyInit", AmqpField.class, - int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - // Methods for AmqpFieldMap.parseFieldMapOrdinally() - - try { mbSizeGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbFieldSize", String.class, String.class, - int.class, int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mbBitSizeGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbBitArrayFieldSize", ArrayList.class, int.class, - int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mbEncodeGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbFieldEncode", String.class, String.class, - int.class, int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mbBitEncodeGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbBitFieldEncode", ArrayList.class, int.class, - int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mbDecodeGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbFieldDecode", String.class, String.class, - int.class, int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mbBitDecodeGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbBitFieldDecode", ArrayList.class, int.class, - int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mbToStringGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbFieldToString", String.class, String.class, - int.class, int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { mbBitToStringGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generateMbBitFieldToString", ArrayList.class, int.class, - int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - // ***************************************** - // Methods for PropertyContentHeader classes - // ***************************************** - - // Methods for AmqpFieldMap.parseFieldMap() - - try { pchClearGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchClearMethod", String.class, AmqpField.class, - AmqpVersionSet.class, int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchMangledClearGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchMangledClearMethod", AmqpField.class, - int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchSetGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchSetMethod", String.class, AmqpField.class, - AmqpVersionSet.class, int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchMangledSetGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchMangledSetMethod", AmqpField.class, - int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchGetGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchGetMethod", String.class, AmqpField.class, - AmqpVersionSet.class, int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchMangledGetGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchMangledGetMethod", AmqpField.class, - int.class, int.class, boolean.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - // Methods for AmqpFieldMap.parseFieldMapOrdinally() - - try { pchSizeGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchFieldSize", String.class, String.class, - int.class, int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchBitSizeGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchBitArrayFieldSize", ArrayList.class, int.class, - int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchEncodeGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchFieldEncode", String.class, String.class, - int.class, int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchBitEncodeGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchBitFieldEncode", ArrayList.class, int.class, - int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchDecodeGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchFieldDecode", String.class, String.class, - int.class, int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchBitDecodeGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchBitFieldDecode", ArrayList.class, int.class, - int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchGetPropertyFlagsGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchGetPropertyFlags", String.class, String.class, - int.class, int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchBitGetPropertyFlagsGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchBitGetPropertyFlags", ArrayList.class, int.class, - int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchSetPropertyFlagsGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchSetPropertyFlags", String.class, String.class, - int.class, int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - - try { pchBitSetPropertyFlagsGenerateMethod = JavaGenerator.class.getDeclaredMethod( - "generatePchBitSetPropertyFlags", ArrayList.class, int.class, - int.class, int.class); } - catch (NoSuchMethodException e) { e.printStackTrace(); } - } - - public JavaGenerator(AmqpVersionSet versionList) - { - super(versionList); - // Load Java type and size maps. - // Adjust or add to these lists as new types are added/defined. - // The char '#' will be replaced by the field variable name (any type). - // The char '~' will be replaced by the compacted bit array size (type bit only). - typeMap.put("bit", new DomainInfo( - "boolean", // Java code type - "~", // size - "EncodingUtils.writeBooleans(buffer, #)", // encode expression - "# = EncodingUtils.readBooleans(buffer)")); // decode expression - typeMap.put("long", new DomainInfo( - "long", // Java code type - "4", // size - "EncodingUtils.writeUnsignedInteger(buffer, #)", // encode expression - "# = buffer.getUnsignedInt()")); // decode expression - typeMap.put("longlong", new DomainInfo( - "long", // Java code type - "8", // size - "buffer.putLong(#)", // encode expression - "# = buffer.getLong()")); // decode expression - typeMap.put("longstr", new DomainInfo( - "String", // Java code type - "EncodingUtils.encodedLongStringLength(#)", // size - "EncodingUtils.writeLongStringBytes(buffer, #)", // encode expression - "# = EncodingUtils.readLongString(buffer)")); // decode expression - typeMap.put("octet", new DomainInfo( - "char", // Java code type - "1", // size - "buffer.putChar(#)", // encode expression - "# = buffer.getChar()")); // decode expression - typeMap.put("short", new DomainInfo( - "int", // Java code type - "2", // size - "EncodingUtils.writeUnsignedShort(buffer, #)", // encode expression - "# = buffer.getUnsignedShort()")); // decode expression - typeMap.put("shortstr", new DomainInfo( - "String", // Java code type - "EncodingUtils.encodedShortStringLength(#)", // size - "EncodingUtils.writeShortStringBytes(buffer, #)", // encode expression - "# = EncodingUtils.readShortString(buffer)")); // decode expression - typeMap.put("table", new DomainInfo( - "FieldTable", // Java code type - "EncodingUtils.encodedFieldTableLength(#)", // size - "EncodingUtils.writeFieldTableBytes(buffer, #)", // encode expression - "# = EncodingUtils.readFieldTable(buffer)")); // decode expression - typeMap.put("timestamp", new DomainInfo( - "long", // Java code type - "8", // size - "EncodingUtils.writeTimestamp(buffer, #)", // encode expression - "# = EncodingUtils.readTimestamp(buffer)")); // decode expression - } - - // === Start of methods for Interface LanguageConverter === - - public String prepareClassName(String className) - { - return camelCaseName(className, true); - } - - public String prepareMethodName(String methodName) - { - return camelCaseName(methodName, false); - } - - public String prepareDomainName(String domainName) - { - return camelCaseName(domainName, false); - } - - public String getDomainType(String domainName, AmqpVersion version) - throws AmqpTypeMappingException - { - return globalDomainMap.getDomainType(domainName, version); - } - - public String getGeneratedType(String domainName, AmqpVersion version) - throws AmqpTypeMappingException - { - String domainType = globalDomainMap.getDomainType(domainName, version); - if (domainType == null) - throw new AmqpTypeMappingException("Domain type \"" + domainName + "\" not found in Java typemap."); - return typeMap.get(domainType).type; - } - - - // === Abstract methods from class Generator - Java-specific implementations === - - @Override - protected String prepareFilename(String filenameTemplate, AmqpClass thisClass, AmqpMethod method, - AmqpField field) - { - StringBuffer sb = new StringBuffer(filenameTemplate); - if (thisClass != null) - replaceToken(sb, "${CLASS}", thisClass.name); - if (method != null) - replaceToken(sb, "${METHOD}", method.name); - if (field != null) - replaceToken(sb, "${FIELD}", field.name); - return sb.toString(); - } - - @Override - protected void processTemplateA(String[] template) - throws IOException, AmqpTemplateException, AmqpTypeMappingException, - IllegalAccessException, InvocationTargetException - { - processTemplateD(template, null, null, null); - } - - @Override - protected void processTemplateB(String[] template, AmqpClass thisClass) - throws IOException, AmqpTemplateException, AmqpTypeMappingException, - IllegalAccessException, InvocationTargetException - { - processTemplateD(template, thisClass, null, null); - } - - @Override - protected void processTemplateC(String[] template, AmqpClass thisClass, - AmqpMethod method) - throws IOException, AmqpTemplateException, AmqpTypeMappingException, - IllegalAccessException, InvocationTargetException - { - processTemplateD(template, thisClass, method, null); - } - - @Override - protected void processTemplateD(String[] template, AmqpClass thisClass, - AmqpMethod method, AmqpField field) - throws IOException, AmqpTemplateException, AmqpTypeMappingException, - IllegalAccessException, InvocationTargetException - { - StringBuffer sb = new StringBuffer(template[1]); - String filename = prepareFilename(getTemplateFileName(sb), thisClass, method, field); - processTemplate(sb, thisClass, method, field, template[templateFileNameIndex], null); - writeTargetFile(sb, new File(genDir + Utils.fileSeparator + filename)); - generatedFileCounter ++; - } - - protected void processTemplate(StringBuffer sb, AmqpClass thisClass, AmqpMethod method, - AmqpField field, String templateFileName, AmqpVersion version) - throws InvocationTargetException, IllegalAccessException, AmqpTypeMappingException - { - try { processAllLists(sb, thisClass, method, version); } - catch (AmqpTemplateException e) - { - System.out.println("WARNING: " + templateFileName + ": " + e.getMessage()); - } - try { processAllTokens(sb, thisClass, method, field, version); } - catch (AmqpTemplateException e) - { - System.out.println("WARNING: " + templateFileName + ": " + e.getMessage()); - } - } - - @Override - protected String processToken(String token, AmqpClass thisClass, AmqpMethod method, AmqpField field, - AmqpVersion version) - throws AmqpTemplateException, AmqpTypeMappingException - { - if (token.compareTo("${GENERATOR}") == 0) - return generatorInfo; - if (token.compareTo("${CLASS}") == 0 && thisClass != null) - return thisClass.name; - if (token.compareTo("${CLASS_ID_INIT}") == 0 && thisClass != null) - return generateIndexInitializer("classIdMap", thisClass.indexMap, 8); - if (token.compareTo("${METHOD}") == 0 && method != null) - return method.name; - if (token.compareTo("${METHOD_ID_INIT}") == 0 && method != null) - return generateIndexInitializer("methodIdMap", method.indexMap, 8); - if (token.compareTo("${FIELD}") == 0 && field != null) - return field.name; - - // This token is used only with class or method-level templates - if (token.compareTo("${pch_property_flags_declare}") == 0) - { - return generatePchPropertyFlagsDeclare(); - } - else if (token.compareTo("${pch_property_flags_initializer}") == 0) - { - int mapSize = method == null ? thisClass.fieldMap.size() : method.fieldMap.size(); - return generatePchPropertyFlagsInitializer(mapSize); - } - else if (token.compareTo("${pch_compact_property_flags_initializer}") == 0) - { - return generatePchCompactPropertyFlagsInitializer(thisClass, 8, 4); - } - else if (token.compareTo("${pch_compact_property_flags_check}") == 0) - { - return generatePchCompactPropertyFlagsCheck(thisClass, 8, 4); - } - - // Oops! - throw new AmqpTemplateException("Template token " + token + " unknown."); - } - - @Override - protected void processClassList(StringBuffer sb, int listMarkerStartIndex, int listMarkerEndIndex, - AmqpModel model) - throws AmqpTemplateException, AmqpTypeMappingException - { - String codeSnippet; - int lend = sb.indexOf(cr, listMarkerStartIndex) + 1; // Include cr at end of line - String tline = sb.substring(listMarkerEndIndex, lend); // Line excluding line marker, including cr - int tokStart = tline.indexOf('$'); - String token = tline.substring(tokStart).trim(); - sb.delete(listMarkerStartIndex, lend); - - if (token.compareTo("${reg_map_put_method}") == 0) - { - codeSnippet = generateRegistry(model, 8, 4); - } - - else // Oops! - { - throw new AmqpTemplateException("Template token " + token + " unknown."); - } - - sb.insert(listMarkerStartIndex, codeSnippet); - } - - @Override - protected void processMethodList(StringBuffer sb, int listMarkerStartIndex, int listMarkerEndIndex, - AmqpClass thisClass) - throws AmqpTemplateException, AmqpTypeMappingException - { - String codeSnippet; - int lend = sb.indexOf(cr, listMarkerStartIndex) + 1; // Include cr at end of line - String tline = sb.substring(listMarkerEndIndex, lend); // Line excluding line marker, including cr - int tokStart = tline.indexOf('$'); - String token = tline.substring(tokStart).trim(); - sb.delete(listMarkerStartIndex, lend); - - //TODO - we don't have any cases of this (yet). - if (token.compareTo("${???}") == 0) - { - codeSnippet = token; - } - else // Oops! - { - throw new AmqpTemplateException("Template token " + token + " unknown."); - } - - sb.insert(listMarkerStartIndex, codeSnippet); - } - - @Override - protected void processFieldList(StringBuffer sb, int listMarkerStartIndex, int listMarkerEndIndex, - AmqpFieldMap fieldMap, AmqpVersion version) - throws AmqpTypeMappingException, AmqpTemplateException, IllegalAccessException, - InvocationTargetException - { - String codeSnippet; - int lend = sb.indexOf(cr, listMarkerStartIndex) + 1; // Include cr at end of line - String tline = sb.substring(listMarkerEndIndex, lend); // Line excluding line marker, including cr - int tokStart = tline.indexOf('$'); - String token = tline.substring(tokStart).trim(); - sb.delete(listMarkerStartIndex, lend); - - // Field declarations - common to MethodBody and PropertyContentHeader classes - if (token.compareTo("${field_declaration}") == 0) - { - codeSnippet = fieldMap.parseFieldMap(declarationGenerateMethod, - mangledDeclarationGenerateMethod, 4, 4, this); - } - - // MethodBody classes - else if (token.compareTo("${mb_field_get_method}") == 0) - { - codeSnippet = fieldMap.parseFieldMap(mbGetGenerateMethod, - mbMangledGetGenerateMethod, 4, 4, this); - } - else if (token.compareTo("${mb_field_parameter_list}") == 0) - { - // This is klunky... (cringe) TODO: Find a more elegant solution here sometime... - codeSnippet = fieldMap.size() > 0 ? Utils.createSpaces(42) + "," + cr : ""; - codeSnippet += fieldMap.parseFieldMap(mbParamListGenerateMethod, - mbMangledParamListGenerateMethod, 42, 4, this); - } - else if (token.compareTo("${mb_field_body_initialize}") == 0) - { - codeSnippet = fieldMap.parseFieldMap(mbBodyInitGenerateMethod, - mbMangledBodyInitGenerateMethod, 8, 4, this); - } - else if (token.compareTo("${mb_field_size}") == 0) - { - codeSnippet = fieldMap.parseFieldMapOrdinally(mbSizeGenerateMethod, - mbBitSizeGenerateMethod, 8, 4, this); - } - else if (token.compareTo("${mb_field_encode}") == 0) - { - codeSnippet = fieldMap.parseFieldMapOrdinally(mbEncodeGenerateMethod, - mbBitEncodeGenerateMethod, 8, 4, this); - } - else if (token.compareTo("${mb_field_decode}") == 0) - { - codeSnippet = fieldMap.parseFieldMapOrdinally(mbDecodeGenerateMethod, - mbBitDecodeGenerateMethod, 8, 4, this); - } - else if (token.compareTo("${mb_field_to_string}") == 0) - { - codeSnippet = fieldMap.parseFieldMapOrdinally(mbToStringGenerateMethod, - mbBitToStringGenerateMethod, 8, 4, this); - } - - // PropertyContentHeader classes - else if (token.compareTo("${pch_field_list_size}") == 0) - { - codeSnippet = fieldMap.parseFieldMapOrdinally(pchSizeGenerateMethod, - pchBitSizeGenerateMethod, 12, 4, this); - } - else if (token.compareTo("${pch_field_list_payload}") == 0 ) - { - codeSnippet = fieldMap.parseFieldMapOrdinally(pchEncodeGenerateMethod, - pchBitEncodeGenerateMethod, 12, 4, this); - } - else if (token.compareTo("${pch_field_list_decode}") == 0) - { - codeSnippet = fieldMap.parseFieldMapOrdinally(pchDecodeGenerateMethod, - pchBitDecodeGenerateMethod, 12, 4, this); - } - else if (token.compareTo("${pch_get_compact_property_flags}") == 0) - { - codeSnippet = fieldMap.parseFieldMapOrdinally(pchGetPropertyFlagsGenerateMethod, - pchBitGetPropertyFlagsGenerateMethod, 8, 4, this); - } - else if (token.compareTo("${pch_set_compact_property_flags}") == 0) - { - codeSnippet = fieldMap.parseFieldMapOrdinally(pchSetPropertyFlagsGenerateMethod, - pchBitSetPropertyFlagsGenerateMethod, 8, 4, this); - } - else if (token.compareTo("${pch_field_clear_methods}") == 0) - { - codeSnippet = fieldMap.parseFieldMap(pchClearGenerateMethod, - pchMangledClearGenerateMethod, 4, 4, this); - } - else if (token.compareTo("${pch_field_get_methods}") == 0) - { - codeSnippet = fieldMap.parseFieldMap(pchGetGenerateMethod, - pchMangledGetGenerateMethod, 4, 4, this); - } - else if (token.compareTo("${pch_field_set_methods}") == 0) - { - codeSnippet = fieldMap.parseFieldMap(pchSetGenerateMethod, - pchMangledSetGenerateMethod, 4, 4, this); - } - - else // Oops! - { - throw new AmqpTemplateException("Template token " + token + " unknown."); - } - sb.insert(listMarkerStartIndex, codeSnippet); - } - - @Override - protected void processConstantList(StringBuffer sb, int listMarkerStartIndex, int listMarkerEndIndex, - AmqpConstantSet constantSet) - throws AmqpTemplateException, AmqpTypeMappingException - - { - String codeSnippet; - int lend = sb.indexOf(cr, listMarkerStartIndex) + 1; // Include cr at end of line - String tline = sb.substring(listMarkerEndIndex, lend); // Line excluding line marker, including cr - int tokStart = tline.indexOf('$'); - String token = tline.substring(tokStart).trim(); - sb.delete(listMarkerStartIndex, lend); - - if (token.compareTo("${const_get_method}") == 0) - { - codeSnippet = generateConstantGetMethods(constantSet, 4, 4); - } - - else // Oops! - { - throw new AmqpTemplateException("Template token " + token + " unknown."); - } - - sb.insert(listMarkerStartIndex, codeSnippet); - } - - - // === Protected and private helper functions unique to Java implementation === - - // Methods used for generation of code snippets called from the field map parsers - - // Common methods - - protected String generateFieldDeclaration(String codeType, AmqpField field, - AmqpVersionSet versionSet, int indentSize, int tabSize, boolean nextFlag) - { - return Utils.createSpaces(indentSize) + "public " + codeType + " " + field.name + - "; // AMQP version(s): " + versionSet + cr; - } - - protected String generateMangledFieldDeclaration(AmqpField field, int indentSize, - int tabSize, boolean nextFlag) - throws AmqpTypeMappingException - { - StringBuffer sb = new StringBuffer(); - Iterator<String> dItr = field.domainMap.keySet().iterator(); - int domainCntr = 0; - while (dItr.hasNext()) - { - String domainName = dItr.next(); - AmqpVersionSet versionSet = field.domainMap.get(domainName); - String codeType = getGeneratedType(domainName, versionSet.first()); - sb.append(Utils.createSpaces(indentSize) + "public " + codeType + " " + - field.name + "_" + (domainCntr++) + "; // AMQP Version(s): " + versionSet + - cr); - } - return sb.toString(); - } - - protected String generateIndexInitializer(String mapName, AmqpOrdinalVersionMap indexMap, int indentSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - - Iterator<Integer> iItr = indexMap.keySet().iterator(); - while (iItr.hasNext()) - { - int index = iItr.next(); - AmqpVersionSet versionSet = indexMap.get(index); - Iterator<AmqpVersion> vItr = versionSet.iterator(); - while (vItr.hasNext()) - { - AmqpVersion version = vItr.next(); - sb.append(indent + mapName + ".put(\"" + version.toString() + "\", " + index + ");" + cr); - } - } - return sb.toString(); - } - - protected String generateRegistry(AmqpModel model, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - - Iterator<String> cItr = model.classMap.keySet().iterator(); - while (cItr.hasNext()) - { - AmqpClass thisClass = model.classMap.get(cItr.next()); - AmqpVersionSet firstVersionSet = thisClass.indexMap.get(thisClass.indexMap.firstKey()); - boolean classVersionConsistentFlag = firstVersionSet.equals(globalVersionSet); - Iterator<String> mItr = thisClass.methodMap.keySet().iterator(); - while (mItr.hasNext()) - { - AmqpMethod method = thisClass.methodMap.get(mItr.next()); - firstVersionSet = method.indexMap.get(method.indexMap.firstKey()); - boolean methodVersionConsistentFlag = firstVersionSet.equals(globalVersionSet); - if (classVersionConsistentFlag && methodVersionConsistentFlag) - { - // Both class and method with consistent indeces for all known versions - int classIndex = thisClass.indexMap.firstKey(); - int methodIndex = method.indexMap.firstKey(); - sb.append(indent + "map.put(" + classIndex + "*1000 + " + methodIndex + - ", " + thisClass.name + Utils.firstUpper(method.name) + "Body.class);" + cr); - } - else - { - // Non-consistent indeces for all known versions - version-specific code required - sb.append(cr); - - Iterator<AmqpVersion> vItr = globalVersionSet.iterator(); - while (vItr.hasNext()) - { - boolean first = true; - AmqpVersion version = vItr.next(); - - // Find class and method index for this version (if it exists) - try - { - int classIndex = findIndex(thisClass.indexMap, version); - int methodIndex = findIndex(method.indexMap, version); - sb.append(indent); - if (!first) - sb.append("else "); - sb.append("if ( major == " + version.getMajor() + " && minor == " + - version.getMinor() + " )" + cr); - sb.append(indent + tab + "map.put(" + classIndex + "*1000 + " + - methodIndex + ", " + thisClass.name + Utils.firstUpper(method.name) + - "Body.class);" + cr); - first = false; - } - catch (Exception e) {} // Ignore - } - sb.append(cr); - } - } - } - return sb.toString(); - } - - protected int findIndex(TreeMap<Integer, AmqpVersionSet> map, AmqpVersion version) - throws Exception - { - Iterator<Integer> iItr = map.keySet().iterator(); - while (iItr.hasNext()) - { - int index = iItr.next(); - AmqpVersionSet versionSet = map.get(index); - if (versionSet.contains(version)) - return index; - } - throw new Exception("Index not found"); - } - - // Methods for AmqpConstants class - - protected String generateConstantGetMethods(AmqpConstantSet constantSet, - int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - Iterator<AmqpConstant> cItr = constantSet.iterator(); - while (cItr.hasNext()) - { - AmqpConstant constant = cItr.next(); - if (constant.isVersionConsistent(globalVersionSet)) - { - // return a constant - String value = constant.firstKey(); - sb.append(indent + "public static String " + constant.name + "() { return \"" + - constant.firstKey() + "\"; }" + cr); - if (Utils.containsOnlyDigits(value)) - { - sb.append(indent + "public static int " + constant.name + "AsInt() { return " + - constant.firstKey() + "; }" + cr); - } - if (Utils.containsOnlyDigitsAndDecimal(value)) - { - sb.append(indent + "public static double " + constant.name + "AsDouble() { return (double)" + - constant.firstKey() + "; }" + cr); - } - sb.append(cr); - } - else - { - // Return version-specific constant - sb.append(generateVersionDependentGet(constant, "String", "", "\"", "\"", indentSize, tabSize)); - sb.append(generateVersionDependentGet(constant, "int", "AsInt", "", "", indentSize, tabSize)); - sb.append(generateVersionDependentGet(constant, "double", "AsDouble", "(double)", "", indentSize, tabSize)); - sb.append(cr); - } - } - return sb.toString(); - } - - protected String generateVersionDependentGet(AmqpConstant constant, - String methodReturnType, String methodNameSuffix, String returnPrefix, String returnPostfix, - int indentSize, int tabSize) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - sb.append(indent + "public static " + methodReturnType + " " + constant.name + - methodNameSuffix + "(byte major, byte minor) throws AMQProtocolVersionException" + cr); - sb.append(indent + "{" + cr); - boolean first = true; - Iterator<String> sItr = constant.keySet().iterator(); - while (sItr.hasNext()) - { - String value = sItr.next(); - AmqpVersionSet versionSet = constant.get(value); - sb.append(indent + tab + (first ? "" : "else ") + "if (" + generateVersionCheck(versionSet) + - ")" + cr); - sb.append(indent + tab + "{" + cr); - if (methodReturnType.compareTo("int") == 0 && !Utils.containsOnlyDigits(value)) - { - sb.append(generateConstantDeclarationException(constant.name, methodReturnType, - indentSize + (2*tabSize), tabSize)); - } - else if (methodReturnType.compareTo("double") == 0 && !Utils.containsOnlyDigitsAndDecimal(value)) - { - sb.append(generateConstantDeclarationException(constant.name, methodReturnType, - indentSize + (2*tabSize), tabSize)); - } - else - { - sb.append(indent + tab + tab + "return " + returnPrefix + value + returnPostfix + ";" + cr); - } - sb.append(indent + tab + "}" + cr); - first = false; - } - sb.append(indent + tab + "else" + cr); - sb.append(indent + tab + "{" + cr); - sb.append(indent + tab + tab + "throw new AMQProtocolVersionException(\"Constant \\\"" + - constant.name + "\\\" \" +" + cr); - sb.append(indent + tab + tab + tab + - "\"is undefined for AMQP version \" + major + \"-\" + minor + \".\");" + cr); - sb.append(indent + tab + "}" + cr); - sb.append(indent + "}" + cr); - return sb.toString(); - } - - protected String generateConstantDeclarationException(String name, String methodReturnType, - int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - sb.append(indent + "throw new AMQProtocolVersionException(\"Constant \\\"" + - name + "\\\" \" +" + cr); - sb.append(indent + tab + "\"cannot be converted to type " + methodReturnType + - " for AMQP version \" + major + \"-\" + minor + \".\");" + cr); - return sb.toString(); - } - - // Methods for MessageBody classes - protected String generateMbGetMethod(String codeType, AmqpField field, - AmqpVersionSet versionSet, int indentSize, int tabSize, boolean nextFlag) - { - return Utils.createSpaces(indentSize) + "public " + codeType + " get" + - Utils.firstUpper(field.name) + "() { return " + field.name + "; }" + - cr; - } - - protected String generateMbMangledGetMethod(AmqpField field, int indentSize, - int tabSize, boolean nextFlag) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(cr); - sb.append(indent + "public <T> T get" + Utils.firstUpper(field.name) + - "(Class<T> classObj) throws AMQProtocolVersionException" + cr); - sb.append(indent + "{" + cr); - Iterator<String> dItr = field.domainMap.keySet().iterator(); - int domainCntr = 0; - while (dItr.hasNext()) - { - String domainName = dItr.next(); - AmqpVersionSet versionSet = field.domainMap.get(domainName); - String codeType = getGeneratedType(domainName, versionSet.first()); - sb.append(indent + tab + "if (classObj.equals(" + codeType + - ".class)) // AMQP Version(s): " + versionSet + cr); - sb.append(indent + tab + tab + "return (T)(Object)" + field.name + "_" + - (domainCntr++) + ";" + cr); - } - sb.append(indent + tab + - "throw new AMQProtocolVersionException(\"None of the AMQP versions defines \" +" + - cr + " \"field \\\"" + field.name + - "\\\" as domain \\\"\" + classObj.getName() + \"\\\".\");" + cr); - sb.append(indent + "}" + cr); - sb.append(cr); - return sb.toString(); - } - - protected String generateMbParamList(String codeType, AmqpField field, - AmqpVersionSet versionSet, int indentSize, int tabSize, boolean nextFlag) - { - return Utils.createSpaces(indentSize) + codeType + " " + field.name + - (nextFlag ? "," : "") + " // AMQP version(s): " + versionSet + cr; - } - - protected String generateMbMangledParamList(AmqpField field, int indentSize, - int tabSize, boolean nextFlag) - throws AmqpTypeMappingException - { - StringBuffer sb = new StringBuffer(); - Iterator<String> dItr = field.domainMap.keySet().iterator(); - int domainCntr = 0; - while (dItr.hasNext()) - { - String domainName = dItr.next(); - AmqpVersionSet versionSet = field.domainMap.get(domainName); - String codeType = getGeneratedType(domainName, versionSet.first()); - sb.append(Utils.createSpaces(indentSize) + codeType + " " + field.name + "_" + - (domainCntr++) + (nextFlag ? "," : "") + " // AMQP version(s): " + - versionSet + cr); - } - return sb.toString(); - } - - protected String generateMbBodyInit(String codeType, AmqpField field, - AmqpVersionSet versionSet, int indentSize, int tabSize, boolean nextFlag) - { - return Utils.createSpaces(indentSize) + "body." + field.name + " = " + field.name + - ";" + cr; - } - - protected String generateMbMangledBodyInit(AmqpField field, int indentSize, - int tabSize, boolean nextFlag) - throws AmqpTypeMappingException - { - StringBuffer sb = new StringBuffer(); - Iterator<String> dItr = field.domainMap.keySet().iterator(); - int domainCntr = 0; - while (dItr.hasNext()) - { - dItr.next(); - sb.append(Utils.createSpaces(indentSize) + "body." + field.name + "_" + domainCntr + - " = " + field.name + "_" + (domainCntr++) + ";" + cr); - } - return sb.toString(); - } - - protected String generateMbFieldSize(String domainType, String fieldName, - int ordinal, int indentSize, int tabSize) - { - StringBuffer sb = new StringBuffer(); - sb.append(Utils.createSpaces(indentSize) + "size += " + - typeMap.get(domainType).size.replaceAll("#", fieldName) + - "; // " + fieldName + ": " + domainType + cr); - return sb.toString(); - } - - protected String generateMbBitArrayFieldSize(ArrayList<String> bitFieldList, - int ordinal, int indentSize, int tabSize) - { - StringBuffer sb = new StringBuffer(); - int numBytes = ((bitFieldList.size() - 1) / 8) + 1; - String comment = bitFieldList.size() == 1 ? - bitFieldList.get(0) + ": bit" : - "Combinded bits: " + bitFieldList; - sb.append(Utils.createSpaces(indentSize) + "size += " + - typeMap.get("bit").size.replaceAll("~", String.valueOf(numBytes)) + - "; // " + comment + cr); - return sb.toString(); - } - - protected String generateMbFieldEncode(String domain, String fieldName, - int ordinal, int indentSize, int tabSize) - { - StringBuffer sb = new StringBuffer(); - sb.append(Utils.createSpaces(indentSize) + - typeMap.get(domain).encodeExpression.replaceAll("#", fieldName) + - "; // " + fieldName + ": " + domain + cr); - return sb.toString(); - } - - protected String generateMbBitFieldEncode(ArrayList<String> bitFieldList, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - String bitArrayName = "bitArray_" + ordinal; - StringBuffer sb = new StringBuffer(indent + "boolean[] " + bitArrayName + - " = new boolean[] { "); - for (int i=0; i<bitFieldList.size(); i++) - { - if (i != 0) - { - if ((i + 3) % 6 == 0) - sb.append("," + cr + indent + Utils.createSpaces(tabSize)); - else - sb.append(", "); - } - sb.append(bitFieldList.get(i)); - } - sb.append(" };" + cr); - sb.append(Utils.createSpaces(indentSize) + - typeMap.get("bit").encodeExpression.replaceAll("#", bitArrayName) + ";" + cr); - return sb.toString(); - } - - protected String generateMbFieldDecode(String domain, String fieldName, - int ordinal, int indentSize, int tabSize) - { - StringBuffer sb = new StringBuffer(); - sb.append(Utils.createSpaces(indentSize) + - typeMap.get(domain).decodeExpression.replaceAll("#", fieldName) + - "; // " + fieldName + ": " + domain + cr); - return sb.toString(); - } - - protected String generateMbBitFieldDecode(ArrayList<String> bitFieldList, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - String bitArrayName = "bitArray_" + ordinal; - StringBuffer sb = new StringBuffer(); - sb.append(indent + - typeMap.get("bit").decodeExpression.replaceAll("#", "boolean[] " + bitArrayName) + - ";" + cr); - for (int i=0; i<bitFieldList.size(); i++) - { - sb.append(indent + bitFieldList.get(i) + " = " + bitArrayName + "[" + i + "];" + cr); - } - return sb.toString(); - } - - protected String generateMbFieldToString(String domain, String fieldName, - int ordinal, int indentSize, int tabSize) - { - StringBuffer sb = new StringBuffer(); - sb.append(Utils.createSpaces(indentSize) + - "buf.append(\" " + fieldName + ": \" + " + fieldName + ");" + cr); - return sb.toString(); - } - - protected String generateMbBitFieldToString(ArrayList<String> bitFieldList, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - for (int i=0; i<bitFieldList.size(); i++) - { - String bitFieldName = bitFieldList.get(i); - sb.append(indent + "buf.append(\" " + bitFieldName + ": \" + " + bitFieldName + - ");" + cr); - } - return sb.toString(); - } - - // Methods for PropertyContentHeader classes - - protected String generatePchClearMethod(String codeType, AmqpField field, - AmqpVersionSet versionSet, int indentSize, int tabSize, boolean nextFlag) - throws AmqpTypeMappingException - { - // This is one case where the ordinal info is the only significant factor, - // the domain info plays no part. Defer to the mangled version; the code would be - // identical anyway... - return generatePchMangledClearMethod(field, indentSize, tabSize, nextFlag); - } - - protected String generatePchMangledClearMethod(AmqpField field, int indentSize, - int tabSize, boolean nextFlag) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - sb.append(indent + "public void clear" + Utils.firstUpper(field.name) + - "()" + cr); - sb.append(indent + "{" + cr); - - // If there is more than one ordinal for this field or the ordinal does not - // apply to all known versions, then we need to generate version checks so - // we know which fieldProperty to clear. - if (field.ordinalMap.size() == 1 && - field.ordinalMap.get(field.ordinalMap.firstKey()).size() == globalVersionSet.size()) - { - int ordinal = field.ordinalMap.firstKey(); - sb.append(indent + tab + "clearEncodedForm();" + cr); - sb.append(indent + tab + "propertyFlags[" + ordinal + "] = false;" + cr); - } - else - { - Iterator<Integer> oItr = field.ordinalMap.keySet().iterator(); - while (oItr.hasNext()) - { - int ordinal = oItr.next(); - AmqpVersionSet versionSet = field.ordinalMap.get(ordinal); - sb.append(indent + tab); - if (ordinal != field.ordinalMap.firstKey()) - sb.append("else "); - sb.append("if ("); - sb.append(generateVersionCheck(versionSet)); - sb.append(")" + cr); - sb.append(indent + tab + "{" + cr); - sb.append(indent + tab + tab + "clearEncodedForm();" + cr); - sb.append(indent + tab + tab + "propertyFlags[" + ordinal + "] = false;" + cr); - sb.append(indent + tab + "}" + cr); - } - } - sb.append(indent + "}" + cr); - sb.append(cr); - return sb.toString(); - } - - protected String generatePchGetMethod(String codeType, AmqpField field, - AmqpVersionSet versionSet, int indentSize, int tabSize, boolean nextFlag) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(indent + "public " + codeType + " get" + - Utils.firstUpper(field.name) + "()" + cr); - sb.append(indent + "{" + cr); - sb.append(indent + tab + "decodeIfNecessary();" + cr); - sb.append(indent + tab + "return " + field.name + ";" + cr); - sb.append(indent + "}" + cr); - sb.append(cr); - return sb.toString(); - } - - protected String generatePchMangledGetMethod(AmqpField field, int indentSize, - int tabSize, boolean nextFlag) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(indent + "public <T> T get" + - Utils.firstUpper(field.name) + - "(Class<T> classObj) throws AMQProtocolVersionException" + cr); - sb.append(indent + "{" + cr); - Iterator<String> dItr = field.domainMap.keySet().iterator(); - int domainCntr = 0; - while (dItr.hasNext()) - { - String domainName = dItr.next(); - AmqpVersionSet versionSet = field.domainMap.get(domainName); - String codeType = getGeneratedType(domainName, versionSet.first()); - sb.append(indent + tab + "if (classObj.equals(" + codeType + - ".class)) // AMQP Version(s): " + versionSet + cr); - sb.append(indent + tab + "{" + cr); - sb.append(indent + tab + tab + "decodeIfNecessary();" + cr); - sb.append(indent + tab + tab + "return (T)(Object)" + field.name + "_" + - (domainCntr++) + ";" + cr); - sb.append(indent + tab + "}" + cr); - } - sb.append(indent + tab + - "throw new AMQProtocolVersionException(\"None of the AMQP versions defines \" +" + - cr + " \"field \\\"" + field.name + - "\\\" as domain \\\"\" + classObj.getName() + \"\\\".\");" + cr); - sb.append(indent + "}" + cr); - sb.append(cr); - return sb.toString(); - } - - protected String generatePchSetMethod(String codeType, AmqpField field, - AmqpVersionSet versionSet, int indentSize, int tabSize, boolean nextFlag) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - sb.append(indent + "public void set" + Utils.firstUpper(field.name) + - "(" + codeType + " " + field.name + ")" + cr); - sb.append(indent + "{" + cr); - - // If there is more than one ordinal for this field or the ordinal does not - // apply to all known versions, then we need to generate version checks so - // we know which fieldProperty to clear. - if (field.ordinalMap.size() == 1 && - field.ordinalMap.get(field.ordinalMap.firstKey()).size() == globalVersionSet.size()) - { - int ordinal = field.ordinalMap.firstKey(); - sb.append(indent + tab + "clearEncodedForm();" + cr); - sb.append(indent + tab + "propertyFlags[" + ordinal + "] = true;" + cr); - sb.append(indent + tab + "this." + field.name + " = " + field.name + ";" + cr); - } - else - { - Iterator<Integer> oItr = field.ordinalMap.keySet().iterator(); - while (oItr.hasNext()) - { - int ordinal = oItr.next(); - AmqpVersionSet oVersionSet = field.ordinalMap.get(ordinal); - sb.append(indent + tab); - if (ordinal != field.ordinalMap.firstKey()) - sb.append("else "); - sb.append("if ("); - sb.append(generateVersionCheck(oVersionSet)); - sb.append(")" + cr); - sb.append(indent + tab + "{" + cr); - sb.append(indent + tab + tab + "clearEncodedForm();" + cr); - sb.append(indent + tab + tab + "propertyFlags[" + ordinal + "] = true;" + cr); - sb.append(indent + tab + tab + "this." + field.name + " = " + field.name + ";" + cr); - sb.append(indent + tab + "}" + cr); - } - } - sb.append(indent + "}" + cr); - sb.append(cr); - return sb.toString(); - } - - protected String generatePchMangledSetMethod(AmqpField field, int indentSize, - int tabSize, boolean nextFlag) - throws AmqpTypeMappingException - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - - Iterator<String> dItr = field.domainMap.keySet().iterator(); - int domainCntr = 0; - while (dItr.hasNext()) - { - String domainName = dItr.next(); - AmqpVersionSet versionSet = field.domainMap.get(domainName); - String codeType = getGeneratedType(domainName, versionSet.first()); - - // Find ordinal with matching version - AmqpVersionSet commonVersionSet = new AmqpVersionSet(); - Iterator<Integer> oItr = field.ordinalMap.keySet().iterator(); - while (oItr.hasNext()) - { - int ordinal = oItr.next(); - AmqpVersionSet oVersionSet = field.ordinalMap.get(ordinal); - Iterator<AmqpVersion> vItr = oVersionSet.iterator(); - boolean first = true; - while (vItr.hasNext()) - { - AmqpVersion thisVersion = vItr.next(); - if (versionSet.contains(thisVersion)) - commonVersionSet.add(thisVersion); - } - if (!commonVersionSet.isEmpty()) - { - sb.append(indent + "public void set" + Utils.firstUpper(field.name) + - "(" + codeType + " " + field.name + ")" + cr); - sb.append(indent + "{" + cr); - sb.append(indent + tab); - if (!first) - sb.append("else "); - sb.append("if ("); - sb.append(generateVersionCheck(commonVersionSet)); - sb.append(")" + cr); - sb.append(indent + tab + "{" + cr); - sb.append(indent + tab + tab + "clearEncodedForm();" + cr); - sb.append(indent + tab + tab + "propertyFlags[" + ordinal + "] = true;" + cr); - sb.append(indent + tab + tab + "this." + field.name + "_" + (domainCntr++) + - " = " + field.name + ";" + cr); - sb.append(indent + tab + "}" + cr); - sb.append(indent + "}" + cr); - sb.append(cr); - first = false; - } - } - } - return sb.toString(); - } - - protected String generatePchFieldSize(String domainType, String fieldName, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(indent + "if (propertyFlags[" + ordinal + "]) // " + - fieldName + ": " + domainType + cr); - sb.append(indent + Utils.createSpaces(tabSize) + "size += " + - typeMap.get(domainType).size.replaceAll("#", fieldName) + ";" + cr); - sb.append(cr); - return sb.toString(); - } - - protected String generatePchBitArrayFieldSize(ArrayList<String> bitFieldList, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - String comment = bitFieldList.size() == 1 ? - bitFieldList.get(0) + ": bit" : - "Combinded bits: " + bitFieldList; - StringBuffer sb = new StringBuffer(); - - if (bitFieldList.size() == 1) // single bit - { - sb.append(indent + "if (propertyFlags[" + (ordinal - 1) + "]) // " + comment + cr); - sb.append(indent + tab + "size += " + - typeMap.get("bit").size.replaceAll("~", "1") + ";" + cr); - } - else // multiple bits - up to 8 are combined into one byte - { - String bitCntrName = "bitCntr_" + ordinal; - int startOrdinal = ordinal - bitFieldList.size(); - sb.append(indent + "// " + comment + cr); - sb.append(indent + "int " + bitCntrName + " = 0;" + cr); - sb.append(indent + "for (int i=" + startOrdinal + "; i<" + ordinal + "; i++)" + cr); - sb.append(indent + "{" + cr); - sb.append(indent + tab + "if (propertyFlags[i])" + cr); - sb.append(indent + tab + tab + bitCntrName + "++;" + cr); - sb.append(indent + "}" + cr); - sb.append(indent + "size += " + - typeMap.get("bit").size.replaceAll("~", bitCntrName + - " > 0 ? ((" + bitCntrName + " - 1) / 8) + 1 : 0") + ";" + cr); - } - sb.append(cr); - return sb.toString(); - } - - protected String generatePchFieldEncode(String domainType, String fieldName, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - sb.append(indent + "if (propertyFlags[" + ordinal + "]) // " + fieldName + ": " + - domainType + cr); - sb.append(indent + Utils.createSpaces(tabSize) + - typeMap.get(domainType).encodeExpression.replaceAll("#", fieldName) + ";" + cr); - sb.append(cr); - return sb.toString(); - } - - protected String generatePchBitFieldEncode(ArrayList<String> bitFieldList, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - String comment = bitFieldList.size() == 1 ? - bitFieldList.get(0) + ": bit" : - "Combinded bits: " + bitFieldList; - StringBuffer sb = new StringBuffer(); - - if (bitFieldList.size() == 1) // single bit - { - sb.append(indent + "if (propertyFlags[" + (ordinal - 1) + "]) // " + - bitFieldList.get(0) + ": bit" + cr); - sb.append(indent + tab + typeMap.get("bit").encodeExpression.replaceAll("#", - "new boolean[] {" + bitFieldList.get(0) + "}") + ";" + cr); - } - else // multiple bits - up to 8 are combined into one byte - { - int startOrdinal = ordinal - bitFieldList.size(); - String bitCntrName = "bitCntr" + startOrdinal; - sb.append(indent + "// " + comment + cr); - sb.append(indent + "int " + bitCntrName + " = 0;" + cr); - sb.append(indent + "for (int i=" + startOrdinal + "; i<=" + (ordinal - 1) + "; i++)" + cr); - sb.append(indent + "{" + cr); - sb.append(indent + tab + "if (propertyFlags[i])" + cr); - sb.append(indent + tab + tab + bitCntrName + "++;" + cr); - sb.append(indent + "}" + cr); - sb.append(indent + "if (" + bitCntrName + " > 0) // Are any of the property bits set?" + cr); - sb.append(indent + "{" + cr); - sb.append(indent + tab + "boolean[] fullBitArray = new boolean[] { "); - for (int i=0; i<bitFieldList.size(); i++) - { - if (i != 0) - sb.append(", "); - sb.append(bitFieldList.get(i)); - } - sb.append(" };" + cr); - sb.append(indent + tab + "boolean[] flaggedBitArray = new boolean[" +bitCntrName + - "];" + cr); - sb.append(indent + tab + bitCntrName + " = 0;" + cr); - sb.append(indent + tab + "for (int i=" + startOrdinal + "; i<=" + (ordinal - 1) + - "; i++)" + cr); - sb.append(indent + tab + "{" + cr); - sb.append(indent + tab + tab+ "if (propertyFlags[i])" + cr); - sb.append(indent + tab + tab + tab + "flaggedBitArray[" + bitCntrName + - "++] = fullBitArray[i];" + cr); - sb.append(indent + tab + "}" + cr); - sb.append(indent + tab + typeMap.get("bit").encodeExpression.replaceAll("#", - "flaggedBitArray") + ";" + cr); - sb.append(indent + "}" + cr); - } - sb.append(cr); - return sb.toString(); - } - - protected String generatePchFieldDecode(String domainType, String fieldName, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - sb.append(indent + "if (propertyFlags[" + ordinal + "]) // " + fieldName + ": " + - domainType + cr); - sb.append(indent + Utils.createSpaces(tabSize) + - typeMap.get(domainType).decodeExpression.replaceAll("#", fieldName) + ";" + cr); - sb.append(cr); - return sb.toString(); - } - - protected String generatePchBitFieldDecode(ArrayList<String> bitFieldList, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - String comment = bitFieldList.size() == 1 ? - bitFieldList.get(0) + ": bit" : - "Combinded bits: " + bitFieldList; - StringBuffer sb = new StringBuffer(); - - if (bitFieldList.size() == 1) // single bit - { - sb.append(indent + "if (propertyFlags[" + (ordinal - 1) + "]) // " + - bitFieldList.get(0) + ": bit" + cr); - sb.append(indent + "{" + cr); - sb.append(indent + tab + typeMap.get("bit").decodeExpression.replaceAll("#", - "boolean[] flaggedBitArray") + ";" + cr); - sb.append(indent + tab + bitFieldList.get(0) + " = flaggedBitArray[0];" + cr); - sb.append(indent + "}" + cr); - } - else // multiple bits - up to 8 are combined into one byte - { - int startOrdinal = ordinal - bitFieldList.size(); - String bitCntr = "bitCntr" + startOrdinal; - sb.append(indent + "// " + comment + cr); - sb.append(indent + "int " + bitCntr + " = 0;" + cr); - sb.append(indent + "for (int i=" + startOrdinal + "; i<=" + (ordinal - 1) + "; i++)" + cr); - sb.append(indent + "{" + cr); - sb.append(indent + tab + "if (propertyFlags[i])" + cr); - sb.append(indent + tab + tab + bitCntr + "++;" + cr); - sb.append(indent + "}" + cr); - sb.append(indent + "if (" + bitCntr + " > 0) // Are any of the property bits set?" + cr); - sb.append(indent + "{" + cr); - sb.append(indent + tab + typeMap.get("bit").decodeExpression.replaceAll("#", - "boolean[] flaggedBitArray") + ";" + cr); - sb.append(indent + tab + bitCntr + " = 0;" + cr); - for (int i=0; i<bitFieldList.size(); i++) - { - sb.append(indent + tab + "if (propertyFlags[" + (startOrdinal + i) + "])" + cr); - sb.append(indent + tab + tab + bitFieldList.get(i) + " = flaggedBitArray[" + - bitCntr + "++];" + cr); - } - sb.append(indent + "}" + cr); - } - - sb.append(cr); - return sb.toString(); - } - - protected String generatePchGetPropertyFlags(String domainType, String fieldName, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - int word = ordinal / 15; - int bit = 15 - (ordinal % 15); - sb.append(indent + "if (propertyFlags[" + ordinal + "]) // " + fieldName + ": " + - domainType + cr); - sb.append(indent + tab + "compactPropertyFlags[" + word + "] |= (1 << " + - bit + ");" + cr); - sb.append(cr); - return sb.toString(); - } - - protected String generatePchBitGetPropertyFlags(ArrayList<String> bitFieldList, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - int startOrdinal = ordinal - bitFieldList.size(); - - for (int i=0; i<bitFieldList.size(); i++) - { - int thisOrdinal = startOrdinal + i; - int word = thisOrdinal / 15; - int bit = 15 - (thisOrdinal % 15); - sb.append(indent + "if (propertyFlags[" + thisOrdinal + "])" + cr); - sb.append(indent + tab + "compactPropertyFlags[" + word + - "] |= (1 << " + bit + ");" + cr); - } - - sb.append(cr); - return sb.toString(); - } - - protected String generatePchSetPropertyFlags(String domainType, String fieldName, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - int word = ordinal / 15; - int bit = 15 - (ordinal % 15); - sb.append(indent + "propertyFlags[" + ordinal + "] = (compactPropertyFlags[" + - word + "] & (1 << " + bit + ")) > 0;" + cr); - return sb.toString(); - } - - protected String generatePchBitSetPropertyFlags(ArrayList<String> bitFieldList, - int ordinal, int indentSize, int tabSize) - { - String indent = Utils.createSpaces(indentSize); - StringBuffer sb = new StringBuffer(); - int startOrdinal = ordinal - bitFieldList.size(); - - for (int i=0; i<bitFieldList.size(); i++) - { - int thisOrdinal = startOrdinal + i; - int word = thisOrdinal / 15; - int bit = 15 - (thisOrdinal % 15); - sb.append(indent + "propertyFlags[" + thisOrdinal + "] = (compactPropertyFlags[" + - word + "] & (1 << " + bit + ")) > 0;" + cr); - } - return sb.toString(); - } - - private String generatePchPropertyFlagsDeclare() - { - return "private boolean[] propertyFlags;"; - } - - private String generatePchPropertyFlagsInitializer(int totNumFields) - { - return "propertyFlags = new boolean[" + totNumFields + "];"; - } - - private String generatePchCompactPropertyFlagsInitializer(AmqpClass thisClass, int indentSize, - int tabSize) - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - Iterator<AmqpVersion> vItr = globalVersionSet.iterator(); - while (vItr.hasNext()) - { - AmqpVersion version = vItr.next(); - int numBytes = ((thisClass.fieldMap.getNumFields(version) - 1) / 15) + 1; - - sb.append(indent); - if (!version.equals(globalVersionSet.first())) - sb.append("else "); - sb.append("if ( major == " + version.getMajor() + " && minor == " + - version.getMinor() + " )" + cr); - sb.append(indent + tab + "compactPropertyFlags = new int[] { "); - for (int i=0; i<numBytes; i++) - { - if (i!= 0) - sb.append(", "); - sb.append(i < numBytes - 1 ? "1" : "0"); // Set the "continue" flag where required - } - sb.append(" };" + cr); - } - return sb.toString(); - } - - private String generatePchCompactPropertyFlagsCheck(AmqpClass thisClass, int indentSize, - int tabSize) - { - String indent = Utils.createSpaces(indentSize); - String tab = Utils.createSpaces(tabSize); - StringBuffer sb = new StringBuffer(); - Iterator<AmqpVersion> vItr = globalVersionSet.iterator(); - while (vItr.hasNext()) - { - AmqpVersion version = vItr.next(); - int numFields = thisClass.fieldMap.getNumFields(version); - int numBytes = ((numFields - 1) / 15) + 1; - - sb.append(indent); - if (!version.equals(globalVersionSet.first())) - sb.append("else "); - sb.append("if ( major == " + version.getMajor() + " && minor == " + - version.getMinor() + " && compactPropertyFlags.length != " + numBytes + " )" + cr); - sb.append(indent + tab + - "throw new AMQProtocolVersionException(\"Property flag array size mismatch:\" +" + cr); - sb.append(indent + tab + tab + "\"(Size found: \" + compactPropertyFlags.length +" + cr); - sb.append(indent + tab + tab + "\") Version " + version + " has " + numFields + - " fields which requires an int array of size " + numBytes + ".\");" + cr); - } - return sb.toString(); - } - - private String generateVersionCheck(AmqpVersionSet v) - throws AmqpTypeMappingException - { - StringBuffer sb = new StringBuffer(); - AmqpVersion[] versionArray = new AmqpVersion[v.size()]; - v.toArray(versionArray); - for (int i=0; i<versionArray.length; i++) - { - if (i != 0) - sb.append(" || "); - if (versionArray.length > 1) - sb.append("("); - sb.append("major == (byte)" + versionArray[i].getMajor() + " && minor == (byte)" + - versionArray[i].getMinor()); - if (versionArray.length > 1) - sb.append(")"); - } - return sb.toString(); - } - - private String camelCaseName(String name, boolean upperFirstFlag) - { - StringBuffer ccn = new StringBuffer(); - String[] toks = name.split("[-_.\\ ]"); - for (int i=0; i<toks.length; i++) - { - StringBuffer b = new StringBuffer(toks[i]); - if (upperFirstFlag || i>0) - b.setCharAt(0, Character.toUpperCase(toks[i].charAt(0))); - ccn.append(b); - } - return ccn.toString(); - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/LanguageConverter.java b/qpid/gentools/org/apache/qpid/gentools/LanguageConverter.java deleted file mode 100644 index cb0a14e3bc..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/LanguageConverter.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * 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 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; -} diff --git a/qpid/gentools/org/apache/qpid/gentools/Main.java b/qpid/gentools/org/apache/qpid/gentools/Main.java deleted file mode 100644 index 5993a556f8..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/Main.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * - * 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.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; - -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; - -public class Main -{ - private DocumentBuilder docBuilder; - private AmqpVersionSet versionSet; - private Generator generator; - private AmqpConstantSet constants; - private AmqpDomainMap domainMap; - private AmqpModel model; - - public Main() throws ParserConfigurationException - { - docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - versionSet = new AmqpVersionSet(); - } - - public void run(String[] args) - throws IOException, - SAXException, - AmqpParseException, - AmqpTypeMappingException, - AmqpTemplateException, - TargetDirectoryException, - IllegalAccessException, - InvocationTargetException - { - File[] modelTemplateFiles = new File[]{}; - File[] classTemplateFiles = new File[]{}; - File[] methodTemplateFiles = new File[]{}; - File[] fieldTemplateFiles = new File[]{}; - String outDir = "out"; - - if (args[0].compareToIgnoreCase("-c") == 0) - { - // *** C++ generation *** - 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("templ.cpp/AMQP_ServerOperations.h.tmpl"), - new File("templ.cpp/AMQP_ClientOperations.h.tmpl"), - new File("templ.cpp/AMQP_ServerProxy.h.tmpl"), - new File("templ.cpp/AMQP_ClientProxy.h.tmpl"), - new File("templ.cpp/AMQP_ServerProxy.cpp.tmpl"), - new File("templ.cpp/AMQP_ClientProxy.cpp.tmpl"), - new File("templ.cpp/AMQP_Constants.h.tmpl"), - new File("templ.cpp/AMQP_MethodVersionMap.h.tmpl"), - new File("templ.cpp/AMQP_MethodVersionMap.cpp.tmpl") - }; - methodTemplateFiles = new File[] - { - new File("templ.cpp/MethodBodyClass.h.tmpl") - }; - outDir += ".cpp"; - } - else if (args[0].compareToIgnoreCase("-j") == 0) - { - // *** Java generation *** - 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("templ.java/MethodRegistryClass.tmpl"), - new File("templ.java/AmqpConstantsClass.tmpl") - }; - classTemplateFiles = new File[] - { - new File("templ.java/PropertyContentHeaderClass.tmpl") - }; - methodTemplateFiles = new File[] - { - new File("templ.java/MethodBodyClass.tmpl") - }; - outDir += ".java"; - } - else - { - System.err.println("ERROR: Required argument specifying language (C++ [-c] or Java [-j]) missing."); - usage(); - } - - 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. - System.out.println("Analyzing XML Specification files:"); - for (int i=1; i<args.length; i++) - { - File f = new File(args[i]); - if (f.exists()) - { - // 1a. Initialize dom - System.out.print(" \"" + args[i] + "\":"); - Document doc = docBuilder.parse(new File(args[i])); - 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); - } - else - System.err.println("ERROR: AMQP XML file \"" + args[i] + "\" not found."); - } -// *** DEBUG INFO *** Uncomment bits from this block to see lots of stuff.... -// System.out.println(); -// System.out.println("*** Debug output ***"); -// System.out.println(); -// versionSet.print(System.out, 0, 2); -// System.out.println(); -// constants.print(System.out, 0, 2); -// System.out.println(); -// domainMap.print(System.out, 0, 2); -// System.out.println(); -// model.print(System.out, 0, 2); -// System.out.println(); -// System.out.println("*** End debug output ***"); -// System.out.println(); - - // 2. Load up all templates - generator.initializeTemplates(modelTemplateFiles, classTemplateFiles, - methodTemplateFiles, fieldTemplateFiles); - - // 3. Generate output - generator.generate(new File(outDir)); - - System.out.println("Files generated: " + generator.getNumberGeneratedFiles()); - System.out.println("Done."); - } - - public static void main(String[] args) - { - if (args.length < 2) - usage(); - try { new Main().run(args); } - 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(); } - } - - public static void usage() - { - System.out.println("AMQP XML generator v.0.0"); - System.out.println("Usage: Main -c|-j filename [filename ...]"); - System.out.println(" where -c flags C++ generation."); - System.out.println(" -j flags Java generation."); - System.out.println(" filename is a space-separated list of files to be parsed."); - System.exit(0); - } - - 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(); - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/NodeAware.java b/qpid/gentools/org/apache/qpid/gentools/NodeAware.java deleted file mode 100644 index a8f20f611a..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/NodeAware.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * 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 org.w3c.dom.Node; - -/** - * @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. - */ -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 - */ - public void addFromNode(Node n, int o, AmqpVersion v) - throws AmqpParseException, AmqpTypeMappingException; -} diff --git a/qpid/gentools/org/apache/qpid/gentools/Printable.java b/qpid/gentools/org/apache/qpid/gentools/Printable.java deleted file mode 100644 index a73878c506..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/Printable.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * - * 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; - -public interface Printable -{ - public void print(PrintStream out, int marginSize, int tabSize); -} diff --git a/qpid/gentools/org/apache/qpid/gentools/TargetDirectoryException.java b/qpid/gentools/org/apache/qpid/gentools/TargetDirectoryException.java deleted file mode 100644 index cdaf381f0a..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/TargetDirectoryException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * 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 TargetDirectoryException extends Exception -{ - public TargetDirectoryException(String msg) - { - super(msg); - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/Utils.java b/qpid/gentools/org/apache/qpid/gentools/Utils.java deleted file mode 100644 index 705e7dbf19..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/Utils.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * - * 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 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 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_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 static boolean containsOnlyDigits(String str) - { - boolean foundNonDigit = false; - for (int i=0; i<str.length() && !foundNonDigit; i++) - { - if (!Character.isDigit(str.charAt(i))) - { - foundNonDigit = true; - } - } - 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++) - { - char ch = str.charAt(i); - if (!(Character.isDigit(ch) || ch == '.')) - { - foundNonDigit = true; - } - else if (ch == '.') - decimalCntr++; - } - return !foundNonDigit && decimalCntr<2; - } -} diff --git a/qpid/gentools/org/apache/qpid/gentools/VersionConsistencyCheck.java b/qpid/gentools/org/apache/qpid/gentools/VersionConsistencyCheck.java deleted file mode 100644 index 1f6b9f1a6d..0000000000 --- a/qpid/gentools/org/apache/qpid/gentools/VersionConsistencyCheck.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * 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 VersionConsistencyCheck -{ - public boolean isVersionConsistent(AmqpVersionSet globalVersionSet); -} |