KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > validation > jaxp > JaxpResolver


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.validation.jaxp;
17
18 import org.apache.cocoon.components.validation.impl.ValidationResolver;
19 import org.apache.commons.lang.exception.NestableRuntimeException;
20 import org.apache.excalibur.source.SourceResolver;
21 import org.w3c.dom.DOMError JavaDoc;
22 import org.w3c.dom.ls.LSException JavaDoc;
23 import org.w3c.dom.ls.LSInput JavaDoc;
24 import org.w3c.dom.ls.LSResourceResolver JavaDoc;
25 import org.xml.sax.EntityResolver JavaDoc;
26 import org.xml.sax.InputSource JavaDoc;
27
28 /**
29  * <p>An implementation of the {@link LSResourceResolver} interface based on the
30  * generic {@link ValidationResolver} to supply to JAXP schema factories.</p>
31  *
32  * @author <a HREF="mailto:pier@betaversion.org">Pier Fumagalli</a>
33  */

34 public class JaxpResolver extends ValidationResolver
35 implements LSResourceResolver JavaDoc {
36
37     /**
38      * <p>Create a new {@link JaxpResolver} instance.</p>
39      */

40     public JaxpResolver(SourceResolver sourceResolver,
41                         EntityResolver JavaDoc entityResolver) {
42         super(sourceResolver, entityResolver);
43     }
44
45     /**
46      * <p>Resolve a resource into a {@link LSInput} from the provided location
47      * information.</p>
48      *
49      * <p>This method will obtain a {@link InputSource} instance invoking the
50      * {@link ValidationResolver#resolveEntity(String, String, String)} method
51      * return it wrapped in a {@link JaxpInput} instance.</p>
52      *
53      * @param type the type of the resource being resolved.
54      * @param namespace the namespace of the resource being resolved.
55      * @param systemId the system identifier of the resource being resolved.
56      * @param publicId the public identifier of the resource being resolved.
57      * @param base the base uri against wich relative resolution should happen.
58      * @return a <b>non null</b> {@link LSInput} instance.
59      * @throws LSException wrapping another {@link Exception}.
60      */

61     public LSInput JavaDoc resolveResource(String JavaDoc type, String JavaDoc namespace, String JavaDoc systemId,
62                                    String JavaDoc publicId, String JavaDoc base)
63     throws LSException JavaDoc {
64         try {
65             final InputSource JavaDoc source = this.resolveEntity(base, publicId, systemId);
66             return new JaxpInput(source);
67         } catch (Exception JavaDoc exception) {
68             String JavaDoc message = "Exception resolving resource " + systemId;
69             Throwable JavaDoc err = new LSException JavaDoc(DOMError.SEVERITY_FATAL_ERROR, message);
70             throw new NestableRuntimeException(message, err);
71         }
72     }
73 }
74
Popular Tags