* @param classLoader
* @throws OpenEJBException
*/
private void buildWebServiceRef(final JndiConsumer consumer, final WebServiceRef webService, final HandlerChain handlerChain, final Member member, final ClassLoader classLoader) throws OpenEJBException {
ServiceRef serviceRef;
String refName = webService.name();
if (refName.equals("")) {
if (member == null) {
//TODO fail
return;
}
refName = member.getDeclaringClass().getName() + "/" + member.getName();
}
refName = normalize(refName);
serviceRef = consumer.getServiceRefMap().get(refName);
if (serviceRef == null) {
serviceRef = new ServiceRef();
serviceRef.setServiceRefName(refName);
consumer.getServiceRef().add(serviceRef);
}
if (member != null) {
// Set the member name where this will be injected
final InjectionTarget target = new InjectionTarget();
target.setInjectionTargetClass(member.getDeclaringClass().getName());
target.setInjectionTargetName(member.getName());
serviceRef.getInjectionTarget().add(target);
}
// Set service interface
Class<?> serviceInterface = null;
if (serviceRef.getServiceInterface() == null) {
serviceInterface = webService.type();
if (serviceInterface.equals(Object.class)) {
serviceInterface = webService.value();
if ((Service.class.equals(serviceInterface) || Object.class.equals(serviceInterface)) && member != null) {
serviceInterface = member.getType();
}
}
}
if (serviceInterface == null || !Service.class.isAssignableFrom(serviceInterface)) {
serviceInterface = Service.class;
}
serviceRef.setServiceInterface(serviceInterface.getName());
// reference type
if (serviceRef.getServiceRefType() == null || "".equals(serviceRef.getServiceRefType())) {
if (webService.type() != Object.class) {
serviceRef.setServiceRefType(webService.type().getName());
} else {
if (member != null) {
serviceRef.setServiceRefType(member.getType().getName());
}
}
}
Class<?> refType = null;
try {
refType = classLoader.loadClass(realClassName(serviceRef.getType()));
} catch (final ClassNotFoundException e) {
// no-op
}
// Set the mappedName
if (serviceRef.getMappedName() == null) {
String mappedName = webService.mappedName();
if (mappedName.equals("")) {
mappedName = null;
}
serviceRef.setMappedName(mappedName);
}
// wsdl file
if (serviceRef.getWsdlFile() == null) {
final String wsdlLocation = webService.wsdlLocation();
if (!wsdlLocation.equals("")) {
serviceRef.setWsdlFile(wsdlLocation);
}
}
if (SystemInstance.get().hasProperty("openejb.geronimo")) {
return;
}
if (serviceRef.getWsdlFile() == null && refType != null) {
serviceRef.setWsdlFile(JaxWsUtils.getServiceWsdlLocation(refType, classLoader));
}
if (serviceRef.getWsdlFile() == null) {
serviceRef.setWsdlFile(JaxWsUtils.getServiceWsdlLocation(serviceInterface, classLoader));
}
// service qname
if (serviceRef.getServiceQname() == null && refType != null) {
serviceRef.setServiceQname(JaxWsUtils.getServiceQName(refType));
}
if (serviceRef.getServiceQname() == null) {
serviceRef.setServiceQname(JaxWsUtils.getServiceQName(serviceInterface));
}
// handlers
if (serviceRef.getHandlerChains() == null && null != handlerChain && null != member) {
try {
final URL handlerFileURL = member.getDeclaringClass().getResource(handlerChain.file());
final HandlerChains handlerChains = ReadDescriptors.readHandlerChains(handlerFileURL);
serviceRef.setHandlerChains(handlerChains);
} catch (final Throwable e) {
throw new OpenEJBException("Unable to load handler chain file: " + handlerChain.file(), e);
}
}
}