KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > description > Property


1 /**
2  * Copyright (C) 2002 Kelua SA
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.kilim.description;
19
20 import org.objectweb.kilim.KilimException;
21
22 /**
23  * @author horn
24  * Describes a Kilim Template Property.
25  * Provides the basic primitive types & their values.
26  */

27 public class Property extends BasicNamedElementImpl {
28     private static final Class JavaDoc[] TYPE_CLASSES = {
29         null,
30         Boolean JavaDoc.class,
31         Character JavaDoc.class,
32         Byte JavaDoc.class,
33         Short JavaDoc.class,
34         Integer JavaDoc.class,
35         Long JavaDoc.class,
36         Float JavaDoc.class,
37         Double JavaDoc.class,
38         String JavaDoc.class,
39         Object JavaDoc.class
40     };
41                 
42     private Class JavaDoc type;
43     private Object JavaDoc value = null;
44     private int typeKind;
45     private boolean isBound;
46     
47     /**
48      * The public constructor for properties.
49      * @param aName : the name of the property.
50      * @param aStatus : the status of the property. It should be one KILIM.PUBLIC, PUBLIC.PROTECTED, KILIM.PRµIVATE.
51      * @param aTypeKind : the type kind of the property. It should be one of the kind defined in the class KILIM.
52      * @param aTemplate : the template in which the property is defined.
53      * @throws KilimException : generated if aName or a Template is null, if aStatus or aTypeKind has an illegal value.
54      */

55     public Property(String JavaDoc 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     /**
62      * sets the property type
63      * @param aType : a type kind defined in the KILIM class.
64      * @throws KilimException : generated if Type has an illegal value.
65      */

66     public void setType(int aType) throws KilimException {
67         type = getClassFromTypeKind(aType);
68         typeKind = aType;
69     }
70     
71     /**
72      * returns the property type.
73      * @return Class
74      */

75     public Class JavaDoc getType() {
76         return type;
77     }
78     
79     /**
80      * @see org.objectweb.kilim.description.Property#getTypeKind()
81      */

82     public int getTypeKind() {
83         return typeKind;
84     }
85     
86     /**
87      * @see org.objectweb.kilim.description.BasicElement#getKind()
88      */

89     public int getKind() {
90         return KILIM.PROPERTY;
91     }
92         
93     /**
94      * @see org.objectweb.kilim.description.Property#setValue(Object)
95      */

96     public void setValue(Object JavaDoc 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     /**
111      * @see org.objectweb.kilim.description.Property#getValue()
112      */

113     public Object JavaDoc getValue() {
114         return value;
115     }
116     
117     private static Class JavaDoc 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