You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2006/12/28 01:32:47 UTC

svn commit: r490614 [4/4] - in /incubator/qpid/branches/new_persistence/gentools: org/ src/ src/org/ src/org/apache/ src/org/apache/qpid/ src/org/apache/qpid/gentools/ templ.java/

Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/Utils.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/Utils.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/Utils.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/Utils.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,145 @@
+/*
+ *
+ * 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;
+    }
+}

Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/Utils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java (added)
+++ incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java Wed Dec 27 16:32:45 2006
@@ -0,0 +1,26 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.gentools;
+
+public interface VersionConsistencyCheck
+{
+	public boolean isVersionConsistent(AmqpVersionSet globalVersionSet);
+}

Propchange: incubator/qpid/branches/new_persistence/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/branches/new_persistence/gentools/templ.java/AmqpConstantsClass.tmpl
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/templ.java/AmqpConstantsClass.tmpl?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/templ.java/AmqpConstantsClass.tmpl (added)
+++ incubator/qpid/branches/new_persistence/gentools/templ.java/AmqpConstantsClass.tmpl Wed Dec 27 16:32:45 2006
@@ -0,0 +1,37 @@
+&{AmqpConstants.java}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * This file is auto-generated by ${GENERATOR} - do not modify.
+ * Supported AMQP versions:
+%{VLIST} *   ${major}-${minor}
+ */
+ 
+package org.apache.qpid.framing;
+
+class AmqpConstants
+{
+ 	// Constant getValue methods
+ 	
+%{TLIST} ${const_get_method}
+	
+}

Modified: incubator/qpid/branches/new_persistence/gentools/templ.java/MethodBodyClass.tmpl
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/templ.java/MethodBodyClass.tmpl?view=diff&rev=490614&r1=490613&r2=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/templ.java/MethodBodyClass.tmpl (original)
+++ incubator/qpid/branches/new_persistence/gentools/templ.java/MethodBodyClass.tmpl Wed Dec 27 16:32:45 2006
@@ -1,19 +1,22 @@
 &{${CLASS}${METHOD}Body.java}
 /*
  *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
+ * 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.
  *
  */
 
@@ -51,6 +54,8 @@
 
     public int getClazz() { return classIdMap.get(major + "-" + minor); }
     public int getMethod() { return methodIdMap.get(major + "-" + minor); }
+    public static int getClazz(byte major, byte minor) { return classIdMap.get(major + "-" + minor); }
+    public static int getMethod(byte major, byte minor) { return methodIdMap.get(major + "-" + minor); }
     
     // Field methods		
 %{FLIST}    ${mb_field_get_method}

Modified: incubator/qpid/branches/new_persistence/gentools/templ.java/MethodRegistryClass.tmpl
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/templ.java/MethodRegistryClass.tmpl?view=diff&rev=490614&r1=490613&r2=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/templ.java/MethodRegistryClass.tmpl (original)
+++ incubator/qpid/branches/new_persistence/gentools/templ.java/MethodRegistryClass.tmpl Wed Dec 27 16:32:45 2006
@@ -1,19 +1,22 @@
 &{MainRegistry.java}
 /*
  *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
+ * 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.
  *
  */
 
@@ -25,12 +28,53 @@
  
 package org.apache.qpid.framing;
 
-import java.util.Map;
+import java.util.HashMap;
+import java.lang.reflect.Constructor;
+import org.apache.log4j.Logger;
 
 class MainRegistry
 {
-    static void register(Map map, byte major, byte minor)
+    private static final Logger _log = Logger.getLogger(MainRegistry.class);
+	private static HashMap<Long, Class> classIDMethodIDVersionBodyMap = new HashMap<Long, Class>();
+	
+    static
     {
 %{CLIST}	${reg_map_put_method}
+    }
+    
+    public static AMQMethodBody get(short classID, short methodID, byte major, byte minor)
+        throws AMQFrameDecodingException
+    {
+		Class bodyClass = classIDMethodIDVersionBodyMap.get(
+		    createMapKey(classID, methodID, major, minor));
+		if (bodyClass == null)
+		{
+	    	throw new AMQFrameDecodingException(_log,
+	    	    "Unable to find a suitable decoder for class " + classID + " and method " +
+	    	    methodID + " in AMQP version " + major + "-" + minor + ".");
+	    }
+	    try
+	    {
+	    	Constructor initFn = bodyClass.getConstructor(byte.class, byte.class);
+	        return (AMQMethodBody) initFn.newInstance(major, minor);
+	    }
+	    catch (Exception e)
+	    {
+	    	throw new AMQFrameDecodingException(_log,
+	    	    "Unable to instantiate body class for class " + classID + " and method " +
+	    	    methodID + " in AMQP version " + major + "-" + minor + " : " + e, e);
+	    }
+    }
+    
+    private static Long createMapKey(short classID, short methodID, byte major, byte minor)
+    {
+    	/**
+         *	Mapping of 4 components into a guaranteed unique key:
+         *  MSB                                     LSB
+         *  +----+----+----+----+----+----+-----+-----+
+         *  |    0    | classID |methodID |major|minor|
+         *  +----+----+----+----+----+----+-----+-----+
+         */
+    	return new Long(((long)classID << 32) + ((long)methodID << 16) + ((long)major << 8) + minor);
     }
 }

Modified: incubator/qpid/branches/new_persistence/gentools/templ.java/PropertyContentHeaderClass.tmpl
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/templ.java/PropertyContentHeaderClass.tmpl?view=diff&rev=490614&r1=490613&r2=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/templ.java/PropertyContentHeaderClass.tmpl (original)
+++ incubator/qpid/branches/new_persistence/gentools/templ.java/PropertyContentHeaderClass.tmpl Wed Dec 27 16:32:45 2006
@@ -1,19 +1,22 @@
-&{${CLASS}PropertyContentHeader.java}
+&{${CLASS}ContentHeaderProperties.java}
 /*
  *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
+ * 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.
  *
  */
 
@@ -28,7 +31,7 @@
 import org.apache.log4j.Logger;
 import org.apache.mina.common.ByteBuffer;
 
-class ${CLASS}ContentHeaderProperties implements ContentHeaderProperties
+public class ${CLASS}ContentHeaderProperties implements ContentHeaderProperties
 {
     private static final Logger logger = Logger.getLogger(BasicContentHeaderProperties.class);
 

Added: incubator/qpid/branches/new_persistence/gentools/templ.java/ProtocolVersionListClass.tmpl
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/new_persistence/gentools/templ.java/ProtocolVersionListClass.tmpl?view=auto&rev=490614
==============================================================================
--- incubator/qpid/branches/new_persistence/gentools/templ.java/ProtocolVersionListClass.tmpl (added)
+++ incubator/qpid/branches/new_persistence/gentools/templ.java/ProtocolVersionListClass.tmpl Wed Dec 27 16:32:45 2006
@@ -0,0 +1,38 @@
+&{ProtocolVersionList.java}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * This file is auto-generated by ${GENERATOR} - do not modify.
+ * Supported AMQP versions:
+%{VLIST} *   ${major}-${minor}
+ */
+ 
+package org.apache.qpid.framing;
+
+public interface ProtocolVersionList
+{
+    public final int PROTOCOL_MAJOR = 0;
+    public final int PROTOCOL_MINOR = 1;
+    public final byte pv[][] = {
+%{VLIST} ${protocol-version-list-entry}
+        };
+}