00001
00027 package org.objectweb.jonas_ear.deployment.api;
00028
00029 import java.util.ArrayList;
00030 import java.util.Enumeration;
00031 import java.util.HashMap;
00032 import java.util.Iterator;
00033 import java.util.List;
00034 import java.util.Map;
00035 import java.util.Vector;
00036
00037 import org.objectweb.jonas_ear.deployment.xml.Application;
00038 import org.objectweb.jonas_ear.deployment.xml.JonasApplication;
00039 import org.objectweb.jonas_ear.deployment.xml.JonasSecurity;
00040 import org.objectweb.jonas_ear.deployment.xml.Module;
00041 import org.objectweb.jonas_ear.deployment.xml.SecurityRole;
00042 import org.objectweb.jonas_ear.deployment.xml.SecurityRoleMapping;
00043 import org.objectweb.jonas_ear.deployment.xml.Web;
00044
00045 import org.objectweb.jonas_lib.deployment.api.AbsDeploymentDesc;
00046
00055 public class EarDeploymentDesc extends AbsDeploymentDesc {
00056
00060 private Vector connectorTags = null;
00061
00065 private Vector altDDConnectors = null;
00066
00070 private Vector ejbTags = null;
00071
00075 private Vector altDDEjbs = null;
00076
00080 private Vector webTags = null;
00081
00085 private Vector clientTags = null;
00086
00090 private Vector altDDWebs = null;
00091
00095 private Vector altDDClients = null;
00096
00100 private Vector securityRolesNames = null;
00101
00105 private String xmlContent = null;
00106
00110 private String jonasXmlContent = null;
00111
00115 private Map userToRoleMapping = null;
00116
00125 public EarDeploymentDesc(ClassLoader classLoaderForCls, Application application, JonasApplication jonasApplication)
00126 throws EarDeploymentDescException {
00127
00128
00129 if (classLoaderForCls == null) {
00130 throw new EarDeploymentDescException("DeploymentDesc: Classloader is null");
00131 }
00132
00133 ejbTags = new Vector();
00134 connectorTags = new Vector();
00135 webTags = new Vector();
00136 clientTags = new Vector();
00137 altDDEjbs = new Vector();
00138 altDDClients = new Vector();
00139 altDDConnectors = new Vector();
00140 altDDWebs = new Vector();
00141 securityRolesNames = new Vector();
00142
00143
00144 displayName = application.getDisplayName();
00145
00146
00147 for (Iterator i = application.getModuleList().iterator(); i.hasNext();) {
00148 Module module = (Module) i.next();
00149 String ejb = module.getEjb();
00150 String connector = module.getConnector();
00151 String java = module.getJava();
00152 Web web = module.getWeb();
00153 String altDD = module.getAltDd();
00154 if (ejb != null) {
00155 ejbTags.add(ejb);
00156 altDDEjbs.add(altDD);
00157 } else if (connector != null) {
00158 connectorTags.add(connector);
00159 altDDConnectors.add(altDD);
00160 } else if (java != null) {
00161 clientTags.add(java);
00162 altDDClients.add(altDD);
00163 } else if (web != null) {
00164 webTags.add(web);
00165 altDDWebs.add(altDD);
00166 }
00167 }
00168
00169
00170 for (Iterator i = application.getSecurityRoleList().iterator(); i.hasNext();) {
00171 SecurityRole securityRole = (SecurityRole) i.next();
00172 if (securityRole != null) {
00173 if (securityRole.getRoleName() != null) {
00174 securityRolesNames.add(securityRole.getRoleName());
00175 }
00176 }
00177 }
00178
00179
00180 JonasSecurity jonasSecurity = jonasApplication.getJonasSecurity();
00181 if (jonasSecurity != null) {
00182 userToRoleMapping = new HashMap();
00183 for (Iterator it = jonasSecurity.getSecurityRoleMappingList().iterator(); it.hasNext();) {
00184 SecurityRoleMapping securityRoleMapping = (SecurityRoleMapping) it.next();
00185 if (securityRoleMapping != null) {
00186
00187 String roleName = securityRoleMapping.getRoleName();
00188
00189 List principals = securityRoleMapping.getPrincipalNamesList();
00190
00191
00192 for (Iterator itPrincipals = principals.iterator(); itPrincipals.hasNext();) {
00193
00194 String principalName = (String) itPrincipals.next();
00195
00196 List currentMapping = (List) userToRoleMapping.get(principalName);
00197 if (currentMapping == null) {
00198 currentMapping = new ArrayList();
00199 userToRoleMapping.put(principalName, currentMapping);
00200 }
00201
00202 currentMapping.add(roleName);
00203 }
00204 }
00205 }
00206 }
00207
00208 }
00209
00214 public String[] getEjbTags() {
00215 String[] tmp = new String[ejbTags.size()];
00216 ejbTags.copyInto(tmp);
00217 return tmp;
00218 }
00219
00224 public String[] getAltDDEjbs() {
00225 String[] tmp = new String[altDDEjbs.size()];
00226 altDDEjbs.copyInto(tmp);
00227 return tmp;
00228 }
00229
00234 public String[] getClientTags() {
00235 String[] tmp = new String[clientTags.size()];
00236 clientTags.copyInto(tmp);
00237 return tmp;
00238 }
00239
00244 public String[] getAltDDClients() {
00245 String[] tmp = new String[altDDClients.size()];
00246 altDDClients.copyInto(tmp);
00247 return tmp;
00248 }
00249
00254 public Web[] getWebTags() {
00255 Web[] tmp = new Web[webTags.size()];
00256 webTags.copyInto(tmp);
00257 return tmp;
00258 }
00259
00264 public String[] getAltDDWebs() {
00265 String[] tmp = new String[altDDWebs.size()];
00266 altDDWebs.copyInto(tmp);
00267 return tmp;
00268 }
00269
00274 public String[] getConnectorTags() {
00275 String[] tmp = new String[connectorTags.size()];
00276 connectorTags.copyInto(tmp);
00277 return tmp;
00278 }
00279
00284 public String[] getAltDDConnectors() {
00285 String[] tmp = new String[altDDConnectors.size()];
00286 altDDConnectors.copyInto(tmp);
00287 return tmp;
00288 }
00289
00294 public String[] getSecurityRolesNames() {
00295 String[] tmp = new String[securityRolesNames.size()];
00296 securityRolesNames.copyInto(tmp);
00297 return tmp;
00298 }
00299
00304 public String getXmlContent() {
00305 return xmlContent;
00306 }
00307
00312 public String getJonasXmlContent() {
00313 return jonasXmlContent;
00314 }
00315
00320 public void setXmlContent(String xml) {
00321 xmlContent = xml;
00322 }
00323
00328 public void setJonasXmlContent(String xml) {
00329 jonasXmlContent = xml;
00330 }
00331
00336 public String toString() {
00337
00338 StringBuffer ret = new StringBuffer();
00339 ret.append("\ndisplay-name=" + displayName);
00340 ret.append("\nconnectors=");
00341 for (Enumeration e = connectorTags.elements(); e.hasMoreElements();) {
00342 ret.append(e.nextElement() + ",");
00343 }
00344 ret.append("\nejbs=");
00345 for (Enumeration e = ejbTags.elements(); e.hasMoreElements();) {
00346 ret.append(e.nextElement() + ",");
00347 }
00348 ret.append("\nwebs=");
00349 for (Enumeration e = webTags.elements(); e.hasMoreElements();) {
00350 ret.append(((Web) e.nextElement()).getWebUri() + ",");
00351 }
00352 ret.append("\njavas=");
00353 for (Enumeration e = clientTags.elements(); e.hasMoreElements();) {
00354 ret.append(e.nextElement() + ",");
00355 }
00356 ret.append("\nsecurity-roles-names=");
00357 for (Enumeration e = securityRolesNames.elements(); e.hasMoreElements();) {
00358 ret.append(e.nextElement() + ",");
00359 }
00360
00361 return ret.toString();
00362 }
00363
00367 public Map getUserToRoleMapping() {
00368 return userToRoleMapping;
00369 }
00370 }