/**
 * 
 */
package org.cohorte.ecf.provider.jabsorb;

import java.util.Dictionary;

import org.eclipse.ecf.core.util.ECFException;
import org.eclipse.ecf.remoteservice.client.RemoteServiceClientRegistration;

/**
 * @author Thomas Calmant
 */
public class Utilities {

    /**
     * Generates an endpoint name according to the properties in the given
     * dictionary
     * 
     * @param aDictionary
     *            Properties of a service
     * @return The endpoint name
     * @throws ECFException
     *             Values used to generate a name are null or invalid
     */
    @SuppressWarnings("rawtypes")
    public static String getEndpointName(final Dictionary aDictionary)
            throws ECFException {

        return getEndpointName(
                (String) aDictionary.get(JabsorbConstants.ENDPOINT_NAME),
                (Long) aDictionary.get(JabsorbConstants.ENDPOINT_SERVICE_ID));
    }

    /**
     * Generates an endpoint name according to the properties from the given
     * registration bean
     * 
     * @param aRegistration
     *            Remote Service registration bean
     * @return The endpoint name
     * @throws ECFException
     *             Values used to generate a name are null or invalid
     */
    public static String getEndpointName(
            final RemoteServiceClientRegistration aRegistration)
            throws ECFException {

        return getEndpointName(
                (String) aRegistration
                        .getProperty(JabsorbConstants.ENDPOINT_NAME),
                (Long) aRegistration
                        .getProperty(JabsorbConstants.ENDPOINT_SERVICE_ID));
    }

    /**
     * Generates an endpoint name from the given property values
     * 
     * @param aEndpointName
     *            Endpoint name property value
     * @param aServiceId
     *            Remote serivce ID property value
     * @return The endpoint name (given or generated)
     * @throws ECFException
     *             Both given values are null or incorrect
     */
    public static String getEndpointName(final String aEndpointName,
            final Long aServiceId) throws ECFException {

        if (aEndpointName != null && !aEndpointName.isEmpty()) {
            // Valid endpoint name
            return aEndpointName;
        }

        if (aServiceId != null && aServiceId != 0) {
            return "service_" + aServiceId;
        }

        throw new ECFException("No endpoint name to generate");
    }

    /**
     * Hidden constructor
     */
    private Utilities() {

    }
}

@@ -201,16 +201,97 @@
 tration;
+%0Aimport org.osgi.framework.Constants;%0Aimport org.osgi.framework.ServiceReference;
 %0A%0A/**%0A *
@@ -974,32 +974,94 @@
 OINT_SERVICE_ID)
+,%0A                (Long) aDictionary.get(Constants.SERVICE_ID)
 );%0A    %7D%0A%0A    /*
@@ -1776,32 +1776,849 @@
 OINT_SERVICE_ID)
+,%0A                null);%0A    %7D%0A%0A    /**%0A     * Generates an endpoint name according to the properties from the given%0A     * service reference%0A     * %0A     * @param aServiceReference%0A     *            A service reference%0A     * @return The endpoint name%0A     * @throws ECFException%0A     *             Values used to generate a name are null or invalid%0A     */%0A    public static String getEndpointName(%0A            final ServiceReference%3C?%3E aServiceReference) throws ECFException %7B%0A%0A        return getEndpointName(%0A                (String) aServiceReference%0A                        .getProperty(JabsorbConstants.ENDPOINT_NAME),%0A                (Long) aServiceReference%0A                        .getProperty(JabsorbConstants.ENDPOINT_SERVICE_ID),%0A                (Long) aServiceReference.getProperty(Constants.SERVICE_ID)
 );%0A    %7D%0A%0A    /*
@@ -2782,22 +2782,21 @@
 @param a
-Servic
+Remot
 eId%0A    
@@ -2819,18 +2819,18 @@
 mote ser
-i
 v
+i
 ce ID pr
@@ -2833,32 +2833,118 @@
 D property value
+ (for consumer)%0A     * @param aServiceId%0A     *            Local service ID (for host)
 %0A     * @return 
@@ -3153,24 +3153,46 @@
 %0A           
+ final Long aRemoteId,
  final Long 
@@ -3360,16 +3360,17 @@
 ntName;%0A
+%0A
         
@@ -3362,32 +3362,123 @@
 Name;%0A%0A        %7D
+ else if (aRemoteId != null && aRemoteId != 0) %7B%0A            return %22service_%22 + aRemoteId;
 %0A%0A        if (aS
@@ -3467,24 +3467,31 @@
 d;%0A%0A        
+%7D else 
 if (aService

Support ServiceReference entry