You are viewing a plain text version of this content. The canonical link for it is here.
Posted to yoko-commits@incubator.apache.org by kr...@apache.org on 2006/04/18 11:21:54 UTC

svn commit: r394918 [2/2] - in /incubator/yoko/trunk/orb/src/main: generated-java/org/omg/SendingContext/ generated-java/org/omg/SendingContext/CodeBasePackage/ java/org/apache/yoko/orb/CORBA/ java/org/apache/yoko/orb/OB/

Modified: incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/CORBA/InputStream.java
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/CORBA/InputStream.java?rev=394918&r1=394917&r2=394918&view=diff
==============================================================================
--- incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/CORBA/InputStream.java (original)
+++ incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/CORBA/InputStream.java Tue Apr 18 04:21:49 2006
@@ -11,6 +11,8 @@
 
 package org.apache.yoko.orb.CORBA;
 
+import org.omg.SendingContext.CodeBase;
+
 final public class InputStream extends org.omg.CORBA_2_3.portable.InputStream {
     org.apache.yoko.orb.OB.ORBInstance orbInstance_;
 
@@ -44,6 +46,10 @@
 
     private boolean wCharConversionRequired_;
 
+	private CodeBase sendingContextRuntime_;
+
+	private String codebase_;
+
     // ------------------------------------------------------------------
     // Private and protected members
     // ------------------------------------------------------------------
@@ -1981,4 +1987,20 @@
     public void _OB_remarshalValue(org.omg.CORBA.TypeCode tc, OutputStream out) {
         valueReader().remarshalValue(tc, out);
     }
+
+    public void __setSendingContextRuntime(org.omg.SendingContext.CodeBase runtime) {
+    		sendingContextRuntime_ = runtime;
+    }
+    
+	public org.omg.SendingContext.CodeBase __getSendingContextRuntime() {
+		return sendingContextRuntime_;
+	}
+
+	public void __setCodeBase(String codebase) {
+		this.codebase_ = codebase;
+	}
+	
+	public String __getCodeBase() {
+		return codebase_;
+	}
 }

