001 /*
002 * GeoAPI - Java interfaces for OGC/ISO standards
003 * http://www.geoapi.org
004 *
005 * Copyright (C) 2006-2012 Open Geospatial Consortium, Inc.
006 * All Rights Reserved. http://www.opengeospatial.org/ogc/legal
007 *
008 * Permission to use, copy, and modify this software and its documentation, with
009 * or without modification, for any purpose and without fee or royalty is hereby
010 * granted, provided that you include the following on ALL copies of the software
011 * and documentation or portions thereof, including modifications, that you make:
012 *
013 * 1. The full text of this NOTICE in a location viewable to users of the
014 * redistributed or derivative work.
015 * 2. Notice of any changes or modifications to the OGC files, including the
016 * date changes were made.
017 *
018 * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE
019 * NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
020 * TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT
021 * THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
022 * PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
023 *
024 * COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR
025 * CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
026 *
027 * The name and trademarks of copyright holders may NOT be used in advertising or
028 * publicity pertaining to the software without specific, written prior permission.
029 * Title to copyright in this software and any associated documentation will at all
030 * times remain with copyright holders.
031 */
032 package org.opengis.feature;
033
034 import java.util.Map;
035
036 import org.opengis.feature.type.Name;
037 import org.opengis.feature.type.PropertyDescriptor;
038 import org.opengis.feature.type.PropertyType;
039
040 /**
041 * An instance of a {@link PropertyType} relised as a {@link Attribute} or {@link Association}.
042 * <p>
043 * A property is a wrapper around an arbitrary object or value. The value is
044 * available via the {@link #getValue()} and {@link #setValue(Object)}.
045 *
046 * <pre>
047 * Property property = ...;
048 *
049 * //set the value
050 * property.setValue( "foo" );
051 *
052 * //get the value
053 * String value = (String) property.getValue();
054 * </pre>
055 *
056 * </p>
057 * <p>
058 * Every property has a type. This {@link PropertyType} defines information
059 * about the property. This includes which java class the value of the property
060 * is an instance of, any restrictions on the value, etc...
061 * The type is available via the {@link #getType()} method.
062 *
063 * <pre>
064 * Property property = ...;
065 *
066 * //get the type
067 * PropertyType type = property.getType();
068 *
069 * //get the class of the value
070 * Class<String> valueClass = (Class<String>)type.getBinding();
071 *
072 * </pre>
073 *
074 * </p>
075 * <p>
076 * A property can often be part of another entity such as a {@link Feature} or {@link ComplexAttribute}.
077 * When this is the case, the relationship between the property and its "container" is described by
078 * a {@link PropertyDescriptor}.
079 * The descriptor of a property defines things like nilablility, multiplicity,
080 * etc... See the javadoc of {@link PropertyDescriptor} for more details. The
081 * descriptor is available via the {@link #getDescriptor()} method.
082 *
083 * <pre>
084 * Property property = ...;
085 *
086 * //get the descriptor
087 * PropertyDescriptor descriptor = property.getDescriptor()l
088 *
089 * //is the value allowed to be null?
090 * descriptor.isNillable();
091 *
092 * //how many instances of this property are allowed?
093 * descriptor.getMaxOccurs();
094 * </pre>
095 *
096 * @author Jody Garnett (Refractions Research)
097 * @author Justin Deoliveira (The Open Planning Project)
098 */
099 public interface Property {
100
101 /**
102 * The value or content of the property.
103 * <p>
104 * The class of this object is defined by
105 * <code>getType().getBinding()</code>.
106 * </p>
107 * <p>
108 * This value may be <code>null</code>. In this case
109 * <code>getDescriptor().isNillable()</code> would be <code>true</code>.
110 * </p>
111 *
112 * @return The value of the property.
113 */
114 Object getValue();
115
116 /**
117 * Sets the value or content of the property.
118 * <p>
119 * The class of <tt>newValue</tt> should be the same as or a subclass of
120 * <code>getType().getBinding()</code>.
121 * </p>
122 * <p>
123 * <tt>newValue</tt> may be <code>null</code> if
124 * <code>getDescriptor().isNillable()</code> is <code>true</code>.
125 * </p>
126 *
127 * @param newValue
128 * The new value of the property.
129 *
130 */
131 void setValue(Object newValue);
132
133 /**
134 * The type of the property.
135 * <p>
136 * The type contains information about the value or content of the property
137 * such as its java class.
138 * </p>
139 * <p>
140 * This value is also available via <code>getDescriptor().getType()</code>.
141 * </p>
142 *
143 * @return The property type.
144 */
145 PropertyType getType();
146
147 /**
148 * The {@link PropertyDscriptor} of the property, null if this is a top-level value.
149 * <p>
150 * The descriptor provides information about the property with respect to
151 * its containing entity (more often then not a {@link Feature} or {@link ComplexAttribute}.
152 * </p>
153 *
154 * @return The property descriptor, null if this is a top-level value.
155 * @see ComplexAttribute
156 */
157 PropertyDescriptor getDescriptor();
158
159 /**
160 * The name of the property with respect to its descriptor.
161 * <p>
162 * This method is convenience for <code>getDescriptor().getName()</code>.
163 * </p>
164 *
165 * @return name of the property.
166 */
167 Name getName();
168
169 /**
170 * Flag indicating if <code>null</code> is an acceptable value for the
171 * property.
172 * <p>
173 * This method is convenience for <code>getDescriptor().isNillable()</code>.
174 * </p>
175 *
176 * @return <code>true</code> if the value of the property is allowed to be
177 * <code>null</code>, otherwise <code>false</code>.
178 */
179 boolean isNillable();
180
181 /**
182 * A map of "user data" which enables applications to store
183 * "application-specific" information against a property.
184 * <p>
185 * An example of information that may wish to be stored along with an
186 * attribute could be its srs information (in the case of a geometric
187 * attribute ).
188 *
189 * <pre>
190 * <code>
191 * GeometryAttribute attribute = ...;
192 *
193 * //set the crs
194 * CoordinateReferenceSystem crs = CRS.decode("EPSG:4326");
195 * attribute.setCRS( crs );
196 *
197 * //set the srs
198 * attribute.getUserData().put( "srs", "EPSG:4326" );
199 * </code>
200 * </pre>
201 *
202 * </p>
203 *
204 * @return A map of user data.
205 */
206 Map<Object, Object> getUserData();
207
208 }