ue pairs -->
<key1>val1</key1>
<key2>val2</key2>
<!-- a set of named loops -->
<loop name="loopname1">
</loop>
<!-- a set of named loops -->
<loop name="loopname2">
</loop>
</row>
<row>
</row>
</loop>
这里唯一一个不成对的结构就是row结构了.一个row结构可以是一些key/value对的集合.这里的row不仅包含了一些key/value对,并且还包括了多个独立的loop结构的递归集.这种扩展可以生成一定深度的树结构.
Aspire和Tomcat使用层次数据集(2)
时间:2010-12-10
三.Java当中的层次数据的结构
当我把层次数据集以XML的形式展示的时候,你可能会把层次数据集理解为字面上的XML,因此你会先到DOM,接着你甚至会想这样岂不是会占用很大的JVM内存.不必慌张.层次数据集有自己的的Java API二不需要DOM来描述.下面就是一个层次数据集的Java API代码:
package com.ai.htmlgen;
import com.ai.data.*;
/**
* Represents a Hierarchical Data Set.
* An hds is a collection of rows.
* You can step through the rows using ILoopForwardIterator
* You can find out about the columns via IMetaData.
* An hds is also a collection loops originated using the current row.
*/
public interface ihds extends ILoopForwardIterator
{
/**
* Returns the parent if available
* Returns null if there is no parent
*/
public ihds getParent() throws DataException;
/**
* For the current row return a set of
* child loop names. ILoopForwardIteraor determines
* what the current row is. *
* @see ILoopForwardIterator
*/
public IIterator getChildNames() throws DataException;
/**
* Given a child name return the child Java object
* represented by ihds again
*/
public ihds getChild(String childName) throws DataException;
/**
* returns a column that is similar to SUM, AVG etc of a
* set of rows that are children to this row.
*/
public String getAggregatevalue(String keyname) throws DataException;
/**
* Returns the column names of this loop or table.
* @see IMetaData
*/
public IMetaData getMetaData() throws DataException;
/**
* Releases any resources that may be held by this loop of data
* or table.
*/
public void close() throws DataException;
}
Aspire和Tomcat使用层次数据集(3)
时间:2010-12-10
简单的说来,上面的ihds接口就是一个层次数据集的接口.这个API使你可以递归的访问你的loop结构.这个接口里有一些遍历loop结构是需要的一些选项.它也能假定是前序遍历或者随机遍历.现在我来介绍的是这个API用到的两个附加的接口: ILoopForwardIterator和IMetaData:
如何在IHDS里遍历行记录的接口: ILoopForwardIterator
package com.ai.htmlgen;
import com.ai.data.*;
public interface ILoopForwardIterator
{
/**
* getvalue from the current row matching the key
*/
public String getvalue(final String key);
public void moveToFirst() throws DataException;
public void moveToNext() throws DataException;
public boolean isAtTheEnd() throws DataException;
}
IMetaData: 用于读取列名的接口
package com.ai.data;
public interface IMetaData
{
public IIterator getIterator();
public int getColumnCount();
public int getIndex(final String attributeName)
throws FieldNameNotFoundException;
}
怎 |