User: reverbel
Date: 01/08/14 14:25:41
Added: iiop/src/main/org/jboss/ejb/plugins/iiop
CDRStreamReader.java CDRStreamWriter.java
EJBMetaDataImpl.java HomeHandleImpl.java
RmiIdlUtil.java
Log:
Preliminary version of IIOP container invoker.
Revision Changes Path
1.1
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/CDRStreamReader.java
Index: CDRStreamReader.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.iiop;
import org.omg.CORBA_2_3.portable.InputStream;
/**
* Interface of an object that knows how to unmarshal a Java basic type or
* object from a CDR input stream. Implementations of this interface are
* specialized for particular types: an <code>IntReader</code> is a
* <code>CDRStreamReader</code> that knows how to unmarshal <code>int</code>s,
* a <code>LongReader</code> is a <code>CDRStreamReader</code> that knows how
* to unmarshal <code>long</code>s, and so on.
*/
public interface CDRStreamReader
{
/**
* Unmarshals a Java basic data type or object from a CDR input stream.
*
* @param in the input stream
* @return a basic data type (within a suitable wrapper instance) or
* object unmarshalled from the stream
*/
Object read(InputStream in);
}
1.1
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/CDRStreamWriter.java
Index: CDRStreamWriter.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.iiop;
import org.omg.CORBA_2_3.portable.OutputStream;
/**
* Interface of an object that knows how to marshal a Java basic type or
* object into a CDR input stream. Implementations of this interface are
* specialized for particular types: an <code>IntWriter</code> is a
* <code>CDRStreamWriter</code> that knows how to marshal <code>int</code>s,
* a <code>LongWriter</code> is a <code>CDRStreamWriter</code> that knows how
* to marshal <code>long</code>s, and so on.
*/
public interface CDRStreamWriter
{
/**
* Marshals a Java basic data type or object into a CDR output stream.
*
* @param out the output stream
* @param obj the basic data type (within a suitable wrapper instance)
* or object to be marshalled
*/
void write(OutputStream out, Object obj);
}
1.1
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/EJBMetaDataImpl.java
Index: EJBMetaDataImpl.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.iiop;
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.HomeHandle;
import javax.ejb.EJBMetaData;
import javax.ejb.EJBHome;
import javax.ejb.EJBException;
/**
* An implementation of the EJBMetaData interface which allows a
* client to obtain the enterprise Bean's meta-data information.
*
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Francisco Reverbel</a>
*/
public class EJBMetaDataImpl
implements EJBMetaData, Serializable
{
// Attributes ----------------------------------------------------
private final Class remoteClass;
private final Class homeClass;
private final Class pkClass;
private final boolean session;
private final boolean statelessSession;
private final EJBHome home;
// Constructors --------------------------------------------------
/**
* Constructs an <code>EJBMetaDataImpl</code>.
*/
public EJBMetaDataImpl(Class remoteClass,
Class homeClass,
Class pkClass,
boolean session,
boolean statelessSession,
EJBHome home)
{
this.remoteClass = remoteClass;
this.homeClass = homeClass;
this.pkClass = pkClass;
this.session = session;
this.statelessSession = statelessSession;
this.home = home;
}
// EJBMetaData ---------------------------------------------------
/**
* Obtains the home interface of the enterprise Bean.
*/
public EJBHome getEJBHome() { return home; }
/**
* Obtains the <code>Class</code> object for the enterprise Bean's home
* interface.
*/
public Class getHomeInterfaceClass() { return homeClass; }
/**
* Obtains the <code>Class</code> object for the enterprise Bean's remote
* interface.
*/
public Class getRemoteInterfaceClass() { return remoteClass; }
/**
* Obtains the <code>Class</code> object for the enterprise Bean's primary
* key class.
*/
public Class getPrimaryKeyClass() { return pkClass; }
/**
* Tests if the enterprise Bean's type is "session".
*
* @return true if the type of the enterprise Bean is session bean.
*/
public boolean isSession() { return session; }
/**
* Tests if the enterprise Bean's type is "stateless session".
*
* @return true if the type of the enterprise Bean is stateless session.
*/
public boolean isStatelessSession() { return statelessSession; }
}
1.1
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/HomeHandleImpl.java
Index: HomeHandleImpl.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.iiop;
import java.rmi.RemoteException;
import java.util.Properties;
import javax.ejb.EJBHome;
import javax.ejb.HomeHandle;
import javax.rmi.PortableRemoteObject;
import org.omg.CORBA.ORB;
/**
* A CORBA-based EJB home handle implementation.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Francisco Reverbel</a>
* @version $Revision: 1.1 $
*/
public class HomeHandleImpl
implements HomeHandle
{
private static ORB orb;
static {
Properties props = System.getProperties();
orb = ORB.init(new String[0], props);
}
/**
* This handle encapsulates an stringfied CORBA reference for an
* <code>EJBHome</code>.
*/
private String ior;
/**
* Constructs a <code>HomeHandleImpl</code>.
*
* @param ior An stringfied CORBA reference for an <code>EJBHome</code>.
*/
public HomeHandleImpl(String ior)
{
this.ior = ior;
}
/**
* Constructs a <tt>HomeHandleImpl</tt>.
*
* @param home An <code>EJBHome</code>.
*/
public HomeHandleImpl(EJBHome home)
{
this.ior = orb.object_to_string((org.omg.CORBA.Object)home);
}
// Public --------------------------------------------------------
// Handle implementation -----------------------------------------
/**
* Obtains the <code>EJBHome</code> represented by this home handle.
*
* @return a reference to an <code>EJBHome</code>.
*
* @throws RemoteException
*/
public EJBHome getEJBHome()
throws RemoteException
{
try {
return (EJBHome)PortableRemoteObject.narrow(orb.string_to_object(ior),
EJBHome.class);
}
catch (Exception e) {
throw new RemoteException("Could not get EJBHome from HomeHandle");
}
}
}
1.1 contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/RmiIdlUtil.java
Index: RmiIdlUtil.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.iiop;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Iterator;
/**
* This class contains a bunch of methods taken from
* org.jboss.verifier.strategy.AbstractVerifier. There they are declared
* as instance methods. I copied them to this class and made them static here
* in order to call them as utility methods, without having to create a
* verifier instance,
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>
* @author Aaron Mulder ([EMAIL PROTECTED])
* @author Vinay Menon ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Francisco Reverbel</a>
* @version $Revision: 1.1 $
*/
public class RmiIdlUtil {
public static boolean hasLegalRMIIIOPArguments(Method method) {
Class[] params = method.getParameterTypes();
for (int i = 0; i < params.length; ++i)
if (!isRMIIIOPType(params[i]))
return false;
return true;
}
public static boolean hasLegalRMIIIOPReturnType(Method method) {
return isRMIIIOPType(method.getReturnType());
}
public static boolean hasLegalRMIIIOPExceptionTypes(Method method) {
/*
* All checked exception classes used in method declarations
* (other than java.rmi.RemoteException) MUST be conforming
* RMI/IDL exception types.
*
* Spec 28.2.3 (4)
*/
Iterator it = Arrays.asList(method.getExceptionTypes()).iterator();
while (it.hasNext()) {
Class exception = (Class)it.next();
if (!isRMIIDLExceptionType(exception))
return false;
}
return true;
}
/*
* checks if the method includes java.rmi.RemoteException or its
* subclass in its throws clause.
*/
public static boolean throwsRemoteException(Method method) {
Class[] exception = method.getExceptionTypes();
for (int i = 0; i < exception.length; ++i)
if (java.rmi.RemoteException.class.isAssignableFrom(exception[i]))
return true;
return false;
}
/*
* checks if a class's member (method, constructor or field) has a 'static'
* modifier.
*/
public static boolean isStatic(Member member) {
return (Modifier.isStatic(member.getModifiers()));
}
/*
* checks if the given class is declared as static (inner classes only)
*/
public static boolean isStatic(Class c) {
return (Modifier.isStatic(c.getModifiers()));
}
/*
* checks if a class's member (method, constructor or field) has a 'final'
* modifier.
*/
public static boolean isFinal(Member member) {
return (Modifier.isFinal(member.getModifiers()));
}
/*
* checks if the given class is declared as final
*/
public static boolean isFinal(Class c) {
return (Modifier.isFinal(c.getModifiers()));
}
/*
* checks if a class's memeber (method, constructor or field) has a 'public'
* modifier.
*/
public static boolean isPublic(Member member) {
return (Modifier.isPublic(member.getModifiers()));
}
/*
* checks if the given class is declared as public
*/
public static boolean isPublic(Class c) {
return (Modifier.isPublic(c.getModifiers()));
}
/**
* Checks whether all the fields in the class are declared as public.
*/
public static boolean isAllFieldsPublic(Class c) {
try {
Field list[] = c.getFields();
for(int i=0; i<list.length; i++)
if(!Modifier.isPublic(list[i].getModifiers()))
return false;
} catch(Exception e) {
return false;
}
return true;
}
/*
* checks if the given class is declared as abstract
*/
public static boolean isAbstract(Class c) {
return (Modifier.isAbstract(c.getModifiers()));
}
public static boolean isRMIIIOPType(Class type) {
/*
* Java Language to IDL Mapping
* ftp://ftp.omg.org/pub/docs/ptc/99-03-09.pdf
*
* A conforming RMI/IDL type is a Java type whose values
* may be transmitted across an RMI/IDL remote interface at
* run-time. A Java data type is a conforming RMI/IDL type
* if it is:
*
* - one of the Java primitive types (see Primitive Types on page 28-2).
* - a conforming remote interface (as defined in RMI/IDL Remote Interfaces
on page 28-2).
* - a conforming value type (as defined in RMI/IDL Value Types on page 28-4).
* - an array of conforming RMI/IDL types (see RMI/IDL Arrays on page 28-5).
* - a conforming exception type (see RMI/IDL Exception Types on page 28-5).
* - a conforming CORBA object reference type (see CORBA Object Reference
Types on page 28-6).
* - a conforming IDL entity type see IDL Entity Types on page 28-6).
*/
/*
* Primitive types.
*
* Spec 28.2.2
*/
if (type.isPrimitive())
return true;
/*
* Conforming array.
*
* Spec 28.2.5
*/
if (type.isArray())
return isRMIIIOPType(type.getComponentType());
/*
* Conforming CORBA reference type
*
* Spec 28.2.7
*/
if (org.omg.CORBA.Object.class.isAssignableFrom(type))
return true;
/*
* Conforming IDL Entity type
*
* Spec 28.2.8
*/
if (org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(type))
return true;
/*
* Conforming remote interface.
*
* Spec 28.2.3
*/
if (isRMIIDLRemoteInterface(type))
return true;
/*
* Conforming exception.
*
* Spec 28.2.6
*/
if (isRMIIDLExceptionType(type))
return true;
/*
* Conforming value type.
*
* Spec 28.2.4
*/
if (isRMIIDLValueType(type))
return true;
return false;
}
public static boolean isRMIIDLRemoteInterface(Class type) {
/*
* If does not implement java.rmi.Remote, cannot be valid RMI-IDL
* remote interface.
*/
if (!java.rmi.Remote.class.isAssignableFrom(type))
return false;
Iterator methodIterator = Arrays.asList(type.getMethods()).iterator();
while (methodIterator.hasNext()) {
Method m = (Method)methodIterator.next();
/*
* All methods in the interface MUST throw
* java.rmi.RemoteException or its subclass.
*
* Spec 28.2.3 (2)
*/
if (!throwsRemoteException(m)) {
return false;
}
/*
* All checked exception classes used in method declarations
* (other than java.rmi.RemoteException) MUST be conforming
* RMI/IDL exception types.
*
* Spec 28.2.3 (4)
*/
Iterator it = Arrays.asList(m.getExceptionTypes()).iterator();
while (it.hasNext()) {
Class exception = (Class)it.next();
if (!isRMIIDLExceptionType(exception))
return false;
}
}
/*
* The constant values defined in the interface MUST be
* compile-time types of RMI/IDL primitive types or String.
*
* Spec 28.2.3 (6)
*/
Iterator fieldIterator = Arrays.asList(type.getFields()).iterator();
while (fieldIterator.hasNext()) {
Field f = (Field)fieldIterator.next();
if (f.getType().isPrimitive())
continue;
if (f.getType().equals(java.lang.String.class))
continue;
return false;
}
return true;
}
public static boolean isRMIIDLExceptionType(Class type) {
/*
* A conforming RMI/IDL Exception class MUST be a checked
* exception class and MUST be a valid RMI/IDL value type.
*
* Spec 28.2.6
*/
if (!Throwable.class.isAssignableFrom(type))
return false;
if (Error.class.isAssignableFrom(type))
return false;
if (RuntimeException.class.isAssignableFrom(type))
return false;
if (!isRMIIDLValueType(type))
return false;
return true;
}
public static boolean isRMIIDLValueType(Class type) {
/*
* A value type MUST NOT either directly or indirectly implement the
* java.rmi.Remote interface.
*
* Spec 28.2.4 (4)
*/
if (java.rmi.Remote.class.isAssignableFrom(type))
return false;
/*
* If class is a non-static inner class then its containing class must
* also be a conforming RMI/IDL value type.
*
* Spec 2.8.4 (3)
*/
if (type.getDeclaringClass() != null && isStatic(type))
if (!isRMIIDLValueType(type.getDeclaringClass()))
return false;
return true;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development