deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r919737 - in /websites/staging/deltaspike/trunk/content: ./ core.html
Date Mon, 18 Aug 2014 20:48:12 GMT
Author: buildbot
Date: Mon Aug 18 20:48:11 2014
New Revision: 919737

Log:
Staging update by buildbot for deltaspike

Modified:
    websites/staging/deltaspike/trunk/content/   (props changed)
    websites/staging/deltaspike/trunk/content/core.html

Propchange: websites/staging/deltaspike/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Mon Aug 18 20:48:11 2014
@@ -1 +1 @@
-1618462
+1618726

Modified: websites/staging/deltaspike/trunk/content/core.html
==============================================================================
--- websites/staging/deltaspike/trunk/content/core.html (original)
+++ websites/staging/deltaspike/trunk/content/core.html Mon Aug 18 20:48:11 2014
@@ -141,6 +141,7 @@ Notice:    Licensed to the Apache Softwa
 <li><a href="#groupedconversationscoped">@GroupedConversationScoped</a></li>
 </ul>
 </li>
+<li><a href="#creating-a-custom-cdi-scope">Creating a custom CDI Scope</a></li>
 <li><a href="#deactivatable">Deactivatable</a></li>
 </ul>
 </li>
@@ -825,11 +826,79 @@ object to give flow control to the handl
 that exception chain, unless it's explicitly marked as unmuted via the
 <code>unmute()</code> method on <code>ExceptionEvent</code>.</p>
 <h2 id="scopes">Scopes</h2>
-<p>DeltaSpike Core provides the API and SPI for several scopes.
-Currently all scopes are only implemented in the JSF module.</p>
+<p>DeltaSpike Core provides the API and SPI for several scopes. Currently all scopes
are only implemented in the <a href="jsf.html#scopes">JSF module</a>. </p>
 <h3 id="windowscoped">@WindowScoped</h3>
 <h3 id="viewaccessscoped">@ViewAccessScoped</h3>
 <h3 id="groupedconversationscoped">@GroupedConversationScoped</h3>
