Java Code Examples for org.osgi.framework.InvalidSyntaxException

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project jclouds-karaf, under directory /itests/src/test/java/org/jclouds/karaf/itests/.

Source file: JcloudsKarafTestSupport.java

  20 
vote

protected <T>T getOsgiService(Class<T> type,String filter,long timeout){
  ServiceTracker tracker=null;
  try {
    String flt;
    if (filter != null) {
      if (filter.startsWith("(")) {
        flt="(&(" + Constants.OBJECTCLASS + "="+ type.getName()+ ")"+ filter+ ")";
      }
 else {
        flt="(&(" + Constants.OBJECTCLASS + "="+ type.getName()+ ")("+ filter+ "))";
      }
    }
 else {
      flt="(" + Constants.OBJECTCLASS + "="+ type.getName()+ ")";
    }
    Filter osgiFilter=FrameworkUtil.createFilter(flt);
    tracker=new ServiceTracker(bundleContext,osgiFilter,null);
    tracker.open(true);
    Object svc=type.cast(tracker.waitForService(timeout));
    if (svc == null) {
      Dictionary dic=bundleContext.getBundle().getHeaders();
      System.err.println("Test bundle headers: " + explode(dic));
      for (      ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null,null))) {
        System.err.println("ServiceReference: " + ref);
      }
      for (      ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null,flt))) {
        System.err.println("Filtered ServiceReference: " + ref);
      }
      throw new RuntimeException("Gave up waiting for service " + flt);
    }
    return type.cast(svc);
  }
 catch (  InvalidSyntaxException e) {
    throw new IllegalArgumentException("Invalid filter",e);
  }
