1 17 package org.apache.servicemix.jbi.framework; 18 19 import org.apache.servicemix.jbi.deployment.Component; 20 import org.apache.servicemix.jbi.deployment.InstallationDescriptorExtension; 21 import org.apache.servicemix.jbi.deployment.SharedLibraryList; 22 import org.w3c.dom.DocumentFragment ; 23 24 import javax.jbi.component.Bootstrap; 25 import javax.jbi.component.ComponentContext; 26 import javax.jbi.component.InstallationContext; 27 28 import java.io.File ; 29 import java.util.ArrayList ; 30 import java.util.Arrays ; 31 import java.util.Collections ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 35 41 public class InstallationContextImpl implements InstallationContext { 42 43 private Component descriptor; 44 private File installRoot; 45 private List classPathElements = Collections.EMPTY_LIST; 46 private ComponentContext context; 47 private boolean install = true; 48 49 public InstallationContextImpl(Component descriptor) { 50 this.descriptor = descriptor; 51 if (descriptor.getComponentClassPath() != null && 52 descriptor.getComponentClassPath().getPathElements() != null && 53 descriptor.getComponentClassPath().getPathElements().length > 0) { 54 String [] elems = descriptor.getComponentClassPath().getPathElements(); 55 for (int i = 0; i < elems.length; i++) { 56 if (File.separatorChar == '\\') { 57 elems[i] = elems[i].replace('/', '\\'); 58 } else { 59 elems[i] = elems[i].replace('\\', '/'); 60 } 61 } 62 setClassPathElements(Arrays.asList(elems)); 63 } 64 } 65 66 69 public Component getDescriptor() { 70 return descriptor; 71 } 72 73 76 public String [] getSharedLibraries() { 77 return getSharedLibraries(descriptor.getSharedLibraries()); 78 } 79 80 86 public String getComponentClassName() { 87 return descriptor.getComponentClassName(); 88 } 89 90 100 public List getClassPathElements() { 101 return classPathElements; 102 } 103 104 110 public String getComponentName() { 111 return descriptor.getIdentification().getName(); 112 } 113 114 126 public ComponentContext getContext() { 127 return context; 128 } 129 130 136 public String getInstallRoot() { 137 return installRoot != null ? installRoot.getAbsolutePath() : "."; 138 } 139 140 144 public File getInstallRootAsDir(){ 145 return installRoot; 146 } 147 148 158 public DocumentFragment getInstallationDescriptorExtension() { 159 InstallationDescriptorExtension desc = descriptor.getDescriptorExtension(); 160 return desc != null ? desc.getDescriptorExtension() : null; 161 } 162 163 174 public boolean isInstall() { 175 return install; 176 } 177 178 194 public void setClassPathElements(java.util.List classPathElements) { 195 if (classPathElements == null) { 196 throw new IllegalArgumentException ("classPathElements is null"); 197 } 198 if (classPathElements.isEmpty()) { 199 throw new IllegalArgumentException ("classPathElements is empty"); 200 } 201 for (Iterator iter = classPathElements.iterator(); iter.hasNext();) { 202 Object obj = iter.next(); 203 if (obj instanceof String == false) { 204 throw new IllegalArgumentException ("classPathElements must contain element of type String"); 205 } 206 String element = (String ) obj; 207 String sep = File.separator.equals("\\") ? "/" : "\\"; 208 int offset = element.indexOf(sep); 209 if ( offset > -1 ) { 210 throw new IllegalArgumentException ("classPathElements contains an invalid file separator '" + sep + "'"); 211 } 212 File f = new File ((String ) element); 213 if (f.isAbsolute()) { 214 throw new IllegalArgumentException ("classPathElements should not contain absolute paths"); 215 } 216 } 217 this.classPathElements = new ArrayList (classPathElements); 218 } 219 220 221 224 public void setContext(ComponentContext context) { 225 this.context = context; 226 } 227 230 public void setInstall(boolean install) { 231 this.install = install; 232 } 233 236 public void setInstallRoot(File installRoot) { 237 this.installRoot = installRoot; 238 } 239 242 public boolean isBinding() { 243 return descriptor.isBindingComponent(); 244 } 245 248 public boolean isEngine() { 249 return descriptor.isServiceEngine(); 250 } 251 254 public String getComponentDescription() { 255 return descriptor.getIdentification().getDescription(); 256 } 257 258 private static String [] getSharedLibraries(SharedLibraryList[] sharedLibraries) { 259 if (sharedLibraries == null || sharedLibraries.length == 0) { 260 return null; 261 } 262 String [] names = new String [sharedLibraries.length]; 263 for (int i = 0; i < names.length; i++) { 264 names[i] = sharedLibraries[i].getName(); 265 } 266 return names; 267 } 268 269 } 270 | Popular Tags |