CompleteProduct cp = new CompleteProduct();
Product product = cp.getProduct();
ProductType productType = product.getProductType();
Metadata metadata = cp.getMetadata();
List<Reference> references = product.getProductReferences();
Reference rootReference = product.getRootRef();
NodeList children = doc.getChildNodes();
for (int j=0; j<children.getLength(); j++) {
Node child = children.item(j);
Element element = (Element)child;
String name = element.getAttribute("name");
/**
*<arr name="ScanPointingSource">
* <str>G073.65+0.19</str>
* <str>J2015+3410</str>
* ..........
*/
if (child.getNodeName().equals("arr")) {
NodeList values = element.getChildNodes();
List<String> vals = new ArrayList<String>();
for (int k=0; k<values.getLength(); k++) {
String value = ((Element)values.item(k)).getTextContent();
vals.add(value);
}
// CAS.reference.... fields
if (name.startsWith(Parameters.NS)) {
for (int k=0; k<values.getLength(); k++) {
// create this reference
if (references.size()<=k) references.add(new Reference());
if (name.equals(Parameters.REFERENCE_ORIGINAL)) {
references.get(k).setOrigReference(vals.get(k));
} else if (name.equals(Parameters.REFERENCE_DATASTORE)) {
references.get(k).setDataStoreReference(vals.get(k));
} else if (name.equals(Parameters.REFERENCE_FILESIZE)) {
references.get(k).setFileSize(Long.parseLong(vals.get(k)));
} else if (name.equals(Parameters.REFERENCE_MIMETYPE)) {
references.get(k).setMimeType(vals.get(k));
}
}
// all other multi-valued fields
} else {
this.deserializeMultiValueField(name, vals, metadata);
}
/**
* <str name="id">6684d79d-a011-4bc0-b3b3-4f11817091c8</str>
* <str name="CAS.ProductId">6684d79d-a011-4bc0-b3b3-4f11817091c8</str>
* <str name="CAS.ProductName">tns_br145x4_20</str>
* <str name="FileLocation">/usr/local/ska-dc/data/archive</str>
* ...........
*/
} else {
String value = element.getTextContent();
// core CAS fields
if (name.startsWith(Parameters.NS)) {
if (name.equals(Parameters.PRODUCT_ID)) {
product.setProductId(value);
} else if (name.equals(Parameters.PRODUCT_NAME)) {
product.setProductName(value);
} else if (name.equals(Parameters.PRODUCT_STRUCTURE)) {
product.setProductStructure(value);
} else if (name.equals(Parameters.PRODUCT_TRANSFER_STATUS)) {
product.setTransferStatus(value);
} else if (name.equals(Parameters.PRODUCT_TYPE_NAME)) {
productType.setName(value);
} else if (name.equals(Parameters.PRODUCT_TYPE_ID)) {
productType.setProductTypeId(value);
} else if (name.equals(Parameters.PRODUCT_RECEIVED_TIME)) {
// ignore ?
// CAS root reference
} else if (name.startsWith(Parameters.NS+Parameters.ROOT)) {
if (rootReference==null) rootReference = new Reference();
if (name.equals(Parameters.ROOT_REFERENCE_ORIGINAL)) {
rootReference.setOrigReference(value);
} else if (name.equals(Parameters.ROOT_REFERENCE_DATASTORE)) {
rootReference.setDataStoreReference(value);
} else if (name.equals(Parameters.ROOT_REFERENCE_FILESIZE)) {
rootReference.setFileSize(Long.parseLong(value));
} else if (name.equals(Parameters.ROOT_REFERENCE_MIMETYPE)) {
rootReference.setMimeType(value);
}
}
// non core single-valued fields