01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.components.validation.impl;
18:
19: import org.apache.avalon.framework.activity.Disposable;
20: import org.apache.avalon.framework.activity.Initializable;
21: import org.apache.avalon.framework.logger.LogEnabled;
22: import org.apache.avalon.framework.logger.Logger;
23: import org.apache.avalon.framework.service.ServiceException;
24: import org.apache.avalon.framework.service.ServiceManager;
25: import org.apache.avalon.framework.service.Serviceable;
26: import org.apache.cocoon.components.validation.SchemaParser;
27: import org.apache.excalibur.source.SourceResolver;
28: import org.apache.excalibur.xml.EntityResolver;
29:
30: /**
31: * <p>A {@link SchemaParser} caching {@link Schema} instance for multiple use.</p>
32: *
33: * <p>A {@link Schema} will be cached until its {@link SourceValidity} expires.</p>
34: *
35: */
36: public abstract class AbstractSchemaParser implements LogEnabled,
37: Serviceable, Initializable, Disposable, SchemaParser {
38:
39: /** <p>The {@link ServiceManager} configured for this instance.</p> */
40: protected ServiceManager serviceManager = null;
41: /** <p>The {@link SourceResolver} to resolve URIs into {@link Source}s.</p> */
42: protected SourceResolver sourceResolver = null;
43: /** <p>The {@link EntityResolver} resolving against catalogs of public IDs.</p> */
44: protected EntityResolver entityResolver = null;
45: /** <p>The {@link Logger} configured for this instance.</p> */
46: protected Logger logger = null;
47:
48: /**
49: * <p>Create a new {@link AbstractSchemaParser} instance.</p>
50: */
51: public AbstractSchemaParser() {
52: super ();
53: }
54:
55: /**
56: * <p>Enable logging.</p>
57: */
58: public void enableLogging(Logger logger) {
59: this .logger = logger;
60: }
61:
62: /**
63: * <p>Contextualize this component specifying a {@link ServiceManager} instance.</p>
64: */
65: public void service(ServiceManager manager) throws ServiceException {
66: this .serviceManager = manager;
67: }
68:
69: /**
70: * <p>Initialize this component instance.</p>
71: *
72: * <p>A this point component resolution will happen.</p>
73: */
74: public void initialize() throws Exception {
75: this .entityResolver = (EntityResolver) this .serviceManager
76: .lookup(EntityResolver.ROLE);
77: this .sourceResolver = (SourceResolver) this .serviceManager
78: .lookup(SourceResolver.ROLE);
79: }
80:
81: /**
82: * <p>Dispose this component instance.</p>
83: */
84: public void dispose() {
85: if (this.entityResolver != null)
86: this.serviceManager.release(this.entityResolver);
87: if (this.sourceResolver != null)
88: this.serviceManager.release(this.sourceResolver);
89: }
90: }
|