container/components/components/src/main/java/org/mobicents/slee/container/component/deployment/DeployableUnitJarComponentBuilder.java
@SuppressWarnings("deprecation")
	public List<AbstractSleeComponent> buildComponents(
			String componentJarFileName, JarFile deployableUnitJar,
			File deploymentDir)
			throws DeploymentException {
		
		// extract the component jar from the DU jar, to the temp du dir
		File extractedFile = extractFile(componentJarFileName,
				deployableUnitJar, deploymentDir);
		JarFile componentJarFile = null;
		try {
			componentJarFile = new JarFile(extractedFile);
		} catch (IOException e) {
			throw new DeploymentException(
					"failed to create jar file for extracted file "
							+ extractedFile);
		}

		InputStream componentDescriptorInputStream = null;
		List<AbstractSleeComponent> components = new ArrayList<AbstractSleeComponent>();

		try {
			// now extract the jar file to a new dir
			File componentJarDeploymentDir = new File(deploymentDir,
					componentJarFileName + "-contents");
			if (!componentJarDeploymentDir.exists()) {
				// the jar may not be on root of DU, create additional dirs if needed
				LinkedList<File> dirsToCreate = new LinkedList<File>();
				File dir = componentJarDeploymentDir.getParentFile();
				while(!dir.equals(deploymentDir)) {
					dirsToCreate.addFirst(dir);
					dir = dir.getParentFile();
				}
				for (File f : dirsToCreate) {
					f.mkdir();
				}
				// now create the dir for the component jar
				if (!componentJarDeploymentDir.mkdir()) {
						throw new SLEEException("dir for jar "
								+ componentJarFileName + " not created in "
								+ deploymentDir);					
				}				
			} else {
				throw new SLEEException("dir for jar " + componentJarFileName
						+ " already exists in " + deploymentDir);
			}
			extractJar(componentJarFile, componentJarDeploymentDir);
			// create components from descriptor
			JarEntry componentDescriptor = null;
			if ((componentDescriptor = componentJarFile
					.getJarEntry("META-INF/sbb-jar.xml")) != null) {
				// create class loader domain shared by all components
				URLClassLoaderDomainImpl classLoaderDomain = componentManagement
				.getClassLoaderFactory()
				.newClassLoaderDomain(
						new URL[] { componentJarDeploymentDir.toURL() },
						Thread.currentThread().getContextClassLoader());
				// parse descriptor
				componentDescriptorInputStream = componentJarFile
						.getInputStream(componentDescriptor);
				SbbDescriptorFactoryImpl descriptorFactory = componentManagement
						.getComponentDescriptorFactory()
						.getSbbDescriptorFactory();
				List<SbbDescriptorImpl> descriptors = descriptorFactory
						.parse(componentDescriptorInputStream);
				// create components
				for (SbbDescriptorImpl descriptor : descriptors) {
                                        PreferredPackagesBuilder.buildPreferredPackages(descriptor, classLoaderDomain);
					SbbComponentImpl component = new SbbComponentImpl(
							descriptor);
					component.setDeploymentDir(componentJarDeploymentDir);
					component.setClassLoaderDomain(classLoaderDomain);
					components.add(component);
				}
			} else if ((componentDescriptor = componentJarFile
					.getJarEntry("META-INF/profile-spec-jar.xml")) != null) {
				// create class loader domain shared by all components
				URLClassLoaderDomainImpl classLoaderDomain = componentManagement
				.getClassLoaderFactory()
				.newClassLoaderDomain(
						new URL[] { componentJarDeploymentDir.toURL() },
						Thread.currentThread().getContextClassLoader());
				// parse descriptor
				componentDescriptorInputStream = componentJarFile
						.getInputStream(componentDescriptor);
				ProfileSpecificationDescriptorFactoryImpl descriptorFactory = componentManagement
						.getComponentDescriptorFactory()
						.getProfileSpecificationDescriptorFactory();
				List<ProfileSpecificationDescriptorImpl> descriptors = descriptorFactory
						.parse(componentDescriptorInputStream);
				// create components
				for (ProfileSpecificationDescriptorImpl descriptor : descriptors) {
					ProfileSpecificationComponentImpl component = new ProfileSpecificationComponentImpl(
							descriptor);
					component.setDeploymentDir(componentJarDeploymentDir);
					component.setClassLoaderDomain(classLoaderDomain);
					components.add(component);
				}
			} else if ((componentDescriptor = componentJarFile
					.getJarEntry("META-INF/library-jar.xml")) != null) {
				Set<LibraryComponentImpl> libraryComponents = new HashSet<LibraryComponentImpl>();
				// we need to gather all URLs for the shared class loader domain
				// to watch
				Set<URL> classLoaderDomainURLs = new HashSet<URL>();
				classLoaderDomainURLs.add(componentJarDeploymentDir.toURL());
				// parse the descriptor
				componentDescriptorInputStream = componentJarFile
						.getInputStream(componentDescriptor);
				LibraryDescriptorFactoryImpl descriptorFactory = componentManagement
						.getComponentDescriptorFactory()
						.getLibraryDescriptorFactory();
				List<LibraryDescriptorImpl> descriptors = descriptorFactory
						.parse(componentDescriptorInputStream);
				// create components
				for (LibraryDescriptorImpl descriptor : descriptors) {
					LibraryComponentImpl component = new LibraryComponentImpl(
							descriptor);
					for (JarDescriptor mJar : descriptor.getJars()) {
						classLoaderDomainURLs.add(new File(
								componentJarDeploymentDir, mJar.getJarName())
								.toURL());
					}
					// set deploy dir and cl domain
					component.setDeploymentDir(componentJarDeploymentDir);
					components.add(component);
					libraryComponents.add(component);
				}
				// create shared url domain
				URLClassLoaderDomainImpl classLoaderDomain = componentManagement
				.getClassLoaderFactory()
				.newClassLoaderDomain(
						classLoaderDomainURLs
						.toArray(new URL[classLoaderDomainURLs.size()]),
						Thread.currentThread().getContextClassLoader());
				// add it to each component
				for (LibraryComponentImpl component : libraryComponents) {
					component.setClassLoaderDomain(classLoaderDomain);
				}
			} else if ((componentDescriptor = componentJarFile
					.getJarEntry("META-INF/event-jar.xml")) != null) {
				// create class loader domain shared by all components
				URLClassLoaderDomainImpl classLoaderDomain = componentManagement
				.getClassLoaderFactory()
				.newClassLoaderDomain(
						new URL[] { componentJarDeploymentDir.toURL() },
						Thread.currentThread().getContextClassLoader());				
				// parse descriptor
				componentDescriptorInputStream = componentJarFile
						.getInputStream(componentDescriptor);
				EventTypeDescriptorFactoryImpl descriptorFactory = componentManagement
						.getComponentDescriptorFactory()
						.getEventTypeDescriptorFactory();
				List<EventTypeDescriptorImpl> descriptors = descriptorFactory
						.parse(componentDescriptorInputStream);
				// create components
				for (EventTypeDescriptorImpl descriptor : descriptors) {
					EventTypeComponentImpl component = new EventTypeComponentImpl(
							descriptor);
					component.setDeploymentDir(componentJarDeploymentDir);
					component.setClassLoaderDomain(classLoaderDomain);
					components.add(component);
				}
			} else if ((componentDescriptor = componentJarFile
					.getJarEntry("META-INF/resource-adaptor-type-jar.xml")) != null) {
				// create class loader domain shared by all components
				URLClassLoaderDomainImpl classLoaderDomain = componentManagement.getClassLoaderFactory().newClassLoaderDomain(new URL[] { componentJarDeploymentDir.toURL() }, Thread
						.currentThread().getContextClassLoader());
				// parse descriptor
				componentDescriptorInputStream = componentJarFile
						.getInputStream(componentDescriptor);
				ResourceAdaptorTypeDescriptorFactoryImpl descriptorFactory = componentManagement
						.getComponentDescriptorFactory()
						.getResourceAdaptorTypeDescriptorFactory();
				List<ResourceAdaptorTypeDescriptorImpl> descriptors = descriptorFactory
						.parse(componentDescriptorInputStream);
				// create components
				for (ResourceAdaptorTypeDescriptorImpl descriptor : descriptors) {
					ResourceAdaptorTypeComponentImpl component = new ResourceAdaptorTypeComponentImpl(
							descriptor);
					component.setDeploymentDir(componentJarDeploymentDir);
					component.setClassLoaderDomain(classLoaderDomain);
					components.add(component);
				}
			} else if ((componentDescriptor = componentJarFile
					.getJarEntry("META-INF/resource-adaptor-jar.xml")) != null) {
				// create class loader domain shared by all components
				URLClassLoaderDomainImpl classLoaderDomain = componentManagement
						.getClassLoaderFactory()
						.newClassLoaderDomain(
								new URL[] { componentJarDeploymentDir.toURL() },
								Thread.currentThread().getContextClassLoader());				
				// parse descriptor
				componentDescriptorInputStream = componentJarFile
						.getInputStream(componentDescriptor);
				ResourceAdaptorDescriptorFactoryImpl descriptorFactory = componentManagement
						.getComponentDescriptorFactory()
						.getResourceAdaptorDescriptorFactory();
				List<ResourceAdaptorDescriptorImpl> descriptors = descriptorFactory
						.parse(componentDescriptorInputStream);
				// create components
				for (ResourceAdaptorDescriptorImpl descriptor : descriptors) {
					ResourceAdaptorComponentImpl component = new ResourceAdaptorComponentImpl(
							descriptor);
					component.setDeploymentDir(componentJarDeploymentDir);
					component.setClassLoaderDomain(classLoaderDomain);
					components.add(component);
				}
			} else {
				throw new DeploymentException(
						"No Deployment Descriptor found in the "
								+ componentJarFile.getName()
								+ " entry of a deployable unit.");
			}
		} catch (IOException e) {
			throw new DeploymentException(
					"failed to parse jar descriptor from "
							+ componentJarFile.getName(), e);
		} finally {
			if (componentDescriptorInputStream != null) {
				try {
					componentDescriptorInputStream.close();
				} catch (IOException e) {
					logger
							.error("failed to close inputstream of descriptor for jar "
									+ componentJarFile);
				}
			}
		}

		// close component jar file
		try {
			componentJarFile.close();
		} catch (IOException e) {
			logger.error("failed to close component jar file", e);
		}
		// and delete the extracted jar file, we don't need it anymore
		if (!extractedFile.delete()) {
			logger.warn("failed to delete " + extractedFile);
		}

		return components;
	}
