Author: arnaudsimon
Date: Mon Oct 13 02:06:40 2008
New Revision: 703978

URL: http://svn.apache.org/viewvc?rev=703978&view=rev
Log:
qpid-1284: on behalf Adnrea (lnew classes atest posted patch)

Added:
    incubator/qpid/trunk/qpid/java/management/client/src/main/java/log4j.xml
    
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/IMethodInvocationListener.java
    
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InvocationResult.java
    
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/InvocationEvent.java
    
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/MethodInvocationException.java
    
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/SequenceNumberGenerator.java
    
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/UnableToComplyException.java
    
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/
    
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/AmqpCoDec.java
    
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/ManagementMessage.java
    
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/MethodInvocationRequestMessage.java
    
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/SchemaRequestMessage.java

Added: incubator/qpid/trunk/qpid/java/management/client/src/main/java/log4j.xml
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/main/java/log4j.xml?rev=703978&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/management/client/src/main/java/log4j.xml 
(added)
+++ incubator/qpid/trunk/qpid/java/management/client/src/main/java/log4j.xml 
Mon Oct 13 02:06:40 2008
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"; 
debug="false">
+  <appender name="console" class="org.apache.log4j.ConsoleAppender">
+       <layout class="org.apache.log4j.PatternLayout">
+         <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+      </layout>
+  </appender>
+  <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
+      <param name="File" value="C:\\tmp\\qman.log"/>
+      <layout class="org.apache.log4j.PatternLayout">
+         <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+      </layout>
+   </appender>
+       <category name="org.apache.qpid.management.domain.model.QpidClass">
+               <priority value="DEBUG"/>
+       </category>     
+       <category name="org.apache.qpid.management">
+               <priority value="INFO"/>
+       </category>     
+   <root>
+       <priority value="ERROR"/>
+          <appender-ref ref="console"/>
+   </root>
+</log4j:configuration>
\ No newline at end of file

Added: 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/IMethodInvocationListener.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/IMethodInvocationListener.java?rev=703978&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/IMethodInvocationListener.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/IMethodInvocationListener.java
 Mon Oct 13 02:06:40 2008
@@ -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.
+ *
+ */
+package org.apache.qpid.management.domain.handler.impl;
+
+import java.util.EventListener;
+
+import org.apache.qpid.management.domain.model.InvocationEvent;
+
+/**
+ * Listener interface used to denote a component interested in method 
invocation events.
+ * 
+ * @author Andrea Gazzarini
+ */
+public interface IMethodInvocationListener extends EventListener
+{
+    /**
+     * An operation is going to be invoked on a specific object instance.
+     * This lets this listener to be informed about the imminent invocation.
+     * 
+     * @param event the invocation event.
+     */
+    void operationIsGoingToBeInvoked(InvocationEvent event);
+}
\ No newline at end of file

Added: 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InvocationResult.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InvocationResult.java?rev=703978&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InvocationResult.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/handler/impl/InvocationResult.java
 Mon Oct 13 02:06:40 2008
