KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 import org.objectweb.kilim.KilimException;
24 import org.objectweb.kilim.description.Port;
25 import org.objectweb.kilim.description.Slot;
26 import org.objectweb.kilim.model.services.DefaultNamingContext;
27
28 /**
29  * @author horn
30  */

31 public class SlotFactory extends DefaultNamingContext implements Factory {
32     private String JavaDoc localName;
33     private ComponentFactory containingFactory;
34     
35     private Slot slotDescription;
36     private Component containingComponent;
37     
38     /**
39      * The public constructor for slot factories.
40      * @param aName :
41      * @param aFactory :
42      * @throws KilimException :
43      */

44
45     public SlotFactory(String JavaDoc aName, ComponentFactory aFactory) throws KilimException {
46         super(aName, aFactory);
47         localName = aName;
48         containingFactory = aFactory;
49         containingComponent = aFactory.getComponent();
50         if (containingFactory != null) {
51             containingFactory.addChildNamingContext(aName, this);
52         }
53     }
54     
55     /**
56      * returns the containing factory.
57      * @return ComponentFactory
58      */

59     public ComponentFactory getContainingFactory() {
60         return containingFactory;
61     }
62         
63     /**
64      * adds a SubFactory (should not be used !!)
65      * @param aElement :
66      * @throws KilimException : always generated since slots are terminal contrainers in the present model.
67      */

68     public void addSubFactory(ComponentFactory aElement) throws KilimException {
69         throw new KilimException("attempt to add a subfactory to slot factory " + getQualifiedName());
70     }
71     
72     /**
73      * removes a SubFactory (should not be used !!).
74      * @param aElement :
75      * @throws KilimException : always generated since slots are terminal contrainers in the present model.
76      */

77     public void removeSubFactory(ComponentFactory aElement) throws KilimException {
78         throw new KilimException("attempt to remove a subfactory from slot factory " + getQualifiedName());
79     }
80     
81     /**
82      * returns a subFactory (should not be used !!).
83      * @param aName :
84      * @return ComponentFactoryElement
85      * @throws KilimException : always generated since slots are terminal contrainers in the present model.
86      */

87     public ComponentFactory getSubFactory(String JavaDoc aName) throws KilimException {
88         throw new KilimException("attempt to get subfactory " + aName + " from slot factory " + getQualifiedName());
89     }
90     
91     /**
92      * Method getComponentFactorys.
93      * @return Iterator
94      * @throws KilimException :
95      */

96     public Iterator JavaDoc getSubFactories() throws KilimException {
97         throw new KilimException("attempt to get subfactories from slot factory " + getQualifiedName());
98     }
99         
100     /**
101      * creates a new runtime descriptor of a slot from an abstract descriptor of a slot.
102      * @param aSlot : the abstract descriptor of a slot
103      * @return RuntimeSlot
104      * @throws KilimException : generated if aSlot is null.
105      */

106     public RtComponentSlot newSlot(Slot aSlot) throws KilimException {
107         if (aSlot == null) {
108             throw new KilimException("attempt to create a null slot in component " + containingComponent.getQualifiedName());
109         }
110         
111         RtComponentSlot rSlot = new RtComponentSlot(aSlot, containingComponent, this);
112         //((RtComponent) containingComponent).addSlot(rSlot);
113
Iterator JavaDoc iter = aSlot.getPorts();
114         while (iter.hasNext()) {
115             Port elem = (Port) iter.next();
116             RtComponentInterface interf = newInterface(elem, rSlot);
117             rSlot.addInterface(interf);
118             addBoundName(interf.getLocalName(), interf);
119         }
120         return rSlot;
121     }
122     
123     private RtComponentInterface newInterface(Port port, RtComponentSlot aSlot) throws KilimException {
124         RtComponentInterface interf = null;
125         if (port.isUnary()) {
126             interf = new RtSingleValuePort(port, aSlot);
127         } else {
128             interf = new RtCollectionPort(port, aSlot);
129         }
130
131         String JavaDoc interfName;
132         String JavaDoc qualName = getQualifiedName();
133         if ("".equals(qualName)) {
134             interfName = port.getLocalName();
135         } else {
136             interfName = qualName + "/" + port.getLocalName();
137         }
138         return interf;
139     }
140 }
Popular Tags