// Path: src/main/java/org/dynaform/xml/form/FormElement.java
// public interface FormElement<E> extends Form, Data<E>, Labeled {
// 	
//   Data<E> getData();
//   
//   Restrictions<E> getRestrictions();
//   
// 	String getLabel();
// 	void setLabel(String label);
// 	
// 	Control getControl();
// 	void setControl(Control control);
// 	
// 	boolean isReadOnly();
// 	void setReadOnly(boolean readOnly);
// 	
// 	boolean isRequired();
// 	void setRequired(boolean required);
// 	
// 	boolean isDisabled();
// 	void setDisabled(boolean disabled);
// 	
// 	// Listeners
// 	
//   void addListener(ElementChangeListener<E> listener);
//   void removeListener(ElementChangeListener<E> listener);
//   
//   public interface ElementChangeListener<E> {
//     void onSetValue(FormElement<E> element);
//     void onSetLabel(FormElement<E> element);
//     void onSetControl(FormElement<E> element);
//     void onSetReadOnly(FormElement<E> element);
//     void onSetRequired(FormElement<E> element);
//     void onSetDisabled(FormElement<E> element);
//   }	
// 	
// }
// 
// Path: src/main/java/org/dynaform/xml/form/restriction/Choice.java
// public interface Choice<E> {
// 
//   String getLabel();
//   void setLabel(String label);
//   
//   E getValue();
//   void setValue(E value);
//   
// }


import org.dynaform.xml.form.FormElement;
import org.dynaform.xml.form.control.Control;
import org.dynaform.xml.form.data.Data;
import org.dynaform.xml.form.data.DateData;
import org.dynaform.xml.form.restriction.Choice;
import org.dynaform.xml.form.restriction.Restrictions;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.araneaframework.uilib.form.control.CheckboxControl;
import org.araneaframework.uilib.form.control.DateControl;
import org.araneaframework.uilib.form.control.DateTimeControl;
import org.araneaframework.uilib.form.control.DisplayControl;
import org.araneaframework.uilib.form.control.FloatControl;
import org.araneaframework.uilib.form.control.NumberControl;
import org.araneaframework.uilib.form.control.SelectControl;
import org.araneaframework.uilib.form.control.TextControl;
import org.araneaframework.uilib.form.control.TextareaControl;
import org.araneaframework.uilib.form.control.TimeControl;
import org.araneaframework.uilib.support.DisplayItem;

package org.dynaform.web.form.builder;



/**
 * Converts an abstract form into Aranea Widget.
 * 
 * @author Rein Raudjärv
 * 
 * @see FormElement
 * @see AraneaControlEntry
 * @see AraneaFormBuilder
 */
public class ControlBuilder {

  private static final int MAX_LENGTH_LONG  = String.valueOf(Long.MIN_VALUE).length();
  private static final int MAX_LENGTH_INT   = String.valueOf(Integer.MIN_VALUE).length();
  private static final int MAX_LENGTH_SHORT = String.valueOf(Short.MIN_VALUE).length();
  private static final int MAX_LENGTH_BYTE  = String.valueOf(Byte.MIN_VALUE).length();
  
  private static final int SELECT_BOX_MAX_SIZE = 8;
  
  private static final String SELECT_BOX_NULL_VALUE = null;
  private static final String SELECT_BOX_NULL_LABEL = "";

  private static final String RADIO_SELECT_BOX_NULL_VALUE = "__null__";
  private static final String RADIO_SELECT_BOX_NULL_LABEL = "-";
  

// Path: src/main/java/org/dynaform/xml/form/FormElement.java
// public interface FormElement<E> extends Form, Data<E>, Labeled {
// 	
//   Data<E> getData();
//   
//   Restrictions<E> getRestrictions();
//   
// 	String getLabel();
// 	void setLabel(String label);
// 	
// 	Control getControl();
// 	void setControl(Control control);
// 	
// 	boolean isReadOnly();
// 	void setReadOnly(boolean readOnly);
// 	
// 	boolean isRequired();
// 	void setRequired(boolean required);
// 	
// 	boolean isDisabled();
// 	void setDisabled(boolean disabled);
// 	
// 	// Listeners
// 	
//   void addListener(ElementChangeListener<E> listener);
//   void removeListener(ElementChangeListener<E> listener);
//   
//   public interface ElementChangeListener<E> {
//     void onSetValue(FormElement<E> element);
//     void onSetLabel(FormElement<E> element);
//     void onSetControl(FormElement<E> element);
//     void onSetReadOnly(FormElement<E> element);
//     void onSetRequired(FormElement<E> element);
//     void onSetDisabled(FormElement<E> element);
//   }	
// 	
// }
// 
// Path: src/main/java/org/dynaform/xml/form/restriction/Choice.java
// public interface Choice<E> {
// 
//   String getLabel();
//   void setLabel(String label);
//   
//   E getValue();
//   void setValue(E value);
//   
// }


// Path: src/main/java/org/dynaform/web/form/builder/ControlBuilder.java
import org.dynaform.xml.form.FormElement;
import org.dynaform.xml.form.control.Control;
import org.dynaform.xml.form.data.Data;
import org.dynaform.xml.form.data.DateData;
import org.dynaform.xml.form.restriction.Choice;
import org.dynaform.xml.form.restriction.Restrictions;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.araneaframework.uilib.form.control.CheckboxControl;
import org.araneaframework.uilib.form.control.DateControl;
import org.araneaframework.uilib.form.control.DateTimeControl;
import org.araneaframework.uilib.form.control.DisplayControl;
import org.araneaframework.uilib.form.control.FloatControl;
import org.araneaframework.uilib.form.control.NumberControl;
import org.araneaframework.uilib.form.control.SelectControl;
import org.araneaframework.uilib.form.control.TextControl;
import org.araneaframework.uilib.form.control.TextareaControl;
import org.araneaframework.uilib.form.control.TimeControl;
import org.araneaframework.uilib.support.DisplayItem;

package org.dynaform.web.form.builder;



/**
 * Converts an abstract form into Aranea Widget.
 * 
 * @author Rein Raudjärv
 * 
 * @see FormElement
 * @see AraneaControlEntry
 * @see AraneaFormBuilder
 */
public class ControlBuilder {

  private static final int MAX_LENGTH_LONG  = String.valueOf(Long.MIN_VALUE).length();
  private static final int MAX_LENGTH_INT   = String.valueOf(Integer.MIN_VALUE).length();
  private static final int MAX_LENGTH_SHORT = String.valueOf(Short.MIN_VALUE).length();
  private static final int MAX_LENGTH_BYTE  = String.valueOf(Byte.MIN_VALUE).length();
  
  private static final int SELECT_BOX_MAX_SIZE = 8;
  
  private static final String SELECT_BOX_NULL_VALUE = null;
  private static final String SELECT_BOX_NULL_LABEL = "";

  private static final String RADIO_SELECT_BOX_NULL_VALUE = "__null__";
  private static final String RADIO_SELECT_BOX_NULL_LABEL = "-";
  

  static <E> AraneaControlEntry getFormControl(FormElement<E> element) {
