public Set entrySet() { if (entrySet == null) { entrySet = new LinkedHashSet<MapEntry>(); final Collection<PropertyDescriptor> types = feature.getType().getDescriptors(); Name attName; Map attributesMap; for (Iterator<PropertyDescriptor> iterator = types.iterator(); iterator.hasNext(); ) { attName = iterator.next().getName(); attributesMap = new AttributeMap(attName, feature); entrySet.add( new MapEntry<Object, Object>(attName.getLocalPart(), attributesMap)); } } return entrySet; } }
private SimpleHash buildType(ComplexType ft) { // create a variable "attributes" which his a list of all the // attributes, but at the same time, is a map keyed by name Map<String, Object> attributeMap = new LinkedHashMap<String, Object>(); Collection<PropertyDescriptor> descriptors = ft.getDescriptors(); for (Iterator<PropertyDescriptor> it = descriptors.iterator(); it.hasNext(); ) { PropertyDescriptor descr = it.next(); Map<String, Object> attribute = new HashMap<String, Object>(); attribute.put("name", descr.getName().getLocalPart()); attribute.put("namespace", getNamespace(descr.getName())); attribute.put("prefix", getPrefix(descr.getName())); attribute.put("type", descr.getType().getBinding().getName()); attribute.put( "isGeometry", Boolean.valueOf(Geometry.class.isAssignableFrom(descr.getType().getBinding()))); attributeMap.put(descr.getName().toString(), attribute); } // build up the result, feature type is represented by its name an // attributes SimpleHash map = new SimpleHash(); map.put("attributes", new SequenceMapModel(attributeMap, this)); map.put("name", ft.getName().getLocalPart()); map.put("namespace", getNamespace(ft.getName())); map.put("prefix", getPrefix(ft.getName())); return map; }
public List<AttributeTypeInfo> loadAttributes(FeatureTypeInfo info) throws IOException { List<AttributeTypeInfo> attributes = new ArrayList(); FeatureType ft = getFeatureType(info); for (PropertyDescriptor pd : ft.getDescriptors()) { AttributeTypeInfo att = catalog.getFactory().createAttribute(); att.setFeatureType(info); att.setName(pd.getName().getLocalPart()); att.setMinOccurs(pd.getMinOccurs()); att.setMaxOccurs(pd.getMaxOccurs()); att.setNillable(pd.isNillable()); att.setBinding(pd.getType().getBinding()); int length = FeatureTypes.getFieldLength(pd); if (length > 0) { att.setLength(length); } attributes.add(att); } return attributes; }
/** * Extracts the AttributeTypeInfo by copying them from the specified feature type. * * @param ft The schema to be harvested * @param info The optional feature type info from which all the attributes belong to */ public List<AttributeTypeInfo> getAttributes(FeatureType ft, FeatureTypeInfo info) { List<AttributeTypeInfo> attributes = new ArrayList<AttributeTypeInfo>(); for (PropertyDescriptor pd : ft.getDescriptors()) { AttributeTypeInfo att = catalog.getFactory().createAttribute(); att.setFeatureType(info); att.setName(pd.getName().getLocalPart()); att.setMinOccurs(pd.getMinOccurs()); att.setMaxOccurs(pd.getMaxOccurs()); att.setNillable(pd.isNillable()); att.setBinding(pd.getType().getBinding()); int length = FeatureTypes.getFieldLength(pd); if (length > 0) { att.setLength(length); } attributes.add(att); } return attributes; }
public static boolean contains(Collection collection, PropertyDescriptor descriptor) { // check for a descriptor with the same name for (Iterator itr = collection.iterator(); itr.hasNext(); ) { PropertyDescriptor d = (PropertyDescriptor) itr.next(); if (d.getName().equals(descriptor.getName())) { return true; } } return false; }
public NodePointer getNodePointer() { return new FeatureTypeAttributePointer( pointer, featureType, children.get(position).getName()); } }
public Name getName() { return getDescriptor().getName(); }
/** Check whether descriptors have been built. If not, construct and sanitise them. */ private void requireDescriptors() { if (descriptors == null) { Collection<PropertyDescriptor> builtDescriptors = buildDescriptors(); if (builtDescriptors == null) { descriptors = Collections.emptyList(); descriptorMap = Collections.emptyMap(); } else { Collection<PropertyDescriptor> localDescriptors = new ArrayList<PropertyDescriptor>(builtDescriptors); Map<Name, PropertyDescriptor> localDescriptorMap = new HashMap<Name, PropertyDescriptor>(); for (PropertyDescriptor descriptor : localDescriptors) { localDescriptorMap.put(descriptor.getName(), descriptor); } descriptors = Collections.unmodifiableCollection(localDescriptors); descriptorMap = Collections.unmodifiableMap(localDescriptorMap); } } }
/** * Convenience method for getting the descriptor of the default geometry type. This method will * first try to look up the supplied <code>defaultGeom</code> property, if it cant find, it will * try to locate any added geometry. */ protected GeometryDescriptor defaultGeometry() { if (defaultGeom != null) { for (PropertyDescriptor pd : properties) { if (pd.getName().equals(defaultGeom)) { return (GeometryDescriptor) pd; } } } // not found or not set, return first geometry for (PropertyDescriptor pd : properties) { if (pd instanceof GeometryDescriptor) { return (GeometryDescriptor) pd; } } return null; }
public ComplexTypeImpl( Name name, Collection<PropertyDescriptor> properties, boolean identified, boolean isAbstract, List<Filter> restrictions, AttributeType superType, InternationalString description) { super(name, Collection.class, identified, isAbstract, restrictions, superType, description); List<PropertyDescriptor> localProperties; Map<Name, PropertyDescriptor> localPropertyMap; if (properties == null) { localProperties = Collections.emptyList(); localPropertyMap = Collections.emptyMap(); } else { localProperties = new ArrayList<PropertyDescriptor>(properties); localPropertyMap = new HashMap<Name, PropertyDescriptor>(); for (PropertyDescriptor pd : properties) { if (pd == null) { // descriptor entry may be null if a request was made for a property that does // not exist throw new NullPointerException( "PropertyDescriptor is null - did you request a property that does not exist?"); } localPropertyMap.put(pd.getName(), pd); } } this.properties = Collections.unmodifiableList(localProperties); this.propertyMap = Collections.unmodifiableMap(localPropertyMap); }
public String toString() { StringBuffer sb = new StringBuffer(getClass().getSimpleName()).append(":"); sb.append(getDescriptor().getName().getLocalPart()); sb.append("<"); sb.append(getDescriptor().getType().getName().getLocalPart()); sb.append(">="); sb.append(value); return sb.toString(); } }
public Collection<Property> getProperties() { List<Property> result = new ArrayList<Property>(); for (PropertyDescriptor descr : featureTyp.getDescriptors()) { result.add(createProperty(descr.getName().getLocalPart())); } return result; }
/** * Returns a list of properties of a simple feature type, including all properties from a given * list, and all mandatory (minoccurs > 0) added. * * @param type feature type * @param propNames given list of properties * @return list of properties including all mandatory properties * @throws IOException */ public static List<PropertyName> addMandatoryProperties( SimpleFeatureType type, List<PropertyName> oldProps) { Iterator<PropertyDescriptor> ii = type.getDescriptors().iterator(); List<PropertyName> properties = new ArrayList<PropertyName>(); while (ii.hasNext()) { PropertyDescriptor descr = ii.next(); PropertyName propName = ff.property(descr.getName()); if (oldProps != null && oldProps.contains(propName)) { properties.add(propName); } else if (((descr.getMinOccurs() > 0) && (descr.getMaxOccurs() != 0))) { // mandatory, add it properties.add(propName); } } return properties; }
/** * Returns the set of descriptors matching the given local name within the given type. * * @param type The type, non null. * @param name The name, non null. * @return The list of descriptors named 'name', or an empty list if none such match. */ public static List /* <PropertyDescriptor> */ descriptors(ComplexType type, String name) { if (name == null) return Collections.EMPTY_LIST; List match = new ArrayList(); for (Iterator itr = type.getDescriptors().iterator(); itr.hasNext(); ) { PropertyDescriptor descriptor = (PropertyDescriptor) itr.next(); String localPart = descriptor.getName().getLocalPart(); if (name.equals(localPart)) { match.add(descriptor); } } // only look up in the super type if the descriptor is not found // as a direct child definition if (match.size() == 0) { AttributeType superType = type.getSuper(); if (superType instanceof ComplexType) { List superDescriptors = descriptors((ComplexType) superType, name); match.addAll(superDescriptors); } } return match; }
/** * Returns the set of descriptors matching the given name. * * @param type The type, non null. * @param name The name, non null. * @return The list of descriptors named 'name', or an empty list if none such match. */ public static List /* <PropertyDescriptor> */ descriptors(ComplexType type, Name name) { if (name == null) return Collections.EMPTY_LIST; List match = new ArrayList(); for (Iterator itr = type.getDescriptors().iterator(); itr.hasNext(); ) { PropertyDescriptor descriptor = (PropertyDescriptor) itr.next(); Name descriptorName = descriptor.getName(); if (name.equals(descriptorName)) { match.add(descriptor); } } // only look up in the super type if the descriptor is not found // as a direct child definition if (match.size() == 0) { AttributeType superType = type.getSuper(); if (superType instanceof ComplexType) { List superDescriptors = descriptors((ComplexType) superType, name); match.addAll(superDescriptors); } } return match; }
public void init(PropertyDescriptor descriptor) { init(); namespace = descriptor.getName().getNamespaceURI(); name = descriptor.getName().getLocalPart(); minOccurs = descriptor.getMinOccurs(); maxOccurs = descriptor.getMaxOccurs(); if (descriptor instanceof AttributeDescriptor) { AttributeDescriptor attribute = (AttributeDescriptor) descriptor; isNillable = attribute.isNillable(); propertyType = attribute.getType(); } if (descriptor instanceof AssociationDescriptor) { AssociationDescriptor association = (AssociationDescriptor) descriptor; propertyType = association.getType(); } }
public boolean hasNext() { while (next == null && firstDelegate.hasNext()) { SimpleFeature f = firstDelegate.next(); for (PropertyDescriptor property : fb.getFeatureType().getDescriptors()) { fb.set(property.getName(), f.getAttribute(property.getName())); } next = fb.buildFeature(Integer.toString(iterationIndex)); fb.reset(); iterationIndex++; } while (next == null && secondDelegate.hasNext() && !firstDelegate.hasNext()) { SimpleFeature f = secondDelegate.next(); for (PropertyDescriptor property : fb.getFeatureType().getDescriptors()) { fb.set(property.getName(), f.getAttribute(property.getName())); } next = fb.buildFeature(Integer.toString(iterationIndex)); fb.reset(); iterationIndex++; } return next != null; }
public PropertyDescriptor getDescriptor(String name) { PropertyDescriptor result = getDescriptor(new NameImpl(name)); if (result == null) { // look in the same namespace as the complex type result = getDescriptor(new NameImpl(getName().getNamespaceURI(), name)); if (result == null) { // full scan for (PropertyDescriptor pd : properties) { if (pd.getName().getLocalPart().equals(name)) { return pd; } } } } return result; }
/** * The namespace-ignorant version of {@link #getDescriptor(Name)}. Note that we honour the same * permissive algorithm as {@link ComplexTypeImpl}: (1) try no-namespace, (2) try * container-namespace, (2) search for match ignoring namespace. <b>*Shudder*</b> * * @see org.opengis.feature.type.ComplexType#getDescriptor(java.lang.String) * @deprecated Any code that uses this method instead of {@link #getDescriptor(Name)} is * inherently unsafe. */ @Deprecated public PropertyDescriptor getDescriptor(String name) { requireDescriptors(); PropertyDescriptor result = getDescriptor(new NameImpl(name)); if (result == null) { result = getDescriptor(new NameImpl(getName().getNamespaceURI(), name)); if (result == null) { for (PropertyDescriptor pd : descriptors) { if (pd.getName().getLocalPart().equals(name)) { return pd; } } } } return result; }
for (PropertyDescriptor desc : reader.getFeatureType().getDescriptors()) { assertTrue(i < feature.getAttributeCount()); assertEquals(feature.getAttribute(desc.getName()), feature.getAttribute(i++));