KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > service > jsr88 > EnvironmentData


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.deployment.service.jsr88;
18
19 import java.util.Set JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
23 import org.apache.geronimo.deployment.xbeans.DependenciesType;
24 import org.apache.geronimo.deployment.xbeans.EnvironmentType;
25 import org.apache.geronimo.deployment.xbeans.ArtifactType;
26 import org.apache.xmlbeans.SchemaTypeLoader;
27 import org.apache.xmlbeans.XmlBeans;
28
29 /**
30  * Represents an environmentType (e.g. an environment element) in a Geronimo
31  * deployment plan.
32  *
33  * @version $Rev: 470597 $ $Date: 2006-11-02 18:30:55 -0500 (Thu, 02 Nov 2006) $
34  */

35 public class EnvironmentData extends XmlBeanSupport {
36     static final SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.typeLoaderForClassLoader(EnvironmentType.class.getClassLoader());
37
38     private Artifact configId;
39     private Artifact[] dependencies = new Artifact[0];
40
41     public EnvironmentData() {
42         super(null);
43     }
44
45     public EnvironmentData(EnvironmentType dependency) {
46         super(null);
47         configure(dependency);
48     }
49
50     protected EnvironmentType getEnvironmentType() {
51         return (EnvironmentType) getXmlObject();
52     }
53
54     public void configure(EnvironmentType env) {
55         setXmlObject(env);
56         if(env.isSetModuleId()) {
57             configId = new Artifact(env.getModuleId());
58         }
59         if(env.isSetDependencies()) {
60             DependenciesType deps = env.getDependencies();
61             dependencies = new Artifact[deps.getDependencyArray().length];
62             for (int i = 0; i < dependencies.length; i++) {
63                 dependencies[i] = new Artifact(deps.getDependencyArray(i));
64             }
65         }
66     }
67
68     // ----------------------- JavaBean Properties for environmentType ----------------------
69

70     public Artifact getConfigId() {
71         return configId;
72     }
73
74     public void setConfigId(Artifact configId) {
75         Artifact old = this.configId;
76         this.configId = configId;
77         if((old == null && configId == null) || (old != null&& old == configId)) {
78             return;
79         }
80         if(old != null) {
81             getEnvironmentType().unsetModuleId();
82         }
83         if(configId != null) {
84             configId.configure(getEnvironmentType().addNewModuleId());
85         }
86         pcs.firePropertyChange("moduleId", old, configId);
87     }
88
89     public Artifact[] getDependencies() {
90         return dependencies;
91     }
92
93     public void setDependencies(Artifact[] dependencies) {
94         Artifact[] old = this.dependencies;
95         Set JavaDoc before = new HashSet JavaDoc();
96         for (int i = 0; i < old.length; i++) {
97             before.add(old[i]);
98         }
99         this.dependencies = dependencies;
100         // Handle current or new dependencies
101
for (int i = 0; i < dependencies.length; i++) {
102             Artifact dep = dependencies[i];
103             if(dep.getArtifactType() == null) {
104                 if(!getEnvironmentType().isSetDependencies()) {
105                     getEnvironmentType().addNewDependencies();
106                 }
107                 dep.configure(getEnvironmentType().getDependencies().addNewDependency());
108             } else {
109                 before.remove(dep);
110             }
111         }
112         // Handle removed or new dependencies
113
for (Iterator JavaDoc it = before.iterator(); it.hasNext();) {
114             Artifact adapter = (Artifact) it.next();
115             ArtifactType all[] = getEnvironmentType().getDependencies().getDependencyArray();
116             for (int i = 0; i < all.length; i++) {
117                 if(all[i] == adapter) {
118                     getEnvironmentType().getDependencies().removeDependency(i);
119                     break;
120                 }
121             }
122         }
123         if(getEnvironmentType().isSetDependencies() && getEnvironmentType().getDependencies().getDependencyArray().length == 0) {
124             getEnvironmentType().unsetDependencies();
125         }
126         pcs.firePropertyChange("dependencies", old, dependencies);
127     }
128
129     public String JavaDoc[] getHiddenClasses() {
130         return getEnvironmentType().getHiddenClasses().getFilterArray();
131     }
132
133     public void setHiddenClasses(String JavaDoc[] hidden) {
134         String JavaDoc[] old = getEnvironmentType().isSetHiddenClasses() ? getEnvironmentType().getHiddenClasses().getFilterArray() : null;
135         if(!getEnvironmentType().isSetHiddenClasses()) {
136             getEnvironmentType().addNewHiddenClasses();
137         }
138         getEnvironmentType().getHiddenClasses().setFilterArray(hidden);
139         pcs.firePropertyChange("hiddenClasses", old, hidden);
140     }
141
142     public String JavaDoc[] getNonOverridableClasses() {
143         return getEnvironmentType().getNonOverridableClasses().getFilterArray();
144     }
145
146     public void setNonOverridableClasses(String JavaDoc[] fixed) {
147         String JavaDoc[] old = getEnvironmentType().isSetNonOverridableClasses() ? getEnvironmentType().getNonOverridableClasses().getFilterArray() : null;
148         if(!getEnvironmentType().isSetNonOverridableClasses()) {
149             getEnvironmentType().addNewNonOverridableClasses();
150         }
151         getEnvironmentType().getNonOverridableClasses().setFilterArray(fixed);
152         pcs.firePropertyChange("nonOverridableClasses", old, fixed);
153     }
154
155     public boolean isInverseClassLoading() {
156         return getEnvironmentType().isSetInverseClassloading();
157     }
158
159     public void setInverseClassLoading(boolean inverse) {
160         boolean old = isInverseClassLoading();
161         if(!inverse) {
162             if(old) {
163                 getEnvironmentType().unsetInverseClassloading();
164             }
165         } else {
166             if(!old) {
167                 getEnvironmentType().addNewInverseClassloading();
168             }
169         }
170         pcs.firePropertyChange("inverseClassLoading", old, inverse);
171     }
172
173     public boolean isSuppressDefaultEnvironment() {
174         return getEnvironmentType().isSetSuppressDefaultEnvironment();
175     }
176
177     public void setSuppressDefaultEnvironment(boolean suppress) {
178         boolean old = isSuppressDefaultEnvironment();
179         if(!suppress) {
180             if(old) {
181                 getEnvironmentType().unsetSuppressDefaultEnvironment();
182             }
183         } else {
184             if(!old) {
185                 getEnvironmentType().addNewSuppressDefaultEnvironment();
186             }
187         }
188         pcs.firePropertyChange("suppressDefaultEnvironment", old, suppress);
189     }
190
191     // ----------------------- End of JavaBean Properties ----------------------
192

193     protected SchemaTypeLoader getSchemaTypeLoader() {
194         return SCHEMA_TYPE_LOADER;
195     }
196 }
197
Popular Tags