use of org.osgi.framework.InvalidSyntaxException in project bndtools by bndtools.
the class ArbitraryNamespaceSearchPanel method validate.
private void validate() {
try {
if (namespace == null || namespace.length() == 0) {
setError(null);
setRequirement(null);
return;
}
for (int i = 0; i < namespace.length(); i++) {
char c = namespace.charAt(i);
if ('.' == c) {
if (i == 0 || i == namespace.length() - 1)
throw new IllegalArgumentException("Namespace cannot have leading or trailing '.' character");
else if ('.' == namespace.charAt(i - 1))
throw new IllegalArgumentException("Namespace cannot have repeated '.' characters");
} else if (!Character.isLetterOrDigit(c) && c != '-' && c != '_')
throw new IllegalArgumentException(String.format("Invalid character in namespace: '%c'", c));
}
updateFilterExpressionHint(namespace);
CapReqBuilder builder = new CapReqBuilder(namespace);
if (filterStr != null && filterStr.trim().length() > 0) {
try {
Filter filter = FrameworkUtil.createFilter(filterStr.trim());
builder.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString());
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException("Invalid filter string: " + e.getMessage());
}
}
setRequirement(builder.buildSyntheticRequirement());
setError(null);
} catch (Exception e) {
setError(e.getMessage());
setRequirement(null);
}
}
use of org.osgi.framework.InvalidSyntaxException in project ddf by codice.
the class DumpCommand method getTransformers.
private List<MetacardTransformer> getTransformers() {
ServiceReference[] refs = null;
try {
refs = bundleContext.getAllServiceReferences(MetacardTransformer.class.getName(), "(|" + "(" + Constants.SERVICE_ID + "=" + transformerId + ")" + ")");
} catch (InvalidSyntaxException e) {
console.printf("Fail to get MetacardTransformer references due to %s", e.getMessage());
}
if (refs == null || refs.length == 0) {
return null;
}
List<MetacardTransformer> metacardTransformerList = new ArrayList<>();
for (ServiceReference ref : refs) {
metacardTransformerList.add((MetacardTransformer) bundleContext.getService(ref));
}
return metacardTransformerList;
}
use of org.osgi.framework.InvalidSyntaxException in project ddf by codice.
the class IngestCommandTest method setup.
@Before
public void setup() throws Exception {
ingestCommand = new IngestCommand();
ingestCommand.catalogFramework = givenCatalogFramework(getResultList("id1", "id2"));
BundleContext bundleContext = mock(BundleContext.class);
try {
when(bundleContext.getServiceReferences(anyString(), anyString())).thenReturn(new ServiceReference[] { mock(ServiceReference.class) });
InputTransformer inputTransformer = mock(InputTransformer.class);
when(bundleContext.getService(anyObject())).thenReturn(inputTransformer);
} catch (InvalidSyntaxException e) {
//ignore
}
ingestCommand.bundleContext = bundleContext;
ingestCommand.transformerId = CatalogCommands.SERIALIZED_OBJECT_ID;
ingestCommand.filePath = testFolder.getRoot().getAbsolutePath();
}
use of org.osgi.framework.InvalidSyntaxException in project ddf by codice.
the class NamespaceResolver method getNamespaceContexts.
private void getNamespaceContexts() {
// Determine the OSGi bundle context for the NamespaceResolver
if (this.bundleContext == null) {
LOGGER.debug("Setting bundleContext");
this.bundleContext = BundleReference.class.cast(this.getClass().getClassLoader()).getBundle().getBundleContext();
}
namespaceContexts = new ArrayList<NamespaceContext>();
if (bundleContext != null) {
ServiceReference[] refs = null;
try {
// Retrieve all of the namespace mappings from the OSGi Service Registry
refs = bundleContext.getServiceReferences(NamespaceContext.class.getName(), null);
LOGGER.debug("num NamespaceContexts service refs found = {}", refs.length);
} catch (InvalidSyntaxException e) {
LOGGER.debug("Invalid NamespaceContext syntax", e);
}
// If no NamespaceMaps found, nothing further to be done
if (refs == null || refs.length == 0) {
LOGGER.debug("No NamespaceContext services found");
} else {
// maintained for prefix-to-uri and uri=to-prefix
for (ServiceReference ref : refs) {
NamespaceContext namespaceContext = (NamespaceContext) bundleContext.getService(ref);
if (namespaceContext != null) {
namespaceContexts.add(namespaceContext);
} else {
LOGGER.debug("NamespaceContext for ServiceReference was null");
}
}
}
} else {
LOGGER.debug("BundleContext is NULL");
}
}
use of org.osgi.framework.InvalidSyntaxException in project ddf by codice.
the class CatalogFrameworkImplTest method testMetacardTransformWithInvalidSyntaxException.
@Test(expected = IllegalArgumentException.class)
public void testMetacardTransformWithInvalidSyntaxException() throws Exception {
BundleContext context = mock(BundleContext.class);
when(context.getServiceReferences(anyString(), anyString())).thenThrow(new InvalidSyntaxException("Invalid Syntax", ""));
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, context, eventAdmin, true);
framework.transform((Metacard) null, "NONE", new HashMap<String, Serializable>());
}
Aggregations