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 java.util.ArrayList;
021 import java.util.Collection;
022 import java.util.Set;
023
024 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
025 import javax.enterprise.deploy.spi.factories.DeploymentFactory;
026 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
027
028 import org.apache.geronimo.deployment.ModuleConfigurer;
029 import org.apache.geronimo.deployment.plugin.jmx.RemoteDeploymentManager;
030 import org.apache.geronimo.gbean.AbstractName;
031 import org.apache.geronimo.gbean.AbstractNameQuery;
032 import org.apache.geronimo.gbean.GBeanInfo;
033 import org.apache.geronimo.gbean.GBeanInfoBuilder;
034 import org.apache.geronimo.kernel.GBeanNotFoundException;
035 import org.apache.geronimo.kernel.Kernel;
036
037 /**
038 *
039 * @version $Rev: 503905 $ $Date: 2007-02-06 09:20:49 +1100 (Tue, 06 Feb 2007) $
040 */
041 public class DeploymentFactoryWithKernel extends BaseDeploymentFactory {
042 private final Kernel kernel;
043
044 public DeploymentFactoryWithKernel(Kernel kernel) {
045 if (null == kernel) {
046 throw new IllegalArgumentException("kernel is required");
047 }
048 this.kernel = kernel;
049 DeploymentFactoryManager.getInstance().registerDeploymentFactory(this);
050 }
051
052 protected Collection<ModuleConfigurer> getModuleConfigurers() throws DeploymentManagerCreationException {
053 Collection<ModuleConfigurer> moduleConfigurers = new ArrayList<ModuleConfigurer>();
054 Set<AbstractName> configurerNames = kernel.listGBeans(new AbstractNameQuery(ModuleConfigurer.class.getName()));
055 for (AbstractName configurerName : configurerNames) {
056 try {
057 ModuleConfigurer configurer = (ModuleConfigurer) kernel.getGBean(configurerName);
058 moduleConfigurers.add(configurer);
059 } catch (GBeanNotFoundException e) {
060 throw (AssertionError)new AssertionError("No gbean found for name returned in query : " + configurerName).initCause(e);
061 }
062 }
063 return moduleConfigurers;
064 }
065
066 protected RemoteDeploymentManager getRemoteDeploymentManager() throws DeploymentManagerCreationException {
067 try {
068 return (RemoteDeploymentManager) kernel.getGBean(RemoteDeploymentManager.class);
069 } catch (Exception e) {
070 throw (DeploymentManagerCreationException) new DeploymentManagerCreationException("See nested").initCause(e);
071 }
072 }
073
074 public static final GBeanInfo GBEAN_INFO;
075
076 static {
077 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(DeploymentFactoryWithKernel.class, "DeploymentFactory");
078
079 infoBuilder.addInterface(DeploymentFactory.class);
080
081 infoBuilder.setConstructor(new String[] {"kernel"});
082
083 GBEAN_INFO = infoBuilder.getBeanInfo();
084 }
085
086 public static GBeanInfo getGBeanInfo() {
087 return GBEAN_INFO;
088 }
089
090 }