private void addDRLRulesToVerifier() { AssetItemIterator rules = packageItem.listAssetsByFormat(AssetFormats.DRL); while (rules.hasNext()) { AssetItem rule = rules.next(); ContentHandler contentHandler = ContentManager.getHandler(rule.getFormat()); if (contentHandler.isRuleAsset()) { IRuleAsset ruleAsset = (IRuleAsset) contentHandler; String drl = ruleAsset.getRawDRL(rule); verifier.addResourcesToVerify( ResourceFactory.newReaderResource(new StringReader(drl)), ResourceType.DRL); } } }
public String getDRL() { StringBuffer src = new StringBuffer(); src.append("package " + this.pkg.getName() + "\n"); src.append(ServiceImplementation.getDroolsHeader(this.pkg) + "\n\n"); // now we load up the DSL files builder.setDSLFiles( BRMSPackageBuilder.getDSLMappingFiles( pkg, new BRMSPackageBuilder.DSLErrorEvent() { public void recordError(AssetItem asset, String message) { errors.add(new ContentAssemblyError(asset, message)); } })); // do the functions and declared types. AssetItemIterator it = this.pkg.listAssetsByFormat(new String[] {AssetFormats.FUNCTION, AssetFormats.DRL_MODEL}); while (it.hasNext()) { AssetItem func = (AssetItem) it.next(); if (!func.isArchived()) { src.append(func.getContent() + "\n\n"); } } // now the rules Iterator iter = pkg.getAssets(); while (iter.hasNext()) { AssetItem asset = (AssetItem) iter.next(); if (!asset.isArchived()) { ContentHandler h = ContentManager.getHandler(asset.getFormat()); if (h instanceof IRuleAsset) { IRuleAsset ruleAsset = (IRuleAsset) h; ruleAsset.assembleDRL(builder, asset, src); } src.append("\n\n"); } } return src.toString(); }
/** Builds assets that are "rule" assets (ie things that are not functions etc). */ private void buildAsset(AssetItem asset) { ContentHandler h = ContentManager.getHandler(asset.getFormat()); if (h instanceof IRuleAsset) { try { ((IRuleAsset) h).compile(builder, asset, new ErrorLogger()); if (builder.hasErrors()) { this.recordBuilderErrors(asset); // clear the errors, so we don't double report. builder.clearErrors(); } } catch (DroolsParserException e) { throw new RulesRepositoryException(e); } catch (IOException e) { throw new RulesRepositoryException(e); } } }