1 18 package org.objectweb.kilim.description; 19 20 import org.objectweb.kilim.KilimException; 21 22 27 public class Property extends BasicNamedElementImpl { 28 private static final Class [] TYPE_CLASSES = { 29 null, 30 Boolean .class, 31 Character .class, 32 Byte .class, 33 Short .class, 34 Integer .class, 35 Long .class, 36 Float .class, 37 Double .class, 38 String .class, 39 Object .class 40 }; 41 42 private Class type; 43 private Object value = null; 44 private int typeKind; 45 private boolean isBound; 46 47 55 public Property(String aName, int aStatus, int aTypeKind, TemplateDescription aTemplate) throws KilimException { 56 super(aName, aStatus, true, false, aTemplate); 57 type = getClassFromTypeKind(aTypeKind); 58 typeKind = aTypeKind; 59 } 60 61 66 public void setType(int aType) throws KilimException { 67 type = getClassFromTypeKind(aType); 68 typeKind = aType; 69 } 70 71 75 public Class getType() { 76 return type; 77 } 78 79 82 public int getTypeKind() { 83 return typeKind; 84 } 85 86 89 public int getKind() { 90 return KILIM.PROPERTY; 91 } 92 93 96 public void setValue(Object aObject) throws KilimException { 97 if (aObject == null) { 98 value = null; 99 isBound = false; 100 } 101 102 if (!aObject.getClass().isAssignableFrom(type)) { 103 throw new KilimException("Property Exception : trying to assign " + aObject + " of type [" + aObject.getClass() + "] to type " + type); 104 } 105 106 isBound = true; 107 value = aObject; 108 } 109 110 113 public Object getValue() { 114 return value; 115 } 116 117 private static Class getClassFromTypeKind(int aTypeKind) throws KilimException { 118 if (aTypeKind < 0 || aTypeKind > 9) { 119 throw new KilimException("illegal value for typeKind : should be between 1 and 9"); 120 } 121 return TYPE_CLASSES[aTypeKind]; 122 } 123 124 } 125 | Popular Tags |