KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.objectweb.jac.core.rtti.ClassItem;
22 import org.objectweb.jac.core.rtti.FieldItem;
23 import org.objectweb.jac.core.rtti.MethodItem;
24
25 import java.util.List JavaDoc;
26 import java.util.Vector JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 /**
31  * this is a class that represent the call of an aspect Method by a ModelElement
32  * @author gregoire Waymel
33  */

34 public class ConfigItem {
35     /** the Aspect */
36     private AspectConfiguration aspectConfiguration;
37
38     /** Method of the aspect */
39     private MethodItem method;
40
41     /** Element (1st param of method) which call the method */
42     private ModelElement modelElement;
43
44     /** the Params of the method */
45     private List JavaDoc param = new Vector JavaDoc();
46
47     /**
48      * default constructor
49      */

50     public ConfigItem() {
51     }
52
53     public AspectConfiguration getAspectConfiguration() {
54         return aspectConfiguration;
55     }
56
57     public ModelElement getModelElement() {
58         return modelElement;
59     }
60
61     public List JavaDoc getParam() {
62         return param;
63     }
64
65     public MethodItem getMethod() {
66         return method;
67     }
68
69     /**
70      * @param aspectConfiguration the new Aspect for this ConfigItem
71      */

72     public void setAspectConfiguration(AspectConfiguration aspectConfiguration) {
73         this.aspectConfiguration = aspectConfiguration;
74     }
75     public void addParam(String JavaDoc param) {
76         this.param.add(param);
77     }
78
79     public void removeParam(String JavaDoc param) {
80         this.param.remove(param);
81     }
82
83     public void setModelElement(ModelElement modelElement) {
84         this.modelElement = modelElement;
85     }
86
87     public void setMethod(MethodItem newMethod) {
88         this.method = newMethod;
89     }
90
91     public String JavaDoc toString() {
92         return "ConfigItem "+modelElement+" "+method+" "+aspectConfiguration;
93     }
94
95     /**
96      * Gets available aspect configurations
97      */

98     public static Collection JavaDoc getAvailableAspects(ConfigItem item) {
99         ModelElement element = item.getModelElement();
100         Vector JavaDoc configs = new Vector JavaDoc();
101         if (element instanceof Class JavaDoc) {
102             Iterator JavaDoc i = ((Class JavaDoc)element).getProject().getApplications().iterator();
103             while (i.hasNext()) {
104                 Application app = (Application)i.next();
105                 configs.addAll(app.getAspectConfigurations());
106             }
107         }
108         return configs;
109     }
110
111     /**
112      * search the aspect method that can be call by the ModelElement.
113      * @param item the ConfigItem that should have a valid ModelElement and a valid AspectConfiguration.
114      * @return the method name that can be call by the item ModelElement.
115      */

116     public final static Collection JavaDoc getValidMethods(ConfigItem item) throws Exception JavaDoc {
117         Vector JavaDoc list = new Vector JavaDoc();
118         AspectConfiguration aspect = item.getAspectConfiguration();
119         //If the model element or the AspectConfiguration is missing, we cannot determine the valid Method.
120
ModelElement element = item.getModelElement();
121         if ((aspect==null)||(element==null)) {
122             return list;
123         }
124
125         //Iterate all the config method of the aspect
126
Iterator JavaDoc iteMethods = aspect.getConfigurationMethods().iterator();
127         while(iteMethods.hasNext()) {
128             MethodItem method = (MethodItem)iteMethods.next();
129             //Searching the first param
130
java.lang.Class JavaDoc param;
131             //If the method has no param it's a Project method.
132
if (method.getParameterCount()==0) {
133                 param = Project.class;
134             }else{
135                 param = method.getParameterTypes()[0];
136             }
137
138             //test whether the method is a class method.
139
if ((param==ClassItem.class)&&(element.getClass()==Class JavaDoc.class)) {
140                 list.add(method);
141                 continue;
142             }
143             //test whether the method is a Field method.
144
if ((param==FieldItem.class)&&(element.getClass()==Field.class)) {
145                 list.add(method);
146                 continue;
147             }
148             //test whether the method is a Method method.
149
if ((param==MethodItem.class)&&(element.getClass()==Method.class)) {
150                 list.add(method);
151                 continue;
152             }
153             //if it's not this then add the method in the project
154
if (element.getClass()==Project.class) {
155                 list.add(method);
156             }
157             //Else Error
158
//We just continue...
159
}
160         return list;
161     }
162 }
163
Popular Tags