Search in sources :

Example 71 with Dictionary

use of java.util.Dictionary in project sling by apache.

the class WorkspacePickerFilter method activate.

@SuppressWarnings("rawtypes")
protected void activate(ComponentContext ctx) {
    Dictionary props = ctx.getProperties();
    this.parameterName = OsgiUtil.toString(props.get(PROP_PARAM_NAME), DEFAULT_PARAM_NAME);
    this.cookieName = OsgiUtil.toString(props.get(PROP_COOKIE_NAME), DEFAULT_COOKIE_NAME);
}
Also used : Dictionary(java.util.Dictionary)

Example 72 with Dictionary

use of java.util.Dictionary in project stanbol by apache.

the class DataBundleInstaller method register.

/**
     * Registers the bundle to the {@link #activated} map.
     *
     * @param bundle the bundle to register
     */
@SuppressWarnings("unchecked")
private void register(Bundle bundle) {
    synchronized (activated) {
        if (activated.containsKey(bundle)) {
            return;
        }
        //for now put the bundle with a null key to avoid duplicate adding
        activated.put(bundle, null);
    }
    log.debug("Register Bundle {} with DataBundleInstaller", bundle.getSymbolicName());
    Dictionary<String, String> headers = (Dictionary<String, String>) bundle.getHeaders();
    //        log.info("With Headers:");
    //        for(Enumeration<String> keys = headers.keys();keys.hasMoreElements();){
    //            String key = keys.nextElement();
    //            log.info(" > "+key+"="+headers.get(key));
    //        }
    String pathsString = (String) headers.get(BUNDLE_DATAFILE_HEADER);
    if (pathsString != null) {
        Dictionary<String, Object> properties = new Hashtable<String, Object>();
        String dataFilesRankingString = (String) headers.get(BUNDLE_DATAFILES_PRIORITY_HEADER);
        if (dataFilesRankingString != null) {
            try {
                properties.put(Constants.SERVICE_RANKING, Integer.valueOf(dataFilesRankingString));
            } catch (NumberFormatException e) {
                log.warn("Unable to parse integer value for '{}' from the configured value '{}'. " + "Will use default ranking", BUNDLE_DATAFILES_PRIORITY_HEADER, dataFilesRankingString);
            }
        }
        //else no service ranking
        List<String> paths = Arrays.asList(pathsString.replaceAll("\\s", "").split(","));
        BundleDataFileProvider provider = new BundleDataFileProvider(bundle, paths);
        properties.put(Constants.SERVICE_DESCRIPTION, String.format("%s for Bundle %s and Paths %s", BundleDataFileProvider.class.getSimpleName(), bundle.getSymbolicName(), provider.getSearchPaths()));
        ServiceRegistration registration = context.registerService(DataFileProvider.class.getName(), provider, properties);
        log.info("Registerd BundleResourceProvider for {} and relative paths {}", context.getBundle().getSymbolicName(), provider.getSearchPaths());
        synchronized (activated) {
            //update with the registration
            if (activated.containsKey(bundle)) {
                activated.put(bundle, registration);
            } else {
                //the bundle was deactivated in the meantime ... unregister :(
                registration.unregister();
            }
        }
    }
//else key not preset ... ignore bundle!
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) DataFileProvider(org.apache.stanbol.commons.stanboltools.datafileprovider.DataFileProvider) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 73 with Dictionary

use of java.util.Dictionary in project sling by apache.

the class AnonymousAccessConfigServlet method doPost.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
    response.setContentType(request.getContentType());
    String action = request.getParameter("action");
    if ("disable".equals(action)) {
        int existingModifiedCounter = modifiedCounter;
        Configuration config = configAdmin.getConfiguration(AUTH_PID, null);
        Dictionary props = config.getProperties();
        if (props == null) {
            props = new Hashtable();
        }
        props.put(PROP_AUTH_ANNONYMOUS, Boolean.FALSE);
        config.update(props);
        waitForModified(existingModifiedCounter, TIMEOUT);
    } else if ("enable".equals(action)) {
        int existingModifiedCounter = modifiedCounter;
        Configuration config = configAdmin.getConfiguration(AUTH_PID, null);
        Dictionary props = config.getProperties();
        if (props == null) {
            props = new Hashtable();
        }
        props.put(PROP_AUTH_ANNONYMOUS, Boolean.TRUE);
        config.update(props);
        waitForModified(existingModifiedCounter, TIMEOUT);
    }
    response.getWriter().println("ok");
}
Also used : Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable)

