모듈 분석기 사용

XModuleResolver 인터페이스는 구현 가능하며 구현은 기본 XQuery 모듈 분석 동작을 대체하도록 XStaticContext에 등록됩니다. 모듈은 XQuery 모듈 가져오기를 수행할 때마다 분석됩니다.

이 태스크 정보

기본 모듈 분석 동작은 모듈 가져오기에 지정된 각 위치 힌트에 대해 하나의 모듈을 찾는 것입니다. 각 위치 힌트에 대한 기본 분석 동작은 기본 URI가 사용 가능한 경우 정적 컨텍스트에서 기본 URI에 대해 상대 URI를 분석하거나, 기본 URI가 사용 불가능한 경우 현재 작업 디렉토리에 상대적인 파일 경로로 해석하는 것입니다. 절대적 URI는 그대로 사용됩니다. 위치 힌트에 대한 모듈을 찾을 수 없으면 네임스페이스에 대한 모듈을 로드할 수 있는 한, 프로세스는 이를 무시합니다. 로드할 수 없으면 프로세스는 오류 메시지를 생성합니다.

프로시저

XStaticContext 인터페이스에서 setModuleResolver 메소드를 사용하여 모듈 분석기를 등록하십시오.

getModule 메소드는 java.util.List 인터페이스의 인스턴스를 리턴합니다. 위치 힌트에 대한 특정 네임스페이스 및 세트의 모듈 문서가 둘 이상 존재할 수 있기 때문입니다.

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

// Create the static context
XStaticContext staticContext = factory.newStaticContext();

// Create the module resolver and register it with the static context.
staticContext.setModuleResolver(new AModuleResolver(replacementBase));

// Prepare the query.
XQueryExecutable executable = factory.prepareXQuery(new StreamSource(queryFile), staticContext);

// Execute the transformation.
Source source = new StreamSource(inputFile);
Result result = new StreamResult(System.out);
executable.execute(source, result);
다음은 모듈 분석기 구현의 기본 예제입니다.
class AModuleResolver implements XModuleResolver
{
    String _replacementBase;

    public AModuleResolver(String replacementBase)
    {
        _replacementBase=replacementBase;
    }

    // Resolve URI, returning the Source that URI represents.
    // Implements the "rebase:" pseudo-scheme.
    public List<? extends Source> getModule(String namespace, List<String> locations, String baseURI) {
        String rebasePrefix="rebase:";

        List<StreamSource> list = new ArrayList<StreamSource>();
        for (int i = 0; i < locations.size(); i++) {
            String href = locations.get(i);
            String base = baseURI;
            if(href.startsWith(rebasePrefix)) {
                href=href.substring(rebasePrefix.length());
                base=_replacementBase;
            }

            java.net.URI uri;
            StreamSource source=null;
            try {
                // Get base URI object
                uri = new java.net.URI(base);
                // Resolved relative reference against base URI
                URI resolvedURI = uri.resolve(href);
                // Try to read...
                source = new StreamSource(resolvedURI.toString());
            } catch (java.net.URISyntaxException use) {
                throw new RuntimeException(use);
            }

            list.add(source);
        }
        return list;
    }
}

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



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