Search in sources :

Example 76 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class OSGiImpl method buildFilter.

static Filter buildFilter(BundleContext bundleContext, String filterString, Class<?> clazz) {
    Filter filter;
    String string = buildFilterString(filterString, clazz);
    try {
        filter = bundleContext.createFilter(string);
    } catch (InvalidSyntaxException e) {
        throw new RuntimeException(e);
    }
    return filter;
}
Also used : Filter(org.osgi.framework.Filter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

Example 77 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class ConfigurationAdmin method getConfigurations.

/**
     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#getConfigurations(java.lang.String)
     */
public String[][] getConfigurations(String filter) throws IOException {
    if (filter == null || filter.length() < 1) {
        throw new IOException("Argument filter cannot be null or empty");
    }
    List<String[]> result = new ArrayList<String[]>();
    Configuration[] configurations = null;
    try {
        configurations = configurationAdmin.listConfigurations(filter);
    } catch (InvalidSyntaxException e) {
        throw new IOException("Invalid filter [" + filter + "] : " + e);
    }
    if (configurations != null) {
        for (Configuration config : configurations) {
            result.add(new String[] { config.getPid(), config.getBundleLocation() });
        }
    }
    return result.toArray(new String[result.size()][]);
}
Also used : Configuration(org.osgi.service.cm.Configuration) ArrayList(java.util.ArrayList) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException)

Example 78 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class BlueprintMetadata method getBlueprintContainerServiceId.

/*
     * (non-Javadoc)
     * 
     * @see org.apache.aries.jmx.blueprint.BlueprintMetadataMBean#getBlueprintContainerServiceId(long)
     */
public long getBlueprintContainerServiceId(long bundleId) throws IOException {
    Bundle bpBundle = bundleContext.getBundle(bundleId);
    if (null == bpBundle)
        throw new IllegalArgumentException("Invalid bundle id " + bundleId);
    String filter = // no similar one in interfaces
    "(&(osgi.blueprint.container.symbolicname=" + bpBundle.getSymbolicName() + ")(osgi.blueprint.container.version=" + bpBundle.getVersion() + "))";
    ServiceReference[] serviceReferences = null;
    try {
        serviceReferences = bundleContext.getServiceReferences(BlueprintContainer.class.getName(), filter);
    } catch (InvalidSyntaxException e) {
        throw new RuntimeException(e);
    }
    if (serviceReferences == null || serviceReferences.length < 1)
        return -1;
    else
        return (Long) serviceReferences[0].getProperty(Constants.SERVICE_ID);
}
Also used : Bundle(org.osgi.framework.Bundle) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference)

Example 79 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class ServerSideClass method getProviders.

public String[] getProviders() {
    System.err.println("Getting providers...");
    ArrayList<String> result = new ArrayList<String>();
    ServletContext context = ServerContextFactory.get().getServletContext();
    Object o = context.getAttribute("osgi-bundlecontext");
    if (o != null) {
        if (o instanceof BundleContext) {
            BundleContext b_ctx = (BundleContext) o;
            try {
                System.err.println("Getting providers [2]...");
                ServiceReference[] srs = b_ctx.getServiceReferences(ModelInfoService.class.getName(), null);
                System.err.println("Got.. " + srs);
                if (srs == null || srs.length == 0) {
                    System.err.println("NO DATA PROVIDERS");
                    throw new RuntimeException("Unable to find any data providers");
                }
                System.err.println("Processing srs as loop.");
                for (ServiceReference sr : srs) {
                    System.err.println("Processing srs entry...");
                    String name = (String.valueOf(sr.getProperty("displayName")));
                    result.add(name);
                }
                System.err.println("Processed srs as loop.");
            } catch (InvalidSyntaxException e) {
            // wont happen, the exception relates to the filter, (2nd
            // arg above), which is constant null.
            }
        }
    }
    System.err.println("Returning " + result.size());
    String[] arr = new String[result.size()];
    arr = result.toArray(arr);
    for (String x : arr) {
        System.err.println(" - " + x);
    }
    return arr;
}
Also used : ArrayList(java.util.ArrayList) ServletContext(javax.servlet.ServletContext) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleContext(org.osgi.framework.BundleContext) ModelInfoService(org.apache.aries.samples.goat.api.ModelInfoService) ServiceReference(org.osgi.framework.ServiceReference)