catch (  InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 

Example 2

From project agile, under directory /agile-core/src/main/java/org/headsupdev/agile/core/.

Source file: ServTracker.java

  19 
vote

private static Filter createFilter(final BundleContext bundleContext){
  final String filter="(objectClass=org.headsupdev.agile.api.service.ScmService)";
  try {
    return bundleContext.createFilter(filter);
  }
 catch (  InvalidSyntaxException e) {
    throw new IllegalArgumentException("Unexpected InvalidSyntaxException: " + e.getMessage());
  }
}
 

Example 3

From project Android_1, under directory /org.eclipse.ecf.provider.zookeeper/src/org/eclipse/ecf/provider/zookeeper/core/internal/.

Source file: Advertiser.java

  19 
vote

public void autoPublish(){
  Filter filter=null;
  try {
    filter=DiscoveryActivator.getContext().createFilter("(&(!(service.imported=*))" + "(" + IDiscoveryConfig.ZOODISCOVERY_ADVERTISE_AUTO + "=true))");
  }
 catch (  InvalidSyntaxException e) {
    e.printStackTrace();
  }
  this.publicationTracker=new ServiceTracker(DiscoveryActivator.getContext(),filter,null){
    public Object addingService(    ServiceReference reference){
      getWather().publish(reference);
      return super.addingService(reference);
    }
    public void modifiedService(    ServiceReference reference,    Object service){
      getWather().update(reference);
      super.modifiedService(reference,service);
    }
    public void removedService(    ServiceReference reference,    Object service){
      getWather().unpublish(reference.getProperty(Constants.SERVICE_ID).toString());
      super.removedService(reference,service);
    }
  }
;
  this.publicationTracker.open(true);
}
 

Example 4

From project ant4eclipse, under directory /org.ant4eclipse.lib.pde/src/org/ant4eclipse/lib/pde/internal/tools/.

Source file: TargetPlatformImpl.java

  19 
vote

public boolean matchesPlatformFilter(String id){
  try {
    BundleDescription bundleDescription=getBundleDescription(id);
    if (bundleDescription == null) {
      return true;
    }
    String platformFilter=bundleDescription.getPlatformFilter();
    if (platformFilter == null) {
      return true;
    }
    String arch=getTargetPlatformConfiguration().getArchitecture();
    String os=getTargetPlatformConfiguration().getOperatingSystem();
    String ws=getTargetPlatformConfiguration().getWindowingSystem();
    Properties dictionary=new Properties();
    dictionary.put("osgi.ws",ws);
    dictionary.put("osgi.os",os);
    dictionary.put("osgi.arch",arch);
    Filter filter=FrameworkUtil.createFilter(platformFilter);
    return filter.match(dictionary);
  }
 catch (  InvalidSyntaxException e) {
    e.printStackTrace();
    return false;
  }
}
 

Example 5

From project arkadiko, under directory /src/com/liferay/arkadiko/.

Source file: AKBeanPostProcessor.java

  19 
vote

/** 
 * Creates the filter.
 * @param bundleContext the bundle context
 * @param beanId the bean id
 * @param interfaces the interfaces
 * @return the filter
 * @throws AKBeansException the aK beans exception
 */
protected Filter createFilter(BundleContext bundleContext,String beanId,List<Class<?>> interfaces) throws AKBeansException {
  StringBuffer sb=new StringBuffer(interfaces.size() * 5 + 10);
  sb.append(AKConstants.OPEN_PAREN_AND_AMP);
  if (!isStrictMatching() && (interfaces.size() > 1)) {
    sb.append(AKConstants.OPEN_PAREN_AND_PIPE);
  }
  for (  Class<?> clazz : interfaces) {
    sb.append(AKConstants.OPEN_PAREN);
    sb.append(Constants.OBJECTCLASS);
    sb.append(AKConstants.EQUAL);
    sb.append(clazz.getName());
    sb.append(AKConstants.CLOSE_PAREN);
  }
  if (!isStrictMatching() && (interfaces.size() > 1)) {
    sb.append(AKConstants.CLOSE_PAREN);
  }
  sb.append(AKConstants.OPEN_PAREN);
  sb.append(AKConstants.BEAN_ID);
  sb.append(AKConstants.EQUAL);
  sb.append(beanId);
  sb.append(AKConstants.CP_OP_EX_OP);
  sb.append(AKConstants.ORIGINAL_BEAN);
  sb.append(AKConstants.EQ_STAR_CP_CP_CP);
  try {
    return bundleContext.createFilter(sb.toString());
  }
 catch (  InvalidSyntaxException e) {
    throw new AKBeansException(e.getMessage(),e);
  }
}
 

Example 6

From project BHT-FPA, under directory /mailer-common/de.bht.fpa.mail.common/src/de/bht/fpa/mail/s000000/common/osgi/.

Source file: OSGiServiceHelper.java

  19 
vote

/** 
 * This method returns a Collection of service instances, or an empty Collection if no service is currently registered.
 * @param bundleContext the  {@link BundleContext} of your plugin. You can obtain aninstance of the  {@link BundleContext} through your Activator.
 * @param clazz The  {@link Class} of the service. Typically an Java Interface
 * @param filter The filter expression or null for all services. See {@link BundleContext#getServiceReferences(Class,String)}.
 * @return Collection of service instances of the given {@link Class} type, oran empty Collection.
 */
@SuppressWarnings({"unchecked"}) public static <T>Collection<T> getServices(BundleContext bundleContext,Class<T> clazz,String filter){
  Collection<ServiceReference<T>> serviceReferences;
  try {
    serviceReferences=bundleContext.getServiceReferences(clazz,null);
  }
 catch (  InvalidSyntaxException e) {
    throw new RuntimeException(e);
  }
  if (serviceReferences.isEmpty()) {
    return Collections.EMPTY_LIST;
  }
  Collection<T> result=new ArrayList<T>(serviceReferences.size());
  for (  ServiceReference<T> sr : serviceReferences) {
    result.add(bundleContext.getService(sr));
  }
  return result;
}
 

Example 7

From project blueprint-namespaces, under directory /blueprint/blueprint-annotation-itest/src/test/java/org/apache/aries/blueprint/itests/.

Source file: AbstractIntegrationTest.java

  19 
vote

protected <T>T getOsgiService(BundleContext bc,Class<T> type,String filter,long timeout){
  ServiceTracker tracker=null;
  try {
    String flt;
    if (filter != null) {
      if (filter.startsWith("(")) {
        flt="(&(" + Constants.OBJECTCLASS + "="+ type.getName()+ ")"+ filter+ ")";
      }
 else {
        flt="(&(" + Constants.OBJECTCLASS + "="+ type.getName()+ ")("+ filter+ "))";
      }
    }
 else {
      flt="(" + Constants.OBJECTCLASS + "="+ type.getName()+ ")";
    }
    Filter osgiFilter=FrameworkUtil.createFilter(flt);
    tracker=new ServiceTracker(bc == null ? bundleContext : bc,osgiFilter,null);
    tracker.open();
    srs.add(tracker);
    Object svc=type.cast(tracker.waitForService(timeout));
    if (svc == null) {
      throw new RuntimeException("Gave up waiting for service " + flt);
    }
    return type.cast(svc);
  }
 catch (  InvalidSyntaxException e) {
    throw new IllegalArgumentException("Invalid filter",e);
  }
catch (  InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 

Example 8

From project camel-osgi, under directory /component/src/main/java/org/apache/camel/osgi/service/filter/.

Source file: AbstractCriterion.java

  19 
vote

public Filter filter(){
  String value=value();
  if (value == null || value.isEmpty()) {
    return null;
  }
  try {
    return FrameworkUtil.createFilter(value);
  }
 catch (  InvalidSyntaxException e) {
    throw new CriterionException(e);
  }
}
 

Example 9

From project cellar, under directory /config/src/main/java/net/cellar/config/.

Source file: LocalConfigurationListener.java

  19 
vote

/** 
 * Push configuration with pid to the table.
 * @param pid
 */
protected void push(String pid,Group group){
  String groupName=group.getName();
  Map<String,Properties> configurationTable=clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
  try {
    Configuration[] configurations=configurationAdmin.listConfigurations("(service.pid=" + pid + ")");
    for (    Configuration configuration : configurations) {
      Properties properties=dictionaryToProperties(preparePush(filterDictionary(configuration.getProperties())));
      configurationTable.put(configuration.getPid(),properties);
    }
  }
 catch (  IOException e) {
    logger.error("Failed to push configuration with pid:" + pid,e);
  }
catch (  InvalidSyntaxException e) {
    logger.error("Failed to retrieve configuration with pid:" + pid,e);
  }
}
 

Example 10

From project cilia-workbench, under directory /cilia-workbench-monitoring/src/fr/liglab/adele/cilia/workbench/monitoring/.

Source file: Activator.java

  19 
vote

/** 
 * Retrieve a service in the registry, thanks to a class.
 * @param clazz The class used to find the service reference
 * @return the service reference, null if not found
 */
@SuppressWarnings("rawtypes") private static ServiceReference retrieveAdminService(Class clazz){
  ServiceReference[] refs=null;
  ServiceReference refData;
  try {
    refs=context.getServiceReferences(clazz.getName(),null);
  }
 catch (  InvalidSyntaxException e) {
    throw new RuntimeException("Admin data service lookup unrecoverable error",e);
  }
  if (refs != null)   refData=refs[0];
 else {
    refData=null;
  }
  return refData;
}
 

Example 11

From project Cilia_1, under directory /components/ea-adapter/src/main/java/fr/liglab/adele/cilia/ea/.

Source file: EventAdminCollector.java

  19 
vote

private void register(){
  if (m_topics != null && m_topics.length() > 0) {
    m_eventHandler=this;
    Dictionary dico=new Hashtable();
    String[] topics=getListStrings(m_topics);
    dico.put(EventConstants.EVENT_TOPIC,topics);
    if (ldapfilter != null) {
      try {
        Filter filter=null;
        filter=m_bundleContext.createFilter(ldapfilter);
      }
 catch (      InvalidSyntaxException e) {
        log.error("Error when converting filter " + ldapfilter + " in ldap syntax");
        log.error(e.getStackTrace().toString());
        ldapfilter=null;
      }
    }
    if (ldapfilter != null) {
      dico.put(EventConstants.EVENT_FILTER,ldapfilter);
    }
    if (m_serviceRegistration != null) {
      m_serviceRegistration.unregister();
    }
    m_serviceRegistration=m_bundleContext.registerService(EventHandler.class.getName(),m_eventHandler,dico);
  }
 else {
    log.error("Unable to register without topic");
  }
}
 

Example 12

From project CIShell, under directory /clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/.

Source file: AbstractDataManagerView.java

  19 
vote

public void handleEvent(Event event){
  IMenuManager topLevelMenu=CIShellApplication.getMenuManager();
  IMenuManager fileMenu=topLevelMenu.findMenuUsingPath("File");
  BundleContext bundleContext=Activator.getBundleContext();
  try {
    ServiceReference[] serviceReference=bundleContext.getAllServiceReferences(AlgorithmFactory.class.getName(),"(service.pid=org.cishell.reference.gui.persistence.viewwith.FileViewWith)");
    if ((serviceReference != null) && (serviceReference.length > 0)) {
      ActionContributionItem action=(ActionContributionItem)fileMenu.find(getItemID(serviceReference[0]));
      action.getAction().run();
    }
  }
 catch (  InvalidSyntaxException e) {
    e.printStackTrace();
  }
}
 

Example 13

From project cxf-dosgi, under directory /discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/.

Source file: InterfaceDataMonitorListenerImpl.java

  19 
vote

public synchronized void change(){
  Map<String,Map<String,Object>> newNodes=new HashMap<String,Map<String,Object>>();
  Map<String,Map<String,Object>> prevNodes=nodes;
  LOG.info("Zookeeper callback on node: " + znode);
  processChildren(znode,newNodes,prevNodes);
  LOG.fine("processChildren done nodes that are missing now and need to be removed: " + prevNodes.values());
  for (  Map<String,Object> props : prevNodes.values()) {
    EndpointDescription epd=new EndpointDescription(props);
    for (    ServiceReference sref : discoveredServiceTracker.relatedServiceListeners) {
      if (bctx.getService(sref) instanceof EndpointListener) {
        EndpointListener epl=(EndpointListener)bctx.getService(sref);
        String[] scopes=Util.getScopes(sref);
        for (        final String currentScope : scopes) {
          LOG.fine("matching " + epd + " against "+ currentScope);
          Filter f=null;
          try {
            f=FrameworkUtil.createFilter(currentScope);
            Dictionary d=new Properties();
            Set<Map.Entry<String,Object>> entries=props.entrySet();
            for (            Map.Entry<String,Object> entry : entries) {
              d.put(entry.getKey(),entry.getValue());
            }
            if (f.match(d)) {
              LOG.fine("MATCHED " + epd + "against "+ currentScope);
              LOG.info("calling EndpointListener endpointRemoved: " + epl + "from bundle "+ sref.getBundle().getSymbolicName()+ " for endpoint: "+ epd);
              epl.endpointRemoved(epd,currentScope);
              break;
            }
          }
 catch (          InvalidSyntaxException e) {
            LOG.log(Level.SEVERE,"Currentscope [" + currentScope + "] resulted in"+ " a bad filter!",e);
          }
        }
      }
    }
  }
  nodes=newNodes;
}
 

Example 14

From project DirectMemory, under directory /itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/.

Source file: DirectMemoryOsgiTestSupport.java

  19 
vote

protected <T>T getOsgiService(Class<T> type,String filter,long timeout){
  ServiceTracker tracker=null;
  try {
    String flt;
    if (filter != null) {
      if (filter.startsWith("(")) {
        flt="(&(" + Constants.OBJECTCLASS + "="+ type.getName()+ ")"+ filter+ ")";
      }
 else {
        flt="(&(" + Constants.OBJECTCLASS + "="+ type.getName()+ ")("+ filter+ "))";
      }
    }
 else {
      flt="(" + Constants.OBJECTCLASS + "="+ type.getName()+ ")";
    }
    Filter osgiFilter=FrameworkUtil.createFilter(flt);
    tracker=new ServiceTracker(bundleContext,osgiFilter,null);
    tracker.open(true);
    Object svc=type.cast(tracker.waitForService(timeout));
    if (svc == null) {
      Dictionary dic=bundleContext.getBundle().getHeaders();
      System.err.println("Test bundle headers: " + explode(dic));
      for (      ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null,null))) {
        System.err.println("ServiceReference: " + ref);
      }
      for (      ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null,flt))) {
        System.err.println("Filtered ServiceReference: " + ref);
      }
      throw new RuntimeException("Gave up waiting for service " + flt);
    }
    return type.cast(svc);
  }
 catch (  InvalidSyntaxException e) {
    throw new IllegalArgumentException("Invalid filter",e);
  }
