Search in sources :

Example 6 with IContainerFactory

use of org.eclipse.ecf.core.IContainerFactory in project ecf by eclipse.

the class AbstractContainerSelector method createContainer.

/**
 * @param serviceReference serviceReference
 * @param properties overriding properties
 * @param containerTypeDescription containerTypeDescription
 * @param intents intents
 * @return IContainer created container.  May be null if instance cannot be created (e.g. because of intent requirements)
 * @throws SelectContainerException thrown if some create or configure failure
 * @since 4.6
 */
protected IContainer createContainer(ServiceReference serviceReference, Map<String, Object> properties, ContainerTypeDescription containerTypeDescription, String[] intents) throws SelectContainerException {
    IContainerFactory containerFactory = getContainerFactory();
    final Object containerFactoryArguments = getContainerFactoryArguments(serviceReference, properties, containerTypeDescription, intents);
    try {
        if (containerFactoryArguments instanceof String) {
            return containerFactory.createContainer(containerTypeDescription, (String) containerFactoryArguments);
        } else if (containerFactoryArguments instanceof ID) {
            return containerFactory.createContainer(containerTypeDescription, (ID) containerFactoryArguments);
        } else if (containerFactoryArguments instanceof Object[]) {
            return containerFactory.createContainer(containerTypeDescription, (Object[]) containerFactoryArguments);
        } else if (containerFactoryArguments instanceof Map) {
            return containerFactory.createContainer(containerTypeDescription, (Map) containerFactoryArguments);
        }
        return containerFactory.createContainer(containerTypeDescription);
    } catch (ContainerCreateException e) {
        if (e instanceof ContainerIntentException) {
            // $NON-NLS-1$ //$NON-NLS-2$
            LogUtility.logError("createContainer", DebugOptions.CONTAINER_SELECTOR, this.getClass(), "Container creation does not satisfy required intent=" + ((ContainerIntentException) e).getIntentName(), e);
            return null;
        } else
            throw new SelectContainerException(// $NON-NLS-1$
            "Exception creating or configuring container", // $NON-NLS-1$
            e, containerTypeDescription);
    }
}
Also used : IContainerFactory(org.eclipse.ecf.core.IContainerFactory) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) ID(org.eclipse.ecf.core.identity.ID) Map(java.util.Map) TreeMap(java.util.TreeMap) ContainerIntentException(org.eclipse.ecf.core.provider.ContainerIntentException)

Example 7 with IContainerFactory

use of org.eclipse.ecf.core.IContainerFactory in project ecf by eclipse.

the class NoRegistryContainerFactoryTest method testCreateContainer.

public void testCreateContainer() throws Exception {
    IContainerFactory f = Activator.getDefault().getContainerFactory();
    IContainer c = f.createContainer(getClass().getName());
    assertNotNull(c);
}
Also used : IContainerFactory(org.eclipse.ecf.core.IContainerFactory) IContainer(org.eclipse.ecf.core.IContainer)

Aggregations

IContainerFactory (org.eclipse.ecf.core.IContainerFactory)7 Dictionary (java.util.Dictionary)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ContainerCreateException (org.eclipse.ecf.core.ContainerCreateException)1 ContainerTypeDescription (org.eclipse.ecf.core.ContainerTypeDescription)1 IContainer (org.eclipse.ecf.core.IContainer)1 ID (org.eclipse.ecf.core.identity.ID)1 ContainerIntentException (org.eclipse.ecf.core.provider.ContainerIntentException)1 ISharedObjectContainer (org.eclipse.ecf.core.sharedobject.ISharedObjectContainer)1 IRemoteServiceContainer (org.eclipse.ecf.remoteservice.IRemoteServiceContainer)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1