User: chirino
Date: 01/07/10 19:53:50
Modified: src/main/org/jbossmq/referenceable ObjectRefAddr.java
SpyConnectionFactoryObjectFactory.java
Log:
The objects are now serialized using a MarshalledObject and a ByteArrayOutputStream
This should help us work on more JNDI providers
Revision Changes Path
1.3 +44 -7 jbossmq/src/main/org/jbossmq/referenceable/ObjectRefAddr.java
Index: ObjectRefAddr.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmq/src/main/org/jbossmq/referenceable/ObjectRefAddr.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ObjectRefAddr.java 2001/03/02 01:12:59 1.2
+++ ObjectRefAddr.java 2001/07/11 02:53:50 1.3
@@ -8,31 +8,68 @@
import javax.naming.RefAddr;
+import java.rmi.MarshalledObject;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayInputStream;
+import java.lang.ref.Reference;
+import java.io.ObjectInputStream;
+import java.io.ByteArrayOutputStream;
+
/**
* This class is used to store a serializable object in
* a RefAddr object.
*
- * @author Hiram Chirino ([EMAIL PROTECTED])
+ * @author Scott M Stark ([EMAIL PROTECTED])
+ * @author Hiram Chirino ([EMAIL PROTECTED])
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class ObjectRefAddr extends RefAddr {
+
- private Object content;
/**
* ObjectRefAddr constructor comment.
* @param arg1 java.lang.String
*/
- public ObjectRefAddr(String arg1, Object content) {
- super(arg1);
- this.content = content;
+ public ObjectRefAddr(String arg1, Object content) throws
javax.naming.NamingException {
+ super(arg1);
+
+ try {
+ java.rmi.MarshalledObject mo= new MarshalledObject(content);
+ ByteArrayOutputStream baos= new ByteArrayOutputStream();
+ ObjectOutputStream oos= new ObjectOutputStream(baos);
+ oos.writeObject(mo);
+ serialContent= baos.toByteArray();
+ } catch ( java.io.IOException e ) {
+ e.printStackTrace();
+ throw new javax.naming.NamingException("Could not create a
reference: "+e.getMessage());
+ }
}
/**
* getContent method comment.
*/
public Object getContent() {
- return content;
+ return serialContent;
+ }
+
+ private byte[] serialContent;
+
+ /**
+ * getContent method comment.
+ */
+ static public Object extractObjectRefFrom(javax.naming.Reference ref, String
arg1) throws javax.naming.NamingException {
+
+ try {
+ byte[] serialContent= (byte[]) ref.get(arg1).getContent();
+ ByteArrayInputStream bais= new ByteArrayInputStream(serialContent);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ java.rmi.MarshalledObject mo= (java.rmi.MarshalledObject)
ois.readObject();
+ return mo.get();
+ } catch ( Exception e ) {
+ throw new javax.naming.NamingException("Invalid reference.
Error: "+e.getMessage());
+ }
+
}
}
1.3 +13 -28
jbossmq/src/main/org/jbossmq/referenceable/SpyConnectionFactoryObjectFactory.java
Index: SpyConnectionFactoryObjectFactory.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmq/src/main/org/jbossmq/referenceable/SpyConnectionFactoryObjectFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SpyConnectionFactoryObjectFactory.java 2001/03/02 01:12:59 1.2
+++ SpyConnectionFactoryObjectFactory.java 2001/07/11 02:53:50 1.3
@@ -11,9 +11,11 @@
-import org.jbossmq.distributed.interfaces.DistributedConnectionFactory;
+
import org.jbossmq.Log;
+import org.jbossmq.GenericConnectionFactory;
+
/**
* This class is used to create instances of of:
* SpyTopicConnectionFactory
@@ -24,15 +26,10 @@
*
* @author Hiram Chirino ([EMAIL PROTECTED])
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class SpyConnectionFactoryObjectFactory implements
javax.naming.spi.ObjectFactory {
- /**
- * SpyTopicObjectFactory constructor.
- */
- public SpyConnectionFactoryObjectFactory() {
- super();
- }
+
/**
* getObjectInstance method.
@@ -41,32 +38,20 @@
throws java.lang.Exception {
Log.log("SpyConnectionFactoryObjectFactory->getObjectInstance()");
-
try {
javax.naming.Reference ref = (javax.naming.Reference)
reference;
- if
(ref.getClassName().equals("org.jbossmq.SpyTopicConnectionFactory")) {
-
- DistributedConnectionFactory dcf =
(DistributedConnectionFactory) ref.get("DCF").getContent();
- return new org.jbossmq.SpyTopicConnectionFactory(dcf);
-
- } else if
(ref.getClassName().equals("org.jbossmq.SpyQueueConnectionFactory")) {
-
- DistributedConnectionFactory dcf =
(DistributedConnectionFactory) ref.get("DCF").getContent();
- return new org.jbossmq.SpyQueueConnectionFactory(dcf);
-
- } else if
(ref.getClassName().equals("org.jbossmq.SpyXATopicConnectionFactory")) {
-
- DistributedConnectionFactory dcf =
(DistributedConnectionFactory) ref.get("DCF").getContent();
- return new
org.jbossmq.SpyXATopicConnectionFactory(dcf);
-
- } else if
(ref.getClassName().equals("org.jbossmq.SpyXAQueueConnectionFactory")) {
-
- DistributedConnectionFactory dcf =
(DistributedConnectionFactory) ref.get("DCF").getContent();
- return new
org.jbossmq.SpyXAQueueConnectionFactory(dcf);
+ GenericConnectionFactory dcf = (GenericConnectionFactory)
+ ObjectRefAddr.extractObjectRefFrom( ref, "DCF");
+
+ if
(ref.getClassName().equals("org.jbossmq.SpyConnectionFactory")) {
+ return new org.jbossmq.SpyConnectionFactory(dcf);
+ } else if
(ref.getClassName().equals("org.jbossmq.SpyXAConnectionFactory")) {
+ return new org.jbossmq.SpyXAConnectionFactory(dcf);
}
} catch (Throwable ignore) {
+ ignore.printStackTrace();
// This method should not throw an exception since
// It would prevent another ObjectFactory from attempting
// to create an instance of the object.
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development