public static boolean checkLocationGMLPoint(DigestType digest, String pos) {

    boolean foundPointLocation = false;
    List<LocationType> locationElements = EMDigestHelper.getLocationElements(digest);
    for (LocationType location : locationElements) {
      XmlObject[] geoLocations =
          location.selectChildren(
              gov.ucore.ucore.x20.GeoLocationType.type.getName().getNamespaceURI(), "GeoLocation");
      if (geoLocations != null && geoLocations.length > 0) {
        for (XmlObject object : geoLocations) {
          GeoLocationType geo = (GeoLocationType) object;
          XmlObject[] UcorePoint =
              geo.selectChildren(
                  gov.ucore.ucore.x20.PointType.type.getName().getNamespaceURI(), "Point");
          if (UcorePoint.length > 0) {
            gov.ucore.ucore.x20.PointType point = (gov.ucore.ucore.x20.PointType) UcorePoint[0];
            if (point.getPoint().getPos().getStringValue().equals(pos)) {
              foundPointLocation = true;
            }
          }
        }
      }
    }
    return foundPointLocation;
  }
  public static boolean hasAHasDestinationOfElement(DigestType digest, String entityID) {

    boolean found = false;
    XmlObject[] hasDestinationOfs =
        digest.selectChildren(
            EntityLocationRelationshipType.type.getName().getNamespaceURI(), HAS_DESTINATION_TYPE);
    if (hasDestinationOfs.length > 0) {
      for (XmlObject object : hasDestinationOfs) {
        EntityLocationRelationshipType hasDestinationOf = (EntityLocationRelationshipType) object;
        if (hasDestinationOf.getLocationRef().getRef().size() > 0
            && hasDestinationOf.getLocationRef().getRef().size() > 0) {
          String entityRef = (String) hasDestinationOf.getEntityRef().getRef().get(0);
          String locationRef = (String) hasDestinationOf.getLocationRef().getRef().get(0);
          List<LocationType> locationElements = EMDigestHelper.getLocationElements(digest);
          for (LocationType location : locationElements) {
            if (entityRef.equals(entityID) && locationRef.equals(location.getId())) {
              found = true;
              break;
            }
          }
          if (found) break;
        }
      }
    }
    return found;
  }
  public static boolean checkLocationAddresses(DigestType digest) {

    boolean foundPointLocation = false;
    List<LocationType> locationElements = EMDigestHelper.getLocationElements(digest);
    for (LocationType location : locationElements) {
      XmlObject[] addresses =
          location.selectChildren(
              gov.ucore.ucore.x20.PhysicalAddressType.type.getName().getNamespaceURI(),
              "PhysicalAddress");
      if (addresses != null && addresses.length > 0) {
        for (XmlObject object : addresses) {
          PhysicalAddressType address = (PhysicalAddressType) object;
          if (address.getPostalAddress() != null) {
            if (address.getPostalAddress().getCountryCode() != null
                && address.getPostalAddress().getCountryCode().getQualifier() != null
                && address.getPostalAddress().getCountryCode().getValue() != null
                && address.getPostalAddress().getState() != null
                && address.getPostalAddress().getCity() != null
                && address.getPostalAddress().getPostalCode() != null
                && address.getPostalAddress().sizeOfStreetArray() > 0) {
              foundPointLocation = true;
            }
          }
        }
      }
    }
    return foundPointLocation;
  }
  public static boolean checkLocationGMLCircle(DigestType digest, String radius, String UOM) {

    boolean foundCircle = false;
    List<LocationType> locationElements = EMDigestHelper.getLocationElements(digest);
    for (LocationType location : locationElements) {
      XmlObject[] geoLocations =
          location.selectChildren(
              gov.ucore.ucore.x20.GeoLocationType.type.getName().getNamespaceURI(), "GeoLocation");
      if (geoLocations != null && geoLocations.length > 0) {
        for (XmlObject object : geoLocations) {
          GeoLocationType geo = (GeoLocationType) object;
          XmlObject[] ucoreCircles =
              geo.selectChildren(
                  CircleByCenterPointType.type.getName().getNamespaceURI(), "CircleByCenterPoint");
          if (ucoreCircles.length > 0) {
            // TODO: should check point value and UOM
            CircleByCenterPointType circle = (CircleByCenterPointType) ucoreCircles[0];
            if (circle.getCircleByCenterPoint().getRadius().getStringValue().equals(radius)
                && circle.getCircleByCenterPoint().getRadius().getUom().equals(UOM)
                && circle.getCircleByCenterPoint().getNumArc() != null) {
              foundCircle = true;
            }
          }
        }
      }
    }
    return foundCircle;
  }
  public static String checkLocationDescriptor(DigestType digest, String locationDescription) {

    String id = null;
    XmlObject[] locations =
        digest.selectChildren(
            gov.ucore.ucore.x20.LocationType.type.getName().getNamespaceURI(), "Location");
    if (locations.length > 0) {
      for (XmlObject object : locations) {
        LocationType location = (LocationType) object;
        if (location.getDescriptor().getStringValue().equals(locationDescription)) {
          id = location.getId();
        }
      }
    }
    return id;
  }
  public static boolean checkLocationGMLPolygon(DigestType digest, List<String> points) {

    boolean foundPolygon = false;
    List<LocationType> locationElements = EMDigestHelper.getLocationElements(digest);
    for (LocationType location : locationElements) {
      XmlObject[] geoLocations =
          location.selectChildren(
              gov.ucore.ucore.x20.GeoLocationType.type.getName().getNamespaceURI(), "GeoLocation");
      if (geoLocations != null && geoLocations.length > 0) {
        for (XmlObject object : geoLocations) {
          GeoLocationType geo = (GeoLocationType) object;
          XmlObject[] ucorePolygons =
              geo.selectChildren(
                  gov.ucore.ucore.x20.PointType.type.getName().getNamespaceURI(), "Polygon");
          if (ucorePolygons.length > 0) {
            for (XmlObject poly : ucorePolygons) {
              if (poly instanceof PolygonType) {
                net.opengis.gml.x32.PolygonType polygon = ((PolygonType) poly).getPolygon();
                if (polygon.getExterior() != null
                    && polygon.getExterior().getAbstractRing() != null) {
                  if (polygon.getExterior().getAbstractRing()
                      instanceof net.opengis.gml.x32.LinearRingType) {
                    net.opengis.gml.x32.LinearRingType linearRing =
                        (net.opengis.gml.x32.LinearRingType)
                            polygon.getExterior().getAbstractRing();
                    if (linearRing.sizeOfPosArray() == points.size()) {
                      foundPolygon = true;
                      // TODO: check the values
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    return foundPolygon;
  }