KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
23
24 import org.objectweb.kilim.InternalException;
25 import org.objectweb.kilim.KilimException;
26 import org.objectweb.kilim.description.TemplateElementImpl;
27
28 /**
29  * @author horn.
30  * This abstract class is the implementation of the interface ComponentElement, It is thus
31  * the parent interface of all component element objects.It just contains a reference
32  * to the containing element and to the template description.
33  */

34     
35 public abstract class RtComponentElement implements ComponentElement, RuntimeElement {
36     protected static long nbComponent = 0;
37     protected static long nbElement = 0;
38         
39     public static long getNbComponent() {
40         return nbComponent;
41     }
42     
43     public static long getNbElement() {
44         return nbElement;
45     }
46     private ContainerElement container;
47     private TemplateElementImpl element;
48     
49     /**
50      * The protected constructor for a RtComponentElement.
51      * @param aElement : a reference to the template description of the element.
52      * @param aContainer : a reference to the containing element.
53      */

54     protected RtComponentElement(TemplateElementImpl aElement, ContainerElement aContainer) {
55         element = aElement;
56         container = aContainer;
57         nbElement++;
58     }
59     
60     /**
61      * @see org.objectweb.kilim.model.ComponentElement#getContainingElement()
62      */

63     public ContainerElement getContainingElement() {
64         return container;
65     }
66     
67     /**
68      * @see org.objectweb.kilim.model.ComponentElement#getContainingComponent()
69      */

70     public Component getContainingComponent() {
71         ContainerElement cont = getContainingElement();
72         while (cont != null && !cont.isComponent()) {
73             cont = cont.getContainingElement();
74         }
75         return (Component) cont;
76     }
77     
78     /**
79      * @see org.objectweb.kilim.model.ComponentElement#getElementDescription()
80      */

81     public TemplateElementImpl getElementDescription() {
82         return element;
83     }
84     
85     /**
86      * @see org.objectweb.kilim.model.ComponentElement#getTemplateDefHierarchy()
87      */

88     public Iterator JavaDoc getTemplateDefHierarchy() {
89         return element.getTemplateDefHierarchy();
90     }
91     
92     /**
93      * @see org.objectweb.kilim.model.ComponentElement#getQualifiedName()
94      */

95     public String JavaDoc getQualifiedName() {
96         if (container == null) {
97             return getLocalName();
98         }
99         
100         String JavaDoc contName = container.getQualifiedName();
101         
102         if ("".equals(contName)) {
103             return getLocalName();
104         }
105         
106         return contName + "/" + getLocalName();
107     }
108     
109     /**
110      * @see org.objectweb.kilim.model.RuntimeSource#getTarget()
111      */

112     public RuntimeElement getTarget() throws KilimException {
113         return this;
114     }
115     
116     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117
protected boolean containsElement(List JavaDoc aList, String JavaDoc aName) throws InternalException {
118         int lSize = aList.size();
119         if (lSize == 0) {
120             return false;
121         }
122         
123         for (int i = 0; i < lSize; i++) {
124             ComponentElement el = (ComponentElement) aList.get(i);
125             if (aName.equals(el.getLocalName())) {
126                 return true;
127             }
128         }
129         return false;
130     }
131     
132     protected Object JavaDoc removeElement(List JavaDoc aList, String JavaDoc aName) throws InternalException {
133         int lSize = aList.size();
134         if (lSize == 0) {
135             return null;
136         }
137         
138         for (int i = 0; i < lSize; i++) {
139             ComponentElement el = (ComponentElement) aList.get(i);
140             if (aName.equals(el.getLocalName())) {
141                 return aList.remove(i);
142             }
143         }
144         return null;
145     }
146     
147     protected Object JavaDoc getElement(List JavaDoc aList, String JavaDoc aName) throws InternalException {
148         int lSize = aList.size();
149         if (lSize == 0) {
150             return null;
151         }
152         
153         for (int i = 0; i < lSize; i++) {
154             ComponentElement el = (ComponentElement) aList.get(i);
155             if (aName.equals(el.getLocalName())) {
156                 return el;
157             }
158         }
159         return null;
160     }
161 }
Popular Tags