001    package com.oxygenxml.validate.nvdl;
002    
003    /**
004     * Possible values for match, that is represented as a list of elements and attributes.
005     */
006    class ElementsOrAttributes {
007      /**
008       * Flag for none.
009       */
010      private static final int NONE_FLAG = 0;
011      
012      /**
013       * Flag for elements.
014       */
015      private static final int ELEMENTS_FLAG = 01;
016      
017      /**
018       * Flag for attributes.
019       */
020      private static final int ATTRIBUTES_FLAG = 02;
021    
022      // Define constants for all possible values.
023      /**
024       * Neither elements nor attributes specified.
025       */
026      static final ElementsOrAttributes NEITHER = new ElementsOrAttributes(NONE_FLAG);
027      /**
028       * Only elements is specified.
029       */
030      static final ElementsOrAttributes ELEMENTS = new ElementsOrAttributes(ELEMENTS_FLAG);
031      
032      /**
033       * Only attributes is specified.
034       */
035      static final ElementsOrAttributes ATTRIBUTES = new ElementsOrAttributes(ATTRIBUTES_FLAG);
036      
037      /**
038       * Bothe elements and attributes are specified.
039       */
040      static final ElementsOrAttributes BOTH = new ElementsOrAttributes(ELEMENTS_FLAG|ATTRIBUTES_FLAG);
041    
042      /**
043       * All possible values.
044       */
045      private static final ElementsOrAttributes values[] = {
046        NEITHER,
047        ELEMENTS,
048        ATTRIBUTES,
049        BOTH
050      };
051    
052      /**
053       * Stores this instance flags.
054       */
055      private int flags = NONE_FLAG;
056    
057      /**
058       * Creates an instance with the given flags.
059       * @param flags
060       */
061      private ElementsOrAttributes(int flags) {
062        this.flags = flags;
063      }
064    
065      /**
066       * Get the value after adding elements to the current instance.
067       * @return The value that matches also elements.
068       */
069      ElementsOrAttributes addElements() {
070        return values[flags | ELEMENTS_FLAG];
071      }
072    
073      /**
074       * Get the value after adding attributes to the current instance.
075       * @return The value that matches also attributes.
076       */
077      ElementsOrAttributes addAttributes() {
078        return values[flags | ATTRIBUTES_FLAG];
079      }
080    
081      /**
082       * Checks whether the attributes are matched or not. 
083       * @return true is attributes are matched.
084       */
085      boolean containsAttributes() {
086        return (flags & ATTRIBUTES_FLAG) != 0;
087      }
088    
089      /**
090       * Checks whether the elements are matched or not. 
091       * @return true is elements are matched.
092       */
093      boolean containsElements() {
094        return (flags & ELEMENTS_FLAG) != 0;
095      }
096    }