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.kernel.repository;
019    
020    import java.io.Serializable;
021    import java.util.Collection;
022    import java.util.HashSet;
023    import java.util.LinkedHashSet;
024    import java.util.Set;
025    import java.util.List;
026    import java.util.Collections;
027    import java.util.ArrayList;
028    import java.util.Iterator;
029    
030    /**
031     * holds the data from the EnvironmentType xml while it is being resolved, transitively closed, etc.
032     *
033     * @version $Rev: 519834 $ $Date: 2007-03-19 00:32:05 -0400 (Mon, 19 Mar 2007) $
034     */
035    public class Environment implements Serializable {
036        private static final long serialVersionUID = 7075760873629376317L;
037    
038        private Artifact configId;
039    
040        private final LinkedHashSet dependencies = new LinkedHashSet();
041    
042        private final Set hiddenClasses = new HashSet();
043        private final Set nonOverrideableClasses = new HashSet();
044    
045        private boolean inverseClassLoading;
046        private boolean suppressDefaultEnvironment;
047    
048        public Environment() {
049        }
050    
051        public Environment(Artifact configId) {
052            this.configId = configId;
053        }
054    
055        public Environment(Environment environment) {
056            this.configId = environment.getConfigId();
057            this.dependencies.addAll(environment.dependencies);
058            this.hiddenClasses.addAll(environment.getHiddenClasses());
059            this.nonOverrideableClasses.addAll(environment.getNonOverrideableClasses());
060            this.inverseClassLoading = environment.isInverseClassLoading();
061            this.suppressDefaultEnvironment = environment.isSuppressDefaultEnvironment();
062        }
063    
064        public Artifact getConfigId() {
065            return configId;
066        }
067    
068        public void setConfigId(Artifact configId) {
069            this.configId = configId;
070        }
071    
072        /**
073         * Gets a List (with elements of type Dependency) of the configuration and
074         * JAR dependencies of this configuration.
075         *
076         * @see Dependency
077         */
078        public List<Dependency> getDependencies() {
079            return Collections.unmodifiableList(new ArrayList<Dependency>(dependencies));
080        }
081    
082        public void addDependency(Artifact artifact, ImportType importType) {
083            this.dependencies.add(new Dependency(artifact, importType));
084        }
085    
086        public void addDependency(Dependency dependency) {
087            this.dependencies.add(dependency);
088        }
089    
090        public void addDependencies(Collection dependencies) {
091            for (Iterator iterator = dependencies.iterator(); iterator.hasNext();) {
092                // make sure they are all dependency objects... generics would be sooooo nice
093                Dependency dependency = (Dependency) iterator.next();
094                addDependency(dependency);
095            }
096        }
097    
098        public void setDependencies(Collection dependencies) {
099            this.dependencies.clear();
100            addDependencies(dependencies);
101        }
102    
103        /**
104         * todo: I should be documented so it's not completely unclear what kind of
105         * elements I hold.
106         */
107        public Set getHiddenClasses() {
108            return hiddenClasses;
109        }
110    
111        public void addHiddenClasses(Collection hiddenClasses) {
112            this.hiddenClasses.addAll(hiddenClasses);
113        }
114    
115        public void setHiddenClasses(Collection hiddenClasses) {
116            this.hiddenClasses.clear();
117            addHiddenClasses(hiddenClasses);
118        }
119    
120        /**
121         * todo: I should be documented so it's not completely unclear what kind of
122         * elements I hold.
123         */
124        public Set getNonOverrideableClasses() {
125            return nonOverrideableClasses;
126        }
127    
128        public void addNonOverrideableClasses(Collection nonOverrideableClasses) {
129            this.nonOverrideableClasses.addAll(nonOverrideableClasses);
130        }
131    
132        public void setNonOverrideableClasses(Collection nonOverrideableClasses) {
133            this.nonOverrideableClasses.clear();
134            addNonOverrideableClasses(nonOverrideableClasses);
135        }
136    
137        public boolean isInverseClassLoading() {
138            return inverseClassLoading;
139        }
140    
141        public void setInverseClassLoading(boolean inverseClassLoading) {
142            this.inverseClassLoading = inverseClassLoading;
143        }
144    
145        public boolean isSuppressDefaultEnvironment() {
146            return suppressDefaultEnvironment;
147        }
148    
149        public void setSuppressDefaultEnvironment(boolean suppressDefaultEnvironment) {
150            this.suppressDefaultEnvironment = suppressDefaultEnvironment;
151        }
152    
153    }