KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > ide > AspectConfiguration


1 /*
2   Copyright (C) 2002 Renaud Pawlak <renaud@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program 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
12   GNU 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 program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.ide;
20
21 import java.lang.Class JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.Vector JavaDoc;
26 import org.objectweb.jac.core.ACManager;
27 import org.objectweb.jac.core.AspectComponent;
28 import org.objectweb.jac.core.Jac;
29 import org.objectweb.jac.util.File;
30
31 public class AspectConfiguration extends ModelElement {
32
33     public AspectConfiguration() {
34     }
35
36     public AspectConfiguration(String JavaDoc aspectName) {
37         this.name = aspectName;
38     }
39
40     public String JavaDoc toString() {
41         String JavaDoc _name=null;
42         if (name != null) {
43             _name=name;
44         } else if(aspect!=null) {
45             _name=aspect.getName();
46         }
47         if (_name!=null) {
48             if(woven)
49                 return _name+" *";
50             else
51                 return _name;
52         } else {
53             return super.toString();
54         }
55     }
56
57     Application application;
58
59     /**
60      * Get the value of application.
61      * @return value of application.
62      */

63     public Application getApplication() {
64         return application;
65     }
66
67     /**
68      * Set the value of application.
69      * @param v Value to assign to application.
70      */

71     public void setApplication(Application v) {
72         this.application = v;
73     }
74
75     String JavaDoc name;
76
77     /**
78      * Get the value of name.
79      * @return value of name.
80      */

81     public String JavaDoc getName() {
82         return name;
83     }
84
85     /**
86      * Set the value of name.
87      * @param v Value to assign to name.
88      */

89     public void setName(String JavaDoc v) {
90         this.name = v;
91     }
92
93     public static Set JavaDoc getDeclaredAspects(Object JavaDoc substance) {
94         return ACManager.getACM().getDeclaredACs();
95     }
96
97     Aspect aspect;
98
99     /**
100      * Get the value of aspect.
101      * @return value of aspect.
102      */

103     public Aspect getAspect() {
104         return aspect;
105     }
106
107     /**
108      * Set the value of aspect.
109      * @param v Value to assign to aspect.
110      */

111     public void setAspect(Aspect v) {
112         this.aspect = v;
113     }
114
115     boolean woven = true;
116
117     /**
118      * Get the value of woven.
119      * @return value of woven.
120      */

121     public boolean isWoven() {
122         return woven;
123     }
124
125     /**
126      * Set the value of woven.
127      * @param v Value to assign to woven.
128      */

129     public void setWoven(boolean v) {
130         this.woven = v;
131     }
132
133     public boolean canReload() {
134         return application!=null && application.isStarted() && application.isDistributionEnabled();
135     }
136
137     /**
138      * Reloads the configuration in the running process.
139      */

140     public void reload() throws Throwable JavaDoc/*IOException*/ {
141         if (!application.isStarted()) {
142             org.objectweb.jac.aspects.gui.Actions.showStatus(
143                 "Application is not started: cannot reload configuration");
144             return;
145         }
146
147         org.objectweb.jac.aspects.gui.Actions.showStatus("Reloading aspect configuration '"+
148                                                          name+"'...");
149
150         Jac.remoteReloadAspect(getApplication().getName(),
151                                getApplication().getServerName(),name);
152     }
153
154     String JavaDoc configurationCode = "";
155
156     /**
157      * Get the value of configurationCode.
158      * @return value of configurationCode.
159      */

160     public String JavaDoc getConfigurationCode() {
161         return configurationCode;
162     }
163
164     /**
165      * Set the value of configurationCode.
166      * @param v Value to assign to configurationCode.
167      */

168     public void setConfigurationCode(String JavaDoc v) {
169         this.configurationCode = v;
170     }
171
172     String JavaDoc defaultConfigurationCode = "";
173
174     /**
175      * Get the value of defaultConfigurationCode.
176      * @return value of defaultConfigurationCode.
177      */

178     public String JavaDoc getDefaultConfigurationCode() {
179         return defaultConfigurationCode;
180     }
181
182     /**
183      * Set the value of defaultConfigurationCode.
184      * @param v Value to assign to defaultConfigurationCode.
185      */

186     public void setDefaultConfigurationCode(String JavaDoc v) {
187         this.defaultConfigurationCode = v;
188     }
189
190
191     private List JavaDoc configItems=new Vector JavaDoc();
192
193     /**
194      * add a new ConfigItem on this Element
195      * @param config the new ConfigItem
196      */

197     public void addConfigItem(ConfigItem config){
198         configItems.add(config);
199     }
200
201     /**
202      * remove an ConfigItem
203      * @param config the ConfigItem
204      */

205     public void removeConfigItem(ConfigItem config){
206         configItems.remove(config);
207     }
208
209     /**
210      * Returns all the configuration methods of the aspect
211      * @return a collection of java.lang.reflect.Method
212      */

213     public Collection JavaDoc getConfigurationMethods()
214     {
215         String JavaDoc acClassName = ACManager.getACM().getACPathFromName(name);
216         try {
217             Class JavaDoc acClass = Class.forName(acClassName);
218             AspectComponent acInstance = (AspectComponent)acClass.newInstance();
219             return acInstance.getConfigurationMethods();
220         } catch (Exception JavaDoc e) {
221         }
222         return new Vector JavaDoc();
223     }
224 }
225
Popular Tags