catch (  InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 

Example 15

From project e4-rendering, under directory /com.toedter.e4.demo.contacts.generic/src/com/toedter/e4/demo/contacts/generic/.

Source file: BundleActivatorImpl.java

  19 
vote

public IPath getStateLocation(){
  try {
    if (stateLocation == null) {
      Filter filter=context.createFilter(Location.INSTANCE_FILTER);
      if (locationServiceTracker == null) {
        locationServiceTracker=new ServiceTracker(context,filter,null);
        locationServiceTracker.open();
      }
      Location location=(Location)locationServiceTracker.getService();
      if (location != null) {
        IPath path=new Path(location.getURL().getPath());
        stateLocation=path.append(F_META_AREA).append(F_PLUGIN_DATA).append(context.getBundle().getSymbolicName());
        stateLocation.toFile().mkdirs();
      }
    }
  }
 catch (  InvalidSyntaxException e) {
  }
  return stateLocation;
}
 

Example 16

From project eclipse-integration-commons, under directory /org.springsource.ide.eclipse.commons.content.core/src/org/springsource/ide/eclipse/commons/internal/content/core/.

Source file: DescriptorMatcher.java

  19 
vote

@SuppressWarnings({"unchecked","rawtypes"}) public boolean match(Descriptor descriptor){
  if (version != null && descriptor.getRequires() != null) {
    try {
      VersionRange versionRange=new VersionRange(descriptor.getRequires());
      if (!versionRange.isIncluded(version)) {
        return false;
      }
    }
 catch (    IllegalArgumentException e) {
    }
  }
  if (descriptor.getFilter() != null) {
    try {
      Filter filter=FrameworkUtil.createFilter(descriptor.getFilter());
      return filter.match((Dictionary)environment);
    }
 catch (    IllegalArgumentException e) {
    }
catch (    InvalidSyntaxException e) {
    }
  }
  if (descriptor.isLocal()) {
    File baseDirectory=manager.getInstallDirectory();
    File directory=new File(baseDirectory,descriptor.getId() + "-" + descriptor.getVersion());
    if (!directory.exists()) {
      return false;
    }
  }
  return true;
}
 

Example 17

From project eclipse.platform.runtime, under directory /bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/.

Source file: AuthorizationHandler.java

  19 
vote

/** 
 * Opens the password database (if any) initially provided to the platform at startup. Returns <code>true</code> if the authentication implementation was successfully initialized, and <code>false</code> if no authentication implementation is available.
 */
private static boolean loadKeyring() throws CoreException {
  if (getAuthClass() == null)   return false;
  if (keyring != null && new File(keyringFile).lastModified() == keyringTimeStamp)   return true;
  if (keyringFile == null) {
    ServiceReference[] refs=null;
    try {
      refs=PlatformActivator.getContext().getServiceReferences(Location.class.getName(),Location.CONFIGURATION_FILTER);
      if (refs == null || refs.length == 0)       return true;
    }
 catch (    InvalidSyntaxException e) {
      return true;
    }
    Location configurationLocation=(Location)PlatformActivator.getContext().getService(refs[0]);
    if (configurationLocation == null)     return true;
    File file=new File(configurationLocation.getURL().getPath() + "/org.eclipse.core.runtime");
    PlatformActivator.getContext().ungetService(refs[0]);
    file=new File(file,F_KEYRING);
    keyringFile=file.getAbsolutePath();
  }
  try {
    Constructor constructor=authClass.getConstructor(new Class[]{String.class,String.class});
    keyring=constructor.newInstance(new Object[]{keyringFile,password});
  }
 catch (  Exception e) {
    log(e);
  }
  if (keyring == null) {
    new java.io.File(keyringFile).delete();
    try {
      Constructor constructor=authClass.getConstructor(new Class[]{String.class,String.class});
      keyring=constructor.newInstance(new Object[]{keyringFile,password});
    }
 catch (    Exception e) {
    }
  }
  keyringTimeStamp=new File(keyringFile).lastModified();
  return true;
}
 

Example 18

From project examples_1, under directory /datanucleus/com.paremus.datanucleus.extender/src/com/paremus/datanucleus/extender/.

Source file: PublishedAppTracker.java

  19 
vote

private static Filter buildFilter(String uriMatch){
  try {
    return FrameworkUtil.createFilter(String.format("(&(objectClass=%s)(uri=%s))",PublishedApplication.class.getName(),uriMatch));
  }
 catch (  InvalidSyntaxException e) {
    throw new RuntimeException(e);
  }
}
 

Example 19

From project Gemini-Blueprint, under directory /core/src/main/java/org/eclipse/gemini/blueprint/util/.

Source file: OsgiFilterUtils.java

  19 
vote

/** 
 * Creates an OSGi  {@link Filter} from the given String. Translates the {@link InvalidSyntaxException} checkedexception into an unchecked  {@link IllegalArgumentException}.
 * @param filter OSGi filter given as a String
 * @return OSGi filter (as <code>Filter</code>)
 */
public static Filter createFilter(String filter){
  Assert.hasText(filter,"invalid filter");
  try {
    return FrameworkUtil.createFilter(filter);
  }
 catch (  InvalidSyntaxException ise) {
    throw (RuntimeException)new IllegalArgumentException("invalid filter: " + ise.getFilter()).initCause(ise);
  }
}
 

Example 20

From project gemini-dbaccess, under directory /test/org.eclipse.gemini.dbaccess.test/src/org/eclipse/gemini/dbaccess/test/.

Source file: JdbcTests.java

  19 
vote

protected static DataSourceFactory lookupDsf(String driverName,String version){
  log("Lookup (" + driverName + ", "+ version+ ")");
  String filter="(&(" + DataSourceFactory.OSGI_JDBC_DRIVER_CLASS + "="+ driverName+ ")("+ DataSourceFactory.OSGI_JDBC_DRIVER_VERSION+ "="+ version+ "))";
  log("Filter is: " + filter);
  ServiceReference[] refs=null;
  try {
    refs=getContext().getServiceReferences(DataSourceFactory.class.getName(),filter);
  }
 catch (  InvalidSyntaxException isEx) {
    new RuntimeException("Bad filter",isEx);
  }
  log("DSF Service refs looked up from registry: " + refs);
  return (refs == null) ? null : (DataSourceFactory)getContext().getService(refs[0]);
}
 

Example 21

From project gemini.dbaccess, under directory /test/org.eclipse.gemini.dbaccess.test/src/org/eclipse/gemini/dbaccess/test/.

Source file: JdbcTests.java

  19 
vote

protected static DataSourceFactory lookupDsf(String driverName,String version){
  log("Lookup (" + driverName + ", "+ version+ ")");
  String filter="(&(" + DataSourceFactory.OSGI_JDBC_DRIVER_CLASS + "="+ driverName+ ")("+ DataSourceFactory.OSGI_JDBC_DRIVER_VERSION+ "="+ version+ "))";
  log("Filter is: " + filter);
  ServiceReference[] refs=null;
  try {
    refs=getContext().getServiceReferences(DataSourceFactory.class.getName(),filter);
  }
 catch (  InvalidSyntaxException isEx) {
    new RuntimeException("Bad filter",isEx);
  }
  log("DSF Service refs looked up from registry: " + refs);
  return (refs == null) ? null : (DataSourceFactory)getContext().getService(refs[0]);
}
 

Example 22

From project huiswerk, under directory /print/zxing-1.6/bug/src/com/google/zxing/client/bug/.

Source file: Activator.java

  19 
vote

public void start(BundleContext context) throws InvalidSyntaxException {
  barcodeServiceTracker=new BugBarcodeServiceTracker(context);
  Filter filter=context.createFilter(ServiceFilterGenerator.generateServiceFilter(barcodeServiceTracker.getServices()));
  serviceTracker=new ServiceTracker(context,filter,barcodeServiceTracker);
  serviceTracker.open();
}
 

Example 23

From project ihtika, under directory /Sources/Bundles/I_MainForm/src/main/java/ihtika2/mainform/.

Source file: Activator.java

  19 
vote

@Override public void stop(BundleContext context) throws Exception {
  try {
    ServiceReference[] refs=context.getServiceReferences(MainFormInterface.class.getName(),"(Funct=MainForm)");
    if (refs == null) {
      System.out.println("Not Found MainForm on Stop");
    }
 else {
      MainFormInterface MainForm=(MainFormInterface)context.getService(refs[0]);
      MainForm.disposeWindow();
    }
  }
 catch (  InvalidSyntaxException ex) {
    Ini.logger.fatal("Error on stopping MainForm",ex);
  }
}
 

Example 24

From project james, under directory /lifecycle-spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/.

Source file: OsgiLifecycleBeanFactoryPostProcessor.java

  19 
vote

@Override public void postProcessBeanFactory(BundleContext context,ConfigurableListableBeanFactory factory) throws BeansException, InvalidSyntaxException, BundleException {
  LogEnabledBeanPostProcessor loggingProcessor=new LogEnabledBeanPostProcessor();
  loggingProcessor.setBeanFactory(factory);
  loggingProcessor.setLogProvider(logProvider);
  loggingProcessor.setOrder(0);
  factory.addBeanPostProcessor(loggingProcessor);
  OSGIResourceAnnotationBeanPostProcessor resourceProcessor=new OSGIResourceAnnotationBeanPostProcessor();
  resourceProcessor.setBeanClassLoader(factory.getBeanClassLoader());
  resourceProcessor.setBeanFactory(factory);
  resourceProcessor.setBundleContext(context);
  resourceProcessor.setTimeout(60 * 1000);
  factory.addBeanPostProcessor(resourceProcessor);
  OSGIPersistenceUnitAnnotationBeanPostProcessor persistenceProcessor=new OSGIPersistenceUnitAnnotationBeanPostProcessor();
  persistenceProcessor.setBeanClassLoader(factory.getBeanClassLoader());
  persistenceProcessor.setBeanFactory(factory);
  persistenceProcessor.setBundleContext(context);
  persistenceProcessor.setTimeout(60 * 1000);
  factory.addBeanPostProcessor(persistenceProcessor);
  ConfigurableBeanPostProcessor configurationProcessor=new ConfigurableBeanPostProcessor();
  configurationProcessor.setBeanFactory(factory);
  configurationProcessor.setConfigurationProvider(confProvider);
  configurationProcessor.setOrder(2);
  factory.addBeanPostProcessor(configurationProcessor);
  InitDestroyAnnotationBeanPostProcessor annotationProcessor=new InitDestroyAnnotationBeanPostProcessor();
  annotationProcessor.setInitAnnotationType(PostConstruct.class);
  annotationProcessor.setDestroyAnnotationType(PreDestroy.class);
  factory.addBeanPostProcessor(annotationProcessor);
}
 

Example 25

From project jbosgi, under directory /testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi508/.

Source file: JBOSGi508TestCase.java

  19 
vote

private void assertServices() throws InvalidSyntaxException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
  ServiceReference[] srefs=context.getAllServiceReferences("org.jboss.test.osgi.jbosgi508.bundle2.Service2",null);
  Object service2=context.getService(srefs[0]);
  Assert.assertNotNull("Service2 not null",service2);
  Method method=service2.getClass().getMethod("getService1",(Class<?>[])null);
  Object service1=method.invoke(service2,(Object[])null);
  Assert.assertNotNull("Service1 not null",service1);
}
 

