~ubuntu-branches/ubuntu/wily/libjboss-remoting-java/wily

« back to all changes in this revision

Viewing changes to src/org/jboss/remoting/serialization/impl/java/MarshalledValueInputStream.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
* JBoss, Home of Professional Open Source
3
 
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
 
* by the @authors tag. See the copyright.txt in the distribution for a
5
 
* full listing of individual contributors.
6
 
*
7
 
* This is free software; you can redistribute it and/or modify it
8
 
* under the terms of the GNU Lesser General Public License as
9
 
* published by the Free Software Foundation; either version 2.1 of
10
 
* the License, or (at your option) any later version.
11
 
*
12
 
* This software is distributed in the hope that it will be useful,
13
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
 
* Lesser General Public License for more details.
16
 
*
17
 
* You should have received a copy of the GNU Lesser General Public
18
 
* License along with this software; if not, write to the Free
19
 
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
 
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21
 
*/
22
 
 
23
 
 
24
 
package org.jboss.remoting.serialization.impl.java;
25
 
 
26
 
import java.io.IOException;
27
 
import java.io.InputStream;
28
 
import java.io.ObjectInputStream;
29
 
import java.io.ObjectStreamClass;
30
 
import java.lang.reflect.Proxy;
31
 
import java.security.AccessController;
32
 
import java.security.PrivilegedAction;
33
 
 
34
 
import org.jboss.logging.Logger;
35
 
 
36
 
/**
37
 
 * An ObjectInputStream subclass used by the MarshalledValue class to
38
 
 * ensure the classes and proxies are loaded using the thread context
39
 
 * class loader.
40
 
 *
41
 
 * @author Scott.Stark@jboss.org
42
 
 * @author Clebert.suconic@jboss.org - refactored packages only
43
 
 * @version $Revision: 3844 $
44
 
 */
45
 
public class MarshalledValueInputStream
46
 
      extends ObjectInputStream
47
 
{
48
 
   private static Logger log = Logger.getLogger(MarshalledValueInputStream.class);
49
 
 
50
 
   static boolean useClassCache = false;
51
 
 
52
 
   /**
53
 
    * Creates a new instance of MarshalledValueOutputStream
54
 
    */
55
 
   public MarshalledValueInputStream(InputStream is) throws IOException
56
 
   {
57
 
      super(is);
58
 
   }
59
 
 
60
 
   /**
61
 
    * Use the thread context class loader to resolve the class
62
 
    *
63
 
    * @throws java.io.IOException Any exception thrown by the underlying OutputStream.
64
 
    */
65
 
   protected Class resolveClass(ObjectStreamClass v)
66
 
         throws IOException, ClassNotFoundException
67
 
   {
68
 
      String className = v.getName();
69
 
      Class resolvedClass = null;
70
 
 
71
 
      if(resolvedClass == null)
72
 
      {
73
 
         ClassLoader loader = (ClassLoader) AccessController.doPrivileged( new PrivilegedAction()
74
 
         {
75
 
            public Object run()
76
 
            {
77
 
               return Thread.currentThread().getContextClassLoader();
78
 
            }
79
 
         });
80
 
         try
81
 
         {
82
 
            resolvedClass = Class.forName(className, false, loader);
83
 
         }
84
 
         catch(ClassNotFoundException e)
85
 
         {
86
 
            /* Use the super.resolveClass() call which will resolve array
87
 
            classes and primitives. We do not use this by default as this can
88
 
            result in caching of stale values across redeployments.
89
 
            */
90
 
            resolvedClass = super.resolveClass(v);
91
 
         }
92
 
      }
93
 
      return resolvedClass;
94
 
   }
95
 
 
96
 
   protected Class resolveProxyClass(String[] interfaces)
97
 
         throws IOException, ClassNotFoundException
98
 
   {
99
 
      if(log.isTraceEnabled())
100
 
      {
101
 
         StringBuffer tmp = new StringBuffer("[");
102
 
         for(int i = 0; i < interfaces.length; i ++)
103
 
         {
104
 
            if(i > 0)
105
 
            {
106
 
               tmp.append(',');
107
 
            }
108
 
            tmp.append(interfaces[i]);
109
 
         }
110
 
         tmp.append(']');
111
 
         log.trace("resolveProxyClass called, ifaces=" + tmp.toString());
112
 
      }
113
 
 
114
 
      // Load the interfaces from the cache or thread context class loader
115
 
      ClassLoader loader = null;
116
 
      Class[] ifaceClasses = new Class[interfaces.length];
117
 
      for(int i = 0; i < interfaces.length; i++)
118
 
      {
119
 
         Class iface = null;
120
 
         String className = interfaces[i];
121
 
         // Check the proxy cache if it exists
122
 
 
123
 
         // Load the interface class using the thread context ClassLoader
124
 
         if(iface == null)
125
 
         {
126
 
            if(loader == null)
127
 
            {
128
 
               loader = (ClassLoader) AccessController.doPrivileged( new PrivilegedAction()
129
 
               {
130
 
                  public Object run()
131
 
                  {
132
 
                     return Thread.currentThread().getContextClassLoader();
133
 
                  }
134
 
               });
135
 
            }
136
 
            iface = Class.forName(className, false, loader);
137
 
         }
138
 
         ifaceClasses[i] = iface;
139
 
      }
140
 
 
141
 
      return Proxy.getProxyClass(loader, ifaceClasses);
142
 
   }
143
 
}