Example 74 with Dictionary

use of java.util.Dictionary in project stanbol by apache.

the class BundleInstaller method register.

/**
     * Registers the bundle to the {@link #activated} map.
     *
     * @param bundle the bundle to register
     */
@SuppressWarnings("unchecked")
private void register(Bundle bundle) {
    log.debug("register request for Bundle {}", bundle.getSymbolicName());
    synchronized (activated) {
        if (!isFrameworkActive()) {
            log.debug("ignore because Framework is shutting down!");
            return;
        }
        if (activated.containsKey(bundle)) {
            log.debug("  .. already registered ");
            return;
        }
    }
    log.debug("  ... registering");
    Dictionary<String, String> headers = (Dictionary<String, String>) bundle.getHeaders();
    //        log.info("With Headers:");
    //        for(Enumeration<String> keys = headers.keys();keys.hasMoreElements();){
    //            String key = keys.nextElement();
    //            log.info(" > "+key+"="+headers.get(key));
    //        }
    String path = (String) headers.get(BUNDLE_INSTALLER_HEADER);
    activated.put(bundle, path);
    if (path != null) {
        log.info(" ... process configuration within path {} for bundle {}", path, bundle.getSymbolicName());
        Enumeration<URL> resources = (Enumeration<URL>) bundle.findEntries(path, null, true);
        if (resources != null) {
            ArrayList<InstallableResource> updated = new ArrayList<InstallableResource>();
            while (resources.hasMoreElements()) {
                URL url = resources.nextElement();
                if (url != null) {
                    log.debug("  > installable RDFTerm {}", url);
                    InstallableResource resource = createInstallableResource(bundle, path, url);
                    if (resource != null) {
                        updated.add(resource);
                    }
                }
            }
            try {
                storeConfig(bundle, updated);
            } catch (IOException e) {
                throw new IllegalStateException("Unablt to save the IDs of" + "the resources installed for bundle '" + bundle.getSymbolicName() + "'!", e);
            }
            installer.updateResources(PROVIDER_SCHEME, updated.toArray(new InstallableResource[updated.size()]), new String[] {});
        } else {
            log.warn(" ... no Entries found in path '{}' configured for Bundle '{}' with Manifest header field '{}'!", new Object[] { path, bundle.getSymbolicName(), BUNDLE_INSTALLER_HEADER });
        }
    } else {
        log.debug("  ... no Configuration to process");
    }
}
Also used : Dictionary(java.util.Dictionary) Enumeration(java.util.Enumeration) InstallableResource(org.apache.sling.installer.api.InstallableResource) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL)

Example 75 with Dictionary

use of java.util.Dictionary in project sling by apache.

the class MockComponentContextTest method testProvidedProperties.

@Test
public void testProvidedProperties() {
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("prop1", "value1");
    props.put("prop2", 25);
    ComponentContext componentContextWithProperties = MockOsgi.newComponentContext(props);
    Dictionary contextProps = componentContextWithProperties.getProperties();
    assertEquals(2, contextProps.size());
    assertEquals("value1", contextProps.get("prop1"));
    assertEquals(25, contextProps.get("prop2"));
}
Also used : Dictionary(java.util.Dictionary) ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) Test(org.junit.Test)

Aggregations

Dictionary (java.util.Dictionary)198 Hashtable (java.util.Hashtable)91 Test (org.junit.Test)48 Configuration (org.osgi.service.cm.Configuration)33 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)28 State (org.eclipse.osgi.service.resolver.State)28 Enumeration (java.util.Enumeration)27 Properties (java.util.Properties)27 BundleContext (org.osgi.framework.BundleContext)24 ArrayList (java.util.ArrayList)22 ServiceReference (org.osgi.framework.ServiceReference)21 HashMap (java.util.HashMap)20 ServiceRegistration (org.osgi.framework.ServiceRegistration)20 IOException (java.io.IOException)17 Map (java.util.Map)17 Bundle (org.osgi.framework.Bundle)16 LinkedHashMap (java.util.LinkedHashMap)13 List (java.util.List)13 Matchers.anyString (org.mockito.Matchers.anyString)11 MinionIdentity (org.opennms.minion.core.api.MinionIdentity)11