001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.complex;
017:
018: import java.util.Collections;
019: import java.util.Map;
020:
021: import org.geotools.data.complex.filter.XPath.StepList;
022: import org.geotools.resources.Utilities;
023: import org.opengis.feature.type.AttributeType;
024: import org.opengis.filter.expression.Expression;
025:
026: /**
027: * DOCUMENT ME!
028: *
029: * @author Gabriel Roldan, Axios Engineering
030: * @version $Id: AttributeMapping.java 25814 2007-06-12 12:03:41Z groldan $
031: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/community-schemas/community-schema-ds/src/main/java/org/geotools/data/complex/AttributeMapping.java $
032: * @since 2.4
033: */
034: public class AttributeMapping {
035:
036: /** Expression to set the Attribute's ID from, or {@linkplain Expression#NIL} */
037: private Expression identifierExpression;
038:
039: /** DOCUMENT ME! */
040: private Expression sourceExpression;
041:
042: /** DOCUMENT ME! */
043: //private String targetXPath;
044: private StepList targetXPath;
045:
046: private boolean isMultiValued;
047:
048: /**
049: * If present, represents our way to deal polymorphic attribute instances,
050: * so this node should be of a subtype of the one referenced by
051: * {@link #targetXPath}
052: */
053: AttributeType targetNodeInstance;
054:
055: private Map /* <Name,Expression> */clientProperties;
056:
057: /**
058: * Creates a new AttributeMapping object.
059: *
060: * @param sourceExpression
061: * DOCUMENT ME!
062: * @param targetXPath
063: * DOCUMENT ME!
064: */
065: public AttributeMapping(Expression idExpression,
066: Expression sourceExpression, StepList targetXPath) {
067: this (idExpression, sourceExpression, targetXPath, null, false,
068: null);
069: }
070:
071: public AttributeMapping(Expression idExpression,
072: Expression sourceExpression, StepList targetXPath,
073: AttributeType targetNodeInstance, boolean isMultiValued,
074: Map clientProperties) {
075:
076: this .identifierExpression = idExpression == null ? Expression.NIL
077: : idExpression;
078: this .sourceExpression = sourceExpression == null ? Expression.NIL
079: : sourceExpression;
080: this .isMultiValued = isMultiValued;
081: if (this .sourceExpression == null) {
082: this .sourceExpression = Expression.NIL;
083: }
084: this .targetXPath = targetXPath;
085: this .targetNodeInstance = targetNodeInstance;
086: this .clientProperties = clientProperties == null ? Collections.EMPTY_MAP
087: : clientProperties;
088: }
089:
090: public boolean isMultiValued() {
091: return isMultiValued;
092: }
093:
094: /**
095: * DOCUMENT ME!
096: *
097: * @return DOCUMENT ME!
098: */
099: public Expression getSourceExpression() {
100: return sourceExpression;
101: }
102:
103: /**
104: * DOCUMENT ME!
105: *
106: * @return DOCUMENT ME!
107: */
108: public StepList getTargetXPath() {
109: return targetXPath;
110: }
111:
112: public AttributeType getTargetNodeInstance() {
113: return targetNodeInstance;
114: }
115:
116: /**
117: * DOCUMENT ME!
118: *
119: * @param o
120: * DOCUMENT ME!
121: *
122: * @return DOCUMENT ME!
123: */
124: public boolean equals(Object o) {
125: if (this == o) {
126: return true;
127: }
128:
129: if (!(o instanceof AttributeMapping)) {
130: return false;
131: }
132:
133: AttributeMapping other = (AttributeMapping) o;
134:
135: return Utilities.equals(identifierExpression,
136: other.identifierExpression)
137: && Utilities.equals(sourceExpression,
138: other.sourceExpression)
139: && Utilities.equals(targetXPath, other.targetXPath)
140: && Utilities.equals(targetNodeInstance,
141: other.targetNodeInstance);
142: }
143:
144: /**
145: * DOCUMENT ME!
146: *
147: * @return DOCUMENT ME!
148: */
149: public int hashCode() {
150: return (37 * identifierExpression.hashCode() + 37 * sourceExpression
151: .hashCode())
152: ^ targetXPath.hashCode();
153: }
154:
155: /**
156: * DOCUMENT ME!
157: *
158: * @return DOCUMENT ME!
159: */
160: public String toString() {
161: StringBuffer sb = new StringBuffer("AttributeMapping[");
162: sb.append("sourceExpression='").append(sourceExpression)
163: .append("', targetXPath='").append(targetXPath);
164: if (targetNodeInstance != null) {
165: sb.append(", target instance type=").append(
166: targetNodeInstance);
167: }
168: sb.append("']");
169:
170: return sb.toString();
171: }
172:
173: public Map getClientProperties() {
174: return clientProperties == null ? Collections.EMPTY_MAP
175: : clientProperties;
176: }
177:
178: public Expression getIdentifierExpression() {
179: return identifierExpression;
180: }
181:
182: public void setIdentifierExpression(Expression identifierExpression) {
183: this.identifierExpression = identifierExpression;
184: }
185: }
|