You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2009/06/11 17:54:39 UTC

svn commit: r783818 [1/3] - in /qpid/trunk/qpid: cpp/bindings/qmf/ruby/ cpp/examples/qmf-agent/ cpp/managementgen/qmfgen/ cpp/managementgen/qmfgen/templates/ cpp/src/qmf/ cpp/src/qpid/agent/ cpp/src/qpid/console/ cpp/src/qpid/framing/ cpp/src/qpid/mana...

Author: tross
Date: Thu Jun 11 15:54:37 2009
New Revision: 783818

URL: http://svn.apache.org/viewvc?rev=783818&view=rev
Log:
QPID-1786 - Committed qmf patches from Bryan Kearney
            Additionally updated existing qmf and Qman to be compatible.
            The magic number for qmf messages has been incremented.

Added:
    qpid/trunk/qpid/java/agent/
    qpid/trunk/qpid/java/agent/build.xml
    qpid/trunk/qpid/java/agent/src/
    qpid/trunk/qpid/java/agent/src/main/
    qpid/trunk/qpid/java/agent/src/main/java/
    qpid/trunk/qpid/java/agent/src/main/java/org/
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/Agent.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/AgentException.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/EventSeverity.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedEJB.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedObject.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedObjectBase.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedPOJO.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFEvent.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFHide.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFObject.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFProperty.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFSeeAlso.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFType.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingContext.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingException.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingUtils.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/ClassBinding.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/EnumBinding.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/ListBinding.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/MapBinding.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/MethodBinding.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/ParameterBinding.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/PropertyBinding.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/QMFTypeBinding.java
    qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/TypeBinding.java
    qpid/trunk/qpid/java/agent/src/test/
    qpid/trunk/qpid/java/agent/src/test/java/
    qpid/trunk/qpid/java/agent/src/test/java/org/
    qpid/trunk/qpid/java/agent/src/test/java/org/apache/
    qpid/trunk/qpid/java/agent/src/test/java/org/apache/qpid/
    qpid/trunk/qpid/java/agent/src/test/java/org/apache/qpid/agent/
    qpid/trunk/qpid/java/agent/src/test/java/org/apache/qpid/agent/Crumpet.java
    qpid/trunk/qpid/java/agent/src/test/java/org/apache/qpid/agent/Muppet.java
    qpid/trunk/qpid/java/agent/src/test/java/org/apache/qpid/agent/Pikelet.java
    qpid/trunk/qpid/java/agent/src/test/java/org/apache/qpid/agent/Puppet.java
Modified:
    qpid/trunk/qpid/cpp/bindings/qmf/ruby/Makefile.am
    qpid/trunk/qpid/cpp/examples/qmf-agent/Makefile
    qpid/trunk/qpid/cpp/managementgen/qmfgen/management-types.xml
    qpid/trunk/qpid/cpp/managementgen/qmfgen/templates/Class.cpp
    qpid/trunk/qpid/cpp/managementgen/qmfgen/templates/Event.cpp
    qpid/trunk/qpid/cpp/src/qmf/Agent.cpp
    qpid/trunk/qpid/cpp/src/qmf/SchemaImpl.cpp
    qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp
    qpid/trunk/qpid/cpp/src/qpid/console/Broker.cpp
    qpid/trunk/qpid/cpp/src/qpid/console/Schema.cpp
    qpid/trunk/qpid/cpp/src/qpid/console/Value.cpp
    qpid/trunk/qpid/cpp/src/qpid/console/Value.h
    qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp
    qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.h
    qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp
    qpid/trunk/qpid/java/build.deps
    qpid/trunk/qpid/java/build.xml
    qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Protocol.java
    qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/SchemaResponseMessageHandler.java
    qpid/trunk/qpid/python/commands/qpid-config
    qpid/trunk/qpid/python/qmf/console.py
    qpid/trunk/qpid/python/qpid/management.py
    qpid/trunk/qpid/python/qpid/managementdata.py
    qpid/trunk/qpid/ruby/lib/qpid/qmf.rb

Modified: qpid/trunk/qpid/cpp/bindings/qmf/ruby/Makefile.am
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/bindings/qmf/ruby/Makefile.am?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/bindings/qmf/ruby/Makefile.am (original)
+++ qpid/trunk/qpid/cpp/bindings/qmf/ruby/Makefile.am Thu Jun 11 15:54:37 2009
@@ -13,7 +13,7 @@
 dist_rubylib_DATA = qmf.rb
 
 $(generated_file_list): $(srcdir)/ruby.i $(srcdir)/../qmfengine.i
-	swig -ruby -c++ -Wall -I/usr/include $(INCLUDES) $(QPID_CXXFLAGS) -I$(top_srcdir)/src/qmf -o qmfengine.cpp $(srcdir)/ruby.i
+	swig -ruby -c++ -Wall -I/usr/include $(INCLUDES) $(QPID_CXXFLAGS) -o qmfengine.cpp $(srcdir)/ruby.i
 
 AM_CPPFLAGS = $(QPID_CXXFLAGS) $(INCLUDES) -I$(srcdir) -I$(RUBY_INC) -I$(RUBY_INC_ARCH)
 AM_CXXFLAGS = $(QPID_CXXFLAGS)

Modified: qpid/trunk/qpid/cpp/examples/qmf-agent/Makefile
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/qmf-agent/Makefile?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/qmf-agent/Makefile (original)
+++ qpid/trunk/qpid/cpp/examples/qmf-agent/Makefile Thu Jun 11 15:54:37 2009
@@ -27,7 +27,7 @@
 LIB_DIR      = $(QPID_DIR)/cpp/src/.libs
 CC_INCLUDES  = -I$(SRC_DIR) -I$(QPID_DIR)/cpp/src -I$(QPID_DIR)/cpp/src/gen -I$(GEN_DIR)
 CC_FLAGS     = -g -O3
-LD_FLAGS     = -lqmfagent -L$(LIB_DIR)
+LD_FLAGS     = -lqmfagent -lqmfcommon -L$(LIB_DIR)
 SPEC_DIR     = $(QPID_DIR)/specs
 MGEN_DIR     = $(QPID_DIR)/cpp/managementgen
 MGEN         = $(MGEN_DIR)/qmf-gen

Modified: qpid/trunk/qpid/cpp/managementgen/qmfgen/management-types.xml
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/managementgen/qmfgen/management-types.xml?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/managementgen/qmfgen/management-types.xml (original)
+++ qpid/trunk/qpid/cpp/managementgen/qmfgen/management-types.xml Thu Jun 11 15:54:37 2009
@@ -36,7 +36,7 @@
 <type name="float"     base="FLOAT"     cpp="float"         encode="@.putFloat(#)"       decode="# = @.getFloat()"     accessor="direct" init="0."/>
 <type name="double"    base="DOUBLE"    cpp="double"        encode="@.putDouble(#)"      decode="# = @.getDouble()"    accessor="direct" init="0."/>
 <type name="uuid"      base="UUID"      cpp="::qpid::framing::Uuid" encode="#.encode(@)"       decode="#.decode(@)"    accessor="direct" init="::qpid::framing::Uuid()" byRef="y"/>
