Java Code Examples for org.osgi.framework.InvalidSyntaxException#getMessage()

The following examples show how to use org.osgi.framework.InvalidSyntaxException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceTracker.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create a {@code ServiceTracker} on the specified class name.
 * 
 * <p>
 * Services registered under the specified class name will be tracked by
 * this {@code ServiceTracker}.
 * 
 * @param context The {@code BundleContext} against which the tracking is
 *        done.
 * @param clazz The class name of the services to be tracked.
 * @param customizer The customizer object to call when services are added,
 *        modified, or removed in this {@code ServiceTracker}. If customizer
 *        is {@code null}, then this {@code ServiceTracker} will be used as
 *        the {@code ServiceTrackerCustomizer} and this
 *        {@code ServiceTracker} will call the
 *        {@code ServiceTrackerCustomizer} methods on itself.
 */
public ServiceTracker(final BundleContext context, final String clazz, final ServiceTrackerCustomizer<S, T> customizer) {
	this.context = context;
	this.trackReference = null;
	this.trackClass = clazz;
	this.customizer = (customizer == null) ? this : customizer;
	// we call clazz.toString to verify clazz is non-null!
	this.listenerFilter = "(" + Constants.OBJECTCLASS + "=" + clazz.toString() + ")";
	try {
		this.filter = context.createFilter(listenerFilter);
	} catch (InvalidSyntaxException e) {
		/*
		 * we could only get this exception if the clazz argument was
		 * malformed
		 */
		IllegalArgumentException iae = new IllegalArgumentException("unexpected InvalidSyntaxException: " + e.getMessage());
		iae.initCause(e);
		throw iae;
	}
}
 
Example 2
Source File: EndpointDescription.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void bundlePanelShowTab(String name)
{
  ServiceReference<?>[] sr;
  try {
    sr =
      Activator.getBC()
          .getServiceReferences(SwingBundleDisplayer.class.getName(),
                                "(" + SwingBundleDisplayer.PROP_NAME + "="
                                    + name + ")");
    if (sr != null) {
      bundlePanelShowTab(sr[0]);
    }
  } catch (final InvalidSyntaxException e) {
    throw new RuntimeException(e.getMessage());
  }
}
 
Example 4
Source File: ServiceTracker.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a {@code ServiceTracker} on the specified class name.
 * 
 * <p>
 * Services registered under the specified class name will be tracked by
 * this {@code ServiceTracker}.
 * 
 * @param context The {@code BundleContext} against which the tracking is
 *        done.
 * @param clazz The class name of the services to be tracked.
 * @param customizer The customizer object to call when services are added,
 *        modified, or removed in this {@code ServiceTracker}. If customizer
 *        is {@code null}, then this {@code ServiceTracker} will be used as
 *        the {@code ServiceTrackerCustomizer} and this
 *        {@code ServiceTracker} will call the
 *        {@code ServiceTrackerCustomizer} methods on itself.
 */
public ServiceTracker(final BundleContext context, final String clazz, final ServiceTrackerCustomizer<S, T> customizer) {
	this.context = context;
	this.trackReference = null;
	this.trackClass = clazz;
	this.customizer = (customizer == null) ? this : customizer;
	// we call clazz.toString to verify clazz is non-null!
	this.listenerFilter = "(" + Constants.OBJECTCLASS + "=" + clazz.toString() + ")";
	try {
		this.filter = context.createFilter(listenerFilter);
	} catch (InvalidSyntaxException e) {
		/*
		 * we could only get this exception if the clazz argument was
		 * malformed
		 */
		IllegalArgumentException iae = new IllegalArgumentException("unexpected InvalidSyntaxException: " + e.getMessage());
		iae.initCause(e);
		throw iae;
	}
}
 
Example 5
Source File: OsgiScriptingEngines.java    From camunda-bpm-platform-osgi with Apache License 2.0 6 votes vote down vote up
@Override
public ScriptEngine getScriptEngineForLanguage(String language) {
   ScriptEngine scriptEngine = null;
   try {
     scriptEngine = resolveScriptEngine(language);
   } catch (InvalidSyntaxException e) {
     throw new ProcessEngineException(
         "problem resolving scripting engine" + e.getMessage(), e);
   }

   if (scriptEngine == null) {
     throw new ProcessEngineException(
         "Can't find scripting engine for '" + language + "'");
   }
   return scriptEngine;
}
 
Example 6
Source File: ServiceTracker.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Open this {@code ServiceTracker} and begin tracking services.
 * 
 * <p>
 * Services which match the search criteria specified when this
 * {@code ServiceTracker} was created are now tracked by this
 * {@code ServiceTracker}.
 * 
 * @param trackAllServices If {@code true}, then this {@code ServiceTracker}
 *        will track all matching services regardless of class loader
 *        accessibility. If {@code false}, then this {@code ServiceTracker}
 *        will only track matching services which are class loader
 *        accessible to the bundle whose {@code BundleContext} is used by
 *        this {@code ServiceTracker}.
 * @throws java.lang.IllegalStateException If the {@code BundleContext} with
 *         which this {@code ServiceTracker} was created is no longer valid.
 * @since 1.3
 */
