[rules-users] KnowledgeAgent Changeset problems

albertorugnone arugnonechemical at gmail.com
Wed Feb 29 07:52:27 EST 2012


Hi all,
I have  some problem with KnowledgeAgent, maybe you can help me. I will list
these in the following
1)  during change set loading I have the following error
(null: 1, 207): schema_reference.4: Failed to read schema document
'drools-change-set-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 1, 207): cvc-elt.1: Cannot find the declaration of element
'change-set'.
(null: 1, 216): schema_reference.4: Failed to read schema document
'drools-change-set-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 1, 311): schema_reference.4: Failed to read schema document
'drools-change-set-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>

I suppose this is because change-set.xml can be reached. What is a correct
setting for xs:schemaLocation.

2) I would like scan also a directories in order to add knowledge to my rule
set if I add a new file. How I can do that?
3) KnowledgeAgentConfiguration aconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
aconf.setProperty("drools.agent.newInstance", "true") <== what is the
meaning of this property? Where I can find documentation about those
properties
4) why when I would set a global variable I receive
Exception in thread "main" java.lang.RuntimeException: Unexpected global
[service]
	at
org.drools.common.AbstractWorkingMemory.setGlobal(AbstractWorkingMemory.java:615)
	at
org.drools.impl.StatefulKnowledgeSessionImpl.setGlobal(StatefulKnowledgeSessionImpl.java:332)
	at
com.sample.DroolsKnowledgeAgentTest.main(DroolsKnowledgeAgentTest.java:90)


I the following an example about my question


@SuppressWarnings("restriction") public class DroolsKnowledgeAgentTest {

	public static class Service {

	}

	DroolsKnowledgeAgentTest() {
		KnowledgeBase newKnowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
		ResourceFactory.getResourceChangeNotifierService()
						.start();
		ResourceFactory.getResourceChangeScannerService()
						.start();

		final ResourceChangeScannerConfiguration sconf =
ResourceFactory.getResourceChangeScannerService()
																		.newResourceChangeScannerConfiguration();
		sconf.setProperty("drools.resource.scanner.interval", "2");
		ResourceFactory.getResourceChangeScannerService()
						.configure(sconf);

		final KnowledgeAgentConfiguration aconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
		aconf.setProperty("drools.agent.scanDirectories", "true");
		aconf.setProperty("drools.agent.scanResources", "true");
		aconf.setProperty("drools.agent.newInstance", "true");
		final KnowledgeAgent agent =
KnowledgeAgentFactory.newKnowledgeAgent("pch.sel.knowledge.agent",
newKnowledgeBase, aconf);
		// if (_l.isDebugEnabled()) {
		/* we need some log every time */
		agent.setSystemEventListener(new PrintStreamSystemEventListener());
		// }
	}

	public static void main(String[] args) throws IOException {

		ResourceFactory.getResourceChangeNotifierService()
						.start();
		ResourceFactory.getResourceChangeScannerService()
						.start();

		String xml = "";
		xml += "<change-set xmlns='http://drools.org/drools-5.0/change-set'&quot;;
		xml += &quot;   
xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'&quot;;
		xml += &quot;   
xs:schemaLocation='http://drools.org/drools-5.0/change-set
drools-change-set-5.0.xsd' >";
		xml += "    <add> ";
		xml += "        <resource
source='Z:/WSP/drools-test/src/main/java/com/sample/rule1.drl' type='DRL'
/>";
		xml += "    </add> ";
		xml += "</change-set>";
		FileManager fileManager = new FileManager();
		File fxml = fileManager.newFile("changeset.xml");
		BufferedWriter output = new BufferedWriter(new FileWriter(fxml));
		output.write(xml);
		output.close();

		KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();

		ResourceChangeScannerConfiguration sconf =
ResourceFactory.getResourceChangeScannerService()
																	.newResourceChangeScannerConfiguration();
		sconf.setProperty("drools.resource.scanner.interval", "2");
		ResourceFactory.getResourceChangeScannerService()
						.configure(sconf);

		KnowledgeAgentConfiguration aconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
		aconf.setProperty("drools.agent.scanDirectories", "true");
		aconf.setProperty("drools.agent.scanResources", "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();

		ksession.setGlobal("service", new Service());
	}
}

and rule named rule1.drl

#created on: 29-Feb-2012
package com.sample

#list any import classes here.



#declare any global variables here
global  DroolsKnowledgeAgentTest.Service service;


rule "Your First Rule"

    when
        #conditions
    then
        #actions

end

Thank you very much for your answers and kind regards
Alberto
 

--
View this message in context: http://drools.46999.n3.nabble.com/KnowledgeAgent-Changeset-problems-tp3787165p3787165.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list