콜렉션 분석기 등록

XCollectionResolver 인터페이스의 구현을 XDynamicContext에 등록할 수 있습니다.

프로시저

동적 컨텍스트에서 콜렉션 분석기 등록

XDynamicContext에 등록된 XCollectionResolver 구현은 실행 시간에 fn:collection 메소드에 대한 호출에서 제공된 URI와 연관된 노드의 콜렉션을 검색하는 데 사용됩니다. 콜렉션 분석기가 XDynamicContext에 등록되지 않은 경우 fn:collection을 호출하면 복구 가능한 오류가 발생하고 콜렉션에 대한 빈 시퀀스가 사용됩니다.

콜렉션 분석기 및 fn:collection 함수가 문서 URI를 분석함을 의미하지는 않습니다. 소스 분석기 및 fn:doc 함수는 이 목적으로 사용해야 합니다.

다음은 콜렉션 분석기를 사용하는 기본 예제입니다.
XFactory factory = XFactory.newInstance();

// Prepare the XPath expression
XPathExecutable executable = factory.prepareXPath("count(collection('typeA-typeB'))"
           
// Register the collection resolver with the dynamic context
XCollectionResolver collectionResolver = new ACollectionResolver(factory);
XDynamicContext dynamicContext = factory.newDynamicContext();
dynamicContext.setCollectionResolver(collectionResolver);

// Execute the XPath expression
XSequenceCursor cursor = executable.execute(dynamicContext);
다음은 XCollectionResolver 구현의 기본 예제입니다.
public class ACollectionResolver implements XCollectionResolver {
  
    private XFactory m_factory;
   
    public ACollectionResolver(XFactory factory) {
        m_factory = factory;
    }
   
    public XSequenceCursor getCollection(String uri, String base) {
       
        // Get the default collection
        if (uri.equals("")) {
            return getCollection("default", base);
        }
       
        // Get the requested collection
        ArrayList<XItemView> list = new ArrayList<XItemView>();
        StringTokenizer tokenizer = new StringTokenizer(uri, "-");
          XSequenceCursor cursor = null;
          while (tokenizer.hasMoreTokens()) {
              String token = tokenizer.nextToken();
              XSequenceCursor temp = getNodes(new StreamSource("collections.xml"), "/doc/" + token);
              if (cursor == null) {
                  cursor = temp;
                      } else {
                  cursor = cursor.append(temp);
              }
          }
        return cursor;
    }
   
     private XSequenceCursor getNodes(Source source, String expression) {
         XPathExecutable executable = m_factory.prepareXPath(expression);
         XSequenceCursor cursor = executable.execute(source);
         return cursor;
     }
   
}

주제 유형을 표시하는 아이콘 태스크 주제



시간소인 아이콘 마지막 업데이트 날짜: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=txml_resolvers_collection
파일 이름:txml_resolvers_collection.html