Class ContextEnvironment

  • All Implemented Interfaces:
    Environment

    public class ContextEnvironment
    extends java.lang.Object
    implements Environment
    The Environment for ActivityContext.
    • Constructor Detail

      • ContextEnvironment

        public ContextEnvironment()
    • 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 interface Environment
        Returns:
        the set of profiles explicitly made active
      • setActiveProfiles

        public void setActiveProfiles​(java.lang.String... profiles)
        Specify the set of profiles active for this Environment. 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 interface Environment
        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 through setActiveProfiles(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 return true if profile 'p1' is active or 'p2' is not active.
        Specified by:
        acceptsProfiles in interface Environment
        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 interface Environment
        Type Parameters:
        T - the type of the value
        Parameters:
        name - the given property name
        activity - the current activity
        Returns:
        the value of the property on environment