public void addModule(ModuleDescriptor<BundleDescriptor> descriptor) { modules.add(descriptor); if (descriptor.getDescriptor() != null) { descriptor.getDescriptor().setApplication(this); } }
public void removeModule(ModuleDescriptor<BundleDescriptor> descriptor) { if (modules.contains(descriptor)) { if (descriptor.getDescriptor() != null) { descriptor.getDescriptor().setApplication(null); } modules.remove(descriptor); } }
/** * Lookup module by uri. * * @param uri the module path in the application archive * @return a bundle descriptor in this application identified by uri * or null if not found. */ public BundleDescriptor getModuleByUri(String uri) { ModuleDescriptor<BundleDescriptor> md = getModuleDescriptorByUri(uri); if (md != null) { return md.getDescriptor(); } return null; }
public void addManagedBean(ManagedBeanDescriptor managedBeanDesc) { BundleDescriptor bundleDesc = (BundleDescriptor) ((BundleDescriptor) descriptor).getModuleDescriptor().getDescriptor(); bundleDesc.addManagedBean(managedBeanDesc); }
public boolean isJCDIEnabled(BundleDescriptor bundle) { // Get the top-level bundle descriptor from the given bundle. // E.g. allows EjbBundleDescriptor from a .war to be handled correctly. BundleDescriptor topLevelBundleDesc = (BundleDescriptor) bundle.getModuleDescriptor().getDescriptor(); return weldDeployer.is299Enabled(topLevelBundleDesc); }
/** * Obtain a full set of bundle descriptors for a particular type * * @param bundleType the bundle descriptor type requested * @return the set of bundle descriptors */ public Set<BundleDescriptor> getBundleDescriptorsOfType(ArchiveType bundleType) { if (bundleType == null) { return Collections.emptySet(); } Set<BundleDescriptor> bundleSet = new OrderedSet<BundleDescriptor>(); for (ModuleDescriptor aModule : getModules()) { if (aModule.getDescriptor().getModuleType()== bundleType) { bundleSet.add((BundleDescriptor)aModule.getDescriptor()); } for (RootDeploymentDescriptor rd : aModule.getDescriptor().getExtensionsDescriptors()) { if (rd instanceof BundleDescriptor) { if (((BundleDescriptor)rd).getModuleType()== bundleType){ bundleSet.add((BundleDescriptor)rd); } } } } return bundleSet; }
public static List<URI> getLibraryJarURIs(BundleDescriptor bundleDesc, ReadableArchive archive) throws Exception { if (bundleDesc == null) { return Collections.emptyList(); } ModuleDescriptor moduleDesc = ((BundleDescriptor)bundleDesc).getModuleDescriptor(); Application app = ((BundleDescriptor)moduleDesc.getDescriptor()).getApplication(); return getLibraryJarURIs(app, archive); }
public static boolean getTreatComponentAsModule(JndiNameEnvironment env) { boolean treatComponentAsModule = false; if (env instanceof WebBundleDescriptor) { treatComponentAsModule = true; } else { if (env instanceof EjbDescriptor) { EjbDescriptor ejbDesc = (EjbDescriptor) env; EjbBundleDescriptor ejbBundle = ejbDesc.getEjbBundleDescriptor(); if (ejbBundle.getModuleDescriptor().getDescriptor() instanceof WebBundleDescriptor) { treatComponentAsModule = true; } } } return treatComponentAsModule; }
/** * if this application object is virtual, return the standalone * bundle descriptor it is wrapping otherwise return null * * @return the wrapped standalone bundle descriptor */ public BundleDescriptor getStandaloneBundleDescriptor() { if (isVirtual()) { if (getModules().size()>1) { // this is an error, the application is virtual, // which mean a wrapper for a standalone module and // it seems I have more than one module in my list... throw new IllegalStateException("Virtual application contains more than one module"); } return getModules().iterator().next().getDescriptor(); } else { return null; } }
/** * @param type the module type * @param uri the module path in the application archive * @return a bundle descriptor in this application identified by * its type and uri */ public <T extends BundleDescriptor> T getModuleByTypeAndUri(Class<T> type, String uri) { for (ModuleDescriptor<BundleDescriptor> aModule : getModules()) { try { T descriptor = type.cast(aModule.getDescriptor()); if (descriptor.getModuleDescriptor().getArchiveUri().equals(uri)) { return descriptor; } } catch(ClassCastException e) { // ignore } } return null; }
/** * Get a map of bean class to managed bean descriptor for the managed beans * defined within the current module. */ private Map<String, ManagedBeanDescriptor> getManagedBeanMap() { BundleDescriptor thisBundle = getBundleDescriptor(); Set<ManagedBeanDescriptor> managedBeans = new HashSet<ManagedBeanDescriptor>(); // Make sure we're dealing with the top-level bundle descriptor when looking // for managed beans if( thisBundle != null ) { Object desc = thisBundle.getModuleDescriptor().getDescriptor(); if( desc instanceof BundleDescriptor ) { managedBeans = ((BundleDescriptor)desc).getManagedBeans(); } } Map<String, ManagedBeanDescriptor> managedBeanMap = new HashMap<String, ManagedBeanDescriptor>(); for(ManagedBeanDescriptor managedBean : managedBeans ) { String beanClassName = managedBean.getBeanClassName(); managedBeanMap.put(beanClassName, managedBean); } return managedBeanMap; }
/** * Archivists can be associated with a module descriptor once the * XML deployment descriptors have been read and the DOL tree * is initialized. */ public void setModuleDescriptor(ModuleDescriptor<T> module) { setDescriptor(module.getDescriptor()); setManifest(module.getManifest()); }
private BundleDescriptor getBundle() { ComponentEnvManager compEnvManager = habitat.getService(ComponentEnvManager.class); JndiNameEnvironment env = compEnvManager.getCurrentJndiNameEnvironment(); BundleDescriptor bundle = null; if( env instanceof BundleDescriptor) { bundle = (BundleDescriptor) env; } else if( env instanceof EjbDescriptor ) { bundle = (BundleDescriptor) ((EjbDescriptor)env).getEjbBundleDescriptor().getModuleDescriptor().getDescriptor(); } if( bundle == null ) { throw new IllegalStateException("Invalid context for managed bean creation"); } return bundle; } }
/** * Obtain a set of all bundle descriptors, regardless of type * * @return the set of bundle descriptors */ public Set<BundleDescriptor> getBundleDescriptors() { Set<BundleDescriptor> bundleSet = new OrderedSet<BundleDescriptor>(); for (ModuleDescriptor<BundleDescriptor> aModule : getModules()) { BundleDescriptor bundleDesc = aModule.getDescriptor(); if (bundleDesc != null) { bundleSet.add(bundleDesc); for (RootDeploymentDescriptor rd : bundleDesc.getExtensionsDescriptors()) { if (rd instanceof BundleDescriptor) { bundleSet.add((BundleDescriptor)rd); } } } else { DOLUtils.getDefaultLogger().fine("Null descriptor for module " + aModule.getArchiveUri()); } } return bundleSet; }
@Override public void setElementValue(XMLElement element, String value) { if (TagNames.MODULE_NAME.equals(element.getQName())) { EjbBundleDescriptorImpl bundleDesc = getDescriptor(); // ejb-jar.xml <module-name> only applies if this is an ejb-jar if( bundleDesc.getModuleDescriptor().getDescriptor() instanceof EjbBundleDescriptorImpl) { bundleDesc.getModuleDescriptor().setModuleName(value); } } else { super.setElementValue(element, value); } }
if (name == null && newModule != null && newModule.getDescriptor() != null) { name = newModule.getDescriptor().getDisplayName(); newModule.setStandalone(true); newModule.setArchiveUri(untaggedName); if (newModule.getDescriptor() != null) { newModule.getDescriptor().setApplication(application);
private Collection<ModuleDescriptor<BundleDescriptor>> getSubModuleListForEar(com.sun.enterprise.deployment.Application application, String type) { Collection<ModuleDescriptor<BundleDescriptor>> modules = new ArrayList<ModuleDescriptor<BundleDescriptor>>(); if (type == null) { modules = application.getModules(); } else if (type.equals("servlets")) { modules = application.getModuleDescriptorsByType( DOLUtils.warType()); } else if (type.equals("ejbs")) { modules = application.getModuleDescriptorsByType( DOLUtils.ejbType()); // ejb in war case Collection<ModuleDescriptor<BundleDescriptor>> webModules = application.getModuleDescriptorsByType(DOLUtils.warType()); for (ModuleDescriptor webModule : webModules) { if (webModule.getDescriptor().getExtensionsDescriptors(EjbBundleDescriptor.class).size() > 0) { modules.add(webModule); } } } return modules; }
/** * Perform 299 style injection on the <code>managedObject</code> argument. * @param managedObject the managed object * @param bundle the bundle descriptor */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void injectManagedObject(Object managedObject, BundleDescriptor bundle) { BundleDescriptor topLevelBundleDesc = (BundleDescriptor) bundle.getModuleDescriptor().getDescriptor(); // First get BeanDeploymentArchive for this ejb BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(topLevelBundleDesc); //BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, managedObject.getClass().getName()); WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication()); BeanManager beanManager = bootstrap.getManager(bda); AnnotatedType annotatedType = beanManager.createAnnotatedType(managedObject.getClass()); InjectionTarget it = beanManager.createInjectionTarget(annotatedType); CreationalContext cc = beanManager.createCreationalContext(null); it.inject(managedObject, cc); }
/** * writes an application deployment descriptors * @param the application object * @param the abstract archive */ public void write(Application application, ReadableArchive in, WritableArchive out) throws IOException { if (application.isVirtual()) { ModuleDescriptor aModule = (ModuleDescriptor) application.getModules().iterator().next(); Archivist moduleArchivist = archivistFactory.getArchivist(aModule.getModuleType()); write((BundleDescriptor)aModule.getDescriptor(), moduleArchivist, in, out); } else { // this is a real application. // let's start by writing out all submodules deployment descriptors for (ModuleDescriptor aModule : application.getModules()) { Archivist moduleArchivist = archivistFactory.getArchivist(aModule.getModuleType()); WritableArchive moduleArchive = out.createSubArchive(aModule.getArchiveUri()); ReadableArchive moduleArchive2 = in.getSubArchive(aModule.getArchiveUri()); write((BundleDescriptor)aModule.getDescriptor(), moduleArchivist, moduleArchive2, moduleArchive); } // now let's write the application descriptor ApplicationArchivist archivist = archivistProvider.get(); archivist.setDescriptor(application); archivist.writeDeploymentDescriptors(in, out); } }
public static String getContextID(EjbBundleDescriptor ejbBundleDesc) { String cid = null; if (ejbBundleDesc != null) { /* detect special case of EJBs embedded in a war, * and make sure psuedo policy context id is unique within app */ Object root = ejbBundleDesc.getModuleDescriptor().getDescriptor(); if( (root != ejbBundleDesc) && (root instanceof WebBundleDescriptor ) ) { cid = createUniquePseudoModuleID(ejbBundleDesc); } else { cid = VersioningUtils.getRepositoryName(ejbBundleDesc.getApplication().getRegistrationName()) + '/' + ejbBundleDesc.getUniqueFriendlyId(); } } return cid; } public static String getContextID(WebBundleDescriptor wbd) {