package org.jboss.cx.remoting;

import org.jboss.cx.remoting.spi.EndpointProvider;

/**
 *
 */
public final class Remoting {

    private static final class EndpointProviderHolder {
        private static final EndpointProvider provider;

        static {
            provider = load();
        }

        private static EndpointProvider load() {
            return load("org.jboss.cx.remoting.core.CoreEndpointProvider");
        }

        private static EndpointProvider load(String name) {
            try {
                return (EndpointProvider) Class.forName(name).newInstance();
            } catch (Exception ex) {
                throw new IllegalArgumentException("Failed to instantiate Remoting endpoint provider: " + ex.getMessage(), ex);
            }
        }
    }

    public static Endpoint createEndpoint(String name) {
        return EndpointProviderHolder.provider.createEndpoint(name);
    }

    // privates

    private Remoting() { /* empty */ }
}

@@ -80,49 +80,309 @@
 er;%0A
-%0A/**%0A *%0A */%0Apublic final class Remoting %7B
+import org.jboss.cx.remoting.spi.wrapper.SessionWrapper;%0Aimport org.jboss.cx.remoting.spi.wrapper.ContextSourceWrapper;%0Aimport org.jboss.cx.remoting.core.util.Logger;%0Aimport java.net.URI;%0A%0A/**%0A *%0A */%0Apublic final class Remoting %7B%0A    private static final Logger log = Logger.getLogger(Remoting.class);
 %0A%0A  
@@ -1167,24 +1167,2106 @@
 me);%0A    %7D%0A%0A
+    public static Session createEndpointAndSession(String endpointName, URI remoteUri, String userName, char%5B%5D password) throws RemotingException %7B%0A        final Endpoint endpoint = createEndpoint(endpointName);%0A        boolean ok = false;%0A        try %7B%0A            final Session session = new SessionWrapper(endpoint.openSession(EndpointLocator.DEFAULT.setEndpointUri(remoteUri).setClientAuthentication(userName, password))) %7B%0A                public void close() throws RemotingException %7B%0A                    try %7B%0A                        super.close();%0A                    %7D finally %7B%0A                        endpoint.shutdown();%0A                    %7D%0A                %7D%0A            %7D;%0A            ok = true;%0A            return session;%0A        %7D finally %7B%0A            if (! ok) %7B%0A                endpoint.shutdown();%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static %3CI, O%3E ContextSource%3CI, O%3E createEndpointAndOpenService(String endpointName, URI remoteUri, String userName, char%5B%5D password, Class%3CI%3E requestType, Class%3CO%3E replyType, String serviceType, String serviceGroupName) throws RemotingException %7B%0A        final Session session = createEndpointAndSession(endpointName, remoteUri, userName, password);%0A        boolean ok = false;%0A        try %7B%0A            final ContextSource%3CI, O%3E service = new ContextSourceWrapper%3CI, O%3E(session.openService(ServiceLocator.DEFAULT.setRequestType(requestType).setReplyType(replyType).setServiceGroupName(serviceGroupName).setServiceType(serviceType))) %7B%0A                public void close() %7B%0A                    try %7B%0A                        super.close();%0A                    %7D finally %7B%0A                        try %7B%0A                            session.close();%0A                        %7D catch (RemotingException e) %7B%0A                            log.error(e, %22Failed to close Remoting session%22);%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D;%0A            ok = true;%0A            return service;%0A        %7D finally %7B%0A            if (! ok) %7B%0A                session.close();%0A            %7D%0A        %7D%0A    %7D%0A%0A
     // priva

Create simplified static client API