org.apache.myfaces.extensions.cdi.core.impl.projectstage
Class ProjectStageProducer

java.lang.Object
  extended by org.apache.myfaces.extensions.cdi.core.impl.projectstage.ProjectStageProducer

@ApplicationScoped
public class ProjectStageProducer
extends Object

Produces ProjectStage configurations.

The producer will try to detect the currently active ProjectStage on startup and use that for all generated fields.

In case a JSF runtime is not available (e.g. in unit tests) we do all the determining ourself (but in the same way as MyFaces does it!)

Usage:

Simply inject the current ProjectStage into any bean:
 public class MyBean {
   private @Inject ProjectStage projectStage;

   public void fn() {
     if(projectStage == ProjectStage.Production) {
        // do some prodution stuff...
     }
   }
 }
 
TODO move jsf specific parts


Field Summary
static String JSF_PROJECT_STAGE_SYSTEM_PROPERTY_NAME
          System Property to set the ProjectStage, if not present via the standard way
static String PROJECT_STAGE_JNDI_NAME
          JNDI path for the ProjectStage
 
Constructor Summary
protected ProjectStageProducer()
          ProjectStageProducers must only be created by subclassing producers
 
Method Summary
protected  ProjectStage determineCustomProjectStage()
          This can get used to provide additional ProjectStage lookup mechanisms.
 void determineProjectStage()
          Read the configuration from the stated places.
static ProjectStageProducer getInstance()
          This factory method should only get used if there is absolutly no way to get the current ProjectStage via @Inject.
 ProjectStage getProjectStage()
          We can only produce @Dependent scopes since an enum is final.
protected  ProjectStage getProjectStageFromEnvironment()
           
protected  ProjectStage getProjectStageFromJNDI()
           
static void setProjectStage(ProjectStage ps)
          This function can be used to manually set the ProjectStage for the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROJECT_STAGE_JNDI_NAME

public static final String PROJECT_STAGE_JNDI_NAME
JNDI path for the ProjectStage

See Also:
Constant Field Values

JSF_PROJECT_STAGE_SYSTEM_PROPERTY_NAME

public static final String JSF_PROJECT_STAGE_SYSTEM_PROPERTY_NAME
System Property to set the ProjectStage, if not present via the standard way

See Also:
Constant Field Values
Constructor Detail

ProjectStageProducer

protected ProjectStageProducer()
ProjectStageProducers must only be created by subclassing producers

Method Detail

getProjectStage

@Produces
@Dependent
@Default
public ProjectStage getProjectStage()
We can only produce @Dependent scopes since an enum is final.

Returns:
current ProjectStage

getInstance

public static ProjectStageProducer getInstance()
                                        throws IOException,
                                               ClassNotFoundException,
                                               IllegalAccessException,
                                               InstantiationException

This factory method should only get used if there is absolutly no way to get the current ProjectStage via @Inject.

Returns:
the ProjectStageProducer instance.
Throws:
IOException
ClassNotFoundException
IllegalAccessException
InstantiationException

setProjectStage

public static void setProjectStage(ProjectStage ps)
This function can be used to manually set the ProjectStage for the application. This is e.g. useful in unit tests.

Parameters:
ps - the ProjectStage to set

determineProjectStage

@Inject
public void determineProjectStage()
Read the configuration from the stated places. This can be overloaded to implement own lookup mechanisms. This will only determine the ProjectStage if it is not yet set.


determineCustomProjectStage

protected ProjectStage determineCustomProjectStage()
This can get used to provide additional ProjectStage lookup mechanisms.

Returns:
the detected ProjectStage or null if non was found.

getProjectStageFromEnvironment

protected ProjectStage getProjectStageFromEnvironment()

getProjectStageFromJNDI

protected ProjectStage getProjectStageFromJNDI()


Copyright © 2010 The Apache Software Foundation. All Rights Reserved.