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