if (shouldReturn) {
return;
}
}
final EjbRef ejbRef = new EjbRef();
// This is how we deal with the fact that we don't know
// whether to use an EjbLocalRef or EjbRef (remote).
// We flag it uknown and let the linking code take care of
// figuring out what to do with it.
ejbRef.setRefType(EjbReference.Type.UNKNOWN);
// Get the ejb-ref-name
String refName = ejb.name();
if (refName.length() == 0) {
refName = member.getDeclaringClass().getName() + "/" + member.getName();
}
//TODO can refName actually be null?
ejbRef.setEjbRefName(normalize(refName));
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());
ejbRef.getInjectionTarget().add(target);
}
Class<?> interfce = ejb.beanInterface();
if (interfce.equals(Object.class)) {
interfce = member == null ? null : member.getType();
}
final boolean localbean = isKnownLocalBean(interfce);
final boolean dynamicallyImplemented = DynamicProxyImplFactory.isKnownDynamicallyImplemented(interfce);
if (!localbean && interfce != null && !isValidEjbInterface(name, interfce, ejbRef.getName())) {
return;
}
if (interfce != null && !interfce.equals(Object.class)) {
if (EJBHome.class.isAssignableFrom(interfce)) {
ejbRef.setHome(interfce.getName());
final Method[] methods = interfce.getMethods();
for (final Method method : methods) {
if (method.getName().startsWith("create")) {
ejbRef.setRemote(method.getReturnType().getName());
break;
}
}
ejbRef.setRefType(EjbReference.Type.REMOTE);
} else if (EJBLocalHome.class.isAssignableFrom(interfce)) {
ejbRef.setHome(interfce.getName());
final Method[] methods = interfce.getMethods();
for (final Method method : methods) {
if (method.getName().startsWith("create")) {
ejbRef.setRemote(method.getReturnType().getName());
break;
}
}
ejbRef.setRefType(EjbReference.Type.LOCAL);
} else if (localbean) {
ejbRef.setRefType(EjbReference.Type.LOCAL);
ejbRef.setRemote(interfce.getName());
} else if (dynamicallyImplemented) {
ejbRef.setRefType(EjbReference.Type.LOCAL);
ejbRef.setRemote(interfce.getName());
} else {
ejbRef.setRemote(interfce.getName());
if (interfce.getAnnotation(Local.class) != null) {
ejbRef.setRefType(EjbReference.Type.LOCAL);
} else if (interfce.getAnnotation(Remote.class) != null) {
ejbRef.setRefType(EjbReference.Type.REMOTE);
}
}
}
// Set the ejb-link, if any
String ejbName = ejb.beanName();
if (ejbName.equals("")) {
ejbName = null;
}
ejbRef.setEjbLink(ejbName);
// Set the mappedName, if any
String mappedName = ejb.mappedName();
if (mappedName.equals("")) {
mappedName = null;
}
ejbRef.setMappedName(mappedName);
// Set lookup name, if any
String lookupName = getLookupName(ejb);
if (lookupName.equals("")) {
lookupName = null;
}
ejbRef.setLookupName(lookupName);
final Map<String, EjbRef> remoteRefs = consumer.getEjbRefMap();
if (remoteRefs.containsKey(ejbRef.getName())) {
final EjbRef ref = remoteRefs.get(ejbRef.getName());
if (ref.getRemote() == null) {
ref.setRemote(ejbRef.getRemote());
}
if (ref.getHome() == null) {
ref.setHome(ejbRef.getHome());
}
if (ref.getMappedName() == null) {
ref.setMappedName(ejbRef.getMappedName());
}
ref.getInjectionTarget().addAll(ejbRef.getInjectionTarget());
return;
}
final Map<String, EjbLocalRef> localRefs = consumer.getEjbLocalRefMap();
if (localRefs.containsKey(ejbRef.getName())) {
final EjbLocalRef ejbLocalRef = new EjbLocalRef(ejbRef);
final EjbLocalRef ref = localRefs.get(ejbLocalRef.getName());
if (ref.getLocal() == null) {
ref.setLocal(ejbLocalRef.getLocal());
}
if (ref.getLocalHome() == null) {
ref.setLocalHome(ejbLocalRef.getLocalHome());
}
if (ref.getMappedName() == null) {
ref.setMappedName(ejbLocalRef.getMappedName());
}
ref.getInjectionTarget().addAll(ejbLocalRef.getInjectionTarget());
return;
}
switch (ejbRef.getRefType()) {
case UNKNOWN: