文件包括到Aspire的主文件aspire.properties的例子:
application.includeFiles=aspire:\\samples\\hello-world
\\properties\\hello-world.properties,\
aspire:\\samples\\ihds-test\\ihds-test.properties,\
aspire:\\samples\\xml-reader\\xml-reader.properties
为了完整性.我用了双斜线在处理当中.
调用你的定义并得到一个ihds.
现在我们已经又了层次数据集的定义,我们如何从Java里调用它呢?认真阅读第一篇文章对你将会有很大帮助的,下面是相应的Java代码:
Hashtable args = new Hashtable();
args.put("key1".toLowerCase(), "value1");
IFactory factory = AppObjects.getFactory();
ihds hds = (ihds)factory.getObject("ihdsTest",args);
// use ihds
Aspire和Tomcat使用层次数据集(5)
时间:2010-12-10
Aspire有一个IFactory接口描述的factory服务.你可以通过这个factory接口调用Java类ihdsTest,并把所有的参数以哈希表的格式传入.小写的字符串对于一个关系型的适配器的下载流是很必要的.
开发ihds API的程序源码:
下面的代码将遍历ihds树,并把它输出到屏幕:
import com.ai.htmlgen.*;
import com.ai.common.TransformException;
import Java.io.*;
import com.ai.data.*;
// above code removed for clarity
public static void staticTransform(ihds data, PrintWriter out)
throws TransformException
{
try
{
writeALoop("MainData",data,out,"");
}
catch(DataException x)
{
throw new TransformException(
"Error: DebugTextTransform: Data Exception",x);
}
}
/**********************************************************
* A recursive function to write out a loop worth of ihds
**********************************************************/
private static void writeALoop(
String loopname, ihds data, PrintWriter out, String is)
throws DataException
{
println(out,is, ">> Writing data for loop:" + loopname);
// write metadata
IMetaData m = data.getMetaData();
IIterator columns = m.getIterator();
StringBuffer colBuffer = new StringBuffer();
for(columns.moveToFirst();!columns.isAtTheEnd();columns.moveToNext())
{
String columnName = (String)columns.getCurrentElement();
colBuffer.append(columnName).append("|");
}
println(out,is,colBuffer.toString());
//write individual rows
for(data.moveToFirst();!data.isAtTheEnd();data.moveToNext())
{
StringBuffer rowBuffer = new StringBuffer(); for(columns.moveToFirst();!columns.isAtTheEnd();columns.moveToNext())
{
String columnName = (String)columns.getCurrentElement();
rowBuffer.append(data.getvalue(columnName));
rowBuffer.append("|");
}
println(out,is,rowBuffer.toString());
// recursive call to print children
IIterator children = data.getChildNames(); for(children.moveToFirst();!children.isAtTheEnd();children.moveToNext())
{
// for each child
String childName = (String)children.getCurrentElement();
ihds child = data.getChild(childName);
writeALoop(childName,child,out,is + "\t");
}
}
println(out,is,">> Writing data for loop:" + loopname + " is complete");
}
private static void println(PrintWriter out, String indentationString,
String line)
{
out.print(indentationString);
out.p
|