Author: struberg
Date: Sat Feb 9 22:16:04 2013
New Revision: 1444454
URL: http://svn.apache.org/r1444454
Log:
OWB-777 unwrap NormalScope proxies before performing reflection
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/HiddenProducerMethodTest.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/PrivateProducedBean.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/ProtectedProducedBean.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/SampleProducerOwner.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/SomeUserBean.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethod.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethod.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethod.java?rev=1444454&r1=1444453&r2=1444454&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethod.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethod.java
Sat Feb 9 22:16:04 2013
@@ -37,6 +37,8 @@ import org.apache.webbeans.component.Pro
import org.apache.webbeans.container.InjectionResolver;
import org.apache.webbeans.context.creational.CreationalContextImpl;
import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.proxy.NormalScopeProxyFactory;
+import org.apache.webbeans.proxy.OwbNormalScopeProxy;
@SuppressWarnings("unchecked")
public class InjectableMethod<T> extends AbstractInjectable<T>
@@ -45,7 +47,7 @@ public class InjectableMethod<T> extends
protected Method method;
/** Bean parent instance that owns the method */
- protected Object instance;
+ protected Object ownerInstance;
/**If this method is dispose method*/
private boolean disposable;
@@ -65,7 +67,7 @@ public class InjectableMethod<T> extends
{
super(owner,creationalContext);
method = m;
- this.instance = instance;
+ this.ownerInstance = instance;
}
/*
@@ -74,6 +76,12 @@ public class InjectableMethod<T> extends
*/
public T doInjection()
{
+ Object owner = ownerInstance;
+ if (owner instanceof OwbNormalScopeProxy)
+ {
+ owner = NormalScopeProxyFactory.unwrapInstance(owner);
+ }
+
List<InjectionPoint> injectedPoints = getInjectionPoints(method);
List<Object> list = new ArrayList<Object>();
@@ -141,7 +149,7 @@ public class InjectableMethod<T> extends
getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(method,
true);
}
- return (T) method.invoke(instance, list.toArray(new
Object[list.size()]));
+ return (T) method.invoke(owner, list.toArray(new
Object[list.size()]));
}
catch (Exception e)
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/HiddenProducerMethodTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/HiddenProducerMethodTest.java?rev=1444454&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/HiddenProducerMethodTest.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/HiddenProducerMethodTest.java
Sat Feb 9 22:16:04 2013
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.producer;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+
+import org.apache.webbeans.newtests.producer.beans.PrivateProducedBean;
+import org.apache.webbeans.newtests.producer.beans.ProtectedProducedBean;
+import org.apache.webbeans.newtests.producer.beans.SampleProducerOwner;
+import org.apache.webbeans.newtests.producer.beans.SomeUserBean;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test for protected and private producer methods
+ */
+public class HiddenProducerMethodTest extends AbstractUnitTest
+{
+ @Test
+ public void testHiddenProducerMethods()
+ {
+ startContainer(PrivateProducedBean.class, ProtectedProducedBean.class,
SampleProducerOwner.class, SomeUserBean.class);
+
+ PrivateProducedBean privateProducedBean =
getInstance(PrivateProducedBean.class);
+ Assert.assertNotNull(privateProducedBean);
+ Assert.assertEquals(42, privateProducedBean.getMeaningOfLife());
+
+ ProtectedProducedBean protectedProducedBean =
getInstance(ProtectedProducedBean.class);
+ Assert.assertNotNull(protectedProducedBean);
+ Assert.assertEquals(42, privateProducedBean.getMeaningOfLife());
+ }
+
+}
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/PrivateProducedBean.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/PrivateProducedBean.java?rev=1444454&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/PrivateProducedBean.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/PrivateProducedBean.java
Sat Feb 9 22:16:04 2013
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.producer.beans;
+
+import javax.enterprise.inject.Typed;
+
+/**
+ * A sample bean which gets produced by a producer method with modifier
'private'
+ */
+@Typed()
+public class PrivateProducedBean
+{
+ public int getMeaningOfLife()
+ {
+ return 42;
+ }
+}
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/ProtectedProducedBean.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/ProtectedProducedBean.java?rev=1444454&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/ProtectedProducedBean.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/ProtectedProducedBean.java
Sat Feb 9 22:16:04 2013
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.producer.beans;
+
+import javax.enterprise.inject.Typed;
+
+/**
+ * A sample bean which gets produced by a producer method with modifier
'protected'
+ */
+@Typed()
+public class ProtectedProducedBean
+{
+ public int getMeaningOfLife()
+ {
+ return 42;
+ }
+}
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/SampleProducerOwner.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/SampleProducerOwner.java?rev=1444454&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/SampleProducerOwner.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/SampleProducerOwner.java
Sat Feb 9 22:16:04 2013
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.producer.beans;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+import org.junit.Assert;
+
+/**
+ * The bean which contains a few producer methods which are protected and
private.
+ * We use a NormalScope which means the container gets a proxy which it needs
to
+ * unwrap on the fly.
+ */
+@RequestScoped
+public class SampleProducerOwner
+{
+ private @Inject SomeUserBean user;
+
+ @Produces
+ protected ProtectedProducedBean createProtected()
+ {
+ // this is only available if proper injection got performed
+ Assert.assertEquals("Hans", user.getName());
+
+ return new ProtectedProducedBean();
+ }
+
+ @Produces
+ private PrivateProducedBean createPrivate()
+ {
+ // this is only available if proper injection got performed
+ Assert.assertEquals("Hans", user.getName());
+
+ return new PrivateProducedBean();
+ }
+}
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/SomeUserBean.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/SomeUserBean.java?rev=1444454&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/SomeUserBean.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/beans/SomeUserBean.java
Sat Feb 9 22:16:04 2013
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.producer.beans;
+
+import javax.enterprise.context.RequestScoped;
+
+/**
+ * Just a dummy user bean which gets injected in to the producermethod owner
bean.
+ */
+@RequestScoped
+public class SomeUserBean
+{
+ public String getName()
+ {
+ return "Hans";
+ }
+}