package com.nokia.fwcontroller.firewalloperator.cisco;
import java.io.FileInputStream;
import java.util.Date;
import noNamespace.DataFile;
import noNamespace.DataFileDownLoadDocument;
import noNamespace.Item;
import noNamespace.ItemList;
import noNamespace.Record;
import noNamespace.RecordList;
public class DataFileTest {
public void testcreate(){
DataFile dataFile= DataFile.Factory.newInstance();
dataFile.setOperation("queryresult");
dataFile.setOperationTarget("SOCKETSP");
dataFile.setTakeEffectTime((new Date()).toString());
ItemList itemList= dataFile.addNewItemList();
Item item1 = itemList.addNewItem();
item1.setIsKey("true");
item1.setItemName("SP名称");
item1.setItemType("String");
Item item2 = itemList.addNewItem();
item2.setIsKey("false");
item2.setItemName("IP地址");
item2.setItemType("String");
Item item3 = itemList.addNewItem();
item3.setIsKey("false");
item3.setItemName("端口号");
item3.setItemType("String");
Item item4 = itemList.addNewItem();
item4.setIsKey("false");
item4.setItemName("应用名称");
item4.setItemType("String");
RecordList recordList = dataFile.addNewRecordList();
for(int i=1;i<4;i++){
Record record = recordList.addNewRecord();
record.addItemValue("SP Name" +i);
record.addItemValue("172.28.46." + i);
record.addItemValue(String.valueOf(5000+i));
record.addItemValue("comment" + i);
}
System.out.println(dataFile.toString());
}
public void testFromFile()throws Exception{
DataFileDownLoadDocument doc=DataFileDownLoadDocument.Factory.parse(new FileInputStream(".\\socketsp.xml"));
DataFile [] data=doc.getDataFileDownLoad().getDataFileArray();
for(int i=0;i<data.length;i++){
System.out.println(data[i].getOperation());
System.out.println(data[i].getOperationTarget());
RecordList rl=data[i].getRecordList();
Record [] rr=rl.getRecordArray();
for(int j=0;j<rr.length;j++){
String [] values=rr[j].getItemValueArray();
for(int k=0;k<values.length;k++){
System.out.println(values[k]);
}
System.out.println("-------------------");
}
}
}
public static void main(String args[]) throws Exception
{
DataFileTest t = new DataFileTest();
t.testcreate();
t.testFromFile();
}
}
XML Beans 使用和测试
最新推荐文章于 2015-12-15 16:11:32 发布