-<type name="map"       base="FTABLE"    cpp="::qpid::framing::FieldTable" encode="#.encode(@)" decode="#.decode(@)"    accessor="direct" init="::qpid::framing::FieldTable()" byRef="y"/>
+<type name="map"       base="FTABLE"    cpp="::qpid::framing::FieldTable" encode="#.qmfEncode(@)" decode="#.decode(@)"    accessor="direct" init="::qpid::framing::FieldTable()" byRef="y"/>
 
 <type name="hilo8"   base="U8"   cpp="uint8_t"  encode="@.putOctet(#)"    decode="# = @.getOctet()"    style="wm" accessor="counter" init="0"/>
 <type name="hilo16"  base="U16"  cpp="uint16_t" encode="@.putShort(#)"    decode="# = @.getShort()"    style="wm" accessor="counter" init="0"/>

Modified: qpid/trunk/qpid/cpp/managementgen/qmfgen/templates/Class.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/managementgen/qmfgen/templates/Class.cpp?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/managementgen/qmfgen/templates/Class.cpp (original)
+++ qpid/trunk/qpid/cpp/managementgen/qmfgen/templates/Class.cpp Thu Jun 11 15:54:37 2009
@@ -98,6 +98,7 @@
     buf.putShortString (packageName); // Package Name
     buf.putShortString (className);   // Class Name
     buf.putBin128      (md5Sum);      // Schema Hash
+    buf.putOctet       (0);           // No Superclass
     buf.putShort       (/*MGEN:Class.ConfigCount*/); // Config Element Count
     buf.putShort       (/*MGEN:Class.InstCount*/); // Inst Element Count
     buf.putShort       (/*MGEN:Class.MethodCount*/); // Method Count

Modified: qpid/trunk/qpid/cpp/managementgen/qmfgen/templates/Event.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/managementgen/qmfgen/templates/Event.cpp?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/managementgen/qmfgen/templates/Event.cpp (original)
+++ qpid/trunk/qpid/cpp/managementgen/qmfgen/templates/Event.cpp Thu Jun 11 15:54:37 2009
@@ -65,6 +65,7 @@
     buf.putShortString (packageName); // Package Name
     buf.putShortString (eventName);   // Event Name
     buf.putBin128      (md5Sum);      // Schema Hash
+    buf.putOctet       (0);           // No Superclass    
     buf.putShort       (/*MGEN:Event.ArgCount*/); // Argument Count
 
     // Arguments

Modified: qpid/trunk/qpid/cpp/src/qmf/Agent.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qmf/Agent.cpp?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qmf/Agent.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qmf/Agent.cpp Thu Jun 11 15:54:37 2009
@@ -484,7 +484,7 @@
 {
     buf.putOctet('A');
     buf.putOctet('M');
-    buf.putOctet('2');
+    buf.putOctet('3');
     buf.putOctet(opcode);
     buf.putLong (seq);
 }
@@ -501,7 +501,7 @@
     *opcode = buf.getOctet();
     *seq    = buf.getLong();
 
-    return h1 == 'A' && h2 == 'M' && h3 == '2';
+    return h1 == 'A' && h2 == 'M' && h3 == '3';
 }
 
 AgentEventImpl::Ptr AgentImpl::eventDeclareQueue(const string& name)

Modified: qpid/trunk/qpid/cpp/src/qmf/SchemaImpl.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qmf/SchemaImpl.cpp?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qmf/SchemaImpl.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qmf/SchemaImpl.cpp Thu Jun 11 15:54:37 2009
@@ -272,6 +272,7 @@
     buffer.putShortString(package);
     buffer.putShortString(name);
     hash.encode(buffer);
+    buffer.putOctet(0); // No parent class
     buffer.putShort((uint16_t) properties.size());
     buffer.putShort((uint16_t) statistics.size());
     buffer.putShort((uint16_t) methods.size());

Modified: qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp Thu Jun 11 15:54:37 2009
@@ -565,7 +565,7 @@
 {
     buf.putOctet('A');
     buf.putOctet('M');
-    buf.putOctet('2');
+    buf.putOctet('3');
     buf.putOctet(opcode);
     buf.putLong (seq);
 }
@@ -582,7 +582,7 @@
     *opcode = buf.getOctet();
     *seq    = buf.getLong();
 
-    return h1 == 'A' && h2 == 'M' && h3 == '2';
+    return h1 == 'A' && h2 == 'M' && h3 == '3';
 }
 
 ManagementAgentImpl::PackageMap::iterator ManagementAgentImpl::findOrAddPackage(const string& name)

Modified: qpid/trunk/qpid/cpp/src/qpid/console/Broker.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/console/Broker.cpp?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/console/Broker.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/console/Broker.cpp Thu Jun 11 15:54:37 2009
@@ -72,7 +72,7 @@
 {
     buf.putOctet('A');
     buf.putOctet('M');
-    buf.putOctet('2');
+    buf.putOctet('3');
     buf.putOctet(opcode);
     buf.putLong (seq);
 }
@@ -89,7 +89,7 @@
     *opcode = buf.getOctet();
     *seq    = buf.getLong();
 
-    return h1 == 'A' && h2 == 'M' && h3 == '2';
+    return h1 == 'A' && h2 == 'M' && h3 == '3';
 }
 
 void Broker::received(qpid::client::Message& msg)

Modified: qpid/trunk/qpid/cpp/src/qpid/console/Schema.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/console/Schema.cpp?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/console/Schema.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/console/Schema.cpp Thu Jun 11 15:54:37 2009
@@ -119,9 +119,18 @@
     kind(_kind), key(_key)
 {
     if (kind == KIND_TABLE) {
-        uint16_t propCount   = buffer.getShort();
-        uint16_t statCount   = buffer.getShort();
-        uint16_t methodCount = buffer.getShort();
+        uint8_t  hasSupertype = buffer.getOctet();
+        uint16_t propCount    = buffer.getShort();
+        uint16_t statCount    = buffer.getShort();
+        uint16_t methodCount  = buffer.getShort();
+
+        if (hasSupertype) {
+            string unused;
+            buffer.getShortString(unused);
+            buffer.getShortString(unused);
+            buffer.getLongLong();
+            buffer.getLongLong();
+        }
 
         for (uint16_t idx = 0; idx < propCount; idx++)
             properties.push_back(new SchemaProperty(buffer));

Modified: qpid/trunk/qpid/cpp/src/qpid/console/Value.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/console/Value.cpp?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/console/Value.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/console/Value.cpp Thu Jun 11 15:54:37 2009
@@ -114,7 +114,7 @@
 
 MapValue::MapValue(framing::Buffer& buffer)
 {
-    value.decode(buffer);
+    value.qmfDecode(buffer);
 }
 
 

Modified: qpid/trunk/qpid/cpp/src/qpid/console/Value.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/console/Value.h?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/console/Value.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/console/Value.h Thu Jun 11 15:54:37 2009
@@ -98,6 +98,8 @@
         std::string str() const;
         bool isUint() const { return true; }
         uint32_t asUint() const { return value; }
+        bool isUint64() const { return true; }
+        uint64_t asUint64() const { return (uint64_t) value; }
     private:
         uint32_t value;
     };
@@ -108,6 +110,8 @@
         std::string str() const;
         bool isInt() const { return true; }
         int32_t asInt() const { return value; }
+        bool isInt64() const { return true; }
+        int64_t asInt64() const { return (int64_t) value; }
     private:
         int32_t value;
     };
@@ -160,6 +164,8 @@
         std::string str() const;
         bool isFloat() const { return true; }
         float asFloat() const { return value; }
+        bool isDouble() const { return true; }
+        double asDouble() const { return (double) value; }
     private:
         float value;
     };

Modified: qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.cpp Thu Jun 11 15:54:37 2009
@@ -53,6 +53,23 @@
     return len;
 }
 
