1 26 27 package com.opensugar.cube.packageAdmin; 28 29 import com.opensugar.cube.BundleClassLoader; 30 31 import org.osgi.service.packageadmin.ExportedPackage; 32 import org.osgi.framework.Bundle; 33 34 import java.util.Vector ; 35 import java.net.URL ; 36 37 public class ExportedPackageImpl implements ExportedPackage, HasVersion { 38 39 private String name; 40 private String specificationVersion; 41 private Bundle exportingBundle; 42 private BundleClassLoader classLoader; 43 private Vector importingBundles; 44 private boolean removalPending; 45 private boolean open; 46 47 public ExportedPackageImpl( String name, String specificationVersion, Bundle exportingBundle, BundleClassLoader classLoader ) { 48 this.name = name; 49 this.specificationVersion = specificationVersion; 50 this.exportingBundle = exportingBundle; 51 this.classLoader = classLoader; 52 53 importingBundles = new Vector (); 54 importingBundles.addElement( exportingBundle ); 55 removalPending = false; 56 open = false; 57 } 58 59 public String getName() { 60 return name; 61 } 62 63 public String getSpecificationVersion() { 64 return specificationVersion; 65 } 66 67 public Bundle getExportingBundle() { 68 return exportingBundle; 69 } 70 71 public Bundle[] getImportingBundles() { 72 Vector clone = (Vector )importingBundles.clone(); 73 Bundle[] ret = new Bundle[ clone.size() ]; 74 clone.copyInto( ret ); 75 return ret; 76 } 77 78 public boolean isRemovalPending() { 79 return removalPending; 80 } 81 82 protected void addImportingBundle( Bundle bundle ) { 83 if ( importingBundles.indexOf( bundle ) == -1 ) { 84 importingBundles.addElement( bundle ); 85 } 86 } 87 88 protected void removeImportingBundle( Bundle bundle ) { 89 114 importingBundles.removeElement( bundle ); 115 } 116 117 protected boolean isImportingBundle( Bundle bundle ) { 118 return ( importingBundles.indexOf( bundle ) != -1 ); 119 } 120 121 protected void setRemovalPending() { 122 removalPending = true; 123 } 124 125 protected void setStale() { 126 exportingBundle = null; 127 classLoader = null; 128 importingBundles = null; 129 removalPending = true ; 130 } 131 132 protected boolean isOpen() { 133 return open; 134 } 135 136 protected Class loadClass( String className ) throws ClassNotFoundException { 137 try { 138 Class clazz = classLoader.loadOwnClass( className ); 139 open = true; 140 return clazz; 141 } 142 catch ( ClassNotFoundException e ) { 143 throw e; 144 } 145 } 146 147 protected URL getResource( String name ) { 148 URL url = classLoader.getOwnResource( name ); 149 if ( url != null ) { 150 open = true; 151 } 152 return url; 153 } 154 155 } 156 | Popular Tags |