Example 26

From project jbosgi-framework, under directory /core/src/main/java/org/jboss/osgi/framework/internal/.

Source file: AbstractBundleContext.java

  19 
vote

@Override public void addServiceListener(ServiceListener listener){
  checkValidBundleContext();
  if (listener == null)   throw MESSAGES.illegalArgumentNull("listener");
  try {
    getFrameworkEventsPlugin().addServiceListener(bundleState,listener,null);
  }
 catch (  InvalidSyntaxException ex) {
  }
}
 

Example 27

From project jbosgi-resolver, under directory /api/src/main/java/org/jboss/osgi/resolver/spi/.

Source file: AbstractRequirement.java

  19 
vote

public static Filter getFilterFromDirective(Requirement req){
  String filterdir=req.getDirectives().get(AbstractWiringNamespace.REQUIREMENT_FILTER_DIRECTIVE);
  if (filterdir != null) {
    try {
      return FrameworkUtil.createFilter(filterdir);
    }
 catch (    InvalidSyntaxException e) {
      throw MESSAGES.illegalArgumentInvalidFilterDirective(filterdir);
    }
  }
  return null;
}
 

Example 28

From project karaf, under directory /config/command/src/main/java/org/apache/karaf/config/command/completers/.

Source file: ConfigurationPropertyCompleter.java

  19 
