You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by pi...@apache.org on 2005/09/07 01:15:45 UTC
svn commit: r279172 - in
/cocoon/branches/BRANCH_2_1_X/src/blocks/validation: conf/
java/org/apache/cocoon/components/validation/
java/org/apache/cocoon/components/validation/impl/
Author: pier
Date: Tue Sep 6 16:15:33 2005
New Revision: 279172
URL: http://svn.apache.org/viewcvs?rev=279172&view=rev
Log:
Initial implementation of Validation selector
Added:
cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xconf
cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xroles
cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/Validator.java
cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/SchemaParser.java
cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingSchemaParser.java
cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingSchemaParser.java
Added: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xconf
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xconf?rev=279172&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xconf (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xconf Tue Sep 6 16:15:33 2005
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 1999-2004 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<xconf xpath="/cocoon" unless="validator">
+
+ <validator>
+ <schema-parser name="jing" class="org.apache.cocoon.components.validation.impl.JingSchemaParser">
+ <cache-schemas>true</cache-schemas>
+ </schema-parser>
+ </validator>
+
+</xconf>
Added: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xroles
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xroles?rev=279172&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xroles (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xroles Tue Sep 6 16:15:33 2005
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 1999-2004 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<xroles xpath="/role-list" unless="role[@name='org.apache.cocoon.components.validation.Validator']">
+
+ <role name="org.apache.cocoon.components.validation.Validator" shorthand="validator"
+ default-class="org.apache.cocoon.components.validation.impl.DefaultValidator"/>
+
+</xroles>
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/SchemaParser.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/SchemaParser.java?rev=279172&r1=279171&r2=279172&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/SchemaParser.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/SchemaParser.java Tue Sep 6 16:15:33 2005
@@ -17,6 +17,7 @@
import java.io.IOException;
+import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceValidity;
import org.xml.sax.ErrorHandler;
@@ -31,14 +32,15 @@
* provided looking up the {@link SELECTOR} role, and from there determining
* the implementation required.</p>
*
+ * <p>The only requirement imposed by this interface is that the final class
+ * implementing this interface must be {@link ThreadSafe}.</p>
+ *
* @author <a href="mailto:pier@betaversion.org">Pier Fumagalli</a>
*/
-public interface SchemaParser {
-
+public interface SchemaParser extends ThreadSafe {
+
/** <p>Avalon Role name of this component.</p> */
public static final String ROLE = SchemaParser.class.getName();
- /** <p>Role name to use when this component is accessed via a selector.</p> */
- public static final String SELECTOR = ROLE + "Selector";
/**
* <p>Parse the specified URI and return a {@link Schema}.</p>
@@ -60,5 +62,16 @@
*/
public Schema getSchema(String uri)
throws SAXException, IOException;
+
+ /**
+ * <p>Return an array of {@link String}s containing all schema languages
+ * supported by this {@link SchemaParser}.</p>
+ *
+ * <p>All {@link String}s in the array returned by this method should be
+ * valid language names as defined in the {@link Validator} class.</p>
+ *
+ * @return a <b>non-null</b> array of {@link String}s.
+ */
+ public String[] getSupportedLanguages();
}
Added: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/Validator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/Validator.java?rev=279172&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/Validator.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/Validator.java Tue Sep 6 16:15:33 2005
@@ -0,0 +1,50 @@
+/* ========================================================================== *
+ * Copyright (C) 2004-2005 Pier Fumagalli <http://www.betaversion.org/~pier/> *
+ * All rights reserved. *
+ * ========================================================================== *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may *
+ * not use this file except in compliance with the License. You may obtain a *
+ * copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>. *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT *
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the *
+ * License for the specific language governing permissions and limitations *
+ * under the License. *
+ * *
+ * ========================================================================== */
+
+package org.apache.cocoon.components.validation;
+
+import org.apache.avalon.framework.service.ServiceSelector;
+
+/**
+ * <p>The {@link Validator} interface defines a {@link ServiceSelector} selecting
+ * between different {@link SchemaParser}.</p>
+ *
+ * <p>Selection can occur either normally, based on a component name specified in
+ * the configuration files, or on the {@link SchemaParser#getSupportedLanguages()
+ * supported languages} of the configured {@link SchemaParser}s.</p>
+ *
+ * @author <a href="mailto:pier@betaversion.org">Pier Fumagalli</a>
+ */
+public interface Validator extends ServiceSelector {
+
+ /** <p>Role name to use when this component is accessed via a selector.</p> */
+ public static final String ROLE = Validator.class.getName();
+
+ /** <p>The <a href="http://www.relaxng.org/">RELAX NG</a/> language identifer.</p> */
+ public static final String LANGUAGE_RELAX_NG = "http://relaxng.org/ns/structure/0.9";
+ /** <p>The <a href="http://www.xml.gr.jp/relax">RELAX CORE</a/> language identifer.</p> */
+ public static final String LANGUAGE_RELAX_CORE = "http://www.xml.gr.jp/xmlns/relaxCore";
+ /** <p>The <a href="http://www.xml.gr.jp/relax">RELAX NAMESPACE</a/> language identifer.</p> */
+ public static final String LANGUAGE_RELAX_NS = "http://www.xml.gr.jp/xmlns/relaxNamespace";
+ /** <p>The <a href="http://www.thaiopensource.com/trex/">TREX</a/> language identifer.</p> */
+ public static final String LANGUAGE_TREX = "http://www.thaiopensource.com/trex";
+ /** <p>The <a href="http://www.w3.org/XML/Schema">XML SCHEMA</a/> language identifer.</p> */
+ public static final String LANGUAGE_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
+ /** <p>The <a href="http://www.w3.org/TR/REC-xml">XML DTD</a/> language identifer.</p> */
+ public static final String LANGUAGE_XML_DTD = "http://www.w3.org/XML/1998/namespace";
+
+}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingSchemaParser.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingSchemaParser.java?rev=279172&r1=279171&r2=279172&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingSchemaParser.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/CachingSchemaParser.java Tue Sep 6 16:15:33 2005
@@ -19,10 +19,12 @@
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.components.validation.Schema;
import org.apache.cocoon.components.validation.SchemaParser;
import org.apache.excalibur.source.Source;
@@ -40,7 +42,7 @@
* @author <a href="mailto:pier@betaversion.org">Pier Fumagalli</a>
*/
public abstract class CachingSchemaParser
-implements Serviceable, Initializable, Disposable, SchemaParser, ThreadSafe {
+implements Serviceable, Initializable, Disposable, SchemaParser, Configurable {
/** <p>The {@link ServiceManager} configured for this instance.</p> */
protected ServiceManager serviceManager = null;
@@ -48,8 +50,10 @@
protected SourceResolver sourceResolver = null;
/** <p>The {@link EntityResolver} resolving against catalogs of public IDs.</p> */
protected EntityResolver entityResolver = null;
- /** <p>The {@link Store} used for caching {@link Schema}s.</p> */
+ /** <p>The {@link Store} used for caching {@link Schema}s (if enabled).</p> */
protected Store transientStore = null;
+ /** <p>A flag indicating whether schemas can be cached or not.</p> */
+ private boolean enableCache = true;
/**
* <p>Contextualize this component specifying a {@link ServiceManager} instance.</p>
@@ -60,6 +64,20 @@
}
/**
+ * <p>Configure this instance.</p>
+ *
+ * <p>The only configuration sub-element allowed by this instance is
+ * <code><cache-schemas><i>true|false</i></cache-schemas></code>
+ * indicating where parsed schema should be cached. The default value for this
+ * is <code>true</code>.</p>
+ */
+ public void configure(Configuration configuration)
+ throws ConfigurationException {
+ Configuration subconfiguration = configuration.getChild("cache-schemas");
+ this.enableCache = subconfiguration.getValueAsBoolean(true);
+ }
+
+ /**
* <p>Initialize this component instance.</p>
*
* <p>A this point component resolution will happen.</p>
@@ -85,6 +103,8 @@
*/
public final Schema getSchema(String uri)
throws IOException, SAXException {
+
+ /* First of all resolve the source, and use the resolved URI */
Source source = null;
try {
source = this.sourceResolver.resolveURI(uri);
@@ -93,10 +113,12 @@
if (source != null) this.sourceResolver.release(source);
}
+ /* Prepare a key, and try to get the cached copy of the schema */
String key = this.getClass().getName() + ":" + uri;
Schema schema = (Schema) this.transientStore.get(key);
SourceValidity validity = null;
+ /* If the schema was found verify its validity and optionally clear */
if (schema != null) {
validity = schema.getValidity();
if (validity == null) {
@@ -108,6 +130,7 @@
}
}
+ /* If the schema was not cached or was cleared, parse and cache it */
if (schema == null) {
schema = this.parseSchema(uri);
validity = schema.getValidity();
@@ -116,6 +139,7 @@
}
}
+ /* Return the parsed or cached schema */
return schema;
}
Added: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java?rev=279172&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/DefaultValidator.java Tue Sep 6 16:15:33 2005
@@ -0,0 +1,300 @@
+/* ========================================================================== *
+ * Copyright (C) 2004-2005 Pier Fumagalli <http://www.betaversion.org/~pier/> *
+ * All rights reserved. *
+ * ========================================================================== *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may *
+ * not use this file except in compliance with the License. You may obtain a *
+ * copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>. *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT *
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the *
+ * License for the specific language governing permissions and limitations *
+ * under the License. *
+ * *
+ * ========================================================================== */
+
+package org.apache.cocoon.components.validation.impl;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.activity.Startable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.components.validation.SchemaParser;
+import org.apache.cocoon.components.validation.Validator;
+
+/**
+ * <p>The default implementation of the {@link Validator} interface.</p>
+ *
+ * @author <a href="mailto:pier@betaversion.org">Pier Fumagalli</a>
+ */
+public class DefaultValidator implements Validator, LogEnabled,
+Contextualizable, Serviceable, Configurable, Initializable, Disposable {
+
+ /** <p>The default shorthand code to use in subcomponent configurations.</p> */
+ public static final String DEFAULT_SHORTHAND = "schema-parser";
+ /** <p>The default subcomponent {@link Class} instance.</p> */
+ public static final Class DEFAULT_CLASS = SchemaParser.class;
+
+ /** <p>The shorthand code to use in subcomponents configurations.</p> */
+ private final String shorthand;
+ /** <p>The {@link Class} of the subcomponents selected by this instance.</p> */
+ private final Class componentClass;
+ /** <p>The {@link Set} of all instantiated components.</p> */
+ private final Set components;
+ /** <p>A {@link Map} associating names with component instances.</p> */
+ private final Map selections;
+
+ /** <p>The configured {@link Logger} instance.</p> */
+ private Logger logger = null;
+ /** <p>The configured {@link Context} instance.</p> */
+ private Context context = null;
+ /** <p>The configured {@link ServiceManager} instance.</p> */
+ private ServiceManager manager = null;
+ /** <p>The configured {@link Configuration} instance.</p> */
+ private Configuration conf = null;
+
+ /**
+ * <p>Create a new {@link DefaultValidator} instance.</p>
+ */
+ public DefaultValidator() {
+ this(null, null);
+ }
+
+ /**
+ * <p>Create a new {@link DefaultValidator} instance.</p>
+ *
+ * @param shorthand the shorthand code to use in subcomponents configurations.
+ * @param componentClass the {@link Class} of the subcomponents selected by this.
+ */
+ public DefaultValidator(String shorthand, Class componentClass) {
+ this.shorthand = shorthand == null? DEFAULT_SHORTHAND: shorthand;
+ this.componentClass = componentClass == null? DEFAULT_CLASS: componentClass;
+ this.components = Collections.synchronizedSet(new HashSet());
+ this.selections = Collections.synchronizedMap(new HashMap());
+ }
+
+ /**
+ * <p>Enable logging.</p>
+ */
+ public void enableLogging(Logger logger) {
+ this.logger = logger;
+ }
+
+ /**
+ * <p>Contextualize this instance.</p>
+ */
+ public void contextualize(Context context)
+ throws ContextException {
+ this.context = context;
+ }
+
+ /**
+ * <p>Specify the {@link ServiceManager} available to this instance.</p>
+ */
+ public void service(ServiceManager manager)
+ throws ServiceException {
+ this.manager = manager;
+ }
+
+ /**
+ * <p>Configure this instance.</p>
+ */
+ public void configure(Configuration conf)
+ throws ConfigurationException {
+ this.conf = conf;
+ }
+
+ /**
+ * <p>Initialize this instance.</p>
+ *
+ * <p>Required components lookup and sub-components initialization will occur
+ * when this method is called.</p>
+ */
+ public void initialize()
+ throws Exception {
+ if (this.logger == null) throw new IllegalStateException("Null logger");
+ if (this.context == null) throw new IllegalStateException("Null context");
+ if (this.manager == null) throw new IllegalStateException("Null manager");
+ if (this.conf == null) throw new IllegalStateException("Null configuration");
+
+ Configuration configurations[] = this.conf.getChildren(this.shorthand);
+ for (int x = 0; x < configurations.length; x++) try {
+ Configuration configuration = configurations[x];
+ String className = configuration.getAttribute("class");
+ String selectionKey = configuration.getAttribute("name");
+
+ Class clazz;
+ try {
+ clazz = Class.forName(className);
+ } catch (Exception exception) {
+ String message = "Unable to load class " + className;
+ throw new ConfigurationException(message, configuration, exception);
+ }
+
+ if (!clazz.isAssignableFrom(this.componentClass)) {
+ String message = "Class " + className + " does not represent a "
+ + this.componentClass.getName();
+ throw new ConfigurationException(message, configuration);
+ }
+
+ Object component;
+ try {
+ component = clazz.newInstance();
+ } catch (Exception exception) {
+ String message = "Unable to instantiate SchemaParser " + className;
+ throw new ConfigurationException(message, configuration, exception);
+ }
+
+ this.components.add(this.setupComponent(component, configuration));
+ this.selections.put(selectionKey, component);
+ if (component instanceof SchemaParser) {
+ SchemaParser parser = (SchemaParser) component;
+ String languages[] = parser.getSupportedLanguages();
+ if (languages != null) {
+ for (int k = 0; x < languages.length; x++) {
+ if (this.selections.containsKey(languages[x])) continue;
+ this.selections.put(languages[x], component);
+ }
+ }
+ }
+ } catch (Exception exception) {
+ Iterator iterator = this.components.iterator();
+ while (iterator.hasNext()) try {
+ this.decommissionComponent(iterator.next());
+ } catch (Exception nested) {
+ this.logger.fatalError("Error decommissioning component", nested);
+ }
+
+ if (exception instanceof ConfigurationException) {
+ throw exception;
+ } else {
+ Configuration configuration = configurations[x];
+ String message = "Unable to setup SchemaParser declared at ";
+ message += configuration.getLocation();
+ throw new ConfigurationException(message, configuration, exception);
+ }
+ }
+ }
+
+ /**
+ * <p>Select the subcomponent managed by this instance associated wit the
+ * specified key.</p>
+ */
+ public Object select(Object key)
+ throws ServiceException {
+ if (this.isSelectable(key)) return this.selections.get(key);
+ throw new ServiceException((String) key, "Non existing component" + key);
+ }
+
+ /**
+ * <p>Ensure that a subcomponent is selectable for the specified key.</p>
+ */
+ public boolean isSelectable(Object key) {
+ return this.selections.containsKey((String) key);
+ }
+
+ /**
+ * <p>Release a previously selected subcomponent instance.</p>
+ */
+ public void release(Object object) {
+ // Nothing to do over here...
+ }
+
+ /**
+ * <p>Dispose of this instance.</p>
+ *
+ * <p>All sub-components initialized previously will be disposed of when this
+ * method is called.</p>
+ */
+ public void dispose() {
+ Iterator iterator = this.components.iterator();
+ while (iterator.hasNext()) try {
+ this.decommissionComponent(iterator.next());
+ } catch (Exception exception) {
+ this.logger.fatalError("Error decommissioning component", exception);
+ }
+ }
+
+ /**
+ * <p>Manage the instantiation lifecycle of a specified component.</p>
+ */
+ private Object setupComponent(Object component, Configuration configuration)
+ throws Exception {
+ boolean initialized = false;
+ boolean started = false;
+
+ try {
+ if (component instanceof LogEnabled)
+ ((LogEnabled) component).enableLogging(this.logger);
+
+ if (component instanceof Contextualizable)
+ ((Contextualizable) component).contextualize(this.context);
+
+ if (component instanceof Serviceable)
+ ((Serviceable) component).service(this.manager);
+
+ if (component instanceof Configurable)
+ ((Configurable) component).configure(configuration);
+
+ if (component instanceof Parameterizable)
+ ((Parameterizable) component).parameterize(
+ Parameters.fromConfiguration(configuration));
+
+ if (component instanceof Initializable)
+ ((Initializable) component).initialize();
+ initialized = true;
+
+ if (component instanceof Startable)
+ ((Startable) component).start();
+ started = true;
+
+ return component;
+
+ } catch (Exception exception) {
+ if ((started) && (component instanceof Startable)) try {
+ ((Startable) component).stop();
+ } catch (Exception nested) {
+ this.logger.fatalError("Error stopping component", nested);
+ }
+ if ((initialized) && (component instanceof Disposable)) try {
+ ((Disposable) component).dispose();
+ } catch (Exception nested) {
+ this.logger.fatalError("Error disposing component", nested);
+ }
+ throw exception;
+ }
+ }
+
+ /**
+ * <p>Manage the distruction lifecycle of a specified component.</p>
+ */
+ private void decommissionComponent(Object component)
+ throws Exception {
+ try {
+ if (component instanceof Startable) ((Startable) component).stop();
+ } finally {
+ if (component instanceof Disposable) ((Disposable) component).dispose();
+ }
+ }
+}
\ No newline at end of file
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingSchemaParser.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingSchemaParser.java?rev=279172&r1=279171&r2=279172&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingSchemaParser.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/JingSchemaParser.java Tue Sep 6 16:15:33 2005
@@ -17,9 +17,12 @@
import java.io.IOException;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.components.validation.Schema;
import org.apache.cocoon.components.validation.SchemaParser;
+import org.apache.cocoon.components.validation.Validator;
import org.apache.excalibur.source.Source;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -37,6 +40,10 @@
*/
public class JingSchemaParser extends CachingSchemaParser {
+ /** <p>The list of languages supported by the {@link JingSchemaParser}.</p> */
+ private static final String[] LANGUAGES =
+ new String[] { Validator.LANGUAGE_RELAX_NG };
+
/** <p>The {@link ServiceManager} to resolve other components.</p> */
private ServiceManager serviceManager;
@@ -69,5 +76,16 @@
String message = "Incorrect schema \"" + uri + "\"";
throw new SAXException(message, exception);
}
+ }
+
+ /**
+ * <p>Return an array of {@link String}s containing all schema languages
+ * supported by this {@link SchemaParser}.</p>
+ *
+ * <p>The {@link JingSchemaParser} supports only the
+ * {@link Validator#LANGUAGE_RELAX_NG RELAX NG} language.</p>
+ */
+ public String[] getSupportedLanguages() {
+ return LANGUAGES;
}
}