From 3d356cc9ef7b1055242256c00a2e6b93b5462880 Mon Sep 17 00:00:00 2001 From: Dimitar Misev Date: Sat, 5 Feb 2011 22:44:35 +0100 Subject: WCS 2.0 implementation in Petascope --- .../petascope/wcps/server/core/DomainElement.java | 354 +++++++++++---------- 1 file changed, 180 insertions(+), 174 deletions(-) (limited to 'petascope/src/petascope/wcps/server/core/DomainElement.java') diff --git a/petascope/src/petascope/wcps/server/core/DomainElement.java b/petascope/src/petascope/wcps/server/core/DomainElement.java index 098797a..bbf534e 100644 --- a/petascope/src/petascope/wcps/server/core/DomainElement.java +++ b/petascope/src/petascope/wcps/server/core/DomainElement.java @@ -14,181 +14,187 @@ * You should have received a copy of the GNU General Public License * along with rasdaman community. If not, see . * - * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / - rasdaman GmbH. + * Copyright 2003 - 2010 Peter Baumann / rasdaman GmbH. * * For more information please see * or contact Peter Baumann via . */ -package petascope.wcps.server.core; - -import petascope.wcps.server.exceptions.InvalidMetadataException; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -/** - * This is an axis in geographic coordinates. See the WCPS standard. - */ -public class DomainElement implements Cloneable { - - public static final String WGS84_CRS = "EPSG:4326"; - public static final String IMAGE_CRS = "CRS:1"; - private Set crss; - private String name; - private Double numHi; - private Double numLo; - private String strHi; - private String strLo; - private String type; - private Collection allowedAxes; - - public DomainElement(String name, String type, Double numLo, Double numHi, String strLo, - String strHi, Set crss, Collection axes) - throws InvalidMetadataException { - this.allowedAxes = axes; - - if ((name == null) || (type == null)) { - throw new InvalidMetadataException( - "Invalid domain element: Element name and type cannot be null"); - } - - if (name.equals("")) { - throw new InvalidMetadataException( - "Invalid domain element: Element name cannot be empty"); - } - - if (allowedAxes.contains(type) == false) { - throw new InvalidMetadataException( - "Invalid domain element: Invalid element type: " + type - + ". Allowed element types are: " + allowedAxes.toString()); - } - - if ((numLo != null) && (numHi != null) && (strLo == null) && (strHi == null)) { - if (numLo.compareTo(numHi) == 1) { - throw new InvalidMetadataException( - "Invalid domain element: Lower integer bound cannot be larger than upper integer bound"); - } - - this.numLo = numLo; - this.numHi = numHi; - } else if ((strLo != null) && (numHi != null) && (numLo == null) && (numHi == null)) { - if (strLo.equals("") || strHi.equals("")) { - throw new InvalidMetadataException( - "Invalid domain element: String bounds cannot be empty"); - } - - this.strLo = strLo; - this.strHi = strHi; - } else { - /* Allow both sources of info for time-axes */ - if (type.equals("t")) { - this.strLo = strLo; - this.strHi = strHi; - this.numLo = numLo; - this.numHi = numHi; - } else { - throw new InvalidMetadataException( - "Invalid domain element: Integer bounds must both be non-null if string bounds are null, and vice versa at " - + name + ":" + type); - } - } - - if ((type.equals("x") || type.equals("y")) && (numLo == null)) { - throw new InvalidMetadataException( - "Invalid domain element: A spatial axis must have integer extent"); - } else if (type.equals("temporal") && (strLo == null)) { - throw new InvalidMetadataException( - "Invalid domain element: A temporal axis must have string extent"); - } else if (type.equals("t") && (numLo == null) || (numHi == null)) { - throw new InvalidMetadataException("Invalid domain element: A \"t\" axis must have integer extent and optionally, string extent"); - } - - this.name = name; - this.type = type; - - if ((crss == null) || !crss.contains(IMAGE_CRS)) { -// throw new InvalidMetadataException( -// "Invalid domain element: CRS set does not contain image CRS '" -// + IMAGE_CRS + "'"); - crss.add(IMAGE_CRS); - } - - this.crss = crss; - - } - - @Override - public DomainElement clone() { - Set c = new HashSet(crss.size()); - Iterator i = crss.iterator(); - - while (i.hasNext()) { - c.add(new String(i.next())); - } - - try { - String newName = name == null ? null : new String(name); - String newType = type == null ? null : new String(type); - Double newNumLo = numLo == null ? null : new Double(numLo); - Double newNumHi = numHi == null ? null : new Double(numHi); - String newStrLo = strLo == null ? null : new String(strLo); - String newStrHi = strHi == null ? null : new String(strHi); - return new DomainElement(newName, newType, newNumLo, newNumHi, newStrLo, newStrHi, c, allowedAxes); - } catch (InvalidMetadataException ime) { - throw new RuntimeException( - "Invalid metadata while cloning DomainElement. This is a software bug in WCPS.", - ime); - } - - } - - public boolean equals(DomainElement de) { - if ((numLo == null) && (de.numLo == null)) { - return strLo.equals(de.strLo) && strHi.equals(strHi) - && name.equals(de.name) && type.equals(de.type); - } else if ((strLo == null) && (de.strLo == null)) { - return numLo.equals(de.numLo) && numHi.equals(numHi) - && name.equals(de.name) && type.equals(de.type); - } else { - return false; - } - } - - public String getName() { - return name; - } - - public Double getNumHi() { - return numHi; - } - - public Double getNumLo() { - return numLo; - } - - public String getStrHi() { - return strHi; - } - - public String getStrLo() { - return strLo; - } - - public String getType() { - return type; - } - - public Set getCrsSet() { - return crss; - } - - @Override - public String toString() { - String d = "Domain Element { Name: '" + name + "', Type: '" + type - + "', NumLow: '" + numLo + "', NumHi: '" + numHi + "', StrLow: '" - + strLo + "', StrHi: '" + strHi + "', CrsSet: '" + crss + "'}"; - return d; - } -} +package petascope.wcps.server.core; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import petascope.exceptions.ExceptionCode; +import petascope.exceptions.WCPSException; + +/** + * This is an axis in geographic coordinates. See the WCPS standard. + */ +public class DomainElement implements Cloneable { + + public static final String WGS84_CRS = "EPSG:4326"; + public static final String IMAGE_CRS = "CRS:1"; + private Set crss; + private String name; + private Double numHi; + private Double numLo; + private String strHi; + private String strLo; + private String type; + private String uom; + private Collection allowedAxes; + + public DomainElement(String name, String type, Double numLo, Double numHi, String strLo, + String strHi, Set crss, Collection axes, String uom) throws WCPSException + { + this.allowedAxes = axes; + + if ((name == null) || (type == null)) { + throw new WCPSException(ExceptionCode.InvalidMetadata, + "Invalid domain element: Element name and type cannot be null"); + } + + if (name.equals("")) { + throw new WCPSException(ExceptionCode.InvalidMetadata, + "Invalid domain element: Element name cannot be empty"); + } + + if (allowedAxes.contains(type) == false) { + throw new WCPSException(ExceptionCode.InvalidMetadata, + "Invalid domain element: Invalid element type: " + type + + ". Allowed element types are: " + allowedAxes.toString()); + } + + if ((numLo != null) && (numHi != null) && (strLo == null) && (strHi == null)) { + if (numLo.compareTo(numHi) == 1) { + throw new WCPSException(ExceptionCode.InvalidMetadata, + "Invalid domain element: Lower integer bound cannot be larger than upper integer bound"); + } + + this.numLo = numLo; + this.numHi = numHi; + } else if ((strLo != null) && (numHi != null) && (numLo == null) && (numHi == null)) { + if (strLo.equals("") || strHi.equals("")) { + throw new WCPSException(ExceptionCode.InvalidMetadata, + "Invalid domain element: String bounds cannot be empty"); + } + + this.strLo = strLo; + this.strHi = strHi; + } else { + /* Allow both sources of info for time-axes */ + if (type.equals("t")) { + this.strLo = strLo; + this.strHi = strHi; + this.numLo = numLo; + this.numHi = numHi; + } else { + throw new WCPSException(ExceptionCode.InvalidMetadata, + "Invalid domain element: Integer bounds must both be non-null if string bounds are null, and vice versa at " + + name + ":" + type); + } + } + + if ((type.equals("x") || type.equals("y")) && (numLo == null)) { + throw new WCPSException(ExceptionCode.InvalidMetadata, + "Invalid domain element: A spatial axis must have integer extent"); + } else if (type.equals("temporal") && (strLo == null)) { + throw new WCPSException(ExceptionCode.InvalidMetadata, + "Invalid domain element: A temporal axis must have string extent"); + } else if (type.equals("t") && (numLo == null) || (numHi == null)) { + throw new WCPSException(ExceptionCode.InvalidMetadata, "Invalid domain element: A \"t\" axis must have integer extent and optionally, string extent"); + } + + this.name = name; + this.type = type; + + if ((crss == null) || !crss.contains(IMAGE_CRS)) { +// throw new WCPSException(ExceptionCode.InvalidMetadata, +// "Invalid domain element: CRS set does not contain image CRS '" +// + IMAGE_CRS + "'"); + crss.add(IMAGE_CRS); + } + + this.crss = crss; + + } + + @Override + public DomainElement clone() { + Set c = new HashSet(crss.size()); + Iterator i = crss.iterator(); + + while (i.hasNext()) { + c.add(new String(i.next())); + } + + try { + String newName = name == null ? null : new String(name); + String newType = type == null ? null : new String(type); + Double newNumLo = numLo == null ? null : new Double(numLo); + Double newNumHi = numHi == null ? null : new Double(numHi); + String newStrLo = strLo == null ? null : new String(strLo); + String newStrHi = strHi == null ? null : new String(strHi); + String newUom = uom == null ? null : new String(uom); + return new DomainElement(newName, newType, newNumLo, newNumHi, newStrLo, newStrHi, c, allowedAxes, newUom); + } catch (WCPSException ime) { + throw new RuntimeException( + "Invalid metadata while cloning DomainElement. This is a software bug in WCPS.", + ime); + } + + } + + public boolean equals(DomainElement de) { + if ((numLo == null) && (de.numLo == null)) { + return strLo.equals(de.strLo) && strHi.equals(strHi) + && name.equals(de.name) && type.equals(de.type); + } else if ((strLo == null) && (de.strLo == null)) { + return numLo.equals(de.numLo) && numHi.equals(numHi) + && name.equals(de.name) && type.equals(de.type); + } else { + return false; + } + } + + public String getName() { + return name; + } + + public Double getNumHi() { + return numHi; + } + + public Double getNumLo() { + return numLo; + } + + public String getStrHi() { + return strHi; + } + + public String getStrLo() { + return strLo; + } + + public String getType() { + return type; + } + + public Set getCrsSet() { + return crss; + } + + public String getUom() { + return uom; + } + + @Override + public String toString() { + String d = "Domain Element { Name: '" + name + "', Type: '" + type + + "', NumLow: '" + numLo + "', NumHi: '" + numHi + "', StrLow: '" + + strLo + "', StrHi: '" + strHi + "', CrsSet: '" + crss + "'}"; + return d; + } +} -- cgit