1 17 package org.apache.geronimo.deployment.service.jsr88; 18 19 import java.util.Set ; 20 import java.util.HashSet ; 21 import java.util.Iterator ; 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 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 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 before = new HashSet (); 96 for (int i = 0; i < old.length; i++) { 97 before.add(old[i]); 98 } 99 this.dependencies = dependencies; 100 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 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 193 protected SchemaTypeLoader getSchemaTypeLoader() { 194 return SCHEMA_TYPE_LOADER; 195 } 196 } 197 | Popular Tags |