packageDescr = cachedDrlInfo.getPackageDescr();
parserErrors = cachedDrlInfo.getParserErrors();
}
}
DrlParser parser = new DrlParser();
if ( packageDescr == null ) {
Reader dslReader = DSLAdapter.getDSLContent( content, resource );
if ( dslReader != null ) {
packageDescr = parser.parse( true, content, dslReader );
} else {
packageDescr = parser.parse( true, content );
}
parserErrors = new ArrayList<BaseKnowledgeBuilderResultImpl>();
parserErrors.addAll(parser.getErrors());
}
KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl( builder_configuration );
DRLInfo result = null;
// compile parsed rules if necessary
if ( packageDescr != null && compile && !parser.hasErrors()) {
// check whether a .package file exists and add it
if ( resource != null && resource.getParent() != null ) {
MyResourceVisitor visitor = new MyResourceVisitor();
resource.getParent().accept( visitor,
IResource.DEPTH_ONE,
IResource.NONE );
IResource packageDef = visitor.getPackageDef();
if ( packageDef != null ) {
PackageDescr desc = parseResource( packageDef,
false ).getPackageDescr();
if (desc != null){
builder.addPackage( desc);
}
}
}
builder.addPackage( packageDescr );
// make sure the namespace is set, use default if necessary, as this is used to build the DRLInfo
if ( StringUtils.isEmpty( packageDescr.getNamespace() ) ) {
packageDescr.setNamespace( builder.getBuilderConfiguration().getDefaultPackageName() );
}
result = new DRLInfo( resource == null ? "" : resource.getProjectRelativePath().toString(),
packageDescr,
parserErrors,
builder.getPackageRegistry(packageDescr.getNamespace()).getPackage(),
builder.getErrors().getErrors(),
builder.getPackageRegistry( packageDescr.getNamespace() ).getDialectCompiletimeRegistry() );
} else {
result = new DRLInfo( resource == null ? "" : resource.getProjectRelativePath().toString(),
packageDescr,
parserErrors,
new PackageRegistry(newLoader, builder.getBuilderConfiguration(), new KnowledgePackageImpl("")).getDialectCompiletimeRegistry() );
}
// cache result
if ( useCache && resource != null) {
if ( compile && !parser.hasErrors() ) {
parsedRules.remove( resource );
compiledRules.put( resource,
result );
RuleInfo[] ruleInfos = result.getRuleInfos();
for ( int i = 0; i < ruleInfos.length; i++ ) {