protected void cloneMetadataAttributes(MetadataElement sourceRoot, MetadataElement destRoot) { for (int i = 0; i < sourceRoot.getNumAttributes(); i++) { MetadataAttribute sourceAttribute = sourceRoot.getAttributeAt(i); destRoot.addAttribute(sourceAttribute.createDeepClone()); } }
private ExpectedMetadata[] createExpectedMetadata(Product product, Random random) { final MetadataElement metadataRoot = product.getMetadataRoot(); final List<ExpectedMetadata> expectedMetadata = new ArrayList<ExpectedMetadata>(); if (metadataRoot.getNumElements() > 0 || metadataRoot.getNumAttributes() > 0) { while(expectedMetadata.size() < 2) { MetadataElement currentElem = metadataRoot; while (currentElem != null && currentElem.getNumElements() > 0) { currentElem = currentElem.getElementAt((int) (currentElem.getNumElements() * random.nextFloat())); } if (currentElem != null && currentElem.getNumAttributes() > 0) { final MetadataAttribute attributeAt = currentElem.getAttributeAt((int) (currentElem.getNumAttributes() * random.nextFloat())); expectedMetadata.add(new ExpectedMetadata(attributeAt)); } } } return expectedMetadata.toArray(new ExpectedMetadata[expectedMetadata.size()]); }
public static List<Row> createRowList(MetadataElement rootElement) { List<Row> rowList = new ArrayList<Row>(10); for (int i = 0; i < rootElement.getNumAttributes(); i++) { MetadataAttribute attribute = rootElement.getAttributeAt(i); if (!isNumericAttribute(attribute) || attribute.getData().isScalar()) { rowList.add(new MDAttributeRow(attribute, -1)); } else { for (int j = 0; j < attribute.getNumDataElems(); j++) { rowList.add(new MDAttributeRow(attribute, j)); } } } for (int i = 0; i < rootElement.getNumElements(); i++) { MetadataElement element = rootElement.getElementAt(i); rowList.add(new MDElementRow(element)); } return rowList; }
private void writeMetadataElement(NFileWriteable ncFile, MetadataElement element, NVariable ncVariable, String prefix) throws IOException { for (int i = 0; i < element.getNumAttributes(); i++) { MetadataAttribute attribute = element.getAttributeAt(i); writeMetadataAttribute(ncFile, attribute, ncVariable, prefix); } for (int i = 0; i < element.getNumElements(); i++) { MetadataElement subElement = element.getElementAt(i); final String subElementName = subElement.getName(); if (!isGlobalAttributesElement(subElementName)) { final String name; if (prefix.isEmpty()) { name = subElementName; } else { name = prefix + SPLITTER + subElementName; } writeMetadataElement(ncFile, subElement, ncVariable, name); } } }
/** * Tests the functionality for getPropertyValue() */ public void testGetAttribute() { MetadataElement annot = new MetadataElement("yepp"); MetadataAttribute att; // a new object should not return anything on this request try { att = annot.getAttributeAt(0); fail("there are no elements in the list"); } catch (IndexOutOfBoundsException e) { } att = new MetadataAttribute("GuiTest_DialogAndModalDialog", ProductData.createInstance(ProductData.TYPE_INT32), false); annot.addAttribute(att); assertEquals(att, annot.getAttributeAt(0)); }
/** * Gets an estimated, raw storage size in bytes of this product node. * * @param subsetDef if not <code>null</code> the subset may limit the size returned * * @return the size in bytes. */ @Override public long getRawStorageSize(ProductSubsetDef subsetDef) { if (subsetDef != null && !subsetDef.containsNodeName(getName())) { return 0L; } long size = 0; for (int i = 0; i < getNumElements(); i++) { size += getElementAt(i).getRawStorageSize(subsetDef); } for (int i = 0; i < getNumAttributes(); i++) { size += getAttributeAt(i).getRawStorageSize(subsetDef); } return size; }
/** * Accepts the given visitor. This method implements the well known 'Visitor' design pattern of the gang-of-four. * The visitor pattern allows to define new operations on the product data model without the need to add more code * to it. The new operation is implemented by the visitor. * <p/> * <p>The method first visits (calls <code>acceptVisitor</code> for) all elements contained in this element and then * visits all attributes. Finally the method calls <code>visitor.visit(this)</code>. * * @param visitor the visitor */ @Override public void acceptVisitor(ProductVisitor visitor) { Guardian.assertNotNull("visitor", visitor); for (int i = 0; i < getNumElements(); i++) { getElementAt(i).acceptVisitor(visitor); } for (int i = 0; i < getNumAttributes(); i++) { getAttributeAt(i).acceptVisitor(visitor); } visitor.visit(this); }
private void writeMetadataElement(int locationID, MetadataElement element) throws IOException { int groupID = createH5G(locationID, element.getName()); try { for (int i = 0; i < element.getNumAttributes(); i++) { MetadataAttribute attribute = element.getAttributeAt(i); writeMetadataAttribute(groupID, attribute); } for (int i = 0; i < element.getNumElements(); i++) { MetadataElement subElement = element.getElementAt(i); writeMetadataElement(groupID, subElement); } } catch (IOException e) { throw e; } finally { closeH5G(groupID); } }
@Test public void testProductName() throws Exception { String filePath = GPFFacadeTest.class.getResource("test-product.dim").toURI().getPath(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("file", new File(filePath)); Product p1 = GPF.createProduct("Read", parameters); Product p2 = GPF.createProduct("Foo", GPF.NO_PARAMS, new Product[]{p1}); MetadataElement metadataElement = p2.getMetadataRoot().getElement("Processing_Graph"); MetadataElement sourceElement = null; for (MetadataElement element : metadataElement.getElements()) { if (element.getAttribute("operator").getData().getElemString().equals("Foo")) { sourceElement = element.getElement("sources"); break; } } assertNotNull(sourceElement); assertEquals(1, sourceElement.getNumAttributes()); assertEquals("sourceProduct", sourceElement.getAttributeAt(0).getName()); assertTrue(sourceElement.getAttributeAt(0).getData().getElemString().endsWith("test-product.dim")); }
@Test public void testMultiProductsNames() throws Exception { String filePath = GPFFacadeTest.class.getResource("test-product.dim").toURI().getPath(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("file", new File(filePath)); Product p1 = GPF.createProduct("Read", parameters); Product p2 = GPF.createProduct("Foo", GPF.NO_PARAMS, new Product[]{p1}); Product p3 = GPF.createProduct("Foos", GPF.NO_PARAMS, new Product[]{p1, p2}); MetadataElement metadataElement = p3.getMetadataRoot().getElement("Processing_Graph"); MetadataElement sourceElement = null; for (MetadataElement element : metadataElement.getElements()) { if (element.getAttribute("operator").getData().getElemString().equals("Foos")) { sourceElement = element.getElement("sources"); break; } } assertNotNull(sourceElement); assertEquals(2, sourceElement.getNumAttributes()); assertEquals("sourceProduct.1", sourceElement.getAttributeAt(0).getName()); assertEquals("sourceProduct.2", sourceElement.getAttributeAt(1).getName()); }
/** * Tests the functionality for addAttribute */ public void testAddAttribute() { MetadataElement annot = new MetadataElement("test_me"); MetadataAttribute att; // allow null argument try { annot.addAttribute(null); } catch (IllegalArgumentException e) { fail("IllegalArgumentException null argument is allowed"); } // add an attribute att = new MetadataAttribute("Test1", ProductData.createInstance(ProductData.TYPE_INT32), false); annot.addAttribute(att); assertEquals(1, annot.getNumAttributes()); assertEquals(att, annot.getAttributeAt(0)); }
final MetadataAttribute attrib = elem.getAttributeAt(0); assertNotNull(attrib); assertEquals("counter", attrib.getName()); assertSame(attrib, elem.getAttributeAt(0)); assertEquals("counter", attrib.getName()); assertEquals(-3, attrib.getData().getElemInt());