@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; }
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); } } }
final int count = config.getChildCount(); for (int i = 0; i < count; ++i) { final DomElement child = config.getChild(i); if (child.getChildCount() == 0) { final Converter converter = getConverter(valueContainer, name); if (converter == null) { final Object[] objArray = new Object[child.getChildCount()]; int c = 0; for (DomElement ch : child.getChildren()) {
private static void addDomToMetadata(DomElement childDE, String name, MetadataElement parentME) { if (childDE.getChildCount() > 0 || childDE.getAttributeNames().length > 0) { final MetadataElement childME = new MetadataElement(name); addDomToMetadata(childDE, childME); parentME.addElement(childME); if (childDE.getAttributeNames().length != 0) { String[] attributeNames = childDE.getAttributeNames(); for (String attributeName : attributeNames) { String attributeValue = childDE.getAttribute(attributeName); final ProductData valueMEAtrr = ProductData.createInstance(attributeValue); final MetadataAttribute mdAttribute = new MetadataAttribute(attributeName, valueMEAtrr, true); childME.addAttribute(mdAttribute); } } } else { String valueDE = childDE.getValue(); if (valueDE == null) { valueDE = ""; } final ProductData valueME = ProductData.createInstance(valueDE); final MetadataAttribute attribute = new MetadataAttribute(name, valueME, true); parentME.addAttribute(attribute); } }
private void testSession(Session session) { assertEquals(Session.CURRENT_MODEL_VERSION, session.getModelVersion()); assertEquals(2, session.getProductCount()); testProductRef(session.getProductRef(0), 11, "out/DIMAP/X.dim"); testProductRef(session.getProductRef(1), 15, "out/DIMAP/Y.dim"); assertEquals(4, session.getViewCount()); testViewRef(session.getViewRef(0), 0, ProductSceneView.class.getName(), new Rectangle(0, 0, 200, 100), 11, "A"); testViewRef(session.getViewRef(1), 1, ProductSceneView.class.getName(), new Rectangle(200, 0, 200, 100), 15, "C"); testViewRef(session.getViewRef(2), 2, ProductSceneView.class.getName(), new Rectangle(0, 100, 200, 100), 11, "B"); testViewRef(session.getViewRef(3), 3, ProductSceneView.class.getName(), new Rectangle(200, 100, 200, 100), 15, "D"); assertEquals(3, session.getViewRef(3).getLayerCount()); assertEquals("[15] D", session.getViewRef(3).getLayerRef(0).name); final Session.LayerRef graticuleLayerRef = session.getViewRef(3).getLayerRef(1); assertEquals("Graticule", graticuleLayerRef.name); assertNotNull(graticuleLayerRef.configuration); assertEquals(13, graticuleLayerRef.configuration.getChildCount()); final Session.LayerRef maskCollectionLayerRef = session.getViewRef(3).getLayerRef(2); assertEquals("Mask Collection", maskCollectionLayerRef.name); assertNotNull(maskCollectionLayerRef.configuration); assertEquals(0, maskCollectionLayerRef.configuration.getChildCount()); assertEquals(2, maskCollectionLayerRef.children.length); assertEquals("M1", maskCollectionLayerRef.children[0].name); assertEquals("M2", maskCollectionLayerRef.children[1].name); }
@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")); }