本文整理匯總了Java中org.osgi.framework.BundleException類的典型用法代碼示例。如果您正苦於以下問題:Java BundleException類的具體用法?Java BundleException怎麽用?Java BundleException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BundleException類屬於org.osgi.framework包,在下文中一共展示了BundleException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: performAction
import org.osgi.framework.BundleException; //導入依賴的package包/類
private void performAction(DependencyAction action, Map<MavenArtifact, ArtifactLoader> artifact2loader) throws BundleException {
LOGGER.info("Perform " + action);
EventAdmin eventAdmin = this.eventAdmin;
if (eventAdmin != null)
eventAdmin.postEvent(new DependencyActionEvent(action));
if (action instanceof InstallAction) {
performInstall(action.artifact, artifact2loader.get(action.artifact));
} else if (action instanceof UpdateAction) {
MavenArtifact target = ((UpdateAction) action).targetArtifact;
performUpdate(action.artifact, target, artifact2loader.get(target));
} else if (action instanceof UninstallAction) {
performUninstall(action.artifact);
} else {
throw new IllegalArgumentException("Unknown action: " + action);
}
}
示例2: init
import org.osgi.framework.BundleException; //導入依賴的package包/類
@Override
public void init() throws BundleException {
super.init();
if (Boolean.getBoolean("osgi.framework.useSystemProperties")) {
Properties prev = FrameworkProperties.getProperties();
try {
Field f = FrameworkProperties.class.getDeclaredField("properties"); // NOI18N
f.setAccessible(true);
f.set(null, null);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
Properties newP = FrameworkProperties.getProperties();
for (Map.Entry en : prev.entrySet()) {
if (en.getKey() instanceof String && en.getValue() instanceof String) {
newP.setProperty((String)en.getKey(), (String)en.getValue());
}
}
assert System.getProperties() == FrameworkProperties.getProperties();
}
}
示例3: installBundle
import org.osgi.framework.BundleException; //導入依賴的package包/類
@Override
public Bundle installBundle(String url, InputStream in) throws BundleException {
final String pref = "reference:";
if (url.startsWith(pref)) {
// workaround for problems with space in path
url = url.replaceAll("%20", " ");
String filePart = url.substring(pref.length());
if (installArea != null && filePart.startsWith(installArea)) {
String relPath = filePart.substring(installArea.length());
if (relPath.startsWith("/")) { // NOI18N
relPath = relPath.substring(1);
}
url = pref + "file:" + relPath;
NetbinoxFactory.LOG.log(Level.FINE, "Converted to relative {0}", url);
} else {
NetbinoxFactory.LOG.log(Level.FINE, "Kept absolute {0}", url);
}
}
return delegate.installBundle(url, in);
}
示例4: installBundle
import org.osgi.framework.BundleException; //導入依賴的package包/類
/**
* Installs the specified jar bundle and adds the Bundle instance to the local bundle vector {@link #getBundleVector()}.
* @param bundleJarFilePath the bundle jar file path
*/
public void installBundle(String bundleJarFilePath) {
Bundle bundle = null;
try {
BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
bundle = bundleContext.installBundle(bundleJarFilePath);
if (this.debug) System.out.println("=> + " + bundle.getSymbolicName() + " installed.");
} catch (BundleException bEx) {
bEx.printStackTrace();
}
// --- Remind this bundle ---------------
if (bundle!=null) this.getBundleVector().addElement(bundle);
}
示例5: stopAndUninstallBundles
import org.osgi.framework.BundleException; //導入依賴的package包/類
/**
* Stops and un-installs the current bundle.
*/
public void stopAndUninstallBundles() {
// --- Get a copy of loaded bundles -----
Vector<Bundle> bundlesToRemove = new Vector<>(this.getBundleVector());
for (Bundle bundle: bundlesToRemove) {
try {
// --- Remove, if active --------
if (bundle.getState()==Bundle.ACTIVE) {
bundle.stop();
bundle.uninstall();
}
// --- Remove from vector -------
this.getBundleVector().remove(bundle);
if (this.debug) System.out.println("=> - " + bundle.getSymbolicName() + " stoped & uninstalled");
} catch (BundleException bEx) {
bEx.printStackTrace();
}
}
}
示例6: test
import org.osgi.framework.BundleException; //導入依賴的package包/類
/**
* Test currently does not work as data source config is not deployed for unknown reason
*/
@Ignore
@Test
public void test() throws BundleException {
resolveBundles();
Assert.assertEquals(0, taskService.getTasks().size());
Task task = new Task();
task.setId(1);
task.setDescription("My task");
taskService.addTask(task);
Collection<Task> tasks = taskService.getTasks();
Assert.assertEquals(1, tasks.size());
Task task1 = tasks.iterator().next();
Assert.assertEquals(1, task1.getId().intValue());
Assert.assertEquals("My task", task1.getDescription());
}
示例7: setStartLevel
import org.osgi.framework.BundleException; //導入依賴的package包/類
private void setStartLevel ( final String symbolicName, final int startLevel ) throws BundleException
{
final Bundle bundle = findBundle ( symbolicName );
if ( bundle == null )
{
return;
}
final BundleStartLevel bundleStartLevel = bundle.adapt ( BundleStartLevel.class );
if ( bundleStartLevel == null )
{
return;
}
bundleStartLevel.setStartLevel ( startLevel < 0 ? this.defaultStartLevel : startLevel );
bundle.start ();
}
示例8: uninstallBundle
import org.osgi.framework.BundleException; //導入依賴的package包/類
@Deprecated
public void uninstallBundle(final String location) throws BundleException {
Bundle bundle = Framework.getBundle(location);
if (bundle != null) {
BundleImpl b = (BundleImpl)bundle;
File delDir = null;
try {
File soFile = b.getArchive().getArchiveFile();
if(soFile.canWrite()){
soFile.delete();
}
delDir = b.getArchive().getCurrentRevision().getRevisionDir();
bundle.uninstall();
if(delDir !=null ){
Framework.deleteDirectory(delDir);
}
} catch (Exception e) {
}
} else {
throw new BundleException("Could not uninstall bundle " + location + ", because could not find it");
}
}
示例9: BundleImpl
import org.osgi.framework.BundleException; //導入依賴的package包/類
/**
* create a new bundle object from InputStream. This is used when a new bundle is installed.
*
* @param location the bundle location.
* @param stream the input stream.
* @throws BundleException if something goes wrong.
* @throws IOException
*/
BundleImpl(final File bundleDir, final String location, final InputStream stream,
final File file, String unique_tag, boolean installForCurrentVersion, long dexPatchVersion) throws BundleException, IOException{
this.location = location;
this.bundleDir = bundleDir;
if(installForCurrentVersion) {
Framework.notifyBundleListeners(BundleEvent.BEFORE_INSTALL, this);
}
if (stream != null) {
this.archive = new BundleArchive(location,bundleDir, stream,unique_tag, dexPatchVersion);
} else if (file != null) {
this.archive = new BundleArchive(location,bundleDir, file,unique_tag, dexPatchVersion);
}
this.state = INSTALLED;
if (installForCurrentVersion) {
resolveBundle();
Framework.bundles.put(location, this);
// notify the listeners
Framework.notifyBundleListeners(BundleEvent.INSTALLED, this);
}
}
示例10: uninstall
import org.osgi.framework.BundleException; //導入依賴的package包/類
/**
* uninstall the bundle.
*
* @throws BundleException if bundle is already uninstalled
* @see org.osgi.framework.Bundle#uninstall()
* @category Bundle
*/
public synchronized void uninstall() throws BundleException {
if (state == UNINSTALLED) {
throw new IllegalStateException("Bundle " + toString() + " is already uninstalled.");
}
if (state == ACTIVE) {
try {
stop();
} catch (Throwable t) {
Framework.notifyFrameworkListeners(FrameworkEvent.ERROR, this, t);
}
}
state = UNINSTALLED;
classloader.cleanup(true);
classloader = null;
Framework.bundles.remove(getLocation());
Framework.notifyBundleListeners(BundleEvent.UNINSTALLED, this);
}
示例11: startDependencyAsynch
import org.osgi.framework.BundleException; //導入依賴的package包/類
private void startDependencyAsynch(final Bundle bundle) {
System.out.println("starting dependency test bundle");
Runnable runnable = new Runnable() {
public void run() {
try {
bundle.start();
System.out.println("started dependency test bundle");
}
catch (BundleException ex) {
System.err.println("can't start bundle " + ex);
}
}
};
Thread thread = new Thread(runnable);
thread.setDaemon(false);
thread.setName("dependency test bundle");
thread.start();
}
示例12: startBundle
import org.osgi.framework.BundleException; //導入依賴的package包/類
/**
* Starts a bundle and prints a nice logging message in case of failure.
*
* @param bundle to start
* @throws BundleException
*/
private void startBundle(Bundle bundle) throws BundleException {
boolean debug = logger.isDebugEnabled();
String info = "[" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "|" + bundle.getLocation() + "]";
if (!OsgiBundleUtils.isFragment(bundle)) {
if (debug)
logger.debug("Starting " + info);
try {
bundle.start();
} catch (BundleException ex) {
logger.error("cannot start bundle " + info, ex);
throw ex;
}
} else {
// if (!OsgiBundleUtils.isBundleResolved(bundle)) {
// logger.error("fragment not resolved: " + info);
// throw new BundleException("Unable to resolve fragment: " + info);
// } else if (debug)
logger.debug(info + " is a fragment; start not invoked");
}
}
示例13: checkExecutionEnviroment
import org.osgi.framework.BundleException; //導入依賴的package包/類
@Deprecated
private void checkExecutionEnviroment(String[] requireEnv, String[] execEnv)
throws BundleException {
if (requireEnv.length != 0) {
Set hashSet = new HashSet(Arrays.asList(execEnv));
int i = 0;
while (i < requireEnv.length) {
if (!hashSet.contains(requireEnv[i])) {
i++;
} else {
return;
}
}
throw new BundleException("Platform does not provide EEs " + Arrays.asList(requireEnv));
}
}
示例14: BundleImpl
import org.osgi.framework.BundleException; //導入依賴的package包/類
BundleImpl(File file) throws Exception {
long currentTimeMillis = System.currentTimeMillis();
DataInputStream dataInputStream = new DataInputStream(new FileInputStream(new File(file, "meta")));
this.location = dataInputStream.readUTF();
this.currentStartlevel = dataInputStream.readInt();
this.persistently = dataInputStream.readBoolean();
dataInputStream.close();
this.bundleDir = file;
this.state = BundleEvent.STARTED;
try {
this.archive = new BundleArchive(this.location, file);
resolveBundle(false);
Framework.bundles.put(this.location, this);
Framework.notifyBundleListeners(BundleEvent.INSTALLED, this);
if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) {
log.info("Framework: Bundle " + toString() + " loaded. " + (System.currentTimeMillis() - currentTimeMillis) + " ms");
}
} catch (Exception e) {
throw new BundleException("Could not load bundle " + this.location, e.getCause());
}
}
示例15: startBundle
import org.osgi.framework.BundleException; //導入依賴的package包/類
public synchronized void startBundle() throws BundleException {
if (this.state == BundleEvent.INSTALLED) {
throw new IllegalStateException("Cannot start uninstalled bundle "
+ toString());
} else if (this.state != BundleEvent.RESOLVED) {
if (this.state == BundleEvent.STARTED) {
resolveBundle(true);
}
this.state = BundleEvent.UPDATED;
try {
isValid = true;
this.state = BundleEvent.RESOLVED;
Framework.notifyBundleListeners(BundleEvent.STARTED, this);
if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) {
log.info("Framework: Bundle " + toString() + " started.");
}
} catch (Throwable th) {
Framework.clearBundleTrace(this);
this.state = BundleEvent.STOPPED;
String msg = "Error starting bundle " + toString();
log.error(msg,th);
}
}
}