Search in sources :

Example 6 with ContainerCreateException

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

the class AbstractConsumerContainerSelector method createContainer.

/**
 * @param containerTypeDescription containerTypeDescription
 * @param containerTypeDescriptionName containerTypeDescriptionName
 * @param properties properties
 * @return IRemoteServiceContainer created container.  Should not be <code>null</code>
 * @throws SelectContainerException thrown if container cannot be created or configured
 * @since 2.0
 */
protected IRemoteServiceContainer createContainer(ContainerTypeDescription containerTypeDescription, String containerTypeDescriptionName, Map properties) throws SelectContainerException {
    try {
        IContainer container = (properties == null) ? getContainerFactory().createContainer(containerTypeDescriptionName) : getContainerFactory().createContainer(containerTypeDescriptionName, properties);
        IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
        if (adapter == null)
            throw new SelectContainerException("Container config id=" + containerTypeDescriptionName + " does not implement IRemoteServiceContainerAdapter", null, // $NON-NLS-1$ //$NON-NLS-2$
            containerTypeDescription);
        return new RemoteServiceContainer(container);
    } catch (ContainerCreateException e) {
        String message = // $NON-NLS-1$
        "Cannot create container config id=" + containerTypeDescriptionName;
        logException(message, e);
        throw new SelectContainerException(message, e, containerTypeDescription);
    }
}
Also used : RemoteServiceContainer(org.eclipse.ecf.remoteservice.RemoteServiceContainer) IRemoteServiceContainer(org.eclipse.ecf.remoteservice.IRemoteServiceContainer) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) IContainer(org.eclipse.ecf.core.IContainer)

Example 7 with ContainerCreateException

use of org.eclipse.ecf.core.ContainerCreateException 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 8 with ContainerCreateException

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

the class XMPPContainerInstantiator method createInstance.

/*
	 * (non-Javadoc)
	 * 
	 * @seeorg.eclipse.ecf.core.provider.IContainerInstantiator#createInstance(
	 * ContainerDescription, java.lang.Object[])
	 */
public IContainer createInstance(ContainerTypeDescription description, Object[] args) throws ContainerCreateException {
    try {
        Integer ka = new Integer(XMPPContainer.DEFAULT_KEEPALIVE);
        String name = null;
        if (args != null) {
            if (args.length > 0) {
                name = (String) args[0];
                if (args.length > 1) {
                    ka = getIntegerFromArg(args[1]);
                }
            }
        }
        if (name == null) {
            if (ka == null) {
                return new XMPPContainer();
            } else {
                return new XMPPContainer(ka.intValue());
            }
        } else {
            if (ka == null) {
                ka = new Integer(XMPPContainer.DEFAULT_KEEPALIVE);
            }
            return new XMPPContainer(name, ka.intValue());
        }
    } catch (Exception e) {
        throw new ContainerCreateException("Exception creating generic container", e);
    }
}
Also used : ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) XMPPContainer(org.eclipse.ecf.provider.xmpp.XMPPContainer) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException)

Aggregations

ContainerCreateException (org.eclipse.ecf.core.ContainerCreateException)8 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IContainer (org.eclipse.ecf.core.IContainer)2 ID (org.eclipse.ecf.core.identity.ID)2 IRemoteServiceContainer (org.eclipse.ecf.remoteservice.IRemoteServiceContainer)2 URI (java.net.URI)1 UnknownHostException (java.net.UnknownHostException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Job (org.eclipse.core.runtime.jobs.Job)1 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)1 IContainerFactory (org.eclipse.ecf.core.IContainerFactory)1