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.type;
022
023 import org.apache.qpid.transport.codec.Decoder;
024 import org.apache.qpid.transport.codec.Encoder;
025
026 /**
027 * Layer supertype for all management "types".
028 *
029 * @author Andrea Gazzarini
030 */
031 public abstract class Type
032 {
033 /** Java representation of this type. */
034 protected final Class<?> javaType;
035
036 /**
037 * Builds a new management type wiich wraps the given java type.
038 *
039 * @param javaType the java type.
040 */
041 Type(Class<?> javaType)
042 {
043 this.javaType = javaType;
044 }
045
046 /**
047 * Returns the wrapped java type.
048 *
049 * @return the wrapped java type.
050 */
051 public Class<?> getJavaType ()
052 {
053 return javaType;
054 }
055
056 /**
057 * Each concrete subclass must define here how to decode incoming data according.
058 *
059 * @param decoder the decoder used to extract data.
060 * @return the "typed" value.
061 *
062 */
063 public abstract Object decode(Decoder decoder);
064
065 /**
066 * Returns a string representation of this type.
067 *
068 * @return a string representation of this type.
069 */
070 @Override
071 public String toString ()
072 {
073 return new StringBuilder(getClass().getName())
074 .append(" (wraps ")
075 .append(javaType.getName())
076 .append(')').toString();
077 }
078
079 /**
080 * Identity for types is based on wrapped java type identity.
081 */
082 @Override
083 public boolean equals (Object obj)
084 {
085 return getClass() == obj.getClass();
086 }
087
088 @Override
089 public int hashCode ()
090 {
091 return getClass().hashCode();
092 }
093
094 /**
095 * Encodes the given values according to this type definition.
096 *
097 * @param value the value to be encoded.
098 * @param encoder the encoder.
099 */
100 public abstract void encode (Object value,Encoder encoder);
101 }
|