vote

/** 
 * Returns the property names for the given pid.
 * @param pid
 * @return
 */
@SuppressWarnings("rawtypes") private Set<String> getPropertyNames(String pid){
  Set<String> propertyNames=new HashSet<String>();
  if (pid != null) {
    Configuration configuration=null;
    try {
      Configuration[] configs=configAdmin.listConfigurations("(service.pid=" + pid + ")");
      if (configs != null && configs.length > 0) {
        configuration=configs[0];
        if (configuration != null) {
          Dictionary properties=configuration.getProperties();
          if (properties != null) {
            Enumeration keys=properties.keys();
            while (keys.hasMoreElements()) {
              propertyNames.add(String.valueOf(keys.nextElement()));
            }
          }
        }
      }
    }
 catch (    IOException e) {
    }
catch (    InvalidSyntaxException e) {
    }
  }
  return propertyNames;
}
 

Example 29

From project karaf-cellar, under directory /dosgi/src/main/java/org/apache/karaf/cellar/dosgi/.

Source file: EndpointDescription.java

  19 
vote

/** 
 * Tests the properties of this <code>EndpointDescription</code> against the given filter using a case insensitive match.
 * @param filter The filter to test.
 * @return <code>true</code> If the properties of this<code>EndpointDescription</code> match the filter, <code>false</code> otherwise.
 * @throws IllegalArgumentException If <code>filter</code> contains aninvalid filter string that cannot be parsed.
 */
