KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > parser > lib > RoleManager


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2005 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 $Id: RoleManager.java,v 1.2 2005/07/06 15:36:00 moroy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.explorer.parser.lib;
30
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.StringTokenizer JavaDoc;
34 import java.util.Vector JavaDoc;
35
36 import org.objectweb.fractal.api.NoSuchInterfaceException;
37 import org.objectweb.util.explorer.core.common.lib.BindingFeature;
38 import org.objectweb.util.explorer.core.role.api.RoleDescription;
39 import org.objectweb.util.explorer.core.role.api.RoleFeeder;
40 import org.objectweb.util.explorer.core.role.lib.DefaultRoleDescription;
41 import org.objectweb.util.explorer.explorerConfig.Role;
42 import org.objectweb.util.explorer.explorerConfig.beans.ExplorerBean;
43 import org.objectweb.util.explorer.parser.api.ExplorerParser;
44 import org.objectweb.util.explorer.parser.api.RoleParser;
45
46 /**
47  * This component manages the "role" XML element.
48  *
49  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
50  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
51  *
52  * @version 0.1
53  */

54 public class RoleManager
55      extends BindingFeature
56   implements ExplorerParser
57 {
58
59     //==================================================================
60
//
61
// Internal States.
62
//
63
// ==================================================================
64

65     protected boolean firstTime_ = true;
66     
67     // ==================================================================
68
//
69
// Constructors.
70
//
71
// ==================================================================
72

73     // ==================================================================
74
//
75
// No internal method.
76
//
77
// ==================================================================
78

79     protected void initRole(){
80         if(firstTime_){
81             storeRole(createDefaultRoleDesc());
82             firstTime_ = false;
83         }
84     }
85
86     public void storeRole(RoleDescription roleDesc){
87         try {
88             ((RoleFeeder)lookupFc(RoleFeeder.ROLE_FEEDER)).feed(roleDesc);
89         } catch (NoSuchInterfaceException e1) {
90             e1.printStackTrace();
91         }
92     }
93     
94     protected RoleDescription createDefaultRoleDesc(){
95         RoleDescription defaultRole = new DefaultRoleDescription();
96         defaultRole.setId(org.objectweb.util.explorer.core.role.api.RoleProvider.DEFAULT_ROLE);
97         defaultRole.setInheritance(new String JavaDoc[0]);
98         defaultRole.setConcrete(false);
99         return defaultRole;
100     }
101     
102     protected RoleDescription createRoleDesc(org.objectweb.util.explorer.explorerConfig.Role role){
103         RoleDescription theRoleDef = new DefaultRoleDescription();
104         
105         Vector JavaDoc v = new Vector JavaDoc();
106         if(role.getXmlextends()!=null){
107             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(role.getXmlextends(),",");
108             while (st.hasMoreTokens())
109                 v.add(st.nextToken().trim());
110         }
111         
112         theRoleDef.setId(role.getId().trim());
113         theRoleDef.setInheritance((String JavaDoc[])v.toArray(new String JavaDoc[0]));
114         theRoleDef.setConcrete(role.getKind().equals("concrete"));
115         
116         return theRoleDef;
117     }
118     
119     // ==================================================================
120
//
121
// Public methods for BindingFeature class.
122
//
123
// ==================================================================
124

125     /* (non-Javadoc)
126      * @see org.objectweb.util.explorer.core.common.lib.BindingFeature#clientFc()
127      */

128     public String JavaDoc[] clientFc() {
129         return new String JavaDoc[]{RoleParser.ROLE_PARSER,
130                             RoleFeeder.ROLE_FEEDER};
131     }
132
133     // ==================================================================
134
//
135
// Public methods for ExplorerParser interface.
136
//
137
// ==================================================================
138

139     /* (non-Javadoc)
140      * @see org.objectweb.util.explorer.parser.api.ExplorerParser#parseExplorer(org.objectweb.util.explorer.explorerConfig.beans.ExplorerBean)
141      */

142     public void parseExplorer(ExplorerBean explorer) {
143         initRole();
144         List JavaDoc theRoles = explorer.getRoleList();
145         Iterator JavaDoc it = theRoles.iterator();
146         while (it.hasNext()) {
147             Role theRole = (Role) it.next();
148             RoleDescription roleDesc = createRoleDesc(theRole);
149             storeRole(roleDesc);
150             
151             String JavaDoc[] clientIftNames = listFc();
152             for (int i = 0; i < clientIftNames.length; i++) {
153                 if(clientIftNames[i].startsWith(RoleParser.ROLE_PARSER))
154                     try {
155                         ((RoleParser)lookupFc(clientIftNames[i])).parseRole(theRole);
156                     } catch (NoSuchInterfaceException e) {
157                         e.printStackTrace();
158                     }
159             }
160         }
161     }
162
163 }
Popular Tags