You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by si...@apache.org on 2012/10/27 10:14:43 UTC

svn commit: r1402752 - in /river/jtsk/trunk/src/net/jini/loader: RiverClassLoader.java RiverClassLoaderSpi.java

Author: sijskes
Date: Sat Oct 27 08:14:43 2012
New Revision: 1402752

URL: http://svn.apache.org/viewvc?rev=1402752&view=rev
Log:
RIVER-336 related.

Added:
    river/jtsk/trunk/src/net/jini/loader/RiverClassLoader.java
    river/jtsk/trunk/src/net/jini/loader/RiverClassLoaderSpi.java

Added: river/jtsk/trunk/src/net/jini/loader/RiverClassLoader.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/loader/RiverClassLoader.java?rev=1402752&view=auto
==============================================================================
--- river/jtsk/trunk/src/net/jini/loader/RiverClassLoader.java (added)
+++ river/jtsk/trunk/src/net/jini/loader/RiverClassLoader.java Sat Oct 27 08:14:43 2012
@@ -0,0 +1,133 @@
+/*
+ * 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.net.MalformedURLException;
+import java.rmi.server.RMIClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Iterator;
+import java.util.ServiceLoader;
+import java.util.logging.Logger;
+import org.apache.river.common.Beta;
+
+/**
+ *
+ */
+@Beta
+public class RiverClassLoader
+{
+    private final static Logger logger = Logger.getLogger(RiverClassLoader.class.getName());
+    
+    private static final RiverClassLoaderSpi spi = AccessController.doPrivileged(
+            
+            new PrivilegedAction<RiverClassLoaderSpi>()
+            {
+                @Override
+                public RiverClassLoaderSpi run()
+                {
+                    return initSpi();
+                }
+
+            }
+            
+        );
+            
+    private static RiverClassLoaderSpi initSpi()
+    {
+        ServiceLoader<RiverClassLoaderSpi> loader = ServiceLoader.load(RiverClassLoaderSpi.class);
+        
+        Iterator<RiverClassLoaderSpi> iter = loader.iterator();
+        
+        if( iter.hasNext() ) {
+            try {
+                RiverClassLoaderSpi firstSpi = iter.next();
+                return firstSpi ;
+            } catch (Exception e) {
+                logger.severe( "error loading RiverClassLoaderSpi " + e );
+                throw new Error(e);
+            }
+        }
+        
+        return new DefaultRiverClassLoaderSpi();
+    }
+        
+    public static Class<?> loadClass(String codebase, String name, ClassLoader defaultLoader)
+        throws MalformedURLException, ClassNotFoundException
+    {
+        return spi.loadClass(codebase, name, defaultLoader);
+    }
+
+    public static Class<?> loadProxyClass(String codebase, String[] interfaceNames, ClassLoader defaultLoader)
+        throws ClassNotFoundException, MalformedURLException
+    {
+        return spi.loadProxyClass(codebase, interfaceNames, defaultLoader);
+    }
+
+    public static String getClassAnnotation(Class<?> cls)
+    {
+        return spi.getClassAnnotation(cls);
+    }
+
+    public static ClassLoader getClassLoader(String codebase)
+        throws MalformedURLException, SecurityException
+    {
+        return spi.getClassLoader(codebase);
+    }
+
+    public static Class<?> loadClass(String location, String className) 
+        throws MalformedURLException, ClassNotFoundException
+    {
+        return spi.loadClass(className, className, null);
+    }
+
+    private static class DefaultRiverClassLoaderSpi 
+        extends RiverClassLoaderSpi
+    {
+
+        public DefaultRiverClassLoaderSpi()
+        {
+        }
+
+        @Override
+        public Class<?> loadClass(String codebase, String name, ClassLoader defaultLoader) throws MalformedURLException, ClassNotFoundException
+        {
+            return RMIClassLoader.loadClass(codebase, name, defaultLoader);
+        }
+
+        @Override
+        public Class<?> loadProxyClass(String codebase, String[] interfaceNames, ClassLoader defaultLoader) throws ClassNotFoundException, MalformedURLException
+        {
+            return RMIClassLoader.loadProxyClass(codebase, interfaceNames, defaultLoader);
+        }
+
+        @Override
+        public String getClassAnnotation(Class<?> cl)
+        {
+            return RMIClassLoader.getClassAnnotation(cl); 
+        }
+
+        @Override
+        public ClassLoader getClassLoader(String codebase) throws MalformedURLException
+        {
+            return RMIClassLoader.getClassLoader(codebase);
+        }
+    }
+    
+}

Added: river/jtsk/trunk/src/net/jini/loader/RiverClassLoaderSpi.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/loader/RiverClassLoaderSpi.java?rev=1402752&view=auto
==============================================================================
--- river/jtsk/trunk/src/net/jini/loader/RiverClassLoaderSpi.java (added)
+++ river/jtsk/trunk/src/net/jini/loader/RiverClassLoaderSpi.java Sat Oct 27 08:14:43 2012
@@ -0,0 +1,42 @@
+/*
+ * 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.net.MalformedURLException;
+import org.apache.river.common.Beta;
+
+/**
+ *
+ */
+@Beta
+public abstract class RiverClassLoaderSpi
+{
+    
+    public abstract Class<?> loadClass(String codebase, String name, ClassLoader defaultLoader)
+        throws MalformedURLException, ClassNotFoundException ;
+
+    public abstract Class<?> loadProxyClass(String codebase, String[] interfaceNames, ClassLoader defaultLoader)
+        throws ClassNotFoundException, MalformedURLException ;
+
+    public abstract String getClassAnnotation(Class<?> cl);
+
+    public abstract ClassLoader getClassLoader(String codebase)
+        throws MalformedURLException, SecurityException ;
+
+}