public boolean matches(String filter){
  Filter f;
  try {
    f=FrameworkUtil.createFilter(filter);
  }
 catch (  InvalidSyntaxException e) {
    IllegalArgumentException iae=new IllegalArgumentException(e.getMessage());
    iae.initCause(e);
    throw iae;
  }
  Dictionary dictionary=new Properties();
  for (  Map.Entry<String,Object> entry : properties.entrySet()) {
    String key=entry.getKey();
    Object value=entry.getValue();
    dictionary.put(key,value);
  }
  return f.matchCase(dictionary);
}
 

Example 30

From project Karaf-Tutorial, under directory /db/command/src/main/java/net/lr/tutorial/karaf/db/service/.

Source file: DbSelect.java

  19 
vote

public ServiceReference[] getDataSources(){
  try {
    ServiceReference[] dsRefs=context.getServiceReferences(DataSource.class.getName(),null);
    if (dsRefs == null) {
      dsRefs=new ServiceReference[]{};
    }
    return dsRefs;
  }
 catch (  InvalidSyntaxException e) {
    throw new RuntimeException(e);
  }
}
 

Example 31

From project labs-delegation, under directory /service/src/main/java/org/openengsb/labs/delegation/service/.

Source file: DelegatedClassLoadingHelper.java

  19 
