You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by fa...@apache.org on 2013/04/08 17:19:09 UTC

svn commit: r1465662 [12/26] - in /qpid/trunk/qpid/tools/src/java: ./ bin/ bin/qpid-web/ bin/qpid-web/authentication/ bin/qpid-web/web/ bin/qpid-web/web/itablet/ bin/qpid-web/web/itablet/css/ bin/qpid-web/web/itablet/images/ bin/qpid-web/web/itablet/im...

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfData.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfData.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfData.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfData.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,443 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * QMF defines the QmfData class to represent an atomic unit of managment data.
+ * <p>
+ * The QmfData class defines a collection of named data values. Optionally, a string tag, or "sub-type" may be
+ * associated with each data item. This tag may be used by an application to annotate the data item.
+ * (Note the tag implementation is TBD).
+ * <p>
+ * In QMFv2, message bodies are AMQP maps and are therefore easily extended without causing backward
+ * compatibility problems. Another benefit of the map-message format is that all messages can be fully
+ * parsed when received without the need for external schema data
+ * <p>
+ * This class is the base class for all QMF2 Data Types in this implementation. It is intended to provide a
+ * useful wrapper for the underlying Map, supplying accessor and mutator methods that give an element of type
+ * safety (for example strings appear to be encoded as a mixture of byte[] and String depending of the agent, so
+ * this class checks for this in its getString())
+ * <p>
+ * The following diagram represents the QmfData class hierarchy.
+ * <p>
+ * <img src="doc-files/QmfData.png"/>
+ *
+ * @author Fraser Adams
+ */
+public class QmfData
+{
+    protected Map<String, Object> _values = null;
+    protected Map<String, String> _subtypes = null;
+
+    /**
+     * The default constructor, initialises the QmfData with an empty Map.
+     */
+    public QmfData()
+    {
+        _values = new HashMap<String, Object>();
+    }
+
+    /**
+     * The main constructor, taking a java.util.Map as a parameter. In essence it "deserialises" its state from the Map.
+     *
+     * @param m the Map used to construct the QmfData.
+     */
+    @SuppressWarnings("unchecked")
+    public QmfData(final Map m)
+    {
+        if (m == null)
+        { // This branch is just a safety precaution and shouldn't generally occur in normal usage scenarios.
+            // Initialise with a new HashMap. Should then behave the same as the default Constructor.
+            _values = new HashMap<String, Object>();
+        }
+        else
+        {
+            Map<String, Object> values = (Map<String, Object>)m.get("_values");
+            _values = (values == null) ? m : values;
+
+            Map<String, String> subtypes = (Map<String, String>)m.get("_subtypes");
+             _subtypes = subtypes;
+        }   
+    }
+
+    /**
+     * Get the state of the _subtypes Map, (generally used when serialising method request/response arguments.
+     *
+     * @return the value of the _subtypes Map.
+     */
+    public Map<String, String> getSubtypes()
+    {
+        return _subtypes;
+    }
+
+
+    /**
+     * Set the state of the _subtypes Map, (generally used when deserialising method request/response arguments.
+     *
+     * @param subtypes the new value of the _subtypes Map.
+     */
+    @SuppressWarnings("unchecked")
+    public void setSubtypes(Map subtypes)
+    {
+        _subtypes = subtypes;
+    }
+
+    /**
+     * Helper method to return the <i>best</i> String representation of the given Object.
+     * <p>
+     * There seem to be some inconsistencies where string properties are sometimes returned as byte[] and
+     * sometimes as Strings. It seems to vary depending on the Agent and is due to strings being encoded as a mix of
+     * binary strings and UTF-8 strings by C++ Agent classes. Getting it wrong results in ClassCastExceptions, which
+     * is clearly unfortunate.
+     * <p>
+     * This is basically a helper method to check the type of a property and return the most "appropriate"
+     * String representation for it.
+     *
+     * @param p a property in Object form
+     * @return the most appropriate String representation of the property
+     */
+    public static final String getString(final Object p)
+    {
+        if (p == null)
+        {
+            return "";
+        }
+        else if (p instanceof String)
+        {
+            return (String)p;
+        }
+        else if (p instanceof byte[])
+        {
+            return new String((byte[])p);
+        }
+        else return p.toString();
+    }
+
+    /**
+     * Helper method to return the <i>best</i> long representation of the given Object.
+     * <p>
+     * There seem to be some inconsistencies where properties are sometimes returned as Integer and
+     * sometimes as Long. It seems to vary depending on the Agent and getting it wrong results in
+     * ClassCastExceptions, which is clearly unfortunate.
+     * <p>
+     * This is basically a helper method to check the type of a property and return a long representation for it.
+     *
+     * @param p a property in Object form
+     * @return the long representation for it.
+     */
+    public static final long getLong(final Object p)
+    {
+        if (p == null)
+        {
+            return 0;
+        }
+        else if (p instanceof Long)
+        {
+            return ((Long)p).longValue();
+        }
+        else if (p instanceof Integer)
+        {
+            return ((Integer)p).intValue();
+        }
+        else if (p instanceof Short)
+        {
+            return ((Short)p).shortValue();
+        }
+        else return 0;
+    }
+
+    /**
+     * Helper method to return the <i>best</i> boolean representation of the given Object.
+     * <p>
+     * There seem to be some inconsistencies where boolean properties are sometimes returned as Boolean and
+     * sometimes as Long/Integer/Short. It seems to vary depending on the Agent and getting it wrong results in
+     * ClassCastExceptions, which is clearly unfortunate.
+     * <p>
+     * This is basically a helper method to check the type of a property and return a boolean representation for it.
+     *
+     * @param p a property in Object form
+     * @return the boolean representation for it.
+     */
+    public static final boolean getBoolean(final Object p)
+    {
+        if (p == null)
+        {
+            return false;
+        }
+        else if (p instanceof Boolean)
+        {
+            return ((Boolean)p).booleanValue();
+        }
+        else if (p instanceof Long)
+        {
+            return ((Long)p).longValue() > 0;
+        }
+        else if (p instanceof Integer)
+        {
+            return ((Integer)p).intValue() > 0;
+        }
+        else if (p instanceof Short)
+        {
+            return ((Short)p).shortValue() > 0;
+        }
+        else if (p instanceof String)
+        {
+            return Boolean.parseBoolean((String)p);
+        }
+        else return false;
+    }
+
+    /**
+     * Helper method to return the <i>best</i> double representation of the given Object.
+     * <p>
+     * There seem to be some inconsistencies where properties are sometimes returned as Float and
+     * sometimes as Double. It seems to vary depending on the Agent and getting it wrong results in
+     * ClassCastExceptions, which is clearly unfortunate.
+     * <p>
+     * This is basically a helper method to check the type of a property and return a Double representation for it.
+     *
+     * @param p a property in Object form
+     * @return the Double representation for it.
+     */
+    public static final double getDouble(final Object p)
+    {
+        if (p == null)
+        {
+            return 0.0d;
+        }
+        else if (p instanceof Float)
+        {
+            return ((Float)p).floatValue();
+        }
+        else if (p instanceof Double)
+        {
+            return ((Double)p).doubleValue();
+        }
+        else return 0.0d;
+    }
+
+    /**
+     * Determines if the named property exists.
+     *
+     * @param name of the property to check.
+     * @return true if the property exists otherwise false.
+     */
+    public final boolean hasValue(final String name)
+    {
+        return _values.containsKey(name);
+    }
+
+    /**
+     * Accessor method to return a named property as an Object.
+     *
+     * @param name of the property to return as an Object.
+     * @return value of property as an Object.
+     */
+    @SuppressWarnings("unchecked")
+    public final <T> T getValue(final String name)
+    {
+        return (T)_values.get(name);
+    }
+
+    /**
+     * Mutator method to set a named Object property.
+     *
+     * @param name the name of the property to set.
+     * @param value the value of the property to set.
+     */
+    public final void setValue(final String name, final Object value)
+    {
+        _values.put(name, value);
+    }
+
+    /**
+     * Mutator method to set a named Object property.
+     *
+     * @param name the name of the property to set.
+     * @param value the value of the property to set.
+     * @param subtype the subtype of the property.
+     */
+    public final void setValue(final String name, final Object value, final String subtype)
+    {
+        setValue(name, value);
+        setSubtype(name, subtype);
+    }
+
+    /**
+     * Mutator to set or modify the subtype associated with name.
+     *
+     * @param name the name of the property to set the subtype for.
+     * @param subtype the subtype of the property.
+     */
+    public final void setSubtype(final String name, final String subtype)
+    {
+        if (_subtypes == null)
+        {
+            _subtypes = new HashMap<String, String>();
+        }
+        _subtypes.put(name, subtype);
+    }
+
+    /**
+     * Accessor to return the subtype associated with named property.
+     *
+     * @param name the name of the property to get the subtype for.
+     * @return the subtype of the named property or null if not present.
+     */
+    public final String getSubtype(final String name)
+    {
+        if (_subtypes == null)
+        {
+            return null;
+        }
+        return _subtypes.get(name);
+    }
+
+    /**
+     * Accessor method to return a named property as a boolean.
+     *
+     * @param name of the property to return as a boolean.
+     * @return value of property as a boolean.
+     */
+    public final boolean getBooleanValue(final String name)
+    {
+        return getBoolean(getValue(name));
+    }
+
+    /**
+     * Accessor method to return a named property as a long.
+     *
+     * @param name of the property to return as a long.
+     * @return value of property as a long.
+     */
+    public final long getLongValue(final String name)
+    {
+        return getLong(getValue(name));
+    }
+
+    /**
+     * Accessor method to return a named property as a double.
+     *
+     * @param name of the property to return as a double.
+     * @return value of property as a double.
+     */
+    public final double getDoubleValue(final String name)
+    {
+        return getDouble(getValue(name));
+    }
+
+    /**
+     * Accessor method to return a named property as a String.
+     *
+     * @param name of the property to return as a String.
+     * @return value of property as a String.
+     */
+    public final String getStringValue(final String name)
+    {
+        return getString(getValue(name));
+    }
+
+    /**
+     * Accessor method to return a reference property.
+     * <p>
+     * Many QMF Objects contain reference properties, e.g. references to other QMF Objects.
+     * This method allows these to be obtained as ObjectId objects to enable much easier
+     * comparison and rendering.
+     * @return the retrieved value as an ObjectId instance.
+     */
+    public final ObjectId getRefValue(final String name)
+    {
+        return new ObjectId((Map)getValue(name));
+    }
+
+    /**
+     * Mutator method to set a named reference property.
+     * <p>
+     * Many QMF Objects contain reference properties, e.g. references to other QMF Objects.
+     * This method allows these to be set as ObjectId objects.
+     *
+     * @param name the name of the property to set.
+     * @param value the value of the property to set.
+     */
+    public final void setRefValue(final String name, final ObjectId value)
+    {
+        setValue(name, value.mapEncode());
+    }
+
+    /**
+     * Mutator method to set a named reference property.
+     * <p>
+     * Many QMF Objects contain reference properties, e.g. references to other QMF Objects.
+     * This method allows these to be set as ObjectId objects.
+     *
+     * @param name the name of the property to set.
+     * @param value the value of the property to set.
+     * @param subtype the subtype of the property.
+     */
+    public final void setRefValue(final String name, final ObjectId value, final String subtype)
+    {
+        setRefValue(name, value);
+        setSubtype(name, subtype);
+    }
+
+    /**
+     * Return the underlying Map representation of this QmfData.
+     * @return the underlying Map. 
+     */
+    public Map<String, Object> mapEncode()
+    {
+        return _values;
+    }
+
+    /**
+     * Helper/debug method to list the properties and their type.
+     */
+    public void listValues()
+    {
+        for (Map.Entry<String, Object> entry : _values.entrySet())
+        {
+            Object key = entry.getKey();
+            Object value = entry.getValue();
+            if (value instanceof Map)
+            { // Check if the value part is an ObjectId and display appropriately
+                Map map = (Map)value;
+                if (map.containsKey("_object_name"))
+                {
+                    System.out.println(key + ": " + new ObjectId(map));
+                }
+                else
+                {
+                    System.out.println(key + ": " + getString(value));
+                }
+            }
+            else
+            {
+                System.out.println(key + ": " + getString(value));
+            }
+        }
+    }
+}
+

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfData.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfDescribed.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfDescribed.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfDescribed.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfDescribed.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,84 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Subclass of QmfData.
+ * <p>
+ * When representing formally defined data, a QmfData instance is assigned a Schema.
+ *
+ * @author Fraser Adams
+ */
+public class QmfDescribed extends QmfData
+{
+    private SchemaClassId _schema_id;
+
+    /**
+     * The default constructor, initialises the underlying QmfData base class with an empty Map
+     */
+    protected QmfDescribed()
+    {
+    }
+
+    /**
+     * The main constructor, taking a java.util.Map as a parameter. In essence it "deserialises" its state from the Map.
+     *
+     * @param m the map used to construct the QmfDescribed
+     */
+    public QmfDescribed(final Map m)
+    {
+        super(m);
+        _schema_id = (m == null) ? null : new SchemaClassId((Map)m.get("_schema_id"));
+    }
+
+    /**
+     * Returns the SchemaClassId describing this object.
+     * @return the SchemaClassId describing this object.
+     */
+    public final SchemaClassId getSchemaClassId()
+    {
+        return _schema_id;
+    }
+
+    /**
+     * Sets the SchemaClassId describing this object.
+     * @param schema_id the SchemaClassId describing this object.
+     */
+    public final void setSchemaClassId(final SchemaClassId schema_id)
+    {
+        _schema_id = schema_id;
+    }
+
+    /**
+     * Helper/debug method to list the QMF Object properties and their type.
+     */
+    @Override
+    public void listValues()
+    {
+        super.listValues();
+        _schema_id.listValues();
+    }
+}
+

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfDescribed.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfDescribed.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEvent.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEvent.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEvent.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEvent.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,224 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * QMF supports event management functionality. An event is a notification that is sent by an Agent to alert Console(s)
+ * of a change in some aspect of the system under management. Like QMF Data, Events may be formally defined by a Schema
+ * or not. Unlike QMF Data, Events are not manageable entities - they have no lifecycle. Events simply indicate a point
+ * in time where some interesting action occurred.
+ * <p>
+ * An AMQP timestamp value is associated with each QmfEvent instance. It indicates the moment in time the event occurred.
+ * This timestamp is mandatory.
+ * <p>
+ * A severity level may be associated with each QmfEvent instance. The following severity levels are supported:
+ * <pre>
+ *    * "emerg"   - system is unusable
+ *    * "alert"   - action must be taken immediately
+ *    * "crit"    - the system is in a critical condition
+ *    * "err"     - there is an error condition
+ *    * "warning" - there is a warning condition
+ *    * "notice"  - a normal but significant condition
+ *    * "info"    - a purely informational message
+ *    * "debug"   - messages generated to debug the application
+ * </pre>
+ * The default severity is "notice".
+ *
+ * @author Fraser Adams
+ */
+public final class QmfEvent extends QmfDescribed
+{
+    private static final String[] severities = {"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"};
+
+    private long _timestamp;
+    private int  _severity;
+
+    /**
+     * The main constructor, taking a java.util.Map as a parameter. In essence it "deserialises" its state from the Map.
+     *
+     * @param m the map used to construct the QmfEvent
+     */
+    public QmfEvent(final Map m)
+    {
+        super(m);
+        _timestamp = m.containsKey("_timestamp") ? getLong(m.get("_timestamp")) : System.currentTimeMillis()*1000000l;
+        _severity = m.containsKey("_severity") ? (int)getLong(m.get("_severity")) : 5;
+    }
+
+    /**
+     * This constructor taking a SchemaEventClass is the main constructor used by Agents when creating Events
+     * 
+     * @param schema the SchemaEventClass describing the Event
+     */
+    public QmfEvent(final SchemaEventClass schema)
+    {
+        _timestamp = System.currentTimeMillis()*1000000l;
+        setSchemaClassId(schema.getClassId());
+    }
+
+    /**
+     * Return the timestamp. Timestamps are recorded in nanoseconds since the epoch.
+     * <p>
+     * An AMQP timestamp value is associated with each QmfEvent instance. It indicates the moment in time the event
+     * occurred. This timestamp is mandatory.
+     *
+     * @return the AMQP timestamp value in nanoseconds since the epoch.
+     */
+    public long getTimestamp()
+    {
+        return _timestamp;
+    }
+
+    /**
+     * Return the severity.
+     * <p>
+     * A severity level may be associated with each QmfEvent instance. The following severity levels are supported:
+     * <pre>
+     *        * "emerg"   - system is unusable
+     *        * "alert"   - action must be taken immediately
+     *        * "crit"    - the system is in a critical condition
+     *        * "err"     - there is an error condition
+     *        * "warning" - there is a warning condition
+     *        * "notice"  - a normal but significant condition
+     *        * "info"    - a purely informational message
+     *        * "debug"   - messages generated to debug the application
+     * </pre>
+     * The default severity is "notice"
+     *
+     * @return the severity value as a String as described above
+     */
+    public String getSeverity()
+    {
+        return severities[_severity];
+    }
+
+    /**
+     * Set the severity level of the Event
+     * @param severity the severity level of the Event as an int
+     */
+    public void setSeverity(final int severity)
+    {
+        if (severity < 0 || severity > 7)
+        {
+            // If supplied value is out of range we set to the default severity
+            _severity = 5;
+            return;
+        }
+        _severity = severity;
+    }
+
+    /**
+     * Set the severity level of the Event
+     * @param severity the severity level of the Event as a String.
+     * <p>
+     * The following severity levels are supported:
+     * <pre>
+     *        * "emerg"   - system is unusable
+     *        * "alert"   - action must be taken immediately
+     *        * "crit"    - the system is in a critical condition
+     *        * "err"     - there is an error condition
+     *        * "warning" - there is a warning condition
+     *        * "notice"  - a normal but significant condition
+     *        * "info"    - a purely informational message
+     *        * "debug"   - messages generated to debug the application
+     * </pre>
+     */
+    public void setSeverity(final String severity)
+    {
+        for (int i = 0; i < severities.length; i++)
+        {
+            if (severity.equals(severities[i]))
+            {
+                _severity = i;
+                return;
+            }
+        }
+        // If we can't match the values we set to the default severity
+        _severity = 5;
+    }
+
+    /**
+     * Return the underlying Map representation of this QmfEvent
+     * @return the underlying map. 
+     */
+    @Override
+    public Map<String, Object> mapEncode()
+    {
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("_values", super.mapEncode());
+        if (_subtypes != null)
+        {
+            map.put("_subtypes", _subtypes);
+        }
+        map.put("_schema_id", getSchemaClassId().mapEncode());
+        map.put("_timestamp", _timestamp);
+        map.put("_severity", _severity);
+        return map;
+    }
+
+    /**
+     * Helper/debug method to list the object properties and their type.
+     */
+    @Override
+    public void listValues()
+    {
+        System.out.println("QmfEvent:");
+        System.out.println(this);
+    }
+
+    /**
+     * Returns a String representation of the QmfEvent.
+     * <p>
+     * The String representation attempts to mirror the python class Event __repr__ method as far as possible.
+     * @return a String representation of the QmfEvent.
+     */
+    @Override
+    public String toString()
+    {
+        if (getSchemaClassId() == null)
+        {
+            return "<uninterpretable>";
+        }
+
+        String out = new Date(getTimestamp()/1000000l).toString();
+        out += " " + getSeverity() + " " + getSchemaClassId().getPackageName() + ":" + getSchemaClassId().getClassName();
+        
+        StringBuilder buf = new StringBuilder();
+        for (Map.Entry<String, Object> entry : super.mapEncode().entrySet())
+        {
+            String disp = getString(entry.getValue());
+            if (disp.contains(" "))
+            {
+                disp = "\"" + disp + "\"";
+            }
+
+            buf.append(" " + entry.getKey() + "=" + disp);
+        }
+
+        return out + buf.toString();
+    }
+}
+

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEvent.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEventListener.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEventListener.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEventListener.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEventListener.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,51 @@
+/*
+ *
+ * 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.qmf2.common;
+
+/**
+ * A QmfEventListener object is used to receive asynchronously delivered WorkItems.
+ * <p>
+ * This provides an alternative (simpler) API to the official QMF2 WorkQueue API that some (including the Author)
+ * may prefer over the official API.
+ * <p>
+ * The following diagram illustrates the QmfEventListener Event model.
+ * <p>
+ * Notes
+ * <ol>
+ *  <li>This is provided as an alternative to the official QMF2 WorkQueue and Notifier Event model.</li>
+ *  <li>Agent and Console methods are sufficiently thread safe that it is possible to call them from a callback fired
+ *      from the onEvent() method that may have been called from the JMS MessageListener. Internally the synchronous
+ *      and asynchronous calls are processed on different JMS Sessions to facilitate this</li>
+ * </ol>
+ * <p>
+ * <img src="doc-files/QmfEventListenerModel.png"/>
+ * 
+ * @author Fraser Adams
+ */
+public interface QmfEventListener extends QmfCallback
+{
+    /**
+     * Passes a WorkItem to the listener. 
+     *
+     * @param item the WorkItem passed to the listener
+     */
+    public void onEvent(WorkItem item);
+}

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEventListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEventListener.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfException.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfException.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfException.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfException.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,42 @@
+/*
+ *
+ * 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.qmf2.common;
+
+/**
+ * A QmfException object 
+ * 
+ * @author Fraser Adams
+ */
+public class QmfException extends Exception
+{
+    private static final long serialVersionUID = 7526471155622776147L;
+
+    /**
+     * Create a QmfException with a given message String.
+     * @param message the message String.
+     */
+    public QmfException(String message)
+    {
+        super(message);
+    }
+}
+
+

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfManaged.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfManaged.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfManaged.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfManaged.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,83 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.Map;
+
+/**
+ * Subclass of QmfDescribed, which is itself a subclass of QmfData.
+ * <p>
+ * When representing managed data, a QmfData instance is assigned an object identifier 
+ *
+ * @author Fraser Adams
+ */
+public class QmfManaged extends QmfDescribed
+{
+    private ObjectId _object_id;
+
+    /**
+     * The default constructor, initialises the underlying QmfData base class with an empty Map
+     */
+    protected QmfManaged()
+    {
+    }
+
+    /**
+     * The main constructor, taking a java.util.Map as a parameter. In essence it "deserialises" its state from the Map.
+     *
+     * @param m the map used to construct the QmfManaged
+     */
+    public QmfManaged(final Map m)
+    {
+        super(m);
+        _object_id = (m == null) ? null : new ObjectId((Map)m.get("_object_id"));
+    }
+
+    /**
+     * Returns the ObjectId of this managed object.
+     * @return the ObjectId of this managed object.
+     */
+    public final ObjectId getObjectId()
+    {
+        return _object_id;
+    }
+
+    /**
+     * Sets the ObjectId of this managed object.
+     * @param object_id the ObjectId of this managed object.
+     */
+    public final void setObjectId(final ObjectId object_id)
+    {
+        _object_id = object_id;
+    }
+
+    /**
+     * Helper/debug method to list the QMF Object properties and their type.
+     */
+    @Override
+    public void listValues()
+    {
+        super.listValues();
+        System.out.println("_object_id: " + getObjectId());
+    }
+}
+

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfManaged.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfManaged.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQuery.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQuery.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQuery.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQuery.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,343 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+// Reuse this class as it provides a handy mechanism to parse an predicate String into a Map
+import org.apache.qpid.messaging.util.AddressParser;
+
+/**
+ * A Query is a mechanism for interrogating the management database. A Query represents a selector which is sent to
+ * an Agent. The Agent applies the Query against its management database, and returns those objects which meet the  
+ * constraints described in the query.
+ * <p>
+ * A Query must specify the class of information it is selecting. This class of information is considered the target
+ * of the query. Any data objects selected by the query will be of the type indicated by the target.
+ * <p>
+ * A Query may also specify a selector which is used as a filter against the set of all target instances. Only those 
+ * instances accepted by the filter will be returned in response to the query.
+ * <p>
+ * N.B. There appear to be a number of differences in the description of the map encoding of a Query between the
+ * QMF2 API specified at <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a> and the
+ * QMF2 protocol that is specified at <a href=https://cwiki.apache.org/qpid/qmf-map-message-protocol.html>QMF Map
+ * Message Protocol</a> in particular the use of the underscore to specify key names e.g. "_what", "_where",
+ * "_object_id", "_schema_id".
+ * <p>
+ * This implementation trusts the protocol specification more than the API specification as the underscores are more  
+ * consistent with the rest of the protocol and the underscored variants are what have been observed when querying
+ * the broker ManagementAgent.
+ * <p>
+ * A QmfQuery may be constructed as either an "ID" query (to query for a specific ObjectId or SchemaClassId) or a
+ * "PREDICATE" query (to query based upon an expression). Note that QMF considers string arguments in boolean
+ * expressions to be names of data values in the target object. When evaluating a predicate expression, QMF will fetch
+ * the value of the named data item from each candidate target object. The value is then used in the boolean expression.
+ * In other words, QMF considers string arguments to be variables in the expression. In order to indicate that a string 
+ * should be treated as a literal instead, the string must be quoted using the "quote" expression.
+ * <p>
+ * <b>Examples</b>
+ * <p>
+ * Assume a QmfData type defines fields named "name", "address" and "town". The following predicate expression matches
+ * any instance with a name field set to "tross", or any instance where the name field is "jross", the address field is
+ * "1313 Spudboy Lane" and the town field is "Utopia":
+ * <p>
+ * <pre>
+ * ["or" ["eq" "name" ["quote" "tross"]]
+ *       ["and" ["eq" "name" ["quote" "jross"]]
+ *              ["eq" "address" ["quote" "1313 Spudboy Lane"]]
+ *              ["eq" ["quote" "Utopia"] "town"]
+ *     ]
+ * ]
+ * </pre>
+ * Assume a QmfData type with fields "name" and "age". A predicate to find all instances with name matching the regular 
+ * expression "?ross" with an optional age field that is greater than the value 29 or less than 12 would be:
+ * <pre>
+ * ["and" ["re_match" "name" ["quote" "?ross"]]
+ *        ["and" ["exists" "age"]
+ *               ["or" ["gt" "age" 27] ["lt" "age" 12]]
+ *        ]
+ * ]
+ * </pre>
+ * <p>
+ * The Expression structure is illustrated below in the context of its relationship with QmfQuery. 
+ * <img src="doc-files/QmfQuery.png"/>
+ *
+ *
+ * @author Fraser Adams
+ */
+public final class QmfQuery extends QmfData
+{
+    public static final QmfQuery ID = new QmfQuery();
+    public static final QmfQuery PREDICATE = new QmfQuery();
+
+    private QmfQueryTarget _target;
+    private SchemaClassId  _classId;
+    private String         _packageName;
+    private String         _className;
+    private ObjectId       _objectId;
+    private List           _predicate;
+    private Expression     _expression;
+
+    /**
+     * This Constructor is only used to construct the ID and PREDICATE objects
+     */
+    private QmfQuery()
+    {
+    }
+
+    /**
+     * Construct an QmfQuery with no Selector from a QmfQueryTarget
+     * @param target the query target
+     */
+    public QmfQuery(final QmfQueryTarget target)
+    {
+        _target = target;
+        setValue("_what", _target.toString());
+    }
+
+    /**
+     * Construct an ID QmfQuery from a QmfQueryTarget and SchemaClassId
+     * @param target the query target
+     * @param classId the SchemaClassId to evaluate against
+     */
+    public QmfQuery(final QmfQueryTarget target, final SchemaClassId classId)
+    {
+        _target = target;
+        _classId = classId;
+        _packageName = _classId.getPackageName();
+        _className = _classId.getClassName();
+        setValue("_what", _target.toString());
+        setValue("_schema_id", _classId.mapEncode());
+    }
+
+    /**
+     * Construct an ID QmfQuery from a QmfQueryTarget and ObjectId
+     * @param target the query target
+     * @param objectId the ObjectId to evaluate against
+     */
+    public QmfQuery(final QmfQueryTarget target, final ObjectId objectId)
+    {
+        _target = target;
+        _objectId = objectId;
+        setValue("_what", _target.toString());
+        setValue("_object_id", _objectId.mapEncode());
+    }
+
+    /**
+     * Construct a PREDICATE QmfQuery from a QmfQueryTarget and predicate String
+     * @param target the query target
+     * @param predicateString the predicate to evaluate against
+     */
+    public QmfQuery(final QmfQueryTarget target, final String predicateString) throws QmfException
+    {
+        _target = target;
+
+        if (predicateString.charAt(0) == '[')
+        {
+            Map predicateMap = new AddressParser("{'_where': " + predicateString + "}").map();
+            _predicate = (List)predicateMap.get("_where");
+            _expression = Expression.createExpression(_predicate);
+        }
+        else
+        {
+            throw new QmfException("Invalid predicate format");
+        }
+
+        setValue("_what", _target.toString());
+        setValue("_where", _predicate);
+    }
+
+    /**
+     * Construct a QmfQuery from a Map encoding
+     * @param m encoding the query
+     */
+    public QmfQuery(final Map m) throws QmfException
+    {
+        super(m);
+
+        _target = QmfQueryTarget.valueOf(getStringValue("_what"));
+
+        if (hasValue("_object_id"))
+        {
+            _objectId = getRefValue("_object_id");
+        }
+
+        if (hasValue("_schema_id"))
+        {
+            _classId = new SchemaClassId((Map)getValue("_schema_id"));
+            _packageName = _classId.getPackageName();
+            _className = _classId.getClassName();
+        }
+
+        if (hasValue("_where"))
+        {
+            _predicate = (List)getValue("_where");
+            _expression = Expression.createExpression(_predicate);
+        }
+    }
+
+    /**
+     * Return target name.
+     * @return target name.
+     */
+    public QmfQueryTarget getTarget()
+    {
+        return _target;
+    }
+
+    /**
+     * Undefined by QMF2 API.
+     * <p>
+     * According to <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Specification</a>
+     * "The value of the <target name string> map entry is ignored for now, its use is TBD."
+     * so this method returns a null Map.
+     */
+    public Map getTargetParam()
+    {
+        return null;
+    }
+
+    /**
+     * Return QmfQuery.ID or QmfQuery.PREDICATE or null if there is no Selector
+     * @return QmfQuery.ID or QmfQuery.PREDICATE or null if there is no Selector
+     */
+    public QmfQuery getSelector()
+    {
+        if (_predicate == null)
+        {
+            if (_objectId == null && _classId == null)
+            {
+                return null;
+            }
+            return ID;
+        }
+        return PREDICATE;
+    }
+
+    /**
+     * Return predicate expression if selector type is QmfQuery.PREDICATE
+     * @return predicate expression if selector type is QmfQuery.PREDICATE
+     */
+    public List getPredicate()
+    {
+        return _predicate;
+    }
+
+    /**
+     * Return the SchemaClassId if selector type is QmfQuery.ID
+     * @return the SchemaClassId if selector type is QmfQuery.ID
+     */
+    public SchemaClassId getSchemaClassId()
+    {
+        return _classId;
+    }
+
+    /**
+     * Return the ObjectId if selector type is QmfQuery.ID
+     * @return the ObjectId if selector type is QmfQuery.ID
+     */
+    public ObjectId getObjectId()
+    {
+        return _objectId;
+    }
+
+    /**
+     * Evaluate query against a QmfData instance.
+     * @return true if query matches the QmfData instance, else false.
+     */
+    public boolean evaluate(final QmfData data)
+    {
+        if (_predicate == null)
+        {
+            if (data instanceof QmfManaged)
+            {
+                QmfManaged managedData = (QmfManaged)data;
+                // Evaluate an ID query on Managed Data
+                if (_objectId != null && _objectId.equals(managedData.getObjectId()))
+                {
+                    return true;
+                }
+                else if (_classId != null)
+                {
+                    SchemaClassId dataClassId = managedData.getSchemaClassId();
+                    String dataClassName = dataClassId.getClassName();
+                    String dataPackageName = dataClassId.getPackageName();
+
+                    // Wildcard the package name if it hasn't been specified when checking class name
+                    if (_className.equals(dataClassName) &&
+                        (_packageName.length() == 0 || _packageName.equals(dataPackageName)))
+                    {
+                        return true;
+                    }
+
+                    // Wildcard the class name if it hasn't been specified when checking package name
+                    if (_packageName.equals(dataPackageName) &&
+                        (_className.length() == 0 || _className.equals(dataClassName)))
+                    {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+        else
+        {
+            // Evaluate a PREDICATE query by evaluating against the expression created from the predicate
+            if (_predicate.size() == 0)
+            {
+                return true;
+            }
+
+            return _expression.evaluate(data);
+        }
+    }
+
+    /**
+     * Helper/debug method to list the QMF Object properties and their type.
+     */
+    @Override
+    public void listValues()
+    {
+        System.out.println("QmfQuery:");
+        System.out.println("target: " + _target);
+        if (_predicate != null)
+        {
+            System.out.println("selector: QmfQuery.PREDICATE");
+            System.out.println("predicate: " + _predicate);
+        }
+        else if (_classId != null)
+        {
+            System.out.println("selector: QmfQuery.ID");
+            _classId.listValues();
+        }
+        else if (_objectId != null)
+        {
+            System.out.println("selector: QmfQuery.ID");
+            System.out.println(_objectId);
+        }
+    }
+}
+

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQuery.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQueryTarget.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQueryTarget.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQueryTarget.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQueryTarget.java Mon Apr  8 15:19:04 2013
@@ -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.qmf2.common;
+
+/**
+ * An enum containing the QMF type code indicating a QMF query target defined in
+ * <a href=https://cwiki.apache.org/qpid/qmf-map-message-protocol.html>QMF Map Message Protocol</a>
+ *
+ * @author Fraser Adams
+ */
+public enum QmfQueryTarget
+{
+    SCHEMA_ID,
+    SCHEMA,
+    OBJECT_ID,
+    OBJECT;
+}
+

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQueryTarget.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQueryTarget.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfType.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfType.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfType.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfType.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,39 @@
+/*
+ *
+ * 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.qmf2.common;
+
+/**
+ * An enum containing the QMF type code indicating a QMF object's data type
+ *
+ * @author Fraser Adams
+ */
+public enum QmfType
+{
+    TYPE_VOID,
+    TYPE_BOOL,
+    TYPE_INT,
+    TYPE_FLOAT,
+    TYPE_STRING,
+    TYPE_MAP,
+    TYPE_LIST,
+    TYPE_UUID;
+}
+

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfType.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClass.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClass.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClass.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClass.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,135 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Subclass of QmfData
+ * <p>
+ * When representing formally defined data, a QmfData instance is assigned a Schema.
+ * <p>
+ * The following diagram illustrates the QMF2 Schema class hierarchy.
+ * <p>
+ * <img src="doc-files/Schema.png"/>
+ *
+ * @author Fraser Adams
+ */
+public class SchemaClass extends QmfData
+{
+    public static final SchemaClass EMPTY_SCHEMA = new SchemaClass();
+
+    private SchemaClassId _classId;
+
+    /**
+     * The default constructor, initialises the underlying QmfData base class with an empty Map
+     */
+    protected SchemaClass()
+    {
+    }
+
+    /**
+     * The main constructor, taking a java.util.Map as a parameter.
+     *
+     * @param m the map used to construct the SchemaClass
+     */
+    public SchemaClass(final Map m)
+    {
+        super(m);
+        _classId = new SchemaClassId((Map)getValue("_schema_id"));
+    }
+
+    /**
+     * Return the SchemaClassId that identifies this Schema instance.
+     * @return the SchemaClassId that identifies this Schema instance.
+     */
+    public final SchemaClassId getClassId()
+    {
+        if (_classId.getHashString() == null)
+        {
+            _classId = new SchemaClassId(_classId.getPackageName(),
+                                         _classId.getClassName(),
+                                         _classId.getType(),
+                                         generateHash());
+        }
+        return _classId;
+    }
+
+    /**
+     * Set the SchemaClassId that identifies this Schema instance.
+     * @param cid the SchemaClassId that identifies this Schema instance.
+     */
+    public final void setClassId(final SchemaClassId cid)
+    {
+        _classId = cid;
+    }
+
+    /**
+     * Return a hash generated over the body of the schema, and return a  representation of the hash
+     * @return a hash generated over the body of the schema, and return a  representation of the hash
+     */
+    public final UUID generateHash()
+    {
+        try
+        {
+            MessageDigest md5 = MessageDigest.getInstance("MD5");
+            updateHash(md5);
+            return UUID.nameUUIDFromBytes(md5.digest());
+        }
+        catch (NoSuchAlgorithmException nsae)
+        {
+        }
+        return null;
+    }
+
+    /**
+     * Generate the partial hash for the schema fields in this base class
+     * @param md5 the MessageDigest to be updated
+     */
+    protected void updateHash(MessageDigest md5)
+    {
+        try
+        {
+            md5.update(_classId.getPackageName().getBytes("UTF-8"));
+            md5.update(_classId.getClassName().getBytes("UTF-8"));
+            md5.update(_classId.getType().getBytes("UTF-8"));
+        }
+        catch (UnsupportedEncodingException uee)
+        {
+        }
+    }
+
+    /**
+     * Helper/debug method to list the QMF Object properties and their type.
+     */
+    @Override
+    public void listValues()
+    {
+        super.listValues();
+        _classId.listValues();
+    }
+}
+

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClass.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClass.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClassId.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClassId.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClassId.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClassId.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,202 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Schema are identified by a combination of their package name and class name. A hash value over the body of
+ * the schema provides a revision identifier. The class SchemaClassId represents this Schema identifier.
+ * <p>
+ * If the hash value is not supplied, then the value of the hash string will be set to None. This will be the
+ * case when a SchemaClass is being dynamically constructed, and a proper hash is not yet available.
+ *
+ * @author Fraser Adams
+ */
+public final class SchemaClassId extends QmfData
+{
+    private String _packageName = "";
+    private String _className = "";
+    private String _type = "";
+    private UUID _hash = null;
+
+    /**
+     * The main constructor, taking a java.util.Map as a parameter.
+     *
+     * @param m the map used to construct the SchemaClassId.
+     */
+    public SchemaClassId(final Map m)
+    {
+        super(m);
+        _packageName =  getStringValue("_package_name");
+        _className = getStringValue("_class_name");
+        _type = getStringValue("_type");
+        _hash = hasValue("_hash") ? (UUID)getValue("_hash") : null;
+    }
+
+    /**
+     * Construct a SchemaClassId from a given class name.
+     *
+     * @param className the class name.
+     */
+    public SchemaClassId(final String className)
+    {
+        this(null, className, null, null);
+    }
+
+    /**
+     * Construct a SchemaClassId from a given package name and class name.
+     *
+     * @param packageName the package name.
+     * @param className the class name.
+     */
+    public SchemaClassId(final String packageName, final String className)
+    {
+        this(packageName, className, null, null);
+    }
+
+    /**
+     * Construct a SchemaClassId from a given package name and class name and type (_data or _event).
+     *
+     * @param packageName the package name.
+     * @param className the class name.
+     * @param type the schema type (_data or _event).
+     */
+    public SchemaClassId(final String packageName, final String className, final String type)
+    {
+        this(packageName, className, type, null);
+    }
+
+    /**
+     * Construct a SchemaClassId from a given package name and class name, type (_data or _event) and hash.
+     *
+     * @param packageName the package name.
+     * @param className the class name.
+     * @param type the schema type (_data or _event).
+     * @param hash a UUID representation of the md5 hash of the Schema,
+     */
+    public SchemaClassId(final String packageName, final String className, final String type, final UUID hash)
+    {
+        if (packageName != null)
+        {
+            setValue("_package_name", packageName);
+            _packageName = packageName;
+        }
+
+        if (className != null)
+        {
+            setValue("_class_name", className);
+            _className = className;
+        }
+
+        if (type != null)
+        {
+            setValue("_type", type);
+            _type = type;
+        }
+
+        if (hash != null)
+        {
+            setValue("_hash", hash);
+            _hash = hash;
+        }
+    }
+
+    /**
+     * Return The name of the associated package.
+     * @return The name of the associated package. Returns empty String if there's no package name.
+     */
+    public String getPackageName()
+    {
+        return _packageName;
+    }
+
+    /**
+     * Return The name of the class within the package.
+     * @return The name of the class within the package. Returns empty String if there's no class name.
+     */
+    public String getClassName()
+    {
+        return _className;
+    }
+
+    /**
+     * Return The type of schema, either "_data" or "_event".
+     * @return The type of schema, either "_data" or "_event". Returns empty String if type is unknown.
+     */
+    public String getType()
+    {
+        return _type;
+    }
+
+    /**
+     * Return The MD5 hash of the schema.
+     * @return The MD5 hash of the schema, in the format "%08x-%08x-%08x-%08x"
+     */
+    public UUID getHashString()
+    {
+        return _hash;
+    }
+
+    /**
+     * Compares two SchemaClassId objects for equality.
+     * @param rhs the right hands side SchemaClassId in the comparison.
+     * @return true if the two SchemaClassId objects are equal otherwise returns false.
+     */
+    @Override
+    public boolean equals(final Object rhs)
+    {
+        if (rhs instanceof SchemaClassId)
+        {
+            SchemaClassId that = (SchemaClassId)rhs;
+            String lvalue = _packageName + _className + _hash;
+            String rvalue = that._packageName + that._className + that._hash;
+            return lvalue.equals(rvalue);
+        }
+        return false;
+    }
+
+    /**
+     * Returns the SchemaClassId hashCode.
+     * @return the SchemaClassId hashCode.
+     */
+    @Override
+    public int hashCode()
+    {
+        String lvalue = _packageName + _className + _hash;
+        return lvalue.hashCode();
+    }
+
+    /**
+     * Helper/debug method to list the QMF Object properties and their type.
+     */
+    @Override
+    public void listValues()
+    {
+        System.out.println("_package_name: " + getPackageName());
+        System.out.println("_class_name: " + getClassName());
+        System.out.println("_type: " + getType());
+        System.out.println("_hash: " + getHashString());
+    }
+}
+

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClassId.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClassId.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaEventClass.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaEventClass.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaEventClass.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaEventClass.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,266 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.security.MessageDigest;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Subclass of SchemaClass
+ * <p>
+ * Agent applications may dynamically construct instances of these objects by adding properties at run
+ * time. However, once the Schema is made public, it must be considered immutable, as the hash value
+ * must be constant once the Schema is in use.
+ * <p>
+ * Note that <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a> suggests that the
+ * properties are represented by an unordered map of SchemaProperty entries indexed by property name, however
+ * these are actually represented in the QMF2 protocol as a "List of SCHEMA_PROPERTY elements that describe the
+ * schema event's properties.
+ * <p>
+ * In this implementation getProperties() returns a List<SchemaProperty> reflecting the reality of the protocol
+ * rather than what is suggested by the API documentation.
+ *
+ * @author Fraser Adams
+ */
+public final class SchemaEventClass extends SchemaClass
+{
+    private List<SchemaProperty> _properties = new ArrayList<SchemaProperty>();
+
+    /**
+     * The main constructor, taking a java.util.Map as a parameter.
+     *
+     * @param m the map used to construct the SchemaEventClass
+     */
+    public SchemaEventClass(final Map m)
+    {
+       super(m);
+        if (m != null)
+        {
+            List<Map> mapEncodedProperties = this.<List<Map>>getValue("_properties");
+            if (mapEncodedProperties != null)
+            { // In theory this shouldn't be null as "_properties" property of SchemaClass is not optional but.....
+                for (Map property : mapEncodedProperties)
+                {
+                    addProperty(new SchemaProperty(property));
+                }
+            }
+        }
+    }
+
+    /**
+     * Construct a SchemaEventClass from a package name and a class name.
+     *
+     * @param packageName the package name.
+     * @param className the class name.
+     */
+    public SchemaEventClass(final String packageName, final String className)
+    {
+        setClassId(new SchemaClassId(packageName, className, "_event"));
+    }
+
+    /**
+     * Construct a SchemaEventClass from a SchemaClassId.
+     *
+     * @param classId the SchemaClassId identifying this Schema.
+     */
+    public SchemaEventClass(final SchemaClassId classId)
+    {
+        setClassId(new SchemaClassId(classId.getPackageName(), classId.getClassName(), "_event"));
+    }
+
+    /**
+     * Return optional default severity of this Property.
+     * @return optional default severity of this Property.
+     */
+    public long getDefaultSeverity()
+    {
+        return getLongValue("_default_severity");
+    }
+
+    /**
+     * Set the default severity of this Schema Event
+     *
+     * @param severity optional severity of this Schema Event.
+     */
+    public void setDefaultSeverity(final int severity)
+    {
+        setValue("_default_severity", severity);
+    }
+
+    /**
+     * Return optional string description of this Schema Event.
+     * @return optional string description of this Schema Event.
+     */
+    public String getDesc()
+    {
+        return getStringValue("_desc");
+    }
+
+    /**
+     * Set the optional string description of this Schema Object.
+     *
+     * @param description optional string description of this Schema Object.
+     */
+    public void setDesc(final String description)
+    {
+        setValue("_desc", description);
+    }
+
+    /**
+     * Return the count of SchemaProperties in this instance.
+     * @return the count of SchemaProperties in this instance.
+     */
+    public long getPropertyCount()
+    {
+        return getProperties().size();
+    }
+
+    /**
+     * Return Schema Object's properties.
+     * <p>
+     * Note that <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a> suggests that
+     * the properties are represented by an unordered map of SchemaProperty indexed by property name however it
+     * is actually represented in the QMF2 protocol as a "List of SCHEMA_PROPERTY elements that describe the
+     * schema objects's properties. In this implementation getProperties() returns a List<SchemaProperty> 
+     * reflecting the reality of the protocol rather than what is suggested by the API documentation.
+     *
+     * @return Schema Object's properties.
+     */
+    public List<SchemaProperty> getProperties()
+    {
+        return _properties;
+    }
+
+    /**
+     * Return the SchemaProperty for the parameter "name".
+     * @param name the name of the SchemaProperty to return.
+     * @return the SchemaProperty for the parameter "name".
+     */
+    public SchemaProperty getProperty(final String name)
+    {
+        for (SchemaProperty p : _properties)
+        {
+            if (p.getName().equals(name))
+            {
+                return p;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Return the SchemaProperty for the index i.
+     * @param i the index of the SchemaProperty to return.
+     * @return the SchemaProperty for the index i.
+     */
+    public SchemaProperty getProperty(final int i)
+    {
+        return _properties.get(i);
+    }
+
+    /**
+     * Add a new Property.
+     *
+     * @param name the name of the SchemaProperty 
+     * @param value the SchemaProperty associated with "name"
+     */
+    public void addProperty(final String name, final SchemaProperty value)
+    {
+        value.setValue("_name", name);
+        _properties.add(value);
+    }
+
+    /**
+     * Add a new Property.
+     *
+     * @param value the SchemaProperty associated with "name"
+     */
+    public void addProperty(final SchemaProperty value)
+    {
+        _properties.add(value);
+    }
+
+
+    /**
+     * Helper/debug method to list the QMF Object properties and their type.
+     */
+    @Override
+    public void listValues()
+    {
+        System.out.println("SchemaEventClass:");
+        getClassId().listValues();
+
+        if (hasValue("_desc")) System.out.println("desc: " + getDesc());
+        if (hasValue("_default_severity")) System.out.println("default severity: " + getDefaultSeverity());
+
+        if (getPropertyCount() > 0)
+        {
+            System.out.println("properties:");
+        }
+        for (SchemaProperty p : _properties)
+        {
+            p.listValues();
+        }
+    }
+
+    /**
+     * Return the underlying map. 
+     * <p>
+     * We need to convert any properties from SchemaProperty to Map.
+     *
+     * @return the underlying map. 
+     */
+    @Override
+    public Map<String, Object> mapEncode()
+    {
+        // I think a "_methods" property is mandatory for a SchemaClass even if it's empty
+        setValue("_methods", Collections.EMPTY_LIST);
+        List<Map> mapEncodedProperties = new ArrayList<Map>();
+        for (SchemaProperty p : _properties)
+        {
+            mapEncodedProperties.add(p.mapEncode());
+        }
+        setValue("_properties", mapEncodedProperties);
+        setValue("_schema_id", getClassId().mapEncode());
+        return super.mapEncode();
+    }
+
+    /**
+     * Generate the partial hash for the schema fields in this class.
+     * @param md5 the MessageDigest to be updated.
+     */
+    @Override
+    protected void updateHash(MessageDigest md5)
+    {
+        super.updateHash(md5);
+
+        for (SchemaProperty p : _properties)
+        {
+            p.updateHash(md5);
+        }
+    }
+}
+

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaEventClass.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaEventClass.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaMethod.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaMethod.java?rev=1465662&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaMethod.java (added)
+++ qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaMethod.java Mon Apr  8 15:19:04 2013
@@ -0,0 +1,275 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The SchemaMethod class describes a method call's parameter list.
+ * <p>
+ * Note that <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a> suggests that
+ * the parameter list is represented by an unordered map of SchemaProperty entries indexed by parameter name,
+ * however is is actually represented in the QMF2 protocol as a "List of SCHEMA_PROPERTY elements that describe
+ * the method's arguments". 
+ * <p>
+ * In this implementation getArguments() returns a List<SchemaProperty> reflecting the reality of the protocol
+ * rather than what is suggested by the API documentation.
+ *
+ * @author Fraser Adams
+ */
+public final class SchemaMethod extends QmfData
+{
+    private List<SchemaProperty> _arguments = new ArrayList<SchemaProperty>();
+
+    /**
+     * The main constructor, taking a java.util.Map as a parameter.
+     *
+     * @param m the map used to construct the SchemaMethod.
+     */
+    public SchemaMethod(final Map m)
+    {
+        super(m);
+        if (m != null)
+        {
+            List<Map> mapEncodedArguments = this.<List<Map>>getValue("_arguments");
+            if (mapEncodedArguments != null)
+            { // In theory this shouldn't be null as "_arguments" property of SchemaMethod is not optional but.....
+                for (Map argument : mapEncodedArguments)
+                {
+                    addArgument(new SchemaProperty(argument));
+                }
+            }
+        }
+    }
+
+    /**
+     * Construct a SchemaMethod from its name.
+     *
+     * @param name the name of the SchemaMethod.
+     */
+    public SchemaMethod(final String name)
+    {
+        this(name, null);
+    }
+
+    /**
+     * Construct a SchemaMethod from its name and description.
+     *
+     * @param name the name of the SchemaMethod.
+     * @param description a description of the SchemaMethod.
+     */
+    public SchemaMethod(final String name, final String description)
+    {
+        setValue("_name", name);
+
+        if (description != null)
+        {
+            setValue("_desc", description);
+        }
+    }
+
+    /**
+     * Construct a SchemaMethod from a map of "name":<SchemaProperty> entries and description.
+     *
+     * Note this Constructor is the one given in the QMF2 API specification at
+     * <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a>Note too that this method does not
+     * set a name so setName() needs to be called explicitly by clients after construction.
+     *
+     * @param args a Map of "name":<SchemaProperty> entries.
+     * @param description a description of the SchemaMethod.
+     */
+    public SchemaMethod(final Map<String, SchemaProperty> args, final String description)
+    {
+        if (description != null)
+        {
+            setValue("_desc", description);
+        }
+
+        for (Map.Entry<String, SchemaProperty> entry : args.entrySet())
+        {
+            addArgument(entry.getKey(), entry.getValue());
+        }
+    }
+
+    /**
+     * Return the method's name.
+     * @return the method's name.
+     */
+    public String getName()
+    {
+        return getStringValue("_name");
+    }
+
+    /**
+     * Sets the method's name.
+     * @param name the method's name.
+     */
+    public void setName(final String name)
+    {
+        setValue("_name", name);
+    }
+
+    /**
+     * Return a description of the method.
+     * @return a description of the method.
+     */
+    public String getDesc()
+    {
+        return getStringValue("_desc");
+    }
+
+    /**
+     * Return the number of arguments for this method.
+     * @return the number of arguments for this method.
+     */
+    public int getArgumentCount()
+    {
+        return getArguments().size();
+    }
+
+    /**
+     * Return the Method's arguments.
+     *<p>
+     * <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a> suggests that
+     * the parameter list is represented by an unordered map of SchemaProperty entries indexed by parameter name,
+     * however is is actually represented in the QMF2 protocol as a "List of SCHEMA_PROPERTY elements that describe
+     * the method's arguments". In this implementation getArguments() returns a List<SchemaProperty> reflecting the
+     * reality of the protocol rather than what is suggested by the API documentation.
+     *
+     * @return the Method's arguments.
+     */
+    public List<SchemaProperty> getArguments()
+    {
+        return _arguments;
+    }
+
+    /**
+     * Return the argument with the name "name" as a SchemaProperty.
+     * @param name the name of the SchemaProperty to return.
+     * @return the argument with the name "name" as a SchemaProperty.
+     */
+    public SchemaProperty getArgument(final String name)
+    {
+        for (SchemaProperty p : _arguments)
+        {
+            if (p.getName().equals(name))
+            {
+                return p;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Return the argument for the index i as a SchemaProperty.
+     * @param i the index of the SchemaProperty to return.
+     * @return the argument for the index i as a SchemaProperty.
+     */
+    public SchemaProperty getArgument(final int i)
+    {
+        return _arguments.get(i);
+    }
+
+    /**
+     * Add a new method argument.
+     *
+     * @param name the name of the SchemaProperty.
+     * @param value the SchemaProperty to add.
+     */
+    public void addArgument(final String name, final SchemaProperty value)
+    {
+        value.setValue("_name", name);
+        _arguments.add(value);
+    }
+
+    /**
+     * Add a new method argument.
+     *
+     * @param value the SchemaProperty to add.
+     */
+    public void addArgument(final SchemaProperty value)
+    {
+        _arguments.add(value);
+    }
+
+    /**
+     * Return the underlying map. 
+     *
+     * @return the underlying map. 
+     */
+    @Override
+    public Map<String, Object> mapEncode()
+    {
+        List<Map> args = new ArrayList<Map>();
+        for (SchemaProperty p : _arguments)
+        {
+            args.add(p.mapEncode());
+        }
+        setValue("_arguments", args);
+
+        return super.mapEncode();
+    }
+
+    /**
+     * Generate the partial hash for the schema fields in this class.
+     * @param md5 the MessageDigest to be updated.
+     */
+    protected void updateHash(MessageDigest md5)
+    {
+        try
+        {
+            md5.update(getName().getBytes("UTF-8"));
+            md5.update(getDesc().toString().getBytes("UTF-8"));
+        }
+        catch (UnsupportedEncodingException uee)
+        {
+        }
+        for (SchemaProperty p : _arguments)
+        {
+            p.updateHash(md5);
+        }
+    }
+
+    /**
+     * Helper/debug method to list the QMF Object properties and their type.
+     */
+    @Override
+    public void listValues()
+    {
+        System.out.println("SchemaMethod:");
+        System.out.println("_name: " + getName());
+        if (hasValue("_desc")) System.out.println("_desc: " + getDesc());
+        if (getArgumentCount() > 0)
+        {
+            System.out.println("_arguments:");
+        }
+        for (SchemaProperty p : _arguments)
+        {
+            p.listValues();
+        }
+    }
+}
+

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaMethod.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaMethod.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org