public void open(boolean trackAllServices) {
	final Tracked t;
	synchronized (this) {
		if (tracked != null) {
			return;
		}
		if (DEBUG) {
			System.out.println("ServiceTracker.open: " + filter);
		}
		t = trackAllServices ? new AllTracked() : new Tracked();
		synchronized (t) {
			try {
				context.addServiceListener(t, listenerFilter);
				ServiceReference<S>[] references = null;
				if (trackClass != null) {
					references = getInitialReferences(trackAllServices, trackClass, null);
				} else {
					if (trackReference != null) {
						if (trackReference.getBundle() != null) {
							@SuppressWarnings("unchecked")
							ServiceReference<S>[] single = new ServiceReference[] {trackReference};
							references = single;
						}
					} else { /* user supplied filter */
						references = getInitialReferences(trackAllServices, null, listenerFilter);
					}
				}
				/* set tracked with the initial references */
				t.setInitial(references);
			} catch (InvalidSyntaxException e) {
				throw new RuntimeException("unexpected InvalidSyntaxException: " + e.getMessage(), e);
			}
		}
		tracked = t;
	}
	/* Call tracked outside of synchronized region */
	t.trackInitial(); /* process the initial references */
}
 
Example 7
Source File: RequireBundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Filter toFilter()
{
  final StringBuffer sb = new StringBuffer(80);
  boolean multipleConditions = false;

  sb.append('(');
  sb.append(BundleRevision.BUNDLE_NAMESPACE);
  sb.append('=');
  sb.append(name);
  sb.append(')');

  if (bundleRange != null) {
    sb.append(bundleRange.toFilterString(Constants.BUNDLE_VERSION_ATTRIBUTE));
    multipleConditions = true;
  }

  for (final Entry<String,Object> entry : attributes.entrySet()) {
    sb.append('(');
    sb.append(entry.getKey());
    sb.append('=');
    sb.append(entry.getValue().toString());
    sb.append(')');
    multipleConditions = true;
  }

  if (multipleConditions) {
    sb.insert(0, "(&");
    sb.append(')');
  }
  try {
    return FrameworkUtil.createFilter(sb.toString());
  } catch (final InvalidSyntaxException _ise) {
    throw new RuntimeException("Internal error, createFilter: '" +sb.toString() +"': " +_ise.getMessage());
  }
}
 
Example 8
Source File: ServiceTracker.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Open this {@code ServiceTracker} and begin tracking services.
 * 
 * <p>
 * Services which match the search criteria specified when this
 * {@code ServiceTracker} was created are now tracked by this
 * {@code ServiceTracker}.
 * 
 * @param trackAllServices If {@code true}, then this {@code ServiceTracker}
 *        will track all matching services regardless of class loader
 *        accessibility. If {@code false}, then this {@code ServiceTracker}
 *        will only track matching services which are class loader
 *        accessible to the bundle whose {@code BundleContext} is used by
 *        this {@code ServiceTracker}.
 * @throws java.lang.IllegalStateException If the {@code BundleContext} with
 *         which this {@code ServiceTracker} was created is no longer valid.
 * @since 1.3
 */
public void open(boolean trackAllServices) {
	final Tracked t;
	synchronized (this) {
		if (tracked != null) {
			return;
		}
		if (DEBUG) {
			System.out.println("ServiceTracker.open: " + filter);
		}
		t = trackAllServices ? new AllTracked() : new Tracked();
		synchronized (t) {
			try {
				context.addServiceListener(t, listenerFilter);
				ServiceReference<S>[] references = null;
				if (trackClass != null) {
					references = getInitialReferences(trackAllServices, trackClass, null);
				} else {
					if (trackReference != null) {
						if (trackReference.getBundle() != null) {
							@SuppressWarnings("unchecked")
							ServiceReference<S>[] single = new ServiceReference[] {trackReference};
							references = single;
						}
					} else { /* user supplied filter */
						references = getInitialReferences(trackAllServices, null, listenerFilter);
					}
				}
				/* set tracked with the initial references */
				t.setInitial(references);
			} catch (InvalidSyntaxException e) {
				throw new RuntimeException("unexpected InvalidSyntaxException: " + e.getMessage(), e);
			}
		}
		tracked = t;
	}
	/* Call tracked outside of synchronized region */
	t.trackInitial(); /* process the initial references */
}
 
Example 9
Source File: ServiceTracker.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create a {@code ServiceTracker} on the specified {@code ServiceReference}
 * .
 * 
 * <p>
 * The service referenced by the specified {@code ServiceReference} will be
 * tracked by this {@code ServiceTracker}.
 * 
 * @param context The {@code BundleContext} against which the tracking is
 *        done.
 * @param reference The {@code ServiceReference} for the service to be
 *        tracked.
 * @param customizer The customizer object to call when services are added,
 *        modified, or removed in this {@code ServiceTracker}. If customizer
 *        is {@code null}, then this {@code ServiceTracker} will be used as
 *        the {@code ServiceTrackerCustomizer} and this
 *        {@code ServiceTracker} will call the
 *        {@code ServiceTrackerCustomizer} methods on itself.
 */
