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;
  }
예제 #2
0
  public Object copyTo(Object target, CopyBuilder copyBuilder) {
    Country copy = (target == null) ? new Country() : (Country) target;

    if (isSetAddressLine()) {
      for (AddressLine part : addressLine) {
        AddressLine copyPart = (AddressLine) copyBuilder.copy(part);
        copy.addAddressLine(copyPart);

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

    if (isSetCountryName()) {
      for (CountryName part : countryName) {
        CountryName copyPart = (CountryName) copyBuilder.copy(part);
        copy.addCountryName(copyPart);

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

    if (isSetCountryNameCode()) {
      for (CountryNameCode part : countryNameCode) {
        CountryNameCode copyPart = (CountryNameCode) copyBuilder.copy(part);
        copy.addCountryNameCode(copyPart);

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

    if (isSetAdministrativeArea()) {
      copy.setAdministrativeArea((AdministrativeArea) copyBuilder.copy(administrativeArea));
      if (copy.getAdministrativeArea() == administrativeArea) administrativeArea.setParent(this);
    }

    if (isSetLocality()) {
      copy.setLocality((Locality) copyBuilder.copy(locality));
      if (copy.getLocality() == locality) locality.setParent(this);
    }

    if (isSetThoroughfare()) {
      copy.setThoroughfare((Thoroughfare) copyBuilder.copy(thoroughfare));
      if (copy.getThoroughfare() == thoroughfare) thoroughfare.setParent(this);
    }

    copy.unsetParent();

    return copy;
  }