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.service.jsr88;
017:
018: import java.util.Set;
019: import java.util.HashSet;
020: import java.util.Iterator;
021: import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
022: import org.apache.geronimo.deployment.xbeans.DependenciesType;
023: import org.apache.geronimo.deployment.xbeans.EnvironmentType;
024: import org.apache.geronimo.deployment.xbeans.ArtifactType;
025: import org.apache.xmlbeans.SchemaTypeLoader;
026: import org.apache.xmlbeans.XmlBeans;
027:
028: /**
029: * Represents an environmentType (e.g. an environment element) in a Geronimo
030: * deployment plan.
031: *
032: * @version $Rev: 470597 $ $Date: 2006-11-02 16:30:55 -0700 (Thu, 02 Nov 2006) $
033: */
034: public class EnvironmentData extends XmlBeanSupport {
035: static final SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans
036: .typeLoaderForClassLoader(EnvironmentType.class
037: .getClassLoader());
038:
039: private Artifact configId;
040: private Artifact[] dependencies = new Artifact[0];
041:
042: public EnvironmentData() {
043: super (null);
044: }
045:
046: public EnvironmentData(EnvironmentType dependency) {
047: super (null);
048: configure(dependency);
049: }
050:
051: protected EnvironmentType getEnvironmentType() {
052: return (EnvironmentType) getXmlObject();
053: }
054:
055: public void configure(EnvironmentType env) {
056: setXmlObject(env);
057: if (env.isSetModuleId()) {
058: configId = new Artifact(env.getModuleId());
059: }
060: if (env.isSetDependencies()) {
061: DependenciesType deps = env.getDependencies();
062: dependencies = new Artifact[deps.getDependencyArray().length];
063: for (int i = 0; i < dependencies.length; i++) {
064: dependencies[i] = new Artifact(deps
065: .getDependencyArray(i));
066: }
067: }
068: }
069:
070: // ----------------------- JavaBean Properties for environmentType ----------------------
071:
072: public Artifact getConfigId() {
073: return configId;
074: }
075:
076: public void setConfigId(Artifact configId) {
077: Artifact old = this .configId;
078: this .configId = configId;
079: if ((old == null && configId == null)
080: || (old != null && old == configId)) {
081: return;
082: }
083: if (old != null) {
084: getEnvironmentType().unsetModuleId();
085: }
086: if (configId != null) {
087: configId.configure(getEnvironmentType().addNewModuleId());
088: }
089: pcs.firePropertyChange("moduleId", old, configId);
090: }
091:
092: public Artifact[] getDependencies() {
093: return dependencies;
094: }
095:
096: public void setDependencies(Artifact[] dependencies) {
097: Artifact[] old = this .dependencies;
098: Set before = new HashSet();
099: for (int i = 0; i < old.length; i++) {
100: before.add(old[i]);
101: }
102: this .dependencies = dependencies;
103: // Handle current or new dependencies
104: for (int i = 0; i < dependencies.length; i++) {
105: Artifact dep = dependencies[i];
106: if (dep.getArtifactType() == null) {
107: if (!getEnvironmentType().isSetDependencies()) {
108: getEnvironmentType().addNewDependencies();
109: }
110: dep.configure(getEnvironmentType().getDependencies()
111: .addNewDependency());
112: } else {
113: before.remove(dep);
114: }
115: }
116: // Handle removed or new dependencies
117: for (Iterator it = before.iterator(); it.hasNext();) {
118: Artifact adapter = (Artifact) it.next();
119: ArtifactType all[] = getEnvironmentType().getDependencies()
120: .getDependencyArray();
121: for (int i = 0; i < all.length; i++) {
122: if (all[i] == adapter) {
123: getEnvironmentType().getDependencies()
124: .removeDependency(i);
125: break;
126: }
127: }
128: }
129: if (getEnvironmentType().isSetDependencies()
130: && getEnvironmentType().getDependencies()
131: .getDependencyArray().length == 0) {
132: getEnvironmentType().unsetDependencies();
133: }
134: pcs.firePropertyChange("dependencies", old, dependencies);
135: }
136:
137: public String[] getHiddenClasses() {
138: return getEnvironmentType().getHiddenClasses().getFilterArray();
139: }
140:
141: public void setHiddenClasses(String[] hidden) {
142: String[] old = getEnvironmentType().isSetHiddenClasses() ? getEnvironmentType()
143: .getHiddenClasses().getFilterArray()
144: : null;
145: if (!getEnvironmentType().isSetHiddenClasses()) {
146: getEnvironmentType().addNewHiddenClasses();
147: }
148: getEnvironmentType().getHiddenClasses().setFilterArray(hidden);
149: pcs.firePropertyChange("hiddenClasses", old, hidden);
150: }
151:
152: public String[] getNonOverridableClasses() {
153: return getEnvironmentType().getNonOverridableClasses()
154: .getFilterArray();
155: }
156:
157: public void setNonOverridableClasses(String[] fixed) {
158: String[] old = getEnvironmentType()
159: .isSetNonOverridableClasses() ? getEnvironmentType()
160: .getNonOverridableClasses().getFilterArray() : null;
161: if (!getEnvironmentType().isSetNonOverridableClasses()) {
162: getEnvironmentType().addNewNonOverridableClasses();
163: }
164: getEnvironmentType().getNonOverridableClasses().setFilterArray(
165: fixed);
166: pcs.firePropertyChange("nonOverridableClasses", old, fixed);
167: }
168:
169: public boolean isInverseClassLoading() {
170: return getEnvironmentType().isSetInverseClassloading();
171: }
172:
173: public void setInverseClassLoading(boolean inverse) {
174: boolean old = isInverseClassLoading();
175: if (!inverse) {
176: if (old) {
177: getEnvironmentType().unsetInverseClassloading();
178: }
179: } else {
180: if (!old) {
181: getEnvironmentType().addNewInverseClassloading();
182: }
183: }
184: pcs.firePropertyChange("inverseClassLoading", old, inverse);
185: }
186:
187: public boolean isSuppressDefaultEnvironment() {
188: return getEnvironmentType().isSetSuppressDefaultEnvironment();
189: }
190:
191: public void setSuppressDefaultEnvironment(boolean suppress) {
192: boolean old = isSuppressDefaultEnvironment();
193: if (!suppress) {
194: if (old) {
195: getEnvironmentType().unsetSuppressDefaultEnvironment();
196: }
197: } else {
198: if (!old) {
199: getEnvironmentType().addNewSuppressDefaultEnvironment();
200: }
201: }
202: pcs.firePropertyChange("suppressDefaultEnvironment", old,
203: suppress);
204: }
205:
206: // ----------------------- End of JavaBean Properties ----------------------
207:
208: protected SchemaTypeLoader getSchemaTypeLoader() {
209: return SCHEMA_TYPE_LOADER;
210: }
211: }
|