@@ -0,0 +1,157 @@
+/*
+ *
+ * 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.management.domain.handler.impl;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.qpid.management.domain.services.MethodInvocationException;
+
+/**
+ * Value object used for storing an invocation method result.
+ * This is done in order to accomplish multiple return value requirement. 
+ * As we know, it's not possible to do that only with method signature and 
therefore this value object / struct is used.
+ * 
+ * @author Andrea Gazzarini
+ */
+public class InvocationResult implements Serializable
+{
+    private static final long serialVersionUID = 2062662997326399693L;
+    
+    private final long _returnCode;
+    private final String _statusText;
+    private final byte [] _outputAndBidirectionalArgumentValues;
+    private Map<String, Object> _outputSection;
+    
+    /**
+     * Builds an invocation result with the given status code and status text.
+     * 
+     * @param statusCode the status code.
+     * @param statusText the status text.
+     */
+    InvocationResult(long statusCode, String statusText,byte [] 
outputAndBidirectionalArgumentValues)
+    {
+        this._returnCode = statusCode;
+        this._statusText = statusText;
+        this._outputAndBidirectionalArgumentValues = 
outputAndBidirectionalArgumentValues;
+    }
+    
+    /**
+     * Checks if this result contains an error return code.
+     *  
+     * @return true if this result object contains an error return code.
+     */
+    public boolean isException () 
+    {
+        return _returnCode != 0;
+    }
+    
+    /**
+     * Simply throws a new MethodInvocationException.
+     * Usually this method is called in conjunction with the isException() 
method in order to raise an exception if 
+     * the wrapped return code means that there was an error.
+     * 
+     * @throws MethodInvocationException always.
+     */
+    public void createAndThrowException() throws MethodInvocationException
+    {
+        throw new MethodInvocationException(_returnCode, _statusText);
+    }
+    
+    @Override
+    public String toString ()
+    {
+        StringBuilder builder = new StringBuilder()
+            .append("Status code : ")
+            .append(_returnCode)
+            .append(",")
+            .append("Status Text : ")
+            .append(_statusText);
+        if (_outputSection != null && !_outputSection.isEmpty())
+        {
+            builder.append(". Parameters : ");
+            for (Entry<String, Object> outputEntry : _outputSection.entrySet())
+            {
+                
builder.append(outputEntry.getKey()).append('=').append(outputEntry.getValue());
+                builder.append(',');
+            }
+        }            
+        return builder.toString();
+    }
+
+    /**
+     * Returns the return code of this invocation result.
+     * 
+     * @return the return code of this invocation result.
+     */
+    public long getReturnCode ()
+    {
+        return _returnCode;
+    }
+
+    /**
+     * Contains the status text of this invocation result.
+     * 
+     * @return the status text of this invocation result.
+     */
+    public String getStatusText ()
+    {
+        return _statusText;
+    }
+    
+    /**
+     * Returns the output and bidirectional argument values in raw format 
(byte [])
+     * 
+     * @return the output and bidirectional argument values in raw format 
(byte [])
+     */
+    public byte [] getOutputAndBidirectionalArgumentValues()
+    {
+        return _outputAndBidirectionalArgumentValues;
+    }
+
+    /**
+     * Sets the output section (decoded) of this invocation result.
+     * When an incoming message arrives, the output section (output and 
bidirectional argument values) are 
+     * initially stored in raw format.
+     * After that, their values need to be converted. 
+     * The final result is a map containing (for each Output or Input/Output 
parameter) the name of the argument as key 
+     * and its value as value. 
+     * 
+     * @param output a map containing outptu and bidirectional values (not in 
schema order). 
+     */
+    public void setOutputSection (Map<String, Object> outputSection)
+    {
+        this._outputSection = outputSection;
+    }
+    
+    /**
+     * Returns the output section of this invocation result. 
+     * The output section consists in output and bidirectional argument values.
+     * Note that the order of the arguments is not guaranteed.
+     * 
+     * @param outputSection the output section of this invocation result;
+     */
+    public Map<String, Object> getOutputSection ()
+    {
+        return _outputSection;
+    }    
+}
\ No newline at end of file

Added: 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/InvocationEvent.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/InvocationEvent.java?rev=703978&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/InvocationEvent.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/InvocationEvent.java
 Mon Oct 13 02:06:40 2008
@@ -0,0 +1,76 @@
+/*
+ *
+ * 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.management.domain.model;
+
+import java.util.EventObject;
+import java.util.concurrent.BlockingQueue;
+
+import org.apache.qpid.management.domain.handler.impl.InvocationResult;
+
+/**
+ * Operation invocation event. 
+ * This encapsulates all the information that a method invocation listener 
needs to know about an operation which is 
+ * going to be invoked.
+ * 
+ * @author Andrea Gazzarini
+ */
+public class InvocationEvent extends EventObject
+{
+    private static final long serialVersionUID = 240229490753008597L;
+
+    private final int _sequenceNumber;
+    private final BlockingQueue<InvocationResult> _exchangeChannel;
+    
+    /**
+     * Builds a new invocation event with the given data.
+     * 
+     * @param source the event source.
+     * @param sequenceNumber the sequence number of the method invocation.
+     * @param exchangeChannel the exchange channel for synchronous 
communication.
+     */
+    InvocationEvent(Object source, int sequenceNumber, 
BlockingQueue<InvocationResult> exchangeChannel)
+    {
+        super(source);
+        this._sequenceNumber = sequenceNumber;
+        this._exchangeChannel = exchangeChannel;
+    }
+    
+    /**
+     * Returns the sequence number that will be / has been used for method 
invocation.
+     * 
+     * @return the sequence number that will be / has been used for method 
invocation.
+     */
+    public int getSequenceNumber() 
+    {
+        return _sequenceNumber;
+    }
+    
+    /**
+     * Returns the exchange channel that will be used between event source and 
event listener for synchronous 
+     * communication.
+     * 
+     * @return the exchange channel that will be used for synchronous 
communication.
+     */
+    public BlockingQueue<InvocationResult> getExchangeChannel()
+    {
+        return _exchangeChannel;
+    }
+}
\ No newline at end of file

