Save This Page
Home » apache-openwebbeans-1.0.0-incubating-M3-sources » javax.enterprise.context.spi » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   10    * http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied.  See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   package javax.enterprise.context.spi;
   20   
   21   import java.lang.annotation.Annotation;
   22   
   23   import javax.enterprise.context.ContextNotActiveException;
   24   import javax.enterprise.context.NormalScope;
   25   
   26   /**
   27    * Every webbeans component has an associated context that are
   28    * defined by the {@link NormalScope} annotation. Webbeans components
   29    * that are contained in the context are managed by the webbeans container.
   30    * 
   31    * <p>
   32    * Every context has a well-defined lifecycle. It means that
   33    * in some time, context is active and some other time context may
   34    * be passive. Moreover, each context is created and destroyed by the container
   35    * according to the timing requirements. For example, request context is started by every 
   36    * http request and destroyed at the end of the http response. According to the current thread,
   37    * active context is called an thread current context.
   38    * </p>
   39    * 
   40    * <p>
   41    * Context is responsible for creating and destroying the {@link Contextual} instances of the
   42    * webbeans components.
   43    * </p>
   44    * 
   45    * @version $Rev: 815435 $ $Date: 2009-09-15 21:18:44 +0300 (Tue, 15 Sep 2009) $
   46    */
   47   public interface Context
   48   {   
   49       /**
   50        * Returns the scope type of the context.
   51        * 
   52        * @return the scope type of the context
   53        */
   54       public Class<? extends Annotation> getScope();
   55   
   56       /**
   57        * If the context is not active, throws {@link ContextNotActiveException}.
   58        * Otherwise, it looks for the given component instance in the context map. If
   59        * this context contains the given webbeans component instance, it returns the component.
   60        * If the component is not found in this context map, it looks for the <code>creationalContext</code>
   61        * argument. If it is null, it returns null, otherwise new webbeans instance is created
   62        * and puts into the context and returns it.
   63        * 
   64        * @param <T> type of the webbeans component
   65        * @param component webbeans component
   66        * @param creationalContext {@link CreationalContext} instance
   67        * @return the contextual instance or null
   68        */
   69       public <T> T get(Contextual<T> component, CreationalContext<T> creationalContext);
   70   
   71       /**
   72        * Returns the instance of the webbeans in this context if exist otherwise return null.
   73        * 
   74        * @param <T> type of the webbeans component
   75        * @param component webbeans component
   76        * @return the instance of the webbeans in this context if exist otherwise return null
   77        */
   78       public <T> T get(Contextual<T> component);
   79   
   80       /**
   81        * Returns true if context is active according to the current thread,
   82        * returns false otherwise. 
   83        * 
   84        * @return true if context is active according to the current thread, 
   85        * return false otherwise
   86        */
   87       boolean isActive();
   88   }

Save This Page
Home » apache-openwebbeans-1.0.0-incubating-M3-sources » javax.enterprise.context.spi » [javadoc | source]