public ServiceTracker(final BundleContext context, final ServiceReference<S> reference, final ServiceTrackerCustomizer<S, T> customizer) {
	this.context = context;
	this.trackReference = reference;
	this.trackClass = null;
	this.customizer = (customizer == null) ? this : customizer;
	this.listenerFilter = "(" + Constants.SERVICE_ID + "=" + reference.getProperty(Constants.SERVICE_ID).toString() + ")";
	try {
		this.filter = context.createFilter(listenerFilter);
	} catch (InvalidSyntaxException e) {
		/*
		 * we could only get this exception if the ServiceReference was
		 * invalid
		 */
		IllegalArgumentException iae = new IllegalArgumentException("unexpected InvalidSyntaxException: " + e.getMessage());
		iae.initCause(e);
		throw iae;
	}
}
 
Example 10
Source File: NativeRequirement.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
NativeRequirement(final BundleGeneration gen, String bnc)
{
  this.gen = gen;
  final List<HeaderEntry> hes =
    Util.parseManifestHeader(Constants.BUNDLE_NATIVECODE, bnc, false, false, false);
  for (final Iterator<HeaderEntry> heIt = hes.iterator(); heIt.hasNext();) {
    final HeaderEntry he = heIt.next();

    final List<String> keys = he.getKeys();
    if ("*".equals(keys.get(0))) {
      if (keys.size() != 1 || heIt.hasNext()) {
        throw new IllegalArgumentException("Bundle#" + gen.bundle.id +
                                           ", Unexpected characters after '*' in " + 
                                           Constants.BUNDLE_NATIVECODE + " header: " + bnc);
      }
      optional = true;
      break;
    }

    @SuppressWarnings("unchecked")
      final List<String> procs = (List<String>) he.getAttributes().get(Constants.BUNDLE_NATIVECODE_PROCESSOR);

    @SuppressWarnings("unchecked")
      final  List<String> oses = (List<String>) he.getAttributes().get(Constants.BUNDLE_NATIVECODE_OSNAME);

    @SuppressWarnings("unchecked")
      final List<String> vers = (List<String>) he.getAttributes().get(Constants.BUNDLE_NATIVECODE_OSVERSION);

    @SuppressWarnings("unchecked")
      final List<String> langs = (List<String>) he.getAttributes().get(Constants.BUNDLE_NATIVECODE_LANGUAGE);

    @SuppressWarnings("unchecked")
      final List<String> sfs = (List<String>) he.getAttributes().get(Constants.SELECTION_FILTER_ATTRIBUTE);
    String sf = null;
    if (sfs != null) {
      sf = sfs.get(0);
      if (sfs.size() != 1) {
        throw new IllegalArgumentException("Bundle#" + gen.bundle.id +
                                           ", Invalid character after native code selection filter: " + sf);
      }
    }
    try {
      entries.add(new NativeCodeEntry(keys, procs, oses, vers, langs, sf));
    } catch (InvalidSyntaxException ise) {
      throw new IllegalArgumentException("Bundle does not specify a valid " + Constants.BUNDLE_NATIVECODE +
                                         " header. Got exception: " + ise.getMessage());
    }
  }
}
 
Example 11
Source File: ServiceTracker.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Create a {@code ServiceTracker} on the specified {@code ServiceReference}
 * .
 * 
 * <p>
 * The service referenced by the specified {@code ServiceReference} will be
 * tracked by this {@code ServiceTracker}.
 * 
 * @param context The {@code BundleContext} against which the tracking is
 *        done.
 * @param reference The {@code ServiceReference} for the service to be
 *        tracked.
 * @param customizer The customizer object to call when services are added,
 *        modified, or removed in this {@code ServiceTracker}. If customizer
 *        is {@code null}, then this {@code ServiceTracker} will be used as
 *        the {@code ServiceTrackerCustomizer} and this
 *        {@code ServiceTracker} will call the
 *        {@code ServiceTrackerCustomizer} methods on itself.
 */
public ServiceTracker(final BundleContext context, final ServiceReference<S> reference, final ServiceTrackerCustomizer<S, T> customizer) {
	this.context = context;
	this.trackReference = reference;
	this.trackClass = null;
	this.customizer = (customizer == null) ? this : customizer;
	this.listenerFilter = "(" + Constants.SERVICE_ID + "=" + reference.getProperty(Constants.SERVICE_ID).toString() + ")";
	try {
		this.filter = context.createFilter(listenerFilter);
	} catch (InvalidSyntaxException e) {
		/*
		 * we could only get this exception if the ServiceReference was
		 * invalid
		 */
		IllegalArgumentException iae = new IllegalArgumentException("unexpected InvalidSyntaxException: " + e.getMessage());
		iae.initCause(e);
		throw iae;
	}
}