Added: 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/MethodInvocationException.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/MethodInvocationException.java?rev=703978&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/MethodInvocationException.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/MethodInvocationException.java
 Mon Oct 13 02:06:40 2008
@@ -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.management.domain.services;
+
+public class MethodInvocationException extends Exception
+{
+    private static final long serialVersionUID = -7772343434879470351L;
+    private final long _returnCode;
+    private final String _statusText;
+    
+    public MethodInvocationException(long code, String text)
+    {    
+        this._returnCode = code;
+        this._statusText = text;
+    }
+    
+    @Override
+    public String getMessage ()
+    {
+        return String.format("Return code : \"%s, reason : 
\"%s\"",_returnCode,_statusText);
+    }
+    
+    public long getReturnCode ()
+    {
+        return _returnCode;
+    }
+
+    public String getStatusText ()
+    {
+        return _statusText;
+    }
+}
\ No newline at end of file

Added: 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/SequenceNumberGenerator.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/SequenceNumberGenerator.java?rev=703978&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/SequenceNumberGenerator.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/SequenceNumberGenerator.java
 Mon Oct 13 02:06:40 2008
@@ -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.management.domain.services;
+
+/**
+ * Sequence number generator utility class.
+ * 
+ * @author Andrea Gazzarini
+ */
+public class SequenceNumberGenerator
+{
+    private static int sequenceNumber;
+    
+    public static synchronized int getNextSequenceNumber()
+    {
+        return sequenceNumber++;
+    }
+}
\ No newline at end of file

Added: 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/UnableToComplyException.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/UnableToComplyException.java?rev=703978&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/UnableToComplyException.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/UnableToComplyException.java
 Mon Oct 13 02:06:40 2008
@@ -0,0 +1,31 @@
+/*
+ *
+ * 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.management.domain.services;
+
+public class UnableToComplyException extends Exception
+{
+    public UnableToComplyException(Exception exception)
+    {
+        super(exception);
+    }
+
+    private static final long serialVersionUID = -3071434478559509435L;
+}

Added: 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/AmqpCoDec.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/AmqpCoDec.java?rev=703978&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/AmqpCoDec.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/AmqpCoDec.java
 Mon Oct 13 02:06:40 2008
@@ -0,0 +1,136 @@
+package org.apache.qpid.management.messages;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+
+public class AmqpCoDec
+{
+    private byte [] _buffer;
+    private int _position;
+        
+    AmqpCoDec()
+    {
+        _buffer = new byte [1000];
+        _buffer[0] = 'A';
+        _buffer[1] = 'M';
+        _buffer[2] = '1';
+        _position = 3;
+    }
+    
+    
+    /**
+     * Int32-to-4 byte array marshalling.
+     * Marshalles an integer using four bytes.
+     * 
+     * @param data the result array.
+     * @param pos the starting position of the array to be filled.
+     * @param value the value to be marshalled.
+     */
+    public final void pack32(int value) {
+        _buffer[_position++] = (byte) (value >> 24 & 0xff);
+        _buffer[_position++] = (byte) (value >> 16 & 0xff);
+        _buffer[_position++] = (byte) (value >> 8 & 0xff);
+        _buffer[_position++] = (byte) (value & 0xff);
+    }
+
+    /**
+     * Int32-to-4 byte array marshalling.
+     * Marshalles an integer using four bytes.
+     * 
+     * @param data the result array.
+     * @param pos the starting position of the array to be filled.
+     * @param value the value to be marshalled.
+     */
+    public final void pack16(int value) {
+        _buffer[_position++] = (byte) (value >> 8 & 0xff);
+        _buffer[_position++] = (byte) (value & 0xff);
+    }
+    
+    /**
+     * Int32-to-4 byte array marshalling.
+     * Marshalles an integer using four bytes.
+     * 
+     * @param data the result array.
+     * @param pos the starting position of the array to be filled.
+     * @param value the value to be marshalled.
+     */
+    public final void pack64(long value) {
+        _buffer[_position++] = (byte) (value >> 56 & 0xff);
+        _buffer[_position++] = (byte) (value >> 48 & 0xff);
+        _buffer[_position++] = (byte) (value >> 40 & 0xff);
+        _buffer[_position++] = (byte) (value >> 32 & 0xff);
+        _buffer[_position++] = (byte) (value >> 24 & 0xff);
+        _buffer[_position++] = (byte) (value >> 16 & 0xff);
+        _buffer[_position++] = (byte) (value >> 8 & 0xff);
+        _buffer[_position++] = (byte) (value & 0xff);
+    }
+    
+    /**
+     * Int32-to-byte array marshalling.
+     * Marshalles an integer using two bytes.
+     * 
+     * @param data the result array.
+     * @param pos the starting position of the array to be filled.
+     * @param value the value to be marshalled.
+     */
+    public final void pack24(int value) {
+        _buffer[_position++] = (byte) (value >> 16 & 0xff);
+        _buffer[_position++] = (byte) (value >> 8 & 0xff);
+        _buffer[_position++] = (byte) (value & 0xff);
+    }    
+
+    public final void pack8(int value) {
+        _buffer[_position++] = (byte) (value & 0xff);
+    }    
+
+    public void pack8 (byte aByte)
+    {
+        _buffer[_position++] = aByte;
+    }    
+
+    public void packStr8(String aString)
+    {
+        try
+        {
+            byte [] toBytes = aString.getBytes("UTF-8");
+            int length = toBytes.length;
+            pack8(length);
+            System.arraycopy(toBytes, 0, _buffer, _position, length);  
+            _position+=length;
+        } catch (UnsupportedEncodingException exception)
+        {
+            throw new RuntimeException(exception);
+        }
+    }
+    
+    public void packStr16(String aString)
+    {
+        try
+        {
+            byte [] toBytes = aString.getBytes("UTF-8");
+            int length = toBytes.length;
+            pack16(length);
+            System.arraycopy(toBytes, 0, _buffer, _position, length);  
+            _position+=length;
+        } catch (UnsupportedEncodingException exception)
+        {
+            throw new RuntimeException(exception);
+        }
+    }
+
+    public void pack (byte[] bytes)
+    {
+        System.arraycopy(bytes, 0, _buffer, _position, bytes.length);
+        _position+=bytes.length;
+    }
+    
+    /**
+     * Retruns the byte buffer that is wrapping the backing array of this 
codec.
+     * 
+     * @return the byte buffer that is wrapping the backing array of this 
codec.
+     */
+    public ByteBuffer getEncodedBuffer ()
+    {
+        return ByteBuffer.wrap(_buffer,0,_position);
+    }
+}
\ No newline at end of file

