DeploymentDesc.java

00001 
00027 package org.objectweb.jonas_ejb.deployment.api;
00028 
00029 import java.util.HashMap;
00030 import java.util.Iterator;
00031 import java.util.LinkedList;
00032 import java.util.List;
00033 import java.util.Map;
00034 
00035 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
00036 import org.objectweb.jonas_ejb.deployment.xml.EjbJar;
00037 import org.objectweb.jonas_ejb.deployment.xml.Entity;
00038 import org.objectweb.jonas_ejb.deployment.xml.JonasEjbJar;
00039 import org.objectweb.jonas_ejb.deployment.xml.JonasEntity;
00040 import org.objectweb.jonas_ejb.deployment.xml.JonasRunAsMapping;
00041 import org.objectweb.jonas_ejb.deployment.xml.JonasSession;
00042 import org.objectweb.jonas_ejb.deployment.xml.MethodPermission;
00043 import org.objectweb.jonas_ejb.deployment.xml.Session;
00044 
00045 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
00046 import org.objectweb.jonas_lib.deployment.api.DescriptionGroupDesc;
00047 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
00048 import org.objectweb.jonas_lib.deployment.xml.JonasMessageDestination;
00049 import org.objectweb.jonas_lib.deployment.xml.MessageDestination;
00050 
00051 import org.objectweb.util.monolog.api.Logger;
00052 
00061 public abstract class DeploymentDesc  extends DescriptionGroupDesc {
00062 
00066     protected Logger logger;
00067 
00068 
00072     protected String  specVersion = null;
00073 
00077     protected HashMap beanDesc = new HashMap();
00078 
00082     protected AssemblyDescriptor asd = null;
00083 
00087     protected String fileName = null;
00088 
00092     protected String ejbClientJar = null;
00093 
00097     private List methodPermissionsDescList = null;
00098 
00102     private ExcludeListDesc excludeListDesc = null;
00103 
00107     protected JLinkedList jonasMDList = null;
00108 
00112     private String xmlContent = "";
00113 
00117     private String jonasXmlContent = "";
00118 
00123     private Map runAsMapping = null;
00124 
00135     public DeploymentDesc(ClassLoader classLoader,
00136                                 EjbJar ejbJar,
00137                                 JonasEjbJar jonasEjbJar,
00138                                 Logger l,
00139                                 String fileName)
00140         throws DeploymentDescException {
00141 
00142 
00143         logger = l;
00144 
00145         // set jarFileName
00146         this.fileName = fileName;
00147 
00148         // test classloader
00149         if (classLoader == null) {
00150             throw new DeploymentDescException("DeploymentDesc: Classloader is null");
00151         }
00152 
00153         // test the validity of the ejbJar (EnterpriseBeans must be present)
00154         if (ejbJar.getEnterpriseBeans() == null) {
00155             throw new DeploymentDescException("invalid standard deployment descriptor (<enterprise-beans> element missing)");
00156         }
00157         // spec-version
00158         specVersion = ejbJar.getVersion();
00159 
00160         // ejb-client-jar
00161         ejbClientJar = ejbJar.getEjbClientJar();
00162 
00163         // assembly descriptor
00164         asd = ejbJar.getAssemblyDescriptor();
00165 
00166         // Run-as mapping
00167         runAsMapping = new HashMap();
00168         for (Iterator i = jonasEjbJar.getJonasRunAsMappingList().iterator(); i.hasNext();) {
00169             // Get Mapping
00170             JonasRunAsMapping jonasRunAsMapping = (JonasRunAsMapping) i.next();
00171             String principalName = jonasRunAsMapping.getPrincipalName();
00172             // Get existing roles if any
00173             String[] existingRunAsRoleMapping = (String[]) runAsMapping.get(principalName);
00174             String[] newMappingRoles = null;
00175             int r = 0;
00176             if (existingRunAsRoleMapping == null) {
00177                 newMappingRoles = new String[jonasRunAsMapping.getRoleNamesList().size()];
00178             } else {
00179                 newMappingRoles = new String[jonasRunAsMapping.getRoleNamesList().size() + existingRunAsRoleMapping.length];
00180                 // Now add existing roles
00181                 System.arraycopy(existingRunAsRoleMapping, 0, newMappingRoles, 0, existingRunAsRoleMapping.length);
00182                 r =  existingRunAsRoleMapping.length;
00183             }
00184             Iterator itR = jonasRunAsMapping.getRoleNamesList().iterator();
00185             while (itR.hasNext()) {
00186                 newMappingRoles[r] = (String) itR.next();
00187                 r++;
00188             }
00189             runAsMapping.put(principalName, newMappingRoles);
00190 
00191         }
00192 
00193         // Use by PermissionManager for translating xml into EJBMethodPermission
00194         methodPermissionsDescList = new LinkedList();
00195         // Create EJBMEthodPermissions for each method-permission
00196         if (asd != null) {
00197             for (Iterator i = asd.getMethodPermissionList().iterator(); i.hasNext();) {
00198                 MethodPermission methodPermission = (MethodPermission) i.next();
00199                 methodPermissionsDescList.add(new MethodPermissionDesc(methodPermission));
00200             }
00201         }
00202 
00203         // Use by PermissionManager for translating xml into EJBMethodPermission
00204         if (asd != null && asd.getExcludeList() != null) {
00205             excludeListDesc = new ExcludeListDesc(asd.getExcludeList());
00206         }
00207 
00208         // jonas-message-destination
00209         jonasMDList = jonasEjbJar.getJonasMessageDestinationList();
00210 
00211         // HashMap of jonas-session
00212         HashMap jonasSession = new HashMap();
00213         for (Iterator i = jonasEjbJar.getJonasSessionList().iterator(); i.hasNext();) {
00214             JonasSession jSes = (JonasSession) i.next();
00215             jonasSession.put(jSes.getEjbName(), jSes);
00216         }
00217 
00218         // session beans
00219         for (Iterator i = ejbJar.getEnterpriseBeans().getSessionList().iterator(); i.hasNext();) {
00220             BeanDesc bd = null;
00221             Session ses = (Session) i.next();
00222             // find corresponding jonas session
00223             JonasSession jSes = (JonasSession) jonasSession.get(ses.getEjbName());
00224             if (jSes == null) {
00225                 // Build a default jonas-session if not exist
00226                 jSes = new JonasSession();
00227                 jSes.setEjbName(ses.getEjbName());
00228             }
00229             if (ses.getSessionType().equals("Stateful")) {
00230                 // stateful
00231                 bd = new SessionStatefulDesc(classLoader, ses, asd, jSes, jonasMDList, fileName);
00232             } else if (ses.getSessionType().equals("Stateless")) {
00233                 // stateless
00234                 bd = new SessionStatelessDesc(classLoader, ses, asd, jSes, jonasMDList, fileName);
00235             } else {
00236                 throw new DeploymentDescException("invalid session-type content for bean " + ses.getEjbName());
00237             }
00238             bd.setDeploymentDesc(this);
00239             bd.check();
00240             beanDesc.put(bd.getEjbName(), bd);
00241         }
00242 
00243         // HashMap of jonas-entity
00244         HashMap jonasEntity = new HashMap();
00245         for (Iterator i = jonasEjbJar.getJonasEntityList().iterator(); i.hasNext();) {
00246             JonasEntity jEnt = (JonasEntity) i.next();
00247             jonasEntity.put(jEnt.getEjbName(), jEnt);
00248         }
00249         // entity beans
00250         for (Iterator i = ejbJar.getEnterpriseBeans().getEntityList().iterator(); i.hasNext();) {
00251             BeanDesc bd = null;
00252             Entity ent = (Entity) i.next();
00253             // find corresponding jonas entity
00254             JonasEntity jEnt = (JonasEntity) jonasEntity.get(ent.getEjbName());
00255             if (jEnt == null) {
00256                 throw new DeploymentDescException("jonas-entity missing for bean " + ent.getEjbName());
00257             }
00258             if (ent.getPersistenceType().equals("Bean")) {
00259                 // bean managed
00260                 bd = new EntityBmpDesc(classLoader, ent, asd, jEnt, jonasMDList, fileName);
00261             } else if (ent.getPersistenceType().equals("Container")) {
00262                 // container managed (always jdbc)
00263                 bd = newEntityBeanDesc(classLoader, ent, asd, jEnt, jonasMDList);
00264             } else {
00265                 throw new DeploymentDescException("Invalid persistence-type content for bean " + ent.getEjbName());
00266             }
00267             bd.setDeploymentDesc(this);
00268             bd.check();
00269             beanDesc.put(bd.getEjbName(), bd);
00270         }
00271     }
00272 
00277     public Iterator getBeanDescIterator() {
00278         return beanDesc.values().iterator();
00279     }
00280 
00285     public BeanDesc[] getBeanDesc() {
00286         BeanDesc[] ret = new BeanDesc[beanDesc.size()];
00287         int j = 0;
00288         for (Iterator i = beanDesc.values().iterator(); i.hasNext(); j++) {
00289             ret[j] = (BeanDesc) i.next();
00290         }
00291         return ret;
00292     }
00293 
00299     public String[] getRolesForRunAsPrincipal(String principalName) {
00300         return (String[]) runAsMapping.get(principalName);
00301     }
00302 
00308     public BeanDesc getBeanDesc(String ejbName) {
00309         return (BeanDesc) beanDesc.get(ejbName);
00310     }
00311 
00317     public EntityCmp2Desc asn2BeanDesc(String asn) {
00318         for (Iterator i = beanDesc.values().iterator(); i.hasNext();) {
00319             BeanDesc bd = (BeanDesc) i.next();
00320             if (bd instanceof EntityCmp2Desc) {
00321                 if (asn.equals(((EntityCmp2Desc) bd).getAbstractSchemaName())) {
00322                     return ((EntityCmp2Desc) bd);
00323                 }
00324             }
00325         }
00326         return null;
00327     }
00328 
00329 
00335     public List getMethodPermissionsDescList() {
00336         return methodPermissionsDescList;
00337     }
00338 
00343     public ExcludeListDesc getExcludeListDesc() {
00344         return excludeListDesc;
00345     }
00346 
00347 
00353     public BeanDesc getBeanDescWithLocalInterface(String itfLocalName) {
00354         for (Iterator i = beanDesc.values().iterator(); i.hasNext();) {
00355             BeanDesc bd = (BeanDesc) i.next();
00356             if (bd.getLocalClass() != null) {
00357                 if (itfLocalName.equals(bd.getLocalClass().getName())) {
00358                     return bd;
00359                 }
00360             }
00361         }
00362         return null;
00363     }
00364 
00370     public boolean getMessageDestination(String mdLink) {
00371         MessageDestination md = null;
00372         if (asd != null && asd.getMessageDestinationList() != null) {
00373             for (Iterator i = asd.getMessageDestinationList().iterator(); i.hasNext();) {
00374                 md = (MessageDestination) i.next();
00375                 if (md.getMessageDestinationName().equals(mdLink)) {
00376                     return true;
00377                 }
00378             }
00379         }
00380         return false;
00381     }
00382 
00388     public JonasMessageDestination getJonasMessageDestination(String mdLink) {
00389         JonasMessageDestination jmd = null;
00390         if (jonasMDList != null) {
00391             for (Iterator i = jonasMDList.iterator(); i.hasNext();) {
00392                 jmd = (JonasMessageDestination) i.next();
00393                 if (jmd.getMessageDestinationName().equals(mdLink)) {
00394                     return jmd;
00395                 }
00396             }
00397         }
00398         return null;
00399     }
00400 
00416     protected abstract BeanDesc newEntityBeanDesc(ClassLoader cl, Entity ent,
00417                                                   AssemblyDescriptor asd, JonasEntity j, JLinkedList jMDRList)
00418         throws DeploymentDescException;
00419 
00424     public String getDisplayName() {
00425         return displayName;
00426     }
00427 
00432     public String getEjbClientJar() {
00433         return ejbClientJar;
00434     }
00435 
00436 
00441     public Logger getLogger() {
00442         return logger;
00443     }
00444 
00449     public void setLogger(Logger logger) {
00450         this.logger = logger;
00451     }
00452 
00457     public String getXmlContent() {
00458         return xmlContent;
00459     }
00460 
00465     public String getJOnASXmlContent() {
00466         return jonasXmlContent;
00467     }
00468 
00473     public String toString() {
00474         StringBuffer ret = new StringBuffer();
00475         ret.append("\ngetDisplayName()=" + getDisplayName());
00476         ret.append("\ngetEjbClientJar()=" + getEjbClientJar());
00477         BeanDesc[] b = getBeanDesc();
00478         for (int i = 0; i < b.length; i++) {
00479             ret.append("\ngetBeanDesc(" + i + ")=" + b[i].getClass().getName());
00480             ret.append(b[i].toString());
00481         }
00482         return ret.toString();
00483     }
00484 
00488     public void setXmlContent(String xmlContent) {
00489         this.xmlContent = xmlContent;
00490     }
00491 
00495     public void setJOnASXmlContent(String jonasXmlContent) {
00496         this.jonasXmlContent = jonasXmlContent;
00497     }
00498 
00499 }

Generated on Tue Feb 15 15:05:44 2005 for JOnAS by  doxygen 1.3.9.1