KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > resolver > lib > AbstractPropertyResolver


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.util.explorer.resolver.lib;
27
28 import org.objectweb.fractal.api.NoSuchInterfaceException;
29 import org.objectweb.util.explorer.api.Entry;
30 import org.objectweb.util.explorer.core.common.api.BadParamException;
31 import org.objectweb.util.explorer.core.common.api.Description;
32 import org.objectweb.util.explorer.core.common.api.KeyProvider;
33 import org.objectweb.util.explorer.core.common.lib.BindingFeature;
34 import org.objectweb.util.explorer.core.common.lib.ClassesInheritance;
35 import org.objectweb.util.explorer.core.role.api.RoleManager;
36 import org.objectweb.util.explorer.core.role.api.RoleProvider;
37 import org.objectweb.util.explorer.property.api.PropertyProvider;
38 import org.objectweb.util.explorer.resolver.api.PropertyResolver;
39
40 /**
41  *
42  *
43  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">JŽr™me Moroy</a>,
44  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
45  *
46  * @version 0.1
47  */

48 public abstract class AbstractPropertyResolver
49               extends BindingFeature
50            implements PropertyResolver
51 {
52
53     //==================================================================
54
//
55
// Internal States.
56
//
57
// ==================================================================
58

59     // ==================================================================
60
//
61
// Constructors.
62
//
63
// ==================================================================
64

65     // ==================================================================
66
//
67
// Internal method.
68
//
69
// ==================================================================
70

71     /**
72      * Provides the Id of the typeSystem.
73      * @return The id of the type system.
74      */

75     protected String JavaDoc getTypeSystemId(){
76         return "Java";
77     }
78     
79     /**
80      * Provides the KeyProvider.
81      */

82     protected KeyProvider getKeyProvider(){
83         try {
84             return (KeyProvider)lookupFc(KeyProvider.KEY_PROVIDER);
85         } catch (NoSuchInterfaceException e) {
86             getTrace().warn(KeyProvider.KEY_PROVIDER + ": interface not found!");
87             return null;
88         }
89     }
90     
91     /**
92      * Provides the PropertyProvider.
93      */

94     protected PropertyProvider getPropertyProvider(){
95         try {
96             return (PropertyProvider)lookupFc(PropertyProvider.PROPERTY_PROVIDER);
97         } catch (NoSuchInterfaceException e) {
98             getTrace().warn(PropertyProvider.PROPERTY_PROVIDER + ": interface not found!");
99             return null;
100         }
101     }
102
103     /**
104      * Provides the RoleManager.
105      */

106     protected RoleManager getRoleManager(){
107         try {
108             return (RoleManager)lookupFc(RoleManager.ROLE_MANAGER);
109         } catch (NoSuchInterfaceException e) {
110             getTrace().warn(RoleManager.ROLE_MANAGER + ": interface not found!");
111             return null;
112         }
113         
114     }
115     
116     /**
117      * Provides the RoleProvider.
118      */

119     protected RoleProvider getRoleProvider(){
120         try {
121             return (RoleProvider)lookupFc(RoleProvider.ROLE_PROVIDER);
122         } catch (NoSuchInterfaceException e) {
123             getTrace().warn(RoleProvider.ROLE_PROVIDER + ": interface not found!");
124             return null;
125         }
126         
127     }
128     
129     /**
130      * Tries to provide a description for the given entry.
131      * The corresponfing algorithm is the following one:
132      * <pre>
133      * c &lt;- getInheritedClasses();
134      * r &lt;- getInheritedRoles();
135      * for i in c
136      * for j in r
137      * begin
138      * key &lt;- computeKey(c[i],r[j])
139      * getPropertyDescriptionDescription(key);
140      * end
141      * end for j
142      * end for i
143      * </pre>
144      * @param entry The entry for which a description needs to be found
145      * @see org.objectweb.util.explorer.core.common.lib.ClassesInheritance#getInheritedClasses(Class)
146      * @see org.objectweb.util.explorer.core.role.api.RoleProvider#getInheritedRoleIds(String[])
147      * @see org.objectweb.util.explorer.core.common.api.KeyProvider#computeKey(Object)
148      * @see org.objectweb.util.explorer.property.api.PropertyProvider#getPropertyDescription(String, Object)
149      * @return The associated description (or null if no description is found).
150      */

151     protected Description getDescription(Entry entry){
152         if(entry!=null && entry.getValue()!=null){
153             Class JavaDoc[] javaTypes = ClassesInheritance.getInheritedClasses(entry.getValue().getClass());
154             String JavaDoc[] roleIds = getRoleProvider().getInheritedRoleIds(getRoleManager().getCurrentRoleIds());
155             for (int i = 0; i < javaTypes.length; i++) {
156                 for (int j = 0; j < roleIds.length; j++) {
157                     Object JavaDoc key = null;
158                     try {
159                         key = getKeyProvider().computeKey(new String JavaDoc[]{getTypeSystemId(),javaTypes[i].getName(),roleIds[j]});
160                     } catch (BadParamException e) {
161                         getTrace().warn("Bad key param: " + e.getMessage());
162                     }
163                     if(key!=null){
164                         Description desc = (Description)getPropertyProvider().getPropertyDescription(getPropertyType(),key);
165                         if(desc!=null){
166                             return desc;
167                         }
168                     }
169                 }
170             }
171         }
172         return null;
173     }
174
175     /**
176      * Provides the name of the property to resolve.
177      * @return The name of the property
178      * @see org.objectweb.util.explorer.core.common.api.ExplorerConstants
179      */

180     protected abstract String JavaDoc getPropertyType();
181     
182     /* (non-Javadoc)
183      * @see org.objectweb.util.explorer.resolver.api.PropertyResolver#resolve(java.lang.String, org.objectweb.util.explorer.api.Entry)
184      */

185     public Description resolve(String JavaDoc propertyType, Entry currentEntry) {
186         return resolve(getPropertyType(), currentEntry, null);
187     }
188     
189     // ==================================================================
190
//
191
// Public methods for BindingFeature abstract class.
192
//
193
// ==================================================================
194

195     /* (non-Javadoc)
196      * @see org.objectweb.util.explorer.core.common.lib.BindingFeature#clientFc()
197      */

198     public String JavaDoc[] clientFc() {
199         return new String JavaDoc[]{PropertyProvider.PROPERTY_PROVIDER,
200                 KeyProvider.KEY_PROVIDER,
201                 RoleManager.ROLE_MANAGER,
202                 RoleProvider.ROLE_PROVIDER};
203     }
204
205 }
206
207
208
Popular Tags