Added: 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/ManagementMessage.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/ManagementMessage.java?rev=703978&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/ManagementMessage.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/ManagementMessage.java
 Mon Oct 13 02:06:40 2008
@@ -0,0 +1,186 @@
+/*
+ *
+ * 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.management.messages;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.qpid.api.Message;
+import org.apache.qpid.management.configuration.Configuration;
+import org.apache.qpid.management.domain.services.SequenceNumberGenerator;
+import org.apache.qpid.transport.DeliveryProperties;
+import org.apache.qpid.transport.Header;
+import org.apache.qpid.transport.MessageProperties;
+
+/**
+ * Message implementation used for specific management purposes.
+ * 
+ * @author Andrea Gazzarini
+ */
+public abstract class ManagementMessage implements Message
+{
+    /**
+     * Strategy interface for building / getting data.
+     * 
+     * @author Andrea Gazzarini
+     */
+    private interface IDataBuilderStrategy 
+    {
+       ByteBuffer getData(); 
+    };
+    
+    /**
+     * Strategy used for retrieving raw data from this message when it has 
been already encoded.
+     */
+    IDataBuilderStrategy READING = new IDataBuilderStrategy()
+    {
+        public ByteBuffer getData() {
+            return _data;
+        };
+    };
+    
+    /**
+     * Strategy used for retrieving raw data from this message when it hasn't 
been already encoded.
+     */
+    IDataBuilderStrategy ACCUMULATING = new IDataBuilderStrategy()
+    {
+        public ByteBuffer getData() {
+            _codec.pack8((byte)opcode());
+            _codec.pack32(sequenceNumber());
+            
+            specificMessageEncoding();
+            _data =_codec.getEncodedBuffer(); 
+            _reader = READING;
+            return _data;
+        }
+    };    
+    
+    protected AmqpCoDec _codec;
+    protected ByteBuffer _data;
+    private int _messageTransferId;
+    private IDataBuilderStrategy _reader = ACCUMULATING;    
+    
+    /**
+     * Builds an empty  management message.
+     */
+    ManagementMessage()
+    {
+        _codec = new AmqpCoDec();
+    }
+
+    /**
+     * Returns the sequence number that will be used for this message.
+     * 
+     * @return the sequence number that will be used for this message.
+     */
+    protected int sequenceNumber ()
+    {
+        return SequenceNumberGenerator.getNextSequenceNumber();
+    }
+
+    /**
+     * Returns the opcode that will be used for this message.
+     * 
+     * @return the opcode that will be used for this message.
+     */
+    abstract char opcode ();
+
+    /**
+     * Returns the delivery properties of this message.
+     * 
+     * @return the delivery properties of this message.
+     */
+    public DeliveryProperties getDeliveryProperties ()
+    {
+        return Configuration.getInstance().getCommandDeliveryProperties();
+    }
+
+    /**
+     * Returns the header of this message.
+     * 
+     * @return the header of this message.
+     */
+    public Header getHeader ()
+    {
+        return Configuration.getInstance().getCommandMessageHeader();
+    }
+
+    /**
+     * Returns the messages header properties of this message.
+     * 
+     * @return the message header properties of this message.
+     */
+    public MessageProperties getMessageProperties ()
+    {
+        return Configuration.getInstance().getCommandMessageProperties();
+    }
+    
+    /**
+     * Returns the transfer Id of this message.
+     * 
+     * @return the transfer Id of this message.
+     */
+    public int getMessageTransferId ()
+    {
+        return _messageTransferId;
+    }
+
+    /**
+     * Returns the encoded data of this message.
+     * 
+     * @return the encoded data of this message.
+     */
+    public ByteBuffer readData () throws IOException
+    {
+        return _reader.getData();
+    }
+
+    /**
+     * Sets the header for this message.
+     * 
+     * @param header the new message header.
+     */
+    public void setHeader (Header header)
+    {
+       // N.A. at the moment.
+    }
+
+    public void appendData (byte[] src) throws IOException
+    {
+    }
+
+    public void appendData (ByteBuffer src) throws IOException
+    {
+    }
+
+    public void clearData ()
+    {
+    }
+
+    public void readData (byte[] target) throws IOException
+    {
+    }
+    
+    /**
+     * Concrete subclasses (message implementations) must define here their 
specific data encoding.
+     */
+    abstract void specificMessageEncoding();    
+}
\ No newline at end of file

