[jboss-cvs] JBossAS SVN: r96145 - in projects/interceptors/trunk/jboss-interceptor/src: test/java/org/jboss/interceptors/proxy and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Nov 8 23:40:56 EST 2009
Author: marius.bogoevici
Date: 2009-11-08 23:40:56 -0500 (Sun, 08 Nov 2009)
New Revision: 96145
Added:
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor2.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ValueBearer.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ValueBearerImpl.java
Modified:
projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorInvocationContext.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FootballTeam.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor.java
Log:
Further fixes.
Modified: projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorInvocationContext.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorInvocationContext.java 2009-11-09 03:41:15 UTC (rev 96144)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorInvocationContext.java 2009-11-09 04:40:56 UTC (rev 96145)
@@ -99,7 +99,40 @@
public void setParameters(Object[] params)
{
if (method != null)
- this.parameters = params;
+ {
+ // there is no requirement to do anything if params is null
+ // but this is theoretically possible only if the target method has no arguments
+ int newParametersCount = params == null? 0 : params.length;
+ if (method.getParameterTypes().length != newParametersCount)
+ throw new IllegalArgumentException("Wrong number of parameters: method has " + method.getParameterTypes().length
+ + ", attempting to set " + newParametersCount + (params != null?"": " (argument was null)"));
+ if (params != null)
+ {
+ for (int i=0; i<params.length; i++)
+ {
+ Class<?> parameterClass = method.getParameterTypes()[i];
+ if (params[i] != null)
+ {
+ if (!method.getParameterTypes()[i].isAssignableFrom(params[i].getClass()))
+ {
+ throw new IllegalArgumentException("Incompatible parameter: " + params[i] + " (expected type was " + method.getParameterTypes()[i].getName() + ")");
+ }
+ }
+ else
+ {
+ if (method.getParameterTypes()[i].isPrimitive())
+ {
+ throw new IllegalArgumentException("Trying to set a null value on a " + method.getParameterTypes()[i].getName());
+ }
+ }
+ }
+ this.parameters = params;
+ }
+ }
+ else
+ {
+ throw new IllegalStateException("Illegal invocation to setParameters() during lifecycle invocation");
+ }
}
public Object getTimer()
Modified: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FootballTeam.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FootballTeam.java 2009-11-09 03:41:15 UTC (rev 96144)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FootballTeam.java 2009-11-09 04:40:56 UTC (rev 96145)
@@ -48,11 +48,16 @@
return teamName;
}
- public int echo(int i)
+ public int echo(String i)
{
- return i;
+ return Integer.parseInt(i);
}
+ public int echo2(ValueBearer vb)
+ {
+ return vb.getValue();
+ }
+
@PrePassivate
public void beforePassivating()
{
Modified: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java 2009-11-09 03:41:15 UTC (rev 96144)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java 2009-11-09 04:40:56 UTC (rev 96145)
@@ -211,16 +211,32 @@
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
- builder.interceptAroundInvoke(FootballTeam.class.getMethod("echo", int.class)).with(ParameterOverridingInterceptor.class);
+ builder.interceptAroundInvoke(FootballTeam.class.getMethod("echo", String.class)).with(ParameterOverridingInterceptor.class);
interceptionModel = builder.build();
this.interceptorRegistry = new InterceptorRegistry<Class<?>, Class<?>>();
this.interceptorRegistry.registerInterceptionModel(FootballTeam.class, interceptionModel);
FootballTeam proxy = InterceptionUtils.proxifyInstance(new FootballTeam(TEAM_NAME), FootballTeam.class, interceptorRegistry, new DirectClassInterceptionHandlerFactory());
- Assert.assertEquals(42, proxy.echo(1));
+ Assert.assertEquals(42, proxy.echo("1"));
}
+ @Test
+ public void testMethodParameterOverridingWithSubclass() throws Exception
+ {
+ InterceptorTestLogger.reset();
+ InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
+
+ builder.interceptAroundInvoke(FootballTeam.class.getMethod("echo2", ValueBearer.class)).with(ParameterOverridingInterceptor2.class);
+ interceptionModel = builder.build();
+ this.interceptorRegistry = new InterceptorRegistry<Class<?>, Class<?>>();
+ this.interceptorRegistry.registerInterceptionModel(FootballTeam.class, interceptionModel);
+
+ FootballTeam proxy = InterceptionUtils.proxifyInstance(new FootballTeam(TEAM_NAME), FootballTeam.class, interceptorRegistry, new DirectClassInterceptionHandlerFactory());
+ Assert.assertEquals(42, proxy.echo2(new ValueBearerImpl(1)));
+ }
+
+
public void assertRawObject(FootballTeam proxy)
{
InterceptorTestLogger.reset();
Modified: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor.java 2009-11-09 03:41:15 UTC (rev 96144)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor.java 2009-11-09 04:40:56 UTC (rev 96145)
@@ -30,7 +30,7 @@
{
if (invocationContext.getMethod().getName().equals("echo"))
{
- invocationContext.setParameters(new Object[]{Integer.valueOf(42)});
+ invocationContext.setParameters(new Object[]{"42"});
}
return invocationContext.proceed();
}
Copied: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor2.java (from rev 96130, projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor.java)
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor2.java (rev 0)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor2.java 2009-11-09 04:40:56 UTC (rev 96145)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.interceptors.proxy;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class ParameterOverridingInterceptor2
+{
+ @AroundInvoke
+ public Object overrideParameters(InvocationContext invocationContext) throws Exception
+ {
+ if (invocationContext.getMethod().getName().equals("echo2"))
+ {
+ invocationContext.setParameters(new Object[]{new ValueBearer(){
+ public int getValue()
+ {
+ return 42;
+ }
+ }});
+ }
+ return invocationContext.proceed();
+ }
+}
\ No newline at end of file
Added: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ValueBearer.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ValueBearer.java (rev 0)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ValueBearer.java 2009-11-09 04:40:56 UTC (rev 96145)
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.interceptors.proxy;
+
+/**
+ * @author Marius Bogoevici
+ */
+public interface ValueBearer
+{
+ int getValue();
+}
Added: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ValueBearerImpl.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ValueBearerImpl.java (rev 0)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ValueBearerImpl.java 2009-11-09 04:40:56 UTC (rev 96145)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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.jboss.interceptors.proxy;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class ValueBearerImpl implements ValueBearer
+{
+ private int value;
+
+ public ValueBearerImpl(int value)
+ {
+ this.value = value;
+ }
+
+ public int getValue()
+ {
+ return value;
+ }
+}
More information about the jboss-cvs-commits
mailing list