public Function function(Name processName, List<Expression> args, Literal fallback) { // if the param function just return it if (processName.equals(new NameImpl(ParameterFunction.NAME))) { return new ParameterFunction(fallback, args); } // lookup the process if (functionNames == null) { init(); } if (!processToFunction.containsKey(processName)) { // no such function return null; } else { // wrap the process org.geotools.process.Process process = Processors.createProcess(processName); Map<String, Parameter<?>> parameters = Processors.getParameterInfo(processName); if (process instanceof RenderingProcess) { return new RenderingProcessFunction( processName.getLocalPart(), processName, args, parameters, (RenderingProcess) process, fallback); } else { return new ProcessFunction( processName.getLocalPart(), processName, args, parameters, process, fallback); } } }
public Element AbstractFeatureTypeEncode( Object object, Document document, Element value, XSDIdRegistry idSet) { Feature feature = (Feature) object; String id = feature.getIdentifier().getID(); Name typeName; if (feature.getDescriptor() == null) { // no descriptor, assume WFS feature type name is the same as the name of the content // model type typeName = feature.getType().getName(); } else { // honour the name set in the descriptor typeName = feature.getDescriptor().getName(); } Element encoding = document.createElementNS(typeName.getNamespaceURI(), typeName.getLocalPart()); if (!(feature instanceof SimpleFeature) && idSet != null) { if (idSet.idExists(id)) { // XSD type ids can only appear once in the same document, otherwise the document is // not schema valid. Attributes of the same ids should be encoded as xlink:href to // the existing attribute. encoding.setAttributeNS(XLINK.NAMESPACE, XLINK.HREF.getLocalPart(), "#" + id.toString()); // make sure the attributes aren't encoded feature.setValue(Collections.emptyList()); return encoding; } else { idSet.add(id); } } encoding.setAttributeNS(gml.getNamespaceURI(), "id", id); encodeClientProperties(feature, value); return encoding; }
public boolean delete(GeogigTransaction transaction, Feature f) throws Exception { final WorkingTree workTree = (transaction != null ? transaction.workingTree() : repo.workingTree()); Name name = f.getType().getName(); String localPart = name.getLocalPart(); String id = f.getIdentifier().getID(); boolean existed = workTree.delete(localPart, id); return existed; }
/** Inserts the feature to the index but does not stages it to be committed */ public ObjectId insert(GeogigTransaction transaction, Feature f) throws Exception { final WorkingTree workTree = (transaction != null ? transaction.workingTree() : repo.workingTree()); Name name = f.getType().getName(); String parentPath = name.getLocalPart(); Node ref = workTree.insert(parentPath, f); ObjectId objectId = ref.getObjectId(); return objectId; }
public String getContentString() { StringBuilder sb = new StringBuilder(); sb.append("Layer:").append(name.getLocalPart()).append("\n"); Iterator<Entry<String, String>> it = attributes.entrySet().iterator(); while (it.hasNext()) { Entry<String, String> next = it.next(); sb.append(next.getKey()).append(":").append(next.getValue()).append("\n"); } return sb.toString(); }
/** * Encode any client properties (XML attributes) found in the UserData map of a ComplexAttribute * as XML attributes of the element. * * @param complex the ComplexAttribute to search for client properties * @param element the element to which XML attributes should be added */ @SuppressWarnings("unchecked") public static void encodeClientProperties(Property complex, Element element) { Map<Name, Object> clientProperties = (Map<Name, Object>) complex.getUserData().get(Attributes.class); if (clientProperties != null) { for (Name name : clientProperties.keySet()) { if (clientProperties.get(name) != null) { element.setAttributeNS( name.getNamespaceURI(), name.getLocalPart(), clientProperties.get(name).toString()); } } } }
/** * Returns the VPFFile for a particular column. It will only find the first match, but that should * be okay because duplicate columns will cause even bigger problems elsewhere. * * @param column the column to search for * @return the VPFFile that owns this column */ private VPFFile getVPFFile(AttributeDescriptor column) { Name columnName = column.getName(); VPFFile result = null; VPFFile temp; Iterator<VPFFile> iter = featureType.getFeatureClass().getFileList().iterator(); while (iter.hasNext()) { temp = iter.next(); if ((temp != null) && (temp.getColumn(columnName.getLocalPart()) != null)) { result = temp; break; } } return result; }
/** @return the tree of feature references for this type */ public RevTree getCurrentVersion() { // assume HEAD is at MASTER try { final Name typeName = this.type.getName(); GeoGIT geogit = dataStore.getGeogit(); RevTree typeTree = geogit .getRepository() .getWorkingTree() .getHeadVersion(new QName(typeName.getNamespaceURI(), typeName.getLocalPart())); return typeTree; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Special handling for polymorphic mapping. Works out the polymorphic type name by evaluating the * function on the feature, then set the relevant sub-type values. * * @param target The target feature to be encoded * @param id The target feature id * @param nestedMapping The mapping that is polymorphic * @param source The source simple feature * @param xpath The xpath of polymorphic type * @param clientPropsMappings Client properties * @throws IOException */ private Attribute setPolymorphicValues( Name mappingName, Attribute target, String id, NestedAttributeMapping nestedMapping, Object source, StepList xpath, Map<Name, Expression> clientPropsMappings) throws IOException { // process sub-type mapping DataAccess<FeatureType, Feature> da = DataAccessRegistry.getDataAccess((Name) mappingName); if (da instanceof AppSchemaDataAccess) { // why wouldn't it be? check just to be safe FeatureTypeMapping fTypeMapping = ((AppSchemaDataAccess) da).getMappingByName((Name) mappingName); List<AttributeMapping> polymorphicMappings = fTypeMapping.getAttributeMappings(); AttributeDescriptor attDescriptor = fTypeMapping.getTargetFeature(); AttributeType type = attDescriptor.getType(); Name polymorphicTypeName = attDescriptor.getName(); StepList prefixedXpath = xpath.clone(); prefixedXpath.add( new Step( new QName( polymorphicTypeName.getNamespaceURI(), polymorphicTypeName.getLocalPart(), this.namespaces.getPrefix(polymorphicTypeName.getNamespaceURI())), 1)); if (!fTypeMapping.getFeatureIdExpression().equals(Expression.NIL)) { id = fTypeMapping.getFeatureIdExpression().evaluate(source, String.class); } Attribute instance = xpathAttributeBuilder.set( target, prefixedXpath, null, id, type, false, attDescriptor, null); setClientProperties(instance, source, clientPropsMappings); for (AttributeMapping mapping : polymorphicMappings) { if (skipTopElement(polymorphicTypeName, mapping, type)) { // if the top level mapping for the Feature itself, the attribute instance // has already been created.. just need to set the client properties setClientProperties(instance, source, mapping.getClientProperties()); continue; } setAttributeValue( instance, null, source, mapping, null, null, selectedProperties.get(mapping)); } return instance; } return null; }
public HDF4ProductFieldType( final Name name, final InternationalString description, final Unit<?> unit, final SimpleScalarAxis axis, final SampleDimension sd) { Unit<? extends Quantity> uom = unit; if (unit == null) { Product product = getProduct(name.getLocalPart()); if (product != null) uom = product.getUoM(); } this.wrappedFieldType = new BaseFieldType( name, description, uom, Collections.singletonList(axis), Collections.singletonMap(axis.getKey(0), sd)); }
static Filter lookupExtendedOperator( Name opName, List<Expression> expressions, org.opengis.filter.FilterFactory factory) { FunctionFinder finder = new FunctionFinder(null); Function f = finder.findFunction(opName.getLocalPart(), expressions); return factory.equal(f, factory.literal(true), true); }
/** Sets the local name and namespace uri of the built type. */ public void setName(Name name) { setName(name.getLocalPart()); setNamespaceURI(name.getNamespaceURI()); }
/** * Delegates to {@link #updateSchema(String, SimpleFeatureType)} with {@code name.getLocalPart()} * * @since 2.5 * @see DataAccess#getFeatureSource(Name) */ public void updateSchema(Name typeName, SimpleFeatureType featureType) throws IOException { updateSchema(typeName.getLocalPart(), featureType); }
/** * Delegates to {@link #getSchema(String)} with {@code name.getLocalPart()} * * @since 2.5 * @see DataAccess#getSchema(Name) */ public SimpleFeatureType getSchema(Name name) throws IOException { return getSchema(name.getLocalPart()); }
/** * Delegates to {@link #getFeatureSource(String)} with {@code name.getLocalPart()} * * @since 2.5 * @see DataAccess#getFeatureSource(Name) */ public SimpleFeatureSource getFeatureSource(Name typeName) throws IOException { return getFeatureSource(typeName.getLocalPart()); }
/** Creates a new instance of FunctionExpression */ protected FunctionExpressionImpl(Name name, Literal fallback) { this.functionName = new FunctionNameImpl(name, (Class) null); this.name = name.getLocalPart(); this.fallback = fallback; params = new ArrayList<org.opengis.filter.expression.Expression>(); }
@Override public Property getProperty(Name name) { return getProperties(name.getLocalPart()).iterator().next(); }
/** * Write the feature into the stream. * * @param feature The feature * @param root * @throws XMLStreamException */ public Element writeFeature(final Feature feature, final Document rootDocument, boolean fragment) throws ParserConfigurationException { final Document document; if (rootDocument == null) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // then we have to create document-loader: factory.setNamespaceAware(false); DocumentBuilder loader = factory.newDocumentBuilder(); // creating a new DOM-document... document = loader.newDocument(); } else { document = rootDocument; } // the root element of the xml document (type of the feature) final FeatureType type = feature.getType(); final Name typeName = type.getName(); final String namespace = typeName.getNamespaceURI(); final String localPart = typeName.getLocalPart(); final Element rootElement; final Prefix prefix; if (namespace != null) { prefix = getPrefix(namespace); rootElement = document.createElementNS(namespace, localPart); rootElement.setPrefix(prefix.prefix); } else { rootElement = document.createElement(localPart); prefix = null; } // if main document set the xmlns if (!fragment) { rootElement.setAttributeNS( "http://www.w3.org/2000/xmlns/", "xmlns:gml", "http://www.opengis.net/gml"); } final Attr idAttr = document.createAttributeNS(Namespaces.GML, "id"); idAttr.setValue(feature.getIdentifier().getID()); idAttr.setPrefix("gml"); rootElement.setAttributeNodeNS(idAttr); if (rootDocument == null) { document.appendChild(rootElement); } // write properties in the type order for (final PropertyDescriptor desc : type.getDescriptors()) { final Collection<Property> props = feature.getProperties(desc.getName()); for (Property a : props) { final Object valueA = a.getValue(); final PropertyType typeA = a.getType(); final Name nameA = a.getName(); final String nameProperty = nameA.getLocalPart(); String namespaceProperty = nameA.getNamespaceURI(); if (valueA instanceof Collection && !(typeA instanceof GeometryType)) { for (Object value : (Collection) valueA) { final Element element; if (namespaceProperty != null) { element = document.createElementNS(namespaceProperty, nameProperty); } else { element = document.createElement(nameProperty); } element.setTextContent(Utils.getStringValue(value)); if (prefix != null) { element.setPrefix(prefix.prefix); } rootElement.appendChild(element); } } else if (valueA instanceof Map && !(typeA instanceof GeometryType)) { final Map<?, ?> map = (Map) valueA; for (Entry<?, ?> entry : map.entrySet()) { final Element element; if (namespaceProperty != null) { element = document.createElementNS(namespaceProperty, nameProperty); } else { element = document.createElement(nameProperty); } final Object key = entry.getKey(); if (key != null) { element.setAttribute("name", (String) key); } element.setTextContent(Utils.getStringValue(entry.getValue())); if (prefix != null) { element.setPrefix(prefix.prefix); } rootElement.appendChild(element); } } else if (!(typeA instanceof GeometryType)) { String value = Utils.getStringValue(valueA); if (value != null || (value == null && !a.isNillable())) { if ((nameProperty.equals("name") || nameProperty.equals("description")) && !Namespaces.GML.equals(namespaceProperty)) { namespaceProperty = Namespaces.GML; LOGGER.warning( "the property name and description of a feature must have the GML namespace"); } final Element element; if (namespaceProperty != null) { element = document.createElementNS(namespaceProperty, nameProperty); } else { element = document.createElement(nameProperty); } if (value != null) { element.setTextContent(value); } if (prefix != null) { element.setPrefix(prefix.prefix); } rootElement.appendChild(element); } // we add the geometry } else { if (valueA != null) { final Element element; if (namespaceProperty != null) { element = document.createElementNS(namespaceProperty, nameProperty); } else { element = document.createElement(nameProperty); } if (prefix != null) { element.setPrefix(prefix.prefix); } Geometry isoGeometry = JTSUtils.toISO( (com.vividsolutions.jts.geom.Geometry) valueA, type.getCoordinateReferenceSystem()); Marshaller marshaller = null; try { marshaller = POOL.acquireMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false); marshaller.marshal(OBJECT_FACTORY.buildAnyGeometry(isoGeometry), element); } catch (JAXBException ex) { LOGGER.log( Level.WARNING, "JAXB Exception while marshalling the iso geometry: " + ex.getMessage(), ex); } finally { if (marshaller != null) { POOL.release(marshaller); } } rootElement.appendChild(element); } } } } // writer.writeEndElement(); return rootElement; }