Modified: incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/CORBA/OutputStream.java
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/CORBA/OutputStream.java?rev=394918&r1=394917&r2=394918&view=diff
==============================================================================
--- incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/CORBA/OutputStream.java (original)
+++ incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/CORBA/OutputStream.java Tue Apr 18 04:21:49 2006
@@ -1863,7 +1863,7 @@
     }
 
     public void _OB_beginValue(int tag, String[] ids, boolean chunked) {
-        valueWriter().beginValue(tag, ids, chunked);
+        valueWriter().beginValue(tag, ids, null, chunked);
     }
 
     public void _OB_endValue() {

Added: incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/CodeBaseProxy.java
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/CodeBaseProxy.java?rev=394918&view=auto
==============================================================================
--- incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/CodeBaseProxy.java (added)
+++ incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/CodeBaseProxy.java Tue Apr 18 04:21:49 2006
@@ -0,0 +1,119 @@
+// **********************************************************************
+//
+// Copyright (c) 2006
+// Trifork
+//
+// All Rights Reserved
+//
+// Licensed to apache under Apache 2.0 License - 2006
+// **********************************************************************
+package org.apache.yoko.orb.OB;
+
+import org.apache.yoko.orb.CORBA.InputStream;
+import org.apache.yoko.orb.OCI.Buffer;
+import org.omg.CORBA.BAD_PARAM;
+import org.omg.CORBA.LocalObject;
+import org.omg.CORBA.Repository;
+import org.omg.CORBA.ValueDefPackage.FullValueDescription;
+import org.omg.CORBA.portable.ObjectImpl;
+import org.omg.IOP.ServiceContext;
+import org.omg.SendingContext.CodeBase;
+
+public class CodeBaseProxy extends LocalObject implements CodeBase {
+
+    final ORBInstance orbInstance_;
+    ServiceContext ctx;
+    CodeBase codebase;
+
+    CodeBaseProxy(ORBInstance orb, ServiceContext ctx) {
+
+        if (ctx.context_id != org.omg.IOP.SendingContextRunTime.value) {
+        		// TODO: add minor code?
+            throw new BAD_PARAM();
+        }
+
+        this.orbInstance_ = orb;
+        this.ctx = ctx;
+    }
+
+    /* (non-Javadoc)
+     * @see org.omg.SendingContext.CodeBaseOperations#implementation(java.lang.String)
+     */
+    public String implementation(String arg0) {
+        return getCodeBase(orbInstance_).implementation(arg0);
+    }
+
+    /* (non-Javadoc)
+     * @see org.omg.SendingContext.CodeBaseOperations#implementations(java.lang.String[])
+     */
+    public String[] implementations(String[] arg0) {
+        return getCodeBase(orbInstance_).implementations(arg0);
+    }
+
+    /* (non-Javadoc)
+     * @see org.omg.SendingContext.CodeBaseOperations#bases(java.lang.String)
+     */
+    public String[] bases(String arg0) {
+        return getCodeBase(orbInstance_).bases(arg0);
+    }
+
+    /* (non-Javadoc)
+     * @see org.omg.SendingContext.CodeBaseOperations#get_ir()
+     */
+    public Repository get_ir() {
+        return getCodeBase(orbInstance_).get_ir();
+    }
+
+    /* (non-Javadoc)
+     * @see org.omg.SendingContext.CodeBaseOperations#meta(java.lang.String)
+     */
+    public FullValueDescription meta(String arg0) {
+        return getCodeBase(orbInstance_).meta(arg0);
+    }
+
+    /* (non-Javadoc)
+     * @see org.omg.SendingContext.CodeBaseOperations#metas(java.lang.String)
+     */
+    public FullValueDescription[] metas(String arg0) {
+        return getCodeBase(orbInstance_).metas(arg0);
+    }
+
+    
+    private CodeBase getCodeBase(ORBInstance orb) {
+        
+        if (codebase == null || getorb(codebase) != orb.getORB()) {
+        		
+            byte[] coct = ctx.context_data;
+            Buffer buf = new Buffer(coct, coct.length);
+            InputStream in = new InputStream(buf);
+            in._OB_ORBInstance(orb);
+            in._OB_readEndian();
+            org.omg.CORBA.Object obj = in.read_Object();
+            try {
+                codebase = org.omg.SendingContext.CodeBaseHelper.narrow(obj);
+            } catch (BAD_PARAM ex) {
+                codebase = null;
+            }
+
+            ctx = null;
+        }
+
+        // TODO: add minor code //
+        
+        
+        return codebase;
+    }
+
+    /**
+     * @param codebase
+     * @return
+     */
+    private org.omg.CORBA.ORB getorb(org.omg.CORBA.Object codebase) {
+        if (codebase instanceof ObjectImpl) {
+            return ((ObjectImpl)codebase)._orb();   
+        } else {
+            return null;   
+        }
+    }
+
+}

Modified: incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/GIOPConnection.java
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/GIOPConnection.java?rev=394918&r1=394917&r2=394918&view=diff
==============================================================================
--- incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/GIOPConnection.java (original)
+++ incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/GIOPConnection.java Tue Apr 18 04:21:49 2006
@@ -11,7 +11,10 @@
 
 package org.apache.yoko.orb.OB;
 
+import org.apache.yoko.orb.CORBA.InputStream;
 import org.apache.yoko.orb.OB.Logger;
+import org.omg.IOP.ServiceContext;
+import org.omg.SendingContext.CodeBase;
 
 abstract public class GIOPConnection implements DowncallEmitter, UpcallReturn {
     // ----------------------------------------------------------------
@@ -169,6 +172,8 @@
     //
     protected java.util.Timer acmTimer_ = null;
 
+	private CodeBase serverRuntime_;
+
     protected ACMTask acmTask_ = null;
 
     // ----------------------------------------------------------------
@@ -569,6 +574,11 @@
         // read in the peer orbacus version from the SCL if exists
         //
         readOBPeerVersion(scl.value);
+        
+        // 
+        // read in the peer's sendig context runtime object
+        //
+        assignSendingContextRuntime(in, scl.value);
 
         switch (status.value.value()) {
         case org.omg.GIOP.ReplyStatusType_1_2._NO_EXCEPTION:
@@ -638,7 +648,17 @@
         }
     }
 
-    //
+    private void assignSendingContextRuntime(InputStream in, ServiceContext[] scl) {
+        if (serverRuntime_ == null) {
+            serverRuntime_ 
+                = Util.getSendingContextRuntime (orbInstance_, scl);
+        }
+        
+        in.__setSendingContextRuntime(serverRuntime_);
+
+	}
+
+	//
     // process a LocateRequest message
     //
     synchronized protected void processLocateRequest(GIOPIncomingMessage msg) {

Modified: incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/Util.java
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/Util.java?rev=394918&r1=394917&r2=394918&view=diff
==============================================================================
--- incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/Util.java (original)
+++ incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/Util.java Tue Apr 18 04:21:49 2006
@@ -11,6 +11,12 @@
 
 package org.apache.yoko.orb.OB;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.omg.IOP.ServiceContext;
+import org.omg.SendingContext.CodeBase;
+
 public final class Util {
     //
     // Print octets to stream
@@ -504,4 +510,31 @@
         } catch (SecurityException e) {
         }
     }
+
+    static ClassLoader getContextClassLoader ()
+    {
+        if (System.getSecurityManager() == null) {
+                return Thread.currentThread ().getContextClassLoader ();
+        } else {
+        return (ClassLoader)
+        AccessController.doPrivileged(
+        new PrivilegedAction() {
+                public Object run() {
+                                return Thread.currentThread ().getContextClassLoader ();
+                }
+        });
+        }
+    }
+
+	public static CodeBase getSendingContextRuntime(ORBInstance orbInstance_, ServiceContext[] scl) {
+        for(int i = 0 ; i < scl.length ; i++)
+        {
+            if(scl[i].context_id == org.omg.IOP.SendingContextRunTime.value)
+                {
+                    return new CodeBaseProxy(orbInstance_, scl[i]);
+                }
+        }
+
+        return null;
+	}
 }

