hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r400327 - in /jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl: CglibBeanInterfaceFactory.java JavassistBeanInterfaceFactory.java JdkBeanInterfaceFactory.java generated.xml
Date Sat, 06 May 2006 15:50:53 GMT
Author: jcarman
Date: Sat May  6 08:50:51 2006
New Revision: 400327

URL: http://svn.apache.org/viewcvs?rev=400327&view=rev
Log:
HiveMind LoggingInterceptor incompatible with proxies generated by outside means (CGLIB or
Javassist)
PR: HIVEMIND-176

Added:
    jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java
  (with props)
    jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java
  (with props)
    jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java
  (with props)
    jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/generated.xml
  (with props)

Added: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java?rev=400327&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java
(added)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java
Sat May  6 08:50:51 2006
@@ -0,0 +1,75 @@
+// Copyright 2006 The Apache Software Foundation
+//
+// Licensed 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 org.apache.hivemind.service.impl;
+
+import java.lang.reflect.Method;
+
+import net.sf.cglib.proxy.Callback;
+import net.sf.cglib.proxy.CallbackFilter;
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.FixedValue;
+import net.sf.cglib.proxy.NoOp;
+
+import org.apache.hivemind.ServiceImplementationFactory;
+import org.apache.hivemind.ServiceImplementationFactoryParameters;
+
+/**
+ * 
+ * @author James Carman
+ */
+public class CglibBeanInterfaceFactory implements ServiceImplementationFactory
+{
+
+	public Object createCoreServiceImplementation(ServiceImplementationFactoryParameters factoryParameters)
{
+		return createCglibBean();
+	}
+
+
+	/**
+	 * @return
+	 */
+	public static BeanInterface createCglibBean() {
+		Enhancer enhancer = new Enhancer();
+		enhancer.setClassLoader( BeanInterface.class.getClassLoader() );
+		enhancer.setInterfaces( new Class[] { BeanInterface.class } );
+		enhancer.setCallbackFilter( new InterfaceMethodFilter() );
+		enhancer.setCallbacks( new Callback[] { new FixedValue()
+				{
+					public Object loadObject() throws Exception {
+
+						return "Hello, World!";
+					}
+			
+				}, NoOp.INSTANCE } );
+		
+		return (BeanInterface)enhancer.create();
+	}
+	
+	
+	private static class InterfaceMethodFilter implements CallbackFilter
+	{
+
+		public int accept(Method method) 
+		{
+			if( method.getName().equals( "interfaceMethod" ) )
+			{
+				return 0;
+			}
+			return 1;
+		}
+		
+	}
+
+}

Propchange: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/CglibBeanInterfaceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java?rev=400327&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java
(added)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java
Sat May  6 08:50:51 2006
@@ -0,0 +1,63 @@
+// Copyright 2006 The Apache Software Foundation
+//
+// Licensed 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 org.apache.hivemind.service.impl;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtMethod;
+import javassist.LoaderClassPath;
+
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.ServiceImplementationFactory;
+import org.apache.hivemind.ServiceImplementationFactoryParameters;
+import org.apache.hivemind.service.ClassFabUtils;
+
+/**
+ * @author James Carman
+ */
+public class JavassistBeanInterfaceFactory implements
+		ServiceImplementationFactory {
+
+	public Object createCoreServiceImplementation(
+			ServiceImplementationFactoryParameters factoryParameters) {
+		return createJavassistBean();
+	}
+
+	/**
+	 * @return
+	 */
+	public static BeanInterface createJavassistBean() {
+		try {
+			ClassPool classPool = new ClassPool();
+			classPool.appendClassPath(new LoaderClassPath(BeanInterface.class
+					.getClassLoader()));
+			CtClass theClass = classPool
+					.makeClass(ClassFabUtils.generateClassName(BeanInterface.class));
+
+			theClass.addInterface(classPool.get(BeanInterface.class.getName()));
+			CtMethod theMethod = new CtMethod(
+					classPool.get("java.lang.String"), "interfaceMethod",
+					new CtClass[0], theClass);
+			theMethod.setBody("return \"Hello, World!\";");
+			theClass.addMethod(theMethod);
+			Class clazz = theClass.toClass();
+			return ( BeanInterface )clazz.newInstance();
+		} catch (Exception e) {
+			throw new ApplicationRuntimeException("Cannot construct instance.",
+					e);
+		}
+	}
+
+}

Propchange: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JavassistBeanInterfaceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java?rev=400327&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java
(added)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java
Sat May  6 08:50:51 2006
@@ -0,0 +1,48 @@
+// Copyright 2006 The Apache Software Foundation
+//
+// Licensed 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 org.apache.hivemind.service.impl;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.apache.hivemind.ServiceImplementationFactory;
+import org.apache.hivemind.ServiceImplementationFactoryParameters;
+
+/**
+ * 
+ * @author James Carman
+ *
+ */
+public class JdkBeanInterfaceFactory implements ServiceImplementationFactory {
+
+	public Object createCoreServiceImplementation(ServiceImplementationFactoryParameters factoryParameters)
{
+		return createJdkBean();
+	}
+
+	/**
+	 * @return
+	 */
+	public static BeanInterface createJdkBean() {
+		return ( BeanInterface )Proxy.newProxyInstance( BeanInterface.class.getClassLoader(), new
Class[] { BeanInterface.class }, new InvocationHandler()
+				{
+					public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+						return "Hello, World!";
+					}	
+				} );
+	}
+	
+
+}

Propchange: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/JdkBeanInterfaceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/generated.xml
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/generated.xml?rev=400327&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/generated.xml
(added)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/generated.xml
Sat May  6 08:50:51 2006
@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+<!-- 
+   Copyright 2006 The Apache Software Foundation
+
+   Licensed 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.
+-->
+
+<module id="generated" version="1.0.0">
+
+  <service-point id="JavassistFactory" interface="org.apache.hivemind.ServiceImplementationFactory"
parameters-occurs="none">
+    <invoke-factory>
+      <construct class="org.apache.hivemind.service.impl.JavassistBeanInterfaceFactory"
/>
+    </invoke-factory>
+  </service-point>
+
+  <service-point id="CglibFactory" interface="org.apache.hivemind.ServiceImplementationFactory"
parameters-occurs="none">
+    <invoke-factory>
+      <construct class="org.apache.hivemind.service.impl.CglibBeanInterfaceFactory" />
+    </invoke-factory>
+  </service-point>
+  
+  <service-point id="JdkFactory" interface="org.apache.hivemind.ServiceImplementationFactory"
parameters-occurs="none">
+    <invoke-factory>
+      <construct class="org.apache.hivemind.service.impl.JdkBeanInterfaceFactory" />
+    </invoke-factory>
+  </service-point>
+  
+  
+  <service-point id="JavassistBeanInterface" interface="org.apache.hivemind.service.impl.BeanInterface">
+    <invoke-factory service-id="JavassistFactory" />
+    <interceptor service-id="hivemind.LoggingInterceptor" />
+  </service-point>
+  
+  <service-point id="CglibBeanInterface" interface="org.apache.hivemind.service.impl.BeanInterface">
+    <invoke-factory service-id="CglibFactory" />
+    <interceptor service-id="hivemind.LoggingInterceptor" />
+  </service-point>
+  
+  <service-point id="JdkBeanInterface" interface="org.apache.hivemind.service.impl.BeanInterface">
+    <invoke-factory service-id="JdkFactory" />
+    <interceptor service-id="hivemind.LoggingInterceptor" />
+  </service-point>
+</module>

Propchange: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/generated.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/generated.xml
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message