Search in sources :

Example 1 with ContainerIntentException

use of org.eclipse.ecf.core.provider.ContainerIntentException 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)

Aggregations

Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ContainerCreateException (org.eclipse.ecf.core.ContainerCreateException)1 IContainerFactory (org.eclipse.ecf.core.IContainerFactory)1 ID (org.eclipse.ecf.core.identity.ID)1 ContainerIntentException (org.eclipse.ecf.core.provider.ContainerIntentException)1