/**
   * @ejb.interface-method
   * @ejb.transaction type="Required"
   */
  public ValueObject fill(ValueObject valueObject) throws LocalException {
    List list = new CompressedSerializedList();
    ValueObject returnValue = null;
    try {
      if (valueObject instanceof SpecialRateValue) {
        SpecialRateValue object = new SpecialRateValue((SpecialRateValue) valueObject);

        if (object.getId() == null) {
          throw new LocalException("Could not fill object, because primary key is null: " + object);
        }
        SpecialRateLineManagerLocal srlm =
            (SpecialRateLineManagerLocal) SpecialRateLineManagerUtil.getLocalHome().create();
        Collection col =
            SpecialRateLineUtil.getLocalHome().findBySpecialRateId(object.getId().longValue());
        for (Iterator iter = col.iterator(); iter.hasNext(); ) {
          SpecialRateLineLocal element = (SpecialRateLineLocal) iter.next();
          list.add(srlm.fill(element.getSpecialRateLineValue()));
        }
        object.fillSpecialRateLines(list);
        returnValue = object;

      } else {
        // others
        throw new LocalException(
            "Tried to fill an Unsupported valueObject-type: " + valueObject.getClass());
      }
    } catch (NamingException e) {
      throw new LocalException("NamingException while filling: " + valueObject, e);
    } catch (FinderException e) {
      throw new LocalException("FinderException while filling: " + valueObject, e);
    } catch (CreateException e) {
      throw new LocalException("FinderException while filling: " + valueObject, e);
    }
    return returnValue;
  }
  /**
   * @see net.metaship.generic.Manager#deleteSpecialRate(PrimaryKey)
   * @ejb.interface-method
   * @ejb.transaction type="Required"
   */
  public void delete(PrimaryKey primaryKey) throws LocalException {
    checkPrimaryKeyInstance(primaryKey);

    try {
      Collection col =
          SpecialRateLineUtil.getLocalHome()
              .findBySpecialRateId(((SpecialRatePK) primaryKey).getId().longValue());
      for (Iterator iter = col.iterator(); iter.hasNext(); ) {
        SpecialRateLineLocal element = (SpecialRateLineLocal) iter.next();

        Collection col2 =
            RateServiceAreaUtil.getLocalHome().findBySpecialRateLineId(element.getId().longValue());
        for (Iterator iterator = col2.iterator(); iterator.hasNext(); ) {
          RateServiceAreaLocal element2 = (RateServiceAreaLocal) iterator.next();
          element2.remove();
        }

        element.remove();
      }

      SpecialRateLocalHome home = SpecialRateUtil.getLocalHome();
      SpecialRateLocal local = home.findByPrimaryKey((SpecialRatePK) primaryKey);
      local.remove();
    } catch (Exception e) {
      throw new LocalException(
          "An Error occured while deleting object with primary key: " + primaryKey + "!!", e);
    }
  }
  /**
   * Copy the specified tariffPK's with all line items to new tariffs with the given validity Can
   * handle Tariff PK's or TariffLine PK's if TariffLinePK's are handed over onlly the handed ones
   * are copied
   *
   * @param tariffPKs
   * @param newDurationFrom
   * @param newDurationTo
   * @return
   * @throws LocalException
   * @throws NamingException
   * @throws FinderException
   * @ejb.interface-method
   * @ejb.transaction type="Required"
   */
  public List copy(java.util.List tariffPKs, java.util.Date durationFrom, java.util.Date durationTo)
      throws LocalException, FinderException, NamingException {
    if (log.isInfoEnabled())
      log.info(">copy " + " List" + tariffPKs + " Date " + durationFrom + " Date " + durationTo);

    if (tariffPKs.size() < 1) return new ArrayList();

    List pks = null;
    List copiedTariffs = new ArrayList();
    Hashtable pKs = new Hashtable();
    if (tariffPKs.get(0) instanceof SpecialRateLinePK) {
      for (int i = 0, n = tariffPKs.size(); i < n; i++) {
        SpecialRateLineLocal ttll =
            ((SpecialRateLineLocal)
                SpecialRateLineUtil.getLocalHome()
                    .findByPrimaryKey((SpecialRateLinePK) tariffPKs.get(i)));
        SpecialRatePK ttpk = new SpecialRatePK(new Long(ttll.getSpecialRateId()));
        SpecialRateValue ttl = null;
        if (!pKs.contains(ttpk)) {
          ttl =
              SpecialRateUtil.getLocalHome()
                  .findByPrimaryKey(ttpk)
                  .plainCopy(false, durationFrom, durationTo);
          pKs.put(ttpk, ttl);
          copiedTariffs.add(ttl);
        }
        ttl = (SpecialRateValue) pKs.get(ttpk);
        ttll.copyInto(ttl.getPrimaryKey());
      }

    } else {
      pks = tariffPKs;
      copiedTariffs = copyTariffPK(pks, durationFrom, durationTo);
    }
    return copiedTariffs;
  }