+uint32_t FieldTable::qmfEncodedSize() const {
+    uint32_t len(4/*size field*/ + 4/*count field*/);
+    for(ValueMap::const_iterator i = values.begin(); i != values.end(); ++i) {
+        // shortstr_len_byte + key size + typecode
+	len += 1 + (i->first).size() + 1;
+        ValuePtr value(i->second);
+        if (value->convertsTo<int>()) {
+            len += 4;
+        } else if (value->convertsTo<uint64_t>()) {
+            len += 8;
+        } else if (value->convertsTo<string>()) {
+            len += 2 + value->get<string>().size();
+        }
+    }
+    return len;
+}
+
 int FieldTable::count() const {
     return values.size();
 }
@@ -191,7 +208,7 @@
 //    return getValue<uint64_t>(name);
 //}
 
-void FieldTable::encode(Buffer& buffer) const{    
+void FieldTable::encode(Buffer& buffer) const {
     buffer.putLong(encodedSize() - 4);
     buffer.putLong(values.size());
     for (ValueMap::const_iterator i = values.begin(); i!=values.end(); ++i) {
@@ -220,6 +237,122 @@
     }
 }
 
+#define QMF_TYPE_U8        1
+#define QMF_TYPE_U16       2
+#define QMF_TYPE_U32       3
+#define QMF_TYPE_U64       4
+#define QMF_TYPE_SSTR      6                   
+#define QMF_TYPE_LSTR      7
+#define QMF_TYPE_ABSTIME   8
+#define QMF_TYPE_DELTATIME 9
+#define QMF_TYPE_REF       10
+#define QMF_TYPE_BOOL      11
+#define QMF_TYPE_FLOAT     12
+#define QMF_TYPE_DOUBLE    13
+#define QMF_TYPE_UUID      14
+#define QMF_TYPE_S8        16
+#define QMF_TYPE_S16       17
+#define QMF_TYPE_S32       18
+#define QMF_TYPE_S64       19
+#define QMF_TYPE_OBJECT    20
+#define QMF_TYPE_MAP       15
+#define QMF_TYPE_LIST      21
+#define QMF_TYPE_ARRAY     22
+
+void FieldTable::qmfEncode(Buffer& buffer) const {
+    buffer.putLong(qmfEncodedSize() - 4);
+    buffer.putLong(values.size());
+    for (ValueMap::const_iterator i = values.begin(); i!=values.end(); ++i) {
+        ValuePtr value(i->second);
+        buffer.putShortString(i->first);
+        if (value->convertsTo<int>()) {
+            buffer.putOctet(QMF_TYPE_S32);
+            buffer.putLong(value->get<int>());
+        } else if (value->convertsTo<uint64_t>()) {
+            buffer.putOctet(QMF_TYPE_U64);
+            buffer.putLongLong(value->get<uint64_t>());
+        } else if (value->convertsTo<string>()) {
+            buffer.putOctet(QMF_TYPE_LSTR);
+            buffer.putMediumString(value->get<string>());
+        }
+    }
+}
+
+void FieldTable::qmfDecode(Buffer& buffer) {
+    clear();
+    uint32_t len = buffer.getLong();
+    if (len) {
+        uint32_t available = buffer.available();
+        if (available < len)
+            throw IllegalArgumentException(QPID_MSG("Not enough data for  field table."));
+        uint32_t count = buffer.getLong();
+        uint32_t leftover = available - len;
+        while(buffer.available() > leftover && count--) {
+            std::string name;
+            std::string sstr;
+            std::string lstr;
+            buffer.getShortString(name);
+            uint8_t typecode = buffer.getOctet();
+            switch (typecode) {
+            case QMF_TYPE_U8:
+                values[name] = ValuePtr(new IntegerValue(buffer.getOctet()));
+                break;
+            case QMF_TYPE_U16:
+                values[name] = ValuePtr(new IntegerValue(buffer.getShort()));
+                break;
+            case QMF_TYPE_U32:
+                values[name] = ValuePtr(new IntegerValue(buffer.getLong()));
+                break;
+            case QMF_TYPE_U64:
+                values[name] = ValuePtr(new Unsigned64Value(buffer.getLongLong()));
+                break;
+            case QMF_TYPE_SSTR:
+                buffer.getShortString(sstr);
+                values[name] = ValuePtr(new Str16Value(sstr));
+                break;
+            case QMF_TYPE_LSTR:
+                buffer.getMediumString(lstr);
+                values[name] = ValuePtr(new Str16Value(lstr));
+                break;
+            case QMF_TYPE_ABSTIME:
+                values[name] = ValuePtr(new Unsigned64Value(buffer.getLongLong()));
+                break;
+            case QMF_TYPE_DELTATIME:
+                values[name] = ValuePtr(new Unsigned64Value(buffer.getLongLong()));
+                break;
+            case QMF_TYPE_BOOL:
+                values[name] = ValuePtr(new IntegerValue(buffer.getOctet()));
+                break;
+            case QMF_TYPE_FLOAT:
+                values[name] = ValuePtr(new FloatValue(buffer.getFloat()));
+                break;
+            case QMF_TYPE_DOUBLE:
+                values[name] = ValuePtr(new DoubleValue(buffer.getDouble()));
+                break;
+            case QMF_TYPE_S8:
+                values[name] = ValuePtr(new IntegerValue(buffer.getOctet()));
+                break;
+            case QMF_TYPE_S16:
+                values[name] = ValuePtr(new IntegerValue(buffer.getShort()));
+                break;
+            case QMF_TYPE_S32:
+                values[name] = ValuePtr(new IntegerValue(buffer.getLong()));
+                break;
+            case QMF_TYPE_S64:
+                values[name] = ValuePtr(new Unsigned64Value(buffer.getLongLong()));
+                break;
+            case QMF_TYPE_REF:
+            case QMF_TYPE_UUID:
+            case QMF_TYPE_OBJECT:
+            case QMF_TYPE_MAP:
+            case QMF_TYPE_LIST:
+            case QMF_TYPE_ARRAY:
+                break;
+            }
+        }    
+    }
+}
+
 
 bool FieldTable::operator==(const FieldTable& x) const {
     if (values.size() != x.values.size()) return false;

Modified: qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.h?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/framing/FieldTable.h Thu Jun 11 15:54:37 2009
@@ -60,6 +60,10 @@
     QPID_COMMON_EXTERN void encode(Buffer& buffer) const;
     QPID_COMMON_EXTERN void decode(Buffer& buffer);
 
+    QPID_COMMON_EXTERN uint32_t qmfEncodedSize() const;
+    QPID_COMMON_EXTERN void qmfEncode(Buffer& buffer) const;
+    QPID_COMMON_EXTERN void qmfDecode(Buffer& buffer);
+
     QPID_COMMON_EXTERN int count() const;
     QPID_COMMON_EXTERN void set(const std::string& name, const ValuePtr& value);
     QPID_COMMON_EXTERN ValuePtr get(const std::string& name) const;

Modified: qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp?rev=783818&r1=783817&r2=783818&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp Thu Jun 11 15:54:37 2009
@@ -246,7 +246,7 @@
 {
     buf.putOctet ('A');
     buf.putOctet ('M');
-    buf.putOctet ('2');
+    buf.putOctet ('3');
     buf.putOctet (opcode);
     buf.putLong  (seq);
 }
@@ -260,7 +260,7 @@
     *opcode = buf.getOctet();
     *seq    = buf.getLong();
 
-    return h1 == 'A' && h2 == 'M' && h3 == '2';
+    return h1 == 'A' && h2 == 'M' && h3 == '3';
 }
 
 void ManagementAgent::sendBuffer(Buffer&  buf,
@@ -1097,10 +1097,18 @@
         inBuffer.getShortString(text);
         inBuffer.getBin128(hash);
 
+        uint8_t superType = inBuffer.getOctet();      
+
         uint16_t propCount = inBuffer.getShort();
         uint16_t statCount = inBuffer.getShort();
         uint16_t methCount = inBuffer.getShort();
 
+        if (superType == 1) {
+            inBuffer.getShortString(text);
+            inBuffer.getShortString(text);
+            inBuffer.getBin128(hash);
+        }
+        
         for (uint16_t idx = 0; idx < propCount + statCount; idx++) {
             FieldTable ft;
             ft.decode(inBuffer);
@@ -1142,9 +1150,16 @@
         inBuffer.getShortString(text);
         inBuffer.getShortString(text);
         inBuffer.getBin128(hash);
+        
+        uint8_t superType = inBuffer.getOctet();
 
         uint16_t argCount = inBuffer.getShort();
 
+        if (superType == 1) {
+            inBuffer.getShortString(text);
+            inBuffer.getShortString(text);
+            inBuffer.getBin128(hash);
+        }
         for (uint16_t idx = 0; idx < argCount; idx++) {
             FieldTable ft;
             ft.decode(inBuffer);

Added: qpid/trunk/qpid/java/agent/build.xml
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/build.xml?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/build.xml (added)
+++ qpid/trunk/qpid/java/agent/build.xml Thu Jun 11 15:54:37 2009
@@ -0,0 +1,41 @@
+<!--
+ -
+ - 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.
+ -
+ -->
+<project name="QMF Agent" default="build">
+
+    <property name="module.depends" value="common client jms"/>
+    <property name="module.main" value="org.apache.qpid.agent.Agent"/>
+
+    <import file="../module.xml"/>
+
+    <target name="copy-bin-release" description="copy dependencies into module release">
+        <copy todir="${module.release}/bin" failonerror="true">
+            <fileset dir="${module.bin}"/>
+        </copy>
+        <copy todir="${module.release}/bin" failonerror="true" flatten="true">
+            <fileset dir="${basedir}/../common/bin"/>
+        </copy>
+        <chmod dir="${module.release}/bin" perm="ugo+rx" includes="**/*"/>
+
+    </target>
+
+    <target name="release-bin" depends="release-bin-tasks"/>
+
+</project>

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/Agent.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/Agent.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/Agent.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/Agent.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,650 @@
+/*
+ *
+ * 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.agent;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import javax.jms.BytesMessage;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.qpid.agent.binding.BindingContext;
+import org.apache.qpid.agent.binding.BindingUtils;
+import org.apache.qpid.agent.binding.ClassBinding;
+import org.apache.qpid.agent.binding.BindingException;
+import org.apache.qpid.agent.binding.MethodBinding;
+import org.apache.qpid.agent.binding.ParameterBinding;
+import org.apache.qpid.agent.binding.PropertyBinding;
+import org.apache.qpid.agent.binding.TypeBinding;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.transport.codec.BBDecoder;
+import org.apache.qpid.transport.codec.BBEncoder;
+import org.apache.qpid.transport.codec.Decoder;
+
+/**
+ * Agent
+ * 
+ */
+public class Agent implements MessageListener
+{
+    // The following are settings to configure the Agent
+    private AMQConnection connection;
+    private boolean sessionTransacted = false;
+    private int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
+    private String label;
+    private UUID systemId;
+    // this list holds the objects until the agent is started
+    private List managedObjects = new ArrayList();
+    private List registeredClasses = new ArrayList();
+    // The following instance variables are not
+    // able to be set by the end user.
+    private Session session;
+    private MessageProducer prod;
+    private MessageConsumer cons;
+    private Queue reply;
+    private BindingContext bctx = new BindingContext();
+    private Map<Long, ManagedObject> objects = new Hashtable<Long, ManagedObject>();
+    private long bbank;
+    private long abank;
+    private static Log log = LogFactory.getLog(Agent.class);
+    private volatile boolean inside = false;
+
+    public Agent()
+    {
+        systemId = UUID.randomUUID();
+        log.debug(String.format("Agent with uid %s created", systemId
+                .toString()));
+    }
+
+    public Agent(String label, UUID systemId)
+    {
+        this.systemId = systemId;
+        this.label = label;
+        log.debug(String.format("Agent with name %s and uid %s created", label,
+                systemId.toString()));
+    }
+
+    public void register(ManagedObject managedObject)
+    {
+        Class managedClass = managedObject.getObjectClass();
+        long id = managedObject.getId();
+        ClassBinding cb = bctx.register(managedClass);
+        managedObject.setManagedClassName(cb.getName());
+        managedObject.setManagedPackageName(cb.getPackage());
+        log.debug(String.format(
+                "Added managed object id '%d' for package '%s' class '%s'", id,
+                managedObject.getManagedPackageName(), managedObject
+                        .getManagedClassName()));
+        objects.put(id, managedObject);
+        managedObjects.add(managedObject);
+    }
+
+    public void registerClass(Class cls)
+    {
+        bctx.register(cls);
+        if (!registeredClasses.contains(cls))
+        {
+            registeredClasses.add(cls);
+        }
+    }
+
+    public void start()
+    {
+        log.debug(String.format("Agent with uid %s and name %s starting",
+                systemId.toString(), label));
+        for (Object clsName : registeredClasses.toArray())
+        {
+            try
+            {
+                Class cls = Class.forName(clsName.toString());
+                this.registerClass(cls);
+            } catch (Exception e)
+            {
+                log.error("Could not register class " + clsName);
+            }
+        }
+        for (Object obj : managedObjects.toArray())
+        {
+            this.register((ManagedObject) obj);
+        }
+        try
+        {
+            session = connection.createSession(sessionTransacted,
+                    acknowledgeMode);
+            reply = session.createQueue("direct://amq.direct//" + label);
+            cons = session.createConsumer(reply);
+            cons.setMessageListener(this);
+            prod = session.createProducer(null);
+        } catch (JMSException e)
+        {
+            throw new AgentException(e);
+        }
+        attachRequest(label, systemId);
+        try
+        {
+            connection.start();
+        } catch (JMSException e)
+        {
+            throw new AgentException(e);
+        }
+    }
+
+    public void raiseEvent(Object value, EventSeverity sev)
+    {
+        log.debug(String.format("Sending event of class %s with Severity %s",
+                value.getClass(), sev.ordinal()));
+        BBEncoder enc = this.init('e');
+        ClassBinding cb = bctx.getClassBinding(value.getClass());
+        String pkg = cb.getPackage();
+        String cls = cb.getName();
+        enc.writeStr8(pkg);
+        enc.writeStr8(cls);
+        enc.writeBin128(cb.getSchemaHash());
+        long now = System.currentTimeMillis() * 1000000;
+        enc.writeInt64(now);
+        enc.writeUint8((short) sev.ordinal());
+        for (PropertyBinding p : cb.getProperties())
+        {
+            p.getType().encode(enc, BindingUtils.get(p, value));
+        }
+        send(
+                String.format("console.event.%d.%d.%s.%s", bbank, abank, pkg,
+                        cls), enc);
+    }
+
+    public void onMessage(Message message)
+    {
+        if (inside)
+        {
+            new Throwable().printStackTrace();
+        }
+        inside = true;
+        Decoder dec = readBody(message);
+        Destination replyTo;
+        try
+        {
+            replyTo = message.getJMSReplyTo();
+        } catch (JMSException e)
+        {
+            throw new AgentException(e);
+        }
+        byte[] magic = dec.readBytes(3);
+        if (magic[0] != 'A' || magic[1] != 'M' || magic[2] != '2')
+        {
+            throw new AgentException("bad magic: " + new String(magic));
+        }
+        short op = dec.readUint8();
+        long seq = dec.readUint32();
+        log.debug("Message recieved: " + (char) op);
+        switch (op)
+        {
+        case 'a':
+            this.handleAgentAttach(seq, replyTo, dec);
+            break;
+        case 'G':
+            this.handleGetQuery(seq, replyTo, dec);
+            break;
+        case 'M':
+            this.handleMethodRequest(seq, replyTo, dec);
+            break;
+        case 'S':
+            this.handleSchemaRequest(seq, replyTo, dec);
+            break;
+        case 'x':
+            // TODO
+            break;
+        default:
+            throw new IllegalArgumentException("opcode: " + ((char) op));
+        }
+        inside = false;
+    }
+
+    protected ClassBinding getClassBinding(ManagedObject mobj)
+    {
+        return bctx.getClassBinding(mobj.getObjectClass());
+    }
+
+    private byte[] ensure(int capacity, byte[] body, int size)
+    {
+        if (capacity > body.length)
+        {
+            byte[] copy = new byte[capacity];
+            System.arraycopy(body, 0, copy, 0, size);
+            body = copy;
+        }
+        return body;
+    }
+
+    private Decoder readBody(Message message)
+    {
+        BytesMessage msg = (BytesMessage) message;
+        BBDecoder dec = new BBDecoder();
+        byte[] buf = new byte[1024];
+        byte[] body = new byte[1024];
+        int size = 0;
+        int n;
+        try
+        {
+            while ((n = msg.readBytes(buf)) > 0)
+            {
+                body = ensure(size + n, body, size);
+                System.arraycopy(buf, 0, body, size, n);
+                size += n;
+            }
+        } catch (JMSException e)
+        {
+            throw new AgentException(e);
+        }
+        dec.init(ByteBuffer.wrap(body, 0, size));
+        return dec;
+    }
+
+    protected void handleAgentAttach(long seq, Destination replyTo, Decoder dec)
+    {
+        log.debug("Agent Attach Message");
+        bbank = dec.readUint32();
+        abank = dec.readUint32();
+        try
+        {
+            MessageConsumer mc = session
+                    .createConsumer(session
+                            .createQueue(String
+                                    .format(
+                                            "management://qpid.management//%s?routingkey='agent.%d.%d'",
+                                            label, bbank, abank)));
+            mc.setMessageListener(this);
+        } catch (JMSException e)
+        {
+            throw new AgentException(e);
+        }
+        for (String packageName : bctx.getPackages())
+        {
+            packageIndication(packageName);
+        }
+        for (ClassBinding cb : bctx.getAllBindings())
+        {
+            classIndication(cb);
+        }
+        for (ManagedObject mo : objects.values())
+        {
+            content('i', seq, null, mo);
+        }
+    }
+
+    protected void handleMethodRequest(long seq, Destination replyTo,
+            Decoder dec)
+    {
+        dec.readUint64(); // first part of object-id
+        long id = dec.readUint64();
+        ManagedObject mo = objects.get(id);
+        if (mo == null)
+        {
+            methodResponse(seq, replyTo, 1, String.format(
+                    "no such object: 0x%x", id));
+        } else
+        {
+            dec.readStr8(); // pkg
+            dec.readStr8(); // cls
+            dec.readBin128(); // hash
+            String mname = dec.readStr8();
+            ClassBinding cls = getClassBinding(mo);
+            MethodBinding method = cls.getMethod(mname);
+            if (method == null)
+            {
+                methodResponse(seq, replyTo, 2, String.format(
+                        "no such method: %s", mname));
+            } else
+            {
+                log.trace("Handle method: " + method.getName());
+                List<ParameterBinding> params = method.getInParameters();
+                Object[] args = new Object[params.size()];
+                int idx = 0;
+                for (ParameterBinding p : params)
+                {
+                    TypeBinding typeBinding = p.getType();
+                    log
+                            .trace(String
+                                    .format(
+                                            "Decoding parameter with type %s ref package %s ref class %s ",
+                                            typeBinding.getCode(), typeBinding
+                                                    .getRefPackage(),
+                                            typeBinding.getRefClass()));
+                    args[idx++] = typeBinding.decode(dec);
+                    log.trace("Done");
+                }
+                try
+                {
+                    Object[] result = mo.invoke(method, args);
+                    methodResponse(seq, replyTo, 0, null, method, result);
+                } catch (BindingException ex)
+                {
+                    log
+                            .error(String
+                                    .format(
+                                            "An exception occured invoking method %s. Stack trace sent to console.",
+                                            method.getName()));
+                    StringWriter str = new StringWriter();
+                    PrintWriter writer = new PrintWriter(str);
+                    ex.printStackTrace(writer);
+                    writer.flush();
+                    methodResponse(seq, replyTo, 7, str.toString());
+                }
+                log.trace("Done with method: " + method.getName());
+            }
+        }
+    }
+
+    protected void handleGetQuery(long seq, Destination replyTo, Decoder dec)
+    {
+        Map<String, Object> data = dec.readMap();
+        if (data.containsKey("_objectid"))
+        {
+            long objId = (Long) data.get("_objectid");
+            log.debug("Get Request message for object id " + objId);
+            ManagedObject mo = objects.get(objId);
+            if (mo == null)
+            {
+                methodResponse(seq, replyTo, 1, String.format(
+                        "no such object: 0x%x", objId));
+            } else
+            {
+                content('g', seq, replyTo, mo);
+            }
+        } else if (data.containsKey("_class"))
+        {
+            String className = (String) data.get("_class");
+            String packageName = (String) data.get("_package");
+            log.debug(String.format(
+                    "Get Request message for package '%s' class '%s'",
+                    packageName, className));
+            for (ManagedObject mo : objects.values())
+            {
+                if (mo.getManagedClassName().equals(className))
+                {
+                    if ((packageName == null) || packageName.equals("")
+                            || packageName.equals(mo.getManagedPackageName()))
+                    {
+                        content('g', seq, replyTo, mo);
+                    }
+                }
+            }
+        } else
+        {
+            for (ManagedObject mo : objects.values())
+            {
+                content('g', seq, replyTo, mo);
+            }
+        }
+        complete(seq, replyTo);
+    }
+
+    protected void handleSchemaRequest(long seq, Destination replyTo,
+            Decoder dec)
+    {
+        String pkg = dec.readStr8();
+        String cls = dec.readStr8();
+        log.debug(String.format(
+                "SchemaRequest message for package '%s' class '%s'", pkg, cls));
+        ClassBinding cb = bctx.getClassBinding(pkg, cls);
+        if (cb == null)
+        {
+            throw new AgentException("no such class: " + pkg + ", " + cls);
+        }
+        schemaResponse(seq, cb);
+    }
+
+    protected BBEncoder init(char opcode)
+    {
+        return init(opcode, 0);
+    }
+
+    protected BBEncoder init(char opcode, long sequence)
+    {
+        BBEncoder enc = new BBEncoder(1024);
+        enc.init();
+        enc.writeUint8((short) 'A');
+        enc.writeUint8((short) 'M');
+        enc.writeUint8((short) '2');
+        enc.writeUint8((short) opcode);
+        enc.writeUint32(sequence);
+        return enc;
+    }
+
+    protected void send(BBEncoder enc)
+    {
+        send("broker", enc);
+    }
+
+    protected void send(Destination dest, BBEncoder enc)
+    {
+        try
+        {
+            byte[] buf = new byte[1024];
+            byte[] body = new byte[1024];
+            BytesMessage msg = session.createBytesMessage();
+            ByteBuffer slice = enc.segment();
+            while (slice.hasRemaining())
+            {
+                int n = Math.min(buf.length, slice.remaining());
+                slice.get(buf, 0, n);
+                msg.writeBytes(buf, 0, n);
+            }
+            msg.setJMSReplyTo(reply);
+            // ???: I assume this is thread safe.
+            prod.send(dest, msg);
+        } catch (JMSException e)
+        {
+            throw new AgentException(e);
+        }
+    }
+
+    protected void send(String routingKey, BBEncoder enc)
+    {
+        try
+        {
+            send(session
+                    .createQueue("management://qpid.management//?routingkey='"
+                            + routingKey + "'"), enc);
+        } catch (JMSException e)
+        {
+            throw new AgentException(e);
+        }
+    }
+
+    private void attachRequest(String label, UUID systemId)
+    {
+        BBEncoder enc = init('A');
+        enc.writeStr8(label);
+        enc.writeUuid(systemId);
+        enc.writeUint32(0);
+        enc.writeUint32(0);
+        send(enc);
+    }
+
+    private void packageIndication(String pkg)
+    {
+        BBEncoder enc = init('p');
+        enc.writeStr8(pkg);
+        send(enc);
+    }
+
+    private void classIndication(ClassBinding cb)
+    {
+        BBEncoder enc = init('q');
+        enc.writeUint8(cb.getKind());
+        enc.writeStr8(cb.getPackage());
+        enc.writeStr8(cb.getName());
+        enc.writeBin128(cb.getSchemaHash()); // schema hash?
+        send(enc);
+    }
+
+    private void schemaResponse(long seq, ClassBinding cb)
+    {
+        BBEncoder enc = init('s', seq);
+        cb.encode(enc);
+        send(enc);
+    }
+
+    private void content(char c, long seq, Destination dest, ManagedObject mo)
+    {
+        BBEncoder enc = init(c, seq);
+        ClassBinding cb = getClassBinding(mo);
+        String pkg = cb.getPackage();
+        String cls = cb.getName();
+        enc.writeStr8(pkg);
+        enc.writeStr8(cls);
+        enc.writeBin128(cb.getSchemaHash());
+        long now = System.currentTimeMillis() * 1000000;
+        enc.writeUint64(now);
+        enc.writeUint64(now);
+        enc.writeUint64(0);
+        enc.writeUint64(0x0000FFFFFFFFFFFFL & ((bbank << 28) | abank));
+        enc.writeUint64(mo.getId());
+        for (PropertyBinding p : cb.getProperties())
+        {
+            p.getType().encode(enc, mo.get(p));
+        }
+        if (dest == null)
+        {
+            send(String.format("console.obj.%d.%d.%s.%s", bbank, abank, pkg,
+                    cls), enc);
+        } else
+        {
+            send(dest, enc);
+        }
+    }
+
+    private void complete(long seq, Destination dest)
+    {
+        BBEncoder enc = init('z', seq);
+        enc.writeUint32(0);
+        enc.writeStr8("");
+        send(dest, enc);
+    }
+
+    private void methodResponse(long seq, Destination dest, int status,
+            String text)
+    {
+        methodResponse(seq, dest, status, text, null, null);
+    }
+
+    private void methodResponse(long seq, Destination dest, int status,
+            String text, MethodBinding method, Object[] result)
+    {
+        BBEncoder enc = init('m', seq);
+        enc.writeUint32(status);
+        enc.writeStr16(text == null ? "" : text);
+        if (method != null)
+        {
+            int idx = 0;
+            for (ParameterBinding p : method.getOutParameters())
+            {
+                p.getType().encode(enc, result[idx++]);
+            }
+        }
+        send(dest, enc);
+    }
+
+    public String getLabel()
+    {
+        return label;
+    }
+
+    public void setLabel(String label)
+    {
+        this.label = label;
+    }
+
+    public AMQConnection getConnection()
+    {
+        return connection;
+    }
+
+    public void setConnection(AMQConnection connection)
+    {
+        this.connection = connection;
+    }
+
+    public boolean isSessionTransacted()
+    {
+        return sessionTransacted;
+    }
+
+    public void setSessionTransacted(boolean sessionTransacted)
+    {
+        this.sessionTransacted = sessionTransacted;
+    }
+
+    public void setManagedObjects(List objectList)
+    {
+        this.managedObjects = objectList;
+    }
+
+    public List getManagedObjects()
+    {
+        return managedObjects;
+    }
+
+    public void setRegisteredClasses(List objectList)
+    {
+        this.registeredClasses = objectList;
+    }
+
+    public List getRegisteredClasses()
+    {
+        return this.registeredClasses;
+    }
+
+    public static void main(String[] args) throws Exception
+    {
+        String broker = args[0];
+        String name = args[1];
+        String url = String.format(
+                "amqp://guest:guest@/?brokerlist='tcp://%s'", broker);
+        AMQConnection conn = new AMQConnection(url);
+        Agent agent = new Agent(name, UUID.randomUUID());
+        agent.setConnection(conn);
+        for (int i = 2; i < args.length; i++)
+        {
+            Class<?> cls = Class.forName(args[i]);
+            agent.register(new ManagedPOJO(cls.newInstance()));
+        }
+        agent.start();
+        while (true)
+        {
+            Thread.sleep(1000);
+        }
+    }
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/AgentException.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/AgentException.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/AgentException.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/AgentException.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,43 @@
+/*
+ *
+ * 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.agent;
+
+/**
+ * AgentException
+ * 
+ */
+public class AgentException extends RuntimeException
+{
+    public AgentException(String msg)
+    {
+        super(msg);
+    }
+
+    public AgentException(Throwable t)
+    {
+        super(t);
+    }
+
+    public AgentException(String msg, Throwable t)
+    {
+        super(msg, t);
+    }
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/EventSeverity.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/EventSeverity.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/EventSeverity.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/EventSeverity.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,6 @@
+package org.apache.qpid.agent;
+
+public enum EventSeverity
+{
+    EMERGENCY, ALERT, CRIT, ERROR, WARN, NOTICE, INFO, DEBUG
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedEJB.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedEJB.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedEJB.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedEJB.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,104 @@
+/*
+ *
+ * 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.agent;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.qpid.agent.binding.BindingUtils;
+import org.apache.qpid.agent.binding.MethodBinding;
+import org.apache.qpid.agent.binding.PropertyBinding;
+
+public class ManagedEJB extends ManagedObjectBase
+{
+    protected String className;
+    protected String jndiLocation;
+
+    protected Object getEJB()
+    {
+        try
+        {
+            InitialContext ctx = new InitialContext();
+            return ctx.lookup(jndiLocation);
+        } catch (NamingException e)
+        {
+            throw new AgentException("Error looking up EJB at " + jndiLocation,
+                    e);
+        }
+    }
+
+    @Override
+    public Object get(PropertyBinding property)
+    {
+        return BindingUtils.get(property, this.getEJB());
+    }
+
+    @Override
+    public long getId()
+    {
+        return System.identityHashCode(this);
+    }
+
+    @Override
+    public Class getObjectClass()
+    {
+        try
+        {
+            return Class.forName(className);
+        } catch (ClassNotFoundException e)
+        {
+            throw new AgentException(String.format(
+                    "No class named %s was found", className), e);
+        }
+    }
+
+    @Override
+    public Object[] invoke(MethodBinding method, Object... args)
+    {
+        return BindingUtils.invoke(method, this.getEJB(), args);
+    }
+
+    @Override
+    public void set(PropertyBinding property, Object value)
+    {
+        BindingUtils.set(property, value, this.getEJB());
+    }
+
+    public String getClassName()
+    {
+        return className;
+    }
+
+    public void setClassName(String className)
+    {
+        this.className = className;
+    }
+
+    public String getJndiLocation()
+    {
+        return jndiLocation;
+    }
+
+    public void setJndiLocation(String jndiLocation)
+    {
+        this.jndiLocation = jndiLocation;
+    }
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedObject.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedObject.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedObject.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedObject.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,49 @@
+/*
+ *
+ * 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.agent;
+
+import org.apache.qpid.agent.binding.MethodBinding;
+import org.apache.qpid.agent.binding.PropertyBinding;
+
+public interface ManagedObject
+{
+    public abstract long getId();
+
+    public abstract Class getObjectClass();
+
+    public abstract Object get(PropertyBinding property);
+
+    public abstract void set(PropertyBinding property, Object value);
+
+    public abstract Object[] invoke(MethodBinding method, Object... args);
+
+    public abstract String getName();
+
+    public abstract void setName(String name);
+
+    public String getManagedClassName();
+
+    public String getManagedPackageName();
+
+    public void setManagedClassName(String aName);
+
+    public void setManagedPackageName(String aName);
+}
\ No newline at end of file

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedObjectBase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedObjectBase.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedObjectBase.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedObjectBase.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,72 @@
+/*
+ *
+ * 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.agent;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.qpid.agent.binding.MethodBinding;
+import org.apache.qpid.agent.binding.PropertyBinding;
+
+public abstract class ManagedObjectBase implements ManagedObject
+{
+    private static Log log = LogFactory.getLog(ManagedObjectBase.class);
+    protected String name;
+    protected String managedClassName;
+    protected String managedPackageName;
+
+    public abstract long getId();
+
+    public abstract Object get(PropertyBinding property);
+
+    public abstract void set(PropertyBinding property, Object value);
+
+    public abstract Object[] invoke(MethodBinding method, Object... args);
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public String getManagedClassName()
+    {
+        return managedClassName;
+    }
+
+    public void setManagedClassName(String managedClassName)
+    {
+        this.managedClassName = managedClassName;
+    }
+
+    public String getManagedPackageName()
+    {
+        return managedPackageName;
+    }
+
+    public void setManagedPackageName(String managedPackageName)
+    {
+        this.managedPackageName = managedPackageName;
+    }
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedPOJO.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedPOJO.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedPOJO.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/ManagedPOJO.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,87 @@
+/*
+ *
+ * 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.agent;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.qpid.agent.binding.BindingUtils;
+import org.apache.qpid.agent.binding.MethodBinding;
+import org.apache.qpid.agent.binding.PropertyBinding;
+
+public class ManagedPOJO extends ManagedObjectBase implements ManagedObject
+{
+    private Log log = LogFactory.getLog(ManagedPOJO.class);
+    private Object managed;
+
+    public ManagedPOJO()
+    {
+        super();
+    }
+
+    public ManagedPOJO(Object managed)
+    {
+        super();
+        this.setManaged(managed);
+    }
+
+    @Override
+    public long getId()
+    {
+        if (managed == null)
+        {
+            throw new AgentException("The managed object is null");
+        }
+        return System.identityHashCode(managed);
+    }
+
+    public Class getObjectClass()
+    {
+        return managed.getClass();
+    }
+
+    public Object getManaged()
+    {
+        return managed;
+    }
+
+    public void setManaged(Object managed)
+    {
+        this.managed = managed;
+    }
+
+    @Override
+    public Object get(PropertyBinding property)
+    {
+        return BindingUtils.get(property, managed);
+    }
+
+    @Override
+    public Object[] invoke(MethodBinding method, Object... args)
+    {
+        return BindingUtils.invoke(method, managed, args);
+    }
+
+    @Override
+    public void set(PropertyBinding property, Object value)
+    {
+        BindingUtils.set(property, value, managed);
+    }
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFEvent.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFEvent.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFEvent.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFEvent.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,38 @@
+/*
+ *
+ * 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.agent.annotations;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Target(TYPE)
+@Retention(RUNTIME)
+@Documented
+public @interface QMFEvent
+{
+    String eventName();
+
+    String packageName();
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFHide.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFHide.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFHide.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFHide.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,35 @@
+/*
+ *
+ * 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.agent.annotations;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Target(ElementType.METHOD)
+@Retention(RUNTIME)
+@Documented
+public @interface QMFHide
+{
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFObject.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFObject.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFObject.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFObject.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,38 @@
+/*
+ *
+ * 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.agent.annotations;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Target(TYPE)
+@Retention(RUNTIME)
+@Documented
+public @interface QMFObject
+{
+    String className();
+
+    String packageName();
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFProperty.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFProperty.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFProperty.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFProperty.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.agent.annotations;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Target(ElementType.FIELD)
+@Retention(RUNTIME)
+@Documented
+public @interface QMFProperty
+{
+    boolean optional() default false;
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFSeeAlso.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFSeeAlso.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFSeeAlso.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFSeeAlso.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.agent.annotations;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Target(TYPE)
+@Retention(RUNTIME)
+@Documented
+public @interface QMFSeeAlso
+{
+    Class[] value();
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFType.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFType.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFType.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/annotations/QMFType.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,38 @@
+/*
+ *
+ * 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.agent.annotations;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Target(TYPE)
+@Retention(RUNTIME)
+@Documented
+public @interface QMFType
+{
+    String className();
+
+    String packageName();
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingContext.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingContext.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingContext.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingContext.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,209 @@
+/*
+ *
+ * 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.agent.binding;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.qpid.agent.annotations.QMFEvent;
+import org.apache.qpid.agent.annotations.QMFObject;
+import org.apache.qpid.agent.annotations.QMFSeeAlso;
+import org.apache.qpid.agent.annotations.QMFType;
+
+public class BindingContext
+{
+    private static Log log = LogFactory.getLog(BindingContext.class);
+    private Map<Key, ClassBinding> classes = new Hashtable<Key, ClassBinding>();
+    private ArrayList<String> packages = new ArrayList<String>();
+
+    static class Key
+    {
+        String packageName = "";
+        String className = "";
+        boolean object = false;
+
+        @Override
+        public int hashCode()
+        {
+            return (packageName + "." + className).hashCode();
+        }
+
+        @Override
+        public boolean equals(Object obj)
+        {
+            return ((obj.getClass() == Key.class)
+                    && (((Key) obj).packageName.equals(packageName)) && (((Key) obj).className
+                    .equals(className)));
+        }
+    }
+
+    public BindingContext()
+    {
+        Key key = new Key();
+        key.className = "Object";
+        key.packageName = "org.apache.qmf";
+        key.object = false;
+        ClassBinding cb = new ClassBinding("org.apache.qmf", "Object",
+                Object.class, false, this);
+        classes.put(key, cb);
+        packages.add("org.apache.qmf");
+    }
+
+    public ClassBinding getClassBinding(Class clazz)
+    {
+        return classes.get(getClassKey(clazz));
+    }
+
+    public ClassBinding getClassBinding(String packageName, String className)
+    {
+        Key key = new Key();
+        key.packageName = packageName;
+        key.className = className;
+        return classes.get(key);
+    }
+
+    public ClassBinding register(Class cls)
+    {
+        String name = cls.getName();
+        ClassBinding cb = getClassBinding(cls);
+        if (cb == null)
+        {
+            Key key = getClassKey(cls);
+            // Create and store the internal representations
+            if (cls.isEnum())
+            {
+                cb = new EnumBinding(key.packageName, key.className, cls,
+                        key.object, this);
+            } else
+            {
+                cb = new ClassBinding(key.packageName, key.className, cls,
+                        key.object, this);
+            }
+            log.debug(String.format(
+                    "Added class binding '%s' in package %s for class %s'",
+                    key.className, key.packageName, cls.getCanonicalName()));
+            classes.put(key, cb);
+            if (!packages.contains(key.packageName))
+            {
+                packages.add(key.packageName);
+            }
+            // Parse the methods after adding the class to avoid recursion
+            cb.parse();
+            // See if there are other classes which should be looked at
+            QMFSeeAlso seeAlso = (QMFSeeAlso) cls
+                    .getAnnotation(QMFSeeAlso.class);
+            if (seeAlso != null)
+            {
+                for (Class seeAlsoCls : seeAlso.value())
+                {
+                    this.register(seeAlsoCls);
+                }
+            }
+        }
+        return cb;
+    }
+
+    public TypeBinding getTypeBinding(Class cls)
+    {
+        // Look for a built in type
+        TypeBinding type = QMFTypeBinding.forClass(cls);
+        // Have we seen it before?
+        if (type == null)
+        {
+            type = this.getClassBinding(cls);
+        }
+        if ((type == null) && List.class.isAssignableFrom(cls))
+        {
+            type = new ListBinding(this, cls);
+        }
+        if ((type == null) && Map.class.isAssignableFrom(cls))
+        {
+            type = new MapBinding(this, cls);
+        }
+        // Add it, but since we have not seen it before do not expose methods
+        if (type == null)
+        {
+            type = this.register(cls);
+        }
+        return type;
+    }
+
+    // FIXME: Need to store these keys off so we dont create alot of objects
+    protected Key getClassKey(Class cls)
+    {
+        Key key = new Key();
+        QMFObject objAnnotation = (QMFObject) cls
+                .getAnnotation(QMFObject.class);
+        if (objAnnotation != null)
+        {
+            key.className = objAnnotation.className();
+            key.packageName = objAnnotation.packageName();
+            key.object = true;
+        } else
+        {
+            QMFType typeAnnotation = (QMFType) cls.getAnnotation(QMFType.class);
+            if (typeAnnotation != null)
+            {
+                key.className = typeAnnotation.className();
+                key.packageName = typeAnnotation.packageName();
+            } else
+            {
+                QMFEvent eventAnnotation = (QMFEvent) cls
+                        .getAnnotation(QMFEvent.class);
+                if (eventAnnotation != null)
+                {
+                    key.className = eventAnnotation.eventName();
+                    key.packageName = eventAnnotation.packageName();
+                } else
+                {
+                    // If this is Object, we return the fake
+                    // object value
+                    if (cls == Object.class)
+                    {
+                        key.className = "Object";
+                        key.packageName = "org.apache.qmf";
+                    } else
+                    {
+                        String name = cls.getName();
+                        int lastDot = name.lastIndexOf('.');
+                        key.className = name.substring(lastDot + 1);
+                        key.packageName = name.substring(0, lastDot);
+                    }
+                }
+            }
+        }
+        return key;
+    }
+
+    public ArrayList<String> getPackages()
+    {
+        return packages;
+    }
+
+    public Collection<ClassBinding> getAllBindings()
+    {
+        return classes.values();
+    }
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingException.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingException.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingException.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingException.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,50 @@
+/*
+ *
+ * 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.agent.binding;
+
+/**
+ * ManagedException
+ * 
+ */
+public class BindingException extends RuntimeException
+{
+    private static final long serialVersionUID = -7350845525748113340L;
+
+    public BindingException(Throwable t)
+    {
+        super(t);
+    }
+
+    public BindingException()
+    {
+        super();
+    }
+
+    public BindingException(String message, Throwable cause)
+    {
+        super(message, cause);
+    }
+
+    public BindingException(String message)
+    {
+        super(message);
+    }
+}

Added: qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingUtils.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingUtils.java?rev=783818&view=auto
==============================================================================
--- qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingUtils.java (added)
+++ qpid/trunk/qpid/java/agent/src/main/java/org/apache/qpid/agent/binding/BindingUtils.java Thu Jun 11 15:54:37 2009
@@ -0,0 +1,137 @@
+/*
+ *
+ * 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.agent.binding;
+
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class BindingUtils
+{
+    private static Log log = LogFactory.getLog(BindingUtils.class);
+
+    public static Object get(PropertyBinding property, Object managed)
+    {
+        String name = property.getName();
+        return get(name, managed);
+    }
+
+    public static void set(PropertyBinding property, Object value,
+            Object managed)
+    {
+        String name = property.getName();
+        TypeBinding type = property.getType();
+        try
+        {
+            Method meth = managed.getClass().getMethod(accessor("set", name),
+                    type.getJavaClass());
+            meth.invoke(managed, value);
+        } catch (NoSuchMethodException e)
+        {
+            throw new BindingException(e);
+        } catch (IllegalAccessException e)
+        {
+            throw new BindingException(e);
+        } catch (InvocationTargetException e)
+        {
+            throw new BindingException(e.getTargetException());
+        }
+    }
+
+    public static Object[] invoke(MethodBinding method, Object managed,
+            Object... args)
+    {
+        log.debug(String.format("Invoking %s on %s", method.getName(), managed
+                .getClass()));
+        List<ParameterBinding> in = method.getInParameters();
+        List<ParameterBinding> out = method.getOutParameters();
+        Class<?>[] classes = new Class<?>[in.size()];
+        int idx = 0;
+        for (ParameterBinding p : in)
+        {
+            classes[idx++] = p.getType().getJavaClass();
+        }
+        Object result;
+        try
+        {
+            Method meth = managed.getClass().getMethod(method.getName(),
+                    classes);
+            result = meth.invoke(managed, args);
+        } catch (NoSuchMethodException e)
+        {
+            throw new BindingException(e);
+        } catch (IllegalAccessException e)
+        {
+            throw new BindingException(e);
+        } catch (InvocationTargetException e)
+        {
+            throw new BindingException(e.getTargetException());
+        }
+        Object[] results = new Object[out.size()];
+        // XXX: need better way to distinguish this case
+        if (out.size() == 1 && out.get(0).getName().equals("result"))
+        {
+            results[0] = result;
+        } else
+        {
+            for (int i = 0; i < results.length; i++)
+            {
+                results[i] = get(out.get(i).getName(), result);
+            }
+        }
+        return results;
+    }
+
+    public static String accessor(String pfx, String property)
+    {
+        return pfx + Character.toUpperCase(property.charAt(0))
+                + property.substring(1);
+    }
+
+    public static Object get(String name, Object obj)
+    {
+        Object returnValue = null;
+        try
+        {
+            BeanInfo info = Introspector.getBeanInfo(obj.getClass());
+            PropertyDescriptor[] pds = info.getPropertyDescriptors();
+            for (PropertyDescriptor pd : pds)
+            {
+                if (pd.getName().equals(name))
+                {
+                    Method getMethod = pd.getReadMethod();
+                    returnValue = getMethod.invoke(obj);
+                    break;
+                }
+            }
+        } catch (Exception e)
+        {
+            throw new BindingException(e);
+        }
+        return returnValue;
+    }
+}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org