@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { int childCount = parentElement.getChildCount(); AggregatorConfig[] aggregatorConfigs = new AggregatorConfig[childCount]; for (int i = 0; i < childCount; i++) { DomElement child = parentElement.getChild(i); aggregatorConfigs[i] = (AggregatorConfig) super.convertDomToValue(child, null); } return aggregatorConfigs; }
@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { try { String srsName = parentElement.getChild(SRS_NAME).getValue(); double minX = Double.parseDouble(parentElement.getChild(MIN_X).getValue()); double minY = Double.parseDouble(parentElement.getChild(MIN_Y).getValue()); double maxX = Double.parseDouble(parentElement.getChild(MAX_X).getValue()); double maxY = Double.parseDouble(parentElement.getChild(MAX_Y).getValue()); value = new CRSEnvelope(srsName, minX, minY, maxX, maxY); } catch (Exception e) { throw new IllegalArgumentException(e); } return value; }
@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { try { String srsName = parentElement.getChild(SRS_NAME).getValue(); double minX = Double.parseDouble(parentElement.getChild(MIN_X).getValue()); double minY = Double.parseDouble(parentElement.getChild(MIN_Y).getValue()); double maxX = Double.parseDouble(parentElement.getChild(MAX_X).getValue()); double maxY = Double.parseDouble(parentElement.getChild(MAX_Y).getValue()); value = new CRSEnvelope(srsName, minX, minY, maxX, maxY); } catch (Exception e) { throw new IllegalArgumentException(e); } return value; }
@Test public void testStoreAndLoadParameter() throws IOException, ValidationException, ConversionException { final OperatorParameterSupport support = new OperatorParameterSupport(new TestOpSpi().getOperatorDescriptor()); PropertySet container = support.getPropertySet(); container.setValue("paramDouble", 0.42); container.setValue("paramString", "A String!"); container.setValue("paramComplex", new Complex(25)); final DomElement domElement = support.toDomElement(); assertEquals("parameters", domElement.getName()); assertEquals(3, domElement.getChildCount()); assertNotNull(domElement.getChild("paramDouble")); assertEquals("0.42", domElement.getChild("paramDouble").getValue()); assertNotNull(domElement.getChild("paramString")); assertEquals("A String!", domElement.getChild("paramString").getValue()); assertNotNull(domElement.getChild("paramComplex")); assertNotNull(domElement.getChild("paramComplex").getChild("complexInt")); assertEquals("25", domElement.getChild("paramComplex").getChild("complexInt").getValue()); // change container container.setValue("paramDouble", 23.67); container.setValue("paramString", "Another String"); container.setValue("paramComplex", new Complex(17)); support.fromDomElement(domElement); assertEquals(0.42, (double)support.getPropertySet().getValue("paramDouble"), 1.0e-6); assertEquals("A String!", support.getPropertySet().getValue("paramString")); assertEquals(new Complex(25), support.getPropertySet().getValue("paramComplex")); }
@Override protected BitmaskDef getProductNode(DomElement parentElement, Product product) { final String bitmaskName = parentElement.getChild("bitmaskName").getValue(); return product.getBitmaskDef(bitmaskName); }
@Test public void testStoreAndLoadParameter() throws IOException, ValidationException, ConversionException { final OperatorParameterSupport support = new OperatorParameterSupport(new TestOpSpi().getOperatorDescriptor()); PropertySet container = support.getPropertySet(); container.setValue("paramDouble", 0.42); container.setValue("paramString", "A String!"); container.setValue("paramComplex", new Complex(25)); final DomElement domElement = support.toDomElement(); assertEquals("parameters", domElement.getName()); assertEquals(3, domElement.getChildCount()); assertNotNull(domElement.getChild("paramDouble")); assertEquals("0.42", domElement.getChild("paramDouble").getValue()); assertNotNull(domElement.getChild("paramString")); assertEquals("A String!", domElement.getChild("paramString").getValue()); assertNotNull(domElement.getChild("paramComplex")); assertNotNull(domElement.getChild("paramComplex").getChild("complexInt")); assertEquals("25", domElement.getChild("paramComplex").getChild("complexInt").getValue()); // change container container.setValue("paramDouble", 23.67); container.setValue("paramString", "Another String"); container.setValue("paramComplex", new Complex(17)); support.fromDomElement(domElement); assertEquals(0.42, (double)support.getPropertySet().getValue("paramDouble"), 1.0e-6); assertEquals("A String!", support.getPropertySet().getValue("paramString")); assertEquals(new Complex(25), support.getPropertySet().getValue("paramComplex")); }
@Override protected RasterDataNode getProductNode(DomElement parentElement, Product product) { final DomElement rasterName = parentElement.getChild("rasterName"); return product.getRasterDataNode(rasterName.getValue()); }
@Override protected RasterDataNode getProductNode(DomElement parentElement, Product product) { final DomElement rasterName = parentElement.getChild("rasterName"); return product.getRasterDataNode(rasterName.getValue()); }
private Shape convertDomToShape(DomElement parentElement) throws ConversionException, ValidationException { final DomElement shapeChild = parentElement.getChild("shape"); final DefaultDomConverter domConverter = new DefaultDomConverter(Shape.class); return (Shape) domConverter.convertDomToValue(shapeChild, null); }
@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { final DomElement child = parentElement.getChild(0); SLDParser s = new SLDParser(CommonFactoryFinder.getStyleFactory(null), new StringReader(child.toXml())); final Style[] styles = s.readXML(); return styles[0]; }
@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { final DomElement child = parentElement.getChild(0); SLDParser s = new SLDParser(CommonFactoryFinder.getStyleFactory(null), new StringReader(child.toXml())); final Style[] styles = s.readXML(); return styles[0]; }
public File[] getPotentialOutputFiles() { final List<File> fileList = new ArrayList<>(); final Node[] nodes = graph.getNodes(); for (Node n : nodes) { if (n.getOperatorName().startsWith(OperatorSpi.getOperatorAlias(WriteOp.class))) { final DomElement config = n.getConfiguration(); final DomElement fileParam = config.getChild("file"); if (fileParam != null) { final String filePath = fileParam.getValue(); if (filePath != null && !filePath.isEmpty()) { final File file = new File(filePath); fileList.add(file); } } } } return fileList.toArray(new File[fileList.size()]); }
@Override public AbstractFigure convertDomToValue(DomElement parentElement, Object figure) throws ConversionException, ValidationException { final String className = parentElement.getAttribute("class"); final Shape shapeObject = convertDomToShape(parentElement); Map<String, Object> attributes = convertDomToAttributes(parentElement); if (LineFigure.class.getName().equals(className)) { return new LineFigure(shapeObject, attributes); } else if (AreaFigure.class.getName().equals(className)) { return new AreaFigure(shapeObject, attributes); } else if (ShapeFigure.class.getName().equals(className)) { final DomElement dimensionalChild = parentElement.getChild("oneDimensional"); final boolean oneDimensional = Boolean.valueOf(dimensionalChild.getValue()); return new ShapeFigure(shapeObject, oneDimensional, attributes); } return null; }
if (n.getOperatorName().equalsIgnoreCase(OperatorSpi.getOperatorAlias(WriteOp.class))) { final DomElement config = n.getConfiguration(); final DomElement fileParam = config.getChild("file"); if (fileParam != null) { final String filePath = fileParam.getValue(); fileList.add(file); } else { final DomElement formatParam = config.getChild("formatName"); final String format = formatParam.getValue();
@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { ConverterRegistry registry = ConverterRegistry.getInstance(); DomElement widthElement = parentElement.getChild("width"); Float width = registry.getConverter(Float.class).parse(widthElement.getValue()); DomElement capElement = parentElement.getChild("cap"); Integer cap = registry.getConverter(Integer.class).parse(capElement.getValue()); DomElement joinElement = parentElement.getChild("join"); Integer join = registry.getConverter(Integer.class).parse(joinElement.getValue()); DomElement miterlimitElement = parentElement.getChild("miterlimit"); Float miterlimit = registry.getConverter(Float.class).parse(miterlimitElement.getValue()); DomElement dashElement = parentElement.getChild("dash"); float[] dash = null; if(dashElement != null) { dash = registry.getConverter(float[].class).parse(dashElement.getValue()); } DomElement dashPhaseElement = parentElement.getChild("dashPhase"); Float dashPhase = registry.getConverter(Float.class).parse(dashPhaseElement.getValue()); return new BasicStroke(width, cap, join, miterlimit, dash, dashPhase); }
@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { DomElement typeElement = parentElement.getChild("type"); if (typeElement == null) { throw new ConversionException(String.format("Missing element 'type' in parent element '%s'", parentElement.getName())); } String typeName = typeElement.getValue(); TC config; if (value == null) { config = createConfig(typeName); } else { config = (TC) value; } DomConverter childConverter = createChildConverter(config.getClass()); childConverter.convertDomToValue(parentElement, config); return config; }
@Override public final T convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { final DomElement refNoElement = parentElement.getChild("refNo"); if (refNoElement == null) { throw new ConversionException(String.format( "In parent element '%s': no child element 'refNo'", parentElement.getName())); } final Integer refNo; try { refNo = Integer.valueOf(refNoElement.getValue()); } catch (NumberFormatException e) { throw new ConversionException(String.format( "In parent element '%s': %s", parentElement.getName(), e.getMessage())); } final Product product = productManager.getProductByRefNo(refNo); if (product == null) { throw new ConversionException(String.format( "In parent element '%s': no product with refNo = %d", parentElement.getName(), refNo)); } return getProductNode(parentElement, product); }
@Override public final T convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { final DomElement refNoElement = parentElement.getChild("refNo"); if (refNoElement == null) { throw new ConversionException(String.format( "In parent element '%s': no child element 'refNo'", parentElement.getName())); } final Integer refNo; try { refNo = Integer.valueOf(refNoElement.getValue()); } catch (NumberFormatException e) { throw new ConversionException(String.format( "In parent element '%s': %s", parentElement.getName(), e.getMessage())); } final Product product = productManager.getProductByRefNo(refNo); if (product == null) { throw new ConversionException(String.format( "In parent element '%s': no product with refNo = %d", parentElement.getName(), refNo)); } return getProductNode(parentElement, product); }
public void setIO(final File srcFile, final File tgtFile, final String format) { final String readOperatorAlias = OperatorSpi.getOperatorAlias(ReadOp.class); final Node readerNode = findNode(graph, readOperatorAlias); if (readerNode != null) { final DomElement param = new DefaultDomElement("parameters"); param.createChild("file").setValue(srcFile.getAbsolutePath()); readerNode.setConfiguration(param); } final String writeOperatorAlias = OperatorSpi.getOperatorAlias(WriteOp.class); final Node writerNode = findNode(graph, writeOperatorAlias); if (writerNode != null && tgtFile != null) { final DomElement origParam = writerNode.getConfiguration(); origParam.getChild("file").setValue(tgtFile.getAbsolutePath()); if (format != null) origParam.getChild("formatName").setValue(format); } }
public void setOperatorParam(final String id, final String paramName, final String value) { final Node node = graph.getNode(id); DomElement xml = node.getConfiguration().getChild(paramName); if (xml == null) { xml = new XppDomElement(paramName); node.getConfiguration().addChild(xml); } xml.setValue(value); }