@Override public void convertValueToDom(Object value, DomElement parentElement) throws ConversionException { Geometry geom = (Geometry) value; final Coordinate[] coordinates = geom.getCoordinates(); final DefaultDomConverter domConverter = new DefaultDomConverter(Coordinate.class); for (Coordinate coordinate : coordinates) { final DomElement child = parentElement.createChild("coordinate"); domConverter.convertValueToDom(coordinate, child); } }
@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { com.vividsolutions.jts.geom.GeometryFactory gf = new com.vividsolutions.jts.geom.GeometryFactory(); final DefaultDomConverter domConverter = new DefaultDomConverter(Coordinate.class); final DomElement[] children = parentElement.getChildren("coordinate"); List<Coordinate> coordList = new ArrayList<Coordinate>(); for (DomElement child : children) { final Coordinate coordinate = (Coordinate) domConverter.convertDomToValue(child, null); coordList.add(coordinate); } return gf.createPolygon( gf.createLinearRing(coordList.toArray(new Coordinate[coordList.size()])), null); }
private Map<String, Object> convertParameterMap( String operatorName, Map<String, String> parameterMap) throws ValidationException { HashMap<String, Object> parameters = new HashMap<String, Object>(); PropertyContainer container = ParameterDescriptorFactory.createMapBackedOperatorPropertyContainer( operatorName, parameters); // explicitly set default values for putting them into the backing map container.setDefaultValues(); // handle xml parameters Object parametersObject = metadataResourceEngine.getVelocityContext().get("parameterFile"); if (parametersObject instanceof Resource) { Resource paramatersResource = (Resource) parametersObject; if (paramatersResource.isXml()) { OperatorSpiRegistry operatorSpiRegistry = GPF.getDefaultInstance().getOperatorSpiRegistry(); OperatorSpi operatorSpi = operatorSpiRegistry.getOperatorSpi(operatorName); Class<? extends Operator> operatorClass = operatorSpi.getOperatorClass(); DefaultDomConverter domConverter = new DefaultDomConverter(operatorClass, new ParameterDescriptorFactory()); DomElement parametersElement = createDomElement(paramatersResource.getContent()); try { domConverter.convertDomToValue(parametersElement, container); } catch (ConversionException e) { String msgPattern = "Can not convert XML parameters for operator '%s'"; throw new RuntimeException(String.format(msgPattern, operatorName)); } } } for (Entry<String, String> entry : parameterMap.entrySet()) { String paramName = entry.getKey(); String paramValue = entry.getValue(); final Property property = container.getProperty(paramName); if (property != null) { property.setValueFromText(paramValue); } else { throw new RuntimeException( String.format("Parameter '%s' is not known by operator '%s'", paramName, operatorName)); } } return parameters; }