KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 import org.objectweb.kilim.KilimException;
21
22 /**
23  * @author horn
24  */

25 public abstract class BasicNamedElementImpl extends TemplateElementImpl implements BasicNamedElement {
26     private String JavaDoc localName;
27     private int status;
28     private boolean isProvider;
29     private boolean isTransformer;
30     
31     /**
32      * This constructor is used internally by the kilim infrastructure.
33      * @param aName : the name of the basic element.
34      * @param aStatus : an int representing the status : should be one of KILIM.PRIVATE, KILIM.PROTECTED, KILIM.PUBLIC.
35      * @param isP :is true when the element provides a value (i.e. act as a provider).
36      * @param isT : is true when the element performs an action (i.e. act as a transformer).
37      * @param aTemplate : the template containing the element.
38      * @throws KilimException : generatyed when the name reference is null, when the template reference is null,
39      * when the status value is illegal.
40      */

41     protected BasicNamedElementImpl(String JavaDoc aName, int aStatus, boolean isP, boolean isT, TemplateDescription aTemplate) throws KilimException {
42         if (aName == null) {
43             if (aTemplate == null) {
44                 throw new KilimException("attempt to create a named element with a null name in a null template ");
45             } else {
46                 throw new KilimException("attempt to create a named element with a null name in template " + aTemplate.getName());
47             }
48         }
49         if (aTemplate == null) {
50             throw new KilimException("attempt to create a named element " + aName + " in a null template");
51         }
52         checkStatus(aStatus);
53         localName = aName;
54         status = aStatus;
55         isProvider = isP;
56         isTransformer = isT;
57         setContainingTemplate(aTemplate);
58     }
59
60     /**
61      * This constructor is used internally by the kilim infrastructure. No check is performed.
62      * @param aName : the name of the basic element.
63      * @param aStatus : an int representing the status : should be one of KILIM.PRIVATE, KILIM.PROTECTED, KILIM.PUBLIC.
64      * @param isP :is true when the element provides a value (i.e. act as a provider).
65      * @param isT : is true when the element performs an action (i.e. act as a transformer).
66      */

67     
68     protected BasicNamedElementImpl(String JavaDoc aName, int aStatus, boolean isP, boolean isT) {
69         localName = aName;
70         status = aStatus;
71         isProvider = isP;
72         isTransformer = isT;
73     }
74
75     /**
76      * @see org.objectweb.kilim.description.TemplateElement#getLocalName()
77      */

78     public String JavaDoc getLocalName() {
79         return localName;
80     }
81     
82     /**
83      * @see org.objectweb.kilim.description.TemplateElement#setLocalName(String)
84      */

85
86     public void setLocalName(String JavaDoc aName) throws KilimException {
87         if (aName == null) {
88             if (getContainingTemplate() == null) {
89                 throw new KilimException("attempt to set a null name to element " + localName + " in a null template ");
90             } else {
91                 throw new KilimException("attempt to set a null name to element " + localName + " in template " + getContainingTemplate().getName()); }
92         }
93         localName = aName;
94     }
95     
96     /**
97      * @see org.objectweb.kilim.description.TemplateElement#getStatus()
98      */

99     public int getStatus() {
100         return status;
101     }
102     
103     /**
104      * @see org.objectweb.kilim.description.TemplateElement#setStatus(int)
105      */

106     public void setStatus(int aStatus) throws KilimException {
107         checkStatus(aStatus);
108         status = aStatus;
109     }
110             
111     /**
112      * @see org.objectweb.kilim.description.TemplateElement#providesValue()
113      */

114     public boolean providesValue() {
115         return isProvider;
116     }
117     
118     /**
119      * @see org.objectweb.kilim.description.TemplateElement#performsAction()
120      */

121     public boolean performsAction() {
122         return isTransformer;
123     }
124     
125     /**
126      * @see org.objectweb.kilim.description.BasicElement#isEventSource()
127      */

128     public boolean isEventSource() {
129         return false;
130     }
131
132     /**
133      * @see org.objectweb.kilim.description.TemplateElement#setContainingTemplate(TemplateDescription)
134      */

135     public void setContainingTemplate(TemplateDescription aTemplate) throws KilimException {
136         if (aTemplate == null) {
137             throw new KilimException("attempt to set a null template to element " + localName + " in template " + getContainingTemplate().getName());
138         }
139         super.setContainingTemplate(aTemplate);
140     }
141                 
142     /**
143      * @see java.lang.Object#toString()
144      */

145     public String JavaDoc toString() {
146         return getLocalName() + "in template " + getContainingTemplate();
147     }
148     
149     private void checkStatus(int aStatus) throws KilimException {
150         if (aStatus < 1 || aStatus > 3) {
151             throw new KilimException("illegal value " + aStatus + " for element " + localName);
152         }
153     }
154 }
Popular Tags