public DeployableUnitID install(String url) throws NullPointerException,
			MalformedURLException, AlreadyDeployedException,
			DeploymentException, ManagementException {		

		try {
			final SleeContainer sleeContainer = getSleeContainer();
			final DeployableUnitBuilder deployableUnitBuilder = sleeContainer.getDeployableUnitManagement().getDeployableUnitBuilder();
			final SleeTransactionManager sleeTransactionManager = sleeContainer
					.getTransactionManager();
			final ComponentRepository componentRepositoryImpl = sleeContainer
					.getComponentRepository();
			final DeployableUnitManagement deployableUnitManagement = sleeContainer
					.getDeployableUnitManagement();

			synchronized (sleeContainer.getManagementMonitor()) {

				DeployableUnitID deployableUnitID = new DeployableUnitID(url);

				logger.info("Installing " +deployableUnitID);
				
				if (deployableUnitManagement
						.getDeployableUnit(deployableUnitID) != null) {
					throw new AlreadyDeployedException(
							"there is already a DU deployed for url " + url);
				}

				DeployableUnit deployableUnit = null;

				Thread currentThread = Thread.currentThread();
				ClassLoader currentClassLoader = currentThread
						.getContextClassLoader();

				Set<SleeComponent> componentsInstalled = new HashSet<SleeComponent>();
				boolean rollback = true;
				try {
					// start transaction
					sleeTransactionManager.begin();
					// build du
					deployableUnit = deployableUnitBuilder.build(url,
							tempDUJarsDeploymentRoot, componentRepositoryImpl);
					// install each component built
					for (LibraryComponent component : deployableUnit
							.getLibraryComponents().values()) {
						componentRepositoryImpl.putComponent(component);
						updateSecurityPermissions(component, false);
						logger.info("Installed " + component);
					}
					for (EventTypeComponent component : deployableUnit
							.getEventTypeComponents().values()) {
						componentRepositoryImpl.putComponent(component);
						logger.info("Installed " + component);
					}
					for (ResourceAdaptorTypeComponent component : deployableUnit
							.getResourceAdaptorTypeComponents().values()) {
						componentRepositoryImpl.putComponent(component);
						currentThread.setContextClassLoader(component
								.getClassLoader());
						sleeContainer.getResourceManagement()
								.installResourceAdaptorType(component);
						componentsInstalled.add(component);
						logger.info("Installed " + component);
					}
					// before executing the logic to install an profile spec, ra
					// or sbb insert the components in the repo, a component can
					// require that another is already in repo
					for (ProfileSpecificationComponent component : deployableUnit
							.getProfileSpecificationComponents().values()) {
						componentRepositoryImpl.putComponent(component);
					}
					for (ResourceAdaptorComponent component : deployableUnit
							.getResourceAdaptorComponents().values()) {
						componentRepositoryImpl.putComponent(component);
					}
					for (SbbComponent component : deployableUnit
							.getSbbComponents().values()) {
						componentRepositoryImpl.putComponent(component);
					}
					// run the install logic to install an profile spec, ra or
					// sbb
					for (ProfileSpecificationComponent component : deployableUnit
							.getProfileSpecificationComponents().values()) {
						currentThread.setContextClassLoader(component
								.getClassLoader());
						sleeContainer.getSleeProfileTableManager()
								.installProfileSpecification(component);
						componentsInstalled.add(component);
						updateSecurityPermissions(component, false);
						logger.info("Installed " + component);
					}
					for (ResourceAdaptorComponent component : deployableUnit
							.getResourceAdaptorComponents().values()) {
						currentThread.setContextClassLoader(component
								.getClassLoader());
						sleeContainer.getResourceManagement()
								.installResourceAdaptor(component);
						componentsInstalled.add(component);
						updateSecurityPermissions(component, false);
						logger.info("Installed " + component);
					}
					for (SbbComponent component : deployableUnit
							.getSbbComponents().values()) {
						currentThread.setContextClassLoader(component
								.getClassLoader());
						sleeContainer.getSbbManagement().installSbb(component);
						componentsInstalled.add(component);
						updateSecurityPermissions(component, false);
						logger.info("Installed " + component);
					}
					// finally install the services
					currentThread.setContextClassLoader(currentClassLoader);
					for (ServiceComponent component : deployableUnit
							.getServiceComponents().values()) {
						componentRepositoryImpl.putComponent(component);
						sleeContainer.getServiceManagement().installService(
								component);
						componentsInstalled.add(component);
						logger.info("Installed " + component+". Root sbb is "+component.getRootSbbComponent());
					}
					
					deployableUnitManagement.addDeployableUnit(deployableUnit);
					logger.info("Installed " +deployableUnitID);
					updateSecurityPermissions(null, true);
					rollback = false;
					
					return deployableUnitID;
				} finally {
					currentThread.setContextClassLoader(currentClassLoader);
					try {
						if (rollback) {														
							if (deployableUnit != null) {
								// remove all components added to repo
								// put all components in the repo again
								for (LibraryComponent component : deployableUnit
										.getLibraryComponents().values()) {
									removeSecurityPermissions(component, false);
									componentRepositoryImpl.removeComponent(component.getLibraryID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								for (EventTypeComponent component : deployableUnit
										.getEventTypeComponents().values()) {
									componentRepositoryImpl.removeComponent(component.getEventTypeID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								for (ResourceAdaptorTypeComponent component : deployableUnit
										.getResourceAdaptorTypeComponents()
										.values()) {
									removeSecurityPermissions(component, false);
									if(componentsInstalled.contains(component)) {
										sleeContainer.getResourceManagement().uninstallResourceAdaptorType(component);
									}
									componentRepositoryImpl.removeComponent(component.getResourceAdaptorTypeID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								for (ProfileSpecificationComponent component : deployableUnit
										.getProfileSpecificationComponents()
										.values()) {
									if(componentsInstalled.contains(component)) {
										sleeContainer.getSleeProfileTableManager().uninstallProfileSpecification(component);
									}
									componentRepositoryImpl.removeComponent(component.getProfileSpecificationID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								for (ResourceAdaptorComponent component : deployableUnit
										.getResourceAdaptorComponents().values()) {
									removeSecurityPermissions(component, false);
									if(componentsInstalled.contains(component)) {
										sleeContainer.getResourceManagement().uninstallResourceAdaptor(component);
									}
									componentRepositoryImpl.removeComponent(component.getResourceAdaptorID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								for (SbbComponent component : deployableUnit
										.getSbbComponents().values()) {
									removeSecurityPermissions(component, false);
									if(componentsInstalled.contains(component)) {
										sleeContainer.getSbbManagement().uninstallSbb(component);
									}
									componentRepositoryImpl.removeComponent(component.getSbbID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								for (ServiceComponent component : deployableUnit
										.getServiceComponents().values()) {
									if(componentsInstalled.contains(component)) {
										sleeContainer.getServiceManagement().uninstallService(component);
									}
									componentRepositoryImpl.removeComponent(component.getServiceID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								removeSecurityPermissions(null, true);
								// undeploy the unit
								deployableUnit.undeploy();
							}
							sleeTransactionManager.rollback();
						} else {
							sleeTransactionManager.commit();
						}
					} catch (Exception ex) {
						throw new ManagementException(
								"Exception while completing transaction", ex);
					}
				}
			}
		} catch (AlreadyDeployedException e) {
			throw e;
		} catch (DeploymentException e) {
			// This will remove stack trace;
			// throw e;
			throw new DeploymentException(
					"Failure encountered during deploy process.", e);
		} catch (Throwable e) {
			if (logger.isDebugEnabled()) {
				logger.debug(e.getMessage(),e);
			}
			throw new ManagementException(e.getMessage(), e);
		}
	}
public DeployableUnitID install(String url) throws NullPointerException,
			MalformedURLException, AlreadyDeployedException,
			DeploymentException, ManagementException {		

		try {
			final SleeContainer sleeContainer = getSleeContainer();
			final DeployableUnitBuilder deployableUnitBuilder = sleeContainer.getDeployableUnitManagement().getDeployableUnitBuilder();
			final SleeTransactionManager sleeTransactionManager = sleeContainer
					.getTransactionManager();
			final ComponentRepository componentRepositoryImpl = sleeContainer
					.getComponentRepository();
			final DeployableUnitManagement deployableUnitManagement = sleeContainer
					.getDeployableUnitManagement();

			synchronized (sleeContainer.getManagementMonitor()) {

				DeployableUnitID deployableUnitID = new DeployableUnitID(url);

				logger.info("Installing " +deployableUnitID);
				
				if (deployableUnitManagement
						.getDeployableUnit(deployableUnitID) != null) {
					throw new AlreadyDeployedException(
							"there is already a DU deployed for url " + url);
				}

				DeployableUnit deployableUnit = null;

				Thread currentThread = Thread.currentThread();
				ClassLoader currentClassLoader = currentThread
						.getContextClassLoader();

				Set<SleeComponent> componentsInstalled = new HashSet<SleeComponent>();
				boolean rollback = true;
				try {
					
					sleeTransactionManager.begin();
					
					deployableUnit = deployableUnitBuilder.build(url,
							tempDUJarsDeploymentRoot, componentRepositoryImpl);
					
					for (LibraryComponent component : deployableUnit
							.getLibraryComponents().values()) {
						componentRepositoryImpl.putComponent(component);
						updateSecurityPermissions(component, false);
						logger.info("Installed " + component);
					}
					for (EventTypeComponent component : deployableUnit
							.getEventTypeComponents().values()) {
						componentRepositoryImpl.putComponent(component);
						logger.info("Installed " + component);
					}
					for (ResourceAdaptorTypeComponent component : deployableUnit
							.getResourceAdaptorTypeComponents().values()) {
						componentRepositoryImpl.putComponent(component);
						currentThread.setContextClassLoader(component
								.getClassLoader());
						sleeContainer.getResourceManagement()
								.installResourceAdaptorType(component);
						componentsInstalled.add(component);
						logger.info("Installed " + component);
					}
					
					
					
					for (ProfileSpecificationComponent component : deployableUnit
							.getProfileSpecificationComponents().values()) {
						componentRepositoryImpl.putComponent(component);
					}
					for (ResourceAdaptorComponent component : deployableUnit
							.getResourceAdaptorComponents().values()) {
						componentRepositoryImpl.putComponent(component);
					}
					for (SbbComponent component : deployableUnit
							.getSbbComponents().values()) {
						componentRepositoryImpl.putComponent(component);
					}
					
					
					for (ProfileSpecificationComponent component : deployableUnit
							.getProfileSpecificationComponents().values()) {
						currentThread.setContextClassLoader(component
								.getClassLoader());
						sleeContainer.getSleeProfileTableManager()
								.installProfileSpecification(component);
						componentsInstalled.add(component);
						updateSecurityPermissions(component, false);
						logger.info("Installed " + component);
					}
					for (ResourceAdaptorComponent component : deployableUnit
							.getResourceAdaptorComponents().values()) {
						currentThread.setContextClassLoader(component
								.getClassLoader());
						sleeContainer.getResourceManagement()
								.installResourceAdaptor(component);
						componentsInstalled.add(component);
						updateSecurityPermissions(component, false);
						logger.info("Installed " + component);
					}
					for (SbbComponent component : deployableUnit
							.getSbbComponents().values()) {
						currentThread.setContextClassLoader(component
								.getClassLoader());
						sleeContainer.getSbbManagement().installSbb(component);
						componentsInstalled.add(component);
						updateSecurityPermissions(component, false);
						logger.info("Installed " + component);
					}
					
					currentThread.setContextClassLoader(currentClassLoader);
					for (ServiceComponent component : deployableUnit
							.getServiceComponents().values()) {
						componentRepositoryImpl.putComponent(component);
						sleeContainer.getServiceManagement().installService(
								component);
						componentsInstalled.add(component);
						logger.info("Installed " + component+". Root sbb is "+component.getRootSbbComponent());
					}
					
					deployableUnitManagement.addDeployableUnit(deployableUnit);
					logger.info("Installed " +deployableUnitID);
					updateSecurityPermissions(null, true);
					rollback = false;
					
					return deployableUnitID;
				} finally {
					currentThread.setContextClassLoader(currentClassLoader);
					try {
						if (rollback) {														
							if (deployableUnit != null) {
								
								
								for (LibraryComponent component : deployableUnit
										.getLibraryComponents().values()) {
									removeSecurityPermissions(component, false);
									componentRepositoryImpl.removeComponent(component.getLibraryID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								for (EventTypeComponent component : deployableUnit
										.getEventTypeComponents().values()) {
									componentRepositoryImpl.removeComponent(component.getEventTypeID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								for (ResourceAdaptorTypeComponent component : deployableUnit
										.getResourceAdaptorTypeComponents()
										.values()) {
									removeSecurityPermissions(component, false);
									if(componentsInstalled.contains(component)) {
										sleeContainer.getResourceManagement().uninstallResourceAdaptorType(component);
									}
									componentRepositoryImpl.removeComponent(component.getResourceAdaptorTypeID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								for (ProfileSpecificationComponent component : deployableUnit
										.getProfileSpecificationComponents()
										.values()) {
									if(componentsInstalled.contains(component)) {
										sleeContainer.getSleeProfileTableManager().uninstallProfileSpecification(component);
									}
									componentRepositoryImpl.removeComponent(component.getProfileSpecificationID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								for (ResourceAdaptorComponent component : deployableUnit
										.getResourceAdaptorComponents().values()) {
									removeSecurityPermissions(component, false);
									if(componentsInstalled.contains(component)) {
										sleeContainer.getResourceManagement().uninstallResourceAdaptor(component);
									}
									componentRepositoryImpl.removeComponent(component.getResourceAdaptorID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								for (SbbComponent component : deployableUnit
										.getSbbComponents().values()) {
									removeSecurityPermissions(component, false);
									if(componentsInstalled.contains(component)) {
										sleeContainer.getSbbManagement().uninstallSbb(component);
									}
									componentRepositoryImpl.removeComponent(component.getSbbID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								for (ServiceComponent component : deployableUnit
										.getServiceComponents().values()) {
									if(componentsInstalled.contains(component)) {
										sleeContainer.getServiceManagement().uninstallService(component);
									}
									componentRepositoryImpl.removeComponent(component.getServiceID());
									logger.info("Uninstalled " + component
											+ " due to tx rollback");
								}
								removeSecurityPermissions(null, true);
								
								deployableUnit.undeploy();
							}
							sleeTransactionManager.rollback();
						} else {
							sleeTransactionManager.commit();
						}
					} catch (Exception ex) {
						throw new ManagementException(
								"Exception while completing transaction", ex);
					}
				}
			}
		} catch (AlreadyDeployedException e) {
			throw e;
		} catch (DeploymentException e) {
			
			
			throw new DeploymentException(
					"Failure encountered during deploy process.", e);
		} catch (Throwable e) {
			if (logger.isDebugEnabled()) {
				logger.debug(e.getMessage(),e);
			}
			throw new ManagementException(e.getMessage(), e);
		}
	}
public DeployableUnitID install ( String url ) throws NullPointerException , MalformedURLException , AlreadyDeployedException , DeploymentException , ManagementException { try { final SleeContainer sleeContainer = getSleeContainer ( ) ; final DeployableUnitBuilder deployableUnitBuilder = sleeContainer . getDeployableUnitManagement ( ) . getDeployableUnitBuilder ( ) ; final SleeTransactionManager sleeTransactionManager = sleeContainer . getTransactionManager ( ) ; final ComponentRepository componentRepositoryImpl = sleeContainer . getComponentRepository ( ) ; final DeployableUnitManagement deployableUnitManagement = sleeContainer . getDeployableUnitManagement ( ) ; synchronized ( sleeContainer . getManagementMonitor ( ) ) { DeployableUnitID deployableUnitID = new DeployableUnitID ( url ) ; logger . info ( "Installing " + deployableUnitID ) ; if ( deployableUnitManagement . getDeployableUnit ( deployableUnitID ) != null ) { throw new AlreadyDeployedException ( "there is already a DU deployed for url " + url ) ; } DeployableUnit deployableUnit = null ; Thread currentThread = Thread . currentThread ( ) ; ClassLoader currentClassLoader = currentThread . getContextClassLoader ( ) ; Set < SleeComponent > componentsInstalled = new HashSet < SleeComponent > ( ) ; boolean rollback = true ; try { // start transaction sleeTransactionManager . begin ( ) ; // build du deployableUnit = deployableUnitBuilder . build ( url , tempDUJarsDeploymentRoot , componentRepositoryImpl ) ; // install each component built for ( LibraryComponent component : deployableUnit . getLibraryComponents ( ) . values ( ) ) { componentRepositoryImpl . putComponent ( component ) ; updateSecurityPermissions ( component , false ) ; logger . info ( "Installed " + component ) ; } for ( EventTypeComponent component : deployableUnit . getEventTypeComponents ( ) . values ( ) ) { componentRepositoryImpl . putComponent ( component ) ; logger . info ( "Installed " + component ) ; } for ( ResourceAdaptorTypeComponent component : deployableUnit . getResourceAdaptorTypeComponents ( ) . values ( ) ) { componentRepositoryImpl . putComponent ( component ) ; currentThread . setContextClassLoader ( component . getClassLoader ( ) ) ; sleeContainer . getResourceManagement ( ) . installResourceAdaptorType ( component ) ; componentsInstalled . add ( component ) ; logger . info ( "Installed " + component ) ; } // before executing the logic to install an profile spec, ra // or sbb insert the components in the repo, a component can // require that another is already in repo for ( ProfileSpecificationComponent component : deployableUnit . getProfileSpecificationComponents ( ) . values ( ) ) { componentRepositoryImpl . putComponent ( component ) ; } for ( ResourceAdaptorComponent component : deployableUnit . getResourceAdaptorComponents ( ) . values ( ) ) { componentRepositoryImpl . putComponent ( component ) ; } for ( SbbComponent component : deployableUnit . getSbbComponents ( ) . values ( ) ) { componentRepositoryImpl . putComponent ( component ) ; } // run the install logic to install an profile spec, ra or // sbb for ( ProfileSpecificationComponent component : deployableUnit . getProfileSpecificationComponents ( ) . values ( ) ) { currentThread . setContextClassLoader ( component . getClassLoader ( ) ) ; sleeContainer . getSleeProfileTableManager ( ) . installProfileSpecification ( component ) ; componentsInstalled . add ( component ) ; updateSecurityPermissions ( component , false ) ; logger . info ( "Installed " + component ) ; } for ( ResourceAdaptorComponent component : deployableUnit . getResourceAdaptorComponents ( ) . values ( ) ) { currentThread . setContextClassLoader ( component . getClassLoader ( ) ) ; sleeContainer . getResourceManagement ( ) . installResourceAdaptor ( component ) ; componentsInstalled . add ( component ) ; updateSecurityPermissions ( component , false ) ; logger . info ( "Installed " + component ) ; } for ( SbbComponent component : deployableUnit . getSbbComponents ( ) . values ( ) ) { currentThread . setContextClassLoader ( component . getClassLoader ( ) ) ; sleeContainer . getSbbManagement ( ) . installSbb ( component ) ; componentsInstalled . add ( component ) ; updateSecurityPermissions ( component , false ) ; logger . info ( "Installed " + component ) ; } // finally install the services currentThread . setContextClassLoader ( currentClassLoader ) ; for ( ServiceComponent component : deployableUnit . getServiceComponents ( ) . values ( ) ) { componentRepositoryImpl . putComponent ( component ) ; sleeContainer . getServiceManagement ( ) . installService ( component ) ; componentsInstalled . add ( component ) ; logger . info ( "Installed " + component + ". Root sbb is " + component . getRootSbbComponent ( ) ) ; } deployableUnitManagement . addDeployableUnit ( deployableUnit ) ; logger . info ( "Installed " + deployableUnitID ) ; updateSecurityPermissions ( null , true ) ; rollback = false ; return deployableUnitID ; } finally { currentThread . setContextClassLoader ( currentClassLoader ) ; try { if ( rollback ) { if ( deployableUnit != null ) { // remove all components added to repo // put all components in the repo again for ( LibraryComponent component : deployableUnit . getLibraryComponents ( ) . values ( ) ) { removeSecurityPermissions ( component , false ) ; componentRepositoryImpl . removeComponent ( component . getLibraryID ( ) ) ; logger . info ( "Uninstalled " + component + " due to tx rollback" ) ; } for ( EventTypeComponent component : deployableUnit . getEventTypeComponents ( ) . values ( ) ) { componentRepositoryImpl . removeComponent ( component . getEventTypeID ( ) ) ; logger . info ( "Uninstalled " + component + " due to tx rollback" ) ; } for ( ResourceAdaptorTypeComponent component : deployableUnit . getResourceAdaptorTypeComponents ( ) . values ( ) ) { removeSecurityPermissions ( component , false ) ; if ( componentsInstalled . contains ( component ) ) { sleeContainer . getResourceManagement ( ) . uninstallResourceAdaptorType ( component ) ; } componentRepositoryImpl . removeComponent ( component . getResourceAdaptorTypeID ( ) ) ; logger . info ( "Uninstalled " + component + " due to tx rollback" ) ; } for ( ProfileSpecificationComponent component : deployableUnit . getProfileSpecificationComponents ( ) . values ( ) ) { if ( componentsInstalled . contains ( component ) ) { sleeContainer . getSleeProfileTableManager ( ) . uninstallProfileSpecification ( component ) ; } componentRepositoryImpl . removeComponent ( component . getProfileSpecificationID ( ) ) ; logger . info ( "Uninstalled " + component + " due to tx rollback" ) ; } for ( ResourceAdaptorComponent component : deployableUnit . getResourceAdaptorComponents ( ) . values ( ) ) { removeSecurityPermissions ( component , false ) ; if ( componentsInstalled . contains ( component ) ) { sleeContainer . getResourceManagement ( ) . uninstallResourceAdaptor ( component ) ; } componentRepositoryImpl . removeComponent ( component . getResourceAdaptorID ( ) ) ; logger . info ( "Uninstalled " + component + " due to tx rollback" ) ; } for ( SbbComponent component : deployableUnit . getSbbComponents ( ) . values ( ) ) { removeSecurityPermissions ( component , false ) ; if ( componentsInstalled . contains ( component ) ) { sleeContainer . getSbbManagement ( ) . uninstallSbb ( component ) ; } componentRepositoryImpl . removeComponent ( component . getSbbID ( ) ) ; logger . info ( "Uninstalled " + component + " due to tx rollback" ) ; } for ( ServiceComponent component : deployableUnit . getServiceComponents ( ) . values ( ) ) { if ( componentsInstalled . contains ( component ) ) { sleeContainer . getServiceManagement ( ) . uninstallService ( component ) ; } componentRepositoryImpl . removeComponent ( component . getServiceID ( ) ) ; logger . info ( "Uninstalled " + component + " due to tx rollback" ) ; } removeSecurityPermissions ( null , true ) ; // undeploy the unit deployableUnit . undeploy ( ) ; } sleeTransactionManager . rollback ( ) ; } else { sleeTransactionManager . commit ( ) ; } } catch ( Exception ex ) { throw new ManagementException ( "Exception while completing transaction" , ex ) ; } } } } catch ( AlreadyDeployedException e ) { throw e ; } catch ( DeploymentException e ) { // This will remove stack trace; // throw e; throw new DeploymentException ( "Failure encountered during deploy process." , e ) ; } catch ( Throwable e ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( e . getMessage ( ) , e ) ; } throw new ManagementException ( e . getMessage ( ) , e ) ; } }
/*
(non-Javadoc)

@see javax.slee.management.DeploymentMBean#install(java.lang.String)
/ * ( non - Javadoc )