org.geotools.feature.ComplexAttributeImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gt-main Show documentation
Show all versions of gt-main Show documentation
The main module contains the GeoTools public interfaces that are used by
other GeoTools modules (and GeoTools applications). Where possible we make
use industry standard terms as provided by OGC and ISO standards.
The formal GeoTools public api consists of gt-metadata, jts and the gt-main module.
The main module contains the default implementations that are available provided
to other GeoTools modules using our factory system. Factories are obtained from
an appropriate FactoryFinder, giving applications a chance configure the factory
used using the Factory Hints facilities.
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Expression expr = ff.add( expression1, expression2 );
If you find yourself using implementation specific classes chances are you doing it wrong:
Expression expr = new AddImpl( expression1, expressiom2 );
The newest version!
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.feature;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.geotools.feature.type.AttributeDescriptorImpl;
import org.opengis.feature.ComplexAttribute;
import org.opengis.feature.Property;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.feature.type.ComplexType;
import org.opengis.feature.type.Name;
import org.opengis.filter.identity.Identifier;
public class ComplexAttributeImpl extends AttributeImpl implements ComplexAttribute {
public ComplexAttributeImpl(
Collection properties, AttributeDescriptor descriptor, Identifier id) {
super(cloneProperties(properties), descriptor, id);
}
public ComplexAttributeImpl(Collection properties, ComplexType type, Identifier id) {
this(properties, new AttributeDescriptorImpl(type, type.getName(), 1, 1, true, null), id);
}
public ComplexType getType() {
return (ComplexType) super.getType();
}
public Collection extends Property> getValue() {
return FeatureImplUtils.unmodifiable((Collection) super.getValue());
}
public Collection getProperties() {
return FeatureImplUtils.unmodifiable((Collection) super.getValue());
}
/**
* Internal helper method for getting at the properties without wrapping in unmodifiable
* collection.
*/
protected Collection properties() {
return (Collection) super.getValue();
}
public Collection getProperties(Name name) {
List matches = new ArrayList();
for (Iterator p = getValue().iterator(); p.hasNext(); ) {
Property property = (Property) p.next();
if (property.getName().equals(name)) {
matches.add(property);
}
}
return matches;
}
public Collection getProperties(String name) {
List matches = new ArrayList();
for (Iterator p = properties().iterator(); p.hasNext(); ) {
Property property = (Property) p.next();
if (property.getName().getLocalPart().equals(name)) {
matches.add(property);
}
}
return matches;
}
public Property getProperty(Name name) {
for (Iterator p = properties().iterator(); p.hasNext(); ) {
Property property = (Property) p.next();
if (property.getName().equals(name)) {
return property;
}
}
return null;
}
public Property getProperty(String name) {
for (Iterator p = getValue().iterator(); p.hasNext(); ) {
Property property = (Property) p.next();
if (property.getName().getLocalPart().equals(name)) {
return property;
}
}
return null;
}
public void setValue(Object newValue) throws IllegalArgumentException, IllegalStateException {
setValue((Collection) newValue);
}
public void setValue(Collection newValue) {
super.setValue(cloneProperties(newValue));
}
/** helper method to clone the property collection. */
private static Collection cloneProperties(Collection original) {
if (original == null) {
return null;
}
Collection clone = null;
try {
clone = original.getClass().getDeclaredConstructor().newInstance();
} catch (Exception e) {
clone = new ArrayList();
}
clone.addAll(original);
return clone;
}
// public List/* */get(Name name) {
// // JD: this is a farily lenient check, should we be stricter about
// // matching up the namespace
// List/* */childs = new LinkedList/* */();
//
// for (Iterator itr = this.properties.iterator(); itr.hasNext();) {
// Property prop = (Property) itr.next();
// PropertyDescriptor node = prop.descriptor();
// Name propName = node.getName();
// if (name.getNamespaceURI() != null) {
// if (propName.equals(name)) {
// childs.add(prop);
// }
// } else {
// // just do a local part compare
// String localName = propName.getLocalPart();
// if (localName.equals(name.getLocalPart())) {
// childs.add(prop);
// }
// }
//
// }
// return childs;
// }
//
// /**
// * Represents just enough info to convey the idea of this being a "view"
// * into getAttribtues.
// */
// protected synchronized List/* */types() {
// if (types == null) {
// types = createTypesView((List) getValue());
// }
// return types;
// }
//
// /** Factory method so subclasses can optimize */
// protected List/* */createTypesView(
// final List/* */source) {
// if (source == null)
// return Collections.EMPTY_LIST;
//
// return new AbstractList/* */() {
// // @Override
// public Object /* AttributeType */get(int index) {
// return ((Attribute) source.get(index)).getType();
// }
//
// // @Override
// public int size() {
// return source.size();
// }
//
// // @Override
// public Object /* AttributeType */remove(int index) {
// Attribute removed = (Attribute) source.remove(index);
// if (removed != null) {
// return removed.getType();
// }
// return null;
// }
//
// /**
// * Unsupported.
// *
// * We may be able to do this for nilable types, or types that have a
// * default value.
// *
// *
// */
// // @Override
// public void add(int index, Object o) {
// throw new UnsupportedOperationException(
// "Cannot add directly to types");
// }
// };
// }
//
// public synchronized List/*
© 2015 - 2024 Weber Informatics LLC | Privacy Policy