Refine search
this.filter = context.createFilter(listenerFilter); } catch (InvalidSyntaxException e) { IllegalArgumentException iae = new IllegalArgumentException("unexpected InvalidSyntaxException: " + e.getMessage()); iae.initCause(e); throw iae;
FilterImpl parse() throws InvalidSyntaxException { FilterImpl filter; try { filter = parse_filter(); } catch (ArrayIndexOutOfBoundsException e) { throw new InvalidSyntaxException("Filter ended abruptly", filterstring, e); } if (pos != filterChars.length) { throw new InvalidSyntaxException("Extraneous trailing characters: " + filterstring.substring(pos), filterstring); } return filter; }
} catch (InvalidSyntaxException e) { throw new RuntimeException("Invalid filter: " + e.getFilter(), e);
private List<InfoPanelItemProvider> findInfoPanelItems() { try { return m_bundlecontext.getServiceReferences(InfoPanelItemProvider.class, null).stream() .map(eachRef -> m_bundlecontext.getService(eachRef)) .collect(Collectors.toList()); } catch (InvalidSyntaxException e) { LOG.error(e.getMessage(), e); return Collections.emptyList(); } }
public static void initOSGI(final BundleContext context, final ServiceReference servref) { s_context = context; s_serviceref = servref; try { String filter = "(objectclass=" + LogService.class.getName() + ")"; context.addServiceListener(s_servlistener, filter); } catch (InvalidSyntaxException e) { e.printStackTrace(); } ServiceReference ref = context.getServiceReference(LogService.class.getName()); if (ref != null) { s_logservice = (LogService) context.getService(ref); } }
private List<Migration> getMigrations() { Collection<ServiceReference<Migration>> migrationServiceReferences = null; try { migrationServiceReferences = bundleContext.getServiceReferences(Migration.class, null); } catch (InvalidSyntaxException e) { e.printStackTrace(); } SortedSet<Migration> migrations = new TreeSet<>(new Comparator<Migration>() { @Override public int compare(Migration o1, Migration o2) { return o1.getToVersion().compareTo(o2.getToVersion()); } }); for (ServiceReference<Migration> migrationServiceReference : migrationServiceReferences) { Migration migration = bundleContext.getService(migrationServiceReference); migrations.add(migration); } return new ArrayList<>(migrations); }
private List<Object> handleCollection(Bundle bundle, Type t, IRequestor requestor, boolean track) { List<Object> rv = new ArrayList<>(); BundleContext context = bundle.getBundleContext(); if (context == null) { context = FrameworkUtil.getBundle(getClass()).getBundleContext(); } @SuppressWarnings("unchecked") Class<Object> cl = t instanceof ParameterizedType ? (Class<Object>) ((ParameterizedType) t).getRawType() : (Class<Object>) t; try { ServiceReference<?>[] serviceReferences = context.getServiceReferences(cl.getName(), null); if( serviceReferences != null ) { Arrays.sort(serviceReferences); for (ServiceReference<?> serviceReference : serviceReferences) { rv.add(context.getService(serviceReference)); if( track ) { context.addServiceListener(new ServiceHandler(requestor, context, cl)); } } } } catch (InvalidSyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } return rv; } }
private List<?> getAllServices() { Bundle bundle = FrameworkUtil.getBundle(OSGiProxyTargetLocator.class); BundleContext context = bundle.getBundleContext(); ServiceReference<?>[] references; try { references = context.getAllServiceReferences(typeName, null); if(references!=null && references.length>0) { List<Object> services = new ArrayList<Object>(references.length); for (ServiceReference<?> serviceReference : references) { Object service = context.getService(serviceReference); if(service!=null) services.add(service); } if(!services.isEmpty()) return services; } } catch (InvalidSyntaxException e) { // can't happen we use no filter e.printStackTrace(); } return null; }
@Test public void testGet() throws Exception { ServiceReference<String> ref = Mockito.mock( ServiceReference.class ); when( mockContext.getServiceReferences( String.class, null ) ).thenReturn( Collections.singletonList( ref ) ); when( mockContext.getService( ref ) ).thenReturn( "SomeString" ); when( mockContext.getServiceReferences( java.lang.Integer.class, null ) ) .thenThrow( new InvalidSyntaxException( "bad", "call" ) ); String actual = factory.get( String.class, session ); Integer missing = factory.get( Integer.class, session ); assertEquals( "SomeString", actual ); assertNull( missing ); Float missing2 = factory.get( Float.class, session ); assertNull( missing2 ); verify( mockContext ).getServiceReferences( String.class, null ); }
public static void add(final BundleContext context, final String ... pathes) { try { context.addServiceListener(new ServiceListener() { @Override public void serviceChanged(ServiceEvent event) { // only if registering if (event.getType() == ServiceEvent.REGISTERED) { // is the source bundle in the meantime removed ? quit! if (context.getBundle().getState() == Bundle.UNINSTALLED) { context.removeServiceListener(this); return; } // else set the configuration VaadinConfigurableResourceProviderAdmin service = (VaadinConfigurableResourceProviderAdmin) context.getService(event.getServiceReference()); if (service != null) service.addResource(context.getBundle().getSymbolicName(), pathes); } } },"(objectclass="+VaadinConfigurableResourceProviderAdmin.class.getCanonicalName()+")"); } catch (InvalidSyntaxException e) { e.printStackTrace(); } VaadinConfigurableResourceProviderAdmin service = doFind(context); if (service != null) service.addResource(context.getBundle().getSymbolicName(), pathes); }
/** * Returns references to <em>all</em> services matching the given class name and OSGi filter. * * @param bundleContext OSGi bundle context * @param clazz fully qualified class name (can be <code>null</code>) * @param filter valid OSGi filter (can be <code>null</code>) * @return non-<code>null</code> array of references to matching services */ public static ServiceReference[] getServiceReferences(BundleContext bundleContext, String clazz, String filter) { Assert.notNull(bundleContext, "bundleContext should be not null"); try { ServiceReference[] refs = bundleContext.getServiceReferences(clazz, filter); return (refs == null ? new ServiceReference[0] : refs); } catch (InvalidSyntaxException ise) { throw (RuntimeException) new IllegalArgumentException("invalid filter: " + ise.getFilter()).initCause(ise); } }
public static TrustEngine[] getTrustEngines() { if (trustEngineTracker == null) { String trustAuthorityProp = Activator.getBundleContext().getProperty(PROP_TRUST_ENGINE); Filter filter = null; if (trustAuthorityProp != null) try { filter = FrameworkUtil.createFilter("(&(" + Constants.OBJECTCLASS + "=" + TrustEngine.class.getName() + ")(" + PROP_TRUST_ENGINE + "=" + trustAuthorityProp + "))"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ } catch (InvalidSyntaxException e) { e.printStackTrace(); // do nothing just use no filter TODO we may want to log something } if (filter != null) { trustEngineTracker = new ServiceTracker<>(bundleContext, filter, null); } else trustEngineTracker = new ServiceTracker<>(bundleContext, TrustEngine.class, null); trustEngineTracker.open(); } return trustEngineTracker.getServices(new TrustEngine[] {}); }
/** * mapping rule: LDAP filter --> output value * the more specific filters should be given first. */ public void initialize(BundleContext ctx, String[][] mappingRules) { filters = new Filter[mappingRules.length]; outputStrings = new String[mappingRules.length]; for (int i = 0; i < mappingRules.length; i++) { try { filters[i] = ctx.createFilter(mappingRules[i][0]); outputStrings[i] = mappingRules[i][1]; } catch (InvalidSyntaxException e) { //TODO Neeed to process this e.printStackTrace(); } } }
public PackageAdminServiceTracker(BundleContext context) { INSTANCE = this; _context = context; if (!setup()) { try { _context.addServiceListener(this, "(objectclass=" + PackageAdmin.class.getName() + ")"); } catch (InvalidSyntaxException e) { e.printStackTrace(); // won't happen } } }
synchronized (t) { try { context.addServiceListener(t, listenerFilter); ServiceReference<S>[] references = null; if (trackClass != null) { throw new RuntimeException("unexpected InvalidSyntaxException: " + e.getMessage(), e);
/** * <p>fetchReferences.</p> * * @return an array of {@link org.osgi.framework.ServiceReference} objects. */ public ServiceReference<?>[] fetchReferences() { try { LOGGER.debug("Try to locate a suitable service for objectClass = " + serviceInterface + " and filter = " + filterString); return bundleContext.getAllServiceReferences(serviceInterface, filterString); } catch (InvalidSyntaxException e) { LOGGER.error("Creation of filter failed: {}", e.getMessage(), e); throw new RuntimeException("Creation of filter failed", e); } }
/** * Tests the properties of this {@code EndpointDescription} against the * given filter using a case insensitive match. * * @param filter The filter to test. * @return {@code true} If the properties of this * {@code EndpointDescription} match the filter, {@code false} * otherwise. * @throws IllegalArgumentException If {@code filter} contains an invalid * 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<String, Object> d = new UnmodifiableDictionary<String, Object>(properties); /* * we can use matchCase here since properties already supports case * insensitive key lookup. */ return f.matchCase(d); }
public void addServiceListener(ServiceListener listener) { try { addServiceListener(listener, null); } catch (InvalidSyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * construct the ServiceDeclaration from the service string * @param service A single service string value from the Import-Services or Export-Services header * @throws InvalidSyntaxException */ public ServiceDeclarationImpl(String service) throws InvalidSyntaxException { Content content = new ContentImpl(service); this.interfaceName = content.getContentName(); String filterString = content.getAttribute(FILTER); if (filterString != null) { try { this.filter = FrameworkUtil.createFilter(filterString); } catch (InvalidSyntaxException ise) { throw new InvalidSyntaxException("Failed to create filter for " + service, ise.getFilter(), ise.getCause()); } } }
/** * Creates an exception of type {@code InvalidSyntaxException}. * * <p> * This method creates an {@code InvalidSyntaxException} object with the * specified message and the filter string which generated the exception. * * @param msg The message. * @param filter The invalid filter string. */ public InvalidSyntaxException(String msg, String filter) { super(message(msg, filter)); this.filter = filter; }