@SuppressWarnings("deprecation")
	public List<AbstractSleeComponent> buildComponents(
			String componentJarFileName, JarFile deployableUnitJar,
			File deploymentDir)
			throws DeploymentException {
		
		// extract the component jar from the DU jar, to the temp du dir
		File extractedFile = extractFile(componentJarFileName,
				deployableUnitJar, deploymentDir);
		JarFile componentJarFile = null;
		try {
			componentJarFile = new JarFile(extractedFile);
		} catch (IOException e) {
			throw new DeploymentException(
					"failed to create jar file for extracted file "
							+ extractedFile);
		}

		InputStream componentDescriptorInputStream = null;
		List<AbstractSleeComponent> components = new ArrayList<AbstractSleeComponent>();

		try {
			// now extract the jar file to a new dir
			File componentJarDeploymentDir = new File(deploymentDir,
					componentJarFileName + "-contents");
			if (!componentJarDeploymentDir.exists()) {
				// the jar may not be on root of DU, create additional dirs if needed
				LinkedList<File> dirsToCreate = new LinkedList<File>();
				File dir = componentJarDeploymentDir.getParentFile();
				while(!dir.equals(deploymentDir)) {
					dirsToCreate.addFirst(dir);
					dir = dir.getParentFile();
				}
				for (File f : dirsToCreate) {
					f.mkdir();
				}
				// now create the dir for the component jar
				if (!componentJarDeploymentDir.mkdir()) {
						throw new SLEEException("dir for jar "
								+ componentJarFileName + " not created in "
								+ deploymentDir);					
				}				
			} else {
				throw new SLEEException("dir for jar " + componentJarFileName
						+ " already exists in " + deploymentDir);
			}
			extractJar(componentJarFile, componentJarDeploymentDir);
			// create components from descriptor
			JarEntry componentDescriptor = null;
			if ((componentDescriptor = componentJarFile
					.getJarEntry("META-INF/sbb-jar.xml")) != null) {
				// create class loader domain shared by all components
				URLClassLoaderDomainImpl classLoaderDomain = componentManagement
				.getClassLoaderFactory()
				.newClassLoaderDomain(
						new URL[] { componentJarDeploymentDir.toURL() },
						Thread.currentThread().getContextClassLoader());
				// parse descriptor
				componentDescriptorInputStream = componentJarFile
						.getInputStream(componentDescriptor);
				SbbDescriptorFactoryImpl descriptorFactory = componentManagement
						.getComponentDescriptorFactory()
						.getSbbDescriptorFactory();
				List<SbbDescriptorImpl> descriptors = descriptorFactory
						.parse(componentDescriptorInputStream);
				// create components
				for (SbbDescriptorImpl descriptor : descriptors) {
                                        PreferredPackagesBuilder.buildPreferredPackages(descriptor, classLoaderDomain);
					SbbComponentImpl component = new SbbComponentImpl(
							descriptor);
					component.setDeploymentDir(componentJarDeploymentDir);
					component.setClassLoaderDomain(classLoaderDomain);
					components.add(component);
				}
			} else if ((componentDescriptor = componentJarFile
					.getJarEntry("META-INF/profile-spec-jar.xml")) != null) {
				// create class loader domain shared by all components
				URLClassLoaderDomainImpl classLoaderDomain = componentManagement
				.getClassLoaderFactory()
				.newClassLoaderDomain(
						new URL[] { componentJarDeploymentDir.toURL() },
						Thread.currentThread().getContextClassLoader());
				// parse descriptor
				componentDescriptorInputStream = componentJarFile
						.getInputStream(componentDescriptor);
				ProfileSpecificationDescriptorFactoryImpl descriptorFactory = componentManagement
						.getComponentDescriptorFactory()
						.getProfileSpecificationDescriptorFactory();
				List<ProfileSpecificationDescriptorImpl> descriptors = descriptorFactory
						.parse(componentDescriptorInputStream);
				// create components
				for (ProfileSpecificationDescriptorImpl descriptor : descriptors) {
					ProfileSpecificationComponentImpl component = new ProfileSpecificationComponentImpl(
							descriptor);
					component.setDeploymentDir(componentJarDeploymentDir);
					component.setClassLoaderDomain(classLoaderDomain);
					components.add(component);
				}
			} else if ((componentDescriptor = componentJarFile
					.getJarEntry("META-INF/library-jar.xml")) != null) {
				Set<LibraryComponentImpl> libraryComponents = new HashSet<LibraryComponentImpl>();
				// we need to gather all URLs for the shared class loader domain
				// to watch
				Set<URL> classLoaderDomainURLs = new HashSet<URL>();
				classLoaderDomainURLs.add(componentJarDeploymentDir.toURL());
				// parse the descriptor
				componentDescriptorInputStream = componentJarFile
						.getInputStream(componentDescriptor);
				LibraryDescriptorFactoryImpl descriptorFactory = componentManagement
						.getComponentDescriptorFactory()
						.getLibraryDescriptorFactory();
				List<LibraryDescriptorImpl> descriptors = descriptorFactory
						.parse(componentDescriptorInputStream);
				// create components
				for (LibraryDescriptorImpl descriptor : descriptors) {
					LibraryComponentImpl component = new LibraryComponentImpl(
							descriptor);
					for (JarDescriptor mJar : descriptor.getJars()) {
						classLoaderDomainURLs.add(new File(
								componentJarDeploymentDir, mJar.getJarName())
								.toURL());
					}
					// set deploy dir and cl domain
					component.setDeploymentDir(componentJarDeploymentDir);
					components.add(component);
					libraryComponents.add(component);
				}
				// create shared url domain
				URLClassLoaderDomainImpl classLoaderDomain = componentManagement
				.getClassLoaderFactory()
				.newClassLoaderDomain(
						classLoaderDomainURLs
						.toArray(new URL[classLoaderDomainURLs.size()]),
						Thread.currentThread().getContextClassLoader());
				// add it to each component
				for (LibraryComponentImpl component : libraryComponents) {
					component.setClassLoaderDomain(classLoaderDomain);
				}
			} else if ((componentDescriptor = componentJarFile
					.getJarEntry("META-INF/event-jar.xml")) != null) {
				// create class loader domain shared by all components
				URLClassLoaderDomainImpl classLoaderDomain = componentManagement
				.getClassLoaderFactory()
				.newClassLoaderDomain(
						new URL[] { componentJarDeploymentDir.toURL() },
						Thread.currentThread().getContextClassLoader());				
				// parse descriptor
				componentDescriptorInputStream = componentJarFile
						.getInputStream(componentDescriptor);
				EventTypeDescriptorFactoryImpl descriptorFactory = componentManagement
						.getComponentDescriptorFactory()
						.getEventTypeDescriptorFactory();
				List<EventTypeDescriptorImpl> descriptors = descriptorFactory
						.parse(componentDescriptorInputStream);
				// create components
				for (EventTypeDescriptorImpl descriptor : descriptors) {
					EventTypeComponentImpl component = new EventTypeComponentImpl(
							descriptor);
					component.setDeploymentDir(componentJarDeploymentDir);
					component.setClassLoaderDomain(classLoaderDomain);
					components.add(component);
				}
			} else if ((componentDescriptor = componentJarFile
					.getJarEntry("META-INF/resource-adaptor-type-jar.xml")) != null) {
				// create class loader domain shared by all components
				URLClassLoaderDomainImpl classLoaderDomain = componentManagement.getClassLoaderFactory().newClassLoaderDomain(new URL[] { componentJarDeploymentDir.toURL() }, Thread
						.currentThread().getContextClassLoader());
				// parse descriptor
				componentDescriptorInputStream = componentJarFile
						.getInputStream(componentDescriptor);
				ResourceAdaptorTypeDescriptorFactoryImpl descriptorFactory = componentManagement
						.getComponentDescriptorFactory()
						.getResourceAdaptorTypeDescriptorFactory();
				List<ResourceAdaptorTypeDescriptorImpl> descriptors = descriptorFactory
						.parse(componentDescriptorInputStream);
				// create components
				for (ResourceAdaptorTypeDescriptorImpl descriptor : descriptors) {
					ResourceAdaptorTypeComponentImpl component = new ResourceAdaptorTypeComponentImpl(
							descriptor);
					component.setDeploymentDir(componentJarDeploymentDir);
					component.setClassLoaderDomain(classLoaderDomain);
					components.add(component);
				}
			} else if ((componentDescriptor = componentJarFile
					.getJarEntry("META-INF/resource-adaptor-jar.xml")) != null) {
				// create class loader domain shared by all components
				URLClassLoaderDomainImpl classLoaderDomain = componentManagement
						.getClassLoaderFactory()
						.newClassLoaderDomain(
								new URL[] { componentJarDeploymentDir.toURL() },
								Thread.currentThread().getContextClassLoader());				
				// parse descriptor
				componentDescriptorInputStream = componentJarFile
						.getInputStream(componentDescriptor);
				ResourceAdaptorDescriptorFactoryImpl descriptorFactory = componentManagement
						.getComponentDescriptorFactory()
						.getResourceAdaptorDescriptorFactory();
				List<ResourceAdaptorDescriptorImpl> descriptors = descriptorFactory
						.parse(componentDescriptorInputStream);
				// create components
				for (ResourceAdaptorDescriptorImpl descriptor : descriptors) {
					ResourceAdaptorComponentImpl component = new ResourceAdaptorComponentImpl(
							descriptor);
					component.setDeploymentDir(componentJarDeploymentDir);
					component.setClassLoaderDomain(classLoaderDomain);
					components.add(component);
				}
			} else {
				throw new DeploymentException(
						"No Deployment Descriptor found in the "
								+ componentJarFile.getName()
								+ " entry of a deployable unit.");
			}
		} catch (IOException e) {
			throw new DeploymentException(
					"failed to parse jar descriptor from "
							+ componentJarFile.getName(), e);
		} finally {
			if (componentDescriptorInputStream != null) {
				try {
					componentDescriptorInputStream.close();
				} catch (IOException e) {
					logger
							.error("failed to close inputstream of descriptor for jar "
									+ componentJarFile);
				}
			}
		}

		// close component jar file
		try {
			componentJarFile.close();
		} catch (IOException e) {
			logger.error("failed to close component jar file", e);
		}
		// and delete the extracted jar file, we don't need it anymore
		if (!extractedFile.delete()) {
			logger.warn("failed to delete " + extractedFile);
		}

		return components;
	}
Builds the DU component from a jar with the specified file name,
contained in the specified DU jar file. The component is built in the
specified deployment dir.

@param componentJarFileName
@param deployableUnitJar
@param deploymentDir
@param documentBuilder
@return
@throws DeploymentException