Search in sources :

Example 51 with InvalidSyntaxException

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();
}
Also used : InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) InputTransformer(ddf.catalog.transform.InputTransformer) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Before(org.junit.Before)

Example 52 with InvalidSyntaxException

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");
    }
}
Also used : NamespaceContext(javax.xml.namespace.NamespaceContext) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleReference(org.osgi.framework.BundleReference) ServiceReference(org.osgi.framework.ServiceReference)

Example 53 with InvalidSyntaxException

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);
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference)

Example 54 with InvalidSyntaxException

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;
}
Also used : MapToDictionaryAdapter(aQute.bnd.deployer.repository.MapToDictionaryAdapter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

Example 55 with InvalidSyntaxException

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);
    }
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Filter(org.osgi.framework.Filter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

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