vote

/** 
 * Creates the OSGi service filter based on the three given values. Skips null values except for the name value.
 */
private Filter createFilter(String name,String context,String version){
  if (name == null) {
    throw new IllegalArgumentException("Property name may not be null");
  }
  List<String> filterElements=new ArrayList<String>();
  filterElements.add(String.format("(%s=%s)",Constants.PROVIDED_CLASSES_KEY,name));
  if (context != null) {
    filterElements.add(String.format("(%s=%s)",Constants.DELEGATION_CONTEXT_KEY,context));
  }
  if (version != null) {
    filterElements.add(String.format("(%s=%s)",Constants.CLASS_VERSION_KEY,version));
  }
  StringBuilder filterString=new StringBuilder();
  for (  String element : filterElements) {
    filterString.append(element);
  }
  if (filterElements.size() > 1) {
    filterString.insert(0,"(&");
    filterString.append(")");
  }
  try {
    return FrameworkUtil.createFilter(filterString.toString());
  }
 catch (  InvalidSyntaxException e) {
    throw new IllegalArgumentException("Invalid filter string: " + filterString.toString(),e);
  }
}
 

Example 32

From project livetribe-slp, under directory /osgi/bundle/src/main/java/org/livetribe/slp/osgi/.

Source file: DirectoryAgentListenerServiceTracker.java

  19 
vote

/** 
 * Create a <code>DirectoryAgentListenerServiceTracker</code> which will be used to automatically register instances of  {@link DirectoryAgentListener}to a specific  {@link DirectoryAgentNotifier}.
 * @param context  The OSGi {@link BundleContext} used to obtain OSGi service instances.
 * @param notifier The {@link DirectoryAgentNotifier} that directory agent notification listeners will be registered to.
 */
