2006/unicorn/src/org/w3c/unicorn/tasklist/parameters ParameterType.java,NONE,1.1.2.1 Parameter.java,NONE,1.1.2.1 TextAreaParameter.java,NONE,1.1.2.1 Value.java,NONE,1.1.2.1 TextFieldParameter.java,NONE,1.1.2.1 ParameterFactory.java,NONE,1.1.2.1 CheckboxParameter.java,NONE,1.1.2.1 CheckboxListParameter.java,NONE,1.1.2.1 Mapping.java,NONE,1.1.2.1 DropDownParameter.java,NONE,1.1.2.1 RadioParameter.java,NONE,1.1.2.1

Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/tasklist/parameters
In directory hutz:/tmp/cvs-serv2609/src/org/w3c/unicorn/tasklist/parameters

Added Files:
      Tag: dev2
	ParameterType.java Parameter.java TextAreaParameter.java 
	Value.java TextFieldParameter.java ParameterFactory.java 
	CheckboxParameter.java CheckboxListParameter.java Mapping.java 
	DropDownParameter.java RadioParameter.java 
Log Message:
all initialization actions in Init.java
+ compatibility windows/linux

--- NEW FILE: ParameterFactory.java ---
// $Id: ParameterFactory.java,v 1.1.2.1 2009/08/11 16:05:34 tgambet Exp $
// Author: Damien LEROY.
// (c) COPYRIGHT MIT, ERCIM ant Keio, 2006.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.tasklist.parameters;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3.unicorn.tasklist.TParamType;

/**
 * Factory to create any type of parameter.
 * 
 * @author Damien LEROY
 */
public class ParameterFactory {

	private static final Log logger = LogFactory
			.getLog("org.w3c.unicorn.tasklist");

	public static Parameter getParameter(final TParamType.Enum aTParamType) {
		switch (aTParamType.intValue()) {
		case TParamType.INT_CHECKBOX:
			return new CheckboxParameter();
		case TParamType.INT_CHECKBOXLIST:
			return new CheckboxListParameter();
		case TParamType.INT_DROPDOWN:
			return new DropDownParameter();
		case TParamType.INT_RADIO:
			return new RadioParameter();
		case TParamType.INT_TEXTAREA:
			return new TextAreaParameter();
		case TParamType.INT_TEXTFIELD:
			return new TextFieldParameter();
		default:
			ParameterFactory.logger.error("Unknown parameter type.");
			return null;
		}
	}

}

--- NEW FILE: DropDownParameter.java ---
// $Id: DropDownParameter.java,v 1.1.2.1 2009/08/11 16:05:34 tgambet Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2006.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.tasklist.parameters;

import java.util.LinkedHashMap;
import java.util.Map;

import org.w3c.unicorn.exceptions.ParameterException;

/**
 * DropDownParameter<br />
 * Created: Jun 8, 2006 1:48:31 PM<br />
 * 
 * @author Jean-Guilhem ROUEL
 */
public class DropDownParameter extends Parameter {

	private Map<String, Value> mapOfValue;

	private Value aValueDefault;

	/**
	 * Default constructor for a DropDownParameter (see the Parameter default
	 * constructor).
	 */
	protected DropDownParameter() {
		super();
		Parameter.logger.trace("Constructor()");
	}

	/**
	 * Adds a Value object to the mapOfValue.
	 * 
	 * @param aValue
	 *            The value to add.
	 */
	@Override
	public void addValue(final Value aValue) {
		this.mapOfValue.put(aValue.getName(), aValue);
	}

