KickJava   Java API By Example, From Geeks To Geeks.

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


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

24 public class Reference extends TemplateElementImpl implements BasicElement {
25     private String JavaDoc targetName;
26     private BasicNamedElement boundElement;
27     private boolean performsAction;
28     private boolean providesValue;
29
30     /**
31      * a public constructor for references..
32      * @param aTargetName : the name of the target
33      * @param aTemplate : the template in which the reference is defined
34      * @param isP : true if the reference target provides a value (and can thus be used as a provider).
35      * @param isT : true if the reference target executes an action (and can thus be used as a transformer).
36      * @throws KilimException : generated if aTargetName or aTemplate is null.
37      */

38     public Reference(String JavaDoc aTargetName, TemplateDescription aTemplate, boolean isP, boolean isT) throws KilimException {
39         if (aTemplate == null) {
40             throw new KilimException("null template when constructing a reference");
41         }
42         if (aTargetName == null) {
43             throw new KilimException("null Name when constructing a reference in template " + aTemplate.getName());
44         }
45         targetName = aTargetName;
46         providesValue = isP;
47         performsAction = isT;
48         setContainingTemplate(aTemplate);
49     }
50     
51     /**
52      * sets the name of a target for the reference. Setting a new name resets the boundElement to null.
53      * @param aName : a name for the target.
54      */

55     public void setTargetName(String JavaDoc aName) {
56         if (aName == targetName) {
57             return;
58         }
59         targetName = aName;
60         boundElement = null;
61     }
62     
63     /**
64      * returns the name of the target.
65      * @return String
66      */

67     public String JavaDoc getTargetName() {
68         return targetName;
69     }
70         
71     /**
72      * @see org.objectweb.kilim.description.TemplateElement#setContainingTemplate(TemplateDescription)
73      */

74     public void setContainingTemplate(TemplateDescription aTemplate) throws KilimException {
75         if (aTemplate == null) {
76             throw new KilimException("attempt to set a null template to a reference to " + targetName + "in template " + getContainingTemplate());
77         }
78         super.setContainingTemplate(aTemplate);
79     }
80         
81     /**
82      * @see java.lang.Object#toString()
83      */

84     public String JavaDoc toString() {
85         if (targetName == null) {
86             return "[non initialized reference in template " + getContainingTemplate() + "]";
87         }
88         return "[" + targetName + "]";
89     }
90             
91     /**
92      * @see org.objectweb.kilim.description.ExtendedSource#isEventSource()
93      */

94     public boolean isEventSource() {
95         return false;
96     }
97     
98     /**
99      * @see org.objectweb.kilim.description.TemplateElement#providesValue()
100      */

101     public boolean providesValue() {
102         return providesValue;
103     }
104     
105     /**
106      * @see org.objectweb.kilim.description.TemplateElement#performsAction()
107      */

108     public boolean performsAction() {
109         return performsAction;
110     }
111     
112     /**
113      * @see org.objectweb.kilim.description.BasicElement#getKind()
114      */

115     public int getKind() {
116         return KILIM.REFERENCE;
117     }
118 }
119
Popular Tags