java.net.ContentHandler#org.osgi.service.url.URLStreamHandlerService源码实例Demo

下面列出了java.net.ContentHandler#org.osgi.service.url.URLStreamHandlerService 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: activiti6-boot2   文件: Activator.java
public void start(BundleContext context) throws Exception {
  callbacks.add(new Service(context, URLStreamHandlerService.class.getName(), new BpmnURLHandler(), props("url.handler.protocol", "bpmn")));
  callbacks.add(new Service(context, URLStreamHandlerService.class.getName(), new BarURLHandler(), props("url.handler.protocol", "bar")));
  try {
    callbacks.add(new Service(context, new String[] { ArtifactUrlTransformer.class.getName(), ArtifactListener.class.getName() }, new BpmnDeploymentListener(), null));
    callbacks.add(new Service(context, new String[] { ArtifactUrlTransformer.class.getName(), ArtifactListener.class.getName() }, new BarDeploymentListener(), null));
  } catch (NoClassDefFoundError e) {
    LOGGER.warn("FileInstall package is not available, disabling fileinstall support");
    LOGGER.debug("FileInstall package is not available, disabling fileinstall support", e);
  }
  callbacks.add(new Tracker(new Extender(context)));
}
 
源代码2 项目: flowable-engine   文件: Activator.java
@Override
public void start(BundleContext context) throws Exception {
    callbacks.add(new Service(context, URLStreamHandlerService.class.getName(), new BpmnURLHandler(), props("url.handler.protocol", "bpmn")));
    callbacks.add(new Service(context, URLStreamHandlerService.class.getName(), new BarURLHandler(), props("url.handler.protocol", "bar")));
    try {
        callbacks.add(new Service(context, new String[]{ArtifactUrlTransformer.class.getName(), ArtifactListener.class.getName()}, new BpmnDeploymentListener(), null));
        callbacks.add(new Service(context, new String[]{ArtifactUrlTransformer.class.getName(), ArtifactListener.class.getName()}, new BarDeploymentListener(), null));
    } catch (NoClassDefFoundError e) {
        LOGGER.warn("FileInstall package is not available, disabling fileinstall support");
        LOGGER.debug("FileInstall package is not available, disabling fileinstall support", e);
    }
    callbacks.add(new Tracker(new Extender(context)));
}
 
/**
 *
 */
private URLStreamHandler getServiceHandler(final String protocol)
{
  try {
    final String filter =
      "(" +
      URLConstants.URL_HANDLER_PROTOCOL +
      "=" + protocol +
      ")";
    @SuppressWarnings("unchecked")
    final Vector<FrameworkContext> sfws = (Vector<FrameworkContext>)framework.clone();
    for (final FrameworkContext sfw : sfws) {
      @SuppressWarnings("unchecked")
      final ServiceReference<URLStreamHandlerService>[] srl
        = (ServiceReference<URLStreamHandlerService>[]) sfw.services
          .get(URLStreamHandlerService.class.getName(), filter, sfw.systemBundle, false);

      if (srl != null && srl.length > 0) {
        synchronized (wrapMap) {
          URLStreamHandlerWrapper wrapper = wrapMap.get(protocol);
          if (wrapper == null) {
            wrapper = new URLStreamHandlerWrapper(sfw, protocol);
            wrapMap.put(protocol, wrapper);
          } else {
            wrapper.addFramework(sfw);
          }
          return wrapper;
        }
      }
    }
  } catch (final InvalidSyntaxException e) {
    throw new RuntimeException("Failed to get service: " + e);
  }

  // no handler found
  return null;
}
 
/**
 *
 */
private URLStreamHandlerService getService() {
  FrameworkContext fw;
  if (framework.size() == 1) {
    fw = framework.get(0);
  } else {
    // Get current FrameworkContext
    throw new RuntimeException("NYI - walk stack to get framework");
  }
  synchronized (serviceListener) {
    if (best == null) {
      try {
        @SuppressWarnings("unchecked")
        final ServiceReference<URLStreamHandlerService>[] refs =
          (ServiceReference<URLStreamHandlerService>[])
            fw.systemBundle.bundleContext.getServiceReferences(URLStreamHandlerService.class.getName(), filter);
        if (refs != null) {
          // KF gives us highest ranked first.
          best = refs[0];
        }
      } catch (final InvalidSyntaxException _no) { }
    }
    if (best == null) {
      throw new IllegalStateException("null: Lost service for protocol="+ protocol);
    }
    if (bestService == null) {
      bestService = fw.systemBundle.bundleContext.getService(best);
    }
    if (bestService == null) {
      throw new IllegalStateException("null: Lost service for protocol=" + protocol);
    }
    currentFw = fw;
    return bestService;
  }
}
 
@Override
  public String toString() {
    final StringBuffer sb = new StringBuffer();

    sb.append("URLStreamHandlerWrapper[");

    final ServiceReference<URLStreamHandlerService> ref = best;
    sb.append("protocol=" + protocol);
    //    sb.append(", size=" + tracker.size());
    if(ref != null) {
      sb.append(", id=" + ref.getProperty(Constants.SERVICE_ID));
      sb.append(", rank=" + ref.getProperty(Constants.SERVICE_RANKING));

//       ServiceReference[] srl = tracker.getServiceReferences();
//       for(int i = 0; srl != null && i < srl.length; i++) {
// 	sb.append(", {");
// 	sb.append("id=" + srl[i].getProperty(Constants.SERVICE_ID));
// 	sb.append(", rank=" + srl[i].getProperty(Constants.SERVICE_RANKING));

// 	String[] sa = (String[])srl[i].getProperty(URLConstants.URL_HANDLER_PROTOCOL);
// 	sb.append(", proto=");

// 	for(int j = 0; j < sa.length; j++) {
// 	  sb.append(sa[j]);
// 	  if(j < sa.length - 1) {
// 	    sb.append(", ");
// 	  }
// 	}
// 	sb.append("}");
//       }

    } else {
      sb.append(" no service tracked");
    }

    sb.append("]");

    return sb.toString();
  }
 
源代码6 项目: camunda-bpm-platform-osgi   文件: Activator.java
@Override
public void init(BundleContext context, DependencyManager manager) throws Exception {
  manager.add(createComponent().setInterface(new String[] { ArtifactUrlTransformer.class.getName(), ArtifactListener.class.getName() }, null)
      .setImplementation(BpmnDeploymentListener.class));
  manager.add(createComponent().setInterface(URLStreamHandlerService.class.getName(),
      new Hashtable<String, String>(Collections.singletonMap("url.handler.protocol", "bpmn"))).setImplementation(BpmnURLHandler.class));
}