/**
   * Overriding clone, used to do deep copy of jaxb elements that implement Copyable. Otherwise,
   * just a shallow copy.
   *
   * @see java.lang.Object#clone()
   */
  @Override
  @SuppressWarnings("unchecked")
  public Object clone() {
    GenericDefaultValue<E> o = (GenericDefaultValue<E>) super.clone();

    // jaxb copyable
    if (value instanceof CopyTo) {
      E val;
      try {
        val = (E) value.getClass().newInstance();
      } catch (Exception e) {
        log.warn("Could not create new instance of value, doing a shallow copy");
        return o;
      }

      ((CopyTo) value).copyTo(val);
      // log.debug("Copied value from '"+value+"' to '"+val+"'");// TODO locale
      o.setValue(val);
      return o;
    } else {
      return o;
    }
  }
  @SuppressWarnings("unchecked")
  @Override
  protected void parseFile(String[] argFileString, IMetadataFieldSet argDefaultFields)
      throws InvalidDendroFileException {
    defaults = (TrimsToTridasDefaults) argDefaultFields;
    // TODO run the 'metadata' through the defaults, as
    // the user may have specified his own metadata
    // Extract 'metadata' ;-)
    String userid = argFileString[0].trim();
    SafeIntYear startYear = null;

    try {
      startYear = new SafeIntYear(argFileString[2].trim());
    } catch (NumberFormatException e) {
    }

    // Extract data
    ArrayList<TridasValue> ringWidthValues = new ArrayList<TridasValue>();
    for (int i = 3; i < argFileString.length; i++) {
      TridasValue v = new TridasValue();

      if (argFileString[i].startsWith(" ")) {
        if (argFileString[i].trim().equals("999")) {
          break;
        }
        v.setValue(argFileString[i].trim());
        ringWidthValues.add(v);
        log.debug("value = " + String.valueOf(argFileString[i]));
      } else {
        throw new InvalidDendroFileException(I18n.getText("trims.expectingSpace"), i);
      }
    }

    // Now build up our measurementSeries

    TridasMeasurementSeries series = defaults.getMeasurementSeriesWithDefaults();
    TridasUnit units = new TridasUnit();

    // Set units to 1/100th mm. Is this always the case?
    units.setNormalTridas(NormalTridasUnit.HUNDREDTH_MM);

    // Build identifier for series
    TridasIdentifier seriesId = new ObjectFactory().createTridasIdentifier();
    seriesId.setValue(UUID.randomUUID().toString());
    seriesId.setDomain(
        defaults.getDefaultValue(TridasMandatoryField.IDENTIFIER_DOMAIN).getStringValue());

    // Build interpretation group for series
    TridasInterpretation interp = new TridasInterpretation();
    interp.setFirstYear(startYear.toTridasYear(DatingSuffix.AD));
    interp.setLastYear(startYear.add(ringWidthValues.size() - 1).toTridasYear(DatingSuffix.AD));

    // Add values to nested value(s) tags
    TridasValues valuesGroup = new TridasValues();
    valuesGroup.setValues(ringWidthValues);
    valuesGroup.setUnit(units);
    GenericDefaultValue<TridasVariable> variable =
        (GenericDefaultValue<TridasVariable>)
            defaults.getDefaultValue(TridasMandatoryField.MEASUREMENTSERIES_VARIABLE);
    valuesGroup.setVariable(variable.getValue());
    ArrayList<TridasValues> valuesGroupList = new ArrayList<TridasValues>();
    valuesGroupList.add(valuesGroup);

    // Add all the data to the series
    series.setValues(valuesGroupList);
    series.setInterpretation(interp);
    series.setIdentifier(seriesId);
    series.setLastModifiedTimestamp(DateUtils.getTodaysDateTime());
    series.setDendrochronologist(userid);

    // Add series to our list
    mseriesList.add(series);
  }