本文整理汇总了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);
}
}
}