Coverage Report - org.apache.commons.clazz.reflect.extended.ReflectedMappedProperty
 
Classes in this File Line Coverage Branch Coverage Complexity
ReflectedMappedProperty
0%
0/60
0%
0/20
1.611
 
 1  
 /*
 2  
  * Copyright 2002-2004 The Apache Software Foundation
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.commons.clazz.reflect.extended;
 17  
 
 18  
 import java.lang.reflect.Method;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.apache.commons.clazz.Clazz;
 22  
 import org.apache.commons.clazz.reflect.common.ReflectedAccessorPairProperty;
 23  
 
 24  
 /**
 25  
  * 
 26  
  * @author <a href="mailto:dmitri@apache.org">Dmitri Plotnikov</a>
 27  
  * @version $Id: ReflectedMappedProperty.java 155436 2005-02-26 13:17:48Z dirkv $
 28  
  */
 29  
 public class ReflectedMappedProperty extends ReflectedAccessorPairProperty {
 30  
 
 31  
     private Class keyType;
 32  
     private Class contentType;
 33  
     private Method sizeMethod;
 34  
     private Method getMethod;
 35  
     private Method putMethod;
 36  
     private Method removeMethod;
 37  
     private Method keySetMethod;
 38  
     
 39  
     /**
 40  
      * Constructor for ReflectedMappedProperty.
 41  
      * @param declaringClazz
 42  
      * @param name
 43  
      */
 44  
     public ReflectedMappedProperty(Clazz declaringClazz, String name) {
 45  0
         super(declaringClazz, name);
 46  0
     }
 47  
 
 48  
     /**
 49  
      * @see org.apache.commons.clazz.ClazzProperty#isMap()
 50  
      */
 51  
     public boolean isMap() {
 52  0
         return true;
 53  
     }
 54  
     
 55  
     /**
 56  
      * Returns the keyType.
 57  
      * @return Class
 58  
      */
 59  
     public Class getKeyType() {
 60  0
         return keyType;
 61  
     }
 62  
 
 63  
     /**
 64  
      * Sets the keyType.
 65  
      * @param keyType The keyType to set
 66  
      */
 67  
     public void setKeyType(Class keyType) {
 68  0
         this.keyType = keyType;
 69  0
     }
 70  
 
 71  
     /**
 72  
      * Returns the contentType.
 73  
      * @return Class
 74  
      */
 75  
     public Class getContentType() {
 76  0
         return contentType;
 77  
     }
 78  
 
 79  
     /**
 80  
      * Sets the contentType.
 81  
      * @param contentType The contentType to set
 82  
      */
 83  
     public void setContentType(Class valueType) {
 84  0
         this.contentType = valueType;
 85  0
     }
 86  
     
 87  
     /**
 88  
      * Returns the getMethod.
 89  
      * @return Method
 90  
      */
 91  
     public Method getGetMethod() {
 92  0
         return getMethod;
 93  
     }
 94  
 
 95  
     /**
 96  
      * Sets the getMethod.
 97  
      * @param getMethod The getMethod to set
 98  
      */
 99  
     public void setGetMethod(Method getMethod) {
 100  0
         this.getMethod = getMethod;
 101  0
     }
 102  
     
 103  
     /**
 104  
      * Returns the putMethod.
 105  
      * @return Method
 106  
      */
 107  
     public Method getPutMethod() {
 108  0
         return putMethod;
 109  
     }
 110  
 
 111  
     /**
 112  
      * Sets the putMethod.
 113  
      * @param putMethod The putMethod to set
 114  
      */
 115  
     public void setPutMethod(Method putMethod) {
 116  0
         this.putMethod = putMethod;
 117  0
     }
 118  
 
 119  
     /**
 120  
      * Returns the removeMethod.
 121  
      * @return Method
 122  
      */
 123  
     public Method getRemoveMethod() {
 124  0
         return removeMethod;
 125  
     }
 126  
 
 127  
     /**
 128  
      * Sets the removeMethod.
 129  
      * @param removeMethod The removeMethod to set
 130  
      */
 131  
     public void setRemoveMethod(Method removeMethod) {
 132  0
         this.removeMethod = removeMethod;
 133  0
     }
 134  
 
 135  
     /**
 136  
      * Returns the keySetMethod.
 137  
      * @return Method
 138  
      */
 139  
     public Method getKeySetMethod() {
 140  0
         return keySetMethod;
 141  
     }
 142  
 
 143  
     /**
 144  
      * Sets the keySetMethod.
 145  
      * @param keySetMethod The keySetMethod to set
 146  
      */
 147  
     public void setKeySetMethod(Method keySetMethod) {
 148  0
         this.keySetMethod = keySetMethod;
 149  0
     }
 150  
 
 151  
     public String toString() {
 152  0
         StringBuffer buffer = new StringBuffer("[ReflectedMappedProperty ");
 153  0
         if (getType() != null) {
 154  0
             buffer.append(getType().getName());
 155  0
             buffer.append(" ");
 156  
         }
 157  0
         if (getKeyType() != null) {
 158  0
             buffer.append("[key: ");
 159  0
             buffer.append(getKeyType().getName());
 160  0
             buffer.append("] ");
 161  
         }
 162  0
         if (getContentType() != null) {
 163  0
             buffer.append("[content: ");
 164  0
             buffer.append(getContentType().getName());
 165  0
             buffer.append("] ");
 166  
         }
 167  0
         buffer.append(getName());
 168  0
         if (getReadMethod() != null) {
 169  0
             buffer.append("\n   [read method]      ");
 170  0
             buffer.append(getReadMethod());            
 171  
         }
 172  0
         if (getWriteMethod() != null) {
 173  0
             buffer.append("\n   [write method]     ");
 174  0
             buffer.append(getWriteMethod());            
 175  
         }
 176  0
         if (getGetMethod() != null) {
 177  0
             buffer.append("\n   [get method]       ");
 178  0
             buffer.append(getGetMethod());            
 179  
         }
 180  0
         if (getPutMethod() != null) {
 181  0
             buffer.append("\n   [put method]       ");
 182  0
             buffer.append(getPutMethod());            
 183  
         }
 184  0
         if (getRemoveMethod() != null) {
 185  0
             buffer.append("\n   [remove method]    ");
 186  0
             buffer.append(getRemoveMethod());            
 187  
         }
 188  0
         if (getKeySetMethod() != null) {
 189  0
             buffer.append("\n   [keySet method]    ");
 190  0
             buffer.append(getKeySetMethod());            
 191  
         }
 192  0
         buffer.append("]");
 193  0
         return buffer.toString();
 194  
     }
 195  
     /**
 196  
      * @see org.apache.commons.clazz.ClazzProperty#get(java.lang.Object)
 197  
      */
 198  
     public Object get(Object instance) {
 199  0
         return new ReflectedMap(instance, this);
 200  
     }
 201  
     
 202  
     public Map getMap(Object instance) {
 203  0
         if (getReadMethod() == null) {
 204  0
             return null;
 205  
         }
 206  
         
 207  0
         return (Map) super.get(instance);
 208  
     }
 209  
 
 210  
     /**
 211  
      * @see org.apache.commons.clazz.ClazzProperty#set(Object, Object)
 212  
      */
 213  
     public void set(Object instance, Object value) {
 214  0
         super.set(instance, value);
 215  0
     }
 216  
 }