QpidAttribute.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.management.domain.model.type.Type;
025 import org.apache.qpid.transport.codec.Decoder;
026 import org.apache.qpid.transport.util.Logger;
027 
028 /**
029  * Layer supertype for qpid properties and statistics. 
030  
031  @author Andrea Gazzarini
032  */
033 class QpidAttribute extends QpidFeature
034 {
035     private final static Logger LOGGER = Logger.get(QpidAttribute.class);
036     
037     /** feature type */
038     protected Type _type;
039     
040     /** feature unit */
041     protected String _unit;
042 
043     /**
044      * Returns the units used for numeric values (i.e. seconds, bytes, etc.)
045      
046      @return the units used for numeric values (i.e. seconds, bytes, etc.)
047      */
048     String getUnit ()
049     {
050         return _unit;
051     }
052 
053     /**
054      * Sets the unit for this property.
055      
056      @param unit the unit of this property.
057      */
058     void setUnit (String unit)
059     {
060         this._unit = unit;
061     }
062     
063     /**
064      * Returns the java type (class) of this feature.
065      
066      @return the java type (class) of this feature.
067      */
068     Class<?> getJavaType ()
069     {
070         return _type.getJavaType();
071     }
072 
073     /**
074      * Sets the type of this feature.
075      
076      @param type the type of this feature.
077      */
078     void setType (Type type)
079     {
080         this._type = type;
081     }
082     
083     /**
084      * Gets the value of this feature according to its type definition.
085      
086      @param decoder the decoder used to extract the value.
087      @return the value of this feature according to its type definition
088      */
089     Object decodeValue(Decoder decoder)
090     {
091         try {
092             return _type.decode(decoder);
093         catch(RuntimeException exception
094         {
095             LOGGER.error(exception,Messages.QMAN_100014_ATTRIBUTE_DECODING_FAILURE,this);
096             throw exception;
097         }
098     }
099     
100     @Override
101     public String toString ()
102     {
103         return super.toString()+",type="+_type;
104     }
105 }