use of org.drools.compiler.lang.descr.AttributeDescr in project drools by kiegroup.
the class KnowledgeBuilderImpl method processWindowDeclarations.
private void processWindowDeclarations(PackageRegistry pkgRegistry, PackageDescr packageDescr) {
for (WindowDeclarationDescr wd : packageDescr.getWindowDeclarations()) {
WindowDeclaration window = new WindowDeclaration(wd.getName(), packageDescr.getName());
// TODO: process annotations
// process pattern
InternalKnowledgePackage pkg = pkgRegistry.getPackage();
DialectCompiletimeRegistry ctr = pkgRegistry.getDialectCompiletimeRegistry();
RuleDescr dummy = new RuleDescr(wd.getName() + " Window Declaration");
dummy.setResource(packageDescr.getResource());
dummy.addAttribute(new AttributeDescr("dialect", "java"));
RuleBuildContext context = new RuleBuildContext(this, dummy, ctr, pkg, ctr.getDialect(pkgRegistry.getDialect()));
final RuleConditionBuilder builder = (RuleConditionBuilder) context.getDialect().getBuilder(wd.getPattern().getClass());
if (builder != null) {
final Pattern pattern = (Pattern) builder.build(context, wd.getPattern(), null);
if (pattern.getXpathConstraint() != null) {
context.addError(new DescrBuildError(wd, context.getParentDescr(), null, "OOpath expression " + pattern.getXpathConstraint() + " not allowed in window declaration\n"));
}
window.setPattern(pattern);
} else {
throw new RuntimeException("BUG: assembler not found for descriptor class " + wd.getPattern().getClass());
}
if (!context.getErrors().isEmpty()) {
for (DroolsError error : context.getErrors()) {
addBuilderResult(error);
}
} else {
pkgRegistry.getPackage().addWindowDeclaration(window);
}
}
}
use of org.drools.compiler.lang.descr.AttributeDescr in project drools by kiegroup.
the class RuleHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
final RuleDescr ruleDescr = (RuleDescr) parser.getCurrent();
final AndDescr lhs = ruleDescr.getLhs();
if (lhs == null) {
throw new SAXParseException("<rule> requires a LHS", parser.getLocator());
}
NodeList list = element.getElementsByTagName("rhs");
if (list.getLength() == 0) {
throw new SAXParseException("<rule> requires a <rh> child element", parser.getLocator());
}
ruleDescr.setConsequence(((org.w3c.dom.Text) list.item(0).getChildNodes().item(0)).getWholeText());
NodeList attributes = element.getElementsByTagName("rule-attribute");
for (int i = 0, length = attributes.getLength(); i < length; i++) {
final String name = ((Element) attributes.item(i)).getAttribute("name");
emptyAttributeCheck("rule-attribute", "name", name, parser);
final String value = ((Element) attributes.item(i)).getAttribute("value");
ruleDescr.addAttribute(new AttributeDescr(name, value));
}
((PackageDescr) parser.getData()).addRule(ruleDescr);
return ruleDescr;
}
use of org.drools.compiler.lang.descr.AttributeDescr in project drools by kiegroup.
the class PackageBuilderConfigurationTest method testMockDialect.
@Test
public void testMockDialect() {
InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.pkg1");
KnowledgeBuilderConfigurationImpl cfg1 = new KnowledgeBuilderConfigurationImpl();
MockDialectConfiguration mockConf = new MockDialectConfiguration();
// cfg1.buildDialectRegistry().addDialect( "mock",
// mockConf.getDialect() );
cfg1.addDialect("mock", mockConf);
cfg1.setDefaultDialect("mock");
KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl(pkg, cfg1);
PackageRegistry pkgRegistry = builder.getPackageRegistry(pkg.getName());
DialectCompiletimeRegistry dialectRegistry = pkgRegistry.getDialectCompiletimeRegistry();
MockDialect mockDialect2 = (MockDialect) dialectRegistry.getDialect(cfg1.getDefaultDialect());
assertSame(pkg, mockDialect2.getPkg());
assertNull(mockDialect2.getRuleDescr());
RuleDescr ruleDescr = new RuleDescr("test rule");
ruleDescr.addAttribute(new AttributeDescr("dialect", "mock"));
ruleDescr.setLhs(new AndDescr());
EvalDescr evalDescr = new EvalDescr();
ruleDescr.getLhs().addDescr(evalDescr);
PackageDescr pkgDescr = new PackageDescr("org.pkg1");
pkgDescr.addImport(new ImportDescr("java.util.HashMap"));
FunctionImportDescr functionImportDescr = new FunctionImportDescr();
functionImportDescr.setTarget("java.lang.System.currentTimeMillis");
pkgDescr.addFunctionImport(functionImportDescr);
pkgDescr.addRule(ruleDescr);
builder.addPackage(pkgDescr);
assertSame(ruleDescr, mockDialect2.getRuleDescr());
assertTrue(mockDialect2.getImport().contains("java.util.HashMap"));
assertTrue(mockDialect2.getStaticImport().contains("java.lang.System.currentTimeMillis"));
assertEquals("eval was built", evalDescr.getContent());
assertEquals("consequence was built", ruleDescr.getConsequence());
assertTrue(mockDialect2.isCompileAll());
assertNotNull(pkg.getRule("test rule"));
// make sure there were no other general errors.
assertFalse(builder.hasErrors());
}
use of org.drools.compiler.lang.descr.AttributeDescr in project drools by kiegroup.
the class PackageDescrResourceVisitor method visit.
protected void visit(final QueryDescr descr) {
checkResource(descr);
visit(descr.getLhs());
for (AttributeDescr attrDescr : descr.getAttributes().values()) {
visit(attrDescr);
}
}
use of org.drools.compiler.lang.descr.AttributeDescr in project drools by kiegroup.
the class PackageDescrResourceVisitor method visit.
protected void visit(final RuleDescr descr) {
checkResource(descr);
for (AttributeDescr d : descr.getAttributes().values()) {
visit(d);
}
visit(descr.getLhs());
visitConsequence(descr.getConsequence());
for (Object o : descr.getNamedConsequences().values()) {
visitConsequence(o);
}
}
Aggregations