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; }
propertyFields.add(p.getName().toString()); String propName = prop.getName().toString(); if (propertyFields.contains(propName)) { Object binding = prop.getType().getBinding(); LOG.debug("Property {} of feature {} could not be interpreted as int, skipping", prop.getName().toString(), ft.getId()); continue;
public AttributeType put(Name name, AttributeType type) { if (!(name instanceof Name)) { throw new IllegalArgumentException("Please use a Name"); } Name n = (Name) name; if (!(n.toString().startsWith(uri.toString()))) { throw new IllegalArgumentException("Provided name was not in schema:" + uri); } if (!(type instanceof AttributeType)) { throw new IllegalArgumentException("Please use an AttributeType"); } AttributeType t = (AttributeType) type; return contents.put(n, t); }
public QName getRemoteTypeName(Name localTypeName) throws IOException { if (names.isEmpty()) { createTypeNames(); } QName qName = names.get(localTypeName); if (null == qName) { throw new NoSuchElementException(localTypeName.toString()); } return qName; }
public void setFeatureValue(Name name, Object value) { if (currentItem == null) { throw new IllegalStateException("Missing prior call to newFeature method"); } currentItem.put(name.toString(), value); }
/** Read a GridCoverage2D base on the specified read parameters. */ @Override public GridCoverage2D read(GeneralParameterValue[] parameters) throws IllegalArgumentException, IOException { if (!names.isEmpty()) { if (names.size() > 1) { throw new IllegalArgumentException("You need to specify a coverageName"); } else { return read(names.get(0).toString(), parameters); } } return null; }
/** Simple Implementation of toString method for debugging purpose. */ public String toString() { final StringBuilder sb = new StringBuilder(); final String lineSeparator = System.getProperty("line.separator", "\n"); sb.append("Name:").append(name.toString()).append(lineSeparator); sb.append("Description:").append(description.toString()).append(lineSeparator); sb.append("FieldTypes:").append(lineSeparator); for (FieldType fieldType : fieldTypes) { sb.append("fieldType:").append(fieldType.toString()); sb.append(lineSeparator).append(lineSeparator); } return sb.toString(); } }
public Object getProperty(Object object, QName name) throws Exception { Map.Entry<Name, Object> data = (Map.Entry<Name, Object>) object; if ("name".equals(name.getLocalPart())) { return data.getKey().toString(); } if ("value".equals(name.getLocalPart())) { if (data.getValue() != null) { return data.getValue().toString(); } else { return null; } } return super.getProperty(object, name); } }
/** * Look up a QName based on a given Name. * * @param localTypeName The local type name whose QName equivalent you'd like. * @return The QName that corresponds to the Name you passed in. * @throws IOException */ public QName getRemoteTypeName(Name localTypeName) throws IOException { if (names.isEmpty()) { getNames(); } QName qName = names.get(localTypeName); if (null == qName) { throw new NoSuchElementException(localTypeName.toString()); } return qName; }
public DefaultResourceInfo(FeatureSource fs) { this.fs = fs; words = new HashSet<String>(); { words.add("features"); words.add(fs.getSchema().getName().toString()); } }
/** Get features based on the specified filter. */ @Override public FeatureCollection<FeatureType, Feature> getFeatures(Filter filter) throws IOException { return getFeatures(new Query(this.typeName.toString(), filter)); }
/** * Return the feature type for supported type name. Only {@link * SampleDataAccessData.MAPPEDFEATURE_TYPE_NAME} is supported. * * @see org.geotools.data.DataAccess#getSchema(org.opengis.feature.type.Name) */ public FeatureType getSchema(Name name) throws IOException { if (name.equals(SampleDataAccessData.MAPPEDFEATURE_TYPE_NAME)) { return SampleDataAccessData.MAPPEDFEATURE_TYPE; } else if (name.equals(SampleDataAccessData.GEOLOGICUNIT_TYPE_NAME)) { return SampleDataAccessData.GEOLOGICUNIT_TYPE; } else { throw new RuntimeException("Unrecognised feature type " + name.toString()); } }
/** @see org.geotools.data.DataAccess#getFeatureSource(org.opengis.feature.type.Name) */ public FeatureSource<FeatureType, Feature> getFeatureSource(Name typeName) throws IOException { if (typeName.equals(SampleDataAccessData.MAPPEDFEATURE_TYPE_NAME)) { return new SampleDataAccessFeatureSource(); } else if (typeName.equals(SampleDataAccessData.GEOLOGICUNIT_TYPE_NAME)) { throw new IllegalArgumentException( "Although this DataAccess claims to provide " + SampleDataAccessData.GEOLOGICUNIT_TYPE_NAME + ", it does so only so that schema references" + " are resolved when this type is nested inside " + SampleDataAccessData.MAPPEDFEATURE_TYPE_NAME + ". Direct access to the former feature type is not supported."); } else { throw new RuntimeException("Unrecognised feature type " + typeName.toString()); } }
/** * Store the {@link FeatureTypeMapper} instance * * @param mapper */ protected void storeMapper(FeatureTypeMapper mapper) { final Properties properties = new Properties(); final String typeName = mapper.getName().toString(); properties.setProperty(NAME, typeName); properties.setProperty(MAPPEDNAME, mapper.getMappedName().toString()); final List<Definition> definitions = mapper.getDefinitions(); final StringBuilder builder = new StringBuilder(); // Populating schema for (Definition definition : definitions) { builder.append(definition.getName()) .append(":") .append(definition.getBinding().getName()) .append(","); } String schema = builder.toString(); schema = schema.substring(0, schema.length() - 1); properties.setProperty(SCHEMA, schema); properties.setProperty( COORDINATE_REFERENCE_SYSTEM, mapper.getCoordinateReferenceSystem().toWKT()); // Storing properties storeProperties(properties, typeName); }
@Override protected void storeMapper(FeatureTypeMapper mapper) { final Properties properties = new Properties(); final String typeName = mapper.getName().toString(); properties.setProperty(NAME, typeName); properties.setProperty(MAPPEDNAME, mapper.getMappedName().toString()); final List<Definition> definitions = mapper.getDefinitions(); final StringBuilder builder = new StringBuilder(); // Populating schema for (Definition definition : definitions) { builder.append(definition.getName()) .append(":") .append(definition.getBinding().getName()) .append(","); } String schema = builder.toString(); schema = schema.substring(0, schema.length() - 1); properties.setProperty(SCHEMA, schema); properties.setProperty( COORDINATE_REFERENCE_SYSTEM, mapper.getCoordinateReferenceSystem().toWKT()); properties.setProperty( SRID, Integer.toString(((PostgisFeatureTypeMapper) mapper).getSrID())); // Storing properties storeProperties(properties, typeName); } }
/** Attribute error check */ protected void checkAttributeFound( PropertyName expression, StepList exprSteps, FeatureChainedAttributeVisitor nestedAttrExtractor, FeatureChainedAttributeVisitor existsAttrExtractor, List<FeatureChainedAttributeDescriptor> fcAttrs) { if (fcAttrs.size() == 0 && !nestedAttrExtractor.conditionalMappingWasFound() && !isXlinkHRef(exprSteps) && existsAttrExtractor.getFeatureChainedAttributes().isEmpty()) { throw new IllegalArgumentException( String.format( "Attribute \"%s\" not found in type \"%s\"", expression, mappings.getTargetFeature().getName().toString())); } }
@Override public ServiceInfo getInfo(ProgressListener listener) { if (listener == null) { listener = new NullProgressListener(); } listener.started(); final DefaultServiceInfo info = new DefaultServiceInfo(); // Fix that Collection<Name> coverageNames = getNames(listener); Iterator<Name> namesIterator = coverageNames.iterator(); if (namesIterator.hasNext()) { info.setTitle(namesIterator.next().toString()); } try { info.setSource(source.toURI()); } catch (URISyntaxException e1) { } finally { listener.complete(); } return info; }
@Override public ServiceInfo getInfo() { try { DefaultServiceInfo info = new DefaultServiceInfo(); SimpleFeatureType schema = source.getSchema(); info.setDescription("Features from " + schema.getName()); info.setSchema(new URI(schema.getName().getNamespaceURI())); info.setTitle(schema.getName().toString()); return info; } catch (Exception e) { throw new RuntimeException("Feature source returned an invalid namespace URI", e); } }
private int countFeatures(AppSchemaDataAccess dS) throws Exception { // we need the feature type in order to query for the number of features Name[] dSNameArray = dS.getTypeNames(); String testType = dSNameArray[0].toString(); FeatureSource<FeatureType, Feature> featureSource = dS.getFeatureSourceByName(dSNameArray[0]); int numFeatures = featureSource.getCount(new Query(testType)); return numFeatures; }