You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jb...@apache.org on 2010/12/13 19:26:35 UTC
svn commit: r1045274 [4/7] - in
/incubator/aries/sandbox/jbohn/interceptor-proto: ./ application/
application/application-api/src/main/java/org/apache/aries/application/
application/application-api/src/main/java/org/apache/aries/application/management/...
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/application-utils/src/test/java/org/apache/aries/application/utils/filesystem/IOUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/application-utils/src/test/java/org/apache/aries/application/utils/filesystem/IOUtilsTest.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/application-utils/src/test/java/org/apache/aries/application/utils/filesystem/IOUtilsTest.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/application-utils/src/test/java/org/apache/aries/application/utils/filesystem/IOUtilsTest.java Mon Dec 13 18:26:19 2010
@@ -31,23 +31,17 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.StringBufferInputStream;
import java.util.zip.ZipFile;
+import org.apache.aries.application.filesystem.IDirectory;
import org.apache.aries.application.filesystem.IFile;
-import org.apache.aries.application.utils.filesystem.impl.FileImpl;
import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.Test;
public class IOUtilsTest
{
- @BeforeClass
- public static void setup()
- {
- new File("ioUtilsTest").mkdir();
- }
-
@AfterClass
public static void cleanUp()
{
@@ -56,22 +50,38 @@ public class IOUtilsTest
}
@Test
- public void testZipUp() throws IOException
+ public void testZipUpAndUnzipAndDeleteRecursive() throws IOException
{
+ new File ("ioUtilsTest").mkdir();
IOUtils.zipUp(new File("../src/test/resources/zip"), new File("ioUtilsTest/test.zip"));
ZipFile zip = new ZipFile("ioUtilsTest/test.zip");
assertNotNull(zip.getEntry("file.txt"));
assertNotNull(zip.getEntry("subdir/someFile.txt"));
zip.close();
+
+ IDirectory dir = FileSystem.getFSRoot(new File("ioUtilsTest"));
+ IFile izip = dir.getFile("test.zip");
+ File output = new File("ioUtilsTest/zipout");
+ output.mkdirs();
+ IOUtils.unpackZip(izip, output);
+ File a = new File(output,"file.txt");
+ File b = new File(output,"subdir");
+ File c = new File(b,"someFile.txt");
+ assertTrue(output.exists());
+ assertTrue(a.exists() && a.isFile());
+ assertTrue(b.exists() && b.isDirectory());
+ assertTrue(c.exists() && c.isFile());
+
+ IOUtils.deleteRecursive(output);
+ assertFalse(output.exists());
}
@Test
public void testWriteOut() throws IOException
{
File tmpDir = new File("ioUtilsTest/tmp");
- // Do not call mkdirs() on tmpDir. writeOut() should create it.
- // tmpDir.mkdirs();
+ tmpDir.mkdir();
IOUtils.writeOut(tmpDir, "simple.txt", new StringBufferInputStream("abc"));
IOUtils.writeOut(tmpDir, "some/relative/directory/complex.txt", new StringBufferInputStream("def"));
@@ -121,7 +131,7 @@ public class IOUtilsTest
fail("Close was invoked");
}
};
- File f = new File("unittest/outtest1");
+ File f = new File("ioUtilsTest/outtest1");
f.mkdirs();
IOUtils.writeOutAndDontCloseInputStream(f, "/fred", is);
File fred = new File(f,"/fred");
@@ -132,48 +142,90 @@ public class IOUtilsTest
}
- @Test
- public void testEmptyDirectory() throws IOException {
- /* Create a .zip with a single entry, an empty directory inside.
- * Confirm that the directory is recreated on unzip.
- */
- File testDir = new File ("unittest/emptyDirTest/");
- File parent = new File (testDir, "emptyTestRootDir/");
- File emptyDir = new File (parent, "foo/");
- emptyDir.mkdirs();
- assertTrue (emptyDir.exists());
-
- File zipWithEmptyDir = new File (testDir, "empty.zip");
- IOUtils.zipUp(parent, zipWithEmptyDir);
-
- emptyDir.delete();
- assertFalse (emptyDir.exists());
-
- IFile zip = new FileImpl(zipWithEmptyDir, testDir);
- IOUtils.unpackZip(zip, parent);
- assertTrue (emptyDir.exists());
+ @Test
+ public void testCopy() throws IOException{
+ InputStream is = new InputStream(){
+ boolean closed=false;
+ int idx=0;
+ int data[]=new int[]{1,2,3,4,5,-1};
+ @Override
+ public int read() throws IOException
+ {
+ if(idx<data.length)
+ return data[idx++];
+ else
+ return -1;
+ }
+ @Override
+ public void close() throws IOException
+ {
+ closed=true;
+ }
+ @Override
+ public int available() throws IOException
+ {
+ if(!closed)
+ return super.available();
+ else
+ return 123456789;
+ }
+
+ };
+
+ OutputStream os = new OutputStream(){
+ int idx=0;
+ int data[]=new int[]{1,2,3,4,5,-1};
+ @Override
+ public void write(int b) throws IOException
+ {
+ if(b!=data[idx++]){
+ fail("Data written to outputstream was not as expected");
+ }
+ }
+ };
+
+ IOUtils.copy(is,os);
+ if(is.available()!=123456789){
+ fail("close was not invoked");
+ }
+
+
}
@Test
- public void testSingleRootLevelEntry() throws IOException {
- /* Create a .zip with a single entry, a root-level file.
- * Confirm that the file is recreated on unzip.
- */
- File testDir = new File ("unittest/singleFileInZipTest/");
- File parent = new File (testDir, "singleFileRootDir/");
- File entry = new File (parent, "foo.txt");
- entry.mkdirs();
- assertTrue (entry.exists());
-
- File zipWithSingleFileInRootdir = new File (testDir, "singleFile.zip");
- IOUtils.zipUp(parent, zipWithSingleFileInRootdir);
-
- entry.delete();
- assertFalse (entry.exists());
-
- IFile zip = new FileImpl(zipWithSingleFileInRootdir, testDir);
- IOUtils.unpackZip(zip, parent);
- assertTrue (entry.exists());
+ public void testCopyAndDoNotClose() throws IOException{
+
+ InputStream is = new InputStream(){
+ int idx=0;
+ int data[]=new int[]{1,2,3,4,5,-1};
+ @Override
+ public int read() throws IOException
+ {
+ if(idx<data.length)
+ return data[idx++];
+ else
+ return -1;
+ }
+ @Override
+ public void close() throws IOException
+ {
+ fail("Close invoked");
+ }
+ };
+
+ OutputStream os = new OutputStream(){
+ int idx=0;
+ int data[]=new int[]{1,2,3,4,5,-1};
+ @Override
+ public void write(int b) throws IOException
+ {
+ if(b!=data[idx++]){
+ fail("Data written to outputstream was not as expected");
+ }
+ }
+ };
+
+ IOUtils.copyAndDoNotCloseInputStream(is,os);
+
}
}
-
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/application/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/application/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/application/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/application/pom.xml Mon Dec 13 18:26:19 2010
@@ -20,6 +20,7 @@
<groupId>org.apache.aries</groupId>
<artifactId>java5-parent</artifactId>
<version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>../parent/default-parent/java5-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -211,10 +212,10 @@
<module>application-management</module>
<module>application-converters</module>
<module>application-runtime</module>
- <module>application-runtime-isolated</module>
- <module>application-runtime-framework</module>
- <module>application-runtime-framework-management</module>
- <module>application-runtime-repository</module>
+ <module>application-runtime-isolated</module>
+ <module>application-runtime-framework</module>
+ <module>application-runtime-framework-management</module>
+ <module>application-runtime-repository</module>
<module>application-itest-interface</module>
<module>application-itests</module>
<module>application-obr-resolver</module>
@@ -224,10 +225,10 @@
<module>application-deployment-management</module>
<module>application-modeller</module>
<module>application-noop-platform-repository</module>
- <module>application-noop-postresolve-process</module>
- <module>application-default-local-platform</module>
+ <module>application-noop-postresolve-process</module>
+ <module>application-default-local-platform</module>
<module>application-itest-twitter</module>
-
+ <module>application-twitter4j</module>
</modules>
<build>
Propchange: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Dec 13 18:26:19 2010
@@ -5,3 +5,5 @@ target
.classpath
.project
.settings
+velocity.log
+bin
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/BlueprintEvent.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/BlueprintEvent.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/BlueprintEvent.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/BlueprintEvent.java Mon Dec 13 18:26:19 2010
@@ -226,7 +226,8 @@ public class BlueprintEvent {
this.timestamp = System.currentTimeMillis();
this.bundle = bundle;
this.extenderBundle = extenderBundle;
- this.dependencies = dependencies;
+ this.dependencies = dependencies == null ? null
+ : (String[]) dependencies.clone();;
this.cause = cause;
this.replay = false;
if (bundle == null) {
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-bundle/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-bundle/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-bundle/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-bundle/pom.xml Mon Dec 13 18:26:19 2010
@@ -35,12 +35,15 @@
${project.artifactId};blueprint.graceperiod:=false
</aries.osgi.symbolic.name>
<aries.osgi.activator>
- org.apache.aries.blueprint.container.BlueprintExtender
+ org.apache.aries.blueprint.uberbundle.UberActivator
</aries.osgi.activator>
<aries.osgi.import>
!org.apache.aries.blueprint*,
!org.osgi.service.blueprint*,
- !org.objectweb.asm*;version="[3.1,4)";resolution:=optional,
+ !org.objectweb.asm*,
+ org.eclipse.osgi.internal.loader;resolution:=optional,
+ org.eclipse.osgi.framework.internal.core;resolution:=optional,
+ org.eclipse.osgi.framework.adaptor;resolution:=optional,
org.osgi.service.event*;resolution:=optional,
org.osgi.service.framework;resolution:=optional,
org.osgi.service.cm;version="[1.2.0,2.0.0)",
@@ -54,12 +57,13 @@
org.osgi.service.blueprint.container;version="1.0.1",
org.osgi.service.blueprint.reflect;version="1.0.1",
!org.apache.aries.blueprint.annotation*,
- org.apache.aries.blueprint*;version="${pom.version}"
+ org.apache.aries.blueprint*;version="${pom.version}",
+ org.apache.aries.proxy;version=0.3-incubating-SNAPSHOT
</aries.osgi.export>
<aries.osgi.private.pkg>
- org.apache.aries.util.tracker,
- org.objectweb.asm,
- org.objectweb.asm.commons,
+ org.apache.aries.proxy*,
+ org.objectweb.asm*,
+ org.apache.aries.util*,
OSGI-INF*
</aries.osgi.private.pkg>
<aries.osgi.export.service>
@@ -91,6 +95,11 @@
<artifactId>org.apache.aries.blueprint.cm</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.aries.proxy</groupId>
+ <artifactId>org.apache.aries.proxy</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<groupId>asm</groupId>
<artifactId>asm-all</artifactId>
<optional>true</optional>
Propchange: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Dec 13 18:26:19 2010
@@ -3,3 +3,4 @@ target
.settings
.classpath
.project
+velocity.log
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/pom.xml Mon Dec 13 18:26:19 2010
@@ -101,13 +101,16 @@
<dependency>
<groupId>org.apache.aries.quiesce</groupId>
<artifactId>org.apache.aries.quiesce.api</artifactId>
- <version>0.3-incubating-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.aries.testsupport</groupId>
<artifactId>org.apache.aries.testsupport.unit</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.aries.proxy</groupId>
+ <artifactId>org.apache.aries.proxy.api</artifactId>
+ </dependency>
</dependencies>
<build>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentNameAlreadyInUseException.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentNameAlreadyInUseException.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentNameAlreadyInUseException.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentNameAlreadyInUseException.java Mon Dec 13 18:26:19 2010
@@ -16,19 +16,18 @@
*/
package org.apache.aries.blueprint;
+
public class ComponentNameAlreadyInUseException extends RuntimeException {
-
- private String conflictingName;
+ private String conflictingName;
- public ComponentNameAlreadyInUseException(String conflictingName) {
- this.conflictingName = conflictingName;
- }
-
- public String getMessage() {
- return "Name '" + this.conflictingName + "' is already in use by a registered component";
- }
+ public ComponentNameAlreadyInUseException(String conflictingName) {
+ this.conflictingName = conflictingName;
+ }
+
+ public String getMessage() {
+ return "Name '" + this.conflictingName + "' is already in use by a registered component";
+ }
- public String getConflictingName() {
- return this.conflictingName;
- }
-}
+ public String getConflictingName() {
+ return this.conflictingName;
+ }}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java Mon Dec 13 18:26:19 2010
@@ -43,10 +43,9 @@ import org.apache.aries.blueprint.Extend
import org.apache.aries.blueprint.di.AbstractRecipe;
import org.apache.aries.blueprint.di.CollectionRecipe;
import org.apache.aries.blueprint.di.Recipe;
-import org.apache.aries.blueprint.proxy.AsmInterceptorWrapper;
-import org.apache.aries.blueprint.proxy.UnableToProxyException;
import org.apache.aries.blueprint.utils.BundleDelegatingClassLoader;
import org.apache.aries.blueprint.utils.ReflectionUtils;
+import org.apache.aries.proxy.UnableToProxyException;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
@@ -78,7 +77,6 @@ public abstract class AbstractServiceRef
protected final ServiceReferenceMetadata metadata;
protected final CollectionRecipe listenersRecipe;
protected final List<Recipe> explicitDependencies;
- protected final ClassLoader proxyClassLoader;
protected final boolean optional;
/** The OSGi filter for tracking references */
protected final String filter;
@@ -89,7 +87,6 @@ public abstract class AbstractServiceRef
private final AtomicBoolean started = new AtomicBoolean();
private final AtomicBoolean satisfied = new AtomicBoolean();
private SatisfactionListener satisfactionListener;
- private volatile ProxyFactory proxyFactory;
protected AbstractServiceReferenceRecipe(String name,
ExtendedBlueprintContainer blueprintContainer,
@@ -104,57 +101,12 @@ public abstract class AbstractServiceRef
this.explicitDependencies = explicitDependencies;
- this.proxyClassLoader = makeProxyClassLoader(blueprintContainer, metadata);
-
this.optional = (metadata.getAvailability() == ReferenceMetadata.AVAILABILITY_OPTIONAL);
this.filter = createOsgiFilter(metadata);
}
- // Create a ClassLoader delegating to the bundle, but also being able to see our bundle classes
- // so that the created proxy can access cglib classes.
- // TODO: we should be able to get rid of this classloader when using JDK 1.4 proxies with a single interface
- // (the case defined by the spec) and use the interface classloader instead
- private ClassLoader makeProxyClassLoader(
- final ExtendedBlueprintContainer blueprintContainer,
- ServiceReferenceMetadata metadata) {
-
- Class typeClass = getInterfaceClass();
- if (typeClass == null) {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return new BundleDelegatingClassLoader(blueprintContainer.getBundleContext().getBundle(),
- AbstractServiceReferenceRecipe.class.getClassLoader());
- }
- });
- }
-
- final ClassLoader interfaceClassLoader = typeClass.getClassLoader();
-
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return new DualClassloader(interfaceClassLoader);
- }
- });
- }
-
- private static class DualClassloader extends ClassLoader {
- DualClassloader(ClassLoader parent) {
- super(parent);
- }
-
- @Override
- protected Class<?> findClass(String name) throws ClassNotFoundException {
- return getClass().getClassLoader().loadClass(name);
- }
-
- @Override
- protected URL findResource(String name) {
- return getClass().getClassLoader().getResource(name);
- }
- }
-
public CollectionRecipe getListenersRecipe() {
return listenersRecipe;
}
@@ -252,10 +204,10 @@ public abstract class AbstractServiceRef
}
}
- protected List<Class> loadAllClasses(Iterable<String> interfaceNames) {
- List<Class> classes = new ArrayList<Class>();
+ protected List<Class<?>> loadAllClasses(Iterable<String> interfaceNames) {
+ List<Class<?>> classes = new ArrayList<Class<?>>();
for (String name : interfaceNames) {
- Class clazz = loadClass(name);
+ Class<?> clazz = loadClass(name);
classes.add(clazz);
}
return classes;
@@ -277,46 +229,14 @@ public abstract class AbstractServiceRef
}
- protected Object createProxy(final Callable<Object> dispatcher, Set<Class> interfaces) throws Exception {
+ protected Object createProxy(final Callable<Object> dispatcher, Set<Class<?>> interfaces) throws Exception {
if (!interfaces.iterator().hasNext()) {
return new Object();
} else {
- return getProxyFactory().createProxy(proxyClassLoader, toClassArray(interfaces), dispatcher);
+ return BlueprintExtender.getProxyManager().createProxy(blueprintContainer.getBundleContext().getBundle(), interfaces, dispatcher);
}
}
- protected synchronized ProxyFactory getProxyFactory() throws ClassNotFoundException {
- if (proxyFactory == null) {
- boolean proxyClass = false;
- if (metadata instanceof ExtendedServiceReferenceMetadata) {
- proxyClass = (((ExtendedServiceReferenceMetadata) metadata).getProxyMethod() & ExtendedServiceReferenceMetadata.PROXY_METHOD_CLASSES) != 0;
- }
- if (!proxyClass) {
- Set<Class> interfaces = new HashSet<Class>();
- Class clz = getInterfaceClass();
- if (clz != null) interfaces.add(clz);
-
- for (Class cl : interfaces) {
- if (!cl.isInterface()) {
- throw new ComponentDefinitionException("A class " + cl.getName() + " was found in the interfaces list, but class proxying is not allowed by default. The ext:proxy-method='classes' attribute needs to be added to this service reference.");
- }
- }
- }
- try {
- // Try load load a asm class (to make sure it's actually available
- // then create the asm factory
- getClass().getClassLoader().loadClass("org.objectweb.asm.ClassVisitor");
- proxyFactory = new AsmProxyFactory();
- } catch (Throwable t) {
- if (proxyClass) {
- throw new ComponentDefinitionException("Class proxying has been enabled but cglib can not be used", t);
- }
- proxyFactory = new JdkProxyFactory();
- }
- }
- return proxyFactory;
- }
-
public void serviceChanged(ServiceEvent event) {
int eventType = event.getType();
ServiceReference ref = event.getServiceReference();
@@ -610,38 +530,4 @@ public abstract class AbstractServiceRef
return classes.toArray(new Class [classes.size()]);
}
- public static interface ProxyFactory {
-
- public Object createProxy(ClassLoader classLoader, Class[] classes, Callable<Object> dispatcher);
-
- }
-
- public static class JdkProxyFactory implements ProxyFactory {
-
- public Object createProxy(final ClassLoader classLoader, final Class[] classes, final Callable<Object> dispatcher) {
- return Proxy.newProxyInstance(classLoader, getInterfaces(classes), new InvocationHandler() {
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- try {
- return method.invoke(dispatcher.call(), args);
- } catch (InvocationTargetException ite) {
- throw ite.getTargetException();
- }
- }
- });
- }
-
- }
-
- public static class AsmProxyFactory implements ProxyFactory {
-
- public Object createProxy(final ClassLoader classLoader, final Class[] classes, final Callable<Object> dispatcher) {
- try {
- return AsmInterceptorWrapper.createProxyObject(classLoader, null, null, dispatcher, classes);
- } catch (UnableToProxyException e) {
- throw new ComponentDefinitionException("Unable to create asm proxy", e);
- }
- }
-
- }
-
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java Mon Dec 13 18:26:19 2010
@@ -39,11 +39,12 @@ import org.apache.aries.blueprint.Extend
import org.apache.aries.blueprint.Interceptor;
import org.apache.aries.blueprint.di.AbstractRecipe;
import org.apache.aries.blueprint.di.Recipe;
-import org.apache.aries.blueprint.proxy.AsmInterceptorWrapper;
-import org.apache.aries.blueprint.proxy.UnableToProxyException;
+import org.apache.aries.blueprint.proxy.Collaborator;
+import org.apache.aries.blueprint.proxy.ProxyUtils;
import org.apache.aries.blueprint.utils.InterceptorManager;
import org.apache.aries.blueprint.utils.ReflectionUtils;
import org.apache.aries.blueprint.utils.ReflectionUtils.PropertyDescriptor;
+import org.osgi.framework.FrameworkUtil;
import org.osgi.service.blueprint.container.ComponentDefinitionException;
import org.osgi.service.blueprint.container.ReifiedType;
import org.osgi.service.blueprint.reflect.BeanMetadata;
@@ -668,7 +669,7 @@ public class BeanRecipe extends Abstract
return obj;
}
- private Object addInterceptors(Object original)
+ private Object addInterceptors(final Object original)
throws ComponentDefinitionException {
Object intercepted = null;
@@ -694,10 +695,10 @@ public class BeanRecipe extends Abstract
// if asm is available we can proxy the original object with the
// AsmInterceptorWrapper
try {
- intercepted = AsmInterceptorWrapper.createProxyObject(original
- .getClass().getClassLoader(), interceptorLookupKey, interceptors,
- AsmInterceptorWrapper.passThrough(original), original.getClass());
- } catch (UnableToProxyException e) {
+ intercepted = BlueprintExtender.getProxyManager().createProxy(FrameworkUtil.getBundle(original.getClass()),
+ ProxyUtils.asList(original.getClass()), ProxyUtils.passThrough(original),
+ new Collaborator(interceptorLookupKey, interceptors));
+ } catch (org.apache.aries.proxy.UnableToProxyException e) {
throw new ComponentDefinitionException("Unable to create asm proxy", e);
}
} else {
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java Mon Dec 13 18:26:19 2010
@@ -263,7 +263,7 @@ public class BlueprintContainerImpl impl
}
}
if (missing.size() > 0) {
- LOGGER.warn("Bundle " + bundleContext.getBundle().getSymbolicName() + " is waiting for namespace handlers " + missing);
+ LOGGER.info("Bundle {} is waiting for namespace handlers ", bundleContext.getBundle().getSymbolicName(), missing);
eventDispatcher.blueprintEvent(new BlueprintEvent(BlueprintEvent.GRACE_PERIOD, getBundleContext().getBundle(), getExtenderBundle(), missing.toArray(new String[missing.size()])));
return;
}
@@ -302,6 +302,7 @@ public class BlueprintContainerImpl impl
if (waitForDependencies) {
String[] missingDependencies = getMissingDependencies();
if (missingDependencies.length > 0) {
+ LOGGER.info("Bundle {} is waiting for dependencies {}", bundleContext.getBundle().getSymbolicName(), Arrays.asList(missingDependencies));
eventDispatcher.blueprintEvent(new BlueprintEvent(BlueprintEvent.GRACE_PERIOD, getBundleContext().getBundle(), getExtenderBundle(), missingDependencies));
return;
}
@@ -317,6 +318,7 @@ public class BlueprintContainerImpl impl
if (waitForDependencies) {
String[] missingDependencies = getMissingDependencies();
if (missingDependencies.length > 0) {
+ LOGGER.info("Bundle {} is waiting for dependencies {}", bundleContext.getBundle().getSymbolicName(), Arrays.asList(missingDependencies));
eventDispatcher.blueprintEvent(new BlueprintEvent(BlueprintEvent.GRACE_PERIOD, getBundleContext().getBundle(), getExtenderBundle(), missingDependencies));
return;
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java Mon Dec 13 18:26:19 2010
@@ -31,6 +31,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.aries.blueprint.BlueprintConstants;
import org.apache.aries.blueprint.ParserService;
@@ -38,6 +39,9 @@ import org.apache.aries.blueprint.annota
import org.apache.aries.blueprint.namespace.NamespaceHandlerRegistryImpl;
import org.apache.aries.blueprint.utils.HeaderParser;
import org.apache.aries.blueprint.utils.HeaderParser.PathElement;
+import org.apache.aries.proxy.ProxyManager;
+import org.apache.aries.util.SingleServiceTracker;
+import org.apache.aries.util.SingleServiceTracker.SingleServiceListener;
import org.apache.aries.util.tracker.RecursiveBundleTracker;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
@@ -50,6 +54,8 @@ import org.osgi.framework.SynchronousBun
import org.osgi.service.blueprint.container.BlueprintContainer;
import org.osgi.service.blueprint.container.BlueprintEvent;
import org.osgi.util.tracker.BundleTrackerCustomizer;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,37 +78,50 @@ public class BlueprintExtender implement
private RecursiveBundleTracker bt;
private ServiceRegistration parserServiceReg;
private ServiceRegistration quiesceParticipantReg;
-
- public void start(BundleContext context) {
+ private static SingleServiceTracker<ProxyManager> proxyManager;
+
+ public void start(BundleContext ctx) {
LOGGER.debug("Starting blueprint extender...");
- this.context = context;
- handlers = new NamespaceHandlerRegistryImpl(context);
+ this.context = ctx;
+ handlers = new NamespaceHandlerRegistryImpl(ctx);
executors = Executors.newScheduledThreadPool(3, new BlueprintThreadFactory("Blueprint Extender"));
- eventDispatcher = new BlueprintEventDispatcher(context, executors);
+ eventDispatcher = new BlueprintEventDispatcher(ctx, executors);
containers = new HashMap<Bundle, BlueprintContainerImpl>();
int stateMask = Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE
| Bundle.STOPPING;
- bt = new RecursiveBundleTracker(context, stateMask, new BlueprintBundleTrackerCustomizer());
- bt.open();
-
+ bt = new RecursiveBundleTracker(ctx, stateMask, new BlueprintBundleTrackerCustomizer());
+
+ proxyManager = new SingleServiceTracker<ProxyManager>(ctx, ProxyManager.class, new SingleServiceListener() {
+ public void serviceFound() {
+ LOGGER.debug("Found ProxyManager service, starting to process blueprint bundles");
+ bt.open();
+ }
+ public void serviceLost() {
+ // TODO we should probably close here, not sure.
+ }
+ public void serviceReplaced() {
+ }
+ });
+ proxyManager.open();
+
// Create and publish a ParserService
- parserServiceReg = context.registerService(ParserService.class.getName(),
+ parserServiceReg = ctx.registerService(ParserService.class.getName(),
new ParserServiceImpl (handlers),
new Hashtable<Object, Object>());
try{
- context.getBundle().loadClass(QUIESCE_PARTICIPANT_CLASS);
+ ctx.getBundle().loadClass(QUIESCE_PARTICIPANT_CLASS);
//Class was loaded, register
- quiesceParticipantReg = context.registerService(QUIESCE_PARTICIPANT_CLASS,
- new BlueprintQuiesceParticipant(context, this),
+ quiesceParticipantReg = ctx.registerService(QUIESCE_PARTICIPANT_CLASS,
+ new BlueprintQuiesceParticipant(ctx, this),
new Hashtable<Object, Object>());
}
catch (ClassNotFoundException e)
{
- LOGGER.info("No quiesce support is available, so blueprint components will not participate in quiesce operations", e);
+ LOGGER.info("No quiesce support is available, so blueprint components will not participate in quiesce operations");
}
LOGGER.debug("Blueprint extender started");
@@ -154,6 +173,14 @@ public class BlueprintExtender implement
executors.shutdown();
LOGGER.debug("Blueprint extender stopped");
}
+
+ /**
+ * @return the proxy manager. This will return null if the blueprint is not yet managing bundles.
+ */
+ public static ProxyManager getProxyManager()
+ {
+ return proxyManager.getService();
+ }
private List<Bundle> getBundlesToDestroy() {
List<Bundle> bundlesToDestroy = new ArrayList<Bundle>();
@@ -304,7 +331,7 @@ public class BlueprintExtender implement
boolean compatible;
if (bundle.getState() == Bundle.ACTIVE) {
try {
- Class clazz = bundle.getBundleContext().getBundle().loadClass(BlueprintContainer.class.getName());
+ Class<?> clazz = bundle.getBundleContext().getBundle().loadClass(BlueprintContainer.class.getName());
compatible = (clazz == BlueprintContainer.class);
} catch (ClassNotFoundException e) {
compatible = true;
@@ -365,7 +392,7 @@ public class BlueprintExtender implement
}
private void addEntries(Bundle bundle, String path, String filePattern, List<Object> pathList) {
- Enumeration e = bundle.findEntries(path, filePattern, false);
+ Enumeration<?> e = bundle.findEntries(path, filePattern, false);
while (e != null && e.hasMoreElements()) {
URL u = (URL) e.nextElement();
URL override = getOverrideURL(bundle, u, path);
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintQuiesceParticipant.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintQuiesceParticipant.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintQuiesceParticipant.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintQuiesceParticipant.java Mon Dec 13 18:26:19 2010
@@ -61,6 +61,7 @@ public class BlueprintQuiesceParticipant
public void quiesce(QuiesceCallback callback, List<Bundle> bundlesToQuiesce)
{
+ boolean shutdownMe = false;
for(Bundle b : bundlesToQuiesce)
{
try
@@ -70,10 +71,11 @@ public class BlueprintQuiesceParticipant
catch (RejectedExecutionException re) {
}
- //If we are quiescing, then we need to quiesce this threadpool!
- if(b.equals(ctx.getBundle()))
- executor.shutdown();
+ //If we are quiescing, then we need to quiesce this threadpool!
+ shutdownMe |= b.equals(ctx.getBundle());
}
+
+ if (shutdownMe) executor.shutdown();
}
/**
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java Mon Dec 13 18:26:19 2010
@@ -110,8 +110,8 @@ public class ReferenceListRecipe extends
}
} else {
dispatcher = new ServiceDispatcher(reference);
- Set<Class> interfaces = new HashSet<Class>();
- Class clz = getInterfaceClass();
+ Set<Class<?>> interfaces = new HashSet<Class<?>>();
+ Class<?> clz = getInterfaceClass();
if (clz != null) interfaces.add(clz);
if (metadata instanceof ExtendedReferenceListMetadata) {
boolean greedy = (((ExtendedReferenceListMetadata) metadata).getProxyMethod() & ExtendedReferenceListMetadata.PROXY_METHOD_GREEDY) != 0;
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java Mon Dec 13 18:26:19 2010
@@ -75,8 +75,8 @@ public class ReferenceRecipe extends Abs
}
}
// Create the proxy
- Set<Class> interfaces = new HashSet<Class>();
- Class clz = getInterfaceClass();
+ Set<Class<?>> interfaces = new HashSet<Class<?>>();
+ Class<?> clz = getInterfaceClass();
if (clz != null) interfaces.add(clz);
proxy = createProxy(new ServiceDispatcher(), interfaces);
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java Mon Dec 13 18:26:19 2010
@@ -17,13 +17,11 @@
package org.apache.aries.blueprint.container;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -31,18 +29,24 @@ import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.aries.blueprint.*;
+import org.apache.aries.blueprint.BlueprintConstants;
+import org.apache.aries.blueprint.ComponentDefinitionRegistry;
+import org.apache.aries.blueprint.ExtendedBlueprintContainer;
+import org.apache.aries.blueprint.Interceptor;
+import org.apache.aries.blueprint.ServiceProcessor;
import org.apache.aries.blueprint.di.AbstractRecipe;
import org.apache.aries.blueprint.di.CollectionRecipe;
import org.apache.aries.blueprint.di.MapRecipe;
import org.apache.aries.blueprint.di.Recipe;
import org.apache.aries.blueprint.di.Repository;
-import org.apache.aries.blueprint.proxy.AsmInterceptorWrapper;
-import org.apache.aries.blueprint.proxy.FinalModifierException;
+import org.apache.aries.blueprint.proxy.Collaborator;
+import org.apache.aries.blueprint.proxy.ProxyUtils;
import org.apache.aries.blueprint.utils.JavaUtils;
import org.apache.aries.blueprint.utils.ReflectionUtils;
+import org.apache.aries.proxy.InvocationHandlerWrapper;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
@@ -53,8 +57,6 @@ import org.osgi.service.blueprint.reflec
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static java.lang.reflect.Modifier.isFinal;
-
/**
* A <code>Recipe</code> to export services into the OSGi registry.
*
@@ -454,22 +456,20 @@ public class ServiceRecipe extends Abstr
Object intercepted;
try {
+ Bundle b = FrameworkUtil.getBundle(original.getClass());
+ Callable<Object> target = ProxyUtils.passThrough(original);
+ InvocationHandlerWrapper collaborator = new Collaborator(cm, interceptors);
try {
- // Try with subclass proxying first
- intercepted = AsmInterceptorWrapper.createProxyObject(
- original.getClass().getClassLoader(), cm,
- interceptors, AsmInterceptorWrapper.passThrough(original),
- original.getClass());
- } catch (FinalModifierException u) {
+ intercepted = BlueprintExtender.getProxyManager().createProxy(b,
+ ProxyUtils.asList(original.getClass()), target, collaborator);
+ } catch (org.apache.aries.proxy.FinalModifierException u) {
LOGGER.debug("Error creating asm proxy (final modifier), trying with interfaces");
- List<Class> classes = new ArrayList<Class>();
+ List<Class<?>> classes = new ArrayList<Class<?>>();
for (String className : getClasses()) {
classes.add(blueprintContainer.loadClass(className));
}
- intercepted = AsmInterceptorWrapper.createProxyObject(
- original.getClass().getClassLoader(), cm,
- interceptors, AsmInterceptorWrapper.passThrough(original),
- classes.toArray(new Class[classes.size()]));
+ intercepted = BlueprintExtender.getProxyManager().createProxy(b,
+ classes, target, collaborator);
}
} catch (Throwable u) {
LOGGER.info("A problem occurred trying to create a proxy object. Returning the original object instead.", u);
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/Collaborator.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/Collaborator.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/Collaborator.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/Collaborator.java Mon Dec 13 18:26:19 2010
@@ -20,14 +20,12 @@ package org.apache.aries.blueprint.proxy
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
import java.util.List;
import java.util.Stack;
-import java.util.concurrent.Callable;
import org.apache.aries.blueprint.Interceptor;
+import org.apache.aries.proxy.InvocationHandlerWrapper;
import org.osgi.service.blueprint.reflect.ComponentMetadata;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,7 +34,7 @@ import org.slf4j.LoggerFactory;
* A collaborator which ensures preInvoke and postInvoke occur before and after
* method invocation
*/
-class Collaborator implements InvocationHandler, Serializable {
+public class Collaborator implements InvocationHandlerWrapper, Serializable {
/** Serial version UID for this class */
private static final long serialVersionUID = -58189302118314469L;
@@ -44,45 +42,11 @@ class Collaborator implements Invocation
private static final Logger LOGGER = LoggerFactory
.getLogger(Collaborator.class);
- /** The invocation handler to call */
- final InvocationHandler delegate;
- final Callable<?> object;
-
private transient List<Interceptor> interceptors = null;
private transient ComponentMetadata cm = null;
- Collaborator(ComponentMetadata cm, List<Interceptor> interceptors,
- final Callable<?> delegateObj) {
+ public Collaborator(ComponentMetadata cm, List<Interceptor> interceptors) {
this.cm = cm;
- this.object = delegateObj;
- this.delegate = new InvocationHandler() {
- private void onUnexpectedException(Throwable cause) {
- throw new Error("Unreachable catch statement reached", cause);
- }
-
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
- Object result;
- try {
- result = method.invoke(object.call(), args);
- } catch (InvocationTargetException ite) {
- // We are invisible, so unwrap and throw the cause as
- // though we called the method directly.
- throw ite.getCause();
- } catch (IllegalAccessException e) {
- onUnexpectedException(e);
- return null;
- } catch (IllegalArgumentException e) {
- onUnexpectedException(e);
- return null;
- } catch (SecurityException e) {
- onUnexpectedException(e);
- return null;
- }
-
- return result;
- }
- };
this.interceptors = interceptors;
}
@@ -114,84 +78,67 @@ class Collaborator implements Invocation
}
}
- public Object invoke(Object proxy, Method method, Object[] args)
+ public Object invoke(Object proxy, Method method, Object[] args, InvocationHandler target)
throws Throwable {
Object toReturn = null;
- // Unwrap calls for equals
- if (method.getName().equals("equals")
- && method.getDeclaringClass() == Object.class) {
- if (AsmInterceptorWrapper.isProxyClass(args[0].getClass())
- || Proxy.isProxyClass(args[0].getClass())) {
- // unwrap in the asm case
- args[0] = AsmInterceptorWrapper.unwrapObject(args[0]);
+ Stack<Collaborator.StackElement> calledInterceptors = new Stack<Collaborator.StackElement>();
+ boolean inInvoke = false;
+ try {
+ preCallInterceptor(interceptors, cm, method, args,
+ calledInterceptors);
+ inInvoke = true;
+ toReturn = target.invoke(proxy, method, args);
+ inInvoke = false;
+ postCallInterceptorWithReturn(cm, method, toReturn,
+ calledInterceptors);
+
+ } catch (Throwable e) {
+ // whether the the exception is an error is an application decision
+ LOGGER.debug("invoke", e);
+
+ // if we catch an exception we decide carefully which one to
+ // throw onwards
+ Throwable exceptionToRethrow = null;
+ // if the exception came from a precall or postcall interceptor
+ // we will rethrow it
+ // after we cycle through the rest of the interceptors using
+ // postCallInterceptorWithException
+ if (!inInvoke) {
+ exceptionToRethrow = e;
+ }
+ // if the exception didn't come from precall or postcall then it
+ // came from invoke
+ // we will rethrow this exception if it is not a runtime
+ // exception
+ else {
+ if (!(e instanceof RuntimeException)) {
+ exceptionToRethrow = e;
+ }
}
- toReturn = delegate.invoke(proxy, method, args);
- } else if (method.getName().equals("finalize") && method.getParameterTypes().length == 0) {
- // special case finalize, don't route through to delegate because that will get its own call
- toReturn = null;
- } else
- // Proxy the call through to the delegate, wrapping call in
- // interceptor invocations.
- {
- Stack<Collaborator.StackElement> calledInterceptors = new Stack<Collaborator.StackElement>();
- boolean inInvoke = false;
try {
- preCallInterceptor(interceptors, cm, method, args,
- calledInterceptors);
- inInvoke = true;
- toReturn = delegate.invoke(proxy, method, args);
- inInvoke = false;
- postCallInterceptorWithReturn(cm, method, toReturn,
+ postCallInterceptorWithException(cm, method, e,
calledInterceptors);
-
- } catch (Throwable e) {
- // whether the the exception is an error is an application decision
- LOGGER.debug("invoke", e);
-
- // if we catch an exception we decide carefully which one to
- // throw onwards
- Throwable exceptionToRethrow = null;
- // if the exception came from a precall or postcall interceptor
- // we will rethrow it
- // after we cycle through the rest of the interceptors using
+ } catch (Exception f) {
+ // we caught an exception from
// postCallInterceptorWithException
- if (!inInvoke) {
- exceptionToRethrow = e;
- }
- // if the exception didn't come from precall or postcall then it
- // came from invoke
- // we will rethrow this exception if it is not a runtime
- // exception
- else {
- if (!(e instanceof RuntimeException)) {
- exceptionToRethrow = e;
- }
- }
- try {
- postCallInterceptorWithException(cm, method, e,
- calledInterceptors);
- } catch (Exception f) {
- // we caught an exception from
- // postCallInterceptorWithException
- // logger.catching("invoke", f);
- // if we haven't already chosen an exception to rethrow then
- // we will throw this exception
- if (exceptionToRethrow == null) {
- exceptionToRethrow = f;
- } else {
- LOGGER.warn("Discarding post-call with interceptor exception", f);
- }
- }
- // if we made it this far without choosing an exception we
- // should throw e
+ // logger.catching("invoke", f);
+ // if we haven't already chosen an exception to rethrow then
+ // we will throw this exception
if (exceptionToRethrow == null) {
- exceptionToRethrow = e;
- } else if (exceptionToRethrow != e) {
- LOGGER.warn("Discarding initial exception", e);
+ exceptionToRethrow = f;
+ } else {
+ LOGGER.warn("Discarding post-call with interceptor exception", f);
}
- throw exceptionToRethrow;
}
+ // if we made it this far without choosing an exception we
+ // should throw e
+ if (exceptionToRethrow == null) {
+ exceptionToRethrow = e;
+ } else if (exceptionToRethrow != e) {
+ LOGGER.warn("Discarding initial exception", e);
+ }
+ throw exceptionToRethrow;
}
return toReturn;
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/ReflectionUtils.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/ReflectionUtils.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/ReflectionUtils.java Mon Dec 13 18:26:19 2010
@@ -176,18 +176,20 @@ public class ReflectionUtils {
}
if (allowFieldInjection) {
- for (Field field : clazz.getDeclaredFields()) {
- if (!!!Modifier.isStatic(field.getModifiers())) {
- String name = decapitalize(field.getName());
- PropertyDescriptor desc = props.get(name);
- if (desc == null) {
- props.put(name, new FieldPropertyDescriptor(name, field));
- } else if (desc instanceof MethodPropertyDescriptor) {
- props.put(name,
- new JointPropertyDescriptor((MethodPropertyDescriptor) desc,
- new FieldPropertyDescriptor(name, field)));
- } else {
- illegalProperties.add(name);
+ for (Class cl = clazz; cl != null && cl != Object.class; cl = cl.getSuperclass()) {
+ for (Field field : cl.getDeclaredFields()) {
+ if (!!!Modifier.isStatic(field.getModifiers())) {
+ String name = decapitalize(field.getName());
+ PropertyDescriptor desc = props.get(name);
+ if (desc == null) {
+ props.put(name, new FieldPropertyDescriptor(name, field));
+ } else if (desc instanceof MethodPropertyDescriptor) {
+ props.put(name,
+ new JointPropertyDescriptor((MethodPropertyDescriptor) desc,
+ new FieldPropertyDescriptor(name, field)));
+ } else {
+ illegalProperties.add(name);
+ }
}
}
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/pom.xml Mon Dec 13 18:26:19 2010
@@ -22,6 +22,7 @@
<groupId>org.apache.aries</groupId>
<artifactId>java5-parent</artifactId>
<version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>../parent/default-parent/java5-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -155,6 +156,17 @@
<artifactId>org.apache.aries.testsupport.unit</artifactId>
<version>0.3-incubating-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.aries.proxy</groupId>
+ <artifactId>org.apache.aries.proxy.api</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.proxy</groupId>
+ <artifactId>org.apache.aries.proxy</artifactId>
+ <version>0.3-incubating-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</dependencyManagement>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/eba-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/eba-maven-plugin/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/eba-maven-plugin/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/eba-maven-plugin/pom.xml Mon Dec 13 18:26:19 2010
@@ -26,6 +26,7 @@ under the License.
<groupId>org.apache.aries</groupId>
<artifactId>java5-parent</artifactId>
<version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>../parent/default-parent/java5-parent/pom.xml</relativePath>
</parent>
<artifactId>eba-maven-plugin</artifactId>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/jmx/jmx-bundle/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/jmx/jmx-bundle/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/jmx/jmx-bundle/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/jmx/jmx-bundle/pom.xml Mon Dec 13 18:26:19 2010
@@ -45,6 +45,7 @@
<aries.osgi.import>
!org.apache.aries*,
!org.osgi.service.framework,
+ !org.eclipse*,
org.osgi.framework;version="1.5.0",
org.osgi.service.cm;version="1.3.0";resolution:="optional",
org.osgi.service.permissionadmin;version="1.2.0";resolution:="optional",
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java Mon Dec 13 18:26:19 2010
@@ -16,18 +16,18 @@
*/
package org.apache.aries.jmx;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+
import java.util.Collection;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
-import static org.ops4j.pax.exam.OptionUtils.combine;
-import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
-import static org.junit.Assert.*;
-
import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
@@ -41,6 +41,7 @@ import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -50,7 +51,6 @@ import org.osgi.framework.InvalidSyntaxE
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.Version;
-import org.osgi.jmx.framework.BundleStateMBean;
import org.osgi.util.tracker.ServiceTracker;
/**
Propchange: incubator/aries/sandbox/jbohn/interceptor-proto/jmx/jmx-whiteboard/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Dec 13 18:26:19 2010
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/jmx/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/jmx/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/jmx/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/jmx/pom.xml Mon Dec 13 18:26:19 2010
@@ -22,6 +22,7 @@
<groupId>org.apache.aries</groupId>
<artifactId>java5-parent</artifactId>
<version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>../parent/default-parent/java5-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -152,6 +153,7 @@
<module>jmx-api</module>
<module>jmx-blueprint-api</module>
<module>jmx-core</module>
+ <module>jmx-whiteboard</module>
<module>jmx-blueprint-core</module>
<module>jmx-bundle</module>
<module>jmx-blueprint-bundle</module>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-api/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-api/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-api/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-api/pom.xml Mon Dec 13 18:26:19 2010
@@ -33,6 +33,7 @@
<aries.osgi.export>
org.osgi.service.jndi;version="1.0.0",
org.apache.aries.jndi.urls;version=${version},
+ org.apache.aries.jndi.api;version=${version},
org.apache.aries.jndi.spi;version=${version}
</aries.osgi.export>
<aries.osgi.import>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-bundle/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-bundle/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-bundle/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-bundle/pom.xml Mon Dec 13 18:26:19 2010
@@ -59,6 +59,10 @@
</dependency>
<dependency>
<groupId>org.apache.aries.jndi</groupId>
+ <artifactId>org.apache.aries.jndi.rmi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.jndi</groupId>
<artifactId>org.apache.aries.jndi.api</artifactId>
</dependency>
<dependency>
@@ -87,6 +91,7 @@
<includes>
<include>org.apache.aries.jndi:org.apache.aries.jndi.core</include>
<include>org.apache.aries.jndi:org.apache.aries.jndi.url</include>
+ <include>org.apache.aries.jndi:org.apache.aries.jndi.rmi</include>
<include>org.apache.aries.jndi:org.apache.aries.jndi.api</include>
</includes>
</artifactSet>
@@ -104,6 +109,12 @@
</excludes>
</filter>
<filter>
+ <artifact>org.apache.aries.jndi:org.apache.aries.jndi.rmi</artifact>
+ <excludes>
+ <exclude>org/**</exclude>
+ </excludes>
+ </filter>
+ <filter>
<artifact>org.apache.aries.jndi:org.apache.aries.jndi.api</artifact>
<excludes>
<exclude>org/**</exclude>
@@ -152,6 +163,11 @@
</artifactItem>
<artifactItem>
<groupId>org.apache.aries.jndi</groupId>
+ <artifactId>org.apache.aries.jndi.rmi</artifactId>
+ <classifier>sources</classifier>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.apache.aries.jndi</groupId>
<artifactId>org.apache.aries.jndi.api</artifactId>
<classifier>sources</classifier>
</artifactItem>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-bundle/src/main/java/org/apache/aries/jndi/priv/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-bundle/src/main/java/org/apache/aries/jndi/priv/Activator.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-bundle/src/main/java/org/apache/aries/jndi/priv/Activator.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-bundle/src/main/java/org/apache/aries/jndi/priv/Activator.java Mon Dec 13 18:26:19 2010
@@ -28,7 +28,8 @@ public class Activator implements Bundle
public Activator() {
this.activators = new BundleActivator[]{
new org.apache.aries.jndi.startup.Activator(),
- new org.apache.aries.jndi.url.Activator()
+ new org.apache.aries.jndi.url.Activator(),
+ new org.apache.aries.jndi.rmi.Activator()
};
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java Mon Dec 13 18:26:19 2010
@@ -134,7 +134,7 @@ public final class ContextHelper {
if (contextFactoryClass == null) {
return new DelegateContext(context, environment);
} else {
- throw new NoInitialContextException("We could not find an InitialContextFactory to use");
+ throw new NoInitialContextException("We could not find a provider for the InitialContextFactory " + contextFactoryClass);
}
}
}
@@ -212,17 +212,21 @@ public final class ContextHelper {
for (ServiceReference ref : refs) {
InitialContextFactoryBuilder builder = (InitialContextFactoryBuilder) context.getService(ref);
try {
- factory = builder.createInitialContextFactory(environment);
- if (factory != null) {
- provider = new ContextProvider(context, ref, factory.getInitialContext(environment));
- break;
- } else {
- context.ungetService(ref); // we didn't get something back, so this was no good.
- }
- } catch (NamingException e) {
- // TODO: log
- // ignore
- context.ungetService(ref);
+ factory = builder.createInitialContextFactory(environment);
+ } catch (NamingException ne) {
+ // TODO: log
+ // ignore this, if the builder fails we want to move onto the next one
+ }
+
+ if (factory != null) {
+ try {
+ provider = new ContextProvider(context, ref, factory.getInitialContext(environment));
+ } finally {
+ context.ungetService(ref); // we didn't get something back, so this was no good.
+ }
+ break;
+ } else {
+ context.ungetService(ref); // we didn't get something back, so this was no good.
}
}
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextProvider.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextProvider.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextProvider.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextProvider.java Mon Dec 13 18:26:19 2010
@@ -10,7 +10,6 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
public class ContextProvider {
- private ServicePair<?> pair;
private ServiceReference reference;
private Context context;
private BundleContext bc;
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java Mon Dec 13 18:26:19 2010
@@ -35,17 +35,21 @@ import javax.naming.directory.DirContext
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ExtendedRequest;
+import javax.naming.ldap.ExtendedResponse;
+import javax.naming.ldap.LdapContext;
import org.osgi.framework.BundleContext;
-public class DelegateContext implements DirContext {
+public class DelegateContext implements DirContext, LdapContext {
- private Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+ private final Hashtable<Object, Object> env = new Hashtable<Object, Object>();
- private BundleContext bundleContext;
+ private final BundleContext bundleContext;
private ContextProvider contextProvider;
- private Map<String, ContextProvider> urlContexts = new HashMap<String, ContextProvider>();
- private boolean rebind;
+ private final Map<String, ContextProvider> urlContexts = new HashMap<String, ContextProvider>();
+ private final boolean rebind;
public DelegateContext(BundleContext bundleContext, Hashtable<?, ?> theEnv) {
this.bundleContext = bundleContext;
@@ -212,14 +216,6 @@ public class DelegateContext implements
toReturn = getDefaultContext();
}
- if (toReturn != null) {
- String packages = Utils.getSystemProperty(Context.URL_PKG_PREFIXES, null);
-
- if (packages != null) {
- toReturn.addToEnvironment(Context.URL_PKG_PREFIXES, packages);
- }
- }
-
return toReturn;
}
@@ -382,4 +378,35 @@ public class DelegateContext implements
SearchControls cons) throws NamingException {
return ((DirContext) findContext(name)).search(name, filterExpr, filterArgs, cons);
}
+
+ public ExtendedResponse extendedOperation(ExtendedRequest request)
+ throws NamingException {
+ return ((LdapContext) getDefaultContext()).extendedOperation(request);
+ }
+
+ public Control[] getConnectControls() throws NamingException {
+ return ((LdapContext) getDefaultContext()).getConnectControls();
+ }
+
+ public Control[] getRequestControls() throws NamingException {
+ return ((LdapContext) getDefaultContext()).getRequestControls();
+ }
+
+ public Control[] getResponseControls() throws NamingException {
+ return ((LdapContext) getDefaultContext()).getResponseControls();
+ }
+
+ public LdapContext newInstance(Control[] requestControls)
+ throws NamingException {
+ return ((LdapContext) getDefaultContext()).newInstance(requestControls);
+ }
+
+ public void reconnect(Control[] connCtls) throws NamingException {
+ ((LdapContext) getDefaultContext()).reconnect(connCtls);
+ }
+
+ public void setRequestControls(Control[] requestControls)
+ throws NamingException {
+ ((LdapContext) getDefaultContext()).setRequestControls(requestControls);
+ }
}
\ No newline at end of file
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java Mon Dec 13 18:26:19 2010
@@ -20,6 +20,8 @@ package org.apache.aries.jndi.startup;
import java.lang.reflect.Field;
import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
@@ -50,7 +52,9 @@ import org.osgi.util.tracker.ServiceTrac
* driven so they can do their magic stuff properly.
*/
public class Activator implements BundleActivator {
-
+
+ private static final Logger LOGGER = Logger.getLogger(Activator.class.getName());
+
private OSGiInitialContextFactoryBuilder icfBuilder;
private OSGiObjectFactoryBuilder ofBuilder;
private static ServiceTracker icfBuilders;
@@ -72,9 +76,9 @@ public class Activator implements Bundle
NamingManager.setInitialContextFactoryBuilder(builder);
icfBuilder = builder;
} catch (NamingException e) {
- e.printStackTrace();
+ LOGGER.log(Level.INFO, "Cannot set the InitialContextFactoryBuilder.", e);
} catch (IllegalStateException e) {
- System.err.println("Cannot set the InitialContextFactoryBuilder. Another builder is already installed");
+ LOGGER.log(Level.INFO, "Cannot set the InitialContextFactoryBuilder. Another builder " + getClassName(InitialContextFactoryBuilder.class) + " is already installed", e);
}
try {
@@ -82,9 +86,9 @@ public class Activator implements Bundle
NamingManager.setObjectFactoryBuilder(builder);
ofBuilder = builder;
} catch (NamingException e) {
- e.printStackTrace();
+ LOGGER.log(Level.INFO, "Cannot set the ObjectFactoryBuilder.", e);
} catch (IllegalStateException e) {
- System.err.println("Cannot set the ObjectFactoryBuilder. Another builder is already installed");
+ LOGGER.log(Level.INFO, "Cannot set the ObjectFactoryBuilder. Another builder " + getClassName(InitialContextFactoryBuilder.class) + " is already installed", e);
}
context.registerService(JNDIProviderAdmin.class.getName(),
@@ -100,6 +104,22 @@ public class Activator implements Bundle
null);
}
+ private String getClassName(Class<?> expectedType)
+ {
+ try {
+ for (Field field : NamingManager.class.getDeclaredFields()) {
+ if (expectedType.equals(field.getType())) {
+ field.setAccessible(true);
+ Object icf = field.get(null);
+ return icf.getClass().getName();
+ }
+ }
+ } catch (Throwable t) {
+ // Ignore
+ }
+ return "";
+ }
+
private ServiceTracker initServiceTracker(BundleContext context,
Class<?> type, ServiceTrackerCustomizer custom)
{
@@ -141,7 +161,7 @@ public class Activator implements Bundle
}
} catch (Throwable t) {
// Ignore
- t.printStackTrace();
+ LOGGER.log(Level.FINE, "Error setting field.", t);
}
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-core/src/test/java/org/apache/aries/jndi/InitialContextTest.java Mon Dec 13 18:26:19 2010
@@ -11,7 +11,12 @@ import javax.naming.InitialContext;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.NoInitialContextException;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ExtendedRequest;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.InitialContextFactoryBuilder;
import javax.naming.spi.ObjectFactory;
import org.apache.aries.jndi.startup.Activator;
@@ -101,4 +106,29 @@ public class InitialContextTest
Object someObject = initialCtx.lookup("testURL:somedata");
assertEquals("Expected to be given a string, but got something else.", "someText", someObject);
}
+
+ @Test
+ public void testLookFromLdapICF() throws Exception
+ {
+ InitialContextFactoryBuilder icf = Skeleton.newMock(InitialContextFactoryBuilder.class);
+ bc.registerService(new String[] {InitialContextFactoryBuilder.class.getName(), icf.getClass().getName()}, icf, new Properties());
+
+ LdapContext backCtx = Skeleton.newMock(LdapContext.class);
+ InitialContextFactory fac = Skeleton.newMock(InitialContextFactory.class);
+ Skeleton.getSkeleton(fac).setReturnValue(
+ new MethodCall(InitialContextFactory.class, "getInitialContext", Hashtable.class),
+ backCtx);
+ Skeleton.getSkeleton(icf).setReturnValue(
+ new MethodCall(InitialContextFactoryBuilder.class, "createInitialContextFactory", Hashtable.class),
+ fac);
+
+ Properties props = new Properties();
+ props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
+ props.put(Context.INITIAL_CONTEXT_FACTORY, "dummy.factory");
+ InitialLdapContext ilc = new InitialLdapContext(props, new Control[0]);
+
+ ExtendedRequest req = Skeleton.newMock(ExtendedRequest.class);
+ ilc.extendedOperation(req);
+ Skeleton.getSkeleton(backCtx).assertCalled(new MethodCall(LdapContext.class, "extendedOperation", req));
+ }
}
\ No newline at end of file
Propchange: incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-legacy-support/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Dec 13 18:26:19 2010
@@ -1 +1,4 @@
target
+.settings
+.classpath
+.project
Propchange: incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-rmi/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Dec 13 18:26:19 2010
@@ -0,0 +1,4 @@
+.settings
+target
+.classpath
+.project
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-url/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-url/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-url/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/jndi/jndi-url/pom.xml Mon Dec 13 18:26:19 2010
@@ -42,7 +42,7 @@
org.apache.aries.jndi.url.Activator
</aries.osgi.activator>
<aries.osgi.import.pkg>
- net.sf.cglib.proxy;resolution:=optional,
+ org.osgi.service.blueprint.container;resolution:=optional,
*
</aries.osgi.import.pkg>
</properties>
@@ -58,14 +58,18 @@
<artifactId>org.apache.aries.util</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.aries.proxy</groupId>
+ <artifactId>org.apache.aries.proxy.api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.servicemix.bundles</groupId>
- <artifactId>org.apache.servicemix.bundles.cglib</artifactId>
- <optional>true</optional>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.aries.jndi</groupId>
@@ -77,11 +81,7 @@
<artifactId>org.apache.aries.testsupport.unit</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <scope>test</scope>
- </dependency>
+
</dependencies>
</project>