[jboss-svn-commits] JBL Code SVN: r24263 - in labs/jbossrules/trunk: drools-compiler/src/main/java/org/drools/builder/impl and 12 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Dec 6 00:25:10 EST 2008
Author: mark.proctor at jboss.com
Date: 2008-12-06 00:25:09 -0500 (Sat, 06 Dec 2008)
New Revision: 24263
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/builder/
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/builder/impl/
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/builder/impl/DecisionTableConfigurationImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/BaseAbstractHandler.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/ChangeSetSemanticModule.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/DefaultSemanticModule.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/ExtensibleXmlParser.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/Handler.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/SemanticModule.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/SemanticModules.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/XmlChangeSetReader.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/AddHandler.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ModifyHandler.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/RemoveHandler.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ResourceHandler.java
Removed:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/builder/impl/DecisionTableConfigurationImpl.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BaseAbstractHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ChangeSetSemanticModule.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/DefaultSemanticModule.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ExtensibleXmlParser.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Handler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/SemanticModule.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/SemanticModules.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlChangeSetReader.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/AddHandler.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ModifyHandler.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/RemoveHandler.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ResourceHandler.java
Modified:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgent.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/changeset/ChangeSetTest.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java
Log:
JBRULES-1885 Update KnowledgeAgent to use new Resource api
- more fixes to get scanning working.
JBRULES-1874 Create Resource Framework
JBRULES-1875 Load ChangeSet XML files for multiple resources
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgent.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgent.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/agent/KnowledgeAgent.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,6 +1,7 @@
package org.drools.agent;
import org.drools.KnowledgeBase;
+import org.drools.io.Resource;
/**
* <p>
@@ -44,4 +45,6 @@
KnowledgeBase getKnowledgeBase();
void monitorResourceChangeEvents(boolean monitor);
+
+ void applyChangeSet(Resource resource);
}
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/builder/impl/DecisionTableConfigurationImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/builder/impl/DecisionTableConfigurationImpl.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/builder/impl/DecisionTableConfigurationImpl.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,31 +0,0 @@
-package org.drools.builder.impl;
-
-import org.drools.builder.DecisionTableConfiguration;
-import org.drools.builder.DecisionTableInputType;
-
-public class DecisionTableConfigurationImpl implements DecisionTableConfiguration {
-
- private DecisionTableInputType inputType;
-
- private String worksheetName;
-
- public DecisionTableConfigurationImpl() {
-
- }
-
- public void setInputType(DecisionTableInputType inputType) {
- this.inputType = inputType;
- }
-
- public DecisionTableInputType getInputType() {
- return this.inputType;
- }
-
- public void setWorksheetName(String worksheetName) {
- this.worksheetName = worksheetName;
- }
-
- public String getWorksheetName() {
- return this.worksheetName;
- }
-}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -638,6 +638,8 @@
}
}
}
+
+
/**
* This checks to see if it should all be in the one namespace.
@@ -740,7 +742,6 @@
// Merge imports
final Map<String, ImportDeclaration> imports = pkg.getImports();
imports.putAll( newPkg.getImports() );
- pkg.setResourceDirectories( newPkg.getResourceDirectories() );
String lastType = null;
try {
@@ -1177,7 +1178,6 @@
if ( hasErrors() && pkg != null ) {
pkg.setError( getErrors().toString() );
}
- pkg.setResourceDirectories( this.resourceDirectories );
return pkg;
}
@@ -1195,7 +1195,6 @@
pkg.setError( errors );
}
pkgs[i++] = pkg;
- pkg.setResourceDirectories( this.resourceDirectories );
}
return pkgs;
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BaseAbstractHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BaseAbstractHandler.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BaseAbstractHandler.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,63 +0,0 @@
-package org.drools.xml;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * 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.
- */
-
-import java.util.Set;
-
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-/**
- * @author mproctor
- *
- */
-public abstract class BaseAbstractHandler {
- protected Set<Class<?>> validPeers;
- protected Set<Class<?>> validParents;
- protected boolean allowNesting;
-
- public Set<Class<?>> getValidParents() {
- return this.validParents;
- }
-
- public Set<Class<?>> getValidPeers() {
- return this.validPeers;
- }
-
- public boolean allowNesting() {
- return this.allowNesting;
- }
-
- public void emptyAttributeCheck(final String element,
- final String attributeName,
- final String attribute,
- final ExtensibleXmlParser xmlPackageReader) throws SAXException {
- if ( attribute == null || attribute.trim().equals( "" ) ) {
- throw new SAXParseException( "<" + element + "> requires a '" + attributeName + "' attribute",
- xmlPackageReader.getLocator() );
- }
- }
-
- public void emptyContentCheck(final String element,
- final String content,
- final ExtensibleXmlParser xmlPackageReader) throws SAXException {
- if ( content == null || content.trim().equals( "" ) ) {
- throw new SAXParseException( "<" + element + "> requires content",
- xmlPackageReader.getLocator() );
- }
- }
-}
\ No newline at end of file
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ChangeSetSemanticModule.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ChangeSetSemanticModule.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ChangeSetSemanticModule.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,37 +0,0 @@
-/**
- *
- */
-package org.drools.xml;
-
-import org.drools.xml.changeset.AddHandler;
-import org.drools.xml.changeset.ChangeSetHandler;
-import org.drools.xml.changeset.DecisionTableConfigurationHandler;
-import org.drools.xml.changeset.ModifyHandler;
-import org.drools.xml.changeset.RemoveHandler;
-import org.drools.xml.changeset.ResourceHandler;
-
-public class ChangeSetSemanticModule extends DefaultSemanticModule implements SemanticModule {
-
- public ChangeSetSemanticModule() {
- super( "http://drools.org/drools-5.0/change-set" );
-
- addHandler( "change-set",
- new ChangeSetHandler() );
-
- addHandler( "add",
- new AddHandler() );
-
- addHandler( "removed",
- new RemoveHandler() );
-
- addHandler( "modified",
- new ModifyHandler() );
-
- addHandler( "resource",
- new ResourceHandler() );
-
- addHandler( "decisiontable-conf",
- new DecisionTableConfigurationHandler() );
- }
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/DefaultSemanticModule.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/DefaultSemanticModule.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/DefaultSemanticModule.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,43 +0,0 @@
-package org.drools.xml;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class DefaultSemanticModule implements SemanticModule {
- public String uri;
- public Map<String, Handler> handlers;
- public Map<Class<?>, Handler> handlersByClass;
-
- public DefaultSemanticModule(String uri) {
- this.uri = uri;
- this.handlers = new HashMap<String, Handler>();
- this.handlersByClass = new HashMap<Class<?>, Handler>();
- }
-
- public String getUri() {
- return this.uri;
- }
-
- public void addHandler(String name, Handler handler) {
- this.handlers.put( name, handler );
- if (handler != null && handler.generateNodeFor() != null) {
- this.handlersByClass.put( handler.generateNodeFor(), handler );
- }
- }
-
- public Handler getHandler(String name) {
- return this.handlers.get( name );
- }
-
- public Handler getHandlerByClass(Class<?> clazz) {
- while (clazz != null) {
- Handler handler = this.handlersByClass.get( clazz );
- if (handler != null) {
- return handler;
- }
- clazz = clazz.getSuperclass();
- }
- return null;
- }
-
-}
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ExtensibleXmlParser.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ExtensibleXmlParser.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ExtensibleXmlParser.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,751 +0,0 @@
-package org.drools.xml;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * 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.
- */
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.net.URL;
-import java.text.MessageFormat;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-import org.xml.sax.Attributes;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * <code>RuleSet</code> loader.
- *
- * Note you can override the default entity resolver by setting the System property of:
- * <code>org.drools.io.EntityResolve</code> to your own custom entity resolver.
- * This can be done using -Dorg.drools.io.EntityResolver=YourClassHere on the command line, for instance.
- *
- * @author <a href="mailto:bob at werken.com">bob mcwhirter </a>
- */
-public class ExtensibleXmlParser extends DefaultHandler {
- // ----------------------------------------------------------------------
- // Constants
- // ----------------------------------------------------------------------
- public static final String ENTITY_RESOLVER_PROPERTY_NAME = "org.drools.io.EntityResolver";
-
- /** Namespace URI for the general tags. */
- public static final String RULES_NAMESPACE_URI = "http://drools.org/rules";
-
- private static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
-
- private static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
-
- // ----------------------------------------------------------------------
- // Instance members
- // ----------------------------------------------------------------------
- /** SAX parser. */
- private SAXParser parser;
-
- /** isValidating */
- private boolean isValidating = true;
-
- /** Locator for errors. */
- private Locator locator;
-
- // private Map repo;
-
- /** Stack of configurations. */
- private LinkedList configurationStack;
-
- /** Current configuration text. */
- private StringBuilder characters;
-
- private SemanticModules modules;
-
- private boolean lastWasEndElement;
-
- private LinkedList parents;
-
- private Object peer;
-
- private Object current;
-
- private Object data;
-
- private final MessageFormat message = new MessageFormat( "({0}: {1}, {2}): {3}" );
-
- private final Map namespaces = new HashMap();
-
- private EntityResolver entityResolver;
-
- private Document document;
- private DocumentFragment docFragment;
-
- private ClassLoader classLoader;
-
- // ----------------------------------------------------------------------
- // Constructors
- // ----------------------------------------------------------------------
-
- /**
- * Construct.
- *
- * <p>
- * Uses the default JAXP SAX parser and the default classpath-based
- * <code>DefaultSemanticModule</code>.
- * </p>
- */
- public ExtensibleXmlParser() {
- // init
- this.configurationStack = new LinkedList();
- this.parents = new LinkedList();
-
- initEntityResolver();
- }
-
- public void setSemanticModules(SemanticModules modules) {
- this.modules = modules;
- }
-
- /**
- * Construct.
- *
- * <p>
- * Uses the default classpath-based <code>DefaultSemanticModule</code>.
- * </p>
- *
- * @param parser
- * The SAX parser.
- */
- public ExtensibleXmlParser(final SAXParser parser) {
- this();
- this.parser = parser;
- }
-
- // ----------------------------------------------------------------------
- // Instance methods
- // ----------------------------------------------------------------------
-
- /**
- * Read a <code>RuleSet</code> from a <code>Reader</code>.
- *
- * @param reader
- * The reader containing the rule-set.
- *
- * @return The rule-set.
- * @throws ParserConfigurationException
- */
- public Object read(final Reader reader) throws SAXException,
- IOException {
- return read( new InputSource( reader ) );
- }
-
- /**
- * Read a <code>RuleSet</code> from an <code>InputStream</code>.
- *
- * @param inputStream
- * The input-stream containing the rule-set.
- *
- * @return The rule-set.
- * @throws ParserConfigurationException
- */
- public Object read(final InputStream inputStream) throws SAXException,
- IOException {
- return read( new InputSource( inputStream ) );
- }
-
- /**
- * Read a <code>RuleSet</code> from an <code>InputSource</code>.
- *
- * @param in
- * The rule-set input-source.
- *
- * @return The rule-set.
- * @throws ParserConfigurationException
- */
- public Object read(final InputSource in) throws SAXException,
- IOException {
- if ( this.docFragment == null ) {
- try {
- this.document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
- } catch ( ParserConfigurationException e ) {
- throw new RuntimeException( "Unable to create new DOM Document" );
- }
- this.docFragment = this.document.createDocumentFragment();
- }
-
- SAXParser localParser = null;
- if ( this.parser == null ) {
- final SAXParserFactory factory = SAXParserFactory.newInstance();
- factory.setNamespaceAware( true );
-
- final String isValidatingString = System.getProperty( "drools.schema.validating" );
- if ( System.getProperty( "drools.schema.validating" ) != null ) {
- this.isValidating = Boolean.getBoolean( "drools.schema.validating" );
- }
-
- if ( this.isValidating == true ) {
- factory.setValidating( true );
- try {
- localParser = factory.newSAXParser();
- } catch ( final ParserConfigurationException e ) {
- throw new RuntimeException( e.getMessage() );
- }
-
- try {
- localParser.setProperty( ExtensibleXmlParser.JAXP_SCHEMA_LANGUAGE,
- ExtensibleXmlParser.W3C_XML_SCHEMA );
- } catch ( final SAXNotRecognizedException e ) {
- boolean hideWarnings = Boolean.getBoolean( "drools.schema.hidewarnings" );
- if ( !hideWarnings ) {
- System.err.println( "Your SAX parser is not JAXP 1.2 compliant - turning off validation." );
- }
- localParser = null;
- }
- }
-
- if ( localParser == null ) {
- // not jaxp1.2 compliant so turn off validation
- try {
- this.isValidating = false;
- factory.setValidating( this.isValidating );
- localParser = factory.newSAXParser();
- } catch ( final ParserConfigurationException e ) {
- throw new RuntimeException( e.getMessage() );
- }
- }
- } else {
- localParser = this.parser;
- }
-
- if ( !localParser.isNamespaceAware() ) {
- throw new RuntimeException( "parser must be namespace-aware" );
- }
-
- localParser.parse( in,
- this );
-
- return this.data;
- }
-
- public void setData(final Object data) {
- this.data = data;
- }
-
- public Object getData() {
- return this.data;
- }
-
- public ClassLoader getClassLoader() {
- return classLoader;
- }
-
- public void setClassLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
- }
-
- /**
- * @see org.xml.sax.ContentHandler
- */
- public void setDocumentLocator(final Locator locator) {
- this.locator = locator;
- }
-
- /**
- * Get the <code>Locator</code>.
- *
- * @return The locator.
- */
- public Locator getLocator() {
- return this.locator;
- }
-
- public void startDocument() {
- this.isValidating = true;
- this.current = null;
- this.peer = null;
- this.lastWasEndElement = false;
- this.parents.clear();
- this.characters = null;
- this.configurationStack.clear();
- this.namespaces.clear();
- }
-
- private int direction = 0;
-
- /**
- * @param uri
- * @param localName
- * @param qname
- * @param attrs
- * @throws SAXException
- * @see org.xml.sax.ContentHandler
- *
- * @todo: better way to manage unhandled elements
- */
- public void startElement(final String uri,
- final String localName,
- final String qname,
- final Attributes attrs) throws SAXException {
- if ( direction == 1 ) {
- // going down again, so clear
- this.peer = null;
- } else {
- direction = 1;
- }
-
- final Handler handler = getHandler( uri,
- localName );
-
- if ( handler == null ) {
- startElementBuilder( localName,
- attrs );
- return;
- }
-
- validate( uri,
- localName,
- handler );
-
- final Object node = handler.start( uri,
- localName,
- attrs,
- this );
-
- if ( node == null ) {
- this.parents.add( Null.instance );
- } else {
- this.parents.add( node );
- }
- }
-
- /**
- * @param uri
- * @param localName
- * @param qname
- * @throws SAXException
- * @see org.xml.sax.ContentHandler
- */
-
- public void endElement(final String uri,
- final String localName,
- final String qname) throws SAXException {
- direction = -1;
- final Handler handler = getHandler( uri,
- localName );
-
- if ( handler == null ) {
- if ( this.configurationStack.size() >= 1 ) {
- endElementBuilder();
- }
- return;
- }
-
- this.current = removeParent();
-
- this.peer = handler.end( uri,
- localName,
- this );
- }
-
- public static class Null {
- public static final Null instance = new Null();
- }
-
- private void validate(final String uri,
- final String localName,
- final Handler handler) throws SAXParseException {
- boolean validParent = false;
- boolean validPeer = false;
- boolean invalidNesting = false;
-
- final Set validParents = handler.getValidParents();
- final Set validPeers = handler.getValidPeers();
- boolean allowNesting = handler.allowNesting();
-
- // get parent
- Object parent;
- if ( this.parents.size() != 0 ) {
- parent = this.parents.getLast();
- } else {
- parent = null;
- }
-
- // check valid parents
- // null parent means localname is rule-set
- // dont process if elements are the same
- // instead check for allowed nesting
- final Class nodeClass = getHandler( uri,
- localName ).generateNodeFor();
- if ( nodeClass != null && !nodeClass.isInstance( parent ) ) {
- Object allowedParent;
- final Iterator it = validParents.iterator();
- while ( !validParent && it.hasNext() ) {
- allowedParent = it.next();
- if ( parent == null && allowedParent == null ) {
- validParent = true;
- } else if ( allowedParent != null && ((Class) allowedParent).isInstance( parent ) ) {
- validParent = true;
- }
- }
- if ( !validParent ) {
- throw new SAXParseException( "<" + localName + "> has an invalid parent element [" + parent + "]",
- getLocator() );
- }
- }
-
- // check valid peers
- // null peer means localname is rule-set
- final Object peer = this.peer;
-
- Object allowedPeer;
- Iterator it = validPeers.iterator();
- while ( !validPeer && it.hasNext() ) {
- allowedPeer = it.next();
- if ( peer == null && allowedPeer == null ) {
- validPeer = true;
- } else if ( allowedPeer != null && ((Class) allowedPeer).isInstance( peer ) ) {
- validPeer = true;
- }
- }
- if ( !validPeer ) {
- throw new SAXParseException( "<" + localName + "> is after an invalid element: " + Handler.class.getName(),
- getLocator() );
- }
-
- if ( nodeClass != null && !allowNesting ) {
- it = this.parents.iterator();
- while ( !invalidNesting && it.hasNext() ) {
- if ( nodeClass.isInstance( it.next() ) ) {
- invalidNesting = true;
- }
- }
- }
- if ( invalidNesting ) {
- throw new SAXParseException( "<" + localName + "> may not be nested",
- getLocator() );
- }
-
- }
-
- /**
- * Start a configuration node.
- *
- * @param name
- * Tag name.
- * @param attrs
- * Tag attributes.
- */
- public void startElementBuilder(final String tagName,
- final Attributes attrs) {
- this.characters = new StringBuilder();
-
-
- final Element element = this.document.createElement( tagName );
-
- //final DefaultConfiguration config = new DefaultConfiguration( tagName );
-
- final int numAttrs = attrs.getLength();
-
- for ( int i = 0; i < numAttrs; ++i ) {
- element.setAttribute( attrs.getLocalName( i ),
- attrs.getValue( i ) );
- }
-
-// // lets add the namespaces as attributes
-// for ( final Iterator iter = this.namespaces.entrySet().iterator(); iter.hasNext(); ) {
-// final Map.Entry entry = (Map.Entry) iter.next();
-// String ns = (String) entry.getKey();
-// final String value = (String) entry.getValue();
-// if ( ns == null || ns.length() == 0 ) {
-// ns = "xmlns";
-// } else {
-// ns = "xmlns:" + ns;
-// }
-// config.setAttribute( ns,
-// value );
-// }
-
- if ( this.configurationStack.isEmpty() ) {
- this.configurationStack.addLast( element );
- } else {
- ((Element) this.configurationStack.getLast()).appendChild( element );
- this.configurationStack.addLast( element );
- }
- }
-
- Handler getHandler(final String uri,
- final String localName) {
- SemanticModule module = this.modules.getSemanticModule( uri );
- if ( module != null ) {
- return module.getHandler( localName );
- } else {
- return null;
- }
- }
-
- /**
- * @param chars
- * @param start
- * @param len
- * @see org.xml.sax.ContentHandler
- */
- public void characters(final char[] chars,
- final int start,
- final int len) {
- if ( this.characters != null ) {
- this.characters.append( chars,
- start,
- len );
- }
- }
-
- /**
- * End a configuration node.
- *
- * @return The configuration.
- */
- public Element endElementBuilder() {
- final Element element = (Element) this.configurationStack.removeLast();
- if ( this.characters != null ) {
- element.appendChild( this.document.createTextNode( this.characters.toString() ) );
- }
-
- this.characters = null;
-
- return element;
- }
-
- public Object getParent() {
- return this.parents.getLast();
- }
-
- public Object getParent(int index) {
- ListIterator it = this.parents.listIterator( this.parents.size() );
- int x = 0;
- Object parent = null;
- while ( x++ <= index ) {
- parent = it.previous();
- }
- return parent;
- }
-
- public Object removeParent() {
- Object parent = this.parents.removeLast();
- while ( parent == null && !this.parents.isEmpty() ) {
- parent = this.parents.removeLast();
- }
- return parent;
- }
-
- public LinkedList getParents() {
- return this.parents;
- }
-
- public Object getParent(final Class parent) {
- final ListIterator it = this.parents.listIterator( this.parents.size() );
- Object node = null;
- while ( it.hasPrevious() ) {
- node = it.previous();
- if ( parent.isInstance( node ) ) {
- break;
- }
- }
- return node;
- }
-
- public Object getPeer() {
- return this.peer;
- }
-
- public Object getCurrent() {
- return this.current;
- }
-
- public InputSource resolveEntity(final String publicId,
- final String systemId) throws SAXException {
- try {
- final InputSource inputSource = resolveSchema( publicId,
- systemId );
- if ( inputSource != null ) {
- return inputSource;
- }
- if ( this.entityResolver != null ) {
- return this.entityResolver.resolveEntity( publicId,
- systemId );
- }
- } catch ( final IOException ioe ) {
- }
- return null;
- }
-
- public void startPrefixMapping(final String prefix,
- final String uri) throws SAXException {
- super.startPrefixMapping( prefix,
- uri );
- this.namespaces.put( prefix,
- uri );
- }
-
- public void endPrefixMapping(final String prefix) throws SAXException {
- super.endPrefixMapping( prefix );
- this.namespaces.remove( prefix );
- }
-
- private void print(final SAXParseException x) {
- final String msg = this.message.format( new Object[]{x.getSystemId(), new Integer( x.getLineNumber() ), new Integer( x.getColumnNumber() ), x.getMessage()} );
- System.out.println( msg );
- }
-
- public void warning(final SAXParseException x) {
- print( x );
- }
-
- public void error(final SAXParseException x) {
- print( x );
- }
-
- public void fatalError(final SAXParseException x) throws SAXParseException {
- print( x );
- throw x;
- }
-
- private InputSource resolveSchema(final String publicId,
- final String systemId) throws SAXException,
- IOException {
- // Schema files must end with xsd
- if ( !systemId.toLowerCase().endsWith( "xsd" ) ) {
- return null;
- }
-
- // try the actual location given by systemId
- try {
- final URL url = new URL( systemId );
- return new InputSource( url.openStream() );
- } catch ( final Exception e ) {
- }
-
- // Try and get the index for the filename, else return null
- String xsd;
- int index = systemId.lastIndexOf( "/" );
- if ( index == -1 ) {
- index = systemId.lastIndexOf( "\\" );
- }
- if ( index != -1 ) {
- xsd = systemId.substring( index + 1 );
- } else {
- xsd = systemId;
- }
-
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
-
- if ( cl == null ) {
- cl = ExtensibleXmlParser.class.getClassLoader();
- }
-
- // Try looking in META-INF
- {
- final InputStream is = cl.getResourceAsStream( "META-INF/" + xsd );
- if ( is != null ) {
- return new InputSource( is );
- }
- }
-
- // Try looking in /META-INF
- {
- final InputStream is = cl.getResourceAsStream( "/META-INF/" + xsd );
- if ( is != null ) {
- return new InputSource( is );
- }
- }
-
- // Try looking at root of classpath
- {
- final InputStream is = cl.getResourceAsStream( "/" + xsd );
- if ( is != null ) {
- return new InputSource( is );
- }
- }
-
- // Try current working directory
- {
- final File file = new File( xsd );
- if ( file.exists() ) {
- return new InputSource( new BufferedInputStream( new FileInputStream( file ) ) );
- }
- }
-
- cl = ClassLoader.getSystemClassLoader();
-
- // Try looking in META-INF
- {
- final InputStream is = cl.getResourceAsStream( "META-INF/" + xsd );
- if ( is != null ) {
- return new InputSource( is );
- }
- }
-
- // Try looking in /META-INF
- {
- final InputStream is = cl.getResourceAsStream( "/META-INF/" + xsd );
- if ( is != null ) {
- return new InputSource( is );
- }
- }
-
- // Try looking at root of classpath
- {
- final InputStream is = cl.getResourceAsStream( "/" + xsd );
- if ( is != null ) {
- return new InputSource( is );
- }
- }
-
- return null;
- }
-
- /**
- * Intializes EntityResolver that is configured via system property ENTITY_RESOLVER_PROPERTY_NAME.
- */
- private void initEntityResolver() {
- final String entityResolveClazzName = System.getProperty( ExtensibleXmlParser.ENTITY_RESOLVER_PROPERTY_NAME );
- if ( entityResolveClazzName != null && entityResolveClazzName.length() > 0 ) {
- try {
- final Class entityResolverClazz = Thread.currentThread().getContextClassLoader().loadClass( entityResolveClazzName );
- this.entityResolver = (EntityResolver) entityResolverClazz.newInstance();
- } catch ( final Exception ignoreIt ) {
- }
- }
- }
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Handler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Handler.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Handler.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,46 +0,0 @@
-package org.drools.xml;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * 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.
- */
-
-import java.util.Set;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-/**
- * @author mproctor
- *
- */
-public interface Handler {
-
- Object start(String uri,
- String localName,
- Attributes attrs,
- ExtensibleXmlParser xmlPackageReader) throws SAXException;
-
- Object end(String uri,
- String localName,
- ExtensibleXmlParser xmlPackageReader) throws SAXException;
-
- Set<Class<?>> getValidParents();
-
- Set<Class<?>> getValidPeers();
-
- boolean allowNesting();
-
- Class<?> generateNodeFor();
-}
\ No newline at end of file
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/SemanticModule.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/SemanticModule.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/SemanticModule.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,11 +0,0 @@
-package org.drools.xml;
-
-public interface SemanticModule {
- public String getUri();
-
- public void addHandler(String name, Handler handler);
-
- public Handler getHandler(String name);
-
- public Handler getHandlerByClass(Class<?> clazz);
-}
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/SemanticModules.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/SemanticModules.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/SemanticModules.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,26 +0,0 @@
-
-package org.drools.xml;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class SemanticModules {
- public Map<String, SemanticModule> modules;
-
- public SemanticModules() {
- this.modules = new HashMap<String, SemanticModule>();
- }
-
- public void addSemanticModule(SemanticModule module) {
- this.modules.put( module.getUri(),
- module );
- }
-
- public SemanticModule getSemanticModule(String uri) {
- return this.modules.get( uri );
- }
-
- public String toString() {
- return this.modules.toString();
- }
-}
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlChangeSetReader.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlChangeSetReader.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlChangeSetReader.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,77 +0,0 @@
-package org.drools.xml;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
-import javax.xml.parsers.SAXParser;
-
-import org.drools.ChangeSet;
-import org.drools.lang.descr.PackageDescr;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-
-public class XmlChangeSetReader {
- private ExtensibleXmlParser parser;
-
- public XmlChangeSetReader(final SemanticModules modules) {
- this( modules, null );
- }
-
- public XmlChangeSetReader(final SemanticModules modules, final SAXParser parser) {
- if ( parser == null ) {
- this.parser = new ExtensibleXmlParser();
- } else {
- this.parser = new ExtensibleXmlParser( parser );
- }
- this.parser.setSemanticModules( modules );
- }
-
- public void setClassLoader(ClassLoader classLoader) {
- this.parser.setClassLoader( classLoader );
- }
-
- public ExtensibleXmlParser getParser() {
- return this.parser;
- }
-
- /**
- * Read a <code>RuleSet</code> from a <code>Reader</code>.
- *
- * @param reader
- * The reader containing the rule-set.
- *
- * @return The rule-set.
- */
- public ChangeSet read(final Reader reader) throws SAXException,
- IOException {
- return (ChangeSet) this.parser.read( reader );
- }
-
- /**
- * Read a <code>RuleSet</code> from an <code>InputStream</code>.
- *
- * @param inputStream
- * The input-stream containing the rule-set.
- *
- * @return The rule-set.
- */
- public ChangeSet read(final InputStream inputStream) throws SAXException,
- IOException {
- return (ChangeSet) this.parser.read( inputStream );
- }
-
- /**
- * Read a <code>RuleSet</code> from an <code>InputSource</code>.
- *
- * @param in
- * The rule-set input-source.
- *
- * @return The rule-set.
- */
- public ChangeSet read(final InputSource in) throws SAXException,
- IOException {
- return (ChangeSet) this.parser.read( in );
- }
-}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/changeset/ChangeSetTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/changeset/ChangeSetTest.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/xml/changeset/ChangeSetTest.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -160,13 +160,7 @@
output.write( xml );
output.close();
- KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newUrlResource( fxml.toURI().toURL() ),
- ResourceType.ChangeSet );
- assertFalse( kbuilder.hasErrors() );
-
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
- kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
ResourceChangeScannerConfiguration sconf = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
sconf.setProperty( "drools.resource.scanner.interval",
@@ -174,13 +168,17 @@
ResourceFactory.getResourceChangeScannerService().configure( sconf );
KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
+ aconf.setProperty( "drools.agent.scanDirectories",
+ "true" );
aconf.setProperty( "drools.agent.scanResources",
- "true" );
+ "true" );
aconf.setProperty( "drools.agent.newInstance",
"true" );
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "test agent",
kbase,
aconf );
+
+ kagent.applyChangeSet( ResourceFactory.newUrlResource( fxml.toURI().toURL() ) );
StatefulKnowledgeSession ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
List list = new ArrayList();
@@ -217,6 +215,7 @@
assertEquals( 2,
list.size() );
+
assertTrue( list.contains( "rule3" ) );
assertTrue( list.contains( "rule2" ) );
kagent.monitorResourceChangeEvents( false );
@@ -280,13 +279,13 @@
output.write( xml );
output.close();
- KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newUrlResource( fxml.toURI().toURL() ),
- ResourceType.ChangeSet );
- assertFalse( kbuilder.hasErrors() );
+// KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+// kbuilder.add( ResourceFactory.newUrlResource( fxml.toURI().toURL() ),
+// ResourceType.ChangeSet );
+// assertFalse( kbuilder.hasErrors() );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
- kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+ //kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
ResourceChangeScannerConfiguration sconf = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
sconf.setProperty( "drools.resource.scanner.interval",
@@ -294,14 +293,17 @@
ResourceFactory.getResourceChangeScannerService().configure( sconf );
KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
- aconf.setProperty( "drools.agent.scanResources",
+ aconf.setProperty( "drools.agent.scanDirectories",
"true" );
aconf.setProperty( "drools.agent.newInstance",
"true" );
+
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "test agent",
kbase,
aconf );
+ kagent.applyChangeSet( ResourceFactory.newUrlResource( fxml.toURI().toURL() ) );
+ Thread.sleep( 3000 ); // give it 2 seconds to detect and build the changes
StatefulKnowledgeSession ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
List list = new ArrayList();
ksession.setGlobal( "list",
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentConfigurationImpl.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -17,6 +17,7 @@
KnowledgeAgentConfiguration {
private boolean scanResources;
+ private boolean scanDirectories;
private boolean monitorChangeSetEvents;
private boolean newInstance;
@@ -40,8 +41,15 @@
if ( name.equals( "drools.agent.monitorChangeSetEvents" ) ) {
setMonitorChangeSetEvents( StringUtils.isEmpty( value ) ? true : Boolean.parseBoolean( value ) );
- } else if ( name.equals( "drools.agent.scanResources" ) ) {
+ } else if ( name.equals( "drools.agent.scanDirectories" ) ) {
boolean bool = StringUtils.isEmpty( value ) ? true : Boolean.parseBoolean( value );
+ setScanDirectories( bool );
+ if ( bool ) {
+ setScanResources( true );
+ setMonitorChangeSetEvents( true );
+ }
+ } else if ( name.equals( "drools.agent.scanResources" ) ) {
+ boolean bool = StringUtils.isEmpty( value ) ? true : Boolean.parseBoolean( value );
setScanResources( bool );
if ( bool ) {
setMonitorChangeSetEvents( true );
@@ -57,11 +65,13 @@
return null;
}
- if ( name.equals( "drools.agent.scanResources " ) ) {
+ if ( name.equals( "drools.agent.scanResources" ) ) {
return Boolean.toString( this.scanResources );
- } else if ( name.equals( "drools.agent.monitorChangeSetEvents " ) ) {
+ } else if ( name.equals( "drools.agent.scanDirectories" ) ) {
+ return Boolean.toString( this.scanDirectories );
+ } else if ( name.equals( "drools.agent.monitorChangeSetEvents" ) ) {
return Boolean.toString( this.monitorChangeSetEvents );
- } else if ( name.equals( "drools.agent.newInstance " ) ) {
+ } else if ( name.equals( "drools.agent.newInstance" ) ) {
return Boolean.toString( this.newInstance );
}
@@ -76,8 +86,14 @@
this.scanResources = scanResources;
}
-
+ public boolean isScanDirectories() {
+ return scanDirectories;
+ }
+ public void setScanDirectories(boolean scanDirectories) {
+ this.scanDirectories = scanDirectories;
+ }
+
public boolean isMonitorChangeSetEvents() {
return monitorChangeSetEvents;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/impl/KnowledgeAgentImpl.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,13 +1,16 @@
package org.drools.agent.impl;
+import java.io.InputStream;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue;
+import org.drools.ChangeSet;
import org.drools.KnowledgeBase;
-import org.drools.ChangeSet;
import org.drools.KnowledgeBaseFactory;
import org.drools.RuleBase;
import org.drools.agent.KnowledgeAgent;
@@ -16,23 +19,30 @@
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
+import org.drools.common.AbstractRuleBase;
import org.drools.definition.KnowledgeDefinition;
import org.drools.definition.process.Process;
import org.drools.event.io.ResourceChangeListener;
import org.drools.impl.KnowledgeBaseImpl;
+import org.drools.io.InternalResource;
import org.drools.io.Resource;
-import org.drools.io.InternalResource;
import org.drools.io.ResourceFactory;
+import org.drools.io.impl.ClassPathResource;
import org.drools.io.impl.ResourceChangeNotifierImpl;
import org.drools.rule.Function;
import org.drools.rule.Package;
import org.drools.rule.Rule;
import org.drools.rule.TypeDeclaration;
+import org.drools.util.DroolsStreamUtils;
+import org.drools.xml.ChangeSetSemanticModule;
+import org.drools.xml.SemanticModules;
+import org.drools.xml.XmlChangeSetReader;
public class KnowledgeAgentImpl
implements
KnowledgeAgent,
- ResourceChangeListener, Runnable {
+ ResourceChangeListener,
+ Runnable {
private String name;
private Map<Resource, ResourceMapping> resources;
private Set<Resource> resourceDirectories;
@@ -40,6 +50,7 @@
private ResourceChangeNotifierImpl notifier;
private boolean newInstance;
private KnowledgeAgentEventListener listener;
+ private boolean scanDirectories;
private LinkedBlockingQueue<ChangeSet> queue;
private Thread thread;
private volatile boolean monitor;
@@ -50,6 +61,7 @@
KnowledgeAgentEventListener listener) {
this.kbase = kbase;
this.resources = new HashMap<Resource, ResourceMapping>();
+ this.resourceDirectories = new HashSet<Resource>();
this.listener = listener;
this.newInstance = true; // we hard code this for now as incremental kbase changes don't work.
if ( configuration != null ) {
@@ -58,36 +70,129 @@
if ( ((KnowledgeAgentConfigurationImpl) configuration).isMonitorChangeSetEvents() ) {
this.monitor = true;
}
+
+ if ( ((KnowledgeAgentConfigurationImpl) configuration).isScanDirectories() ) {
+ this.scanDirectories = true;
+ }
+
if ( ((KnowledgeAgentConfigurationImpl) configuration).isScanResources() ) {
this.notifier.addResourceChangeMonitor( ResourceFactory.getResourceChangeScannerService() );
this.monitor = true; // if scanning, monitor must be true;
}
}
-
+
if ( this.monitor ) {
this.queue = new LinkedBlockingQueue<ChangeSet>();
thread = new Thread( this );
thread.start();
}
-
+
buildResourceMapping( kbase );
}
+ SemanticModules semanticModules;
+
+ public void applyChangeSet(Resource resource) {
+ applyChangeSet( getChangeSet( resource ) );
+ }
+
+ public void applyChangeSet(ChangeSet changeSet) {
+ ChangeSetState changeSetState = new ChangeSetState();
+ changeSetState.scanDirectories = this.scanDirectories;
+ processChangeSet( changeSet,
+ changeSetState );
+
+ rebuildResources( changeSetState );
+ buildResourceMapping( this.kbase );
+ }
+
+ public void processChangeSet(Resource resource,
+ ChangeSetState changeSetState) {
+ processChangeSet( getChangeSet( resource ),
+ changeSetState );
+ }
+
+ public void processChangeSet(ChangeSet changeSet,
+ ChangeSetState changeSetState) {
+ for ( Resource child : changeSet.getResourcesAdded() ) {
+ if ( ((InternalResource) child).getResourceType() == ResourceType.PKG ) {
+ changeSetState.pkgs.add( child );
+ }
+
+ ResourceMapping mapping = this.resources.get( child );
+ if ( mapping == null ) {
+ this.notifier.subscribeResourceChangeListener( this,
+ child );
+ mapping = new ResourceMapping( child );
+ this.resources.put( child,
+ mapping );
+ }
+ }
+
+ for ( Resource child : changeSet.getResourcesRemoved() ) {
+ if ( ((InternalResource) child).getResourceType() == ResourceType.ChangeSet ) {
+ processChangeSet( child,
+ changeSetState );
+ } else if ( changeSetState.scanDirectories && ((InternalResource) child).isDirectory() ) {
+ this.resourceDirectories.remove( child );
+ this.notifier.unsubscribeResourceChangeListener( this,
+ child );
+ } else {
+ this.resources.remove( child );
+ this.notifier.unsubscribeResourceChangeListener( this,
+ child );
+ }
+ }
+
+ // are we going to need kbuilder to build these resources?
+ for ( Resource resource : this.resources.keySet() ) {
+ if ( ((InternalResource) resource).getResourceType() != ResourceType.ChangeSet && ((InternalResource) resource).getResourceType() != ResourceType.PKG || changeSetState.scanDirectories && !((InternalResource) resource).isDirectory() ) {
+ changeSetState.needsKnowledgeBuilder = true;
+ break;
+ }
+ }
+
+ }
+
+ public ChangeSet getChangeSet(Resource resource) {
+ if ( this.semanticModules == null ) {
+ this.semanticModules = new SemanticModules();
+ this.semanticModules.addSemanticModule( new ChangeSetSemanticModule() );
+ }
+
+ XmlChangeSetReader reader = new XmlChangeSetReader( this.semanticModules );
+ if ( resource instanceof ClassPathResource ) {
+ reader.setClassLoader( ((ClassPathResource) resource).getClassLoader() );
+ } else {
+ reader.setClassLoader( ((AbstractRuleBase) (((KnowledgeBaseImpl) this.kbase).ruleBase)).getConfiguration().getClassLoader() );
+ }
+ ChangeSet changeSet = null;
+ try {
+ changeSet = reader.read( resource.getReader() );
+ } catch ( Exception e ) {
+ // @TODO add proper error handling
+ }
+ if ( changeSet == null ) {
+ // @TODO should log an error
+ }
+ return changeSet;
+ }
+
+ public static class ChangeSetState {
+ List<Resource> pkgs = new ArrayList<Resource>();
+ boolean scanDirectories;
+ boolean needsKnowledgeBuilder;
+ }
+
public void buildResourceMapping(KnowledgeBase kbase) {
RuleBase rbase = ((KnowledgeBaseImpl) kbase).ruleBase;
synchronized ( this.resources ) {
for ( Package pkg : rbase.getPackages() ) {
-
- for ( Resource resource : pkg.getResourceDirectories() ) {
- this.notifier.subscribeResourceChangeListener( this,
- resource );
- }
-
for ( Rule rule : pkg.getRules() ) {
Resource resource = rule.getResource();
- if ( resource == null || !((InternalResource)resource).hasURL() ) {
+ if ( resource == null || !((InternalResource) resource).hasURL() ) {
continue;
}
ResourceMapping mapping = this.resources.get( resource );
@@ -104,7 +209,7 @@
for ( Process process : pkg.getRuleFlows().values() ) {
Resource resource = ((org.drools.process.core.Process) process).getResource();
- if ( resource == null || !((InternalResource)resource).hasURL() ) {
+ if ( resource == null || !((InternalResource) resource).hasURL() ) {
continue;
}
ResourceMapping mapping = this.resources.get( resource );
@@ -121,7 +226,7 @@
for ( TypeDeclaration typeDeclaration : pkg.getTypeDeclarations().values() ) {
Resource resource = typeDeclaration.getResource();
- if ( resource == null || !((InternalResource)resource).hasURL() ) {
+ if ( resource == null || !((InternalResource) resource).hasURL() ) {
continue;
}
ResourceMapping mapping = this.resources.get( resource );
@@ -138,7 +243,7 @@
for ( Function function : pkg.getFunctions().values() ) {
Resource resource = function.getResource();
- if ( resource == null || !((InternalResource)resource).hasURL() ) {
+ if ( resource == null || !((InternalResource) resource).hasURL() ) {
continue;
}
ResourceMapping mapping = this.resources.get( resource );
@@ -205,40 +310,46 @@
}
}
-
- private void processChangeSet(ChangeSet changeSet) {
+
+ private void rebuildResources(ChangeSetState changeSetState) {
// for now we assume newIntance only, so just blow away the mappings and knowledgedefinition sets.
synchronized ( this.resources ) {
- // first remove the unneeded resources
- for ( Resource resource : changeSet.getResourcesRemoved() ) {
- this.resources.remove( resource );
+ for ( Resource child : changeSetState.pkgs ) {
+ try {
+ InputStream is = child.getInputStream();
+ Package pkg = (Package) DroolsStreamUtils.streamIn( is );
+ ((KnowledgeBaseImpl) this.kbase).ruleBase.addPackage( pkg );
+ is.close();
+ } catch ( Exception e ) {
+ // @TODO add proper error
+ e.printStackTrace();
+ }
}
- // now add the new ones
- for ( Resource resource : changeSet.getResourcesAdded() ) {
- this.resources.put( resource,
- null );
- }
+ if ( changeSetState.needsKnowledgeBuilder ) {
+ // modified we already know is in the map, so no need to process those
- // modified we already know is in the map, so no need to process those
+ // now make a copy of the resource keys, as we are about to reset it, but need the keys to rebuild the kbase
+ Resource[] resourcesClone = this.resources.keySet().toArray( new Resource[this.resources.size()] );
- // now make a copy of the resource keys, as we are about to reset it, but need the keys to rebuild the kbase
- Resource[] resourcesClone = this.resources.keySet().toArray( new Resource[this.resources.size()] );
+ // reset the resources map, so it can now be rebuilt
+ this.resources.clear();
- // reset the resources map, so it can now be rebuilt
- this.resources.clear();
+ // rebuild the kbase
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- // rebuild the kbase
- KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ for ( Resource resource : resourcesClone ) {
+ System.out.println( "building : " + resource );
+ if ( ((InternalResource) resource).getResourceType() != ResourceType.PKG ) {
+ // .pks are handled as a special case.
+ kbuilder.add( resource,
+ ((InternalResource) resource).getResourceType() );
+ }
+ }
- for ( Resource resource : resourcesClone ) {
- System.out.println( "building : " + resource );
- kbuilder.add( resource,
- ((InternalResource)resource).getResourceType() );
+ this.kbase = KnowledgeBaseFactory.newKnowledgeBase();
+ this.kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
}
-
- this.kbase = KnowledgeBaseFactory.newKnowledgeBase();
- this.kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
}
// code commented out to try and do incremental kbase changes
@@ -274,7 +385,7 @@
public String getName() {
return this.name;
}
-
+
public void monitorResourceChangeEvents(boolean monitor) {
if ( !this.monitor && monitor ) {
// If the thread is not running and we are trying to start it, we must create a new Thread
@@ -284,11 +395,11 @@
}
this.monitor = monitor;
}
-
- public void run() {
- while ( this.monitor ) {
- try {
- processChangeSet( this.queue.take() );
+
+ public void run() {
+ while ( this.monitor ) {
+ try {
+ applyChangeSet( this.queue.take() );
} catch ( InterruptedException e ) {
// @TODO print proper error message
e.printStackTrace();
@@ -296,7 +407,7 @@
Thread.yield();
}
}
-
+
@Override
protected void finalize() throws Throwable {
// users should turn off monitoring, but just in case when this class is GC'd we turn off the thread
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/builder/impl/DecisionTableConfigurationImpl.java (from rev 24244, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/builder/impl/DecisionTableConfigurationImpl.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/builder/impl/DecisionTableConfigurationImpl.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/builder/impl/DecisionTableConfigurationImpl.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,31 @@
+package org.drools.builder.impl;
+
+import org.drools.builder.DecisionTableConfiguration;
+import org.drools.builder.DecisionTableInputType;
+
+public class DecisionTableConfigurationImpl implements DecisionTableConfiguration {
+
+ private DecisionTableInputType inputType;
+
+ private String worksheetName;
+
+ public DecisionTableConfigurationImpl() {
+
+ }
+
+ public void setInputType(DecisionTableInputType inputType) {
+ this.inputType = inputType;
+ }
+
+ public DecisionTableInputType getInputType() {
+ return this.inputType;
+ }
+
+ public void setWorksheetName(String worksheetName) {
+ this.worksheetName = worksheetName;
+ }
+
+ public String getWorksheetName() {
+ return this.worksheetName;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/builder/impl/DecisionTableConfigurationImpl.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -524,7 +524,6 @@
// Merge imports
final Map<String, ImportDeclaration> imports = pkg.getImports();
imports.putAll( newPkg.getImports() );
- pkg.setResourceDirectories( newPkg.getResourceDirectories() );
String lastType = null;
try {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeNotifierImpl.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -72,6 +72,8 @@
if ( listeners == null ) {
return;
}
+
+ listeners.remove( listeners );
if ( listeners.isEmpty() ) {
this.subscriptions.remove( resource );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/io/impl/ResourceChangeScannerImpl.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -84,10 +84,6 @@
System.out.println( "attempt scan : " + this.resources.size() );
synchronized ( this.resources ) {
-
- if ( this.resources.size() > 0 ) {
- System.out.println( "x" );
- }
Map<ResourceChangeNotifier, ChangeSet> notifications = new HashMap<ResourceChangeNotifier, ChangeSet>();
List<Resource> removed = new ArrayList<Resource>();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java 2008-12-06 00:25:35 UTC (rev 24262)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -97,9 +97,7 @@
* This will keep a summary error message as to why this package is not
* valid
*/
- private String errorSummary;
-
- private Set<Resource> resourceDirectories = Collections.emptySet();
+ private String errorSummary;
// ------------------------------------------------------------
// Constructors
@@ -168,7 +166,6 @@
out.writeBoolean( this.valid );
out.writeObject( this.rules );
out.writeObject( this.classFieldAccessorStore );
- out.writeObject( this.resourceDirectories );
// writing the whole stream as a byte array
if ( !isDroolsStream ) {
bytes.flush();
@@ -210,7 +207,6 @@
this.valid = in.readBoolean();
this.rules = (Map) in.readObject();
this.classFieldAccessorStore = (ClassFieldAccessorStore) in.readObject();
- this.resourceDirectories = (Set<Resource>) in.readObject();
if ( !isDroolsStream ) {
in.close();
}
@@ -495,14 +491,7 @@
return this.errorSummary;
}
- public Set<Resource> getResourceDirectories() {
- return resourceDirectories;
- }
- public void setResourceDirectories(Set<Resource> resourceDirectories) {
- this.resourceDirectories = resourceDirectories;
- }
-
public boolean equals(final Object object) {
if ( this == object ) {
return true;
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/BaseAbstractHandler.java (from rev 24244, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/BaseAbstractHandler.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/BaseAbstractHandler.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/BaseAbstractHandler.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,63 @@
+package org.drools.xml;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * 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.
+ */
+
+import java.util.Set;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @author mproctor
+ *
+ */
+public abstract class BaseAbstractHandler {
+ protected Set<Class<?>> validPeers;
+ protected Set<Class<?>> validParents;
+ protected boolean allowNesting;
+
+ public Set<Class<?>> getValidParents() {
+ return this.validParents;
+ }
+
+ public Set<Class<?>> getValidPeers() {
+ return this.validPeers;
+ }
+
+ public boolean allowNesting() {
+ return this.allowNesting;
+ }
+
+ public void emptyAttributeCheck(final String element,
+ final String attributeName,
+ final String attribute,
+ final ExtensibleXmlParser xmlPackageReader) throws SAXException {
+ if ( attribute == null || attribute.trim().equals( "" ) ) {
+ throw new SAXParseException( "<" + element + "> requires a '" + attributeName + "' attribute",
+ xmlPackageReader.getLocator() );
+ }
+ }
+
+ public void emptyContentCheck(final String element,
+ final String content,
+ final ExtensibleXmlParser xmlPackageReader) throws SAXException {
+ if ( content == null || content.trim().equals( "" ) ) {
+ throw new SAXParseException( "<" + element + "> requires content",
+ xmlPackageReader.getLocator() );
+ }
+ }
+}
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/BaseAbstractHandler.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/ChangeSetSemanticModule.java (from rev 24245, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ChangeSetSemanticModule.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/ChangeSetSemanticModule.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/ChangeSetSemanticModule.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package org.drools.xml;
+
+import org.drools.xml.changeset.AddHandler;
+import org.drools.xml.changeset.ChangeSetHandler;
+import org.drools.xml.changeset.DecisionTableConfigurationHandler;
+import org.drools.xml.changeset.ModifyHandler;
+import org.drools.xml.changeset.RemoveHandler;
+import org.drools.xml.changeset.ResourceHandler;
+
+public class ChangeSetSemanticModule extends DefaultSemanticModule implements SemanticModule {
+
+ public ChangeSetSemanticModule() {
+ super( "http://drools.org/drools-5.0/change-set" );
+
+ addHandler( "change-set",
+ new ChangeSetHandler() );
+
+ addHandler( "add",
+ new AddHandler() );
+
+ addHandler( "removed",
+ new RemoveHandler() );
+
+ addHandler( "modified",
+ new ModifyHandler() );
+
+ addHandler( "resource",
+ new ResourceHandler() );
+
+ addHandler( "decisiontable-conf",
+ new DecisionTableConfigurationHandler() );
+ }
+
+}
\ No newline at end of file
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/DefaultSemanticModule.java (from rev 24244, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/DefaultSemanticModule.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/DefaultSemanticModule.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/DefaultSemanticModule.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,43 @@
+package org.drools.xml;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class DefaultSemanticModule implements SemanticModule {
+ public String uri;
+ public Map<String, Handler> handlers;
+ public Map<Class<?>, Handler> handlersByClass;
+
+ public DefaultSemanticModule(String uri) {
+ this.uri = uri;
+ this.handlers = new HashMap<String, Handler>();
+ this.handlersByClass = new HashMap<Class<?>, Handler>();
+ }
+
+ public String getUri() {
+ return this.uri;
+ }
+
+ public void addHandler(String name, Handler handler) {
+ this.handlers.put( name, handler );
+ if (handler != null && handler.generateNodeFor() != null) {
+ this.handlersByClass.put( handler.generateNodeFor(), handler );
+ }
+ }
+
+ public Handler getHandler(String name) {
+ return this.handlers.get( name );
+ }
+
+ public Handler getHandlerByClass(Class<?> clazz) {
+ while (clazz != null) {
+ Handler handler = this.handlersByClass.get( clazz );
+ if (handler != null) {
+ return handler;
+ }
+ clazz = clazz.getSuperclass();
+ }
+ return null;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/DefaultSemanticModule.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/ExtensibleXmlParser.java (from rev 24245, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/ExtensibleXmlParser.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/ExtensibleXmlParser.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/ExtensibleXmlParser.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,751 @@
+package org.drools.xml;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * 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.
+ */
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URL;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * <code>RuleSet</code> loader.
+ *
+ * Note you can override the default entity resolver by setting the System property of:
+ * <code>org.drools.io.EntityResolve</code> to your own custom entity resolver.
+ * This can be done using -Dorg.drools.io.EntityResolver=YourClassHere on the command line, for instance.
+ *
+ * @author <a href="mailto:bob at werken.com">bob mcwhirter </a>
+ */
+public class ExtensibleXmlParser extends DefaultHandler {
+ // ----------------------------------------------------------------------
+ // Constants
+ // ----------------------------------------------------------------------
+ public static final String ENTITY_RESOLVER_PROPERTY_NAME = "org.drools.io.EntityResolver";
+
+ /** Namespace URI for the general tags. */
+ public static final String RULES_NAMESPACE_URI = "http://drools.org/rules";
+
+ private static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
+
+ private static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
+
+ // ----------------------------------------------------------------------
+ // Instance members
+ // ----------------------------------------------------------------------
+ /** SAX parser. */
+ private SAXParser parser;
+
+ /** isValidating */
+ private boolean isValidating = true;
+
+ /** Locator for errors. */
+ private Locator locator;
+
+ // private Map repo;
+
+ /** Stack of configurations. */
+ private LinkedList configurationStack;
+
+ /** Current configuration text. */
+ private StringBuilder characters;
+
+ private SemanticModules modules;
+
+ private boolean lastWasEndElement;
+
+ private LinkedList parents;
+
+ private Object peer;
+
+ private Object current;
+
+ private Object data;
+
+ private final MessageFormat message = new MessageFormat( "({0}: {1}, {2}): {3}" );
+
+ private final Map namespaces = new HashMap();
+
+ private EntityResolver entityResolver;
+
+ private Document document;
+ private DocumentFragment docFragment;
+
+ private ClassLoader classLoader;
+
+ // ----------------------------------------------------------------------
+ // Constructors
+ // ----------------------------------------------------------------------
+
+ /**
+ * Construct.
+ *
+ * <p>
+ * Uses the default JAXP SAX parser and the default classpath-based
+ * <code>DefaultSemanticModule</code>.
+ * </p>
+ */
+ public ExtensibleXmlParser() {
+ // init
+ this.configurationStack = new LinkedList();
+ this.parents = new LinkedList();
+
+ initEntityResolver();
+ }
+
+ public void setSemanticModules(SemanticModules modules) {
+ this.modules = modules;
+ }
+
+ /**
+ * Construct.
+ *
+ * <p>
+ * Uses the default classpath-based <code>DefaultSemanticModule</code>.
+ * </p>
+ *
+ * @param parser
+ * The SAX parser.
+ */
+ public ExtensibleXmlParser(final SAXParser parser) {
+ this();
+ this.parser = parser;
+ }
+
+ // ----------------------------------------------------------------------
+ // Instance methods
+ // ----------------------------------------------------------------------
+
+ /**
+ * Read a <code>RuleSet</code> from a <code>Reader</code>.
+ *
+ * @param reader
+ * The reader containing the rule-set.
+ *
+ * @return The rule-set.
+ * @throws ParserConfigurationException
+ */
+ public Object read(final Reader reader) throws SAXException,
+ IOException {
+ return read( new InputSource( reader ) );
+ }
+
+ /**
+ * Read a <code>RuleSet</code> from an <code>InputStream</code>.
+ *
+ * @param inputStream
+ * The input-stream containing the rule-set.
+ *
+ * @return The rule-set.
+ * @throws ParserConfigurationException
+ */
+ public Object read(final InputStream inputStream) throws SAXException,
+ IOException {
+ return read( new InputSource( inputStream ) );
+ }
+
+ /**
+ * Read a <code>RuleSet</code> from an <code>InputSource</code>.
+ *
+ * @param in
+ * The rule-set input-source.
+ *
+ * @return The rule-set.
+ * @throws ParserConfigurationException
+ */
+ public Object read(final InputSource in) throws SAXException,
+ IOException {
+ if ( this.docFragment == null ) {
+ try {
+ this.document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ } catch ( ParserConfigurationException e ) {
+ throw new RuntimeException( "Unable to create new DOM Document" );
+ }
+ this.docFragment = this.document.createDocumentFragment();
+ }
+
+ SAXParser localParser = null;
+ if ( this.parser == null ) {
+ final SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware( true );
+
+ final String isValidatingString = System.getProperty( "drools.schema.validating" );
+ if ( System.getProperty( "drools.schema.validating" ) != null ) {
+ this.isValidating = Boolean.getBoolean( "drools.schema.validating" );
+ }
+
+ if ( this.isValidating == true ) {
+ factory.setValidating( true );
+ try {
+ localParser = factory.newSAXParser();
+ } catch ( final ParserConfigurationException e ) {
+ throw new RuntimeException( e.getMessage() );
+ }
+
+ try {
+ localParser.setProperty( ExtensibleXmlParser.JAXP_SCHEMA_LANGUAGE,
+ ExtensibleXmlParser.W3C_XML_SCHEMA );
+ } catch ( final SAXNotRecognizedException e ) {
+ boolean hideWarnings = Boolean.getBoolean( "drools.schema.hidewarnings" );
+ if ( !hideWarnings ) {
+ System.err.println( "Your SAX parser is not JAXP 1.2 compliant - turning off validation." );
+ }
+ localParser = null;
+ }
+ }
+
+ if ( localParser == null ) {
+ // not jaxp1.2 compliant so turn off validation
+ try {
+ this.isValidating = false;
+ factory.setValidating( this.isValidating );
+ localParser = factory.newSAXParser();
+ } catch ( final ParserConfigurationException e ) {
+ throw new RuntimeException( e.getMessage() );
+ }
+ }
+ } else {
+ localParser = this.parser;
+ }
+
+ if ( !localParser.isNamespaceAware() ) {
+ throw new RuntimeException( "parser must be namespace-aware" );
+ }
+
+ localParser.parse( in,
+ this );
+
+ return this.data;
+ }
+
+ public void setData(final Object data) {
+ this.data = data;
+ }
+
+ public Object getData() {
+ return this.data;
+ }
+
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ public void setClassLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+ /**
+ * @see org.xml.sax.ContentHandler
+ */
+ public void setDocumentLocator(final Locator locator) {
+ this.locator = locator;
+ }
+
+ /**
+ * Get the <code>Locator</code>.
+ *
+ * @return The locator.
+ */
+ public Locator getLocator() {
+ return this.locator;
+ }
+
+ public void startDocument() {
+ this.isValidating = true;
+ this.current = null;
+ this.peer = null;
+ this.lastWasEndElement = false;
+ this.parents.clear();
+ this.characters = null;
+ this.configurationStack.clear();
+ this.namespaces.clear();
+ }
+
+ private int direction = 0;
+
+ /**
+ * @param uri
+ * @param localName
+ * @param qname
+ * @param attrs
+ * @throws SAXException
+ * @see org.xml.sax.ContentHandler
+ *
+ * @todo: better way to manage unhandled elements
+ */
+ public void startElement(final String uri,
+ final String localName,
+ final String qname,
+ final Attributes attrs) throws SAXException {
+ if ( direction == 1 ) {
+ // going down again, so clear
+ this.peer = null;
+ } else {
+ direction = 1;
+ }
+
+ final Handler handler = getHandler( uri,
+ localName );
+
+ if ( handler == null ) {
+ startElementBuilder( localName,
+ attrs );
+ return;
+ }
+
+ validate( uri,
+ localName,
+ handler );
+
+ final Object node = handler.start( uri,
+ localName,
+ attrs,
+ this );
+
+ if ( node == null ) {
+ this.parents.add( Null.instance );
+ } else {
+ this.parents.add( node );
+ }
+ }
+
+ /**
+ * @param uri
+ * @param localName
+ * @param qname
+ * @throws SAXException
+ * @see org.xml.sax.ContentHandler
+ */
+
+ public void endElement(final String uri,
+ final String localName,
+ final String qname) throws SAXException {
+ direction = -1;
+ final Handler handler = getHandler( uri,
+ localName );
+
+ if ( handler == null ) {
+ if ( this.configurationStack.size() >= 1 ) {
+ endElementBuilder();
+ }
+ return;
+ }
+
+ this.current = removeParent();
+
+ this.peer = handler.end( uri,
+ localName,
+ this );
+ }
+
+ public static class Null {
+ public static final Null instance = new Null();
+ }
+
+ private void validate(final String uri,
+ final String localName,
+ final Handler handler) throws SAXParseException {
+ boolean validParent = false;
+ boolean validPeer = false;
+ boolean invalidNesting = false;
+
+ final Set validParents = handler.getValidParents();
+ final Set validPeers = handler.getValidPeers();
+ boolean allowNesting = handler.allowNesting();
+
+ // get parent
+ Object parent;
+ if ( this.parents.size() != 0 ) {
+ parent = this.parents.getLast();
+ } else {
+ parent = null;
+ }
+
+ // check valid parents
+ // null parent means localname is rule-set
+ // dont process if elements are the same
+ // instead check for allowed nesting
+ final Class nodeClass = getHandler( uri,
+ localName ).generateNodeFor();
+ if ( nodeClass != null && !nodeClass.isInstance( parent ) ) {
+ Object allowedParent;
+ final Iterator it = validParents.iterator();
+ while ( !validParent && it.hasNext() ) {
+ allowedParent = it.next();
+ if ( parent == null && allowedParent == null ) {
+ validParent = true;
+ } else if ( allowedParent != null && ((Class) allowedParent).isInstance( parent ) ) {
+ validParent = true;
+ }
+ }
+ if ( !validParent ) {
+ throw new SAXParseException( "<" + localName + "> has an invalid parent element [" + parent + "]",
+ getLocator() );
+ }
+ }
+
+ // check valid peers
+ // null peer means localname is rule-set
+ final Object peer = this.peer;
+
+ Object allowedPeer;
+ Iterator it = validPeers.iterator();
+ while ( !validPeer && it.hasNext() ) {
+ allowedPeer = it.next();
+ if ( peer == null && allowedPeer == null ) {
+ validPeer = true;
+ } else if ( allowedPeer != null && ((Class) allowedPeer).isInstance( peer ) ) {
+ validPeer = true;
+ }
+ }
+ if ( !validPeer ) {
+ throw new SAXParseException( "<" + localName + "> is after an invalid element: " + Handler.class.getName(),
+ getLocator() );
+ }
+
+ if ( nodeClass != null && !allowNesting ) {
+ it = this.parents.iterator();
+ while ( !invalidNesting && it.hasNext() ) {
+ if ( nodeClass.isInstance( it.next() ) ) {
+ invalidNesting = true;
+ }
+ }
+ }
+ if ( invalidNesting ) {
+ throw new SAXParseException( "<" + localName + "> may not be nested",
+ getLocator() );
+ }
+
+ }
+
+ /**
+ * Start a configuration node.
+ *
+ * @param name
+ * Tag name.
+ * @param attrs
+ * Tag attributes.
+ */
+ public void startElementBuilder(final String tagName,
+ final Attributes attrs) {
+ this.characters = new StringBuilder();
+
+
+ final Element element = this.document.createElement( tagName );
+
+ //final DefaultConfiguration config = new DefaultConfiguration( tagName );
+
+ final int numAttrs = attrs.getLength();
+
+ for ( int i = 0; i < numAttrs; ++i ) {
+ element.setAttribute( attrs.getLocalName( i ),
+ attrs.getValue( i ) );
+ }
+
+// // lets add the namespaces as attributes
+// for ( final Iterator iter = this.namespaces.entrySet().iterator(); iter.hasNext(); ) {
+// final Map.Entry entry = (Map.Entry) iter.next();
+// String ns = (String) entry.getKey();
+// final String value = (String) entry.getValue();
+// if ( ns == null || ns.length() == 0 ) {
+// ns = "xmlns";
+// } else {
+// ns = "xmlns:" + ns;
+// }
+// config.setAttribute( ns,
+// value );
+// }
+
+ if ( this.configurationStack.isEmpty() ) {
+ this.configurationStack.addLast( element );
+ } else {
+ ((Element) this.configurationStack.getLast()).appendChild( element );
+ this.configurationStack.addLast( element );
+ }
+ }
+
+ Handler getHandler(final String uri,
+ final String localName) {
+ SemanticModule module = this.modules.getSemanticModule( uri );
+ if ( module != null ) {
+ return module.getHandler( localName );
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * @param chars
+ * @param start
+ * @param len
+ * @see org.xml.sax.ContentHandler
+ */
+ public void characters(final char[] chars,
+ final int start,
+ final int len) {
+ if ( this.characters != null ) {
+ this.characters.append( chars,
+ start,
+ len );
+ }
+ }
+
+ /**
+ * End a configuration node.
+ *
+ * @return The configuration.
+ */
+ public Element endElementBuilder() {
+ final Element element = (Element) this.configurationStack.removeLast();
+ if ( this.characters != null ) {
+ element.appendChild( this.document.createTextNode( this.characters.toString() ) );
+ }
+
+ this.characters = null;
+
+ return element;
+ }
+
+ public Object getParent() {
+ return this.parents.getLast();
+ }
+
+ public Object getParent(int index) {
+ ListIterator it = this.parents.listIterator( this.parents.size() );
+ int x = 0;
+ Object parent = null;
+ while ( x++ <= index ) {
+ parent = it.previous();
+ }
+ return parent;
+ }
+
+ public Object removeParent() {
+ Object parent = this.parents.removeLast();
+ while ( parent == null && !this.parents.isEmpty() ) {
+ parent = this.parents.removeLast();
+ }
+ return parent;
+ }
+
+ public LinkedList getParents() {
+ return this.parents;
+ }
+
+ public Object getParent(final Class parent) {
+ final ListIterator it = this.parents.listIterator( this.parents.size() );
+ Object node = null;
+ while ( it.hasPrevious() ) {
+ node = it.previous();
+ if ( parent.isInstance( node ) ) {
+ break;
+ }
+ }
+ return node;
+ }
+
+ public Object getPeer() {
+ return this.peer;
+ }
+
+ public Object getCurrent() {
+ return this.current;
+ }
+
+ public InputSource resolveEntity(final String publicId,
+ final String systemId) throws SAXException {
+ try {
+ final InputSource inputSource = resolveSchema( publicId,
+ systemId );
+ if ( inputSource != null ) {
+ return inputSource;
+ }
+ if ( this.entityResolver != null ) {
+ return this.entityResolver.resolveEntity( publicId,
+ systemId );
+ }
+ } catch ( final IOException ioe ) {
+ }
+ return null;
+ }
+
+ public void startPrefixMapping(final String prefix,
+ final String uri) throws SAXException {
+ super.startPrefixMapping( prefix,
+ uri );
+ this.namespaces.put( prefix,
+ uri );
+ }
+
+ public void endPrefixMapping(final String prefix) throws SAXException {
+ super.endPrefixMapping( prefix );
+ this.namespaces.remove( prefix );
+ }
+
+ private void print(final SAXParseException x) {
+ final String msg = this.message.format( new Object[]{x.getSystemId(), new Integer( x.getLineNumber() ), new Integer( x.getColumnNumber() ), x.getMessage()} );
+ System.out.println( msg );
+ }
+
+ public void warning(final SAXParseException x) {
+ print( x );
+ }
+
+ public void error(final SAXParseException x) {
+ print( x );
+ }
+
+ public void fatalError(final SAXParseException x) throws SAXParseException {
+ print( x );
+ throw x;
+ }
+
+ private InputSource resolveSchema(final String publicId,
+ final String systemId) throws SAXException,
+ IOException {
+ // Schema files must end with xsd
+ if ( !systemId.toLowerCase().endsWith( "xsd" ) ) {
+ return null;
+ }
+
+ // try the actual location given by systemId
+ try {
+ final URL url = new URL( systemId );
+ return new InputSource( url.openStream() );
+ } catch ( final Exception e ) {
+ }
+
+ // Try and get the index for the filename, else return null
+ String xsd;
+ int index = systemId.lastIndexOf( "/" );
+ if ( index == -1 ) {
+ index = systemId.lastIndexOf( "\\" );
+ }
+ if ( index != -1 ) {
+ xsd = systemId.substring( index + 1 );
+ } else {
+ xsd = systemId;
+ }
+
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+ if ( cl == null ) {
+ cl = ExtensibleXmlParser.class.getClassLoader();
+ }
+
+ // Try looking in META-INF
+ {
+ final InputStream is = cl.getResourceAsStream( "META-INF/" + xsd );
+ if ( is != null ) {
+ return new InputSource( is );
+ }
+ }
+
+ // Try looking in /META-INF
+ {
+ final InputStream is = cl.getResourceAsStream( "/META-INF/" + xsd );
+ if ( is != null ) {
+ return new InputSource( is );
+ }
+ }
+
+ // Try looking at root of classpath
+ {
+ final InputStream is = cl.getResourceAsStream( "/" + xsd );
+ if ( is != null ) {
+ return new InputSource( is );
+ }
+ }
+
+ // Try current working directory
+ {
+ final File file = new File( xsd );
+ if ( file.exists() ) {
+ return new InputSource( new BufferedInputStream( new FileInputStream( file ) ) );
+ }
+ }
+
+ cl = ClassLoader.getSystemClassLoader();
+
+ // Try looking in META-INF
+ {
+ final InputStream is = cl.getResourceAsStream( "META-INF/" + xsd );
+ if ( is != null ) {
+ return new InputSource( is );
+ }
+ }
+
+ // Try looking in /META-INF
+ {
+ final InputStream is = cl.getResourceAsStream( "/META-INF/" + xsd );
+ if ( is != null ) {
+ return new InputSource( is );
+ }
+ }
+
+ // Try looking at root of classpath
+ {
+ final InputStream is = cl.getResourceAsStream( "/" + xsd );
+ if ( is != null ) {
+ return new InputSource( is );
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Intializes EntityResolver that is configured via system property ENTITY_RESOLVER_PROPERTY_NAME.
+ */
+ private void initEntityResolver() {
+ final String entityResolveClazzName = System.getProperty( ExtensibleXmlParser.ENTITY_RESOLVER_PROPERTY_NAME );
+ if ( entityResolveClazzName != null && entityResolveClazzName.length() > 0 ) {
+ try {
+ final Class entityResolverClazz = Thread.currentThread().getContextClassLoader().loadClass( entityResolveClazzName );
+ this.entityResolver = (EntityResolver) entityResolverClazz.newInstance();
+ } catch ( final Exception ignoreIt ) {
+ }
+ }
+ }
+
+}
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/ExtensibleXmlParser.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/Handler.java (from rev 24244, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/Handler.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/Handler.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/Handler.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,46 @@
+package org.drools.xml;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * 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.
+ */
+
+import java.util.Set;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * @author mproctor
+ *
+ */
+public interface Handler {
+
+ Object start(String uri,
+ String localName,
+ Attributes attrs,
+ ExtensibleXmlParser xmlPackageReader) throws SAXException;
+
+ Object end(String uri,
+ String localName,
+ ExtensibleXmlParser xmlPackageReader) throws SAXException;
+
+ Set<Class<?>> getValidParents();
+
+ Set<Class<?>> getValidPeers();
+
+ boolean allowNesting();
+
+ Class<?> generateNodeFor();
+}
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/Handler.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/SemanticModule.java (from rev 24244, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/SemanticModule.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/SemanticModule.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/SemanticModule.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,11 @@
+package org.drools.xml;
+
+public interface SemanticModule {
+ public String getUri();
+
+ public void addHandler(String name, Handler handler);
+
+ public Handler getHandler(String name);
+
+ public Handler getHandlerByClass(Class<?> clazz);
+}
Property changes on: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/SemanticModule.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/SemanticModules.java (from rev 24244, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/SemanticModules.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/SemanticModules.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/SemanticModules.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,26 @@
+
+package org.drools.xml;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class SemanticModules {
+ public Map<String, SemanticModule> modules;
+
+ public SemanticModules() {
+ this.modules = new HashMap<String, SemanticModule>();
+ }
+
+ public void addSemanticModule(SemanticModule module) {
+ this.modules.put( module.getUri(),
+ module );
+ }
+
+ public SemanticModule getSemanticModule(String uri) {
+ return this.modules.get( uri );
+ }
+
+ public String toString() {
+ return this.modules.toString();
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/SemanticModules.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/XmlChangeSetReader.java (from rev 24245, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/XmlChangeSetReader.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/XmlChangeSetReader.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/XmlChangeSetReader.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,76 @@
+package org.drools.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import javax.xml.parsers.SAXParser;
+
+import org.drools.ChangeSet;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+
+public class XmlChangeSetReader {
+ private ExtensibleXmlParser parser;
+
+ public XmlChangeSetReader(final SemanticModules modules) {
+ this( modules, null );
+ }
+
+ public XmlChangeSetReader(final SemanticModules modules, final SAXParser parser) {
+ if ( parser == null ) {
+ this.parser = new ExtensibleXmlParser();
+ } else {
+ this.parser = new ExtensibleXmlParser( parser );
+ }
+ this.parser.setSemanticModules( modules );
+ }
+
+ public void setClassLoader(ClassLoader classLoader) {
+ this.parser.setClassLoader( classLoader );
+ }
+
+ public ExtensibleXmlParser getParser() {
+ return this.parser;
+ }
+
+ /**
+ * Read a <code>RuleSet</code> from a <code>Reader</code>.
+ *
+ * @param reader
+ * The reader containing the rule-set.
+ *
+ * @return The rule-set.
+ */
+ public ChangeSet read(final Reader reader) throws SAXException,
+ IOException {
+ return (ChangeSet) this.parser.read( reader );
+ }
+
+ /**
+ * Read a <code>RuleSet</code> from an <code>InputStream</code>.
+ *
+ * @param inputStream
+ * The input-stream containing the rule-set.
+ *
+ * @return The rule-set.
+ */
+ public ChangeSet read(final InputStream inputStream) throws SAXException,
+ IOException {
+ return (ChangeSet) this.parser.read( inputStream );
+ }
+
+ /**
+ * Read a <code>RuleSet</code> from an <code>InputSource</code>.
+ *
+ * @param in
+ * The rule-set input-source.
+ *
+ * @return The rule-set.
+ */
+ public ChangeSet read(final InputSource in) throws SAXException,
+ IOException {
+ return (ChangeSet) this.parser.read( in );
+ }
+}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset (from rev 24245, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset)
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/AddHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/AddHandler.java 2008-12-05 09:57:53 UTC (rev 24245)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/AddHandler.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,68 +0,0 @@
-package org.drools.xml.changeset;
-
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.drools.ChangeSet;
-import org.drools.builder.KnowledgeType;
-import org.drools.io.Resource;
-import org.drools.io.impl.ChangeSetImpl;
-import org.drools.io.impl.ClassPathResource;
-import org.drools.io.impl.KnowledgeResource;
-import org.drools.io.impl.UrlResource;
-import org.drools.util.StringUtils;
-import org.drools.xml.BaseAbstractHandler;
-import org.drools.xml.ExtensibleXmlParser;
-import org.drools.xml.Handler;
-import org.w3c.dom.Element;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-public class AddHandler extends BaseAbstractHandler
- implements
- Handler {
-
- public AddHandler() {
- if ( (this.validParents == null) && (this.validPeers == null) ) {
- this.validParents = new HashSet(1);
- this.validParents.add( ChangeSet.class );
-
- this.validPeers = new HashSet(2);
- this.validPeers.add( null );
- this.validPeers.add( Collection.class );
-
- this.allowNesting = true;
- }
- }
-
- public Object start(String uri,
- String localName,
- Attributes attrs,
- ExtensibleXmlParser parser) throws SAXException {
- parser.startElementBuilder( localName,
- attrs );
-
- final ChangeSet changeSet = (ChangeSet) parser.getParent();
-
- return new ArrayList();
- }
-
- public Object end(String uri,
- String localName,
- ExtensibleXmlParser parser) throws SAXException {
- final Element element = parser.endElementBuilder();
-
- final ChangeSetImpl changeSet = (ChangeSetImpl) parser.getParent();
- final Collection add = ( Collection ) parser.getCurrent();
- changeSet.setResourcesAdded( add );
- return add;
- }
-
-
- public Class< ? > generateNodeFor() {
- return Collection.class;
- }
-
-}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/AddHandler.java (from rev 24247, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/AddHandler.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/AddHandler.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/AddHandler.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,68 @@
+package org.drools.xml.changeset;
+
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.drools.ChangeSet;
+import org.drools.builder.ResourceType;
+import org.drools.io.Resource;
+import org.drools.io.impl.ChangeSetImpl;
+import org.drools.io.impl.ClassPathResource;
+import org.drools.io.impl.KnowledgeResource;
+import org.drools.io.impl.UrlResource;
+import org.drools.util.StringUtils;
+import org.drools.xml.BaseAbstractHandler;
+import org.drools.xml.ExtensibleXmlParser;
+import org.drools.xml.Handler;
+import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+public class AddHandler extends BaseAbstractHandler
+ implements
+ Handler {
+
+ public AddHandler() {
+ if ( (this.validParents == null) && (this.validPeers == null) ) {
+ this.validParents = new HashSet(1);
+ this.validParents.add( ChangeSet.class );
+
+ this.validPeers = new HashSet(2);
+ this.validPeers.add( null );
+ this.validPeers.add( Collection.class );
+
+ this.allowNesting = true;
+ }
+ }
+
+ public Object start(String uri,
+ String localName,
+ Attributes attrs,
+ ExtensibleXmlParser parser) throws SAXException {
+ parser.startElementBuilder( localName,
+ attrs );
+
+ final ChangeSet changeSet = (ChangeSet) parser.getParent();
+
+ return new ArrayList();
+ }
+
+ public Object end(String uri,
+ String localName,
+ ExtensibleXmlParser parser) throws SAXException {
+ final Element element = parser.endElementBuilder();
+
+ final ChangeSetImpl changeSet = (ChangeSetImpl) parser.getParent();
+ final Collection add = ( Collection ) parser.getCurrent();
+ changeSet.setResourcesAdded( add );
+ return add;
+ }
+
+
+ public Class< ? > generateNodeFor() {
+ return Collection.class;
+ }
+
+}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ModifyHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/ModifyHandler.java 2008-12-05 09:57:53 UTC (rev 24245)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ModifyHandler.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,68 +0,0 @@
-package org.drools.xml.changeset;
-
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.drools.ChangeSet;
-import org.drools.builder.KnowledgeType;
-import org.drools.io.Resource;
-import org.drools.io.impl.ChangeSetImpl;
-import org.drools.io.impl.ClassPathResource;
-import org.drools.io.impl.KnowledgeResource;
-import org.drools.io.impl.UrlResource;
-import org.drools.util.StringUtils;
-import org.drools.xml.BaseAbstractHandler;
-import org.drools.xml.ExtensibleXmlParser;
-import org.drools.xml.Handler;
-import org.w3c.dom.Element;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-public class ModifyHandler extends BaseAbstractHandler
- implements
- Handler {
-
- public ModifyHandler() {
- if ( (this.validParents == null) && (this.validPeers == null) ) {
- this.validParents = new HashSet(1);
- this.validParents.add( ChangeSet.class );
-
- this.validPeers = new HashSet(2);
- this.validPeers.add( null );
- this.validPeers.add( Collection.class );
-
- this.allowNesting = true;
- }
- }
-
- public Object start(String uri,
- String localName,
- Attributes attrs,
- ExtensibleXmlParser parser) throws SAXException {
- parser.startElementBuilder( localName,
- attrs );
-
- final ChangeSet changeSet = (ChangeSet) parser.getParent();
-
- return new ArrayList();
- }
-
- public Object end(String uri,
- String localName,
- ExtensibleXmlParser parser) throws SAXException {
- final Element element = parser.endElementBuilder();
-
- final ChangeSetImpl changeSet = (ChangeSetImpl) parser.getParent();
- final Collection modified = ( Collection ) parser.getCurrent();
- changeSet.setResourcesModified( modified );
- return modified;
- }
-
-
- public Class< ? > generateNodeFor() {
- return Collection.class;
- }
-
-}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ModifyHandler.java (from rev 24247, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/ModifyHandler.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ModifyHandler.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ModifyHandler.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,68 @@
+package org.drools.xml.changeset;
+
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.drools.ChangeSet;
+import org.drools.builder.ResourceType;
+import org.drools.io.Resource;
+import org.drools.io.impl.ChangeSetImpl;
+import org.drools.io.impl.ClassPathResource;
+import org.drools.io.impl.KnowledgeResource;
+import org.drools.io.impl.UrlResource;
+import org.drools.util.StringUtils;
+import org.drools.xml.BaseAbstractHandler;
+import org.drools.xml.ExtensibleXmlParser;
+import org.drools.xml.Handler;
+import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+public class ModifyHandler extends BaseAbstractHandler
+ implements
+ Handler {
+
+ public ModifyHandler() {
+ if ( (this.validParents == null) && (this.validPeers == null) ) {
+ this.validParents = new HashSet(1);
+ this.validParents.add( ChangeSet.class );
+
+ this.validPeers = new HashSet(2);
+ this.validPeers.add( null );
+ this.validPeers.add( Collection.class );
+
+ this.allowNesting = true;
+ }
+ }
+
+ public Object start(String uri,
+ String localName,
+ Attributes attrs,
+ ExtensibleXmlParser parser) throws SAXException {
+ parser.startElementBuilder( localName,
+ attrs );
+
+ final ChangeSet changeSet = (ChangeSet) parser.getParent();
+
+ return new ArrayList();
+ }
+
+ public Object end(String uri,
+ String localName,
+ ExtensibleXmlParser parser) throws SAXException {
+ final Element element = parser.endElementBuilder();
+
+ final ChangeSetImpl changeSet = (ChangeSetImpl) parser.getParent();
+ final Collection modified = ( Collection ) parser.getCurrent();
+ changeSet.setResourcesModified( modified );
+ return modified;
+ }
+
+
+ public Class< ? > generateNodeFor() {
+ return Collection.class;
+ }
+
+}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/RemoveHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/RemoveHandler.java 2008-12-05 09:57:53 UTC (rev 24245)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/RemoveHandler.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,68 +0,0 @@
-package org.drools.xml.changeset;
-
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.drools.ChangeSet;
-import org.drools.builder.KnowledgeType;
-import org.drools.io.Resource;
-import org.drools.io.impl.ChangeSetImpl;
-import org.drools.io.impl.ClassPathResource;
-import org.drools.io.impl.KnowledgeResource;
-import org.drools.io.impl.UrlResource;
-import org.drools.util.StringUtils;
-import org.drools.xml.BaseAbstractHandler;
-import org.drools.xml.ExtensibleXmlParser;
-import org.drools.xml.Handler;
-import org.w3c.dom.Element;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-public class RemoveHandler extends BaseAbstractHandler
- implements
- Handler {
-
- public RemoveHandler() {
- if ( (this.validParents == null) && (this.validPeers == null) ) {
- this.validParents = new HashSet(1);
- this.validParents.add( ChangeSet.class );
-
- this.validPeers = new HashSet(2);
- this.validPeers.add( null );
- this.validPeers.add( Collection.class );
-
- this.allowNesting = true;
- }
- }
-
- public Object start(String uri,
- String localName,
- Attributes attrs,
- ExtensibleXmlParser parser) throws SAXException {
- parser.startElementBuilder( localName,
- attrs );
-
- final ChangeSet changeSet = (ChangeSet) parser.getParent();
-
- return new ArrayList();
- }
-
- public Object end(String uri,
- String localName,
- ExtensibleXmlParser parser) throws SAXException {
- final Element element = parser.endElementBuilder();
-
- final ChangeSetImpl changeSet = (ChangeSetImpl) parser.getParent();
- final Collection removed = ( Collection ) parser.getCurrent();
- changeSet.setResourcesRemoved( removed );
- return removed;
- }
-
-
- public Class< ? > generateNodeFor() {
- return Collection.class;
- }
-
-}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/RemoveHandler.java (from rev 24247, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/RemoveHandler.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/RemoveHandler.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/RemoveHandler.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,68 @@
+package org.drools.xml.changeset;
+
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.drools.ChangeSet;
+import org.drools.builder.ResourceType;
+import org.drools.io.Resource;
+import org.drools.io.impl.ChangeSetImpl;
+import org.drools.io.impl.ClassPathResource;
+import org.drools.io.impl.KnowledgeResource;
+import org.drools.io.impl.UrlResource;
+import org.drools.util.StringUtils;
+import org.drools.xml.BaseAbstractHandler;
+import org.drools.xml.ExtensibleXmlParser;
+import org.drools.xml.Handler;
+import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+public class RemoveHandler extends BaseAbstractHandler
+ implements
+ Handler {
+
+ public RemoveHandler() {
+ if ( (this.validParents == null) && (this.validPeers == null) ) {
+ this.validParents = new HashSet(1);
+ this.validParents.add( ChangeSet.class );
+
+ this.validPeers = new HashSet(2);
+ this.validPeers.add( null );
+ this.validPeers.add( Collection.class );
+
+ this.allowNesting = true;
+ }
+ }
+
+ public Object start(String uri,
+ String localName,
+ Attributes attrs,
+ ExtensibleXmlParser parser) throws SAXException {
+ parser.startElementBuilder( localName,
+ attrs );
+
+ final ChangeSet changeSet = (ChangeSet) parser.getParent();
+
+ return new ArrayList();
+ }
+
+ public Object end(String uri,
+ String localName,
+ ExtensibleXmlParser parser) throws SAXException {
+ final Element element = parser.endElementBuilder();
+
+ final ChangeSetImpl changeSet = (ChangeSetImpl) parser.getParent();
+ final Collection removed = ( Collection ) parser.getCurrent();
+ changeSet.setResourcesRemoved( removed );
+ return removed;
+ }
+
+
+ public Class< ? > generateNodeFor() {
+ return Collection.class;
+ }
+
+}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ResourceHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/ResourceHandler.java 2008-12-05 09:57:53 UTC (rev 24245)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ResourceHandler.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -1,86 +0,0 @@
-package org.drools.xml.changeset;
-
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.drools.builder.KnowledgeType;
-import org.drools.io.InternalResource;
-import org.drools.io.Resource;
-import org.drools.io.impl.ClassPathResource;
-import org.drools.io.impl.KnowledgeResource;
-import org.drools.io.impl.UrlResource;
-import org.drools.xml.BaseAbstractHandler;
-import org.drools.xml.ExtensibleXmlParser;
-import org.drools.xml.Handler;
-import org.w3c.dom.Element;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-public class ResourceHandler extends BaseAbstractHandler
- implements
- Handler {
-
- public ResourceHandler() {
- if ( (this.validParents == null) && (this.validPeers == null) ) {
- this.validParents = new HashSet(1);
- this.validParents.add( Collection.class );
-
- this.validPeers = new HashSet(2);
- this.validPeers.add( null );
- this.validPeers.add( Resource.class );
-
- this.allowNesting = true;
- }
- }
-
- public Object start(String uri,
- String localName,
- Attributes attrs,
- ExtensibleXmlParser parser) throws SAXException {
- parser.startElementBuilder( localName,
- attrs );
-
- final Collection collection = (Collection) parser.getParent();
-
- String src = attrs.getValue( "source" );
- String type = attrs.getValue( "type" );
-
- emptyAttributeCheck( localName,
- "source",
- src,
- parser );
-
- emptyAttributeCheck( localName,
- "type",
- type,
- parser );
- InternalResource resource = null;
-
- if ( src.trim().startsWith( "classpath:" ) ) {
- resource = new ClassPathResource( src.substring( src.indexOf( ':' ) + 1 ), parser.getClassLoader() );
- } else {
- resource = new UrlResource( src );
- }
-
- resource.setKnowledgeType( KnowledgeType.valueOf( type ) );
-
- return resource;
- }
-
- public Object end(String uri,
- String localName,
- ExtensibleXmlParser parser) throws SAXException {
- final Element element = parser.endElementBuilder();
-
- final Collection collection = (Collection) parser.getParent();
- final Resource resource = ( Resource ) parser.getCurrent();
- collection.add( resource );
- return resource;
- }
-
-
- public Class< ? > generateNodeFor() {
- return KnowledgeResource.class;
- }
-
-}
Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ResourceHandler.java (from rev 24247, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/xml/changeset/ResourceHandler.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ResourceHandler.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/xml/changeset/ResourceHandler.java 2008-12-06 05:25:09 UTC (rev 24263)
@@ -0,0 +1,86 @@
+package org.drools.xml.changeset;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.drools.builder.ResourceType;
+import org.drools.io.InternalResource;
+import org.drools.io.Resource;
+import org.drools.io.impl.ClassPathResource;
+import org.drools.io.impl.KnowledgeResource;
+import org.drools.io.impl.UrlResource;
+import org.drools.xml.BaseAbstractHandler;
+import org.drools.xml.ExtensibleXmlParser;
+import org.drools.xml.Handler;
+import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+public class ResourceHandler extends BaseAbstractHandler
+ implements
+ Handler {
+
+ public ResourceHandler() {
+ if ( (this.validParents == null) && (this.validPeers == null) ) {
+ this.validParents = new HashSet(1);
+ this.validParents.add( Collection.class );
+
+ this.validPeers = new HashSet(2);
+ this.validPeers.add( null );
+ this.validPeers.add( Resource.class );
+
+ this.allowNesting = true;
+ }
+ }
+
+ public Object start(String uri,
+ String localName,
+ Attributes attrs,
+ ExtensibleXmlParser parser) throws SAXException {
+ parser.startElementBuilder( localName,
+ attrs );
+
+ final Collection collection = (Collection) parser.getParent();
+
+ String src = attrs.getValue( "source" );
+ String type = attrs.getValue( "type" );
+
+ emptyAttributeCheck( localName,
+ "source",
+ src,
+ parser );
+
+ emptyAttributeCheck( localName,
+ "type",
+ type,
+ parser );
+ InternalResource resource = null;
+
+ if ( src.trim().startsWith( "classpath:" ) ) {
+ resource = new ClassPathResource( src.substring( src.indexOf( ':' ) + 1 ), parser.getClassLoader() );
+ } else {
+ resource = new UrlResource( src );
+ }
+
+ resource.setResourceType( ResourceType.valueOf( type ) );
+
+ return resource;
+ }
+
+ public Object end(String uri,
+ String localName,
+ ExtensibleXmlParser parser) throws SAXException {
+ final Element element = parser.endElementBuilder();
+
+ final Collection collection = (Collection) parser.getParent();
+ final Resource resource = ( Resource ) parser.getCurrent();
+ collection.add( resource );
+ return resource;
+ }
+
+
+ public Class< ? > generateNodeFor() {
+ return KnowledgeResource.class;
+ }
+
+}
More information about the jboss-svn-commits
mailing list