Example usage for javax.ejb EJBHome getClass

List of usage examples for javax.ejb EJBHome getClass

Introduction

In this page you can find the example usage for javax.ejb EJBHome getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.wso2.carbon.custom.connector.EJBFactory.java

public Object getEJBObject(MessageContext ctx, String jndiName) {
    EJB2Init ejb2Init = new EJB2Init();
    InitialContext context;// www  . j av  a  2 s . c o  m
    Object obj = null;
    try {
        context = ejb2Init.getInitialContext();
        obj = context.lookup(getParameter(ctx, jndiName).toString());
    } catch (NoClassDefFoundError e) {
        handleException("Failed lookup because of ", ctx);
    } catch (NamingException e) {
        handleException("Failed lookup because of ", e, ctx);
    }
    EJBHome beanHome = (EJBHome) javax.rmi.PortableRemoteObject.narrow(obj, EJBHome.class);
    Method m = null;
    try {
        m = beanHome.getClass().getDeclaredMethod(EJBConstance.CREATE);
    } catch (NoSuchMethodException e) {
        handleException("There is no create method ", ctx);
    }
    Object ejbObj = null;
    try {
        if (m != null) {
            ejbObj = m.invoke(beanHome);
        } else {
            handleException("ejb home is missing", ctx);
        }
    } catch (IllegalAccessException e) {
        handleException("", e, ctx);
    } catch (InvocationTargetException e) {
        handleException("", e, ctx);
    }
    return ejbObj;
}

From source file:org.wso2.carbon.custom.connector.EJBUtil.java

/**
 * @param messageContext messageContext//w ww  . java 2s  .  c om
 * @param jndiName       jndi name
 * @return ejb remote object
 */
public static Object getEJBObject(MessageContext messageContext, String jndiName) {
    Object ejbObject = null;
    try {
        InitialContext context = new InitialContext(
                (Properties) messageContext.getProperty(EJBConstants.JNDI_PROPERTIES));
        Object obj = context.lookup(getParameter(messageContext, jndiName).toString());
        EJBHome ejbHome = (EJBHome) PortableRemoteObject.narrow(obj, EJBHome.class);
        Method method = ejbHome.getClass().getDeclaredMethod(EJBConstants.CREATE);
        if (method != null) {
            ejbObject = method.invoke(ejbHome);
        } else
            handleException("ejb home is missing ");
    } catch (IllegalAccessException e) {
        handleException("Failed to get ejb Object because of IllegalAccessException ", e);
    } catch (InvocationTargetException e) {
        handleException("Failed to get ejb Object because of InvocationTargetException ", e);
    } catch (NoSuchMethodException e) {
        handleException("Failed lookup because of create method not exist " + e.getMessage());
    } catch (NamingException e) {
        handleException("Failed lookup because of NamingException ", e);
    }
    return ejbObject;
}