Modified: incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/ValueReader.java
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/ValueReader.java?rev=394918&r1=394917&r2=394918&view=diff
==============================================================================
--- incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/ValueReader.java (original)
+++ incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/ValueReader.java Tue Apr 18 04:21:49 2006
@@ -11,6 +11,10 @@
 
 package org.apache.yoko.orb.OB;
 
+import javax.rmi.CORBA.ValueHandler;
+
+import org.omg.SendingContext.CodeBase;
+
 final public class ValueReader {
     //
     // Chunk data
@@ -54,11 +58,19 @@
         ChunkState state;
 
         Header next; // Java only
+        String codebase; // Java only
 
         Header() {
             ids = new String[0];
             state = new ChunkState();
         }
+        
+        boolean isRMIValue () {
+            return ids != null
+                && ids.length > 0
+                && ids[0].startsWith ("RMI:");
+        }
+
     }
 
     private org.apache.yoko.orb.OB.ORBInstance orbInstance_;
@@ -76,6 +88,8 @@
     private ChunkState chunkState_ = new ChunkState();
 
     private Header currentHeader_ = null; // Java only
+	private ValueHandler valueHandler;
+	private org.omg.SendingContext.CodeBase remoteCodeBase;
 
     // ------------------------------------------------------------------
     // Valuetype creation strategies
