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 TransformOperations method transform.
//
// Delegate methods
//
public BinaryContent transform(Metacard metacard, String transformerId, Map<String, Serializable> requestProperties) throws CatalogTransformerException {
if (metacard == null) {
throw new IllegalArgumentException("Metacard is null.");
}
ServiceReference[] refs;
try {
// TODO replace shortname with id
refs = frameworkProperties.getBundleContext().getServiceReferences(MetacardTransformer.class.getName(), "(|" + "(" + Constants.SERVICE_SHORTNAME + "=" + transformerId + ")" + "(" + Constants.SERVICE_ID + "=" + transformerId + ")" + ")");
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException("Invalid transformer shortName: " + transformerId, e);
}
if (refs == null || refs.length == 0) {
throw new IllegalArgumentException("Transformer " + transformerId + " not found");
}
MetacardTransformer transformer = (MetacardTransformer) frameworkProperties.getBundleContext().getService(refs[0]);
return transformer.transform(metacard, requestProperties);
}
use of org.osgi.framework.InvalidSyntaxException in project bnd by bndtools.
the class AbstractResolveContext method matches.
private boolean matches(Requirement requirement, Capability selfCap) {
boolean match = false;
if (isCorrectEffectiveness(requirement, selfCap)) {
try {
String filterStr = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
org.osgi.framework.Filter filter = filterStr != null ? org.osgi.framework.FrameworkUtil.createFilter(filterStr) : null;
if (filter == null)
match = true;
else
match = filter.match(new MapToDictionaryAdapter(selfCap.getAttributes()));
} catch (InvalidSyntaxException e) {
log.log(LogService.LOG_ERROR, "Invalid filter directive on requirement: " + requirement, e);
}
}
return match;
}
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);
}
}
Aggregations