use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class KnowledgeBuilderImpl method decisionTableToPackageDescr.
PackageDescr decisionTableToPackageDescr(Resource resource, ResourceConfiguration configuration) throws DroolsParserException, IOException {
DecisionTableConfiguration dtableConfiguration = configuration instanceof DecisionTableConfiguration ? (DecisionTableConfiguration) configuration : null;
if (dtableConfiguration != null && !dtableConfiguration.getRuleTemplateConfigurations().isEmpty()) {
List<String> generatedDrls = DecisionTableFactory.loadFromInputStreamWithTemplates(resource, dtableConfiguration);
if (generatedDrls.size() == 1) {
return generatedDrlToPackageDescr(resource, generatedDrls.get(0));
}
CompositePackageDescr compositePackageDescr = null;
for (String generatedDrl : generatedDrls) {
PackageDescr packageDescr = generatedDrlToPackageDescr(resource, generatedDrl);
if (packageDescr != null) {
if (compositePackageDescr == null) {
compositePackageDescr = new CompositePackageDescr(resource, packageDescr);
} else {
compositePackageDescr.addPackageDescr(resource, packageDescr);
}
}
}
return compositePackageDescr;
}
String generatedDrl = DecisionTableFactory.loadFromResource(resource, dtableConfiguration);
return generatedDrlToPackageDescr(resource, generatedDrl);
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class TypeDeclarationBuilder method normalizeForeignPackages.
protected void normalizeForeignPackages(PackageDescr packageDescr) {
Map<String, PackageDescr> foreignPackages = null;
for (AbstractClassTypeDeclarationDescr typeDescr : packageDescr.getClassAndEnumDeclarationDescrs()) {
if (kbuilder.filterAccepts(ResourceChange.Type.DECLARATION, typeDescr.getNamespace(), typeDescr.getTypeName())) {
if (!typeDescr.getNamespace().equals(packageDescr.getNamespace())) {
// If the type declaration is for a different namespace, process that separately.
PackageDescr altDescr;
if (foreignPackages == null) {
foreignPackages = new HashMap<String, PackageDescr>();
}
if (foreignPackages.containsKey(typeDescr.getNamespace())) {
altDescr = foreignPackages.get(typeDescr.getNamespace());
} else {
altDescr = new PackageDescr(typeDescr.getNamespace());
altDescr.setResource(packageDescr.getResource());
foreignPackages.put(typeDescr.getNamespace(), altDescr);
}
if (typeDescr instanceof TypeDeclarationDescr) {
altDescr.addTypeDeclaration((TypeDeclarationDescr) typeDescr);
} else if (typeDescr instanceof EnumDeclarationDescr) {
altDescr.addEnumDeclaration((EnumDeclarationDescr) typeDescr);
}
for (ImportDescr imp : packageDescr.getImports()) {
altDescr.addImport(imp);
}
kbuilder.getOrCreatePackageRegistry(altDescr);
}
}
}
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class TypeDeclarationCache method registerTypeDeclaration.
private void registerTypeDeclaration(String packageName, TypeDeclaration typeDeclaration) {
if (typeDeclaration.getNature() == TypeDeclaration.Nature.DECLARATION || packageName.equals(typeDeclaration.getTypeClass().getPackage().getName())) {
PackageRegistry packageRegistry = kbuilder.getOrCreatePackageRegistry(new PackageDescr(packageName, ""));
packageRegistry.getPackage().addTypeDeclaration(typeDeclaration);
}
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class DrlParser method compile.
private PackageDescr compile(boolean isEditor, final DRLParser parser) throws DroolsParserException {
PackageDescr pkgDescr = null;
try {
if (isEditor) {
parser.enableEditorInterface();
}
pkgDescr = parser.compilationUnit(resource);
editorSentences = parser.getEditorInterface();
makeErrorList(parser);
if (isEditor || !this.hasErrors()) {
return pkgDescr;
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
final ParserError err = new ParserError(resource, GENERIC_ERROR_MESSAGE + e.toString() + "\n" + Arrays.toString(e.getStackTrace()), -1, 0);
this.results.add(err);
if (isEditor) {
return pkgDescr;
} else {
throw new DroolsParserException(GENERIC_ERROR_MESSAGE + e.getMessage(), e);
}
}
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class FunctionHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
FunctionDescr functionDescr = (FunctionDescr) parser.getCurrent();
final NodeList parameters = element.getElementsByTagName("parameter");
for (int i = 0, length = parameters.getLength(); i < length; i++) {
final String identifier = ((Element) parameters.item(i)).getAttribute("identifier");
final String type = ((Element) parameters.item(i)).getAttribute("type");
emptyAttributeCheck("parameter", "identifier", identifier, parser);
emptyAttributeCheck("parameter", "type", type, parser);
functionDescr.addParameter(type, identifier);
}
// we allow empty, "", bodies - but make sure that we atleast have a body element
NodeList list = element.getElementsByTagName("body");
if (list.getLength() == 0) {
throw new SAXParseException("function must have a <body>", parser.getLocator());
}
functionDescr.setText(((org.w3c.dom.Text) list.item(0).getChildNodes().item(0)).getWholeText());
final PackageDescr packageDescr = (PackageDescr) parser.getData();
packageDescr.addFunction(functionDescr);
return functionDescr;
}
Aggregations