// Determine if a business interface is defined here
boolean hasBusiness = this.hasBusiness(name, referenceAddresses);
// Cast
SessionSpecProxyFactory sFactory = null;
try
{
sFactory = (SessionSpecProxyFactory) this.getProxyFactoryClass().cast(factory);
}
catch (ClassCastException cce)
{
throw new RuntimeException(ProxyFactory.class.getSimpleName() + " used in "
+ SessionProxyObjectFactory.class.getSimpleName() + " must be of type "
+ SessionSpecProxyFactory.class.getName() + " but was instead " + factory, cce);
}
// If home and business are bound together
if (hasHome && hasBusiness)
{
proxy = sFactory.createProxyDefault();
log.debug("Created Proxy for both EJB2.x Home and EJB3 Business Interfaces.");
}
// If bound to home only
else if (hasHome)
{
proxy = sFactory.createProxyHome();
log.debug("Created Proxy for EJB2.x Home Interface(s)");
}
// If bound to business only
else if (hasBusiness)
{
// Initialize
String type = null;
// If local
if (this.hasLocalBusiness(referenceAddresses))
{
type = ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_LOCAL;
}
// If remote
else
{
type = ProxyFactoryReferenceAddressTypes.REF_ADDR_TYPE_PROXY_BUSINESS_INTERFACE_REMOTE;
}
// Get all business interfaces to be used
List<String> businessInterfaces = referenceAddresses.get(type);
// If only one is defined
if (businessInterfaces.size() == 1)
{
// Obtain a proxy specific to this business interface
String businessInterface = businessInterfaces.get(0);
proxy = sFactory.createProxyBusiness(businessInterface);
log.debug("Created Proxy of type " + proxy.getClass().getSimpleName() + " for EJB3 Business Interface: "
+ businessInterface);
// Ensure the proxy is visible to the TCL
proxy = this.redefineProxyInTcl(proxy);
}
else
{
// Use a general-purpose proxy for all business interfaces
proxy = sFactory.createProxyDefault();
log.debug("Created Proxy of type " + proxy.getClass().getSimpleName() + " for EJB3 Business Interfaces: "
+ businessInterfaces);
}
}
// No valid type is bound here