下面列出了怎么用javax.ejb.EJBHome的API类实例代码及写法,或者点击链接到github查看源代码。
public void Xtest03_copyHandleBySerialize() {
try {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(ejbHomeHandle);
oos.flush();
oos.close();
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
final ObjectInputStream ois = new ObjectInputStream(bais);
final HomeHandle copy = (HomeHandle) ois.readObject();
assertNotNull("The HomeHandle copy is null", copy);
final EJBHome home = copy.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void Xtest39_returnEJBHomeArray() {
try {
final EncCmpHome[] expected = new EncCmpHome[3];
for (int i = 0; i < expected.length; i++) {
final Object obj = initialContext.lookup("client/tests/entity/cmp/EncBean");
expected[i] = (EncCmpHome) obj;
assertNotNull("The EJBHome returned from JNDI is null", expected[i]);
}
final EJBHome[] actual = ejbObject.returnEJBHomeArray(expected);
assertNotNull("The EJBHome array returned is null", actual);
assertEquals(expected.length, actual.length);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public ProxyFactory(final BeanContext beanContext) {
this.beanContext = beanContext;
keyGenerator = beanContext.getKeyGenerator();
remoteInterface = beanContext.getRemoteInterface();
if (remoteInterface != null) {
final EJBHome homeProxy = beanContext.getEJBHome();
remoteHandler = (EntityEjbHomeHandler) ProxyManager.getInvocationHandler(homeProxy);
} else {
remoteHandler = null;
}
localInterface = beanContext.getLocalInterface();
if (localInterface != null) {
final EJBLocalHome localHomeProxy = beanContext.getEJBLocalHome();
localHandler = (EntityEjbHomeHandler) ProxyManager.getInvocationHandler(localHomeProxy);
} else {
localHandler = null;
}
}
public void Xtest03_copyHandleBySerialize() {
try {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(ejbHomeHandle);
oos.flush();
oos.close();
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
final ObjectInputStream ois = new ObjectInputStream(bais);
final HomeHandle copy = (HomeHandle) ois.readObject();
assertNotNull("The HomeHandle copy is null", copy);
final EJBHome home = copy.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void Xtest03_copyHandleBySerialize() {
try {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(ejbHomeHandle);
oos.flush();
oos.close();
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
final ObjectInputStream ois = new ObjectInputStream(bais);
final HomeHandle copy = (HomeHandle) ois.readObject();
assertNotNull("The HomeHandle copy is null", copy);
final EJBHome home = copy.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test39_returnEJBHomeArray() {
try {
final EncCmpHome[] expected = new EncCmpHome[3];
for (int i = 0; i < expected.length; i++) {
final Object obj = initialContext.lookup("client/tests/entity/cmp/EncBean");
expected[i] = (EncCmpHome) obj;
assertNotNull("The EJBHome returned from JNDI is null", expected[i]);
}
final EJBHome[] actual = ejbObject.returnEJBHomeArray(expected);
assertNotNull("The EJBHome array returned is null", actual);
assertEquals(expected.length, actual.length);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
/**
* Check for EJB3-style home object that serves as EJB component directly.
*/
@Override
protected Method getCreateMethod(Object home) throws EjbAccessException {
if (this.homeAsComponent) {
return null;
}
if (!(home instanceof EJBHome)) {
// An EJB3 Session Bean...
this.homeAsComponent = true;
return null;
}
return super.getCreateMethod(home);
}
/**
* Check for EJB3-style home object that serves as EJB component directly.
*/
@Override
protected Method getCreateMethod(Object home) throws EjbAccessException {
if (this.homeAsComponent) {
return null;
}
if (!(home instanceof EJBHome)) {
// An EJB3 Session Bean...
this.homeAsComponent = true;
return null;
}
return super.getCreateMethod(home);
}
/**
* Check for EJB3-style home object that serves as EJB component directly.
*/
@Override
protected Method getCreateMethod(Object home) throws EjbAccessException {
if (this.homeAsComponent) {
return null;
}
if (!(home instanceof EJBHome)) {
// An EJB3 Session Bean...
this.homeAsComponent = true;
return null;
}
return super.getCreateMethod(home);
}
public EJBInvoker(EJBHome home) {
this.home = home;
try {
if (!home.getEJBMetaData().isSession() || !home.getEJBMetaData().isStatelessSession()) {
throw new IllegalArgumentException("home must be for a stateless session bean");
}
createMethod = home.getClass().getMethod("create", new Class[0]);
} catch (Exception ex) {
throw new IllegalArgumentException("Unable to initialize invoker: " + ex);
}
}
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
final byte version = in.readByte(); // future use
homeClass = (Class) in.readObject();
remoteClass = (Class) in.readObject();
keyClass = (Class) in.readObject();
ejbHomeProxy = (EJBHome) in.readObject();
type = in.readByte();
deploymentID = in.readUTF();
deploymentCode = in.readShort();
for (int i = in.readShort(); i > 0; i--) {
businessClasses.add((Class) in.readObject());
}
if (businessClasses.size() > 0) {
primaryKey = in.readObject();
}
if (version > 2) {
mainInterface = (Class) in.readObject();
}
if (version > 1) {
final byte typeIndex = in.readByte();
interfaceType = InterfaceType.values()[typeIndex];
}
for (int i = in.readInt(); i > 0; i--) {
asynchronousMethods.add((String) in.readObject());
}
final boolean hasProperties = in.readBoolean();
if (hasProperties) {
final int bufferLength = in.readInt();
final byte[] buffer = new byte[bufferLength];
in.read(buffer);
final ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
properties.load(bais);
}
}
public EJBInvocationHandler(final EJBMetaDataImpl ejb, final ServerMetaData server, final ClientMetaData client, final JNDIContext.AuthenticationInfo auth) {
this.ejb = ejb;
this.server = server;
this.client = client;
this.authenticationInfo = auth;
final Class remoteInterface = ejb.getRemoteInterfaceClass();
remote = remoteInterface != null && (EJBObject.class.isAssignableFrom(remoteInterface) || EJBHome.class.isAssignableFrom(remoteInterface));
}
public void test01_getEJBHome() {
try {
final EJBHome home = ejbMetaData.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test04_getEjbHome() {
try {
final EJBHome home = ejbObject.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test01_getEJBHome() {
try {
final EJBHome home = ejbMetaData.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void Xtest02_copyHandleByMarshalledObject() {
try {
final MarshalledObject obj = new MarshalledObject(ejbHomeHandle);
final HomeHandle copy = (HomeHandle) obj.get();
assertNotNull("The HomeHandle copy is null", copy);
final EJBHome home = copy.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test01_getEJBHome() {
try {
final EJBHome home = ejbMetaData.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test01_getEJBHome() {
try {
final EJBHome home = ejbMetaData.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test04_getEjbHome() {
try {
final EJBHome home = ejbObject.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test04_getEjbHome() {
try {
final EJBHome home = ejbObject.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void Xtest02_copyHandleByMarshalledObject() {
try {
final MarshalledObject obj = new MarshalledObject(ejbHomeHandle);
final HomeHandle copy = (HomeHandle) obj.get();
assertNotNull("The HomeHandle copy is null", copy);
final EJBHome home = copy.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void Xtest02_copyHandleByMarshalledObject() {
try {
final MarshalledObject obj = new MarshalledObject(ejbHomeHandle);
final HomeHandle copy = (HomeHandle) obj.get();
assertNotNull("The HomeHandle copy is null", copy);
final EJBHome home = copy.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test01_getEJBHome() {
try {
final EJBHome home = ejbHomeHandle.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test04_getEjbHome() {
try {
final EJBHome home = ejbObject.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test01_getEJBHome() {
try {
final EJBHome home = ejbHomeHandle.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test04_getEjbHome() {
try {
final EJBHome home = ejbObject.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test01_getEJBHome() {
try {
final EJBHome home = ejbMetaData.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test01_getEJBHome() {
try {
final EJBHome home = ejbMetaData.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test01_getEJBHome() {
try {
final EJBHome home = ejbMetaData.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
public void test01_getEJBHome() {
try {
final EJBHome home = ejbHomeHandle.getEJBHome();
assertNotNull("The EJBHome is null", home);
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}