Search in sources :

Example 41 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)

Example 42 with InvalidSyntaxException

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

Example 43 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 44 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 45 with InvalidSyntaxException

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>());
}
Also used : Serializable(java.io.Serializable) CatalogFramework(ddf.catalog.CatalogFramework) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Matchers.anyString(org.mockito.Matchers.anyString) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)105 ServiceReference (org.osgi.framework.ServiceReference)54 Filter (org.osgi.framework.Filter)26 ArrayList (java.util.ArrayList)22 IOException (java.io.IOException)20 BundleContext (org.osgi.framework.BundleContext)16 ServiceTracker (org.osgi.util.tracker.ServiceTracker)14 HashMap (java.util.HashMap)12 Configuration (org.osgi.service.cm.Configuration)12 Map (java.util.Map)10 Test (org.junit.Test)9 Dictionary (java.util.Dictionary)8 Hashtable (java.util.Hashtable)8 List (java.util.List)6 ConfigurationException (org.osgi.service.cm.ConfigurationException)6 Metacard (ddf.catalog.data.Metacard)4 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)4 CatalogFramework (ddf.catalog.CatalogFramework)3 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)3 InputTransformer (ddf.catalog.transform.InputTransformer)3