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;
019    
020    import java.io.File;
021    import java.io.InputStream;
022    import java.util.Collection;
023    import java.util.Locale;
024    
025    import javax.enterprise.deploy.model.DeployableObject;
026    import javax.enterprise.deploy.shared.DConfigBeanVersionType;
027    import javax.enterprise.deploy.shared.ModuleType;
028    import javax.enterprise.deploy.spi.DeploymentConfiguration;
029    import javax.enterprise.deploy.spi.DeploymentManager;
030    import javax.enterprise.deploy.spi.Target;
031    import javax.enterprise.deploy.spi.TargetModuleID;
032    import javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException;
033    import javax.enterprise.deploy.spi.exceptions.InvalidModuleException;
034    import javax.enterprise.deploy.spi.exceptions.TargetException;
035    import javax.enterprise.deploy.spi.status.ProgressObject;
036    
037    import org.apache.geronimo.deployment.ModuleConfigurer;
038    
039    /**
040     * Implementation of a disconnected JSR88 DeploymentManager.
041     *
042     *
043     * @version $Rev: 512979 $ $Date: 2007-02-28 16:28:28 -0500 (Wed, 28 Feb 2007) $
044     */
045    public class DisconnectedDeploymentManager implements DeploymentManager {
046    
047        private final Collection<ModuleConfigurer> moduleConfigurers;
048    
049        public DisconnectedDeploymentManager(Collection<ModuleConfigurer> moduleConfigurers) {
050            if (null == moduleConfigurers) {
051                throw new IllegalArgumentException("moduleConfigurers is required");
052            }
053            this.moduleConfigurers = moduleConfigurers;
054        }
055    
056        public DeploymentConfiguration createConfiguration(DeployableObject dObj) throws InvalidModuleException {
057            if (dObj == null) {
058                throw new NullPointerException("No deployable object supplied to configure");
059            }
060            ModuleConfigurer configurer = null;
061            for (ModuleConfigurer moduleConfigurer : moduleConfigurers) {
062                if (moduleConfigurer.getModuleType() == dObj.getType()) {
063                    configurer = moduleConfigurer;
064                   break;
065                }
066            }
067            if (configurer == null) {
068                throw new InvalidModuleException("No configurer for module type: " + dObj.getType() + " registered");
069            }
070            return configurer.createConfiguration(dObj);
071        }
072    
073        public Locale[] getSupportedLocales() {
074            return new Locale[]{getDefaultLocale()};
075        }
076    
077        public Locale getCurrentLocale() {
078            return getDefaultLocale();
079        }
080    
081        public Locale getDefaultLocale() {
082            return Locale.getDefault();
083        }
084    
085        public boolean isLocaleSupported(Locale locale) {
086            return getDefaultLocale().equals(locale);
087        }
088    
089        public void setLocale(Locale locale) {
090            if (isLocaleSupported(locale)) {
091                throw new UnsupportedOperationException("Unsupported Locale");
092            }
093        }
094    
095        public DConfigBeanVersionType getDConfigBeanVersion() {
096            return DConfigBeanVersionType.V1_4;
097        }
098    
099        public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType version) {
100            return DConfigBeanVersionType.V1_4.equals(version);
101        }
102    
103        public void setDConfigBeanVersion(DConfigBeanVersionType version) throws DConfigBeanVersionUnsupportedException {
104            if (!isDConfigBeanVersionSupported(version)) {
105                throw new DConfigBeanVersionUnsupportedException("Version not supported " + version);
106            }
107        }
108    
109        public Target[] getTargets() throws IllegalStateException {
110            throw new IllegalStateException("Disconnected");
111        }
112    
113        public TargetModuleID[] getRunningModules(ModuleType moduleType, Target[] targets) throws TargetException, IllegalStateException {
114            throw new IllegalStateException("Disconnected");
115        }
116    
117        public TargetModuleID[] getNonRunningModules(ModuleType moduleType, Target[] targets) throws TargetException, IllegalStateException {
118            throw new IllegalStateException("Disconnected");
119        }
120    
121        public TargetModuleID[] getAvailableModules(ModuleType moduleType, Target[] targets) throws TargetException, IllegalStateException {
122            throw new IllegalStateException("Disconnected");
123        }
124    
125        public ProgressObject distribute(Target[] targets, File file, File file1) throws IllegalStateException {
126            throw new IllegalStateException("Disconnected");
127        }
128    
129        /**
130         * @deprecated
131         */
132        public ProgressObject distribute(Target[] targets, InputStream inputStream, InputStream inputStream1) throws IllegalStateException {
133            throw new IllegalStateException("Disconnected");
134        }
135    
136        public ProgressObject distribute(Target[] targets, ModuleType moduleType, InputStream inputStream, InputStream inputStream1) throws IllegalStateException {
137            throw new IllegalStateException("Disconnected");
138        }
139    
140        public ProgressObject start(TargetModuleID[] targetModuleIDs) throws IllegalStateException {
141            throw new IllegalStateException("Disconnected");
142        }
143    
144        public ProgressObject stop(TargetModuleID[] targetModuleIDs) throws IllegalStateException {
145            throw new IllegalStateException("Disconnected");
146        }
147    
148        public ProgressObject undeploy(TargetModuleID[] targetModuleIDs) throws IllegalStateException {
149            throw new IllegalStateException("Disconnected");
150        }
151    
152        public boolean isRedeploySupported() {
153            return false;
154        }
155    
156        public ProgressObject redeploy(TargetModuleID[] targetModuleIDs, File file, File file1) throws UnsupportedOperationException, IllegalStateException {
157            throw new IllegalStateException("Disconnected");
158        }
159    
160        public ProgressObject redeploy(TargetModuleID[] targetModuleIDs, InputStream inputStream, InputStream inputStream1) throws UnsupportedOperationException, IllegalStateException {
161            throw new IllegalStateException("Disconnected");
162        }
163    
164        public void release() {
165            throw new IllegalStateException("Disconnected");
166        }
167    }