use of org.drools.drl.parser.DroolsError in project drools by kiegroup.
the class KnowledgeBuilderImpl method addPackageFromInputStream.
void addPackageFromInputStream(final Resource resource) throws IOException, ClassNotFoundException {
InputStream is = resource.getInputStream();
Object object = DroolsStreamUtils.streamIn(is, this.configuration.getClassLoader());
is.close();
if (object instanceof Collection) {
// KnowledgeBuilder API
Collection<KiePackage> pkgs = (Collection<KiePackage>) object;
for (KiePackage kpkg : pkgs) {
overrideReSource((KnowledgePackageImpl) kpkg, resource);
addPackage((KnowledgePackageImpl) kpkg);
}
} else if (object instanceof KnowledgePackageImpl) {
// KnowledgeBuilder API
KnowledgePackageImpl kpkg = (KnowledgePackageImpl) object;
overrideReSource(kpkg, resource);
addPackage(kpkg);
} else {
results.add(new DroolsError(resource) {
@Override
public String getMessage() {
return "Unknown binary format trying to load resource " + resource.toString();
}
@Override
public int[] getLines() {
return new int[0];
}
});
}
}
use of org.drools.drl.parser.DroolsError in project drools by kiegroup.
the class PackageBuilderResults method readExternal.
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
SerializableDroolsError[] temp = (SerializableDroolsError[]) in.readObject();
this.errors = temp;
for (DroolsError error : temp) {
add(error);
}
}
use of org.drools.drl.parser.DroolsError in project drools by kiegroup.
the class PackageBuilderErrors method writeExternal.
public void writeExternal(ObjectOutput out) throws IOException {
if (!this.errors.getClass().getComponentType().equals(SerializableDroolsError.class)) {
SerializableDroolsError[] temp = new SerializableDroolsError[this.errors.length];
int i = 0;
for (DroolsError error : this.errors) {
temp[i] = new SerializableDroolsError(error);
}
out.writeObject(temp);
} else {
out.writeObject(this.errors);
}
}
use of org.drools.drl.parser.DroolsError in project drools by kiegroup.
the class KnowledgeBuilderImpl method registerBuildResource.
public void registerBuildResource(final Resource resource, ResourceType type) {
InternalResource ires = (InternalResource) resource;
if (ires.getResourceType() == null) {
ires.setResourceType(type);
} else if (ires.getResourceType() != type) {
addBuilderResult(new ResourceTypeDeclarationWarning(resource, ires.getResourceType(), type));
}
if (ResourceType.CHANGE_SET == type) {
try {
ChangeSet changeSet = parseChangeSet(resource);
List<Resource> resources = new ArrayList<>();
resources.add(resource);
resources.addAll(changeSet.getResourcesAdded());
resources.addAll(changeSet.getResourcesModified());
resources.addAll(changeSet.getResourcesRemoved());
buildResources.push(resources);
} catch (Exception e) {
results.add(new DroolsError() {
public String getMessage() {
return "Unable to register changeset resource " + resource;
}
public int[] getLines() {
return new int[0];
}
});
}
} else {
buildResources.push(Collections.singletonList(resource));
}
}
use of org.drools.drl.parser.DroolsError in project drools by kiegroup.
the class KnowledgeBuilderImpl method processWindowDeclarations.
protected 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);
}
}
}
Aggregations