Skip to Content.
Sympa Menu

perfsonar-dev - Re: Datum Class

Subject: perfsonar development work

List archive

Re: Datum Class


Chronological Thread 
  • From: Loukik Kudarimoti <>
  • To: "Ivan K. Koga" <>
  • Cc: Jason Zurawski <>,
  • Subject: Re: Datum Class
  • Date: Mon, 14 Aug 2006 15:52:19 +0100

Hi Jason,

Can you please take a look at this class that Ivan has written for AMP MA and see if it can be included in the ggf package? I am not all too familiar with the ggf classes and will take a while for me to help him.

I have asked Ivan to provide example instances of requests and replies that he wants to make use of. This should help us in deciding the best way forward for this service.

thanks,
Loukik.

Ivan K. Koga wrote:
Hi Loukik,

See attached the Datum class that I modified for MA-AMP.
I donĀ“t know if I did it correctly... So, I want to know what I did wrong and how to correct it.


Regards,
Ivan Koga
------------------------------------------------------------------------

/**
* This describes the datum format of a amp delay measurement.
*
* @author Ivan Koji Koga
* @version $Id: Datum.java 143 2006-08-02 16:18:29 +3 $ * @see org.ggf.ns.nmwg.base.v2_0.Element
* @see org.ggf.ns.nmwg.base.v2_0.Datum * @see org.ggf.ns.nmwg.time.v2_0.Time * @see org.w3c.dom.Document
* @see org.w3c.dom.Element
*/
package org.ggf.ns.nmwg.tools.maamp;

import org.xml.sax.ContentHandler;
import org.xml.sax.helpers.AttributesImpl;
import org.ggf.ns.nmwg.base.v2_0.Element;
import org.ggf.ns.nmwg.time.v2_0.Time;
import org.xml.sax.helpers.NamespaceSupport;

