You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2007/01/31 17:40:20 UTC

svn commit: r501890 - in /incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools: AmqpFlagMap.java AmqpMethod.java CppGenerator.java

Author: aconway
Date: Wed Jan 31 08:40:14 2007
New Revision: 501890

URL: http://svn.apache.org/viewvc?view=rev&rev=501890
Log:

* gentools/AmqpFlagMa.javap: Refactor repetative set/get code into FlagMap.

* gentools/AmqpMethod.java: Fixed algorithm for deducing whether a method
  is a request or a response. Version-aware isResponseFlagMap.

* gentools/CppGenerator.java: Use new response flag.

Modified:
    incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java
    incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpMethod.java
    incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/CppGenerator.java

Modified: incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java?view=diff&rev=501890&r1=501889&r2=501890
==============================================================================
--- incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java (original)
+++ incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java Wed Jan 31 08:40:14 2007
@@ -30,7 +30,21 @@
 	{
 		return containsKey(true);
 	}
-	
+
+	public boolean isSet(AmqpVersion version)
+	{
+	    System.out.println("VERSION="+version);
+	    return containsKey(true) && get(true).contains(version);
+	}
+
+        public void setFlagForVersion(boolean flag, AmqpVersion version) {
+	    if (get(flag) == null) {
+		put(flag, new AmqpVersionSet(version));
+	    } else {
+		get(flag).add(version);
+	    }
+	}
+    
 	public String toString()
 	{
 		AmqpVersionSet versionSet = get(true);

Modified: incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpMethod.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpMethod.java?view=diff&rev=501890&r1=501889&r2=501890
==============================================================================
--- incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpMethod.java (original)
+++ incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpMethod.java Wed Jan 31 08:40:14 2007
@@ -24,6 +24,7 @@
 
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.w3c.dom.Element;
 
 public class AmqpMethod implements Printable, NodeAware, VersionConsistencyCheck
 {
@@ -31,10 +32,10 @@
 	public AmqpVersionSet versionSet;
 	public AmqpFieldMap fieldMap;
 	public String name;
-        public boolean isRequest;
 	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 AmqpFlagMap isResponseFlagMap;
 	
 	public AmqpMethod(String name, LanguageConverter converter)
 	{
@@ -45,8 +46,26 @@
 		indexMap = new AmqpOrdinalVersionMap();
 		clientMethodFlagMap = new AmqpFlagMap();
 		serverMethodFlagMap = new AmqpFlagMap();
+		isResponseFlagMap = new AmqpFlagMap();
 	}
 
+        /** Check if this method is named as a response by any other method in the class. */
+        public void checkForResponse(Element methodElement, AmqpVersion version) {
+	    Element clazz = (Element)methodElement.getParentNode();
+	    String methodName = methodElement.getAttribute("name");
+	    NodeList methods = clazz.getElementsByTagName("method");
+	    for (int i=0; i<methods.getLength(); ++i) {
+		Element method = (Element)methods.item(i);
+		NodeList responses = method.getElementsByTagName("response");
+		for (int j =0; j<responses.getLength(); ++j) {
+		    Element response = (Element)responses.item(j);
+		    if (methodName.equals(response.getAttribute("name"))) {
+			isResponseFlagMap.setFlagForVersion(true, version);
+		    }
+		}
+	    }
+        }
+    
 	public boolean addFromNode(Node methodNode, int ordinal, AmqpVersion version)
 		throws AmqpParseException, AmqpTypeMappingException
 	{
@@ -65,7 +84,6 @@
 		}
 		NodeList nList = methodNode.getChildNodes();
 		int fieldCntr = fieldMap.size();
-		isRequest = false; // Assume not a request  unless we find a response node.
 		for (int i=0; i<nList.getLength(); i++)
 		{
 			Node child = nList.item(i);
@@ -105,10 +123,8 @@
 				if (value.compareTo("no-gen") == 0)
 					return false;
 			}
-			else if (child.getNodeName().equals("response")) {
-			    isRequest = true;
-			}
 		}
+		checkForResponse((Element)methodNode, version);
 		processChassisFlags(serverChassisFlag, clientChassisFlag, version);
 		return true;
 	}
@@ -117,6 +133,7 @@
 	{
 		clientMethodFlagMap.removeVersion(version);
 		serverMethodFlagMap.removeVersion(version);
+		isResponseFlagMap.removeVersion(version);
 		indexMap.removeVersion(version);
 		fieldMap.removeVersion(version);
 		versionSet.remove(version);
@@ -146,25 +163,8 @@
 	
 	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);
-		}		
+	    serverMethodFlagMap.setFlagForVersion(serverFlag, version);
+	    clientMethodFlagMap.setFlagForVersion(clientFlag, version);
 	}
 	
 	public AmqpOverloadedParameterMap getOverloadedParameterLists(AmqpVersionSet globalVersionSet,

Modified: incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/CppGenerator.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/CppGenerator.java?view=diff&rev=501890&r1=501889&r2=501890
==============================================================================
--- incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/CppGenerator.java (original)
+++ incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/CppGenerator.java Wed Jan 31 08:40:14 2007
@@ -355,13 +355,15 @@
         if (token.equals("${hv_latest_minor}"))
             return String.valueOf(globalVersionSet.last().getMinor());
 	if (token.equals("${mb_base_class}")) 
-	    return baseClass(method);
+	    return baseClass(method, version);
             
         throw new AmqpTemplateException("Template token " + token + " unknown.");       
     }
 
-    private String baseClass(AmqpMethod method) {
-	return method.isRequest ? "AMQRequestBody" : "AMQResponseBody";
+    private String baseClass(AmqpMethod method, AmqpVersion version) {
+	boolean isResponse =  (version == null) ? method.isResponseFlagMap.isSet() : method.isResponseFlagMap.isSet(version);
+	String base = isResponse ? "AMQResponseBody":"AMQRequestBody";
+	return base;
     }
     
     @Override
@@ -1428,7 +1430,7 @@
                 sb.append(indent + thisClass.name + Utils.firstUpper(method.name) + "Body(const ProtocolVersion& version," + cr);
                 sb.append(generateFieldList(method.fieldMap, version, true, false, 8));
                 sb.append(indent + tab + ") :" + cr);
-                sb.append(indent + tab + baseClass(method) + "(version)," + cr);
+                sb.append(indent + tab + baseClass(method, version) + "(version)," + cr);
                 sb.append(generateFieldList(method.fieldMap, version, false, true, 8));
                 sb.append(indent + "{ }" + cr);
             }