Added: 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/MethodInvocationRequestMessage.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/MethodInvocationRequestMessage.java?rev=703978&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/MethodInvocationRequestMessage.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/MethodInvocationRequestMessage.java
 Mon Oct 13 02:06:40 2008
@@ -0,0 +1,54 @@
+/*
+ *
+ * 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.management.messages;
+
+import org.apache.qpid.management.Protocol;
+import org.apache.qpid.management.domain.model.QpidMethod;
+import org.apache.qpid.management.domain.model.type.Binary;
+
+public abstract class MethodInvocationRequestMessage extends ManagementMessage
+{
+    @Override
+    char opcode ()
+    {
+        return Protocol.OPERATION_INVOCATION_REQUEST_OPCODE;
+    }
+    
+    protected abstract String packageName();
+    protected abstract String className();
+    protected abstract Binary schemaHash();
+    protected abstract Binary objectId();
+    protected abstract QpidMethod method();
+    protected abstract Object[] parameters();
+
+    @Override
+    void specificMessageEncoding ()
+    {
+        objectId().encode(_codec);
+        _codec.packStr8(packageName());
+        _codec.packStr8(className());
+        schemaHash().encode(_codec);
+        
+        QpidMethod method = method();
+       _codec.packStr8(method.getName());
+       method.encodeParameters(parameters(), _codec);
+    }
+}
\ No newline at end of file

Added: 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/SchemaRequestMessage.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/SchemaRequestMessage.java?rev=703978&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/SchemaRequestMessage.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/messages/SchemaRequestMessage.java
 Mon Oct 13 02:06:40 2008
@@ -0,0 +1,47 @@
+/*
+ *
+ * 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.management.messages;
+
+import org.apache.qpid.management.Protocol;
+import org.apache.qpid.management.domain.model.type.Binary;
+
+public abstract class SchemaRequestMessage extends ManagementMessage
+{
+    @Override
+    char opcode ()
+    {
+        return Protocol.SCHEMA_REQUEST_OPCODE;
+    }
+    
+    protected abstract String packageName();
+    
+    protected abstract String className();
+    
+    protected abstract Binary schemaHash();
+
+    @Override
+    final void specificMessageEncoding ()
+    {
+        _codec.packStr8(packageName());
+        _codec.packStr8(className());
+        schemaHash().encode(_codec);
+    }
+}
\ No newline at end of file


Reply via email to