gt:         return instance(flexClass, null);
context: /*
   * ====================================================================
   * JAFFA - Java Application Framework For All
   *
   * Copyright (C) 2002 JAFFA Development Group
   *
   *     This library is free software; you can redistribute it and/or
   *     modify it under the terms of the GNU Lesser General Public
   *     License as published by the Free Software Foundation; either
   *     version 2.1 of the License, or (at your option) any later version.
   *
   *     This library is distributed in the hope that it will be useful,
   *     but WITHOUT ANY WARRANTY; without even the implied warranty of
   *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   *     Lesser General Public License for more details.
   *
   *     You should have received a copy of the GNU Lesser General Public
   *     License along with this library; if not, write to the Free Software
   *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   *
   * Redistribution and use of this software and associated documentation ("Software"),
   * with or without modification, are permitted provided that the following conditions are met:
   * 1.  Redistributions of source code must retain copyright statements and notices.
   *     Redistributions must also contain a copy of this document.
   * 2.  Redistributions in binary form must reproduce the above copyright notice,
   *     this list of conditions and the following disclaimer in the documentation
   *     and/or other materials provided with the distribution.
   * 3.  The name "JAFFA" must not be used to endorse or promote products derived from
   *     this Software without prior written permission. For written permission,
   *     please contact mail to: jaffagroup@yahoo.com.
   * 4.  Products derived from this Software may not be called "JAFFA" nor may "JAFFA"
   *     appear in their names without prior written permission.
   * 5.  Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net).
   *
   * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   */
  package org.jaffa.flexfields;
  
  import java.lang.reflect.Array;
  import java.util.Collection;
  import java.util.LinkedList;
  import java.util.Map;
  import java.util.Properties;
  import java.util.TreeMap;
  import javax.xml.bind.annotation.XmlTransient;
  import org.apache.commons.beanutils.DynaBean;
  import org.apache.commons.beanutils.DynaClass;
  import org.apache.log4j.Logger;
  import org.jaffa.components.finder.BooleanCriteriaField;
  import org.jaffa.components.finder.CriteriaField;
  import org.jaffa.components.finder.CurrencyCriteriaField;
  import org.jaffa.components.finder.DateOnlyCriteriaField;
  import org.jaffa.components.finder.DateTimeCriteriaField;
  import org.jaffa.components.finder.DecimalCriteriaField;
  import org.jaffa.components.finder.FinderTx;
  import org.jaffa.components.finder.IntegerCriteriaField;
  import org.jaffa.components.finder.StringCriteriaField;
  import org.jaffa.datatypes.Currency;
  import org.jaffa.datatypes.DataTypeMapper;
  import org.jaffa.datatypes.DateOnly;
  import org.jaffa.datatypes.DateTime;
  import org.jaffa.exceptions.ApplicationExceptions;
  import org.jaffa.exceptions.FrameworkException;
  import org.jaffa.flexfields.domain.FlexFieldMeta;
  import org.jaffa.metadata.FieldMetaData;
  import org.jaffa.persistence.Criteria;
  import org.jaffa.persistence.util.PersistentHelper;
  import org.jaffa.rules.IObjectRuleIntrospector;
  import org.jaffa.rules.RulesEngineFactory;
  import org.jaffa.util.StringHelper;
  
  /**
   * FlexBean implements the DynaBean interface.
   * <p>
   * It holds the following information when linked to a persistent object:
   *   flexClass: the associated DynaClass
   *   persistentObject: the persistent object for which this bean will hold FlexField instances.
   *   flexFields: the associated FlexField instances.
   * NOTE: For a persistent object, the setter will either set a flex field directly on the
   * associated persistent object, if a domain-mapping is provided, or the flex field will be
   * added to the flexFields property.
   * <p>
   * It holds the following information when linked to a non-persistent object:
   *   flexClass: the associated DynaClass
   *   flexParams: the associated FlexParam instances.
   * NOTE: For a non-persistent object, the setter will always add the flex field to the
   * flexParams property.
   * <p>
   * It is highly recommended to use the instance() method to instantiate this bean.
   */
  public class FlexCriteriaBean implements DynaBean {
  
      private static Logger log = Logger.getLogger(FlexCriteriaBean.class);
      private FlexClass flexClass;
      private Map<String, FlexCriteriaParam> flexCriteriaParams = new TreeMap<String, FlexCriteriaParam>();
  
      /**
       * Creates a new instance.
       */
      public FlexCriteriaBean() {
      }
  
      /**
       * Creates a new instance.
       * @param flexClass the associated FlexClass.
       */
      public FlexCriteriaBean(FlexClass flexClass) {
          this.flexClass = flexClass;
      }
  
      // *************************
      // **** IMPLEMENTATION *****
      // *************************
      /**
       * NOTE: This is an unsupported operation for a FlexCriteriaBean instance.
       */
      public boolean contains(String name, String key) {
          throw new UnsupportedOperationException();
      }
  
      /**
       * Return the value of the input property.
       * If the property has a domain-mapping (as determined from the associated FlexProperty, value will
       * be obtained from the persistentObject. Else the value will be obtained from
       * the appropriate FlexField instance.
       * @param name the property name.
       * @return value for the property.
       */
      public Object get(String name) {
          return getset(true, name, null, null);
      }
  
      /**
       * NOTE: This is an unsupported operation for a FlexCriteriaBean instance.
       */
      public Object get(String name, int index) {
          throw new UnsupportedOperationException();
      }
  
      /**
       * NOTE: This is an unsupported operation for a FlexCriteriaBean instance.
       */
      public Object get(String name, String key) {
          throw new UnsupportedOperationException();
      }
  
      /**
       * Return the FlexClass instance that describes the set of properties available for this FlexCriteriaBean.
       * @return the FlexClass instance that describes the set of properties available for this FlexCriteriaBean.
       */
      @XmlTransient
      public DynaClass getDynaClass() {
          return flexClass;
      }
  
      /**
       * NOTE: This is an unsupported operation for a FlexCriteriaBean instance.
       */
      public void remove(String name, String key) {
          throw new UnsupportedOperationException();
      }
  
      /**
       * Sets the value of the input property.
       * If the property has a domain-mapping (as determined from the associated FlexProperty, value will
       * be stamped on the persistentObject. Else the value will be stamped on
       * the appropriate FlexField instance.
       * @param name the property name.
       * @param value the new value.
       */
      public void set(String name, Object value) {
          getset(false, name, value, null);
      }
  
      /**
       * NOTE: This is an unsupported operation for a FlexCriteriaBean instance.
       */
      public void set(String name, int index, Object value) {
          throw new UnsupportedOperationException();
      }
  
      /**
       * NOTE: This is an unsupported operation for a FlexCriteriaBean instance.
       */
      public void set(String name, String key, Object value) {
          throw new UnsupportedOperationException();
      }
  
      // ***********************************
      // **** METHODS TO SUPPORT TOOLS *****
      // ***********************************
      /**
       * Sets the FlexClass instance that describes the set of properties available for this FlexCriteriaBean.
       *
       * NOTE: This method will throw a ClassCastException if a non-FlexClass argument is passed.
       * DynaClass is used in the signature so that this property turns up as a valid read+write property via the JavaBeans Introspector.
       * @param flexClass new value for the property flexClass.
       */
      public void setDynaClass(DynaClass flexClass) {
          this.flexClass = (FlexClass) flexClass;
      }
  
      /**
       * Getter for the property flexCriteriaParams.
       * @return the value of the property flexCriteriaParams.
       */
      public FlexCriteriaParam[] getFlexCriteriaParams() {
          return flexCriteriaParams.values().toArray(new FlexCriteriaParam[flexCriteriaParams.size()]);
      }
  
      /**
       * Setter for the property flexCriteriaParams.
       * @param flexCriteriaParams new value for the property flexCriteriaParams.
       */
      public void setFlexCriteriaParams(FlexCriteriaParam[] flexCriteriaParams) {
          if (flexCriteriaParams != null) {
              for (FlexCriteriaParam flexCriteriaParam : flexCriteriaParams)
                  getset(false, null, null, flexCriteriaParam);
          }
      }
  
      // *****************************
      // **** ADDITIONAL METHODS *****
      // *****************************
      /**
       * Returns debug info.
       * @return debug info.
       */
      @Override
      public String toString() {
          StringBuilder buf = new StringBuilder();
          try {
              buf.append("<FlexCriteriaBean");
              if (flexClass != null)
                  buf.append(" name='").append(flexClass.getName()).append("' logicalName='").append(flexClass.getLogicalName()).append('\'');
              buf.append('>');
              if (flexClass != null) {
                  for (FlexProperty f : flexClass.getDynaProperties()) {
                      buf.append('<').append(f.getName()).append(" logicalName='").append(f.getLogicalName()).append("' value='");
                      Object value = get(f.getName());
                      if (value != null)
                          buf.append(value);
                      buf.append("'/>");
                  }
              } else {
                  for (FlexCriteriaParam flexCriteriaParam : flexCriteriaParams.values()) {
                      buf.append('<').append(flexCriteriaParam.getName()).append("' value='");
                      if (flexCriteriaParam.getValue() != null)
                          buf.append(flexCriteriaParam.getValue());
                      buf.append("'/>");
                  }
              }
              buf.append("</FlexCriteriaBean>");
          } catch (Exception ignore) {
          }
          return buf.toString();
      }
  
      /**
       * This is the recommended way to instantiate a FlexCriteriaBean.
       * It obtains the appropriate FlexClass.
       * @param object the associated object.
       * @return a FlexCriteriaBean instance.
       * @throws ApplicationExceptions if any application error occurs.
       * @throws FrameworkException if any framework error occurs.
       */
      public static FlexCriteriaBean instance(Object object) throws ApplicationExceptions, FrameworkException {
          if (object instanceof FlexClass)
              return instance((FlexClass) object);
          else {
              FlexClass flexClass = FlexClass.instance(object);
              return instance(flexClass, object);
          }
      }
  
      /**
       * Creates an instance based on the input FlexClass and clears all the initial values.
       * @param flexClass the associated FlexClass.
       * @return a FlexCriteriaBean instance.
       * @throws ApplicationExceptions if any application error occurs.
       * @throws FrameworkException if any framework error occurs.
       */
      public static FlexCriteriaBean instance(FlexClass flexClass) throws ApplicationExceptions, FrameworkException {
  