2010年10月18日 星期一

Parsing jpos.xml

原來JPOS內提供的source code已經有現成的library,我居然用jdom來土法煉鋼。

留個記錄:

SimpleEntryRegistry reg = new SimpleEntryRegistry(new SimpleXmlRegPopulator());
reg.load();
Enumeration entriesEnum = reg.getEntries();

int count = 0;
while (entriesEnum.hasMoreElements())
{
JposEntry entry = (JposEntry) entriesEnum.nextElement();

if (entry.getLogicalName().equals(sDeviceName))
{
int ii = entry.getPropertyCount();

Iterator ppp = entry.getProps();
while (ppp.hasNext())
{
JposEntry.Prop prop = (JposEntry.Prop) ppp.next();
propName = prop.getName();
propValue = prop.getValueAsString();

if (propName.equals("Debug"))
{
DEBUG = (propValue.equals("1") ? true : false);
String sDebug = (propValue.equals("1") ? "true" :
"false");
//save to system property
System.setProperty("msr.msr.debug", sDebug);
TraceLog.WriteMessage("MSRService.open() " +
sDeviceName, DEBUG);
}
else if (propName.equals("Port"))
{
comid = Integer.parseInt(propValue.substring(3));
sComport = propValue;
TraceLog.WriteMessage("Port Connected: " + sComport,
DEBUG);
}
else if (propName.equals("PhysicalDeviceName"))
{
physicalDeviceName = propValue;
}
else if (propName.equals("DeviceServiceDescription"))
{
deviceServiceDescription = propValue;
}
else if (propName.equals("PhysicalDeviceDescription"))
{
physicalDeviceDescription = propValue;
}
else
{
//do nothing here
}
}
}
count++;
}

沒有留言:

張貼留言