public class Datum extends org.ggf.ns.nmwg.base.v2_0.Datum {


/**
* attribute for delay value
*/
protected String delayvalue;

/**
* The constructor initializes the variables and * sets xml element information (when applicable).
*/
public Datum() { delayvalue="";
localName = "datum";
uri = "http://ggf.org/ns/nmwg/tools/maamp";;
qName = "maamp:datum";
prefix = "maamp";
fileName = "org/ggf/ns/nmwg/tools/maamp/Datum.java";
}


/**
* Returns the value of the sDate attribute.
* @return
*/
public String getDelayValue() {
return delayvalue;
}
/**
* Sets the sDate attribute
* @param date
*/
public void setDelayValue(String ndelayvalue) {
delayvalue = ndelayvalue;
}
/**
* Sets attributes, it is important to note that we
* access the underlying NMWG Datum information from the
* base.
*/
public boolean addAttr(String attr, String value, NamespaceSupport
nss) {
/* if(attr.equals("value")) {
setValue(value);
} else if(attr.equals("valueUnits")) {
setValueUnits(value);
}
else if(attr.equals("numBytes")) {
setNumBytes(value);
} else if(attr.equals("numBytesUnits")) {
setNumBytesUnits(value);
}
else if(attr.equals("timeType")) {
setTimeType(value);
}
else if(attr.equals("timeValue")) {
setTimeValue(value);
}
else */
if(attr.equals("delayvalue")) {
setDelayValue(value);
} else if(attr.indexOf("xmlns") >= 0) {
if(attr.split(":").length == 1) {
if(nss.getURI("") == null) {
nss.declarePrefix("", value);
}
if((prefix.equals("")) &&
!(value.equals(uri))) {
uri = value;
}
}
else {
if(nss.getURI(attr.split(":")[1]) == null) {
nss.declarePrefix(attr.split(":")[1],
value);
}
if((prefix.equals(attr.split(":")[1])) &&
!(value.equals(uri))) {
uri = value;
}
}
}
else {
System.err.println("Error: " + getFileName() + " addAttr(String,
String, NamespaceSupport) unrecognized attribute pair: " + attr + " - " + value);
return false;
}
return true;
}

/**
* The only allowable child for a datum element is the
* time.
*/
public boolean addChild(Element newChild) {
if(newChild.getLocalName().equals("time")) {
setTime((Time)newChild);
}
else {
System.err.println("Error: " + getFileName() + "
addChild(Element) unrecognized child: " + newChild);
return false;
}
return true;
}

/**
* Converts the contents of this object into an xml tag.
*/
public ContentHandler toXML(ContentHandler handler, NamespaceSupport
nss) throws Exception {
try {
handler.startElement(getUri(), getLocalName(),
getQName(), getAttributes(nss));
handler = getChildren(handler, nss);
handler.endElement(getUri(), getLocalName(),
getQName());

if(getCompleted()) {
nss.popContext();
unSetCompleted();
}
}
catch(Exception e) {
System.err.println("Error: " + getFileName() + "
toXML(ContentHandler, NamespaceSupport) XML formulation error.");
}
return handler;
}

/**
* Converts items into attributes for an xml tag.
*/
public AttributesImpl getAttributes(NamespaceSupport nss) {
AttributesImpl atts = new AttributesImpl();

/*if(!(getValue().equals(""))) {
atts.addAttribute(getUri(), "value", "value",
"CDATA", getValue());
} if(!(getValueUnits().equals(""))) {
atts.addAttribute(getUri(), "valueUnits", "valueUnits",
"CDATA", getValueUnits());
}
if(!(getNumBytes().equals(""))) {
atts.addAttribute(getUri(), "numBytes", "numBytes",
"CDATA", getNumBytes());
} if(!(getNumBytesUnits().equals(""))) {
atts.addAttribute(getUri(), "numBytesUnits", "numBytesUnits",
"CDATA", getNumBytesUnits());
} if(!(getTimeType().equals(""))) {
atts.addAttribute(getUri(), "timeType", "timeType",
"CDATA", getTimeType());
} if(!(getTimeValue().equals(""))) {
atts.addAttribute(getUri(), "timeValue", "timeValue",
"CDATA", getTimeValue());
}
if(!(getSeqNum().equals(""))) {
atts.addAttribute(getUri(), "seqNum", "seqNum",
"CDATA", getSeqNum());
}
if(!(getTTL().equals(""))) {
atts.addAttribute(getUri(), "ttl", "ttl", "CDATA",
getTTL());
}*/

if(!(getDelayValue().equals(""))) {
atts.addAttribute(getUri(), "delayvalue", "delayvalue",
"CDATA", getDelayValue());
}
if(nss.getURI(getPrefix()) == null) {
nss.pushContext();
if(getPrefix().equals("")) {
atts.addAttribute(getUri(), "xmlns", "xmlns",
"CDATA", getUri());
}
else {
atts.addAttribute(getUri(), "xmlns:" + getPrefix(),
"xmlns:" + getPrefix(), "CDATA", getUri());
}
nss.declarePrefix(getPrefix(), getUri());

setCompleted();
}

return atts;
}

/**
* Chases children references down to print out all related xml tags.
*/
public ContentHandler getChildren(ContentHandler handler,
NamespaceSupport nss) throws Exception {
if(getTime() != null) {
handler = getTime().toXML(handler, nss);
}
return handler;
}

/** * Given a DOM element (a parent), construct
* the children elements.
*/
public void getDOM(org.w3c.dom.Element parent) {
org.w3c.dom.Document doc = parent.getOwnerDocument();
org.w3c.dom.Element datum = doc.createElement(getLocalName());
datum = doc.createElementNS(getUri(), getQName()); parent.appendChild(datum);
/* if(!(getValue().equals(""))) {
datum.setAttribute("value", getValue());
} if(!(getValueUnits().equals(""))) {
datum.setAttribute("valueUnits", getValueUnits());
} if(!(getTimeType().equals(""))) {
datum.setAttribute("timeType", getTimeType());
} if(!(getTimeValue().equals(""))) {
datum.setAttribute("timeValue", getTimeValue());
}
if(!(getNumBytes().equals(""))) {
datum.setAttribute("numBytes", getNumBytes());
} if(!(getNumBytesUnits().equals(""))) {
datum.setAttribute("numBytesUnits",
getNumBytesUnits());
}
if(!(getSeqNum().equals(""))) {
datum.setAttribute("seqNum", getSeqNum());
}
if(!(getTTL().equals(""))) {
datum.setAttribute("ttl", getTTL());
}*/
if(!(getDelayValue().equals(""))) {
datum.setAttribute("delayvalue", getDelayValue());
}

if(getTime() != null) {
getTime().getDOM(datum);
}
}

/**
* Called when the object is placed in
* an output statement.
*/
public String toString() {
return getFileName() + ": ---> " + getValue() + /*" seqNum:" + getSeqNum() + " numBytes:" + getNumBytes() + "
numBytesUnits:" + getNumBytesUnits() + " ttl:" + getTTL() + " valueUnits:" + getValueUnits()+ */ "delayvalue" + getDelayValue() +
" timeType:" + getTimeType() + " timeValue:" + getTimeValue() + getTime();
}
}





Archive powered by MHonArc 2.6.16.

Top of Page