001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.deployment.plugin.factories; 019 020 import javax.enterprise.deploy.spi.DeploymentManager; 021 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException; 022 import javax.enterprise.deploy.spi.factories.DeploymentFactory; 023 024 import org.apache.geronimo.kernel.Kernel; 025 import org.apache.geronimo.kernel.util.MainBootstrapper; 026 027 /** 028 * 029 * @version $Rev: 503905 $ $Date: 2007-02-06 09:20:49 +1100 (Tue, 06 Feb 2007) $ 030 */ 031 public class DeploymentFactoryBootstrapper implements DeploymentFactory { 032 private final Kernel kernel; 033 private final DeploymentFactory delegate; 034 035 public DeploymentFactoryBootstrapper() throws DeploymentManagerCreationException { 036 kernel = newKernel(); 037 038 try { 039 delegate = (DeploymentFactory) kernel.getGBean(DeploymentFactory.class); 040 } catch (Exception e) { 041 throw (DeploymentManagerCreationException) new DeploymentManagerCreationException("See nested").initCause(e); 042 } 043 } 044 045 046 public DeploymentManager getDeploymentManager(String uri, String username, String password) throws DeploymentManagerCreationException { 047 return delegate.getDeploymentManager(uri, username, password); 048 } 049 050 public DeploymentManager getDisconnectedDeploymentManager(String uri) throws DeploymentManagerCreationException { 051 return delegate.getDisconnectedDeploymentManager(uri); 052 } 053 054 public String getDisplayName() { 055 return delegate.getDisplayName(); 056 } 057 058 public String getProductVersion() { 059 return delegate.getProductVersion(); 060 } 061 062 public boolean handlesURI(String uri) { 063 return delegate.handlesURI(uri); 064 } 065 066 protected Kernel newKernel() throws DeploymentManagerCreationException { 067 ClassLoader classLoader = DeploymentFactoryBootstrapper.class.getClassLoader(); 068 069 MainBootstrapper bootstrapper = new MainBootstrapper(); 070 try { 071 bootstrapper.bootKernel(); 072 bootstrapper.loadBootConfiguration(classLoader); 073 bootstrapper.loadPersistentConfigurations(); 074 } catch (Exception e) { 075 throw (DeploymentManagerCreationException) new DeploymentManagerCreationException("See nested").initCause(e); 076 } 077 return bootstrapper.getKernel(); 078 } 079 080 }