This class is the base of all ProjectStages. A ProjectStage identifies the environment the application currently runs in. It provides the same functionality as the JSF-2 ProjectStage but has a few additional benefits:
- it also works for JSF-1.0, JSF-1.1 and JSF-1.2 applications
- it also works in pure backends and unit tests without any faces-api
- it is dynamic. Everyone can add own ProjectStages!
Technically this is kind of a 'dynamic enum'.
The following ProjectStages are provided by default
- UnitTest
- Development
- SystemTest
- IntegrationTest
- Staging
- Production
The following resolution mechanism is used to determine the current ProjectStage:
Adding a new ProjectStage is done via the {@link java.util.ServiceLoader} mechanism. A class deriving from {@link ProjectStage}must be provided and used for creating a single static instance of it.
Custom ProjectStages can be implemented by writing anonymous ProjectStage members into a registered {@link ProjectStageHolder} as shown in the followingsample:
package org.apache.myfaces.extensions.cdi.test.api.projectstage; public class MyProjectStages implements ProjectStageHolder { public static final class MyOwnProjectStage extends ProjectStage {}; public static final MyOwnProjectStage MyOwnProjectStage = new MyOwnProjectStage(); public static final class MyOtherProjectStage extends ProjectStage {}; public static final MyOtherProjectStage MyOtherProjectStage = new MyOtherProjectStage(); }
For activating those projectstages, you have to register this ProjectStageHolder class to get picked up via the java.util.ServiceLoader mechanism. Simply create a file
META-INF/services/org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStageHolder
which contains the fully qualified class name of custom ProjectStageHolder implementation:
# this class now get's picked up by java.util.ServiceLoader org.apache.myfaces.extensions.cdi.core.test.api.projectstage.MyProjectStages
You can use your own ProjectStages exactly the same way as all the ones provided by the system:
ProjectStage myOwnPs = ProjectStage.valueOf("MyOwnProjectStage"); if (myOwnPs.equals(MyOwnProjectStage.MyOwnProjectStage)) ...