Exemplo n.º 1
0
  @Override
  public Object copyTo(Object target, CopyBuilder copyBuilder) {
    Address copy = (target == null) ? new Address() : (Address) target;
    super.copyTo(copy, copyBuilder);

    if (isSetXalAddress()) {
      copy.setXalAddress((XalAddressProperty) copyBuilder.copy(xalAddress));
      if (copy.getXalAddress() == xalAddress) xalAddress.setParent(this);
    }

    if (isSetMultiPoint()) {
      copy.setMultiPoint((MultiPointProperty) copyBuilder.copy(multiPoint));
      if (copy.getMultiPoint() == multiPoint) multiPoint.setParent(this);
    }

    if (isSetGenericApplicationPropertyOfAddress()) {
      for (ADEComponent part : ade) {
        ADEComponent copyPart = (ADEComponent) copyBuilder.copy(part);
        copy.addGenericApplicationPropertyOfAddress(copyPart);

        if (part != null && copyPart == part) part.setParent(this);
      }
    }

    return copy;
  }
  public long insert(Address address) throws SQLException {
    if (!address.isSetXalAddress() || !address.getXalAddress().isSetAddressDetails()) return 0;

    XalAddressProperty xalAddressProperty = address.getXalAddress();
    AddressDetails addressDetails = xalAddressProperty.getAddressDetails();

    // ok, let's start
    long addressId = dbImporterManager.getDBId(DBSequencerEnum.ADDRESS_ID_SEQ);
    if (addressId == 0) return 0;

    boolean success = false;
    String streetAttr, houseNoAttr, poBoxAttr, zipCodeAttr, cityAttr, countryAttr, xalSource;
    streetAttr = houseNoAttr = poBoxAttr = zipCodeAttr = cityAttr = countryAttr = xalSource = null;
    PGgeometry multiPoint = null;

    // try and interpret <country> child element
    if (addressDetails.isSetCountry()) {
      Country country = addressDetails.getCountry();

      // country name
      if (country.isSetCountryName()) {
        List<String> countryName = new ArrayList<String>();
        for (CountryName name : country.getCountryName()) countryName.add(name.getContent());

        countryAttr = Util.collection2string(countryName, ",");
      }

      // locality
      if (country.isSetLocality()) {
        Locality locality = country.getLocality();

        // check whether we deal with a city or a town
        if (locality.isSetType()
            && (locality.getType().toUpperCase().equals("CITY")
                || locality.getType().toUpperCase().equals("TOWN"))) {

          // city name
          if (locality.isSetLocalityName()) {
            List<String> localityName = new ArrayList<String>();
            for (LocalityName name : locality.getLocalityName())
              localityName.add(name.getContent());

            cityAttr = Util.collection2string(localityName, ",");
          }

          // thoroughfare - just streets are supported
          if (locality.isSetThoroughfare()) {
            Thoroughfare thoroughfare = locality.getThoroughfare();

            // check whether we deal with a street
            if (thoroughfare.isSetType()
                && (thoroughfare.getType().toUpperCase().equals("STREET")
                    || thoroughfare.getType().toUpperCase().equals("ROAD"))) {

              // street name
              if (thoroughfare.isSetThoroughfareName()) {
                List<String> fareName = new ArrayList<String>();
                for (ThoroughfareName name : thoroughfare.getThoroughfareName())
                  fareName.add(name.getContent());

                streetAttr = Util.collection2string(fareName, ",");
              }

              // house number - we do not support number ranges so far...
              if (thoroughfare.isSetThoroughfareNumberOrThoroughfareNumberRange()) {
                List<String> houseNumber = new ArrayList<String>();
                for (ThoroughfareNumberOrRange number :
                    thoroughfare.getThoroughfareNumberOrThoroughfareNumberRange()) {
                  if (number.isSetThoroughfareNumber())
                    houseNumber.add(number.getThoroughfareNumber().getContent());
                }

                houseNoAttr = Util.collection2string(houseNumber, ",");
              }
            }
          }

          // dependent locality
          if (streetAttr == null && houseNoAttr == null && locality.isSetDependentLocality()) {
            DependentLocality dependentLocality = locality.getDependentLocality();

            if (dependentLocality.isSetType()
                && dependentLocality.getType().toUpperCase().equals("DISTRICT")) {

              if (dependentLocality.isSetThoroughfare()) {
                Thoroughfare thoroughfare = dependentLocality.getThoroughfare();

                // street name
                if (streetAttr == null && thoroughfare.isSetThoroughfareName()) {
                  List<String> fareName = new ArrayList<String>();
                  for (ThoroughfareName name : thoroughfare.getThoroughfareName())
                    fareName.add(name.getContent());

                  streetAttr = Util.collection2string(fareName, ",");
                }

                // house number - we do not support number ranges so far...
                if (houseNoAttr == null
                    && thoroughfare.isSetThoroughfareNumberOrThoroughfareNumberRange()) {
                  List<String> houseNumber = new ArrayList<String>();
                  for (ThoroughfareNumberOrRange number :
                      thoroughfare.getThoroughfareNumberOrThoroughfareNumberRange()) {
                    if (number.isSetThoroughfareNumber())
                      houseNumber.add(number.getThoroughfareNumber().getContent());
                  }

                  houseNoAttr = Util.collection2string(houseNumber, ",");
                }
              }
            }
          }

          // postal code
          if (locality.isSetPostalCode()) {
            PostalCode postalCode = locality.getPostalCode();

            // get postal code number
            if (postalCode.isSetPostalCodeNumber()) {
              List<String> zipCode = new ArrayList<String>();
              for (PostalCodeNumber number : postalCode.getPostalCodeNumber())
                zipCode.add(number.getContent());

              zipCodeAttr = Util.collection2string(zipCode, ",");
            }
          }

          // post box
          if (locality.isSetPostBox()) {
            PostBox postBox = locality.getPostBox();

            // get post box nummber
            if (postBox.isSetPostBoxNumber()) poBoxAttr = postBox.getPostBoxNumber().getContent();
          }
        }
      }

      // multiPoint geometry
      if (address.isSetMultiPoint()) multiPoint = stGeometry.getMultiPoint(address.getMultiPoint());

      success = true;
    } else {
      StringBuilder msg =
          new StringBuilder(Util.getFeatureSignature(address.getCityGMLClass(), address.getId()));
      msg.append(": Failed to interpret xAL address element.");
      LOG.error(msg.toString());
    }

    // get XML representation of <xal:AddressDetails>
    if (importXalSource) {
      xalSource = dbImporterManager.marshal(addressDetails, XALModuleType.CORE);
      if (xalSource != null && xalSource.length() > 0) success = true;
    }

    if (success) {
      psAddress.setLong(1, addressId);
      psAddress.setString(2, streetAttr);
      psAddress.setString(3, houseNoAttr);
      psAddress.setString(4, poBoxAttr);
      psAddress.setString(5, zipCodeAttr);
      psAddress.setString(6, cityAttr);
      psAddress.setString(7, countryAttr);

      if (multiPoint != null) {
        psAddress.setObject(8, multiPoint);
      } else psAddress.setNull(8, Types.OTHER, "ST_GEOMETRY");

      if (xalSource != null) psAddress.setString(9, xalSource);
      else psAddress.setNull(9, Types.CLOB);

      psAddress.addBatch();
      if (++batchCounter == Internal.POSTGRESQL_MAX_BATCH_SIZE)
        dbImporterManager.executeBatch(DBImporterEnum.ADDRESS);

      // enable xlinks
      if (address.isSetId())
        dbImporterManager.putGmlId(address.getId(), addressId, address.getCityGMLClass());
    } else addressId = 0;

    return addressId;
  }