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 package org.apache.geronimo.deployment.service.jsr88; 018 019 import java.util.Set; 020 import java.util.HashSet; 021 import java.util.Iterator; 022 import org.apache.geronimo.deployment.plugin.XmlBeanSupport; 023 import org.apache.geronimo.deployment.xbeans.DependenciesType; 024 import org.apache.geronimo.deployment.xbeans.EnvironmentType; 025 import org.apache.geronimo.deployment.xbeans.ArtifactType; 026 import org.apache.xmlbeans.SchemaTypeLoader; 027 import org.apache.xmlbeans.XmlBeans; 028 029 /** 030 * Represents an environmentType (e.g. an environment element) in a Geronimo 031 * deployment plan. 032 * 033 * @version $Rev: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $ 034 */ 035 public class EnvironmentData extends XmlBeanSupport { 036 static final SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.typeLoaderForClassLoader(EnvironmentType.class.getClassLoader()); 037 038 private Artifact configId; 039 private Artifact[] dependencies = new Artifact[0]; 040 041 public EnvironmentData() { 042 super(null); 043 } 044 045 public EnvironmentData(EnvironmentType dependency) { 046 super(null); 047 configure(dependency); 048 } 049 050 protected EnvironmentType getEnvironmentType() { 051 return (EnvironmentType) getXmlObject(); 052 } 053 054 public void configure(EnvironmentType env) { 055 setXmlObject(env); 056 if(env.isSetModuleId()) { 057 configId = new Artifact(env.getModuleId()); 058 } 059 if(env.isSetDependencies()) { 060 DependenciesType deps = env.getDependencies(); 061 dependencies = new Artifact[deps.getDependencyArray().length]; 062 for (int i = 0; i < dependencies.length; i++) { 063 dependencies[i] = new Artifact(deps.getDependencyArray(i)); 064 } 065 } 066 } 067 068 // ----------------------- JavaBean Properties for environmentType ---------------------- 069 070 public Artifact getConfigId() { 071 return configId; 072 } 073 074 public void setConfigId(Artifact configId) { 075 Artifact old = this.configId; 076 this.configId = configId; 077 if((old == null && configId == null) || (old != null&& old == configId)) { 078 return; 079 } 080 if(old != null) { 081 getEnvironmentType().unsetModuleId(); 082 } 083 if(configId != null) { 084 configId.configure(getEnvironmentType().addNewModuleId()); 085 } 086 pcs.firePropertyChange("moduleId", old, configId); 087 } 088 089 public Artifact[] getDependencies() { 090 return dependencies; 091 } 092 093 public void setDependencies(Artifact[] dependencies) { 094 Artifact[] old = this.dependencies; 095 Set before = new HashSet(); 096 for (int i = 0; i < old.length; i++) { 097 before.add(old[i]); 098 } 099 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 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[] getHiddenClasses() { 130 return getEnvironmentType().getHiddenClasses().getFilterArray(); 131 } 132 133 public void setHiddenClasses(String[] hidden) { 134 String[] 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[] getNonOverridableClasses() { 143 return getEnvironmentType().getNonOverridableClasses().getFilterArray(); 144 } 145 146 public void setNonOverridableClasses(String[] fixed) { 147 String[] 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 }