You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pe...@apache.org on 2010/04/15 03:11:13 UTC
svn commit: r934258 [2/2] - in /incubator/river/jtsk/trunk: ./ qa/
qa/harness/policy/ src/com/sun/jini/constants/ src/com/sun/jini/norm/
src/com/sun/jini/outrigger/ src/com/sun/jini/phoenix/
src/com/sun/jini/reggie/ src/manifest/ src/net/jini/activatio...
Modified: incubator/river/jtsk/trunk/src/net/jini/io/MarshalledObject.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/MarshalledObject.java?rev=934258&r1=934257&r2=934258&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/io/MarshalledObject.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/io/MarshalledObject.java Thu Apr 15 01:11:12 2010
@@ -24,7 +24,7 @@ import java.io.Serializable;
* This is a private class used to convert <code>java.rmi.MarshalledObject</code>
* to <code>MarshalledInstance</code> and vice versa.
*/
-final class MarshalledObject implements Serializable {
+final class MarshalledObject<T> implements Serializable {
// Duplicate (private) MarshalledObject fields, and make them
// package visable
Added: incubator/river/jtsk/trunk/src/net/jini/io/PackageVersion.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/PackageVersion.java?rev=934258&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/io/PackageVersion.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/io/PackageVersion.java Thu Apr 15 01:11:12 2010
@@ -0,0 +1,255 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.jini.io;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ * Contains Package information from a jar files Manifest utilising the
+ * java ClassLoader.
+ *
+ * It is expected that these packages be utilised to create some kind of weak
+ * hashtable cache that looks up ClassLoaders from a PackageVersion for Class
+ * resolution.
+ *
+ * OSGi or other frameworks can utilise this information to decide package
+ * imports.
+ *
+ * I'm also considering a jini service which provides version compatibility
+ * information, along with a codebase service.
+ *
+ * @author Peter Firmstone
+ * @see java.lang.Package
+ * @see java.lang.ClassLoader
+ */
+public final class PackageVersion implements Serializable {
+ private static final Map<Integer,PackageVersion> pool
+ = new WeakHashMap<Integer,PackageVersion>(60);
+ private static final long serialVersionUID = 1L;
+ private static final String EMPTY = new String();
+ private final String packageName; // Cannot be null
+ // Allowing null is a pain as it requires additional checks
+ // however the tradeoff is worth it for Serialization performance
+ private final String implementationVendor; // Can be null
+ private final String implementationVersion; // Can be null
+ private transient int hash;
+ // Specification isn't important as a spec only represents the public API
+ // an object is specific to the implementation.
+ // Title probably doesn't matter either. Perhaps the implementation Vendor
+ // doesn't either, however I've left it in place.
+ private PackageVersion(String pkgName, String impVendor, String impVersion,
+ Integer hashCode){
+ packageName = pkgName;
+ implementationVendor = impVendor;
+ implementationVersion = impVersion;
+ hash = hashCode.intValue();
+ }
+
+ public String getPkgName(){
+ return packageName;
+ }
+
+ public String getImplVendor(){
+ if (implementationVendor == null) return EMPTY;
+ return implementationVendor;
+ }
+
+ public String getImplVersion(){
+ if (implementationVersion == null) return EMPTY;
+ return implementationVersion;
+ }
+
+ public static PackageVersion getInstance(String pkgName,
+ String impVendor, String impVersion){
+ if (pkgName == null) throw new NullPointerException("Package" +
+ " name cannot be null");
+ Integer hashCode = hashCode( pkgName, impVendor, impVersion);
+ PackageVersion pv = null;
+ boolean wasNull = false;
+ synchronized (pool) {
+ pv = pool.get(hashCode);
+ if (pv == null) {
+ wasNull = true;
+ pv = new PackageVersion(pkgName, impVendor, impVersion, hashCode);
+ pool.put(hashCode, pv);
+ }
+ }
+ // Just in case something has the same hashcode but not equal -unlikely
+ if ( !wasNull ) {
+ if ( (pv.implementationVendor == impVendor ||
+ pv.implementationVendor.equals(impVendor)) &&
+ (pv.implementationVersion == impVersion ||
+ pv.implementationVersion.equals(impVersion)) &&
+ pv.packageName.equals(pkgName)){
+ return pv;
+ } else {
+ // This is rare there must be an identical hash value.
+ return new PackageVersion(pkgName, impVendor, impVersion, hashCode);
+ }
+ }
+ // pv was null, just return the new one.
+ return pv;
+ }
+
+ public static PackageVersion getInstance(Package pkg){
+ String pkgName = pkg.getName();
+ String impVendor = pkg.getImplementationVendor();
+ String impVersion = pkg.getImplementationVersion();
+ return getInstance(pkgName, impVendor, impVersion);
+ }
+
+ public static PackageVersion getInstance(Object obj){
+ Class clazz = obj.getClass();
+ Package pkg = getPackage(clazz);
+ return getInstance(pkg);
+ }
+
+
+ private static Package getPackage(Class type){
+ Package pkg = type.getPackage();
+ if (pkg != null) return pkg;
+ String name = type.getName();
+ String pkgName = getPackageName(name);
+ // Arrays strings return null packages, should we return the package
+ // belonging to the class withing the array?
+ return pkg.getPackage(pkgName);
+ }
+
+ private static String getPackageName(String className){
+ int index = className.lastIndexOf('.');
+ if (index != -1) {
+ return className.substring(0, index);
+ }
+ return "";
+ }
+
+ @Override
+ public boolean equals(Object obj){
+ if (this == obj) return true;
+ if ( obj instanceof PackageVersion )
+ {
+ PackageVersion pkg = (PackageVersion) obj;
+ if (
+ (implementationVendor == pkg.implementationVendor ||
+ implementationVendor.equals(pkg.implementationVendor)) &&
+ (implementationVersion == pkg.implementationVersion ||
+ implementationVersion.equals(pkg.implementationVersion)) &&
+ packageName.equals(pkg.packageName))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode(){
+ return hash;
+ }
+
+ private static Integer hashCode(String pkgName, String impVendor,
+ String impVersion){
+ if (impVendor == null) impVendor = EMPTY;
+ if (impVersion == null) impVersion = EMPTY;
+ return ( pkgName.hashCode() - impVendor.hashCode() +
+ impVersion.hashCode());
+ }
+
+ public boolean equalsPackage(Package pkg){
+ String impVendor = pkg.getImplementationVendor();
+ String impVersion = pkg.getImplementationVersion();
+ if (
+ (implementationVendor == impVendor ||
+ implementationVendor.equals(impVendor)) &&
+ (implementationVersion == impVersion ||
+ implementationVersion.equals(impVersion)) &&
+ packageName.equals(pkg.getName()))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public String toString(){
+ return "package " + getPkgName() + "|" + getImplVendor() + "|" +
+ getImplVersion();
+ }
+
+ private void writeObject(ObjectOutputStream out) throws IOException{
+ out.defaultWriteObject();
+ }
+
+
+ /**
+ * readObject ensures we add any new instances to the pool, while
+ * readResolve ensures that external usages don't refer to duplicates, so
+ * any duplicates can be garbage collected. The pool is a weak reference
+ * pool, so pool instances will be garbage collected too, if no longer
+ * reachable from a strong reference.
+ * @param in
+ * @throws java.io.IOException
+ * @throws java.lang.ClassNotFoundException
+ */
+ private void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException{
+ in.defaultReadObject();
+ // Strings are immutable and immune to unmarshalling reference stealing
+ // attacks with final references.
+ // Hash is transient set it to a value consistent with the local jvm.
+ if (packageName == null) throw new NullPointerException("Package" +
+ " name cannot be null");
+ hash = hashCode(packageName, implementationVendor, implementationVersion);
+ Integer key = new Integer(hash);
+ synchronized (pool){
+ if ( !pool.containsKey(key)) {
+ pool.put(key,this);
+ }
+ }
+ }
+
+ /**
+ * This method just ensure's we use our local jvm pool objects, instead of
+ * unmarshalled duplicates, so as not to cause a memory explosion, that is
+ * an instance for every class in every package.
+ *
+ * If communication only occured with one remote host, we could leave
+ * the responsibility of ensuring all marshalled instances referenced the
+ * same PackageVersion object in the Serialization Object Graph, however
+ * in an environment with many hosts, we couldn't rely on that mechanism.
+ *
+ * The readObject method ensures that any new objects are placed into the
+ * pool. A concurrently accessible pool is not deemed necessary since
+ * the network is much slower than the CPU and the synchronized block
+ * is small.
+ *
+ * Any duplicates created by the readObject method will not be strongly
+ * referenced and can be collected by the garbage collector.
+ *
+ * @return
+ * @SerializedForm
+ */
+ private Object readResolve() {
+ return getInstance(packageName, implementationVendor, implementationVersion);
+ }
+}
Propchange: incubator/river/jtsk/trunk/src/net/jini/io/PackageVersion.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/river/jtsk/trunk/src/net/jini/io/ToMOInputStream.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/ToMOInputStream.java?rev=934258&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/io/ToMOInputStream.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/io/ToMOInputStream.java Thu Apr 15 01:11:12 2010
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.jini.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+
+class ToMOInputStream extends ObjectInputStream {
+
+ public ToMOInputStream(InputStream in) throws IOException {
+ super(in);
+ }
+
+ @Override
+ protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+ if (desc.getName().equals("net.jini.io.MarshalledObject")) {
+ return java.rmi.MarshalledObject.class;
+ }
+ return super.resolveClass(desc);
+ }
+}
Propchange: incubator/river/jtsk/trunk/src/net/jini/io/ToMOInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/river/jtsk/trunk/src/net/jini/loader/ClassAnnotation.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/loader/ClassAnnotation.java?rev=934258&r1=934257&r2=934258&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/loader/ClassAnnotation.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/loader/ClassAnnotation.java Thu Apr 15 01:11:12 2010
@@ -18,7 +18,6 @@
package net.jini.loader;
-import java.rmi.server.RMIClassLoader;
import net.jini.loader.pref.PreferredClassProvider;
/**
@@ -26,19 +25,19 @@ import net.jini.loader.pref.PreferredCla
* loader that is an instance of this interface.
*
* <p>This interface allows a {@link ClassLoader} subclass to
- * customize the behavior of {@link RMIClassLoader#getClassAnnotation
- * RMIClassLoader.getClassAnnotation} (and thus RMI marshalling
+ * customize the behavior of {@link CodebaseAccessClassLoader#getClassAnnotation
+ * CodebaseAccessClassLoader.getClassAnnotation} (and thus RMI marshalling
* semantics) for classes defined by its instances.
*
* <p>Note that this interface is only effective if the current {@link
- * RMIClassLoader} provider supports it; not all
- * <code>RMIClassLoader</code> providers support this interface. In
+ * CodebaseAccessClassLoader} provider supports it; not all
+ * <code>CodebaseAccessClassLoader</code> providers support this interface. In
* particular, the default provider (see {@link
- * RMIClassLoader#getDefaultProviderInstance
- * RMIClassLoader.getDefaultProviderInstance}) does <i>not</i> support
+ * CodebaseAccessClassLoader#getDefaultProviderInstance
+ * CodebaseAccessClassLoader.getDefaultProviderInstance}) does <i>not</i> support
* this interface, and so when the default provider is used, this
* interface will be ignored by
- * <code>RMIClassLoader.getClassAnnotation</code>. {@link
+ * <code>CodebaseAccessClassLoader.getClassAnnotation</code>. {@link
* PreferredClassProvider} and its subclasses do support this
* interface.
*
Modified: incubator/river/jtsk/trunk/src/net/jini/loader/ClassLoading.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/loader/ClassLoading.java?rev=934258&r1=934257&r2=934258&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/loader/ClassLoading.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/loader/ClassLoading.java Thu Apr 15 01:11:12 2010
@@ -18,18 +18,21 @@
package net.jini.loader;
+import java.io.IOException;
import java.lang.ref.SoftReference;
import java.net.MalformedURLException;
-import java.rmi.server.RMIClassLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.HashSet;
import java.util.Map;
import java.util.WeakHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import net.jini.security.Security;
/**
* Provides static methods for loading classes using {@link
- * RMIClassLoader} with optional verification that the codebase URLs
+ * CodebaseAccessClassLoader} with optional verification that the codebase URLs
* used to load classes provide content integrity (see {@link
* Security#verifyCodebaseIntegrity
* Security.verifyCodebaseIntegrity}).
@@ -38,7 +41,18 @@ import net.jini.security.Security;
* @since 2.0
**/
public final class ClassLoading {
-
+ private static Logger logger = Logger.getLogger( ClassLoading.class.getName() );
+// private static HashSet<String>noprefs = new HashSet<String>();
+//
+// public synchronized static void neverPrefer( String name ) {
+// logger.fine("neverPrefer("+name+")");
+// noprefs.add( name );
+// }
+//
+// public synchronized static void honorPreferenceFor( String name ) {
+// logger.fine("honorPreferenceFor("+name+")");
+// noprefs.remove( name );
+// }
/**
* per-thread cache (weakly) mapping verifierLoader values to
* (soft) sets of codebase values that have been verified (to
@@ -50,8 +64,8 @@ public final class ClassLoading {
/**
* Loads a class using {@link
- * RMIClassLoader#loadClass(String,String,ClassLoader)
- * RMIClassLoader.loadClass}, optionally verifying that the
+ * CodebaseAccessClassLoader#loadClass(String,String,ClassLoader)
+ * CodebaseAccessClassLoader.loadClass}, optionally verifying that the
* codebase URLs provide content integrity.
*
* <p>If <code>verifyCodebaseIntegrity</code> is <code>true</code>
@@ -72,19 +86,19 @@ public final class ClassLoading {
* other exception, then this method throws that exception.
*
* <p>This method then invokes {@link
- * RMIClassLoader#loadClass(String,String,ClassLoader)
- * RMIClassLoader.loadClass} with <code>codebase</code> as the
+ * CodebaseAccessClassLoader#loadClass(String,String,ClassLoader)
+ * CodebaseAccessClassLoader.loadClass} with <code>codebase</code> as the
* first argument (or <code>null</code> if in the previous step
* <code>Security.verifyCodebaseIntegrity</code> was invoked and
* it threw a <code>SecurityException</code>), <code>name</code>
* as the second argument, and <code>defaultLoader</code> as the
- * third argument. If <code>RMIClassLoader.loadClass</code>
+ * third argument. If <code>CodebaseAccessClassLoader.loadClass</code>
* throws a <code>ClassNotFoundException</code>, then this method
* throws a <code>ClassNotFoundException</code>; if
- * <code>RMIClassLoader.loadClass</code> throws any other
+ * <code>CodebaseAccessClassLoader.loadClass</code> throws any other
* exception, then this method throws that exception; otherwise,
* this method returns the <code>Class</code> returned by
- * <code>RMIClassLoader.loadClass</code>.
+ * <code>CodebaseAccessClassLoader.loadClass</code>.
*
* @param codebase the list of URLs (separated by spaces) to load
* the class from, or <code>null</code>
@@ -93,7 +107,7 @@ public final class ClassLoading {
*
* @param defaultLoader the class loader value (possibly
* <code>null</code>) to pass as the <code>defaultLoader</code>
- * argument to <code>RMIClassLoader.loadClass</code>
+ * argument to <code>CodebaseAccessClassLoader.loadClass</code>
*
* @param verifyCodebaseIntegrity if <code>true</code>, verify
* that the codebase URLs provide content integrity
@@ -108,11 +122,11 @@ public final class ClassLoading {
*
* @throws MalformedURLException if
* <code>Security.verifyCodebaseIntegrity</code> or
- * <code>RMIClassLoader.loadClass</code> throws a
+ * <code>CodebaseAccessClassLoader.loadClass</code> throws a
* <code>MalformedURLException</code>
*
* @throws ClassNotFoundException if
- * <code>RMIClassLoader.loadClass</code> throws a
+ * <code>CodebaseAccessClassLoader.loadClass</code> throws a
* <code>ClassNotFoundException</code>
*
* @throws NullPointerException if <code>name</code> is
@@ -123,7 +137,7 @@ public final class ClassLoading {
ClassLoader defaultLoader,
boolean verifyCodebaseIntegrity,
ClassLoader verifierLoader)
- throws MalformedURLException, ClassNotFoundException
+ throws IOException, ClassNotFoundException
{
SecurityException verifyException = null;
if (verifyCodebaseIntegrity && codebase != null) {
@@ -134,8 +148,57 @@ public final class ClassLoading {
codebase = null;
}
}
- try {
- return RMIClassLoader.loadClass(codebase, name, defaultLoader);
+// if( logger.isLoggable(Level.FINEST) ) {
+// logger.log(Level.FINEST, "loadClass(url="+codebase+",class="+name+
+// ") with="+defaultLoader+", noprefs="+isNeverPreferred(name),
+// new Throwable("loadClass("+name+")") );
+// } else if( logger.isLoggable(Level.FINER) ) {
+// logger.finer("loadClass(url="+codebase+",class="+name+
+// ") with="+defaultLoader+", noprefs="+isNeverPreferred(name));
+// }
+// if( logger.isLoggable(Level.FINEST) ) {
+// synchronized( noprefs ) {
+// logger.finest("Check Pref \""+name+"\" in "+noprefs );
+// }
+// }
+// if( isNeverPreferred(name) ) {
+// // defaultLoader is the remote loader, only use it's classLoader
+// if( defaultLoader != null ) {
+// // If it's loaded by the system class loader, don't use it
+// if( defaultLoader.getClass().getClassLoader() != null ) {
+// logger.fine("Loading with defaultLoader: "+
+// defaultLoader+" which was loaded from "+
+// defaultLoader.getClass().getClassLoader() );
+// Class c = Class.forName( name, true,
+// CodebaseAccessClassLoader.getSystemContextClassLoader( defaultLoader ) );
+// logger.fine("Loaded "+c.getName()+" using: "+c.getClassLoader() );
+// return c;
+// }
+// }
+//
+// if (logger.isLoggable(Level.FINE))
+// logger.fine("\""+name+"\" is never preferred and there is no " +
+// "defaultLoader, so calling forName()" +
+// ", ctx loader="+Thread.currentThread().getContextClassLoader()+
+// ", thisLoader="+ClassLoading.class.getClassLoader() );
+// Class c = Class.forName( name, true, CodebaseAccessClassLoader.getSystemContextClassLoader( null ) );
+// if (logger.isLoggable(Level.FINE)) {
+// logger.fine("Loaded "+
+// c.getName()+" using: "+c.getClassLoader() );
+// }
+// return c;
+// }
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine( "Using ("+(defaultLoader != null ?
+ defaultLoader.getClass().getClassLoader() : null)+
+ "="+defaultLoader+") to download: "+name+" from "+codebase );
+ }
+ try {
+ Class c = CodebaseAccessClassLoader.loadClass(codebase, name, defaultLoader );
+ if (logger.isLoggable(Level.FINE))
+ logger.fine("Loaded "+c.getName()+" using: "+c.getClassLoader() );
+ return c;
} catch (ClassNotFoundException e) {
if (verifyException != null) {
// assume that the verify exception is more important
@@ -149,8 +212,8 @@ public final class ClassLoading {
/**
* Loads a dynamic proxy class using {@link
- * RMIClassLoader#loadProxyClass(String,String[],ClassLoader)
- * RMIClassLoader.loadProxyClass}, optionally verifying that the
+ * CodebaseAccessClassLoader#loadProxyClass(String,String[],ClassLoader)
+ * CodebaseAccessClassLoader.loadProxyClass}, optionally verifying that the
* codebase URLs provide content integrity.
*
* <p>If <code>verifyCodebaseIntegrity</code> is <code>true</code>
@@ -171,20 +234,20 @@ public final class ClassLoading {
* exception, then this method throws that exception.
*
* <p>This method invokes {@link
- * RMIClassLoader#loadProxyClass(String,String[],ClassLoader)
- * RMIClassLoader.loadProxyClass} with <code>codebase</code> as
+ * CodebaseAccessClassLoader#loadProxyClass(String,String[],ClassLoader)
+ * CodebaseAccessClassLoader.loadProxyClass} with <code>codebase</code> as
* the first argument (or <code>null</code> if in the previous
* step <code>Security.verifyCodebaseIntegrity</code> was invoked
* and it threw a <code>SecurityException</code>),
* <code>interfaceNames</code> as the second argument, and
* <code>defaultLoader</code> as the third argument. If
- * <code>RMIClassLoader.loadProxyClass</code> throws a
+ * <code>CodebaseAccessClassLoader.loadProxyClass</code> throws a
* <code>ClassNotFoundException</code>, then this method throws a
* <code>ClassNotFoundException</code>; if
- * <code>RMIClassLoader.loadProxyClass</code> throws any other
+ * <code>CodebaseAccessClassLoader.loadProxyClass</code> throws any other
* exception, then this method throws that exception; otherwise,
* this method returns the <code>Class</code> returned by
- * <code>RMIClassLoader.loadProxyClass</code>.
+ * <code>CodebaseAccessClassLoader.loadProxyClass</code>.
*
* @param codebase the list of URLs (separated by spaces) to load
* classes from, or <code>null</code>
@@ -194,7 +257,7 @@ public final class ClassLoading {
*
* @param defaultLoader the class loader value (possibly
* <code>null</code>) to pass as the <code>defaultLoader</code>
- * argument to <code>RMIClassLoader.loadProxyClass</code>
+ * argument to <code>CodebaseAccessClassLoader.loadProxyClass</code>
*
* @param verifyCodebaseIntegrity if <code>true</code>, verify
* that the codebase URLs provide content integrity
@@ -209,11 +272,11 @@ public final class ClassLoading {
*
* @throws MalformedURLException if
* <code>Security.verifyCodebaseIntegrity</code> or
- * <code>RMIClassLoader.loadProxyClass</code> throws a
+ * <code>CodebaseAccessClassLoader.loadProxyClass</code> throws a
* <code>MalformedURLException</code>
*
* @throws ClassNotFoundException if
- * <code>RMIClassLoader.loadProxyClass</code> throws a
+ * <code>CodebaseAccessClassLoader.loadProxyClass</code> throws a
* <code>ClassNotFoundException</code>
*
* @throws NullPointerException if <code>interfaceNames</code> is
@@ -225,7 +288,7 @@ public final class ClassLoading {
ClassLoader defaultLoader,
boolean verifyCodebaseIntegrity,
ClassLoader verifierLoader)
- throws MalformedURLException, ClassNotFoundException
+ throws IOException, ClassNotFoundException
{
SecurityException verifyException = null;
if (verifyCodebaseIntegrity && codebase != null) {
@@ -237,7 +300,7 @@ public final class ClassLoading {
}
}
try {
- return RMIClassLoader.loadProxyClass(codebase, interfaceNames,
+ return CodebaseAccessClassLoader.loadProxyClass(codebase, interfaceNames,
defaultLoader);
} catch (ClassNotFoundException e) {
if (verifyException != null) {
Added: incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseAccessClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseAccessClassLoader.java?rev=934258&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseAccessClassLoader.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseAccessClassLoader.java Thu Apr 15 01:11:12 2010
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.jini.loader;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import net.jini.loader.pref.PreferredClassLoader;
+
+/**
+ *
+ * @author Gregg Wonderly
+ */
+public class CodebaseAccessClassLoader {
+ private static CodebaseClassAccess provider = new RMIClassLoaderCodebaseAccess();
+
+ /**
+ * Sets the provider that will resolve classes for remote codebases.
+ * The initial provider is {@link RMIClassLoaderCodebaseAccess} which uses the
+ * {@link java.rmi.server.RMIClassLoaderSpi} defined mechanisms.
+ * Requires CodebaseAccessOverridePermission() for the current provider's class name
+ */
+ public static void setCodebaseAccessClassLoader( CodebaseClassAccess access ) {
+ SecurityManager sm = System.getSecurityManager();
+ if( sm != null ) {
+ sm.checkPermission(
+ new CodebaseAccessOverridePermission( provider.getClass().getName() ) );
+ }
+ provider = access;
+ }
+ public static Class loadClass( String codebase, String name, ClassLoader defaultLoader ) throws IOException,ClassNotFoundException {
+ return provider.loadClass( codebase, name, defaultLoader != null ? defaultLoader : getParentContextClassLoader() );
+ }
+
+ public static Class loadProxyClass( String codebase, String[] interfaceNames, ClassLoader defaultLoader ) throws IOException,ClassNotFoundException {
+ return provider.loadProxyClass( codebase, interfaceNames, defaultLoader);
+ }
+
+ public static String getClassAnnotation( Class cls ) {
+ return provider.getClassAnnotation( cls );
+ }
+
+ public static ClassLoader getClassLoader( String codebase ) throws IOException {
+ return provider.getClassLoader( codebase );
+ }
+
+ public static Class loadClass(String name, String location) throws IOException, ClassNotFoundException {
+ return provider.loadClass( name, location);
+ }
+
+ public static ClassLoader createClassLoader( final URL[] urls, final ClassLoader parent,
+ final boolean requireDlPerm, final AccessControlContext ctx ) {
+ return provider.createClassLoader( urls, parent, requireDlPerm, ctx );
+ }
+ public static ClassLoader getParentContextClassLoader() {
+ return provider.getParentContextClassLoader();
+ }
+ public static ClassLoader getSystemContextClassLoader( ClassLoader defaultLoader ) {
+ return provider.getSystemContextClassLoader( defaultLoader );
+ }
+}
Propchange: incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseAccessClassLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseAccessOverridePermission.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseAccessOverridePermission.java?rev=934258&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseAccessOverridePermission.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseAccessOverridePermission.java Thu Apr 15 01:11:12 2010
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.jini.loader;
+
+import java.security.BasicPermission;
+
+/**
+ *
+ * @author Gregg Wonderly
+ */
+public class CodebaseAccessOverridePermission extends BasicPermission {
+ public CodebaseAccessOverridePermission( String name, String access ) {
+ super( name, access );
+ }
+ public CodebaseAccessOverridePermission( String name ) {
+ super( name );
+ }
+}
Propchange: incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseAccessOverridePermission.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseClassAccess.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseClassAccess.java?rev=934258&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseClassAccess.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseClassAccess.java Thu Apr 15 01:11:12 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.jini.loader;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.AccessControlContext;
+
+/**
+ *
+ * @author Gregg Wonderly
+ */
+public interface CodebaseClassAccess {
+ public Class loadClass(String codebase,
+ String name ) throws IOException, ClassNotFoundException;
+ public Class loadClass(String codebase,
+ String name,
+ ClassLoader defaultLoader) throws IOException,ClassNotFoundException;
+ public Class loadProxyClass(String codebase,
+ String[] interfaceNames,
+ ClassLoader defaultLoader ) throws IOException,ClassNotFoundException;
+ public String getClassAnnotation( Class cls );
+ public ClassLoader getClassLoader(String codebase) throws IOException;
+ public ClassLoader createClassLoader( URL[] urls,
+ ClassLoader parent,
+ boolean requireDlPerm,
+ AccessControlContext ctx );
+ /**
+ * This should return the class loader that represents the system
+ * environment. This might often be the same as {@link #getSystemContextClassLoader()}
+ * but may not be in certain circumstances where container mechanisms isolate certain
+ * parts of the classpath between various contexts.
+ * @return
+ */
+ public ClassLoader getParentContextClassLoader();
+ /**
+ * This should return the class loader that represents the local system
+ * environment that is associated with never-preferred classes
+ * @return
+ */
+ public ClassLoader getSystemContextClassLoader( ClassLoader defaultLoader );
+}
Propchange: incubator/river/jtsk/trunk/src/net/jini/loader/CodebaseClassAccess.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/river/jtsk/trunk/src/net/jini/loader/DownloadPermission.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/loader/DownloadPermission.java?rev=934258&r1=934257&r2=934258&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/loader/DownloadPermission.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/loader/DownloadPermission.java Thu Apr 15 01:11:12 2010
@@ -18,39 +18,35 @@
package net.jini.loader;
-import java.rmi.server.RMIClassLoader;
import java.security.BasicPermission;
-import java.security.CodeSource;
-import net.jini.loader.pref.PreferredClassProvider;
-import net.jini.loader.pref.RequireDlPermProvider;
/**
* Permission that must be granted to the {@link CodeSource} of a
* downloaded class in order for the class to be defined using {@link
- * RMIClassLoader}.
+ * CodebaseAccessClassLoader}.
*
* <p>A <code>DownloadPermission</code> contains a name (also referred
* to as a "target name") but no action list; you either have the
* named permission or you don't. The only defined target name is
* "permit", which allows a downloaded class with a
* <code>CodeSource</code> that is granted the permission to be
- * defined by a class loader created by <code>RMIClassLoader</code>.
+ * defined by a class loader created by <code>CodebaseAccessClassLoader</code>.
*
* <p>Selective granting of this permission can be used to restrict
* the <code>CodeSource</code> values (codebase URLs and signers) from
* which downloaded classes can be defined using
- * <code>RMIClassLoader</code>.
+ * <code>CodebaseAccessClassLoader</code>.
*
* <p>Note that this permission is only enforced if the current {@link
- * RMIClassLoader} provider supports it; not all
- * <code>RMIClassLoader</code> providers support this permission. In
+ * CodebaseAccessClassLoader} provider supports it; not all
+ * <code>CodebaseAccessClassLoader</code> providers support this permission. In
* particular, the default provider (see {@link
- * RMIClassLoader#getDefaultProviderInstance
- * RMIClassLoader.getDefaultProviderInstance}) does <i>not</i> support
+ * CodebaseAccessClassLoader#getDefaultProviderInstance
+ * CodebaseAccessClassLoader.getDefaultProviderInstance}) does <i>not</i> support
* this permission, and so when the default provider is used,
* downloaded classes do not need to be granted
* <code>DownloadPermission</code> in order to be defined using
- * <code>RMIClassLoader</code>. {@link PreferredClassProvider} itself
+ * <code>CodebaseAccessClassLoader</code>. {@link PreferredClassProvider} itself
* does not enforce this permission, but subclasses may configure it
* to do so (see {@link RequireDlPermProvider}).
*
Added: incubator/river/jtsk/trunk/src/net/jini/loader/RMIClassLoaderCodebaseAccess.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/loader/RMIClassLoaderCodebaseAccess.java?rev=934258&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/loader/RMIClassLoaderCodebaseAccess.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/loader/RMIClassLoaderCodebaseAccess.java Thu Apr 15 01:11:12 2010
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.jini.loader;
+
+import java.io.IOException;
+import java.net.URL;
+import java.rmi.server.RMIClassLoader;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import net.jini.loader.pref.PreferredClassLoader;
+
+/**
+ *
+ * @author Gregg Wonderly
+ */
+public class RMIClassLoaderCodebaseAccess implements CodebaseClassAccess {
+ public Class loadClass( String codebase,
+ String name,
+ ClassLoader defaultLoader ) throws IOException, ClassNotFoundException {
+ return RMIClassLoader.loadClass( codebase, name, defaultLoader );
+ }
+
+ public Class loadProxyClass(String codebase, String[] interfaceNames, ClassLoader defaultLoader) throws IOException, ClassNotFoundException {
+ return RMIClassLoader.loadProxyClass( codebase, interfaceNames, defaultLoader );
+ }
+
+ public String getClassAnnotation( Class cls ) {
+ return RMIClassLoader.getClassAnnotation( cls );
+ }
+
+ public ClassLoader getClassLoader(String codebase) throws IOException {
+ return RMIClassLoader.getClassLoader( codebase );
+ }
+
+ public Class loadClass(String codebase, String name) throws IOException, ClassNotFoundException {
+ return RMIClassLoader.loadClass( codebase, name );
+ }
+
+ public ClassLoader createClassLoader( final URL[] urls, final ClassLoader parent,
+ final boolean requireDlPerm, final AccessControlContext ctx) {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return new PreferredClassLoader(urls, parent, null, requireDlPerm);
+ }
+ }, ctx );
+ }
+ public ClassLoader getParentContextClassLoader() {
+ /*
+ * The RMI supporting, default implementation simply uses the current thread's
+ * context class loader.
+ */
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ public ClassLoader getSystemContextClassLoader( ClassLoader defaultLoader ) {
+ if( defaultLoader == null ) {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ return defaultLoader.getClass().getClassLoader( );
+ }
+}
+
Propchange: incubator/river/jtsk/trunk/src/net/jini/loader/RMIClassLoaderCodebaseAccess.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassProvider.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassProvider.java?rev=934258&r1=934257&r2=934258&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassProvider.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassProvider.java Thu Apr 15 01:11:12 2010
@@ -32,7 +32,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLClassLoader;
-import java.rmi.server.RMIClassLoader;
import java.rmi.server.RMIClassLoaderSpi;
import java.security.AccessController;
import java.security.CodeSource;
@@ -49,19 +48,20 @@ import java.util.WeakHashMap;
import java.util.logging.Logger;
import java.util.logging.Level;
import net.jini.loader.ClassAnnotation;
+import net.jini.loader.CodebaseAccessClassLoader;
import net.jini.loader.DownloadPermission;
/**
- * An <code>RMIClassLoader</code> provider that supports preferred
+ * An <code>CodebaseAccessClassLoader</code> provider that supports preferred
* classes.
*
- * <p>See the {@link RMIClassLoader} specification for information
- * about how to install and configure the <code>RMIClassLoader</code>
+ * <p>See the {@link CodebaseAccessClassLoader} specification for information
+ * about how to install and configure the <code>CodebaseAccessClassLoader</code>
* service provider.
*
* <p><code>PreferredClassProvider</code> uses instances of {@link
* PreferredClassLoader} to load classes from codebase URL paths
- * supplied to <code>RMIClassLoader.loadClass</code> methods.
+ * supplied to <code>CodebaseAccessClassLoader.loadClass</code> methods.
*
* <p><code>PreferredClassProvider</code> does not enforce {@link
* DownloadPermission} by default, but a subclass can configure it to
@@ -79,7 +79,7 @@ import net.jini.loader.DownloadPermissio
*
* The following section defines terms and describes behaviors common
* to how <code>PreferredClassProvider</code> implements the abstract
- * methods of <code>RMIClassLoaderSpi</code>. Where applicable, these
+ * methods of <code>CodebaseAccessClassLoaderSpi</code>. Where applicable, these
* definitions and descriptions are relative to the instance of
* <code>PreferredClassProvider</code> on which a method is invoked
* and the context in which it is invoked.
@@ -282,10 +282,10 @@ public class PreferredClassProvider exte
/**
* Creates a new <code>PreferredClassProvider</code>.
*
- * <p>This constructor is used by the {@link RMIClassLoader}
+ * <p>This constructor is used by the {@link CodebaseAccessClassLoader}
* service provider location mechanism when
* <code>PreferredClassProvider</code> is configured as the
- * <code>RMIClassLoader</code> provider class.
+ * <code>CodebaseAccessClassLoader</code> provider class.
*
* <p>If there is a security manager, its {@link
* SecurityManager#checkCreateClassLoader checkCreateClassLoader}
@@ -387,7 +387,7 @@ public class PreferredClassProvider exte
/**
* Provides the implementation for {@link
- * RMIClassLoaderSpi#loadClass(String,String,ClassLoader)}.
+ * CodebaseAccessClassLoaderSpi#loadClass(String,String,ClassLoader)}.
*
* <p><code>PreferredClassProvider</code> implements this method
* as follows:
@@ -684,7 +684,7 @@ public class PreferredClassProvider exte
/**
* Provides the implementation for {@link
- * RMIClassLoaderSpi#getClassAnnotation(Class)}.
+ * CodebaseAccessClassLoaderSpi#getClassAnnotation(Class)}.
*
* <p><code>PreferredClassProvider</code> implements this method
* as follows:
@@ -1416,23 +1416,14 @@ public class PreferredClassProvider exte
}
/** map from weak(key=string) to [URL[], soft(key)] */
- private static Map pathToURLsCache = new WeakHashMap(5);
+ private final static Map pathToURLsCache = new WeakHashMap(5);
/**
* Return the class loader to be used as the parent for an RMI class
* loader used in the current execution context.
*/
private static ClassLoader getRMIContextClassLoader() {
- /*
- * The current implementation simply uses the current thread's
- * context class loader.
- */
- return (ClassLoader) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return Thread.currentThread().getContextClassLoader();
- }
- });
+ return CodebaseAccessClassLoader.getParentContextClassLoader();
}
/**
@@ -1666,13 +1657,15 @@ public class PreferredClassProvider exte
final boolean requireDlPerm)
{
checkInitialized();
- return (ClassLoader)
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return new PreferredClassLoader(urls, parent, null,
- requireDlPerm);
- }
- }, PreferredClassLoader.getLoaderAccessControlContext(urls));
+ return CodebaseAccessClassLoader.createClassLoader( urls, parent, requireDlPerm,
+ PreferredClassLoader.getLoaderAccessControlContext(urls) );
+// return (ClassLoader)
+// AccessController.doPrivileged(new PrivilegedAction() {
+// public Object run() {
+// return new PreferredClassLoader(urls, parent, null,
+// requireDlPerm);
+// }
+// }, PreferredClassLoader.getLoaderAccessControlContext(urls));
}
/**
@@ -1697,7 +1690,7 @@ public class PreferredClassProvider exte
}
hashValue = h;
}
-
+
public int hashCode() {
return hashValue;
}
Modified: incubator/river/jtsk/trunk/src/net/jini/loader/pref/RequireDlPermProvider.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/loader/pref/RequireDlPermProvider.java?rev=934258&r1=934257&r2=934258&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/loader/pref/RequireDlPermProvider.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/loader/pref/RequireDlPermProvider.java Thu Apr 15 01:11:12 2010
@@ -18,15 +18,15 @@
package net.jini.loader.pref;
-import java.rmi.server.RMIClassLoader;
+import net.jini.loader.CodebaseAccessClassLoader;
import net.jini.loader.DownloadPermission;
/**
- * An <code>RMIClassLoader</code> provider that supports preferred
+ * An <code>CodebaseAccessClassLoader</code> provider that supports preferred
* classes and enforces {@link DownloadPermission}.
*
- * <p>See the {@link RMIClassLoader} specification for information
- * about how to install and configure the <code>RMIClassLoader</code>
+ * <p>See the {@link CodebaseAccessClassLoader} specification for information
+ * about how to install and configure the <code>CodebaseAccessClassLoader</code>
* service provider.
*
* @author Sun Microsystems, Inc.
@@ -37,10 +37,10 @@ public class RequireDlPermProvider exten
/**
* Creates a new <code>RequireDlPermProvider</code>.
*
- * <p>This constructor is used by the {@link RMIClassLoader}
+ * <p>This constructor is used by the {@link CodebaseAccessClassLoader}
* service provider location mechanism when
* <code>RequireDlPermProvider</code> is configured as the
- * <code>RMIClassLoader</code> provider class.
+ * <code>CodebaseAccessClassLoader</code> provider class.
*
* <p>This constructor passes <code>true</code> to the superclass
* constructor that has a <code>boolean</code> parameter.
Modified: incubator/river/jtsk/trunk/src/net/jini/security/proxytrust/ProxyTrustVerifier.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/security/proxytrust/ProxyTrustVerifier.java?rev=934258&r1=934257&r2=934258&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/security/proxytrust/ProxyTrustVerifier.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/security/proxytrust/ProxyTrustVerifier.java Thu Apr 15 01:11:12 2010
@@ -31,8 +31,6 @@ import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import java.rmi.UnmarshalException;
-import java.rmi.server.RMIClassLoader;
-import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
@@ -46,6 +44,7 @@ import net.jini.core.constraint.MethodCo
import net.jini.core.constraint.RemoteMethodControl;
import net.jini.io.MarshalInputStream;
import net.jini.io.ObjectStreamContext;
+import net.jini.loader.CodebaseAccessClassLoader;
import net.jini.security.SecurityContext;
import net.jini.security.TrustVerifier;
@@ -228,8 +227,8 @@ public class ProxyTrustVerifier implemen
* method; the class loader of the proxy's class is
* the proper Java(TM) RMI class
* loader (as defined below) for its parent class loader and the class's
- * codebase (as produced by {@link RMIClassLoader#getClassAnnotation
- * RMIClassLoader.getClassAnnotation}); and both <code>ProxyTrust</code>
+ * codebase (as produced by {@link CodebaseAccessClassLoader#getClassAnnotation
+ * CodebaseAccessClassLoader.getClassAnnotation}); and both <code>ProxyTrust</code>
* and <code>RemoteMethodControl</code> are loadable by the parent class
* loader. The derivative that is produced is an instance of a dynamically
* generated <code>Proxy</code> class defined by the parent class loader
@@ -270,7 +269,7 @@ public class ProxyTrustVerifier implemen
* parent class loader and the class's codebase if the class loader is
* not <code>null</code>, the codebase for the class is a non-empty
* string, and calling
- * {@link RMIClassLoader#getClassLoader RMIClassLoader.getClassLoader}
+ * {@link CodebaseAccessClassLoader#getClassLoader CodebaseAccessClassLoader.getClassLoader}
* with that codebase, with the thread's context class loader set to the
* parent class loader, returns the class loader of the class.
*
@@ -413,7 +412,7 @@ public class ProxyTrustVerifier implemen
throws IllegalAccessException,
InvocationTargetException
{
- return m.invoke(obj, null);
+ return m.invoke(obj, (Object[])null);
}
}), rsc.getAccessControlContext());
} catch (PrivilegedActionException pae) {
@@ -513,7 +512,7 @@ public class ProxyTrustVerifier implemen
return null;
}
final Class base = obj.getClass();
- final String bcb = RMIClassLoader.getClassAnnotation(base);
+ final String bcb = CodebaseAccessClassLoader.getClassAnnotation(base);
if (bcb == null || bcb.length() == 0) {
return null;
}
@@ -530,8 +529,9 @@ public class ProxyTrustVerifier implemen
boolean proper = false;
try {
t.setContextClassLoader(pcl);
- proper = (RMIClassLoader.getClassLoader(bcb) == bcl);
- } catch (MalformedURLException e) {
+ proper = (CodebaseAccessClassLoader.getClassLoader(bcb) == bcl);
+ } catch (IOException e) {
+ logger.log(Level.FINER, e.toString()+": Can't get ClassLoader for "+bcb, e);
} finally {
t.setContextClassLoader(ccl);
}
@@ -543,6 +543,7 @@ public class ProxyTrustVerifier implemen
RemoteMethodControl.class},
ih);
} catch (IllegalArgumentException e) {
+ logger.log(Level.FINER, e.toString(), e);
}
}
return null;
@@ -631,7 +632,7 @@ public class ProxyTrustVerifier implemen
}
private void writeAnnotation(final Class c) throws IOException {
- String cb = RMIClassLoader.getClassAnnotation(c);
+ String cb = CodebaseAccessClassLoader.getClassAnnotation(c);
writeObject(cb);
if (bcb.equals(cb)) {
AccessController.doPrivileged(new PrivilegedAction() {
Added: incubator/river/jtsk/trunk/test/src/net/jini/io/ConvertTest.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/test/src/net/jini/io/ConvertTest.java?rev=934258&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/test/src/net/jini/io/ConvertTest.java (added)
+++ incubator/river/jtsk/trunk/test/src/net/jini/io/ConvertTest.java Thu Apr 15 01:11:12 2010
@@ -0,0 +1,103 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.jini.io;
+
+import java.io.IOException;
+import java.rmi.MarshalledObject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ConvertTest {
+
+ public ConvertTest() {
+ }
+ String strObject;
+
+ @org.junit.BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @org.junit.AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @org.junit.Before
+ public void setUp() throws Exception {
+ strObject = "Test String";
+ }
+
+ @org.junit.After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test of toRmiMarshalledObject method, of class Convert.
+ */
+ @org.junit.Test
+ public void toRmiMarshalledObject() {
+ try {
+ System.out.println("toRmiMarshalledObject");
+ CDCMarshalledObject<String> instance_2 = new CDCMarshalledObject<String>(strObject);
+ Convert<String> convert = new Convert<String>();
+ MarshalledObject<String> expResult = new MarshalledObject<String>(strObject);
+ MarshalledObject<String> result = convert.toRmiMarshalledObject(instance_2);
+ assertEquals(expResult, result);
+ //fail("The test case is a prototype.");
+ } catch (Exception ex) {
+ fail("The test threw an exception: " + ex.getMessage());
+ }
+ }
+
+ /**
+ * Test of toMarshalledInstance method, of class Convert.
+ */
+ @org.junit.Test
+ public void toMarshalledInstance() {
+ try {
+ System.out.println("toMarshalledInstance");
+ MarshalledObject<String> instance_2 = new MarshalledObject<String>(strObject);
+ Convert<String> convert = new Convert<String>();
+ MarshalledInstance<String> expResult = new MarshalledInstance<String>(strObject);
+ MarshalledInstance<String> result = convert.toMarshalledInstance(instance_2);
+ assertEquals(expResult, result);
+
+ //fail("The test case is a prototype.");
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ fail("The test threw an exception: " + ex.getMessage());
+ }
+ }
+
+ /**
+ * Test of toCDCMarshalledObject method, of class Convert.
+ */
+ @org.junit.Test
+ public void toCDCMarshalledObject() {
+ try {
+ System.out.println("toCDCMarshalledObject");
+ MarshalledObject<String> instance_2 = new MarshalledObject<String>(strObject);
+ Convert<String> instance = new Convert<String>();
+ CDCMarshalledObject<String> expResult = new CDCMarshalledObject<String>(strObject);
+ CDCMarshalledObject<String> result = instance.toCDCMarshalledObject(instance_2);
+ assertEquals(expResult, result);
+ // TODO review the generated test code and remove the default call to fail.
+ //fail("The test case is a prototype.");
+ } catch (Exception ex) {
+ fail("The test threw an exception: " + ex.getMessage());
+ }
+ // TODO review the generated test code and remove the default call to fail.
+ //fail("The test case is a prototype.");
+ }
+
+}
\ No newline at end of file
Propchange: incubator/river/jtsk/trunk/test/src/net/jini/io/ConvertTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/river/jtsk/trunk/test/src/net/jini/io/PackageVersionTest.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/test/src/net/jini/io/PackageVersionTest.java?rev=934258&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/test/src/net/jini/io/PackageVersionTest.java (added)
+++ incubator/river/jtsk/trunk/test/src/net/jini/io/PackageVersionTest.java Thu Apr 15 01:11:12 2010
@@ -0,0 +1,158 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.jini.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class PackageVersionTest {
+
+ public PackageVersionTest() {
+ }
+ Package[] pkg;
+
+ @org.junit.BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @org.junit.AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @org.junit.Before
+ public void setUp() throws Exception {
+ pkg = Package.getPackages();
+ }
+
+ @org.junit.After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test of getInstance method, of class PackageVersion.
+ */
+ @org.junit.Test
+ public void getInstance() {
+ System.out.println("getInstance");
+ String pkgName = pkg[0].getName();
+ String impVendor = pkg[0].getImplementationVendor();
+ String impVersion = pkg[0].getImplementationVersion();
+ System.out.println(pkgName + "|" + impVendor + "|" +impVersion);
+ PackageVersion expResult = PackageVersion.getInstance(pkg[0]);
+ PackageVersion result = PackageVersion.getInstance(pkgName, impVendor, impVersion);
+ assertEquals(expResult, result);
+ // TODO review the generated test code and remove the default call to fail.
+ // fail("The test case is a prototype.");
+ }
+
+ /**
+ * Test of equals method, of class PackageVersion.
+ */
+ @org.junit.Test
+ public void equalHashCode() {
+ System.out.println("equalsHashCode");
+ Object obj = PackageVersion.getInstance(pkg[1]);
+ String pkgName = pkg[1].getName();
+ String impVendor = pkg[1].getImplementationVendor();
+ String impVersion = pkg[1].getImplementationVersion();
+ System.out.println(pkgName + "|" + impVendor + "|" +impVersion);
+ PackageVersion instance = PackageVersion.getInstance(pkgName, impVendor,
+ impVersion);
+ boolean expResult = true;
+ boolean result = instance.equals(obj);
+ assertEquals(expResult, result);
+ assertEquals(obj.hashCode(), instance.hashCode());
+ // TODO review the generated test code and remove the default call to fail.
+ //fail("The test case is a prototype.");
+ }
+
+ /**
+ * Test of equalsPackage method, of class PackageVersion.
+ */
+ @org.junit.Test
+ public void equalsPackage() {
+ System.out.println("equalsPackage");
+ String pkgName = pkg[1].getName();
+ String impVendor = pkg[1].getImplementationVendor();
+ String impVersion = pkg[1].getImplementationVersion();
+ System.out.println(pkgName + "|" + impVendor + "|" +impVersion);
+ PackageVersion instance = PackageVersion.getInstance(pkg[1]);
+ boolean expResult = true;
+ boolean result = instance.equalsPackage(pkg[1]);
+ assertEquals(expResult, result);
+ // TODO review the generated test code and remove the default call to fail.
+ //fail("The test case is a prototype.");
+ }
+
+ /**
+ * Test of equalsPackage method, of class PackageVersion.
+ */
+ @org.junit.Test
+ public void equalsPackage2() {
+ System.out.println("equalsPackage2");
+ String pkgName = pkg[2].getName();
+ String impVendor = pkg[2].getImplementationVendor();
+ String impVersion = pkg[2].getImplementationVersion();
+ System.out.println(pkgName + "|" + impVendor + "|" +impVersion);
+ PackageVersion instance = PackageVersion.getInstance(pkg[2]);
+ boolean expResult = false;
+ boolean result = instance.equalsPackage(pkg[3]);
+ assertEquals(expResult, result);
+ // TODO review the generated test code and remove the default call to fail.
+ //fail("The test case is a prototype.");
+ }
+
+ /**
+ * Test of equalsPackage method, of class PackageVersion.
+ */
+ @org.junit.Test
+ public void marshalUnmarshal() {
+ System.out.println("marshalUnmarshal");
+ ObjectOutputStream out = null;
+ ObjectInputStream in = null;
+ try {
+ PackageVersion instance = PackageVersion.getInstance(pkg[2]);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ out = new ObjectOutputStream(baos);
+ out.writeObject(instance);
+ // Unmarshall it
+ in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+ PackageVersion result = (PackageVersion) in.readObject();
+ assertEquals(instance, result);
+ // TODO review the generated test code and remove the default call to fail.
+ //fail("The test case is a prototype.");
+ } catch (IOException ex) {
+ System.out.println( ex.getMessage());
+ ex.printStackTrace(System.out);
+ fail("The test case threw an exception.");
+ } catch (ClassNotFoundException ex) {
+ System.out.println( ex.getMessage());
+ ex.printStackTrace(System.out);
+ fail("The test case threw an exception.");
+ } finally {
+ try {
+ out.close();
+ } catch (IOException ex) {
+ System.out.println( ex.getMessage());
+ ex.printStackTrace(System.out);
+ fail("The test case threw an exception.");
+ }
+ }
+ }
+}
Propchange: incubator/river/jtsk/trunk/test/src/net/jini/io/PackageVersionTest.java
------------------------------------------------------------------------------
svn:eol-style = native