+<h2 id="creating-a-custom-cdi-scope">Creating a custom CDI Scope</h2>
+<p>If you want to create a custom CDI scope to match your needs, you will need to follow
these steps:</p>
+<ol>
+<li>
+<p>First, create an Annotation with annotated with @javax.inject.Scope; Example:</p>
+<p>:::java
+@Scope
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE,ElementType.METHOD,ElementType.FIELD})
+public @interface ACustomScope {}</p>
+</li>
+<li>
+<p>Second, create an Extension to add the scope and a context for it. Example:</p>
+<p>:::java  <br />
+public class ACustomScopeExtension implements Extension, Serializable {</p>
+<div class="codehilite"><pre><span class="n">public</span> <span
class="n">void</span> <span class="n">addACustomScope</span><span
class="p">(@</span><span class="n">Observes</span> <span class="n">final</span>
<span class="n">BeforeBeanDiscovery</span> <span class="n">event</span><span
class="p">)</span> <span class="p">{</span>
+    <span class="n">event</span><span class="p">.</span><span
class="n">addScope</span><span class="p">(</span><span class="n">ACustomScope</span><span
class="p">.</span><span class="n">class</span><span class="p">,</span>
<span class="n">true</span><span class="p">,</span> <span class="n">false</span><span
class="p">);</span>
+<span class="p">}</span>
+
+<span class="n">public</span> <span class="n">void</span> <span
class="n">registerACustomScopeContext</span><span class="p">(@</span><span
class="n">Observes</span> <span class="n">final</span> <span class="n">AfterBeanDiscovery</span>
<span class="n">event</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">event</span><span class="p">.</span><span
class="n">addContext</span><span class="p">(</span><span class="n">new</span>
<span class="n">ACustomScopeContext</span><span class="p">());</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>}</p>
+</li>
+<li>
+<p>Implement a javax.enterprise.context.spi.Context interface to hold the javax.enterprise.inject.spi.Bean
instances according to your needs</p>
+<p>:::java
+public class ACustomScopeContext implements Context, Serializable {</p>
+<p>// Get the scope type of the context object.
+    public Class&lt;? extends Annotation&gt; getScope() {
+        return ACustomScope.class;
+    }</p>
+<div class="codehilite"><pre><span class="c1">// Return an existing instance
of certain contextual type or create a new instance by calling</span>
+<span class="c1">// javax.enterprise.context.spi.Contextual.create(CreationalContext)
and return the new instance.</span>
+<span class="n">public</span> <span class="o">&lt;</span><span
class="no">T</span><span class="o">&gt;</span> <span class="no">T</span>
<span class="n">get</span><span class="p">(</span><span class="n">Contextual</span><span
class="o">&lt;</span><span class="no">T</span><span class="o">&gt;</span>
<span class="n">contextual</span><span class="p">,</span> <span
class="n">CreationalContext</span><span class="o">&lt;</span><span
class="no">T</span><span class="o">&gt;</span> <span class="n">creationalContext</span><span
class="p">)</span> <span class="p">{</span>
+    <span class="n">Bean</span> <span class="n">bean</span> <span
class="o">=</span> <span class="p">(</span><span class="n">Bean</span><span
class="p">)</span> <span class="n">contextual</span><span class="p">;</span>
+    <span class="c1">// you can store the bean somewhere</span>
+    <span class="k">if</span> <span class="p">(</span><span class="n">somewhere</span><span
class="p">.</span><span class="n">containsKey</span><span class="p">(</span><span
class="n">bean</span><span class="p">.</span><span class="n">getName</span><span
class="p">()))</span> <span class="p">{</span>
+        <span class="k">return</span> <span class="p">(</span><span
class="no">T</span><span class="p">)</span> <span class="n">somewhere</span><span
class="p">.</span><span class="n">get</span><span class="p">(</span><span
class="n">bean</span><span class="p">.</span><span class="n">getName</span><span
class="p">());</span>
+    <span class="p">}</span> <span class="k">else</span> <span
class="p">{</span>
+        <span class="no">T</span> <span class="n">t</span> <span
class="o">=</span> <span class="p">(</span><span class="no">T</span><span
class="p">)</span> <span class="n">bean</span><span class="p">.</span><span
class="n">create</span><span class="p">(</span><span class="n">creationalContext</span><span
class="p">);</span>
+        <span class="n">somewhere</span><span class="p">.</span><span
class="n">put</span><span class="p">(</span><span class="n">bean</span><span
class="p">.</span><span class="n">getName</span><span class="p">(),</span>
<span class="n">t</span><span class="p">);</span>
+        <span class="k">return</span> <span class="n">t</span><span
class="p">;</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+
+<span class="c1">// Return an existing instance of a certain contextual type or a null
value.</span>
+<span class="n">public</span> <span class="o">&lt;</span><span
class="no">T</span><span class="o">&gt;</span> <span class="no">T</span>
<span class="n">get</span><span class="p">(</span><span class="n">Contextual</span><span
class="o">&lt;</span><span class="no">T</span><span class="o">&gt;</span>
<span class="n">contextual</span><span class="p">)</span> <span
class="p">{</span>
+    <span class="n">Bean</span> <span class="n">bean</span> <span
class="o">=</span> <span class="p">(</span><span class="n">Bean</span><span
class="p">)</span> <span class="n">contextual</span><span class="p">;</span>
+    <span class="c1">// you can store the bean somewhere</span>
+    <span class="k">if</span> <span class="p">(</span><span class="n">somewhere</span><span
class="p">.</span><span class="n">containsKey</span><span class="p">(</span><span
class="n">bean</span><span class="p">.</span><span class="n">getName</span><span
class="p">()))</span> <span class="p">{</span>
+        <span class="k">return</span> <span class="p">(</span><span
class="no">T</span><span class="p">)</span> <span class="n">somewhere</span><span
class="p">.</span><span class="n">get</span><span class="p">(</span><span
class="n">bean</span><span class="p">.</span><span class="n">getName</span><span
class="p">());</span>
+    <span class="p">}</span> <span class="k">else</span> <span
class="p">{</span>
+        <span class="k">return</span> <span class="k">null</span><span
class="p">;</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>// Determines if the context object is active.
+    public boolean isActive() {
+        return true;
+    }</p>
+<p>}</p>
+</li>
+</ol>
 <h2 id="deactivatable">Deactivatable</h2>
 <p>DeltaSpike allows you to deactivate its own Extensions. You just need to implement
your <a href="spi.html#classdeactivator">ClassDeactivator</a>.</p>
 <p>The ClassDeactivator should be resolved by any ConfigSource using the key <code>org.apache.deltaspike.core.spi.activation.ClassDeactivator</code>.
For example, we can disable SecurityExtension having the following class:</p>



Mime
View raw message