Search in sources :

Example 21 with Dictionary

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

the class HelloWorldManagedServiceImpl method start.

/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
public void start(BundleContext context) throws Exception {
    Properties props = new Properties();
    props.put(Constants.SERVICE_PID, "helloworld-mn");
    this.context = context;
    this.msRegistration = context.registerService(ManagedService.class.getName(), this, (Dictionary) props);
    this.hwRegistration = null;
    //manually call our update to make sure the HW service is exposed out
    updated(null);
}
Also used : Dictionary(java.util.Dictionary) Properties(java.util.Properties)

Example 22 with Dictionary

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

the class JavaUtils method getBundleVersion.

public static Version getBundleVersion(Bundle bundle) {
    Dictionary headers = bundle.getHeaders();
    String version = (String) headers.get(Constants.BUNDLE_VERSION);
    return (version != null) ? Version.parseVersion(version) : Version.emptyVersion;
}
Also used : Dictionary(java.util.Dictionary)

Example 23 with Dictionary

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

the class MapRecipe method internalCreate.

protected Object internalCreate() throws ComponentDefinitionException {
    Class<?> mapType = getMap(typeClass);
    if (!ReflectionUtils.hasDefaultConstructor(mapType)) {
        throw new ComponentDefinitionException("Type does not have a default constructor " + mapType.getName());
    }
    Object o;
    try {
        o = mapType.newInstance();
    } catch (Exception e) {
        throw new ComponentDefinitionException("Error while creating set instance: " + mapType.getName());
    }
    Map instance;
    if (o instanceof Map) {
        instance = (Map) o;
    } else if (o instanceof Dictionary) {
        instance = new DummyDictionaryAsMap((Dictionary) o);
    } else {
        throw new ComponentDefinitionException("Specified map type does not implement the Map interface: " + mapType.getName());
    }
    ReifiedType defaultConvertKeyType = getType(keyType);
    ReifiedType defaultConvertValueType = getType(valueType);
    // add map entries
    try {
        for (Recipe[] entry : entries) {
            ReifiedType convertKeyType = workOutConversionType(entry[0], defaultConvertKeyType);
            Object key = convert(entry[0].create(), convertKeyType);
            // Each entry may have its own types
            ReifiedType convertValueType = workOutConversionType(entry[1], defaultConvertValueType);
            Object value = entry[1] != null ? convert(entry[1].create(), convertValueType) : null;
            instance.put(key, value);
        }
    } catch (Exception e) {
        throw new ComponentDefinitionException(e);
    }
    return instance;
}
Also used : Dictionary(java.util.Dictionary) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ReifiedType(org.osgi.service.blueprint.container.ReifiedType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException)

Example 24 with Dictionary

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

the class Activator method start.

public void start(BundleContext bc) throws Exception {
    Dictionary props = new Hashtable();
    props.put("service.exported.interfaces", "*");
    props.put("service.exported.configs", "org.apache.cxf.ws");
    props.put("org.apache.cxf.ws.address", "http://localhost:9090/greeter");
    registration = bc.registerService(GreeterService.class.getName(), new GreeterServiceImpl(), props);
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable)

Example 25 with Dictionary

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

the class ServiceInterceptor method registerServiceEnhancer.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void registerServiceEnhancer(ServiceReference reference) {
    Object actualService = ctx.getService(reference);
    if (actualService instanceof ModelInfoService) {
        ModelInfoService infoService = (ModelInfoService) actualService;
        Object serviceId = reference.getProperty(SERVICE_ID);
        Object enhancer = new ModelInfoEnhancerService(infoService);
        Dictionary properties = new Hashtable();
        Object originalDisplayName = reference.getProperty(DISPLAY_NAME);
        properties.put(DISPLAY_NAME, originalDisplayName + " [enhanced]");
        ServiceRegistration registration = ctx.registerService(ModelInfoService.class.getName(), enhancer, properties);
        registrations.put(serviceId + "", registration);
    } else {
        System.out.println("Oh dear - unexpected service " + actualService.getClass());
    }
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) ModelInfoService(org.apache.aries.samples.goat.api.ModelInfoService) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

Dictionary (java.util.Dictionary)161 Hashtable (java.util.Hashtable)61 Test (org.junit.Test)48 Configuration (org.osgi.service.cm.Configuration)33 Enumeration (java.util.Enumeration)27 Properties (java.util.Properties)24 BundleContext (org.osgi.framework.BundleContext)21 ServiceReference (org.osgi.framework.ServiceReference)21 HashMap (java.util.HashMap)19 ServiceRegistration (org.osgi.framework.ServiceRegistration)19 Map (java.util.Map)17 ArrayList (java.util.ArrayList)15 Bundle (org.osgi.framework.Bundle)15 IOException (java.io.IOException)13 LinkedHashMap (java.util.LinkedHashMap)12 Matchers.anyString (org.mockito.Matchers.anyString)11 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)10 ComponentContext (org.osgi.service.component.ComponentContext)10 TreeMap (java.util.TreeMap)9 MinionIdentity (org.opennms.minion.core.api.MinionIdentity)9