KickJava   Java API By Example, From Geeks To Geeks.

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


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.BasicElement;
26 import org.objectweb.kilim.description.InlinedElement;
27 import org.objectweb.kilim.description.KILIM;
28 import org.objectweb.kilim.description.NamedElement;
29 import org.objectweb.kilim.description.TemplateDescription;
30 import org.objectweb.kilim.description.TemplateElementImpl;
31
32 /**
33  * @author horn
34  */

35 public abstract class RtComponentProvider extends RtComponentInterface {
36     protected static Stack JavaDoc callStack = new Stack JavaDoc();
37     private RuntimeSource support;
38     private Object JavaDoc source;
39         
40     /**
41      * The public constructor for RtComponentProvider.
42      * @param aElement : the template description associated to the element
43      * @param aComponent : the component containing the provider (it is either a component or a slot).
44      * @param aSupport : the support of the provider, i.e. source supporting the method, the constructor, the getter, .... associated to the provider.
45      */

46     protected RtComponentProvider(TemplateElementImpl aElement, ContainerElement aComponent, RuntimeSource aSupport) {
47         super(aElement, aComponent);
48         support = aSupport;
49     }
50     
51     /**
52      * @see org.objectweb.kilim.model.ComponentElement#getLocalName()
53      */

54     public String JavaDoc getLocalName() {
55         TemplateElementImpl elem = getElementDescription();
56         if (elem instanceof InlinedElement) {
57             return ((InlinedElement) elem).getLocalName();
58         } else if (elem instanceof NamedElement) {
59             return ((NamedElement) elem).getLocalName();
60         }
61         return "";
62     }
63
64     /**
65      * @see org.objectweb.kilim.model.RuntimeSource#isEventSource()
66      */

67     public boolean isEventSource() {
68         return false;
69     }
70     
71     /**
72      * @see org.objectweb.kilim.model.RuntimeSource#getEventSource()
73      */

74     public Object JavaDoc getEventSourceValue() throws KilimException {
75         return source;
76     }
77     
78     /**
79      * @see org.objectweb.kilim.model.RuntimeSource#setEventSource(Object)
80      */

81     public void setEventSourceValue(Object JavaDoc aSource) throws KilimException {
82         source = aSource;
83     }
84     
85     /**
86      * returns the support of the provider.
87      * @return RuntimeSource
88      */

89     public RuntimeSource getSupport() {
90         return support;
91     }
92         
93     /**
94      * @see org.objectweb.kilim.model.RtComponentInterface#bindProvider(RuntimeSource, boolean)
95      */

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

112     public void unbindProvider(RuntimeSource aSource) throws KilimException {
113         throw new KilimException("attempt to unbind a provider " + getQualifiedName());
114     }
115     
116     /**
117      * @see org.objectweb.kilim.model.ComponentInterface#isSingleValueInterface()
118      */

119     public boolean isSingleValuePort() {
120         return false;
121     }
122     
123     /**
124      * @see org.objectweb.kilim.model.ComponentInterface#isCollectionInterface()
125      */

126     public boolean isCollectionPort() {
127         return false;
128     }
129     
130     /**
131      * @see org.objectweb.kilim.model.ComponentInterface#isProvider()
132      */

133     public boolean isProvider() {
134         return true;
135     }
136     
137     /**
138      * @see org.objectweb.kilim.model.ComponentInterface#isProperty()
139      */

140     public boolean isProperty() {
141         return false;
142     }
143             
144     /**
145      * @see org.objectweb.kilim.model.RtComponentInterface#specificBindValue(Object)
146      */

147     protected void specificBindValue(Object JavaDoc aValue) throws KilimException {
148         throw new KilimException ("attempt to bind a value to a provider " + getQualifiedName());
149     }
150     
151     /**
152      * @see org.objectweb.kilim.model.RtComponentInterface#specificUnbindValue()
153      */

154     protected void specificUnbindValue() throws KilimException {
155         throw new KilimException ("attempt to bind a value to a provider " + getQualifiedName());
156     }
157         
158     /**
159      * Method getKind. This method returns the kind of the provider.
160      * @return int
161      */

162     public int getKind() {
163         return ((BasicElement) getElementDescription()).getKind();
164     }
165 }
Popular Tags