KickJava   Java API By Example, From Geeks To Geeks.

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


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 Port extends BasicNamedElementImpl {
26
27     /** a constant associated to the "this" port, a port bound to the Component object */
28     public static final Port THIS_PORT = new Port();
29         
30     private Arity arity;
31     private boolean isOffered;
32     
33     /**
34      * The public constructor for a port.
35      * @param aName : the local name of the port.
36      * @param aArity : the arity of the port.
37      * @param aStatus : the status of the port. It should be one of KILIM.PRIVATE, KILIM.PROTECTED, KILIM.PUBLIC.
38      * @param isP : true if the port is offered, false if not.
39      * @param aTemplate : the template in which the port is defined.
40      * @throws KilimException : generated if aName or aTemplate is null, or if aStatus has an illegal value,
41      */

42     public Port(String JavaDoc aName, Arity aArity, int aStatus, boolean isP, TemplateDescription aTemplate) throws KilimException {
43         super(aName, aStatus, true, false, aTemplate);
44         isOffered = isP;
45         arity = aArity;
46     }
47     
48     private Port() {
49         super("THIS", KILIM.PUBLIC, true, false);
50         isOffered = true;
51         arity = Arity.REQUIRED;
52     }
53     
54     /**
55      * returns whether the port is offered or not.
56      * @return boolean
57      */

58     public boolean isOffered() {
59         return isOffered;
60     }
61     
62     /**
63      * @see org.objectweb.kilim.description.BasicElement#getKind()
64      */

65     public int getKind() {
66         return KILIM.PORT;
67     }
68     
69     /**
70      * @see org.objectweb.kilim.description.NamedElement#setLocalName(String)
71      */

72     public void setLocalName(String JavaDoc aName) throws KilimException {
73         String JavaDoc oName = getLocalName();
74         super.setLocalName(aName);
75         TemplateDescription template = getContainingTemplate();
76         if (template != null) {
77             template.removeLocalPort(oName);
78             template.addLocalPort(this);
79         }
80     }
81         
82     /**
83      * @see org.objectweb.kilim.description.NamedElement#setStatus(int)
84      */

85     public void setStatus(int aStatus) throws KilimException {
86         super.setStatus(aStatus);
87         TemplateDescription template = getContainingTemplate();
88         if (template != null) {
89             template.removeLocalPort(getLocalName());
90             template.addLocalPort(this);
91         }
92     }
93     
94     /**
95      * @see org.objectweb.kilim.description.Port#isOptional()
96      */

97     public boolean isOptional() {
98         return arity == Arity.OPTIONAL;
99     }
100         
101     /**
102      * @see org.objectweb.kilim.description.Port#isUnary()
103      */

104     public boolean isUnary() {
105         return arity != Arity.COLLECTION;
106     }
107     
108     /**
109      * Returns the arity.
110      * @return Arity
111      */

112     public Arity getArity() {
113         return arity;
114     }
115     
116     /**
117      * Sets the arity.
118      * @param anArity The arity to set
119      * @throws KilimException :
120      */

121     public void setArity(Arity anArity) throws KilimException {
122         if (anArity == null) {
123             throw new KilimException("attempt to set a null arity to port " + getLocalName() + " in template " + getContainingTemplate().getName());
124         }
125         arity = anArity;
126     }
127 }
Popular Tags