Java tutorial
// license-header java merge-point package es.pode.empaquetador.presentacion.avanzado.submanifiestos.desagregar; public class DesagregarSubmanifiestoFormImpl extends org.apache.struts.validator.ValidatorForm implements java.io.Serializable, es.pode.empaquetador.presentacion.avanzado.submanifiestos.desagregar.RecuperarDatosForm, es.pode.empaquetador.presentacion.avanzado.submanifiestos.desagregar.DesagregarLocalForm, es.pode.empaquetador.presentacion.avanzado.submanifiestos.desagregar.EsOfflineForm { private java.lang.String destino; private java.lang.Object[] destinoValueList; private java.lang.Object[] destinoLabelList; private java.util.List identificadores; private java.lang.Object[] identificadoresValueList; private java.lang.Object[] identificadoresLabelList; private java.lang.String action; private java.lang.Object[] actionValueList; private java.lang.Object[] actionLabelList; public DesagregarSubmanifiestoFormImpl() { } /** * Resets the given <code>destino</code>. */ public void resetDestino() { this.destino = null; } public void setDestino(java.lang.String destino) { this.destino = destino; } /** * */ public java.lang.String getDestino() { return this.destino; } /** * Converts the selected option index to the corresponding value as it was modeled. */ public java.lang.String getDestinoOptionValue(int optionIndex) { switch (optionIndex) { case 0: return "personales"; case 1: return "local"; default: throw new java.lang.ArrayIndexOutOfBoundsException( "Cannot access option " + optionIndex + ", please specify a value in the range [0-1]"); } } public java.lang.Object[] getDestinoBackingList() { java.lang.Object[] values = this.destinoValueList; java.lang.Object[] labels = this.destinoLabelList; if (values == null || values.length == 0) { return values; } if (labels == null || labels.length == 0) { labels = values; } final int length = java.lang.Math.min(labels.length, values.length); java.lang.Object[] backingList = new java.lang.Object[length]; for (int i = 0; i < length; i++) { backingList[i] = new LabelValue(labels[i], values[i]); } return backingList; } public java.lang.Object[] getDestinoValueList() { return this.destinoValueList; } public void setDestinoValueList(java.lang.Object[] destinoValueList) { this.destinoValueList = destinoValueList; } public java.lang.Object[] getDestinoLabelList() { return this.destinoLabelList; } public void setDestinoLabelList(java.lang.Object[] destinoLabelList) { this.destinoLabelList = destinoLabelList; } public void setDestinoBackingList(java.util.Collection items, java.lang.String valueProperty, java.lang.String labelProperty) { if (valueProperty == null || labelProperty == null) { throw new IllegalArgumentException( "DesagregarSubmanifiestoFormImpl.setDestinoBackingList requires non-null property arguments"); } this.destinoValueList = null; this.destinoLabelList = null; if (items != null) { this.destinoValueList = new java.lang.Object[items.size()]; this.destinoLabelList = new java.lang.Object[items.size()]; try { int i = 0; for (java.util.Iterator iterator = items.iterator(); iterator.hasNext(); i++) { final java.lang.Object item = iterator.next(); this.destinoValueList[i] = org.apache.commons.beanutils.PropertyUtils.getProperty(item, valueProperty); this.destinoLabelList[i] = org.apache.commons.beanutils.PropertyUtils.getProperty(item, labelProperty); } } catch (Exception ex) { throw new java.lang.RuntimeException( "DesagregarSubmanifiestoFormImpl.setDestinoBackingList encountered an exception", ex); } } } /** * Resets the given <code>identificadores</code>. */ public void resetIdentificadores() { this.identificadores = null; } public void setIdentificadores(java.util.List identificadores) { this.identificadores = identificadores; } /** * */ public java.util.List getIdentificadores() { return this.identificadores; } public void setIdentificadoresAsArray(Object[] identificadores) { this.identificadores = (identificadores == null) ? null : java.util.Arrays.asList(identificadores); } /** * Returns this collection as an array, if the collection itself would be <code>null</code> this method * will also return <code>null</code>. * * @see es.pode.empaquetador.presentacion.avanzado.submanifiestos.desagregar.DesagregarSubmanifiestoFormImpl#getIdentificadores */ public java.lang.Object[] getIdentificadoresAsArray() { return (identificadores == null) ? null : identificadores.toArray(); } public java.lang.Object[] getIdentificadoresBackingList() { java.lang.Object[] values = this.identificadoresValueList; java.lang.Object[] labels = this.identificadoresLabelList; if (values == null || values.length == 0) { return values; } if (labels == null || labels.length == 0) { labels = values; } final int length = java.lang.Math.min(labels.length, values.length); java.lang.Object[] backingList = new java.lang.Object[length]; for (int i = 0; i < length; i++) { backingList[i] = new LabelValue(labels[i], values[i]); } return backingList; } public java.lang.Object[] getIdentificadoresValueList() { return this.identificadoresValueList; } public void setIdentificadoresValueList(java.lang.Object[] identificadoresValueList) { this.identificadoresValueList = identificadoresValueList; } public java.lang.Object[] getIdentificadoresLabelList() { return this.identificadoresLabelList; } public void setIdentificadoresLabelList(java.lang.Object[] identificadoresLabelList) { this.identificadoresLabelList = identificadoresLabelList; } public void setIdentificadoresBackingList(java.util.Collection items, java.lang.String valueProperty, java.lang.String labelProperty) { if (valueProperty == null || labelProperty == null) { throw new IllegalArgumentException( "DesagregarSubmanifiestoFormImpl.setIdentificadoresBackingList requires non-null property arguments"); } this.identificadoresValueList = null; this.identificadoresLabelList = null; if (items != null) { this.identificadoresValueList = new java.lang.Object[items.size()]; this.identificadoresLabelList = new java.lang.Object[items.size()]; try { int i = 0; for (java.util.Iterator iterator = items.iterator(); iterator.hasNext(); i++) { final java.lang.Object item = iterator.next(); this.identificadoresValueList[i] = org.apache.commons.beanutils.PropertyUtils.getProperty(item, valueProperty); this.identificadoresLabelList[i] = org.apache.commons.beanutils.PropertyUtils.getProperty(item, labelProperty); } } catch (Exception ex) { throw new java.lang.RuntimeException( "DesagregarSubmanifiestoFormImpl.setIdentificadoresBackingList encountered an exception", ex); } } } /** * Resets the given <code>action</code>. */ public void resetAction() { this.action = null; } public void setAction(java.lang.String action) { this.action = action; } /** * */ public java.lang.String getAction() { return this.action; } public java.lang.Object[] getActionBackingList() { java.lang.Object[] values = this.actionValueList; java.lang.Object[] labels = this.actionLabelList; if (values == null || values.length == 0) { return values; } if (labels == null || labels.length == 0) { labels = values; } final int length = java.lang.Math.min(labels.length, values.length); java.lang.Object[] backingList = new java.lang.Object[length]; for (int i = 0; i < length; i++) { backingList[i] = new LabelValue(labels[i], values[i]); } return backingList; } public java.lang.Object[] getActionValueList() { return this.actionValueList; } public void setActionValueList(java.lang.Object[] actionValueList) { this.actionValueList = actionValueList; } public java.lang.Object[] getActionLabelList() { return this.actionLabelList; } public void setActionLabelList(java.lang.Object[] actionLabelList) { this.actionLabelList = actionLabelList; } public void setActionBackingList(java.util.Collection items, java.lang.String valueProperty, java.lang.String labelProperty) { if (valueProperty == null || labelProperty == null) { throw new IllegalArgumentException( "DesagregarSubmanifiestoFormImpl.setActionBackingList requires non-null property arguments"); } this.actionValueList = null; this.actionLabelList = null; if (items != null) { this.actionValueList = new java.lang.Object[items.size()]; this.actionLabelList = new java.lang.Object[items.size()]; try { int i = 0; for (java.util.Iterator iterator = items.iterator(); iterator.hasNext(); i++) { final java.lang.Object item = iterator.next(); this.actionValueList[i] = org.apache.commons.beanutils.PropertyUtils.getProperty(item, valueProperty); this.actionLabelList[i] = org.apache.commons.beanutils.PropertyUtils.getProperty(item, labelProperty); } } catch (Exception ex) { throw new java.lang.RuntimeException( "DesagregarSubmanifiestoFormImpl.setActionBackingList encountered an exception", ex); } } } /** * @see org.apache.struts.validator.ValidatorForm#reset(org.apache.struts.action.ActionMapping,javax.servlet.http.HttpServletRequest) */ public void reset(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { } public java.lang.String toString() { org.apache.commons.lang.builder.ToStringBuilder builder = new org.apache.commons.lang.builder.ToStringBuilder( this); builder.append("destino", this.destino); builder.append("identificadores", this.identificadores); builder.append("action", this.action); return builder.toString(); } /** * Allows you to clean all values from this form. Objects will be set to <code>null</code>, numeric values will be * set to zero and boolean values will be set to <code>false</code>. Backinglists for selectable fields will * also be set to <code>null</code>. */ public void clean() { this.destino = null; this.destinoValueList = null; this.destinoLabelList = null; this.identificadores = null; this.identificadoresValueList = null; this.identificadoresLabelList = null; this.action = null; this.actionValueList = null; this.actionLabelList = null; } /** * Override to provide population of current form with request parameters when validation fails. * * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest) */ public org.apache.struts.action.ActionErrors validate(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { final org.apache.struts.action.ActionErrors errors = super.validate(mapping, request); if (errors != null && !errors.isEmpty()) { // we populate the current form with only the request parameters Object currentForm = request.getSession().getAttribute("form"); // if we can't get the 'form' from the session, try from the request if (currentForm == null) { currentForm = request.getAttribute("form"); } if (currentForm != null) { final java.util.Map parameters = new java.util.HashMap(); for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) { final String name = String.valueOf(names.nextElement()); parameters.put(name, request.getParameter(name)); } try { org.apache.commons.beanutils.BeanUtils.populate(currentForm, parameters); } catch (java.lang.Exception populateException) { // ignore if we have an exception here (we just don't populate). } } } return errors; } public final static class LabelValue { private java.lang.Object label = null; private java.lang.Object value = null; public LabelValue(Object label, java.lang.Object value) { this.label = label; this.value = value; } public java.lang.Object getLabel() { return this.label; } public java.lang.Object getValue() { return this.value; } public java.lang.String toString() { return label + "=" + value; } } }