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;
}
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()][]);
}
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);
}
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;
}
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);
}
});
}
Aggregations