KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Stack JavaDoc;
26
27 import org.objectweb.kilim.KilimConfiguration;
28 import org.objectweb.kilim.KilimException;
29 import org.objectweb.kilim.description.KILIM;
30 import org.objectweb.kilim.description.TemplateElementImpl;
31 import org.objectweb.kilim.model.mapping.Mapper;
32 import org.objectweb.kilim.model.mapping.MappingContext;
33
34 /**
35  * @author horn
36  */

37
38 public abstract class RtComponentSource extends RtComponentElement implements RuntimeSource {
39     //svpStack and knownValues are two data structures necessary to solve the "evaluation cycle" problem
40
//svpStack is the stack of the single value ports which are in the process of being evaluated.
41
//knownValues is a hashmap containing the value of already evaluated single value ports.
42
protected static Stack JavaDoc svpStack = new Stack JavaDoc();
43     protected static HashMap JavaDoc knownValues = new HashMap JavaDoc();
44     
45     protected Mapper mapper;
46     protected MappingContext mappingContext;
47
48     //nAryListeners are mainly used to implement the plug operations
49
private List JavaDoc nAryListeners;
50
51     protected RtComponentSource(TemplateElementImpl aElement, ContainerElement aComponent) {
52             super(aElement, aComponent);
53             mapper = KilimConfiguration.getMappingStrategy().getDefaultMapper();
54             mappingContext = KilimConfiguration.getMappingContext();
55     }
56     
57     /**
58      * Method getCurrentSVP.
59      * @return RtSingleValuePort
60      */

61     public static RtSingleValuePort getCurrentSVP() {
62         int svpSize = svpStack.size();
63         if (svpSize == 0) {
64             return null;
65         } else {
66             return (RtSingleValuePort) svpStack.get(svpSize - 1);
67         }
68     }
69     
70     /**
71      * Method evaluationPerformed.
72      * @param aPort : a single value port.
73      * @return boolean : the value is true if the single value port has already been evaluated. False otherwise.
74      */

75     public static boolean evaluationPerformed(RtSingleValuePort aPort) {
76         if (knownValues.containsKey(aPort)) {
77             return true;
78         } else {
79             return false;
80         }
81     }
82
83     /**
84      * @see org.objectweb.kilim.model.RuntimeSource#addInterfaceListener(RtCollectionInterface)
85      */

86     public void addInterfaceListener(RtCollectionPort aInterface) throws KilimException {
87         if (aInterface == null) {
88             throw new KilimException("attempt to add a null nary port listener to an interface " + getQualifiedName());
89         }
90             
91         if (nAryListeners == null) {
92             nAryListeners = new ArrayList JavaDoc();
93         }
94         
95         if (nAryListeners.contains(aInterface)) {
96             throw new KilimException("attempt to add an already known nary port listener to an interface " + getQualifiedName());
97         }
98         nAryListeners.add(aInterface);
99     }
100     
101     /**
102      * @see org.objectweb.kilim.model.RuntimeSource#removeInterfaceListener(RtCollectionInterface)
103      */

104     public void removeInterfaceListener(RtCollectionPort aInterface) throws KilimException {
105         if (aInterface == null) {
106             throw new KilimException("attempt to remove a null nary port listener from an interface " + getQualifiedName());
107         }
108         if (nAryListeners == null) {
109             throw new KilimException("attempt to remove a nary port listener from an interface " + getQualifiedName() + " without listeners");
110         }
111         
112         boolean result = nAryListeners.remove(aInterface);
113         if (!result) {
114             throw new KilimException("attempt to remove a unknown nary port listener from an interface " + getQualifiedName());
115         }
116     }
117     
118     /**
119      * returns as an iterator the interface listeners associated to the source.
120      * @return Iterator
121      */

122     public Iterator JavaDoc getInterfaceListeners() {
123         if (nAryListeners == null) {
124             return KILIM.EMPTY_ITERATOR;
125         }
126         
127         return nAryListeners.iterator();
128     }
129 }
130
Popular Tags