コード例 #1
0
 /**
  * creates a new container instance.
  *
  * @param description the container type description.
  * @param parameters the parameter passed to the container constructor.
  * @return the factored container instance.
  * @see
  *     org.eclipse.ecf.core.provider.IContainerInstantiator#createInstance(org.eclipse.ecf.core.ContainerTypeDescription,
  *     java.lang.Object[])
  */
 public IContainer createInstance(
     final ContainerTypeDescription description, final Object[] parameters)
     throws ContainerCreateException {
   try {
     final RemoteOSGiService remoteOSGiService = Activator.getDefault().getRemoteOSGiService();
     String descriptionName = description.getName();
     boolean wss = descriptionName.equals(ROSGI_WEBSOCKETSS_CONFIG);
     boolean ws = (descriptionName.equals(ROSGI_WEBSOCKETS_CONFIG) || wss);
     Namespace ns =
         (wss
             ? R_OSGiWSSNamespace.getDefault()
             : ((ws) ? R_OSGiWSNamespace.getDefault() : R_OSGiNamespace.getDefault()));
     ID containerID = null;
     if (parameters == null) {
       String localHost = "localhost"; // $NON-NLS-1$
       if (useHostname) {
         try {
           localHost = InetAddress.getLocalHost().getCanonicalHostName();
         } catch (UnknownHostException e) {
           // Ignore
         }
       }
       final String nsScheme = ns.getScheme();
       final String wsProtocol = (wss ? WSS_PROTOCOL : (ws ? WS_PROTOCOL : null));
       int listeningPort =
           remoteOSGiService.getListeningPort((wsProtocol != null) ? wsProtocol : nsScheme);
       int idPort = -1;
       if (WSS_PROTOCOL.equals(wsProtocol) && listeningPort != WSS_DEFAULT_PORT)
         idPort = listeningPort;
       else if (WS_PROTOCOL.equals(wsProtocol) && listeningPort != WS_DEFAULT_PORT)
         idPort = listeningPort;
       String portStr = (idPort > 0 ? (":" + idPort) : ""); // $NON-NLS-1$ //$NON-NLS-2$
       containerID =
           createR_OSGiID(ns, new String(nsScheme + "://" + localHost + portStr)); // $NON-NLS-1$
     } else if (parameters.length > 0) {
       if (parameters[0] instanceof ID) containerID = (ID) parameters[0];
       else if (parameters[0] instanceof String)
         containerID = createR_OSGiID(ns, (String) parameters[0]);
       else if (parameters[0] instanceof Map) {
         Map params = (Map) parameters[0];
         String idStr = (String) params.get(ID_PROP);
         if (idStr == null)
           throw new NullPointerException("No ID prop found in parameters map"); // $NON-NLS-1$
         containerID = createR_OSGiID(ns, idStr);
       }
     }
     if (containerID == null)
       throw new ContainerCreateException(
           "Unsupported arguments " //$NON-NLS-1$
               + Arrays.asList(parameters));
     if (wss) return new R_OSGiWSSRemoteServiceContainer(remoteOSGiService, containerID);
     else if (ws) return new R_OSGiWSRemoteServiceContainer(remoteOSGiService, containerID);
     else return new R_OSGiRemoteServiceContainer(remoteOSGiService, containerID);
   } catch (Exception e) {
     throw new ContainerCreateException("Could not create R_OSGI ID", e); // $NON-NLS-1$
   }
 }
コード例 #2
0
 public String[] getSupportedConfigs(ContainerTypeDescription description) {
   return new String[] {description.getName()};
 }