KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > model > RtComponentProperty


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
19 package org.objectweb.kilim.model;
20
21 import java.util.Iterator JavaDoc;
22 import java.util.Stack JavaDoc;
23
24 import org.objectweb.kilim.KilimException;
25 import org.objectweb.kilim.description.KILIM;
26 import org.objectweb.kilim.description.NamedElement;
27 import org.objectweb.kilim.description.Property;
28 import org.objectweb.kilim.description.TemplateDescription;
29 import org.objectweb.kilim.description.TemplateElementImpl;
30
31 /**
32  * @author horn
33  */

34
35 public class RtComponentProperty extends RtComponentInterface implements ComponentProperty {
36     private static Object JavaDoc UNSET = new Object JavaDoc();
37     private boolean used;
38     private Object JavaDoc value;
39     
40         
41     /**
42      * The public constructor for RtComponentProperties.
43      * @param aElement : the template description of the property.
44      * @param aComponent : the component containing the property.
45      */

46     public RtComponentProperty(TemplateElementImpl aElement, Component aComponent) {
47         super(aElement, aComponent);
48         value = ((Property) getElementDescription()).getValue();
49     }
50
51     /**
52      * @see org.objectweb.kilim.model.ComponentElement#getLocalName()
53      */

54     public String JavaDoc getLocalName() {
55         NamedElement elem = (NamedElement) getElementDescription();
56         return elem.getLocalName();
57     }
58     
59     /**
60      * sets the value of a property. It is strictly equivalent to bindValue(aValue).
61      * @param aValue : the value to be set.
62      * @throws KilimException : generated if the value is illegal (type mismatch, for example).
63      */

64     public void setValue(Object JavaDoc aValue) throws KilimException {
65         bindValue(aValue);
66     }
67         
68     /**
69      * @see org.objectweb.kilim.model.RuntimeSource#isEventSource()
70      */

71     public boolean isEventSource() {
72         return false;
73     }
74     
75     /**
76      * @see org.objectweb.kilim.model.RuntimeSource#getEventSource()
77      */

78     public Object JavaDoc getEventSourceValue() throws KilimException {
79         return null;
80     }
81     
82     /**
83      * @see org.objectweb.kilim.model.RuntimeSource#setEventSource(Object)
84      */

85     public void setEventSourceValue(Object JavaDoc aSource) throws KilimException { }
86     
87     /**
88      * @see org.objectweb.kilim.model.RtComponentInterface#bindProvider(RuntimeSource, boolean)
89      */

90     public void bindProvider(RuntimeSource aSource, boolean jReplace) throws KilimException {
91         TemplateDescription tmp0 = getContainingComponent().getTemplate();
92         String JavaDoc lName = getLocalName();
93         String JavaDoc tmpList = tmp0.getName();
94         while ((tmp0 = tmp0.getSuperTemplate()) != null) {
95             Iterator JavaDoc iter = tmp0.getBindings(lName, true);
96             if (iter != KILIM.EMPTY_ITERATOR) {
97                 tmpList = tmpList + ", " + tmp0.getName();
98             }
99         }
100         throw new KilimException("attempt to bind a property " + getQualifiedName() + " (binding definition in templates : " + tmpList + ")");
101     }
102     
103     /**
104      * @see org.objectweb.kilim.model.RtComponentInterface#unbindProvider(RuntimeSource)
105      */

106     public void unbindProvider(RuntimeSource aSource) throws KilimException {
107         throw new KilimException("attempt to unbind a provider " + aSource + " from a property " + getQualifiedName());
108     }
109     
110     /**
111      * @see org.objectweb.kilim.model.RuntimeSource#getValue(RuntimeContext)
112      */

113     protected Object JavaDoc specificGetValue() throws KilimException {
114         Object JavaDoc resultValue = null;
115         if (mappingContext != null) {
116             mappingContext.getCallStack().push(this);
117         }
118         if (value == UNSET) {
119             throw new KilimException("attempt to get the value of an unset property " + getQualifiedName());
120         }
121
122         mapper.enterContext(mappingContext);
123         resultValue = mapper.getPropertyValue(value, mappingContext);
124         if (mappingContext != null) {
125             mappingContext.getCallStack().pop();
126         }
127         mapper.leaveContext(mappingContext);
128         used = true;
129         return resultValue;
130     }
131
132     /**
133      * @see org.objectweb.kilim.model.ComponentInterface#unbindValue()
134      */

135     protected void specificUnbindValue() throws KilimException {
136         value = UNSET;
137     }
138         
139     /**
140      * @see org.objectweb.kilim.model.ComponentInterface#bindValue(Object)
141      */

142     protected void specificBindValue(Object JavaDoc aValue) throws KilimException {
143         value = aValue;
144     }
145         
146     /**
147      * @see org.objectweb.kilim.model.ComponentInterface#isSingleValueInterface()
148      */

149     public boolean isSingleValuePort() {
150         return false;
151     }
152     
153     /**
154      * @see org.objectweb.kilim.model.ComponentInterface#isCollectionInterface()
155      */

156     public boolean isCollectionPort() {
157         return false;
158     }
159     
160     /**
161      * @see org.objectweb.kilim.model.ComponentInterface#isProvider()
162      */

163     public boolean isProvider() {
164         return false;
165     }
166     
167     /**
168      * @see org.objectweb.kilim.model.ComponentInterface#isProperty()
169      */

170     public boolean isProperty() {
171         return true;
172     }
173     
174     /**
175      * @see org.objectweb.kilim.model.RtComponentInterface#checkValue()
176      */

177     public boolean hasValue() {
178         return value != UNSET;
179     }
180     
181     /**
182      * @see org.objectweb.kilim.model.RuntimeSource#checkValue(Stack)
183      */

184     public boolean checkValue(Stack JavaDoc exclude) throws KilimException {
185         return true;
186     }
187 }
188
Popular Tags