@@ -140,6 +154,10 @@
         java.io.Serializable create(Header h) {
             Assert._OB_assert(h.tag >= 0x7fffff00 && h.tag != -1);
 
+            if (h.isRMIValue()) {
+            		return reader_.readRMIValue(h, clz_, h.ids[0]);
+            }
+            
             java.io.Serializable result = null;
 
             try {
@@ -336,8 +354,6 @@
         // Check for presence of codebase URL
         //
         if ((h.tag & 0x00000001) == 1) {
-            String codebase = null;
-
             //
             // Check for indirection tag
             //
@@ -351,11 +367,11 @@
                 buf_.pos_ = buf_.pos_ - 4 + offs;
                 if (buf_.pos_ < 0)
                     throw new org.omg.CORBA.MARSHAL();
-                codebase = in_.read_string();
+                h.codebase = in_.read_string();
                 buf_.pos_ = tmp;
             } else {
                 buf_.pos_ = save;
-                codebase = in_.read_string();
+                h.codebase = in_.read_string();
             }
         }
 
@@ -774,6 +790,98 @@
         orbInstance_ = in._OB_ORBInstance();
         instanceTable_ = new java.util.Hashtable(131);
         headerTable_ = new java.util.Hashtable(131);
+    }
+
+    java.io.Serializable
+    readRMIValue(Header h, Class clz, String repid)
+    {
+        if (valueHandler == null)
+            valueHandler = javax.rmi.CORBA.Util.createValueHandler ();
+
+        if (repid == null)
+        {
+            repid = h.ids[0];
+            
+            if (repid == null)
+            {
+               throw new org.omg.CORBA.MARSHAL("missing repository id");
+            }
+        }
+
+        String className = Util.idToClassName (repid, "");
+        String codebase  = h.codebase;
+
+        if (clz == null)
+        {
+            if (codebase == null) {
+                codebase = in_.__getCodeBase ();
+            }
+
+            try
+            {
+                clz = javax.rmi.CORBA.Util.loadClass
+                    (className,
+                     codebase,
+                     Util.getContextClassLoader ());
+            }
+            catch (ClassNotFoundException ex)
+            {
+                if (codebase == null || codebase.length () == 0) {
+                    // ignore, we'll try to grab the codebase, and then
+                    // call loadClass again.
+                } else {
+                		// TODO: Add minor code
+                    throw new org.omg.CORBA.MARSHAL
+                        ("class "+className
+                         +" not found (cannot load from "+codebase+")" );
+                    
+                }
+            }
+        }
+        
+        if (remoteCodeBase == null)
+        {
+            remoteCodeBase = in_.__getSendingContextRuntime ();
+        }
+
+            if (clz == null) {
+
+                if (codebase == null && remoteCodeBase != null)
+                {
+                    try {
+                        codebase = remoteCodeBase.implementation (repid);
+                    } catch (org.omg.CORBA.SystemException ex) {
+                        // ignore
+                    }
+
+                } 
+
+                if (codebase == null) {
+            		// TODO: add minor code
+                    throw new org.omg.CORBA.MARSHAL
+                        ("class "+className+" not found (no codebase provided)");
+                }
+                
+                try
+                {
+                    clz = javax.rmi.CORBA.Util.loadClass
+                        (className,
+                         codebase,
+                         Util.getContextClassLoader ());
+                }
+                catch (ClassNotFoundException ex)
+                {
+                		// TODO: add minor code
+                    throw new org.omg.CORBA.MARSHAL
+                        ("class "+className+" not found (cannot load from codebase)");
+                }
+
+
+            }
+
+            return valueHandler.readValue (in_, h.headerPos, clz,
+                    repid, remoteCodeBase);
+
     }
 
     public java.io.Serializable readValue() {

Modified: incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/ValueWriter.java
URL: http://svn.apache.org/viewcvs/incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/ValueWriter.java?rev=394918&r1=394917&r2=394918&view=diff
==============================================================================
--- incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/ValueWriter.java (original)
+++ incubator/yoko/trunk/orb/src/main/java/org/apache/yoko/orb/OB/ValueWriter.java Tue Apr 18 04:21:49 2006
@@ -11,6 +11,10 @@
 
 package org.apache.yoko.orb.OB;
 
+import java.io.Serializable;
+
+import javax.rmi.CORBA.ValueHandler;
+
 import org.omg.CORBA.portable.BoxedValueHelper;
 
 final public class ValueWriter {
@@ -66,6 +70,9 @@
     private java.util.Hashtable idTable_;
 
     private java.util.Hashtable idListTable_;
+    private java.util.Hashtable codebaseTable_;
+
+	private ValueHandler valueHandler;
 
     //
     // Helper class for using a String array as the key in a Hashtable
@@ -225,6 +232,7 @@
         instanceTable_ = new java.util.Hashtable(131);
         idTable_ = new java.util.Hashtable(131);
         idListTable_ = new java.util.Hashtable(131);
+        codebaseTable_ = new java.util.Hashtable(3);
     }
 
     public void writeValue(java.io.Serializable value, String id) {
@@ -253,7 +261,12 @@
             // or CustomMarshal.
             //
             if (!isStreamable && !isCustom) {
-                writeValueBox(value, null, null);
+                BoxedValueHelper helper = getHelper (value, null);
+                if (helper == null) {
+                    writeRMIValue (value, id);
+                } else {
+                    writeValueBox (value, null, helper);
+                }
                 return;
             }
 
@@ -337,7 +350,7 @@
                 ids = new String[0];
             }
 
-            int startPos = beginValue(tag, ids, chunked);
+            int startPos = beginValue(tag, ids, null, chunked);
             instanceTable_.put(value, new Integer(startPos));
 
             //
@@ -356,6 +369,90 @@
         }
     }
 
