KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > validation > impl > AbstractSchemaParser


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.impl;
17
18 import org.apache.avalon.framework.activity.Disposable;
19 import org.apache.avalon.framework.activity.Initializable;
20 import org.apache.avalon.framework.logger.LogEnabled;
21 import org.apache.avalon.framework.logger.Logger;
22 import org.apache.avalon.framework.service.ServiceException;
23 import org.apache.avalon.framework.service.ServiceManager;
24 import org.apache.avalon.framework.service.Serviceable;
25 import org.apache.cocoon.components.validation.Schema;
26 import org.apache.cocoon.components.validation.SchemaParser;
27 import org.apache.excalibur.source.Source;
28 import org.apache.excalibur.source.SourceResolver;
29 import org.apache.excalibur.source.SourceValidity;
30 import org.apache.excalibur.xml.EntityResolver;
31
32 /**
33  * <p>A {@link SchemaParser} caching {@link Schema} instance for multiple use.</p>
34  *
35  * <p>A {@link Schema} will be cached until its {@link SourceValidity} expires.</p>
36  *
37  * @author <a HREF="mailto:pier@betaversion.org">Pier Fumagalli</a>
38  */

39 public abstract class AbstractSchemaParser
40 implements LogEnabled, Serviceable, Initializable, Disposable, SchemaParser {
41
42     /** <p>The {@link ServiceManager} configured for this instance.</p> */
43     protected ServiceManager serviceManager = null;
44     /** <p>The {@link SourceResolver} to resolve URIs into {@link Source}s.</p> */
45     protected SourceResolver sourceResolver = null;
46     /** <p>The {@link EntityResolver} resolving against catalogs of public IDs.</p> */
47     protected EntityResolver entityResolver = null;
48     /** <p>The {@link Logger} configured for this instance.</p> */
49     protected Logger logger = null;
50
51     /**
52      * <p>Create a new {@link AbstractSchemaParser} instance.</p>
53      */

54     public AbstractSchemaParser() {
55         super();
56     }
57
58     /**
59      * <p>Enable logging.</p>
60      */

61     public void enableLogging(Logger logger) {
62         this.logger = logger;
63     }
64
65     /**
66      * <p>Contextualize this component specifying a {@link ServiceManager} instance.</p>
67      */

68     public void service(ServiceManager manager)
69     throws ServiceException {
70         this.serviceManager = manager;
71     }
72     
73     /**
74      * <p>Initialize this component instance.</p>
75      *
76      * <p>A this point component resolution will happen.</p>
77      */

78     public void initialize()
79     throws Exception JavaDoc {
80         this.entityResolver = (EntityResolver) this.serviceManager.lookup(EntityResolver.ROLE);
81         this.sourceResolver = (SourceResolver) this.serviceManager.lookup(SourceResolver.ROLE);
82     }
83     
84     /**
85      * <p>Dispose this component instance.</p>
86      */

87     public void dispose() {
88         if (this.entityResolver != null) this.serviceManager.release(this.entityResolver);
89         if (this.sourceResolver != null) this.serviceManager.release(this.sourceResolver);
90     }
91 }
92
Popular Tags