QpidDomainObject.java
001 /*
002  *
003  * Licensed to the Apache Software Foundation (ASF) under one
004  * or more contributor license agreements.  See the NOTICE file
005  * distributed with this work for additional information
006  * regarding copyright ownership.  The ASF licenses this file
007  * to you under the Apache License, Version 2.0 (the
008  * "License"); you may not use this file except in compliance
009  * with the License.  You may obtain a copy of the License at
010  *
011  *   http://www.apache.org/licenses/LICENSE-2.0
012  *
013  * Unless required by applicable law or agreed to in writing,
014  * software distributed under the License is distributed on an
015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016  * KIND, either express or implied.  See the License for the
017  * specific language governing permissions and limitations
018  * under the License.
019  *
020  */
021 package org.apache.qpid.management.domain.handler.impl;
022 
023 import java.net.URI;
024 import java.util.Date;
025 import java.util.HashMap;
026 import java.util.Map;
027 import java.util.UUID;
028 
029 import org.apache.qpid.management.domain.services.MethodInvocationException;
030 
031 /**
032  * This is a sample entity used on QMan test case.
033  
034  @author Andrea Gazzarini
035  */
036 public class QpidDomainObject implements QpidDomainObjectMBean
037 {
038   private UUID _vhostRef;
039   private String _name;
040   private Boolean _durable;
041   private Map<String, Object> _arguments;
042   private Long _msgTotalEnqueues;
043   private Integer _consumerCount;
044   private Short _mgmtPubInterval;
045   private Date _expireTime;
046   private String _type;
047   private byte [] _byteArray;
048   
049   /**
050    * Builds a new QpidDomainObject with default values for 
051    * its properties.
052    */
053   public QpidDomainObject()
054   {
055     _vhostRef = UUID.randomUUID();
056     _name = "Initial Name";
057     _durable = Boolean.TRUE;
058     _arguments = new HashMap<String, Object>();  
059     _arguments.put("Key1""aStringValue");
060     _arguments.put("Key2", Long.MIN_VALUE);
061     _arguments.put("Key3", Integer.MAX_VALUE);
062     _arguments.put("Key4", Double.MIN_VALUE);
063     _arguments.put("Key4", Float.MAX_VALUE);
064 
065     _msgTotalEnqueues = Long.MAX_VALUE-10;
066     _consumerCount =  Integer.MIN_VALUE+10;
067     _mgmtPubInterval = Short.MAX_VALUE;
068     _expireTime = new Date(Long.MAX_VALUE);
069     _byteArray = new byte[]{1,2,3,5,6,7,8,7,56};
070   }
071   
072   /**
073    * A method that is throwing an exception, everytime.
074    
075    @throws Exception each time the method is called.
076    */
077   public void throwsException() throws Exception
078   {
079     throw new MethodInvocationException(-1,"KO");
080   }
081   
082   /**
083    * Sample echo method that return an empty result object.
084    * That is, an object with only status code / text valorized 
085    * (no output parameters).
086    
087    @return an empty result object.
088    */
089   public InvocationResult voidWithoutArguments()
090   {
091     return new InvocationResult(0,"OK,null",null);
092   
093   
094   /**
095    * Echo method that accepts and returns primitive type arrays.
096    
097    @param longs an array of long.
098    @param booleans an array of boolean.
099    @param doubles an array of double.
100    @param floats an array of float.
101    @param integers an array of int.
102    @param shorts an array of short.
103     @return a result object with the same input parameters (as output parameters).
104    */
105   public InvocationResult echoWithSimpleTypeArrays(
106       long [] longs,
107       boolean [] booleans,
108       double [] doubles,
109       float [] floats,
110       int [] integers,
111       short [] shorts)
112   {  
113     InvocationResult result = new InvocationResult(0,"OK",null);
114     Map<String, Object> outputParameters = new HashMap<String, Object>();
115     outputParameters.put(long.class.getName(), longs);
116     outputParameters.put(boolean.class.getName(), booleans);
117     outputParameters.put(double.class.getName(), doubles);
118     outputParameters.put(float.class.getName(), floats);
119     outputParameters.put(int.class.getName(), integers);
120     outputParameters.put(short.class.getName(), shorts);
121     result.setOutputSection(outputParameters);
122     return result;
123   }
124   
125   /**
126    * Echo method that accepts and returns wrapper types.
127    
128    @param aLong a java.lang.Long
129    @param aBoolean a java.lang.Boolean
130    @param aDouble a java.lang.Double
131    @param aFloat a java.lang.Float
132    @param anInteger a java.lang.Integer
133    @param aShort a java.lang.Short
134    @param aString a java.lang.String
135    @param anURI a java.net.URI
136    @param aDate a java.util.Date
137    @return a result object with the same given parameters (as output parameters)
138    */
139   public InvocationResult echoWithSimpleTypes(
140       Long aLong,
141       Boolean aBoolean,
142       Double aDouble,
143       Float aFloat,
144       Integer anInteger,
145       Short aShort,
146       String aString,
147       URI anURI,
148       Date aDate)
149   {
150     InvocationResult result = new InvocationResult(0,"OK",null);
151     Map<String, Object> outputParameters = new HashMap<String, Object>();
152     outputParameters.put("p1", aLong);
153     outputParameters.put("p2", aBoolean);
154     outputParameters.put("p3", aDouble);
155     outputParameters.put("p4", aFloat);
156     outputParameters.put("p5", anInteger);
157     outputParameters.put("p6", aShort);
158     outputParameters.put("p7", aString);
159     outputParameters.put("p8", anURI);
160     outputParameters.put("p9", aDate);
161     result.setOutputSection(outputParameters);
162     return result;
163   }
164 
165   /**
166    *  Echo method that accepts and returns wrapper type arrays .
167    *  
168    @param longs an array of java.lang.Long
169    @param booleans an array of java.lang.Boolean
170    @param doubles an array of java.lang.Double
171    @param floats an array of java.lang.Float
172    @param integers an array of java.lang.Integer
173    @param shorts an array of java.lang.Short
174    @param strings an array of java.lang.String
175    @param uris an array of java.net.URI
176    @param dates an array of java.util.Date
177    @return a result object with the same input parameters (as output parameters).
178    */
179   public InvocationResult echoWithArrays(
180       Long [] longs,
181       Boolean [] booleans,
182       Double [] doubles,
183       Float [] floats,
184       Integer [] integers,
185       Short [] shorts,
186       String [] strings,
187       URI [] uris,
188       Date [] dates)
189   {
190     InvocationResult result = new InvocationResult(0,"OK",null);
191     Map<String, Object> outputParameters = new HashMap<String, Object>();
192     outputParameters.put(Long.class.getName(), longs);
193     outputParameters.put(Boolean.class.getName(), booleans);
194     outputParameters.put(Double.class.getName(), doubles);
195     outputParameters.put(Float.class.getName(), floats);
196     outputParameters.put(Integer.class.getName(), integers);
197     outputParameters.put(Short.class.getName(), shorts);
198     outputParameters.put(String.class.getName(), strings);
199     outputParameters.put(URI.class.getName(), uris);
200     outputParameters.put(Date.class.getName(), dates);
201     result.setOutputSection(outputParameters);
202     return result;
203   }
204   
205   /**
206    * Echo method that accepts and returns a byte array.
207    
208    @param byteArray a byte array
209    @return a result containing the input byte array (as output parameter)
210    */
211   public InvocationResult echoWithByteArray(byte [] byteArray)
212   
213     InvocationResult result = new InvocationResult(0,"OK",null);
214     Map<String, Object> outputParameters = new HashMap<String, Object>();
215     outputParameters.put(byte[].class.getName(),byteArray);
216     result.setOutputSection(outputParameters);
217     return result;
218   }
219   
220   /**
221    * Echo method that accepts and returns an UUID.
222    
223    @param uuid a java.util.UUID.
224    @return a result containing the input UUID (as output parameter)
225    */
226   public InvocationResult echoWithUUID(UUID uuid
227   
228     InvocationResult result = new InvocationResult(0,"OK",null);
229     Map<String, Object> outputParameters = new HashMap<String, Object>();
230     outputParameters.put("uuid",uuid);
231     result.setOutputSection(outputParameters);
232     return result;
233   }
234   
235   /**
236    * Echo method that accepts and returns a Map.
237    
238    @param map a java.util.Map.
239    @return a result containing the input Map (as output parameter)
240    */
241   public InvocationResult echoWithMap(Map<String,Object> map
242   {
243     InvocationResult result = new InvocationResult(0,"OK",null);
244     Map<String, Object> outputParameters = new HashMap<String, Object>();
245     outputParameters.put("map",map);
246     result.setOutputSection(outputParameters);
247     return result;
248   }
249 
250   public UUID getVhostRef()
251   {
252     return _vhostRef;
253   }
254 
255   public String getName()
256   {
257     return _name;
258   }
259 
260   public Boolean getDurable()
261   {
262     return _durable;
263   }
264 
265   public Map<String, Object> getArguments()
266   {
267     return _arguments;
268   }
269 
270   public Long getMsgTotalEnqueues()
271   {
272     return _msgTotalEnqueues;
273   }
274 
275   public Integer getConsumerCount()
276   {
277     return _consumerCount;
278   }
279 
280   public Date getExpireTime()
281   {
282     return _expireTime;
283   }
284 
285   public Short getMgmtPubInterval()
286   {
287     return _mgmtPubInterval;
288   }
289 
290   public void setExpireTime(Date expireTime)
291   {
292     this._expireTime = expireTime;
293   }
294 
295   public void setMgmtPubInterval(Short value)
296   {
297     this._mgmtPubInterval = value;
298   }
299   
300   public void setType(String type)
301   {
302     this._type = type;
303   }
304   
305   public String getType()
306   {
307     return _type;
308   }
309   
310   public byte[] getByteArray()
311   {
312     return _byteArray;
313   }
314 }