private static void addDomToMetadata(DomElement parentDE, MetadataElement parentME) { final HashMap<String, List<DomElement>> map = new HashMap<>( parentDE.getChildCount() + 5); for (DomElement childDE : parentDE.getChildren()) { final String name = childDE.getName(); List<DomElement> elementList = map.get(name); if (elementList == null) { elementList = new ArrayList<>(3); map.put(name, elementList); } elementList.add(childDE); } for (Entry<String, List<DomElement>> entry : map.entrySet()) { String name = entry.getKey(); final List<DomElement> elementList = entry.getValue(); if (elementList.size() > 1) { for (int i = 0; i < elementList.size(); i++) { addDomToMetadata(elementList.get(i), name + '.' + i, parentME); } } else { addDomToMetadata(elementList.get(0), name, parentME); } } }
@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); }
private ProductSetData[] findProductSets(final String readerName) { final List<ProductSetData> productSetDataList = new ArrayList<>(); for (Node n : graph.getNodes()) { if (n.getOperatorName().equalsIgnoreCase(readerName)) { final ProductSetData psData = new ProductSetData(); psData.nodeID = n.getId(); final DomElement config = n.getConfiguration(); final DomElement[] params = config.getChildren(); for (DomElement p : params) { if (p.getName().equals("fileList") && p.getValue() != null) { final StringTokenizer st = new StringTokenizer(p.getValue(), ProductSetHandler.SEPARATOR); int length = st.countTokens(); for (int i = 0; i < length; i++) { final String str = st.nextToken().replace(ProductSetHandler.SEPARATOR_ESC, ProductSetHandler.SEPARATOR); psData.fileList.add(str); } break; } } productSetDataList.add(psData); } } return productSetDataList.toArray(new ProductSetData[productSetDataList.size()]); }
private SubGraphData[] findSubGraphs(final String opName) throws GraphException { try { final List<SubGraphData> dataList = new ArrayList<>(); for (Node n : graph.getNodes()) { if (n.getOperatorName().equalsIgnoreCase(opName)) { final SubGraphData data = new SubGraphData(); data.nodeID = n.getId(); final DomElement config = n.getConfiguration(); final DomElement[] params = config.getChildren(); for (DomElement p : params) { if (p.getName().equals("graphFile") && p.getValue() != null) { data.subGraph = GraphIO.read(new FileReader(p.getValue())); break; } } dataList.add(data); } } return dataList.toArray(new SubGraphData[dataList.size()]); } catch (Exception e) { throw new GraphException(e.getMessage(), e); } }
@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; }
return null; DomElement resolvedElement = new XppDomElement(domElement.getName()); Set<OperatorConfiguration.Reference> references = new HashSet<>(17); DomElement[] children = domElement.getChildren(); String reference = child.getAttribute("refid"); if (reference != null) { String parameterName = child.getName(); if (reference.contains(".")) { String[] referenceParts = reference.split("\\.");
for (int i = 0; i < count; ++i) { final DomElement child = config.getChild(i); final String name = child.getName(); final String value = child.getValue(); if (name == null || value == null)
@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")); }
@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")); }