}
}
public static void addEJBRefs(EARContext earContext, URI uri, EjbRefType[] ejbRefs, Map ejbRefMap, ClassLoader cl, ComponentContextBuilder builder) throws DeploymentException {
RefContext refContext = earContext.getRefContext();
J2eeContext j2eeContext = earContext.getJ2eeContext();
for (int i = 0; i < ejbRefs.length; i++) {
EjbRefType ejbRef = ejbRefs[i];
String ejbRefName = getStringValue(ejbRef.getEjbRefName());
String remote = getStringValue(ejbRef.getRemote());
assureEJBObjectInterface(remote, cl);
String home = getStringValue(ejbRef.getHome());
assureEJBHomeInterface(home, cl);
Reference ejbReference;
boolean isSession = "Session".equals(getStringValue(ejbRef.getEjbRefType()));
if (isSession && remote.equals("javax.management.j2ee.Management") && home.equals("javax.management.j2ee.ManagementHome")) {
String mejbName = refContext.getMEJBName();
ejbReference = refContext.getEJBRemoteRef(mejbName, isSession, home, remote);
} else {
String ejbLink = null;
GerEjbRefType remoteRef = (GerEjbRefType) ejbRefMap.get(ejbRefName);
if (remoteRef != null && remoteRef.isSetEjbLink()) {
ejbLink = remoteRef.getEjbLink();
} else if (ejbRef.isSetEjbLink()) {
ejbLink = getStringValue(ejbRef.getEjbLink());
}
if (ejbLink != null) {
ejbReference = refContext.getEJBRemoteRef(uri, ejbLink, isSession, home, remote);
} else if (remoteRef != null) {
if (remoteRef.isSetTargetName()) {
ejbReference = refContext.getEJBRemoteRef(getStringValue(remoteRef.getTargetName()), isSession, home, remote);
} else if (remoteRef.isSetNsCorbaloc()) {
try {
ObjectName cssBean;
if (remoteRef.isSetCssName()) {
cssBean = ObjectName.getInstance(getStringValue(remoteRef.getCssName()));
} else if (remoteRef.isSetCssLink()) {
String cssLink = remoteRef.getCssLink().trim();
cssBean = refContext.locateComponent(cssLink, NameFactory.CORBA_CSS, j2eeContext, earContext, "css gbean");
} else {
GerCssType css = remoteRef.getCss();
cssBean = NameFactory.getComponentName(getStringValue(css.getDomain()),
getStringValue(css.getServer()),
getStringValue(css.getApplication()),
getStringValue(css.getModule()),
getStringValue(css.getName()),
getStringValue(NameFactory.CORBA_CSS),
j2eeContext);
}
ejbReference = refContext.getCORBARemoteRef(new URI(getStringValue(remoteRef.getNsCorbaloc())),
getStringValue(remoteRef.getName()),
ObjectName.getInstance(cssBean),
home);
} catch (URISyntaxException e) {
throw new DeploymentException("Could not construct CORBA NameServer URI: " + remoteRef.getNsCorbaloc(), e);
} catch (MalformedObjectNameException e) {
throw new DeploymentException("Could not construct CSS container name: " + remoteRef.getCssName(), e);
}
} else {
String containerId = null;
try {
containerId = NameFactory.getEjbComponentNameString(getStringValue(remoteRef.getDomain()),
getStringValue(remoteRef.getServer()),
getStringValue(remoteRef.getApplication()),
getStringValue(remoteRef.getModule()),
getStringValue(remoteRef.getName()),
getStringValue(remoteRef.getType()),
j2eeContext);
} catch (MalformedObjectNameException e) {
throw new DeploymentException("Could not construct ejb object name: " + remoteRef.getName(), e);
}
ejbReference = refContext.getEJBRemoteRef(containerId, isSession, home, remote);
}
} else {
ejbReference = refContext.getImplicitEJBRemoteRef(uri, ejbRefName, isSession, home, remote);
}
}
builder.bind(ejbRefName, ejbReference);
}
}