Class ComponentGroup


  • public class ComponentGroup
    extends Object

    This class represents a group of components.

    The form builder library supports adding components to logical groups. Logical in this context means that these groups do not have a direct representation on the generated GUI. They exist only during the builder process and can be used to reference components. Examples include constructing radio groups or composite component handlers.

    A ComponentGroup instance does not contain the components themselves, but rather their names. For obtaining the corresponding components access to a ComponentBuilderData object is required.

    Version:
    $Id: ComponentGroup.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • ComponentGroup

        public ComponentGroup()
        Creates a new instance of ComponentGroup.
    • Method Detail

      • getComponentNames

        public Set<String> getComponentNames()
        Returns a set with the names of all components contained in this group. The order of elements in the set corresponds to the order in which the components have been added to this group.
        Returns:
        a set with the names of all contained components
      • addComponent

        public void addComponent​(String name)
        Adds a component to this group.
        Parameters:
        name - the name of the component to add
      • getComponents

        public Map<String,​Object> getComponents​(ComponentBuilderData data)
                                               throws FormBuilderException
        Returns a map with all components this group refers to. This method looks up all component names in the specified ComponentBuilderData object. The resulting map contains the names of the components as keys and the corresponding component objects as values. If a component name cannot be resolved, a FormBuilderException exception is thrown.
        Parameters:
        data - the ComponentBuilderData object (must not be null)
        Returns:
        a map with all components that belong to this group
        Throws:
        FormBuilderException - if a component cannot be resolved
        IllegalArgumentException - if the ComponentBuilderData object is null
      • fromContext

        public static ComponentGroup fromContext​(org.apache.commons.jelly.JellyContext context,
                                                 String name)
                                          throws NoSuchElementException
        Fetches the group with the given name from the specified jelly context. If the group does not exist, an exception will be thrown.
        Parameters:
        context - the jelly context (must not be null
        name - the name of the desired group
        Returns:
        the group with this name
        Throws:
        IllegalArgumentException - if the context is null
        NoSuchElementException - if there is no such group
      • groupExists

        public static boolean groupExists​(org.apache.commons.jelly.JellyContext context,
                                          String name)
        Tests whether a group with the specified name exists in the given jelly context. Note that ComponentGroup objects are not stored under their name in the context, but a specific prefix is used. So always this method has to be used to check the existence of a group rather than testing the context directly.
        Parameters:
        context - the jelly context
        name - the name of the group
        Returns:
        true if there is such a group, false otherwise
        Throws:
        IllegalArgumentException - if the context is null
      • storeGroup

        public static void storeGroup​(org.apache.commons.jelly.JellyContext context,
                                      String name,
                                      ComponentGroup group)
        Stores a component group in the jelly context under a given name.
        Parameters:
        context - the context
        name - the group's name
        group - the group to store (if null , the group will be removed if it exists)
      • createGroup

        public static ComponentGroup createGroup​(org.apache.commons.jelly.JellyContext context,
                                                 String name)
                                          throws FormBuilderException
        Creates a new ComponentGroup instance and stores it in the specified context. This is a convenience method which performs the following steps:
        1. It checks whether already a group with the specified name exists in the context. If this is the case, an exception is thrown.
        2. Otherwise a new ComponentGroup instance is created.
        3. The new instance is stored in the context under the specified name.
        4. The newly created instance is returned.
        Parameters:
        context - the Jelly context (must not be null
        name - the name of the new ComponentGroup (must not be null)
        Returns:
        the newly created ComponentGroup instance
        Throws:
        FormBuilderException - if a group with this name already exists
        IllegalArgumentException - if the group name or the context is null
      • fromBeanContext

        public static ComponentGroup fromBeanContext​(BeanContext context,
                                                     String groupName)
        Obtains the ComponentGroup with the specified name from the given BeanContext. This method is similar to fromContext(JellyContext, String), but the ComponentGroup is resolved from a BeanContext object. This can be useful if the group is to be obtained after a builder operation. In this case, the Jelly context may not be available directly, but it can be accessed through the BeanContext returned by the builder.
        Parameters:
        context - the BeanContext
        groupName - the name of the group to be obtained
        Returns:
        the corresponding ComponentGroup instance
        Throws:
        IllegalArgumentException - if the BeanContext is null
        InjectionException - if the group cannot be resolved
      • groupExistsInBeanContext

        public static boolean groupExistsInBeanContext​(BeanContext context,
                                                       String groupName)
        Tests whether a group with the specified name exists in the given BeanContext. Works like groupExists(JellyContext, String), but checks the given BeanContext.
        Parameters:
        context - the BeanContext
        groupName - the name of the group in question
        Returns:
        a flag whether this ComponentGroup can be found in this BeanContext
        Throws:
        IllegalArgumentException - if the BeanContext is null