1 28 29 package org.objectweb.util.explorer.parser.lib; 30 31 import java.util.Iterator ; 32 import java.util.List ; 33 import java.util.StringTokenizer ; 34 import java.util.Vector ; 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 54 public class RoleManager 55 extends BindingFeature 56 implements ExplorerParser 57 { 58 59 65 protected boolean firstTime_ = true; 66 67 73 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 [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 v = new Vector (); 106 if(role.getXmlextends()!=null){ 107 StringTokenizer st = new StringTokenizer (role.getXmlextends(),","); 108 while (st.hasMoreTokens()) 109 v.add(st.nextToken().trim()); 110 } 111 112 theRoleDef.setId(role.getId().trim()); 113 theRoleDef.setInheritance((String [])v.toArray(new String [0])); 114 theRoleDef.setConcrete(role.getKind().equals("concrete")); 115 116 return theRoleDef; 117 } 118 119 125 128 public String [] clientFc() { 129 return new String []{RoleParser.ROLE_PARSER, 130 RoleFeeder.ROLE_FEEDER}; 131 } 132 133 139 142 public void parseExplorer(ExplorerBean explorer) { 143 initRole(); 144 List theRoles = explorer.getRoleList(); 145 Iterator it = theRoles.iterator(); 146 while (it.hasNext()) { 147 Role theRole = (Role) it.next(); 148 RoleDescription roleDesc = createRoleDesc(theRole); 149 storeRole(roleDesc); 150 151 String [] 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 |