Package com.aspectran.core.context.env
Interface Environment
- All Known Implementing Classes:
ActivityEnvironment
public interface Environment
Interface representing the environment in which the current application is running.
Models two key aspects of the application environment: profiles and properties.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
acceptsProfiles
(Profiles profiles) Determine whether the givenProfiles
predicate matches the active profiles — or in the case of no explicit active profiles, whether the givenProfiles
predicate matches the default profiles.boolean
acceptsProfiles
(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
addActiveProfile
(String profile) Add a profile to the current set of active profiles.String[]
Return the set of profiles explicitly made active for this environment.String[]
Return the set of profiles explicitly made active for this environment.String[]
Return the set of profiles to be active by default when no active profiles have been set explicitly.<T> T
getProperty
(String name) Returns the value of the property on environment via the currently available activity.<T> T
getProperty
(String name, Activity activity) Returns the value of the property on environment via the specified activity.boolean
matchesProfiles
(String profileExpression) Determine whether one of the given profile expressions matches the active profiles — or in the case of no explicit active profiles, whether one of the given profile expressions matches the default profiles.
-
Method Details
-
getActiveProfiles
String[] getActiveProfiles()Return the set of profiles explicitly made active for this environment. Profiles are used for creating logical groupings of bean definitions to be registered conditionally, for example based on deployment environment. Profiles can be activated by setting "aspectran.profiles.active" as a system property or by callingEnvironmentProfiles.setActiveProfiles(String...)
.If no profiles have explicitly been specified as active, then any default profiles will automatically be activated.
-
getDefaultProfiles
String[] getDefaultProfiles()Return the set of profiles to be active by default when no active profiles have been set explicitly. -
getCurrentProfiles
String[] getCurrentProfiles()Return the set of profiles explicitly made active for this environment. If no active profile is explicitly set, returns the set of profiles to be active by default. -
matchesProfiles
Determine whether one of the given profile expressions matches the active profiles — or in the case of no explicit active profiles, whether one of the given profile expressions matches the default profiles.Profile expressions allow for complex, boolean profile logic to be expressed — for example
"p1 & p2"
,"(p1 & p2) | p3"
, etc. SeeProfiles.of(String)
for details on the supported expression syntax.This method is a convenient shortcut for
env.acceptsProfiles(Profiles.of(profileExpression))
.- Since:
- 7.5.0
- See Also:
-
acceptsProfiles
Determine whether the givenProfiles
predicate matches the active profiles — or in the case of no explicit active profiles, whether the givenProfiles
predicate matches the default profiles.If you wish provide profile expressions directly as strings, use
matchesProfiles(String)
instead.- Since:
- 7.5.0
- See Also:
-
acceptsProfiles
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.- Parameters:
profiles
- the given profiles- Returns:
- true if the given profile is active; false otherwise
- Throws:
IllegalArgumentException
- if called with zero arguments or if any profile isnull
, empty or whitespace-only- See Also:
-
addActiveProfile
Add a profile to the current set of active profiles.- Throws:
IllegalArgumentException
- if the profile is null, empty or whitespace-only
-
getProperty
Returns the value of the property on environment via the currently available activity.- Type Parameters:
T
- the type of the value- Parameters:
name
- the given property name- Returns:
- the value of the property on environment
-
getProperty
Returns the value of the property on environment via the specified activity.- Type Parameters:
T
- the type of the value- Parameters:
name
- the given property nameactivity
- the activity- Returns:
- the value of the property on environment
-