001: /*
002: * Geotools2 - 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: */
017: package org.geotools.data.complex.config;
018:
019: import java.io.Serializable;
020: import java.util.Collections;
021: import java.util.HashMap;
022: import java.util.Map;
023:
024: /**
025: * Configuration object for the mapping of a community schema attribute.
026: *
027: * @author Gabriel Roldan, Axios Engineering
028: * @version $Id: AttributeMapping.java 25814 2007-06-12 12:03:41Z groldan $
029: * @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/config/AttributeMapping.java $
030: * @since 2.4
031: */
032: public class AttributeMapping implements Serializable {
033: private static final long serialVersionUID = 3624951889528331592L;
034:
035: /**
036: * XPath expression addressing the target attribute in a target FeatureType.
037: */
038: private String targetAttributePath;
039:
040: /**
041: * Expression whose evaluation result against a Feature of the source
042: * FeatureType is going to be the value of the target attribute in output
043: * FeatureType.
044: *
045: * <p>
046: * At this stage, the expression must be a valid OpenGIS Common Query
047: * Language expression.
048: * </p>
049: */
050: private String sourceExpression;
051:
052: /**
053: * Expression whose evaluation result against a Feature of the source
054: * FeatureType is going to be the value of the id attribute property
055: *
056: * <p>
057: * At this stage, the expression must be a valid OpenGIS Common Query
058: * Language expression.
059: * </p>
060: */
061: private String identifierExpression;
062:
063: /**
064: * Name of the target element instance this attribute mapping applies to, or
065: * <code>null</code> if its fully addressable by the FeatureType.
066: *
067: * <p>
068: * for example, the target FeatureType may define a property as
069: * GeometryAttributeType, but the actual instance should be
070: * PointPropertyType.
071: * </p>
072: */
073: private String targetAttributeSchemaElement;
074:
075: /**
076: * If <code>true</code>, indicates that one instance of this attribute
077: * mapping must be created for every repeating group of attributes. In other
078: * words, indicates wether this attribute corresponds to a multivalued or a
079: * single valued attribute.
080: */
081: private boolean isMultiple;
082:
083: /**
084: * Client properties definitions for instances of the target attribute. The
085: * map is keys are strings representing the name of the client properties,
086: * and the map values are strings representing OCG's CQL expressions whose
087: * evaluated value against the instances of the source features are going to
088: * be the client properties values.
089: * <p>
090: * for example: srsName/strConcat("#bh.", BGS_ID)
091: * </p>
092: */
093: private Map clientProperties;
094:
095: /**
096: * Returns the expression whose evaluation result against a Feature of the
097: * source FeatureType is going to be the value of the target attribute in
098: * output FeatureType.
099: *
100: * <p>
101: * At this stage, the expression must be a valid OpenGIS Common Query
102: * Language expression.
103: * </p>
104: *
105: * @return OGC CQL expression for the attribute value
106: */
107: public String getSourceExpression() {
108: return sourceExpression;
109: }
110:
111: /**
112: * Sets the OGC CQL expression for the attribute value.
113: *
114: * @param sourceExpression
115: * OGC CQL expression for the attribute value.
116: */
117: public void setSourceExpression(String sourceExpression) {
118: this .sourceExpression = sourceExpression;
119: }
120:
121: /**
122: * Returns the XPath expression addressing the target attribute in a target
123: * FeatureType.
124: *
125: * @return the XPath location path for the target attribute of the mapping.
126: */
127: public String getTargetAttributePath() {
128: return targetAttributePath;
129: }
130:
131: /**
132: * Sets the XPath expression addressing the target attribute in a target
133: * FeatureType.
134: *
135: * @param targetAttributePath
136: * the XPath location path for the target attribute of the
137: * mapping.
138: */
139: public void setTargetAttributePath(String targetAttributePath) {
140: this .targetAttributePath = targetAttributePath;
141: }
142:
143: /**
144: * Returns the name of the target element instance this attribute mapping
145: * applies to, or <code>null</code> if its fully addressable by the
146: * FeatureType.
147: *
148: * <p>
149: * For example, the target FeatureType may define a property as
150: * GeometryAttributeType, but the actual instance should be
151: * PointPropertyType. In which case, it should be set to
152: * "gml:PointPropertyType" so ComplexDataStore knows it should create a
153: * point property an thus its subelements are to be addressable by
154: * subsequent mappings.
155: * </p>
156: *
157: * @return name of the target element instance in the output schema or
158: * <code>null</code> if not set.
159: */
160: public String getTargetAttributeSchemaElement() {
161: return targetAttributeSchemaElement;
162: }
163:
164: /**
165: * Sets the name of the target element instance in the output schema.
166: *
167: * @param targetAttributeSchemaElement
168: * name of the target element instance in the output schema.
169: * Could be prefixed, in which case the prefix mapping has to be
170: * available in the corresponding {@link
171: * ComplexDataStoreDTO#getNamespaces()}
172: */
173: public void setTargetAttributeSchemaElement(
174: String targetAttributeSchemaElement) {
175: this .targetAttributeSchemaElement = targetAttributeSchemaElement;
176: }
177:
178: /**
179: * Returns wether this attribute should be treated as a single or multi
180: * valued property.
181: *
182: * @return <code>true</code> if this attribute corresponds to a
183: * multivalued property, <code>false</code> otherwise.
184: */
185: public boolean isMultiple() {
186: return isMultiple;
187: }
188:
189: /**
190: * Sets wether this attribute should be treated as a single or multi valued
191: * property.
192: *
193: * @param isMultiple
194: * <code>true</code> if this attribute corresponds to a
195: * multivalued property, <code>false</code> otherwise.
196: */
197: public void setMultiple(boolean isMultiple) {
198: this .isMultiple = isMultiple;
199: }
200:
201: /**
202: * Helper method to allow config digester passing a string.
203: *
204: * @see #setMultiple(boolean)
205: * @param isMultiple
206: */
207: public void setMultiple(String isMultiple) {
208: boolean multiple = Boolean.valueOf(isMultiple).booleanValue();
209: setMultiple(multiple);
210: }
211:
212: /**
213: * Returns a string representation of this config object.
214: *
215: * @return String representation of this config object.
216: */
217: public String toString() {
218: return "AttributeMappingDTO[id > "
219: + identifierExpression
220: + ", "
221: + sourceExpression
222: + " -> "
223: + targetAttributePath
224: + ", isMultiple: "
225: + isMultiple
226: + ((targetAttributeSchemaElement == null) ? ""
227: : (", target node: " + targetAttributeSchemaElement))
228: + "]";
229: }
230:
231: public Map getClientProperties() {
232: return clientProperties == null ? Collections.EMPTY_MAP
233: : clientProperties;
234: }
235:
236: public void setClientProperties(Map clientProperties) {
237: this .clientProperties = clientProperties == null ? null
238: : new HashMap(clientProperties);
239: }
240:
241: public void putClientProperty(String name, String expression) {
242: if (name == null || expression == null) {
243: throw new NullPointerException("name=" + name
244: + ", expression=" + expression);
245: }
246: if (clientProperties == null) {
247: clientProperties = new HashMap();
248: }
249: clientProperties.put(name, expression);
250: }
251:
252: public String getIdentifierExpression() {
253: return identifierExpression;
254: }
255:
256: public void setIdentifierExpression(String identifierExpression) {
257: this.identifierExpression = identifierExpression;
258: }
259: }
|