+    private void writeRMIValue(Serializable value, String id) {
+
+    		// check if it is the null object
+    		if (value == null) {
+    			out_.write_long(0);
+    			return;
+    		}
+    		
+    		// check if this value has already been written
+    		if (checkIndirection(value)) {
+    			return;
+    		}
+    		
+    		// special-case string
+    		if (value instanceof java.lang.String) {
+    			org.omg.CORBA.WStringValueHelper.write (out_, (String)value);
+    			return;
+    		}	
+
+    		// get hold of the value handler
+    		if (valueHandler == null) {
+    	        valueHandler = javax.rmi.CORBA.Util.createValueHandler ();
+    	    }
+
+        //
+        // Needs writeReplace?
+        //
+        java.io.Serializable repValue 
+            = valueHandler.writeReplace (value);
+
+        //
+        // Repeat base checks if value was replaced
+        //
+        if (value != repValue)
+        {
+            if (repValue == null) {
+                out_.write_long(0);
+                return;
+            }
+            
+            if (checkIndirection(repValue)) {
+                return;
+            }
+            
+            if (repValue instanceof java.lang.String) {
+	    			org.omg.CORBA.WStringValueHelper.write (out_, (String)value);
+	    			return;
+            }
+
+            value = repValue;
+        }
+
+        //
+        // Get the class object for the value
+        //
+        Class clz = value.getClass ();
+
+        // 
+        // 0x7fffff00 + SINGLE_ID
+        //
+        int tag = 0x7fffff02;
+
+        String codebase = javax.rmi.CORBA.Util.getCodebase (clz);
+        if (codebase != null && codebase.length () != 0)
+            tag |= 1;
+
+        //
+        // Determine the repository ID
+        //
+        String[] ids = new String[1];
+        ids[0] = valueHandler.getRMIRepositoryID (clz);
+
+        //
+        // Determine if chunked encoding is needed.
+        // (we chunk all RMI objects)
+        // 
+        boolean isChunked = true; // valueHandler.isCustomMarshaled (clz);
+
+        int pos = beginValue (tag, ids, codebase, isChunked);
+        instanceTable_.put (value, new Integer (pos));
+        valueHandler.writeValue (out_, value);
+        endValue ();
+	}
+
     public void writeValueBox(java.io.Serializable value,
             org.omg.CORBA.TypeCode type,
             org.omg.CORBA.portable.BoxedValueHelper helper) {
@@ -388,7 +485,7 @@
             //
             // Marshal value
             //
-            int startPos = beginValue(tag, ids, false);
+            int startPos = beginValue(tag, ids, null, false);
             instanceTable_.put(value, new Integer(startPos));
             helper.write_value(out_, value);
             endValue();
@@ -415,8 +512,9 @@
         }
     }
 
-    public int beginValue(int tag, String[] ids, boolean chunk) {
-        if (chunk)
+    public int
+    beginValue(int tag, String[] ids, String codebase, boolean chunk) {
+        if(chunk)
             chunked_ = true;
 
         if (chunked_) {
@@ -438,6 +536,21 @@
 
         out_.write_long(tag);
         int startPos = buf_.pos_ - 4; // start of value
+
+        // write codebase if present
+        if ((tag & 0x00000001) == 1) {
+
+        		// check for indirection of codebase
+        		Integer pos = (Integer)codebaseTable_.get(codebase);
+        		if (pos != null) {
+        			out_.write_long(-1);
+        			int off = pos.intValue() - buf_.pos_;
+        			out_.write_long(off);
+        		} else {
+        			codebaseTable_.put(codebase, new Integer(buf_.pos_));
+        			out_.write_string(codebase);
+        		}
+        }
 
         if ((tag & 0x00000006) == 6) {
             //