Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELD-1177 Built-in InjectionPoint bean not injected for stateless ses…
…sion bean
- Loading branch information
Showing
15 changed files
with
472 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...java/org/jboss/weld/bean/proxy/InjectionPointPropagatingEnterpriseTargetBeanInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2013, Red Hat, Inc., 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.weld.bean.proxy; | ||
|
||
import java.io.ObjectStreamException; | ||
import java.lang.reflect.Method; | ||
|
||
import javax.enterprise.inject.spi.InjectionPoint; | ||
|
||
import org.jboss.weld.Container; | ||
import org.jboss.weld.injection.CurrentInjectionPoint; | ||
import org.jboss.weld.injection.EmptyInjectionPoint; | ||
import org.jboss.weld.injection.SLSBInvocationInjectionPoint; | ||
import org.jboss.weld.manager.BeanManagerImpl; | ||
import org.jboss.weld.serialization.InjectionPointHolder; | ||
|
||
/** | ||
* @author Marko Luksa | ||
* @author Jozef Hartinger | ||
* | ||
*/ | ||
public class InjectionPointPropagatingEnterpriseTargetBeanInstance extends EnterpriseTargetBeanInstance { | ||
|
||
private static final long serialVersionUID = 166825647603520280L; | ||
|
||
private final InjectionPointHolder injectionPointHolder; | ||
private transient SLSBInvocationInjectionPoint slsbInvocationInjectionPoint; | ||
|
||
public InjectionPointPropagatingEnterpriseTargetBeanInstance(Class<?> baseType, MethodHandler methodHandler, BeanManagerImpl manager) { | ||
super(baseType, methodHandler); | ||
this.slsbInvocationInjectionPoint = manager.getServices().get(SLSBInvocationInjectionPoint.class); | ||
InjectionPoint ip = manager.getServices().get(CurrentInjectionPoint.class).peek(); | ||
if (ip != null) { | ||
this.injectionPointHolder = new InjectionPointHolder(ip); | ||
} else { | ||
this.injectionPointHolder = null; | ||
} | ||
} | ||
|
||
@Override | ||
public Object invoke(Object instance, Method method, Object... arguments) throws Throwable { | ||
if (injectionPointHolder != null) { | ||
slsbInvocationInjectionPoint.push(injectionPointHolder.get()); | ||
} else { | ||
slsbInvocationInjectionPoint.push(EmptyInjectionPoint.INSTANCE); | ||
} | ||
|
||
try { | ||
return super.invoke(instance, method, arguments); | ||
} finally { | ||
slsbInvocationInjectionPoint.pop(); | ||
} | ||
} | ||
|
||
private Object readResolve() throws ObjectStreamException { | ||
this.slsbInvocationInjectionPoint = Container.instance().services().get(SLSBInvocationInjectionPoint.class); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
impl/src/main/java/org/jboss/weld/injection/DynamicInjectionPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2013, Red Hat, Inc., 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.weld.injection; | ||
|
||
import java.io.ObjectStreamException; | ||
import java.io.Serializable; | ||
|
||
import javax.enterprise.inject.spi.InjectionPoint; | ||
|
||
import org.jboss.weld.Container; | ||
import org.jboss.weld.bootstrap.api.ServiceRegistry; | ||
|
||
/** | ||
* A proxy that forwards call to the current {@link SLSBInvocationInjectionPoint}. | ||
* | ||
* @author Marko Luksa | ||
* | ||
*/ | ||
public class DynamicInjectionPoint extends ForwardingInjectionPoint implements Serializable { | ||
|
||
private static final long serialVersionUID = 0L; | ||
|
||
private final transient SLSBInvocationInjectionPoint invocationInjectionPoint; | ||
|
||
public DynamicInjectionPoint(ServiceRegistry services) { | ||
this.invocationInjectionPoint = services.get(SLSBInvocationInjectionPoint.class); | ||
} | ||
|
||
private DynamicInjectionPoint(SLSBInvocationInjectionPoint invocationInjectionPoint) { | ||
this.invocationInjectionPoint = invocationInjectionPoint; | ||
} | ||
|
||
protected InjectionPoint delegate() { | ||
return invocationInjectionPoint.peek(); | ||
} | ||
|
||
private Object readResolve() throws ObjectStreamException { | ||
return new DynamicInjectionPoint(Container.instance().services().get(SLSBInvocationInjectionPoint.class)); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
impl/src/main/java/org/jboss/weld/injection/InjectionPointStack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2008, Red Hat, Inc., 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.weld.injection; | ||
|
||
import java.util.EmptyStackException; | ||
import java.util.Stack; | ||
|
||
import javax.enterprise.inject.spi.InjectionPoint; | ||
|
||
import org.jboss.weld.bootstrap.api.Service; | ||
|
||
public class InjectionPointStack implements Service { | ||
|
||
private final ThreadLocal<Stack<InjectionPoint>> injectionPointStack; | ||
|
||
public InjectionPointStack() { | ||
this.injectionPointStack = new ThreadLocal<Stack<InjectionPoint>>(); | ||
} | ||
|
||
/** | ||
* Replaces (or adds) the current injection point. If a current injection | ||
* point exists, it will be replaced. If no current injection point exists, | ||
* one will be added. | ||
* | ||
* @param injectionPoint the injection point to use | ||
* @return the injection point added, or null if previous existed did not exist | ||
*/ | ||
public void push(InjectionPoint injectionPoint) { | ||
Stack<InjectionPoint> stack = injectionPointStack.get(); | ||
if (stack == null) { | ||
stack = new Stack<InjectionPoint>(); | ||
injectionPointStack.set(stack); | ||
} | ||
stack.push(injectionPoint); | ||
} | ||
|
||
public InjectionPoint pop() { | ||
Stack<InjectionPoint> stack = injectionPointStack.get(); | ||
if (stack == null) { | ||
throw new EmptyStackException(); | ||
} | ||
try { | ||
return stack.pop(); | ||
} finally { | ||
if (stack.isEmpty()) { | ||
injectionPointStack.remove(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* The injection point being operated on for this thread | ||
* | ||
* @return the current injection point | ||
*/ | ||
public InjectionPoint peek() { | ||
Stack<InjectionPoint> stack = injectionPointStack.get(); | ||
if (stack == null) { | ||
return null; | ||
} | ||
if (!stack.empty()) { | ||
return stack.peek(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public void cleanup() { | ||
|
||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
impl/src/main/java/org/jboss/weld/injection/SLSBInvocationInjectionPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2008, Red Hat, Inc., 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.weld.injection; | ||
|
||
public class SLSBInvocationInjectionPoint extends InjectionPointStack { | ||
|
||
} |
Oops, something went wrong.