{
throw new NullPointerException("locator cannot be null");
}
synchronized(clientLock)
{
ClientInvoker invoker = (ClientInvoker) clientLocators.get(locator);
if(invoker != null)
{
return invoker;
}
boolean isPassByValue = false;
Map parameters = locator.getParameters();
if(parameters != null)
{
String value = (String) parameters.get(InvokerLocator.BYVALUE);
if(value != null && Boolean.valueOf(value).booleanValue())
{
isPassByValue = true;
}
}
// Check to see if server invoker is local
// If in server locators map, then created locally by this class
ServerInvoker svrInvoker = (ServerInvoker) serverLocators.get(locator);
if(svrInvoker != null && !isPassByValue)
{
LocalClientInvoker localInvoker = new LocalClientInvoker(locator);
// have to set reference to local server invoker so client in invoke directly
localInvoker.setServerInvoker(svrInvoker);
invoker = localInvoker;
InvokerLocator l = invoker.getLocator();
clientLocators.put(l, invoker);
}
else //not local
{
String protocol = locator.getProtocol();
if(protocol == null)
{
throw new NullPointerException("protocol cannot be null for the locator");
}
Class cl = (Class) clientInvokers.get(protocol);
if(cl == null)
{
cl = loadClientInvoker(protocol);
if(cl == null)
{
throw new RuntimeException("Couldn't find valid client invoker class for transport '" + protocol + "'");
}
}
if(configuration != null)
{
Constructor ctor = cl.getConstructor(new Class[]{InvokerLocator.class, Map.class});
invoker = (ClientInvoker) ctor.newInstance(new Object[]{locator, configuration});
}
else
{
Constructor ctor = cl.getConstructor(new Class[]{InvokerLocator.class});
invoker = (ClientInvoker) ctor.newInstance(new Object[]{locator});
}
InvokerLocator l = invoker.getLocator();
clientLocators.put(l, invoker);
}
return invoker;
}
}