	/**
	 * Finds a Value object in the map given its name.
	 * 
	 * @param sName
	 *            The name of the Value.
	 * @return The Value object if the String corresponds to a key.
	 */
	@Override
	public Value getValue(final String sName) {
		return this.mapOfValue.get(sName);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.unicorn.tasklist.parameters.Parameter#getDefault()
	 */
	@Override
	public Map<String, Value> getMapOfDefaultValue() {
		final Map<String, Value> mapOfValue = new LinkedHashMap<String, Value>();
		mapOfValue.put(this.aValueDefault.getName(), this.aValueDefault);
		return mapOfValue;
	}

	/**
	 * Sets the default Value in the mapOfDefaultValue.
	 * 
	 * @param sDefaultValues
	 *            The new default value.
	 */
	@Override
	public void setDefaultValues(final String sDefaultValues) {
		this.aValueDefault = this.mapOfValue.get(sDefaultValues);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.unicorn.tasklist.parameters.Parameter#getValues()
	 */
	@Override
	public Map<String, Value> getMapOfValue() {
		return this.mapOfValue;
	}

	/**
	 * Defines or replaces the mapOfValue.
	 * 
	 * @param mapOfValue
	 *            The new map of values.
	 */
	@Override
	public void setMapOfValue(final Map<String, Value> mapOfValue)
			throws ParameterException {
		if (mapOfValue.size() < 1) {
			Parameter.logger
					.error("Dropdown parameter must have at least one value.");
			throw new ParameterException(
					"Dropdown parameter must have at least one value.");
		}
		this.mapOfValue = mapOfValue;
	}

	/**
	 * Returns the type of the parameter.
	 * 
	 * @return The type DROPDOWN.
	 */
	@Override
	public ParameterType getType() {
		return ParameterType.DROPDOWN;
	}

	/**
	 * Merges a Parameter with this one if the type complies.
	 * 
	 * @param aParameter
	 *            The parameter to merge with the current one.
	 * @return True if they merged correctly, else false.
	 */
	@Override
	public boolean merge(final Parameter aParameter) {
		Parameter.logger.trace("merge");
		// Types must match
		if (!(aParameter instanceof DropDownParameter)) {
			Parameter.logger.warn("Type of parameter " + this.getName()
					+ " and " + aParameter.getName() + " not matching.");
			return false;
		}
		if (!super.merge(aParameter)) {
			return false;
		}
		final DropDownParameter aDropDownParameter = (DropDownParameter) aParameter;
		for (final Value aValue : aDropDownParameter.getMapOfValue().values()) {
			final Value aLocalValue = this.getValue(aValue.getName());
			if (null == aLocalValue) {
				this.addValue(aValue);
				continue;
			}
			for (final String sLocale : aValue.getLongName().getSetOfLocale()) {
				if (!aLocalValue.hasLongName(sLocale)) {
					aLocalValue.addLongName(sLocale, aValue
							.getLongName(sLocale));
					continue;
				}
			}
			for (final String sValue : aValue.getMapOfMapping().keySet()) {
				if (!aLocalValue.hasMapping(sValue)) {
					aLocalValue.addListOfMapping(sValue, aValue
							.getListOfMapping(sValue));
				}
			}
		}
		return true;
	}

}

--- NEW FILE: CheckboxListParameter.java ---
// $Id: CheckboxListParameter.java,v 1.1.2.1 2009/08/11 16:05:34 tgambet Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2006.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.tasklist.parameters;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * CheckboxListParameter<br />
 * Created: Jun 8, 2006 4:13:46 PM<br />
 * 
 * @author Jean-Guilhem ROUEL
 */
public class CheckboxListParameter extends Parameter {

	private Map<String, Value> mapOfValue;

	private Map<String, Value> mapOfDefaultValue;

	/**
	 * Default constructor for a CheckboxListParameter (see Parameter default
	 * constructor).
	 */
	protected CheckboxListParameter() {
		super();
		Parameter.logger.trace("Constructor()");
	}

	/**
	 * Adds a Value object to the mapOfValue.
	 * 
	 * @param aValue
	 *            The value to add.
	 */
	@Override
	public void addValue(final Value aValue) {
		this.mapOfValue.put(aValue.getName(), aValue);
	}

	/**
	 * Finds a Value object in the map given its name.
	 * 
	 * @param sName
	 *            The name of the Value.
	 * @return The Value object if the String corresponds to a key.
	 */
	@Override
	public Value getValue(final String sName) {
		return this.mapOfValue.get(sName);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.unicorn.tasklist.parameters.Parameter#getDefault()
	 */
	@Override
	public Map<String, Value> getMapOfDefaultValue() {
		return this.mapOfDefaultValue;
	}

	/**
	 * Sets the default Value in the mapOfDefaultValue.
	 * 
	 * @param sDefaultValues
	 *            The new default value.
	 */
	@Override
	public void setDefaultValues(final String sDefaultValues) {
		this.mapOfDefaultValue = new LinkedHashMap<String, Value>();
		for (String sDefault : sDefaultValues.split(",")) {
			sDefault = sDefault.trim();
			final Value aValue = this.mapOfValue.get(sDefault);
			if (aValue != null) {
				this.mapOfDefaultValue.put(sDefault, aValue);
			} else {
				Parameter.logger.error("The default value " + sDefault
						+ " is not a valid value.");
			}
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.unicorn.tasklist.parameters.Parameter#getValues()
	 */
	@Override
	public Map<String, Value> getMapOfValue() {
		return this.mapOfValue;
	}

	/**
	 * Defines or replaces the mapOfValue.
	 * 
	 * @param mapOfValue
	 *            The new map of values.
	 */
	@Override
	public void setMapOfValue(final Map<String, Value> mapOfValue) {
		this.mapOfValue = mapOfValue;
	}

	/**
	 * Returns the type of the parameter.
	 * 
	 * @return The type CHECKBOXLIST.
	 */
	@Override
	public ParameterType getType() {
		return ParameterType.CHECKBOXLIST;
	}

	/**
	 * Merges a Parameter with this one if the type complies.
	 * 
	 * @param aParameter
	 *            The parameter to merge with the current one.
	 * @return True if they merged correctly, else false.
	 */
	@Override
	public boolean merge(final Parameter aParameter) {
		Parameter.logger.trace("merge");
		// Types must match
		if (!(aParameter instanceof CheckboxListParameter)) {
			Parameter.logger.warn("Type of parameter " + this.getName()
					+ " and " + aParameter.getName() + " not matching.");
			return false;
		}
		if (!super.merge(aParameter)) {
			return false;
		}
		final CheckboxListParameter aCheckboxListParameter = (CheckboxListParameter) aParameter;
		for (final Value aValue : aCheckboxListParameter.getMapOfValue()
				.values()) {
			final Value aLocalValue = this.getValue(aValue.getName());
			if (null == aLocalValue) {
				this.addValue(aValue);
				continue;
			}
			for (final String sLocale : aValue.getLongName().getSetOfLocale()) {
				if (!aLocalValue.hasLongName(sLocale)) {
					aLocalValue.addLongName(sLocale, aValue
							.getLongName(sLocale));
					continue;
				}
			}
			for (final String sValue : aValue.getMapOfMapping().keySet()) {
				if (!aLocalValue.hasMapping(sValue)) {
					aLocalValue.addListOfMapping(sValue, aValue
							.getListOfMapping(sValue));
				}
			}
		}
		return true;
	}

}

--- NEW FILE: TextFieldParameter.java ---
// $Id: TextFieldParameter.java,v 1.1.2.1 2009/08/11 16:05:34 tgambet Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2006.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.tasklist.parameters;

import java.util.LinkedHashMap;
import java.util.Map;

import org.w3c.unicorn.exceptions.ParameterException;

/**
 * TextFieldParameter<br />
 * Created: Jun 8, 2006 4:30:49 PM<br />
 * 
 * @author Jean-Guilhem ROUEL
 */
public class TextFieldParameter extends Parameter {

	private Value aValueDefault;

	/**
	 * Default constructor for a TextFieldParameter (see the Parameter default
	 * constructor).
	 */
	protected TextFieldParameter() {
		super();
		Parameter.logger.trace("Constructor()");
	}

	/**
	 * Adds a Value object to the mapOfValue.
	 * 
	 * @param aValue
	 *            The value to add.
	 */
	@Override
	public void addValue(final Value aValue) {
		this.aValueDefault = aValue;
	}

	/**
	 * Finds a Value object in the map given its name.
	 * 
	 * @param sName
	 *            The name of the Value.
	 * @return The Value object if the String corresponds to a key.
	 */
	@Override
	public Value getValue(final String sName) {
		if (this.aValueDefault.getName().equals(sName)) {
			return this.aValueDefault;
		}
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.unicorn.tasklist.parameters.Parameter#getDefault()
	 */
	@Override
	public Map<String, Value> getMapOfDefaultValue() {
		final Map<String, Value> mapOfValue = new LinkedHashMap<String, Value>();
		mapOfValue.put(this.aValueDefault.getName(), this.aValueDefault);
		return mapOfValue;
	}

	/**
	 * Sets the default Value in the mapOfDefaultValue.
	 * 
	 * @param sDefaultValues
	 *            The new default value.
	 */
	@Override
	public void setDefaultValues(final String sDefaultValues) {
		this.aValueDefault.setName(sDefaultValues);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.unicorn.tasklist.parameters.Parameter#getValues()
	 */
	@Override
	public Map<String, Value> getMapOfValue() {
		// no value because we allow any text
		return null;
	}

	/**
	 * Defines or replaces the mapOfValue.
	 * 
	 * @param mapOfValue
	 *            The new map of values.
	 */
	@Override
	public void setMapOfValue(final Map<String, Value> mapOfValue)
			throws ParameterException {
		if (mapOfValue.size() != 1) {
			Parameter.logger
					.error("TextField parameter should have exactly one value.");
			throw new ParameterException(
					"TextField parameter should have exactly one value.");
		}
		this.aValueDefault = mapOfValue.values().iterator().next();
	}

	/**
	 * Returns the type of the parameter.
	 * 
	 * @return The type TEXTFIELD.
	 */
	@Override
	public ParameterType getType() {
		return ParameterType.TEXTFIELD;
	}

	/**
	 * Merges a Parameter with this one if the type complies.
	 * 
	 * @param aParameter
	 *            The parameter to merge with the current one.
	 * @return True if they merged correctly, else false.
	 */
	@Override
	public boolean merge(final Parameter aParameter) {
		Parameter.logger.trace("merge");
		// Types must match
		if (!(aParameter instanceof TextFieldParameter)) {
			Parameter.logger.warn("Type of parameter " + this.getName()
					+ " and " + aParameter.getName() + " not matching.");
			return false;
		}
		if (!super.merge(aParameter)) {
			return false;
		}
		final TextFieldParameter aTextFieldParameter = (TextFieldParameter) aParameter;
		this.aValueDefault = aTextFieldParameter.aValueDefault;
		return true;
	}

}

--- NEW FILE: RadioParameter.java ---
// $Id: RadioParameter.java,v 1.1.2.1 2009/08/11 16:05:34 tgambet Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2006.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.tasklist.parameters;

import java.util.LinkedHashMap;
import java.util.Map;

import org.w3c.unicorn.exceptions.ParameterException;

/**
 * RadioParameter<br />
 * Created: Jun 8, 2006 5:36:52 PM<br />
 */
public class RadioParameter extends Parameter {

	private Map<String, Value> mapOfValue;

	private Value aValueDefault;

	/**
	 * Default constructor for a RadioParameter (see the Parameter default
	 * constructor).
	 */
	protected RadioParameter() {
		super();
		Parameter.logger.trace("Constructor()");
	}

	/**
	 * Adds a Value object to the mapOfValue.
	 * 
	 * @param aValue
	 *            The value to add.
	 */
	@Override
	public void addValue(final Value aValue) {
		this.mapOfValue.put(aValue.getName(), aValue);
	}

	/**
	 * Finds a Value object in the map given its name.
	 * 
	 * @param sName
	 *            The name of the Value.
	 * @return The Value object if the String corresponds to a key.
	 */
	@Override
	public Value getValue(final String sName) {
		return this.mapOfValue.get(sName);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.unicorn.tasklist.parameters.Parameter#getDefault()
	 */
	@Override
	public Map<String, Value> getMapOfDefaultValue() {
		final Map<String, Value> mapOfValue = new LinkedHashMap<String, Value>();
		mapOfValue.put(this.aValueDefault.getName(), this.aValueDefault);
		return mapOfValue;
	}

	/**
	 * Sets the default Value in the mapOfDefaultValue.
	 * 
	 * @param sDefaultValues
	 *            The new default value.
	 */
	@Override
	public void setDefaultValues(final String sDefaultValues) {
		this.aValueDefault = this.mapOfValue.get(sDefaultValues);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.unicorn.tasklist.parameters.Parameter#getValues()
	 */
	@Override
	public Map<String, Value> getMapOfValue() {
		return this.mapOfValue;
	}

	/**
	 * Defines or replaces the mapOfValue.
	 * 
	 * @param mapOfValue
	 *            The new map of values.
	 */
	@Override
	public void setMapOfValue(final Map<String, Value> mapOfValue)
			throws ParameterException {
		if (mapOfValue.size() == 0) {
			throw new ParameterException(
					"Radio parameter must have at least one value.");
		}
		this.mapOfValue = mapOfValue;
	}

	/**
	 * Returns the type of the parameter.
	 * 
	 * @return The type RADIO.
	 */
	@Override
	public ParameterType getType() {
		return ParameterType.RADIO;
	}

	/**
	 * Merges a Parameter with this one if the type complies.
	 * 
	 * @param aParameter
	 *            The parameter to merge with the current one.
	 * @return True if they merged correctly, else false.
	 */
	@Override
	public boolean merge(final Parameter aParameter) {
		Parameter.logger.trace("merge");
		// Types must match
		if (!(aParameter instanceof RadioParameter)) {
			Parameter.logger.warn("Type of parameter " + this.getName()
					+ " and " + aParameter.getName() + " not matching.");
			return false;
		}
		if (!super.merge(aParameter)) {
			return false;
		}
		final RadioParameter aRadioParameter = (RadioParameter) aParameter;
		for (final Value aValue : aRadioParameter.getMapOfValue().values()) {
			final Value aLocalValue = this.getValue(aValue.getName());
			if (null == aLocalValue) {
				this.addValue(aValue);
				continue;
			}
			for (final String sLocale : aValue.getLongName().getSetOfLocale()) {
				if (!aLocalValue.hasLongName(sLocale)) {
					aLocalValue.addLongName(sLocale, aValue
							.getLongName(sLocale));
					continue;
				}
			}
			for (final String sValue : aValue.getMapOfMapping().keySet()) {
				if (!aLocalValue.hasMapping(sValue)) {
					aLocalValue.addListOfMapping(sValue, aValue
							.getListOfMapping(sValue));
				}
			}
		}
		return true;
	}

}

--- NEW FILE: ParameterType.java ---
// $Id: ParameterType.java,v 1.1.2.1 2009/08/11 16:05:33 tgambet Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2006.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.tasklist.parameters;

/**
 * ParameterType<br />
 * Created: Jun 22, 2006 10:39:41 AM<br />
 * 
 * @author Jean-Guilhem Rouel
 */
public enum ParameterType {

	CHECKBOX("checkbox"), CHECKBOXLIST("checkboxlist"), DROPDOWN("dropdownlist"), RADIO(
			"radio"), TEXTAREA("textarea"), TEXTFIELD("textfield"), UNKNOWN(
			"unknown");

	private final String sValue;

	private ParameterType(final String sValue) {
		this.sValue = sValue;
	}

	public final String value() {
		return this.sValue;
	}

	public static ParameterType fromValue(final String sValue) {
		for (final ParameterType aParameterType : ParameterType.values()) {
			if (aParameterType.sValue.equals(sValue)) {
				return aParameterType;
			}
		}
		throw new IllegalArgumentException("Parameter type "
				+ sValue.toString() + " unknow.");
	}

}

--- NEW FILE: CheckboxParameter.java ---
// $Id: CheckboxParameter.java,v 1.1.2.1 2009/08/11 16:05:34 tgambet Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2006.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.tasklist.parameters;

import java.util.LinkedHashMap;
import java.util.Map;

import org.w3c.unicorn.exceptions.ParameterException;

/**
 * CheckboxParameter<br />
 * Created: May 30, 2006 11:23:34 AM<br />
 */
public class CheckboxParameter extends Parameter {

	private boolean bCheckedByDefault;

	private Map<String, Value> mapOfValue = null;

	/**
	 * Default constructor for a CheckboxParameter (see the Parameter default
	 * constructor).
	 */
	protected CheckboxParameter() {
		super();
		Parameter.logger.trace("Constructor()");
	}

	/**
	 * Adds a Value object to the mapOfValue.
	 * 
	 * @param aValue
	 *            The value to add.
	 */
	@Override
	public void addValue(final Value aValue) {
		this.mapOfValue.put(aValue.getName(), aValue);
	}

	/**
	 * Finds a Value object in the map given its name.
	 * 
	 * @param sName
	 *            The name of the Value.
	 * @return The Value object if the String corresponds to a key.
	 */
	@Override
	public Value getValue(final String sName) {
		return this.mapOfValue.get(sName);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.unicorn.tasklist.parameters.Parameter#getDefault()
	 */
	@Override
	public Map<String, Value> getMapOfDefaultValue() {
		final Map<String, Value> mapOfValue = new LinkedHashMap<String, Value>();
		mapOfValue.put((this.bCheckedByDefault) ? "checked" : "unchecked",
				(this.bCheckedByDefault) ? this.mapOfValue.get("checked")
						: this.mapOfValue.get("unchecked"));
		return mapOfValue;
	}

	/**
	 * Sets the default Value in the mapOfDefaultValue.
	 * 
	 * @param sDefaultValues
	 *            The new default value.
	 */
	@Override
	public void setDefaultValues(final String sDefaultValues) {
		this.bCheckedByDefault = (sDefaultValues != null && "checked"
				.equals(sDefaultValues));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.unicorn.tasklist.parameters.Parameter#getValues()
	 */
	@Override
	public Map<String, Value> getMapOfValue() {
		return this.mapOfValue;
	}

	/**
	 * Defines or replaces the mapOfValue.
	 * 
	 * @param mapOfValue
	 *            The new map of values.
	 */
	@Override
	public void setMapOfValue(final Map<String, Value> mapOfValue)
			throws ParameterException {
		if (mapOfValue.size() > 2 || mapOfValue.size() < 1) {
			Parameter.logger.error("Checkbox parameter " + this.getName()
					+ "must have only one or two values.");
			throw new ParameterException("Checkbox parameter " + this.getName()
					+ "must have only one or two values.");
		}
		this.mapOfValue = mapOfValue;
	}

	/**
	 * Gets the checked Value in the mapOfValue.
	 * 
	 * @return Returns the checked Value.
	 */
	public Value getChecked() {
		return this.mapOfValue.get("checked");
	}

	/**
	 * Sets the given Value to "checked" or adds it with this key.
	 * 
	 * @param aValueChecked
	 *            The Value to set as checked.
	 */
	public void setChecked(final Value aValueChecked) {
		this.mapOfValue.put("checked", aValueChecked);
	}

	/**
	 * Gets the unchecked Value in the mapOfValue.
	 * 
	 * @return Returns the unchecked.
	 */
	public Value getUnchecked() {
		return this.mapOfValue.get("unchecked");
	}

	/**
	 * Sets the given Value to "unchecked" or adds it with this key.
	 * 
	 * @param aValueUnchecked
	 *            The Value to set as unchecked.
	 */
	public void setUnchecked(final Value aValueUnchecked) {
		this.mapOfValue.put("unchecked", aValueUnchecked);
	}

	/**
	 * Returns the type of the parameter.
	 * 
	 * @return The type CHECKBOX.
	 */
	@Override
	public ParameterType getType() {
		return ParameterType.CHECKBOX;
	}

	/**
	 * Merges a Parameter with this one if the type complies.
	 * 
	 * @param aParameter
	 *            The parameter to merge with the current one.
	 * @return True if they merged correctly, else false.
	 */
	@Override
	public boolean merge(final Parameter aParameter) {
		Parameter.logger.trace("merge");
		// Types must match
		if (!(aParameter instanceof CheckboxParameter)) {
			Parameter.logger.warn("Type of parameter " + this.getName()
					+ " and " + aParameter.getName() + " not matching.");
			return false;
		}
		if (!super.merge(aParameter)) {
			return false;
		}
		final CheckboxParameter aCheckboxParameter = (CheckboxParameter) aParameter;
		for (final Value aValue : aCheckboxParameter.getMapOfValue().values()) {
			final Value aLocalValue = this.getValue(aValue.getName());
			if (null == aLocalValue) {
				this.addValue(aValue);
				continue;
			}
			for (final String sLocale : aValue.getLongName().getSetOfLocale()) {
				if (!aLocalValue.hasLongName(sLocale)) {
					aLocalValue.addLongName(sLocale, aValue
							.getLongName(sLocale));
					continue;
				}
			}
			for (final String sValue : aValue.getMapOfMapping().keySet()) {
				if (!aLocalValue.hasMapping(sValue)) {
					aLocalValue.addListOfMapping(sValue, aValue
							.getListOfMapping(sValue));
				}
			}
		}
		return true;
	}

}

--- NEW FILE: Value.java ---
// $Id: Value.java,v 1.1.2.1 2009/08/11 16:05:34 tgambet Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2006.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.tasklist.parameters;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.w3c.unicorn.util.LocalizedString;

/**
 * Value<br />
 * Created: May 30, 2006 11:34:57 AM<br />
 * A value, as seen in the tasklist: a name and a list of mappings.
 * 
 * @author Jean-Guilhem ROUEL
 */
public class Value {

	/**
	 * Name of the value
	 */
	private String sName;

	/**
	 * Internationalized long name of the task
	 */
	private LocalizedString longNames;

	/**
	 * List of mappings for this value
	 */
	private Map<String, List<Mapping>> mapOfListOfMapping;

	/**
	 * Creates a new Value.
	 */
	public Value() {
		this.sName = "";
		this.longNames = new LocalizedString();
		this.mapOfListOfMapping = new LinkedHashMap<String, List<Mapping>>();
	}

	/**
	 * Creates a new Value.
	 * 
	 * @param mapOfListOfMapping
	 *            List of mappings.
	 * @param sName
	 *            Name of this value.
	 */
	public Value(final Map<String, List<Mapping>> mapOfListOfMapping,
			final String sName) {
		this.longNames = new LocalizedString();
		this.mapOfListOfMapping = mapOfListOfMapping;
		this.sName = sName;
	}

	/**
	 * Creates a new Value.
	 * 
	 * @param longname
	 *            internationalized long name of this value
	 * @param mapOfListOfMapping
	 *            list of mappings
	 * @param sName
	 *            name of this value
	 */
	public Value(final LocalizedString aInternationalizedMessageLongName,
			final Map<String, List<Mapping>> mapOfListOfMapping,
			final String sName) {
		super();
		this.longNames = aInternationalizedMessageLongName;
		this.mapOfListOfMapping = mapOfListOfMapping;
		this.sName = sName;
	}

	public boolean hasLongName(final String sLocale) {
		return this.longNames.hasLocale(sLocale);
	}

	/**
	 * Returns the internationalized long name of this value
	 * 
	 * @return Returns the longname.
	 */
	public LocalizedString getLongName() {
		return this.longNames;
	}

	/**
	 * Sets the internationalized long name of this value
	 * 
	 * @param longname
	 *            The longname to set.
	 */
	public void setLongName(final LocalizedString longNames) {
		this.longNames = longNames;
	}

	/**
	 * Adds a list of mapping to the mapOfListOfMapping.
	 * 
	 * @param sKey
	 *            The key for the list.
	 * @param listOfMapping
	 *            The list to add.
	 */
	public void addListOfMapping(final String sKey,
			final List<Mapping> listOfMapping) {
		this.mapOfListOfMapping.put(sKey, listOfMapping);
	}

	/**
	 * Checks if the given mapping exists.
	 * 
	 * @param sMapping
	 * @return True if the map contains sMapping, else false.
	 */
	public boolean hasMapping(final String sMapping) {
		return null != this.mapOfListOfMapping.get(sMapping);
	}

	/**
	 * Finds a list of mapping given its name.
	 * 
	 * @param sName
	 *            The name of the mapping.
	 * @return The list of mapping if the name matches an entry.
	 */
	public List<Mapping> getListOfMapping(final String sName) {
		return this.mapOfListOfMapping.get(sName);
	}

	/**
	 * Returns all the mappings for this value
	 * 
	 * @return Returns the mappings.
	 */
	public Map<String, List<Mapping>> getMapOfMapping() {
		return this.mapOfListOfMapping;
	}

	/**
	 * Sets the mappings for this value
	 * 
	 * @param mappings
	 *            The mappings to set.
	 */
	public void setMapOfMapping(final Map<String, List<Mapping>> mappings) {
		this.mapOfListOfMapping = mappings;
	}

	/**
	 * Sets the name of this value
	 * 
	 * @param sName
	 *            The name to set.
	 */
	public void setName(final String sName) {
		this.sName = sName;
	}

	/**
	 * Gets the name of this value
	 * 
	 * @return the name of this value
	 */
	public String getName() {
		return this.sName;
	}

	/**
	 * Returns a localized long name of this value
	 * 
	 * @param sLang
	 *            the locale
	 * @return the localized long name
	 */
	public String getLongName(final String sLang) {
		final String sName = this.longNames.getLocalization(sLang);
		if (sName != null) {
			return sName;
		}
		return this.sName;
	}

	/**
	 * Adds a localized long name to this value
	 * 
	 * @param sLang
	 *            the locale
	 * @param sLongName
	 *            the localized name
	 */
	public void addLongName(final String sLang, final String sLongName) {
		this.longNames.addLocalization(sLang, sLongName);
	}

	/**
	 * Adds or merges a mapping to this value, depending on the existence of a
	 * similar mapping.
	 * 
	 * @param m
	 *            the mapping to add or merge
	 */
	/*
	 * public void addMapping (Mapping m) { boolean done = false; for (Mapping
	 * mapping : this.mappings.get(m.getObserver().getDescription().getId())) { //
	 * A mapping with these observer, param and value already exists // We only
	 * need to add the input method
	 * if(mapping.getObserver().getDescription().getId().equals(
	 * m.getObserver().getDescription().getId()) &&
	 * mapping.getParam().equals(m.getParam()) &&
	 * mapping.getValue().equals(m.getValue())) {
	 * 
	 * List<EnumInputMethod> inputMethods = mapping.getInputMethodsList(); for
	 * (EnumInputMethod im : m.getInputMethodsList()) {
	 * if(inputMethods.contains(im)) { System.err.println("The value " + name + "
	 * already" + " contains this mapping"); } else {
	 * mapping.addInputMethod(im); } } // ok, the mapping has been merged done =
	 * true; } } // no similar mapping exists, so we simply add it if(!done) {
	 * mappings.add(m); } }
	 */

	@Override
	public String toString() {
		final int iStringBufferSize = 1000;
		final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize);

		aStringBuffer.append(this.sName);
		aStringBuffer.append("=>");
		aStringBuffer.append(this.mapOfListOfMapping);

		return aStringBuffer.toString();
	}

}

--- NEW FILE: Parameter.java ---
// $Id: Parameter.java,v 1.1.2.1 2009/08/11 16:05:33 tgambet Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2006.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.tasklist.parameters;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3.unicorn.tasklist.TUi;
import org.w3c.unicorn.exceptions.ParameterException;
import org.w3c.unicorn.util.LocalizedString;

/**
 * Parameter<br />
 * Created: May 29, 2006 5:57:26 PM<br />
 * This class represents a parameter used in the tasklist
 * 
 * @author Jean-Guilhem ROUEL
 */
public abstract class Parameter {

	protected static final Log logger = LogFactory
			.getLog("org.w3c.unicorn.tasklist");

	/**
	 * Name of the parameter
	 */
	private String sName;

	/**
	 * Long name of the parameter
	 */
	private LocalizedString longnames;

	/**
	 * Level of the interface in which the parameter appears
	 */
	private TUi.Enum aTUiLevel;

	/**
	 * Returns the default values of this parameter.
	 * 
	 * @return The default values of this parameter.
	 */
	public abstract Map<String, Value> getMapOfDefaultValue();

	/**
	 * Returns the possible values of this parameter.
	 * 
	 * @return The possible values of this parameter.
	 */
	public abstract Map<String, Value> getMapOfValue();

	/**
	 * Creates a new Parameter.
	 */
	public Parameter() {
		this("", new LocalizedString(), TUi.ADVANCED);
	}

	/**
	 * Creates a new Parameter.
	 * 
	 * @param aLocalizedString
	 * @param sName
	 * @param aTUi
	 */
	public Parameter(final String sName,
			final LocalizedString aLocalizedString, final TUi.Enum aTUi) {
		super();
		this.longnames = aLocalizedString;
		this.sName = sName;
		this.aTUiLevel = aTUi;
	}

	/**
	 * Sets the name of this parameter
	 * 
	 * @param sName
	 *            The name to set.
	 */
	public void setName(final String sName) {
		this.sName = sName;
	}

	/**
	 * Returns the name of this parameter
	 * 
	 * @return the name of this parameter
	 */
	public String getName() {
		return this.sName;
	}

	/**
	 * Returns the internationalized long name of this parameter
	 * 
	 * @return Returns the longname.
	 */
	public LocalizedString getLongNames() {
		return this.longnames;
	}

	/**
	 * Sets the internationalized long name of this parameter
	 * 
	 * @param longname
	 *            The longname to set.
	 */
	public void setLongNames(final LocalizedString aLocalizedString) {
		this.longnames = aLocalizedString;
	}

	/**
	 * Returns a localized long name of this parameter
	 * 
	 * @param sLocale
	 *            locale of the long name
	 * @return the localized long name
	 */
	public String getLongName(final String sLocale) {
		return this.longnames.getLocalization(sLocale);
	}

	/**
	 * Adds a localization to this parameter's long name
	 * 
	 * @param sLocale
	 *            locale of the long name
	 * @param sLongName
	 *            the localized long name
	 */
	public void addLongName(final String sLocale, final String sLongName) {
		this.longnames.addLocalization(sLocale, sLongName);
	}

	/**
	 * Returns the interface level
	 * 
	 * @return Returns the uiLevel.
	 */
	public TUi.Enum getUiLevel() {
		return this.aTUiLevel;
	}

	/**
	 * Sets the interface level
	 * 
	 * @param aTUiLevel
	 *            The uiLevel to set.
	 */
	public void setUiLevel(final TUi.Enum aTUiLevel) {
		this.aTUiLevel = aTUiLevel;
	}

	public abstract void addValue(final Value aValue);

	public abstract ParameterType getType();

	public abstract Value getValue(final String sName);

	public abstract void setDefaultValues(final String sDefaultValues);

	public abstract void setMapOfValue(final Map<String, Value> mapOfValue)
			throws ParameterException;

	/**
	 * Merges two parameters.
	 * 
	 * @param aParameter
	 *            TODO End coding this function. TODO Check this function.
	 */
	public boolean merge(final Parameter aParameter) {
		Parameter.logger.trace("merge");
		// UI must match
		if (!this.getUiLevel().equals(aParameter.getUiLevel())) {
			Parameter.logger.warn("UI of parameter " + this.sName + " and "
					+ aParameter.sName + " not matching.");
			return false;
		}
		// merge long name
		for (final String sLocale : aParameter.getLongNames().getSetOfLocale()) {
			if (this.getLongNames().hasLocale(sLocale)) {
				this.addLongName(sLocale, aParameter.getLongName(sLocale));
			}
		}
		return true;
	}

	@Override
	public String toString() {
		final int iStringBufferSize = 1000;
		final String sVariableSeparator = " ";
		final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize);

		aStringBuffer.append("name:").append(sName);
		aStringBuffer.append(sVariableSeparator);
		aStringBuffer.append("ui:").append(aTUiLevel);
		aStringBuffer.append(sVariableSeparator);
		aStringBuffer.append("default:[").append(this.getMapOfDefaultValue())
				.append("]");
		aStringBuffer.append(sVariableSeparator);
		aStringBuffer.append("values:").append(getMapOfValue());

		return aStringBuffer.toString();
	}

}

--- NEW FILE: Mapping.java ---
// $Id: Mapping.java,v 1.1.2.1 2009/08/11 16:05:34 tgambet Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2006.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.tasklist.parameters;

import org.w3c.unicorn.contract.Observer;

/**
 * Mapping<br />
 * Created: May 30, 2006 12:25:00 PM<br />
 * This class represents a mapping between a value of parameter in a task and a
 * value of a parameter in an observer.
 * 
 * @author Jean-Guilhem ROUEL
 */
public class Mapping {

	/**
	 * Mapped observer
	 */
	private Observer aObserver;

	/**
	 * Mapped parameter
	 */
	private String sParam;

	/**
	 * Mapped value
	 */
	private String sValue;

	/**
	 * List of mapped input methods
	 */
	// private List<EnumInputMethod> listOfEnumInputMethod;
	public Mapping() {
	}

	/**
	 * Creates a new Mapping.
	 * 
	 * @param aObserver
	 * @param sParam
	 * @param sValue
	 */
	public Mapping(final Observer aObserver, final String sParam,
			final String sValue/*
								 * , final List<EnumInputMethod>
								 * listOfEnumInputMethod
								 */) {
		super();

		this.aObserver = aObserver;
		this.sParam = sParam;
		this.sValue = sValue;
		// this.listOfEnumInputMethod = listOfEnumInputMethod;
	}

	/**
	 * Returns the observer mapped
	 * 
	 * @return Returns the observer.
	 */
	public Observer getObserver() {
		return this.aObserver;
	}

	/**
	 * Sets the mapped observer
	 * 
	 * @param aObserver
	 *            The observer to set.
	 */
	public void setObserver(final Observer aObserver) {
		this.aObserver = aObserver;
	}

	/**
	 * Gets the name of the mapped parameter
	 * 
	 * @return Returns the param.
	 */
	public String getParam() {
		return this.sParam;
	}

	/**
	 * Sets the name of the mapped parameter
	 * 
	 * @param sParam
	 *            The param to set.
	 */
	public void setParam(final String sParam) {
		this.sParam = sParam;
	}

	/**
	 * Gets the name of the mapped value
	 * 
	 * @return Returns the value.
	 */
	public String getValue() {
		return this.sValue;
	}

	/**
	 * Sets the name of the mapped value
	 * 
	 * @param sValue
	 *            The value to set.
	 */
	public void setValue(final String sValue) {
		this.sValue = sValue;
	}

	/**
	 * Returns the list of input methods to whose the value is mapped
	 * 
	 * @return Returns the inputMethodsList.
	 */
	/*
	 * private List<EnumInputMethod> getInputMethodsList() { return
	 * this.listOfEnumInputMethod; }
	 */

	/**
	 * Sets the input methods
	 * 
	 * @param listOfEnumInputMethod
	 *            The inputMethodsList to set.
	 */
	/*
	 * private void setInputMethodsList (final List<EnumInputMethod>
	 * listOfEnumInputMethod) { this.listOfEnumInputMethod =
	 * listOfEnumInputMethod; }
	 */

	/**
	 * Adds an input method to this mapping
	 * 
	 * @param aEnumInputMethod
	 *            the input method to add
	 * @return
	 */
	/*
	 * private boolean addInputMethod (final EnumInputMethod aEnumInputMethod) {
	 * if (this.listOfEnumInputMethod.contains(aEnumInputMethod)) { return
	 * false; } return this.listOfEnumInputMethod.add(aEnumInputMethod); }
	 */

	@Override
	public String toString() {
		final int iStringBufferSize = 1000;
		final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize);

		aStringBuffer.append(this.aObserver.getID());
		aStringBuffer.append('.');
		aStringBuffer.append('.');
		aStringBuffer.append(this.sParam);
		aStringBuffer.append('=');
		aStringBuffer.append(this.sValue);

		return aStringBuffer.toString();
	}

}

--- NEW FILE: TextAreaParameter.java ---
// $Id: TextAreaParameter.java,v 1.1.2.1 2009/08/11 16:05:33 tgambet Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2006.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.unicorn.tasklist.parameters;

import java.util.LinkedHashMap;
import java.util.Map;

import org.w3c.unicorn.exceptions.ParameterException;

/**
 * TextAreaParameter<br />
 * Created: Jun 8, 2006 5:35:31 PM<br />
 */
public class TextAreaParameter extends Parameter {

	private Value aValueDefault;

	/**
	 * Default constructor for a TextAreaParameter (see the Parameter default
	 * constructor).
	 */
	protected TextAreaParameter() {
		super();
		Parameter.logger.trace("Constructor()");
	}

	/**
	 * Adds a Value object to the mapOfValue.
	 * 
	 * @param aValue
	 *            The value to add.
	 */
	@Override
	public void addValue(final Value aValue) {
		this.aValueDefault = aValue;
	}

	/**
	 * For velocity engine.
	 * 
	 * @return The default value.
	 */
	public Value getDefaultValue() {
		return this.aValueDefault;
	}

	/**
	 * Finds a Value object in the map given its name.
	 * 
	 * @param sName
	 *            The name of the Value.
	 * @return The Value object if the String corresponds to a key.
	 */
	@Override
	public Value getValue(final String sName) {
		if (this.aValueDefault.getName().equals(sName)) {
			return this.aValueDefault;
		}
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.unicorn.tasklist.parameters.Parameter#getDefault()
	 */
	@Override
	public Map<String, Value> getMapOfDefaultValue() {
		final Map<String, Value> mapOfValue = new LinkedHashMap<String, Value>();
		mapOfValue.put(this.aValueDefault.getName(), this.aValueDefault);
		return mapOfValue;
	}

	/**
	 * Sets the default Value in the mapOfDefaultValue.
	 * 
	 * @param sDefaultValues
	 *            The new default value.
	 */
	@Override
	public void setDefaultValues(final String sDefaultValues) {
		this.aValueDefault.setName(sDefaultValues);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.w3c.unicorn.tasklist.parameters.Parameter#getValues()
	 */
	@Override
	public Map<String, Value> getMapOfValue() {
		// no value because we allow any text
		return null;
	}

	/**
	 * Defines or replaces the mapOfValue.
	 * 
	 * @param mapOfValue
	 *            The new map of values.
	 */
	@Override
	public void setMapOfValue(final Map<String, Value> mapOfValue)
			throws ParameterException {
		if (mapOfValue.size() != 1) {
			throw new ParameterException(
					"Textarea parameter should have exactly one value.");
		}
		this.aValueDefault = mapOfValue.values().iterator().next();
	}

	/**
	 * Returns the type of the parameter.
	 * 
	 * @return The type TEXTAREA.
	 */
	@Override
	public ParameterType getType() {
		return ParameterType.TEXTAREA;
	}

	/**
	 * Merges a Parameter with this one if the type complies.
	 * 
	 * @param aParameter
	 *            The parameter to merge with the current one.
	 * @return True if they merged correctly, else false.
	 */
	@Override
	public boolean merge(final Parameter aParameter) {
		Parameter.logger.trace("merge");
		// Types must match
		if (!(aParameter instanceof TextAreaParameter)) {
			Parameter.logger.warn("Type of parameter " + this.getName()
					+ " and " + aParameter.getName() + " not matching.");
			return false;
		}
		if (!super.merge(aParameter)) {
			return false;
		}
		final TextAreaParameter aTextAreaParameter = (TextAreaParameter) aParameter;
		this.aValueDefault = aTextAreaParameter.aValueDefault;
		return true;
	}

}

Received on Tuesday, 11 August 2009 16:08:41 UTC