KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Collection;
20 import java.util.HashSet;
21 import java.util.LinkedHashMap;
22 import java.util.Set;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.ArrayList;
26
27 import org.objectweb.kilim.InternalException;
28 import org.objectweb.kilim.KilimException;
29 import org.objectweb.kilim.repository.ResourceLoader;
30
31 /**
32  * @author horn
33  * This is the class for Kilim templates.
34  */

35
36 public class TemplateDescription {
37
38     private static final Object LOCK = new Object();
39     
40     private static final int PROVIDER_REFERENCE = 1;
41     private static final int TRANSFORMER_REFERENCE = 2;
42
43     private static final int PROVIDER_KEY = 1;
44     private static final int TRANSFORMER_KEY = 2;
45     private static final int PROPERTY_KEY = 3;
46     private static final int INSTANCE_KEY = 4;
47     private static final int PORT_KEY = 5;
48     private static final int TRIGGER_KEY = 6;
49     private static final int BINDING_KEY = 7;
50     private static final int SLOT_KEY = 8;
51     private static final int PLUG_KEY = 9;
52     private static final int ANY_PROVIDER_KEY = 10;
53     
54     private static final int LEGAL_OVERRIDE = 1;
55     private static final int ILLEGAL_OVERRIDE = 2;
56     private static final int NAME_CLASH = 3;
57     private static final int NO_OVERRIDE = 4;
58     
59     private String name;
60     private TemplateDescription superTemplate;
61     
62     private LinkedHashMap transformers;
63     private LinkedHashMap instances;
64     private LinkedHashMap slots;
65     private LinkedHashMap references;
66     private LinkedHashMap allProviders;
67     
68     private Set subTemplates;
69     private List triggers;
70     private List plugs;
71     private List bindings;
72     
73     private ResourceLoader resourceLoader;
74     
75     private class ReferenceData {
76         int referenceKind;
77         Object reference;
78         
79         ReferenceData(int aKind, Object aReference) {
80             referenceKind = aKind;
81             reference = aReference;
82         }
83     }
84     
85     private class ProviderData {
86         int referenceKind;
87         NamedElement provider;
88         
89         ProviderData(int aKind, NamedElement aProvider) {
90             referenceKind = aKind;
91             provider = aProvider;
92         }
93     }
94         
95     /**
96      * A public constructor to be used to build a template extending an existing template
97      * @param aName : the name of the template (which must be non null)
98      * @param aSuperTemplate : the reference of the super template (xhich can be null)
99      * @throws KilimException : thrown when name is null.
100      */

101     public TemplateDescription(String aName, TemplateDescription aSuperTemplate) throws KilimException {
102         if (aName == null) {
103             if (superTemplate != null) {
104                 throw new KilimException("attempt to create a sub-template with a null name in template " + aSuperTemplate);
105             } else {
106                 throw new KilimException("attempt to create a sub-template with a null name ");
107             }
108         }
109         name = aName;
110         
111         superTemplate = aSuperTemplate;
112         if (superTemplate != null) {
113             superTemplate.addSubTemplate(this);
114         }
115     }
116     
117     /**
118      * To be used to build a top level template (i.e. a template without super template).
119      * @param aName : the name of the template (which must be non null)
120      * @throws KilimException : thrown when name is null
121      */

122     public TemplateDescription(String aName) throws KilimException {
123         this(aName, null);
124     }
125     
126     /**
127      * @see org.objectweb.kilim.description.Template#getName()
128      */

129     public String getName() {
130         return name;
131     }
132     
133     /**
134      * @see org.objectweb.kilim.description.Template#setName(String)
135      */

136     public void setName(String aName) throws KilimException {
137         if (aName == null) {
138             throw new KilimException("illegal null name in setName of TemplateImpl");
139         }
140         name = aName;
141     }
142         
143     /**
144      * @see org.objectweb.kilim.description.Template#getSuperTemplate()
145      */

146     public TemplateDescription getSuperTemplate() {
147         return superTemplate;
148     }
149
150     /**
151      * @see org.objectweb.kilim.description.Template#setSuperTemplate(Template)
152      */

153     public void setSuperTemplate(TemplateDescription aTemplate) throws KilimException {
154         if (superTemplate != null) {
155             superTemplate.removeSubTemplate(this);
156         }
157         superTemplate = aTemplate;
158         if (superTemplate != null) {
159             superTemplate.addSubTemplate(this);
160         }
161     }
162     
163     /**
164      * @see org.objectweb.kilim.description.Template#addSubTemplate(Template)
165      */

166     public void addSubTemplate(TemplateDescription aTemplate) throws KilimException {
167         if (aTemplate == null) {
168             throw new KilimException("null template in addSubTemplate");
169         }
170         if (subTemplates == null) {
171             subTemplates = new HashSet();
172         }
173         subTemplates.add(aTemplate);
174         
175         Iterator iter = getPorts(false);
176         while (iter.hasNext()) {
177             NamedElement element = (NamedElement) iter.next();
178             addSubTemplate1(element, PORT_KEY, aTemplate);
179         }
180         iter = getProperties(false);
181         while (iter.hasNext()) {
182             NamedElement element = (NamedElement) iter.next();
183             addSubTemplate1(element, PROPERTY_KEY, aTemplate);
184         }
185         iter = getProviders(false);
186         while (iter.hasNext()) {
187             NamedElement element = (NamedElement) iter.next();
188             addSubTemplate1(element, PROVIDER_KEY, aTemplate);
189         }
190         iter = getTransformers(false);
191         while (iter.hasNext()) {
192             NamedElement element = (NamedElement) iter.next();
193             addSubTemplate1(element, TRANSFORMER_KEY, aTemplate);
194         }
195     }
196     
197     private void addSubTemplate1(NamedElement element, int tabKey, TemplateDescription aTemplate) throws KilimException {
198         String eName = element.getLocalName();
199         int status = element.getStatus();
200         boolean canOverride = (status == KILIM.PUBLIC || status == KILIM.PROTECTED);
201         int result = aTemplate.checkDownOverride(eName, tabKey, canOverride);
202         if (result == NAME_CLASH) {
203             throw new KilimException("setting template " + name + " as super template of " + aTemplate + " leads to a name clash for" + eName);
204         }
205         if (result == ILLEGAL_OVERRIDE) {
206             throw new KilimException("setting template " + name + " as super template of " + aTemplate + " leads to an illegal override" + eName);
207         }
208     }
209         
210     /**
211      * @see org.objectweb.kilim.description.Template#removeSubTemplate(Template)
212      */

213     public void removeSubTemplate(TemplateDescription aTemplate) throws KilimException {
214         if (aTemplate == null) {
215             throw new KilimException("illegal null template in removeSubTemplate");
216         }
217         subTemplates.remove(aTemplate);
218     }
219     
220     /**
221      * @see org.objectweb.kilim.description.Template#getSubTemplates()
222      */

223     public Iterator getSubTemplates() {
224         if (subTemplates == null) {
225             return KILIM.EMPTY_ITERATOR;
226         }
227         return subTemplates.iterator();
228     }
229     
230     /**
231      * Method getTemplateDefHierarchy returns an iterator providing all the template elements overriden by a given element.
232      * The iterator contains the base element used for the look up.
233      * @param aElement : the base element used for the look up.
234      * @return Iterator
235      * @throws KilimException :
236      */

237     public Iterator getTemplateDefHierarchy(TemplateElementImpl aElement) throws KilimException {
238         String lName = null;
239         if (aElement instanceof Port) {
240             lName = ((Port) aElement).getLocalName();
241             return getMapDefHierarchy(lName, PORT_KEY);
242         }
243         if (aElement instanceof Property) {
244             lName = ((Property) aElement).getLocalName();
245             return getMapDefHierarchy(lName, PROPERTY_KEY);
246         }
247         if (aElement instanceof Provider) {
248             lName = ((Provider) aElement).getLocalName();
249             return getMapDefHierarchy(lName, PROVIDER_KEY);
250         }
251         if (aElement instanceof Transformer) {
252             lName = ((Transformer) aElement).getLocalName();
253             return getMapDefHierarchy(lName, TRANSFORMER_KEY);
254         }
255         if (aElement instanceof Slot) {
256             lName = ((Slot) aElement).getLocalName();
257             return getMapDefHierarchy(lName, SLOT_KEY);
258         }
259         if (aElement instanceof Instance) {
260             lName = ((Instance) aElement).getLocalName();
261             return getMapDefHierarchy(lName, INSTANCE_KEY);
262         }
263         if (aElement instanceof Binding) {
264             lName = ((Binding) aElement).getPortName();
265             return getListDefHierarchy(lName, BINDING_KEY);
266         }
267         if (aElement instanceof Trigger) {
268             lName = ((Trigger) aElement).getSourceName();
269             return getListDefHierarchy(lName, TRIGGER_KEY);
270         }
271         if (aElement instanceof Plug) {
272             lName = ((Plug) aElement).getSlotName();
273             return getListDefHierarchy(lName, PLUG_KEY);
274         }
275         return KILIM.EMPTY_ITERATOR;
276     }
277     
278     /**
279      * Method getAllMapContainingTemplates.
280      * @param aName :
281      * @param tabKey :
282      * @return Iterator
283      * @throws KilimException :
284      */

285     private Iterator getMapDefHierarchy(String aName, int tabKey) throws KilimException {
286         if (aName == null) {
287             throw new KilimException("attempt to get the containing templates of an element through a null name");
288         }
289         
290         TemplateDescription tmp0 = this;
291         List list = new ArrayList();
292         do {
293             NamedElement elem = tmp0.getLocalMapElement(aName, tabKey);
294             if (elem != null) {
295                 list.add(tmp0);
296             }
297         } while ((tmp0 = tmp0.getSuperTemplate()) != null);
298         if (list.size() == 0) {
299             return KILIM.EMPTY_ITERATOR;
300         }
301         return list.iterator();
302     }
303
304         
305     private Iterator getListDefHierarchy(String aName, int tabKey) throws KilimException {
306         if (aName == null) {
307             throw new KilimException("attempt to get the containing templates of an element through a null name");
308         }
309         
310         TemplateDescription tmp0 = this;
311         List list = new ArrayList();
312         do {
313             Iterator iter = tmp0.getLocalListElements(aName, tabKey);
314             if (iter != KILIM.EMPTY_ITERATOR) {
315                 list.add(tmp0);
316             }
317         } while ((tmp0 = tmp0.getSuperTemplate()) != null);
318         if (list.size() == 0) {
319             return KILIM.EMPTY_ITERATOR;
320         }
321         return list.iterator();
322     }
323     
324     /**
325      * @see org.objectweb.kilim.description.Template#getPort(String, boolean)
326      */

327     public BasicNamedElement getAnyProvider(String aName, boolean onlyLocal) throws KilimException {
328         LinkedHashMap map = getMap(ANY_PROVIDER_KEY, false);
329         BasicNamedElement provider = null;
330         if (map != null) {
331             ProviderData data = (ProviderData) map.get(aName);
332             if (data != null) {
333                 provider = (BasicNamedElement) data.provider;
334             }
335         }
336         if (provider != null || onlyLocal || superTemplate == null) {
337             return provider;
338         }
339         return (BasicNamedElement) getSuperTemplate().getRMapElement(aName, ANY_PROVIDER_KEY);
340     }
341
342     /**
343      * @see org.objectweb.kilim.description.Template#getProviderMap(boolean)
344      */

345     public Iterator getProviders(boolean onlyLocal) throws KilimException {
346         List list = new ArrayList();
347         Iterator iter = getAllInterfaces(onlyLocal);
348         while (iter.hasNext()) {
349             Object elem = iter.next();
350             if (elem instanceof Provider) {
351                 list.add(elem);
352             }
353         }
354
355         if (list.size() == 0) {
356             return KILIM.EMPTY_ITERATOR;
357         }
358         return list.iterator();
359     }
360
361     /**
362      * @see org.objectweb.kilim.description.Template#getProviderMap(boolean)
363      */

364     public Iterator getPorts(boolean onlyLocal) throws KilimException {
365         List list = new ArrayList();
366         Iterator iter = getAllInterfaces(onlyLocal);
367         while (iter.hasNext()) {
368             Object elem = iter.next();
369             if (elem instanceof Port) {
370                 list.add(elem);
371             }
372         }
373
374         if (list.size() == 0) {
375             return KILIM.EMPTY_ITERATOR;
376         }
377         return list.iterator();
378     }
379
380     /**
381      * @see org.objectweb.kilim.description.Template#getProviderMap(boolean)
382      */

383     public Iterator getProperties(boolean onlyLocal) throws KilimException {
384         List list = new ArrayList();
385         Iterator iter = getAllInterfaces(onlyLocal);
386         while (iter.hasNext()) {
387             Object elem = iter.next();
388             if (elem instanceof Property) {
389                 list.add(elem);
390             }
391         }
392
393         if (list.size() == 0) {
394             return KILIM.EMPTY_ITERATOR;
395         }
396         return list.iterator();
397     }
398
399     /**
400      * @see org.objectweb.kilim.description.Template#getPort(String, boolean)
401      */

402     public Slot getSlot(String aName, boolean onlyLocal) throws KilimException {
403         LinkedHashMap map = getMap(SLOT_KEY, false);
404         Slot slot = null;
405         if (map != null) {
406             slot = (Slot) map.get(aName);
407         }
408             
409         if (slot != null || onlyLocal || superTemplate == null) {
410             return slot;
411         }
412
413         return (Slot) getSuperTemplate().getRMapElement(aName, SLOT_KEY);
414     }
415         
416     /**
417      * @see org.objectweb.kilim.description.Template#getPortMap(boolean)
418      */

419     public Iterator getSlots(boolean onlyLocal) throws KilimException {
420         if (onlyLocal) {
421             if (slots == null) {
422                 return KILIM.EMPTY_ITERATOR;
423             }
424             return slots.values().iterator();
425         }
426         
427         LinkedHashMap map = new LinkedHashMap();
428         addMapVisible(map, SLOT_KEY, false);
429         return map.values().iterator();
430     }
431                     
432     /**
433      * @see org.objectweb.kilim.description.Template#getTransformer(String, boolean)
434      */

435     public BasicNamedElement getTransformer(String aName, boolean onlyLocal) throws KilimException {
436         LinkedHashMap map = getMap(TRANSFORMER_KEY, false);
437         BasicNamedElement transformer = null;
438         if (map != null) {
439             transformer = (BasicNamedElement) map.get(aName);
440         }
441
442         if (transformer != null || onlyLocal || superTemplate == null) {
443             return transformer;
444         }
445         return (BasicNamedElement) ((TemplateDescription) superTemplate).getRMapElement(aName, TRANSFORMER_KEY);
446     }
447
448     /**
449      * @see org.objectweb.kilim.description.Template#getTransformerMap(boolean)
450      */

451     public Iterator getTransformers(boolean onlyLocal) throws KilimException {
452         if (onlyLocal) {
453             if (transformers == null) {
454                 return KILIM.EMPTY_ITERATOR;
455             }
456             return transformers.values().iterator();
457         }
458         
459         LinkedHashMap map = new LinkedHashMap();
460         addMapVisible(map, TRANSFORMER_KEY, false);
461         return map.values().iterator();
462     }
463
464     /**
465      * @see org.objectweb.kilim.description.Template#getInstance(String, boolean)
466      */

467     public Instance getInstance(String aName, boolean onlyLocal) throws KilimException {
468         LinkedHashMap map = getMap(INSTANCE_KEY, false);
469         Instance instance = null;
470         if (map != null) {
471             instance = (Instance) map.get(aName);
472         }
473         
474         if (instance != null || onlyLocal || superTemplate == null) {
475             return instance;
476         }
477         return (Instance) ((TemplateDescription) superTemplate).getRMapElement(aName, INSTANCE_KEY);
478     }
479             
480     /**
481      * @see org.objectweb.kilim.description.Template#getInstanceMap(boolean)
482      */

483     public Iterator getInstances(boolean onlyLocal) throws KilimException {
484         if (onlyLocal) {
485             if (instances == null) {
486                 return KILIM.EMPTY_ITERATOR;
487             }
488             return instances.values().iterator();
489         }
490         
491         LinkedHashMap map = new LinkedHashMap();
492         addMapVisible(map, INSTANCE_KEY, false);
493         
494         Collection vls = map.values();
495         return vls.iterator();
496     }
497     
498     /**
499      * @see org.objectweb.kilim.description.Template#addProviderReference(ProviderReference)
500      */

501     public void addProviderReference(Reference reference) throws KilimException {
502         if (reference == null) {
503             throw new KilimException("illegal null reference in addProviderReference of TemplateImpl " + name);
504         }
505         if (!reference.providesValue()) {
506             throw new KilimException("illegal attempt to use a non provider reference in addProvider");
507         }
508         
509         String rName = reference.getTargetName();
510         if (rName == null) {
511             throw new KilimException("illegal null name in addProvider of TemplateImpl " + name);
512         }
513         ReferenceData data = (ReferenceData) getReferenceMap().get(rName);
514         
515         if (data == null) {
516             getReferenceMap().put(rName, new ReferenceData(PROVIDER_REFERENCE, reference));
517             return;
518         }
519     }
520     
521     /**
522      * @see org.objectweb.kilim.description.Template#removeProviderReference(String)
523      */

524     public void removeProviderReference(String aName) throws KilimException {
525         if (aName == null) {
526             throw new KilimException("illegal null name in removeProviderReference of TemplateImpl " + name);
527         }
528
529         ReferenceData data = (ReferenceData) getReferenceMap().get(aName);
530         
531         if (data == null) {
532             throw new KilimException("name " + aName + " is unknown in removeProviderReference of TemplateImpl" + name);
533         }
534         
535         if (data.referenceKind == PROVIDER_REFERENCE) {
536             getReferenceMap().remove(aName);
537         } else {
538             throw new KilimException("use of a transformer name in removeProviderReference of TemplateImpl " + name);
539         }
540     }
541     
542     /**
543      * @see org.objectweb.kilim.description.Template#getProviderReference(String, boolean)
544      */

545     public Reference getProviderReference(String aName, boolean onlyLocal) throws KilimException {
546         if (aName == null) {
547             throw new KilimException("illegal null name in getProviderReference of TemplateImpl" + name);
548         }
549
550         ReferenceData data = (ReferenceData) getReferenceMap().get(aName);
551                 
552         if (data == null) {
553             //throw new KilimException("name " + aName + " is unknown in getProviderReference of TemplateImpl " + name);
554
return null;
555         }
556         
557         if (data.referenceKind == PROVIDER_REFERENCE) {
558             return (Reference) data.reference;
559         } else {
560             throw new KilimException("use of a transformer name in removeProviderReference of TemplateImpl " + name);
561         }
562     }
563         
564     /**
565      * @see org.objectweb.kilim.description.Template#getTransformerReference(String, boolean)
566      */

567     public Reference getTransformerReference(String aName, boolean onlyLocal) throws KilimException {
568         if (aName == null) {
569             throw new KilimException("illegal null name in getTransformerReference of TemplateImpl " + name);
570         }
571
572         ReferenceData data = (ReferenceData) getReferenceMap().get(aName);
573         
574         if (data == null) {
575             //throw new KilimException("name " + aName + " is unknown in getTransformerReference of TemplateImpl " + name);
576
return null;
577         }
578         
579         if (data.referenceKind == TRANSFORMER_REFERENCE) {
580             return (Reference) data.reference;
581         } else {
582             throw new KilimException("use of a transformer name in removeProviderReference of TemplateImpl " + name);
583         }
584     }
585
586     /**
587      * @see org.objectweb.kilim.description.Template#getUnresolvedProviderReferences()
588      */

589     public Iterator getProviderReferences(boolean onlyLocal) {
590         List list = new ArrayList();
591         getReferences(list, onlyLocal, PROVIDER_REFERENCE);
592         return list.listIterator();
593     }
594
595     /**
596      * @see org.objectweb.kilim.description.Template#addTransformerReference(TransformerReference)
597      */

598     public void addTransformerReference(Reference reference) throws KilimException {
599         if (reference == null) {
600             throw new KilimException("illegal null reference in addProviderReference of TemplateImpl " + name);
601         }
602         if (!reference.performsAction()) {
603             throw new KilimException("attempt to use a non transformer reference in addTransformer");
604         }
605         
606         String rName = reference.getTargetName();
607         if (rName == null) {
608             throw new KilimException("illegal null name in addTransformer of TemplateImpl");
609         }
610         ReferenceData data = (ReferenceData) getReferenceMap().get(rName);
611         
612         if (data == null) {
613             getReferenceMap().put(rName, new ReferenceData(TRANSFORMER_REFERENCE, reference));
614             return;
615         }
616     }
617     
618     /**
619      * @see org.objectweb.kilim.description.Template#removeProviderReference(String)
620      */

621     public void removeTransformerReference(String aName) throws KilimException {
622         if (aName == null) {
623             throw new KilimException("illegal null name in removeTransformerReference of TemplateImpl " + name);
624         }
625
626         ReferenceData data = (ReferenceData) getReferenceMap().get(aName);
627         
628         if (data == null) {
629             throw new KilimException("transformer name " + aName + " is unknown in removeTransformerReference of TemplateImpl " + name);
630         }
631         
632         if (data.referenceKind == TRANSFORMER_REFERENCE) {
633             getReferenceMap().remove(aName);
634         } else {
635             throw new KilimException("use of a provider name in removeTransformerReference of TemplateImpl " + name);
636         }
637     }
638         
639     /**
640      * @see org.objectweb.kilim.description.Template#getUnresolvedTransformerReferences()
641      */

642     public Iterator getTransformerReferences(boolean onlyLocal) {
643         List list = new ArrayList();
644         getReferences(list, onlyLocal, TRANSFORMER_REFERENCE);
645         return list.listIterator();
646     }
647         
648     /**
649      * @see org.objectweb.kilim.description.Template#getReference(String, boolean)
650      */

651     public Reference getReference(String aName, boolean onlyLocal) throws KilimException {
652         if (aName == null) {
653             throw new KilimException("illegal null name in getProviderReference of TemplateImpl" + name);
654         }
655
656         ReferenceData data = (ReferenceData) getReferenceMap().get(aName);
657         
658         if (data == null) {
659             return null;
660         }
661         
662         return (Reference) data.reference;
663     }
664
665     /**
666      * @see org.objectweb.kilim.description.Template#addLocalPort(Port)
667      */

668     public void addLocalPort(Port port) throws KilimException {
669         addLocalMapElement(port, PORT_KEY);
670     }
671     
672     /**
673      * @see org.objectweb.kilim.description.Template#removeLocalPort(String)
674      */

675     public void removeLocalPort(String aName) throws KilimException {
676         removeLocalMapElement(aName, PORT_KEY);
677     }
678     
679     /**
680      * @see org.objectweb.kilim.description.Template#addLocalProperty(Property)
681      */

682     public void addLocalProperty(Property property) throws KilimException {
683         addLocalMapElement(property, PROPERTY_KEY);
684     }
685
686     /**
687      * @see org.objectweb.kilim.description.Template#removeLocalProperty(String)
688      */

689     public void removeLocalProperty(String aName) throws KilimException {
690         removeLocalMapElement(aName, PROPERTY_KEY);
691     }
692
693     /**
694      * @see org.objectweb.kilim.description.Template#addProvider(Provider)
695      */

696     public void addLocalProvider(BasicNamedElement aProvider) throws KilimException {
697         addLocalMapElement(aProvider, PROVIDER_KEY);
698     }
699
700     /**
701      * @see org.objectweb.kilim.description.Template#removeLocalProvider(String)
702      */

703     public void removeLocalProvider(String aName) throws KilimException {
704         removeLocalMapElement(aName, PROVIDER_KEY);
705     }
706
707     /**
708      * @see org.objectweb.kilim.description.Template#addLocalTransformer(Transformer)
709      */

710     public void addLocalTransformer(BasicNamedElement transformer) throws KilimException {
711         addLocalMapElement(transformer, TRANSFORMER_KEY);
712     }
713
714     /**
715      * @see org.objectweb.kilim.description.Template#removeLocalTransformer(String)
716      */

717     public void removeLocalTransformer(String aName) throws KilimException {
718         removeLocalMapElement(aName, TRANSFORMER_KEY);
719     }
720
721     /**
722      * @see org.objectweb.kilim.description.Template#addInstance(Instance)
723      */

724     public void addLocalInstance(Instance aInstance) throws KilimException {
725         addLocalMapElement(aInstance, INSTANCE_KEY);
726     }
727
728     /**
729      * @see org.objectweb.kilim.description.Template#removeLocalInstance(String)
730      */

731     public void removeLocalInstance(String aName) throws KilimException {
732         removeLocalMapElement(aName, INSTANCE_KEY);
733     }
734     
735     /**
736      * adds a slot declatation in the template description.
737      * @param aSlot : the slot to be added.
738      * @throws KilimException : generated when aSlot is null or has already been added previously.
739      */

740     public void addLocalSlot(Slot aSlot) throws KilimException {
741         addLocalMapElement(aSlot, SLOT_KEY);
742     }
743     
744     /**
745      * removes a slot definition from a template description.
746      * @param aName : the name of the the slot to be removed.
747      * @throws KilimException : generated when aSlot is null or unknown.
748      */

749     public void removeLocalSlot(String aName) throws KilimException {
750         removeLocalMapElement(aName, SLOT_KEY);
751     }
752
753     /**
754      * @see org.objectweb.kilim.description.Template#addLocalTrigger(Trigger)
755      */

756     public void addLocalTrigger(Trigger aTrigger) throws KilimException {
757         addLocalListElement(aTrigger, TRIGGER_KEY);
758     }
759     
760     /**
761      * @see org.objectweb.kilim.description.Template#removeLocalTrigger(Trigger)
762      */

763     public void removeLocalTrigger(Trigger aTrigger) throws KilimException {
764         removeLocalListElement(aTrigger, TRIGGER_KEY);
765     }
766         
767     /**
768      * @see org.objectweb.kilim.description.Template#addBinding(Binding)
769      */

770     public void addLocalBinding(Binding aBinding) throws KilimException {
771         addLocalListElement(aBinding, BINDING_KEY);
772     }
773     
774     /**
775      * @see org.objectweb.kilim.description.Template#removeBinding(String)
776      */

777     public void removeLocalBinding(Binding aBinding) throws KilimException {
778         removeLocalListElement(aBinding, BINDING_KEY);
779     }
780     
781         /**
782      * @see org.objectweb.kilim.description.Template#addBinding(Binding)
783      */

784     public void addLocalPlug(Plug aPlug) throws KilimException {
785         addLocalListElement(aPlug, PLUG_KEY);
786     }
787     
788     /**
789      * @see org.objectweb.kilim.description.Template#removeLocalPlug(String)
790      */

791     public void removeLocalPlug(Plug aPlug) throws KilimException {
792         removeLocalListElement(aPlug, PLUG_KEY);
793     }
794         
795     /**
796      * @see org.objectweb.kilim.description.Template#getTrigger(String, boolean)
797      */

798     public Iterator getTriggers(String aName, boolean onlyLocal) {
799         if (onlyLocal) {
800             return getLocalListElements(aName, TRIGGER_KEY);
801         }
802         
803         List list = new ArrayList();
804         addVisibleListElements(list, aName, TRIGGER_KEY);
805         return list.listIterator();
806     }
807     
808     /**
809      * @see org.objectweb.kilim.description.Template#getTrigger(String, boolean)
810      */

811     public Iterator getBindings(String aName, boolean onlyLocal) {
812         if (onlyLocal) {
813             return getLocalListElements(aName, BINDING_KEY);
814         }
815         
816         List list = new ArrayList();
817         addVisibleListElements(list, aName, BINDING_KEY);
818         return list.listIterator();
819     }
820
821     /**
822      * @see org.objectweb.kilim.description.Template#getTrigger(String, boolean)
823      */

824     public Iterator getPlugs(String aName, boolean onlyLocal) {
825         if (onlyLocal) {
826             return getLocalListElements(aName, PLU