KickJava   Java API By Example, From Geeks To Geeks.

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


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 class Instance extends TemplateElementImpl implements NamedElement {
26     private String JavaDoc localName;
27     private int status;
28     private TemplateDescription template;
29
30     /** Constructs a new Instance in a template
31      * @param aName identifies the Instance in its Template
32      * @param aStatus :indicates the status of the template
33      * (should be one of KILIM.PUBLIC, KILIM.PROTECTED, KILIM.PRIVATE)
34      * @param aTemplate :indicates the templates in which the template is defined.
35      * @param aContain :
36      * @throws KilimException : thrown when the name is null or the statu illegal.
37      */

38     public Instance(String JavaDoc aName, int aStatus, TemplateDescription aTemplate, TemplateDescription aContain) throws KilimException {
39         if (aName == null) {
40             throw new KilimException("illegal null name for a named template element in template " + getContainingTemplate().getName());
41         }
42         checkStatus(aStatus);
43         localName = aName;
44         status = aStatus;
45         template = aTemplate;
46         setContainingTemplate(aContain);
47     }
48     
49     /**
50      * @see org.objectweb.kilim.description.NamedElement#setLocalName(String)
51      */

52     public void setLocalName(String JavaDoc aName) throws KilimException {
53         String JavaDoc oName = getLocalName();
54         if (aName == null) {
55             throw new KilimException("null name in setting local name of a component " + oName + " in template " + getContainingTemplate().getName());
56         }
57         localName = aName;
58         TemplateDescription template = getContainingTemplate();
59         if (template != null) {
60             template.removeLocalInstance(oName);
61             template.addLocalInstance(this);
62         }
63     }
64     
65     /**
66      * @see org.objectweb.kilim.description.NamedElement#getLocalName()
67      */

68     public String JavaDoc getLocalName() {
69         return localName;
70     }
71     
72     /**
73      * @see org.objectweb.kilim.description.NamedElement#getStatus()
74      */

75     public int getStatus() {
76         return status;
77     }
78     
79     /**
80      * @see org.objectweb.kilim.description.TemplateElement#setStatus(int)
81      */

82     public void setStatus(int aStatus) throws KilimException {
83         checkStatus(aStatus);
84         status = aStatus;
85         TemplateDescription template = getContainingTemplate();
86         if (template != null) {
87             template.removeLocalInstance(getLocalName());
88             template.addLocalInstance(this);
89         }
90     }
91     
92     /**
93      * returns the template describing the instance.
94      * @return String
95      */

96     public TemplateDescription getTemplate() {
97         return template;
98     }
99
100     /**
101      * set the template describing the instance.
102      * @param aTemplate :
103      */

104     public void setTemplate(TemplateDescription aTemplate) {
105         template = aTemplate;
106     }
107
108     /**
109      * @see java.lang.Object#toString()
110      */

111     public String JavaDoc toString() {
112         return "[" + getLocalName() + "]";
113     }
114     
115     private void checkStatus(int aStatus) throws KilimException {
116         if (aStatus < 1 || aStatus > 3) {
117             throw new KilimException("illegal value " + aStatus + " for element " + localName);
118         }
119     }
120 }
Popular Tags