public DirectoryAgentListenerServiceTracker(final BundleContext context,final DirectoryAgentNotifier notifier){
  if (context == null)   throw new IllegalArgumentException("Bundle context cannot be null");
  if (notifier == null)   throw new IllegalArgumentException("Directory agent notifier cannot be null");
  try {
    tracker=generateServiceTracker(context,context.createFilter("(objectClass=" + DirectoryAgentListener.class.getName() + ")"),notifier);
  }
 catch (  InvalidSyntaxException ise) {
    LOGGER.log(Level.WARNING,"Oddly this caused an invalid syntax exception",ise);
    throw new IllegalStateException("Oddly this caused an invalid syntax exception");
  }
  if (LOGGER.isLoggable(Level.CONFIG)) {
    LOGGER.config("context: " + context);
    LOGGER.config("notifier: " + notifier);
  }
}
 

Example 33

From project Newsreader, under directory /bundles/org.eclipse.ecf.salvo.ui/src/org/eclipse/ecf/salvo/ui/internal/preferences/.

Source file: SignaturePreferencePage.java

  19 
vote

private void initTables(){
  try {
    ServiceReference[] x=Activator.getDefault().getBundle().getBundleContext().getAllServiceReferences(QuoteService.class.getName(),null);
    if (x != null)     for (int i=0; i < x.length; i++) {
      Button b=new Button(grpQuoteServices,SWT.RADIO);
      b.setText(x[i].getProperty("component.name").toString());
      b.setSelection(model.getQuoteService().equals(b.getText()));
      b.addSelectionListener(new SelectionAdapter(){
        @Override public void widgetSelected(        SelectionEvent e){
          if (((Button)e.widget).getSelection())           model.setQuoteService(((Button)e.widget).getText());
 else           model.setQuoteService("");
        }
      }
);
    }
  }
 catch (  InvalidSyntaxException e) {
    Debug.log(getClass(),e);
  }
}
 

Example 34

From project nuxeo-tycho-osgi, under directory /nuxeo-runtime/nuxeo-runtime-jetty7-adpater/src/main/java/org/nuxeo/runtime/jetty/.

Source file: JettyComponent.java

  19 
vote

protected void addFilter(FilterDescriptor contribution,ComponentInstance contributor){
  String contextPath=contribution.getContext();
  if (contextPath.startsWith("/")) {
    if (contextPath.length() > 1) {
      contextPath=contextPath.substring(1);
    }
 else {
      contextPath="";
    }
  }
  BundleContext bc=FrameworkUtil.getBundle(JettyBootstrapActivator.class).getBundleContext();
  String filter=OSGiWebappConstants.SERVICE_PROP_CONTEXT_PATH + "=" + SLASH_ESCAPED_FOR_LDAP+ contextPath;
  try {
    ServiceReference[] refs=bc.getServiceReferences(ContextHandler.class.getName(),filter);
    for (    ServiceReference r : refs) {
    }
  }
 catch (  InvalidSyntaxException e) {
    e.printStackTrace();
  }
  WebAppContext webAppContext=null;
}
 

Example 35

From project openengsb-framework, under directory /components/services/src/main/java/org/openengsb/core/services/internal/.

Source file: DefaultWiringService.java

  19 
vote

@Override public <T extends Domain>List<T> getDomainEndpoints(Class<T> domainType,String location,String context){
  Filter filterForLocation=OsgiUtils.getFilterForLocation(domainType,location);
  ServiceReference[] allServiceReferences;
  try {
    allServiceReferences=bundleContext.getAllServiceReferences(domainType.getName(),filterForLocation.toString());
  }
 catch (  InvalidSyntaxException e) {
    throw new RuntimeException(e);
  }
  List<T> result=new ArrayList<T>();
  if (allServiceReferences == null) {
    LOGGER.info("no references found for filter: {}",filterForLocation);
    return result;
  }
  LOGGER.debug("found {} references for {}",allServiceReferences.length,filterForLocation);
  for (  ServiceReference ref : allServiceReferences) {
    Object serviceId=ref.getProperty(Constants.SERVICE_ID);
    String filterString=String.format("(%s=%s)",Constants.SERVICE_ID,serviceId);
    try {
      T osgiServiceProxy=getServiceUtils().getOsgiServiceProxy(FrameworkUtil.createFilter(filterString),domainType);
      result.add(osgiServiceProxy);
    }
 catch (    InvalidSyntaxException e) {
      throw new RuntimeException(e);
    }
  }
  return result;
}
 

Example 36

From project org.openscada.atlantis, under directory /org.openscada.ae.event/src/org/openscada/ae/event/internal/.

Source file: EventServiceImpl.java

  19 
vote

public EventServiceImpl(final BundleContext context) throws InvalidSyntaxException {
  this.context=context;
  this.storeListener=new StoreListener(){
    @Override public void notify(    final Event event){
      EventServiceImpl.this.eventStored(event);
    }
  }
;
  final Filter filter=FilterUtil.createClassFilter(Storage.class.getName());
  this.storageTracker=new SingleServiceTracker<Storage>(this.context,filter,new SingleServiceListener<Storage>(){
    @Override public void serviceChange(    final ServiceReference<Storage> reference,    final Storage service){
      setStorage(service);
    }
  }
);
  this.storageTracker.open();
}