Package com.aspectran.core.context.env
Class ContextEnvironment
- java.lang.Object
-
- com.aspectran.core.context.env.ContextEnvironment
-
- All Implemented Interfaces:
Environment
public class ContextEnvironment extends java.lang.Object implements Environment
The Environment for ActivityContext.
-
-
Field Summary
-
Fields inherited from interface com.aspectran.core.context.env.Environment
ACTIVE_PROFILES_PROPERTY_NAME, DEFAULT_PROFILES_PROPERTY_NAME
-
-
Constructor Summary
Constructors Constructor Description ContextEnvironment()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acceptsProfiles(java.lang.String... profiles)
Return whether one or more of the given profiles is active or, in the case of no explicit active profiles, whether one or more of the given profiles is included in the set of default profiles.void
addPropertyItemRule(ItemRuleMap propertyItemRuleMap)
java.lang.String[]
getActiveProfiles()
Returns the set of profiles explicitly made active for this environment.java.lang.String[]
getDefaultProfiles()
Returns the set of profiles to be active by default when no active profiles have been set explicitly.<T> T
getProperty(java.lang.String name, Activity activity)
Returns the value of the property on environment via Activity.ItemRuleMap
getPropertyItemRuleMap()
void
setActiveProfiles(java.lang.String... profiles)
Specify the set of profiles active for thisEnvironment
.void
setDefaultProfiles(java.lang.String... profiles)
Specify the set of profiles to be made active by default if no other profiles are explicitly made active throughsetActiveProfiles(java.lang.String...)
.void
setPropertyItemRuleMap(ItemRuleMap propertyItemRuleMap)
protected void
validateProfile(java.lang.String profile)
Validate the given profile, called internally prior to adding to the set of active or default profiles.
-
-
-
Method Detail
-
getActiveProfiles
public java.lang.String[] getActiveProfiles()
Description copied from interface:Environment
Returns the set of profiles explicitly made active for this environment.- Specified by:
getActiveProfiles
in interfaceEnvironment
- Returns:
- the set of profiles explicitly made active
-
setActiveProfiles
public void setActiveProfiles(java.lang.String... profiles)
Specify the set of profiles active for thisEnvironment
. Profiles are evaluated during the ActivityContext configuration to determine whether configuration settings or rules should be registered.Any existing active profiles will be replaced with the given arguments; call with zero arguments to clear the current set of active profiles.
- Parameters:
profiles
- the set of profiles active- Throws:
java.lang.IllegalArgumentException
- if any profile is null, empty or whitespace-only- See Also:
setDefaultProfiles(java.lang.String...)
-
getDefaultProfiles
public java.lang.String[] getDefaultProfiles()
Description copied from interface:Environment
Returns the set of profiles to be active by default when no active profiles have been set explicitly.- Specified by:
getDefaultProfiles
in interfaceEnvironment
- Returns:
- the set of profiles to be active by default
-
setDefaultProfiles
public void setDefaultProfiles(java.lang.String... profiles)
Specify the set of profiles to be made active by default if no other profiles are explicitly made active throughsetActiveProfiles(java.lang.String...)
.Calling this method removes overrides any reserved default profiles that may have been added during construction of the environment.
- Parameters:
profiles
- the set of profiles to be made active by default
-
acceptsProfiles
public boolean acceptsProfiles(java.lang.String... profiles)
Description copied from interface:Environment
Return whether one or more of the given profiles is active or, in the case of no explicit active profiles, whether one or more of the given profiles is included in the set of default profiles. If a profile begins with '!' the logic is inverted, i.e. the method will return true if the given profile is not active. For example,env.acceptsProfiles("p1", "!p2")
will returntrue
if profile 'p1' is active or 'p2' is not active.- Specified by:
acceptsProfiles
in interfaceEnvironment
- Parameters:
profiles
- the given profiles- Returns:
- true if the given profile is active; false otherwise
- See Also:
Environment.getActiveProfiles()
,Environment.getDefaultProfiles()
-
validateProfile
protected void validateProfile(java.lang.String profile)
Validate the given profile, called internally prior to adding to the set of active or default profiles.Subclasses may override to impose further restrictions on profile syntax.
- Parameters:
profile
- the given profile- Throws:
java.lang.IllegalArgumentException
- if the profile is null, empty, whitespace-only or begins with the profile NOT operator (!)- See Also:
acceptsProfiles(java.lang.String...)
,setDefaultProfiles(java.lang.String...)
-
getPropertyItemRuleMap
public ItemRuleMap getPropertyItemRuleMap()
-
setPropertyItemRuleMap
public void setPropertyItemRuleMap(ItemRuleMap propertyItemRuleMap)
-
addPropertyItemRule
public void addPropertyItemRule(ItemRuleMap propertyItemRuleMap)
-
getProperty
public <T> T getProperty(java.lang.String name, Activity activity)
Description copied from interface:Environment
Returns the value of the property on environment via Activity.- Specified by:
getProperty
in interfaceEnvironment
- Type Parameters:
T
- the type of the value- Parameters:
name
- the given property nameactivity
- the current activity- Returns:
- the value of the property on environment
-
-