QpidArgument.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.model;
022 
023 import org.apache.qpid.management.Messages;
024 import org.apache.qpid.transport.codec.Encoder;
025 import org.apache.qpid.transport.util.Logger;
026 
027 /**
028  * An argument is the formal definition of a parameter belonging to a specific method / operation.
029  */
030 class QpidArgument extends QpidProperty
031 {
032     private final static Logger LOGGER = Logger.get(QpidArgument.class);
033     
034     private Object _defaultValue;
035     
036     private Direction _direction;
037     
038     /**
039      * Sets the direction of this argument.
040      
041      @param the direction of this argument.
042      */
043     public void setDirection(String code
044     {
045         this._direction = Direction.valueOf(code);
046     }
047     
048     /**
049      * Returns the direction of this argument.
050      
051      @return the direction of this argument.
052      */
053     public Direction getDirection()
054     {
055         return _direction;
056     }
057     
058     /**
059      * Sets the default value of this argument.
060      
061      @param defaultValue the default value of this argument.
062      */
063     public void setDefaultValue(Object defaultValue)
064     {
065         this._defaultValue = defaultValue;
066     }
067 
068     /**
069      * Returns the default value of this argument.
070      
071      @return the default value of this argument.
072      */
073     public Object getDefaultValue()
074     {
075         return _defaultValue;
076     }
077     
078     /**
079      * Returns true if this is an Input argument.
080      *  
081      @return true if this is an Input argument.
082      */
083     public boolean isInput()
084     {
085         return _direction != Direction.O;
086     }
087     
088     @Override
089     public String toString ()
090     {
091         return new StringBuilder()
092             .append(getJavaType().getName())
093             .append(' ')
094             .append(_name)
095             .append("(")
096             .append(_direction)
097             .append(")")
098             .toString();
099     }
100 
101     /**
102      * Encodes the given value according to this argument type & definition.
103      
104      @param value the value to be encoded.
105      @param encoder the encoder.
106      */
107     public void encode(Object value,Encoder encoder
108     {
109         _type.encode(value, encoder);
110         LOGGER.debug(Messages.QMAN_200013_ARGUMENT_VALUE_ENCODED,value,_name,_type);
111     }
112     
113     /**
114      * Decodes the value for this argument according to its type & definition.
115      
116      @param decoder the decoder
117      @return the decoded value of this argument.
118      */
119     public Object decode(org.apache.qpid.transport.codec.Decoder decoder
120     {
121         return _type.decode(decoder);
122     }
123 }