Example 80 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class StartAction method setExportIsolationPolicy.

private static void setExportIsolationPolicy(final BasicSubsystem subsystem, Coordination coordination) throws InvalidSyntaxException {
    if (!subsystem.isComposite())
        return;
    final Region from = ((BasicSubsystem) subsystem.getParents().iterator().next()).getRegion();
    final Region to = subsystem.getRegion();
    RegionFilterBuilder builder = from.getRegionDigraph().createRegionFilterBuilder();
    setExportIsolationPolicy(builder, subsystem.getDeploymentManifest().getExportPackageHeader(), subsystem);
    setExportIsolationPolicy(builder, subsystem.getDeploymentManifest().getProvideCapabilityHeader(), subsystem);
    setExportIsolationPolicy(builder, subsystem.getDeploymentManifest().getSubsystemExportServiceHeader(), subsystem);
    RegionFilter regionFilter = builder.build();
    if (regionFilter.getSharingPolicy().isEmpty())
        return;
    if (logger.isDebugEnabled())
        logger.debug("Establishing region connection: from=" + from + ", to=" + to + ", filter=" + regionFilter);
    try {
        from.connectRegion(to, regionFilter);
    } catch (BundleException e) {
        // been set. Bad assumption?
        return;
    }
    coordination.addParticipant(new Participant() {

        @Override
        public void ended(Coordination coordination) throws Exception {
            // It may be necessary to rollback the export sharing policy
            // even when the coordination did not fail. For example, this
            // might have been a subsystem whose export sharing policy was
            // set just in case it offered dependencies for some other
            // subsystem.
            unsetExportIsolationPolicyIfNecessary();
        }

        @Override
        public void failed(Coordination coordination) throws Exception {
        // Nothing to do because a coordination is always ended.
        }

        private void unsetExportIsolationPolicyIfNecessary() throws BundleException, InvalidSyntaxException {
            if (!EnumSet.of(State.INSTALLING, State.INSTALLED).contains(subsystem.getState())) {
                // does not require a rollback.
                return;
            }
            // The subsystem is either INSTALLING or INSTALLED and therefore
            // requires a rollback since the export sharing policy must only
            // be set upon entering the RESOLVED state.
            RegionUpdater updater = new RegionUpdater(from, to);
            updater.addRequirements(null);
        }
    });
}
Also used : RegionFilter(org.eclipse.equinox.region.RegionFilter) Participant(org.osgi.service.coordinator.Participant) Coordination(org.osgi.service.coordinator.Coordination) Region(org.eclipse.equinox.region.Region) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleException(org.osgi.framework.BundleException) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder) BundleException(org.osgi.framework.BundleException) SubsystemException(org.osgi.service.subsystem.SubsystemException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) CoordinationException(org.osgi.service.coordinator.CoordinationException)

Aggregations

InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)124 ServiceReference (org.osgi.framework.ServiceReference)59 Filter (org.osgi.framework.Filter)29 ArrayList (java.util.ArrayList)27 IOException (java.io.IOException)23 BundleContext (org.osgi.framework.BundleContext)21 HashMap (java.util.HashMap)17 ServiceTracker (org.osgi.util.tracker.ServiceTracker)14 BundleException (org.osgi.framework.BundleException)12 Configuration (org.osgi.service.cm.Configuration)12 Map (java.util.Map)11 Dictionary (java.util.Dictionary)9 Hashtable (java.util.Hashtable)9 Test (org.junit.Test)9 List (java.util.List)8 File (java.io.File)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 URL (java.net.URL)6 LinkedHashMap (java.util.LinkedHashMap)6 FilterImpl (org.eclipse.osgi.internal.framework.FilterImpl)6