public PackageDescr parse(boolean isEditor, final Reader drl, final Reader dsl) throws DroolsParserException, IOException { final StringBuilder text = getDRLText( drl ); return parse( text.toString(), dsl ); }
/** * This will expand the DRL. useful for debugging. * * @param source - * the source which use a DSL * @param dsl - * the DSL itself. * @throws DroolsParserException * If unable to expand in any way. */ public String getExpandedDRL(final String source, final Reader dsl) throws DroolsParserException { DefaultExpanderResolver resolver = getDefaultResolver( dsl ); return getExpandedDRL( source, resolver ); }
PackageDescr decisionTableToPackageDescr(Resource resource, ResourceConfiguration configuration) throws DroolsParserException, IOException { DecisionTableConfiguration dtableConfiguration = (DecisionTableConfiguration) configuration; String string = DecisionTableFactory.loadFromInputStream( resource.getInputStream(), dtableConfiguration ); DrlParser parser = new DrlParser(); PackageDescr pkg = parser.parse( new StringReader( string ) ); this.results.addAll( parser.getErrors() ); if (pkg == null) { this.results.add( new ParserError( resource, "Parser returned a null Package", 0, 0 ) ); } return parser.hasErrors() ? null : pkg; }
/** Parse a rule from text */ public PackageDescr parse(final String text) throws DroolsParserException { return parse( false, text ); }
/** * Parse and build a rule package from a DRL source with a domain specific * language. * * @param source * As Text. * @param dsl * @return * @throws DroolsParserException */ public PackageDescr parse(boolean isEditor, final String source, final Reader dsl) throws DroolsParserException { DefaultExpanderResolver resolver = getDefaultResolver( dsl ); final Expander expander = resolver.get( "*", null ); final String expanded = expander.expand( source ); if ( expander.hasErrors() ) { this.results.addAll( expander.getErrors() ); } return this.parse( isEditor, expanded ); }
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 ); } } }
PackageDescr drlToPackageDescr(Resource resource) throws DroolsParserException, IOException { PackageDescr pkg; boolean hasErrors = false; if (resource instanceof DescrResource) { pkg = (PackageDescr) ( (DescrResource) resource ).getDescr(); } else { final DrlParser parser = new DrlParser(); pkg = parser.parse( resource ); this.results.addAll( parser.getErrors() ); if (pkg == null) { this.results.add( new ParserError( resource, "Parser returned a null Package", 0, 0 ) ); } hasErrors = parser.hasErrors(); } return hasErrors ? null : pkg; }
/** * Parse and build a rule package from a DRL source with a domain specific * language. */ public PackageDescr parse(final Reader drl, final Reader dsl) throws DroolsParserException, IOException { return parse( false, drl, dsl ); }
/** * Load a rule package from DRL source using the supplied DSL configuration. * * @param source * The source of the rules. * @param dsl * The source of the domain specific language configuration. * @throws DroolsParserException * @throws IOException */ public void addPackageFromDrl( final Reader source, final Reader dsl ) throws DroolsParserException, IOException { this.resource = new ReaderResource( source, ResourceType.DSLR ); final DrlParser parser = new DrlParser(); final PackageDescr pkg = parser.parse( source, dsl ); this.results.addAll( parser.getErrors() ); if (!parser.hasErrors()) { addPackage( pkg ); } this.resource = null; }
public PackageDescr parse(final Reader reader) throws DroolsParserException { return parse( false, reader ); }
/** * Load a rule package from DRL source and associate all loaded artifacts * with the given resource. * * @param reader * @param sourceResource the source resource for the read artifacts * @throws DroolsParserException * @throws IOException */ public void addPackageFromDrl( final Reader reader, final Resource sourceResource ) throws DroolsParserException, IOException { this.resource = sourceResource; final DrlParser parser = new DrlParser(); final PackageDescr pkg = parser.parse( reader ); this.results.addAll( parser.getErrors() ); if (pkg == null) { this.results.add( new ParserError( sourceResource, "Parser returned a null Package", 0, 0 ) ); } if (!parser.hasErrors()) { addPackage( pkg ); } this.resource = null; }
public PackageDescr parse(final String source, final Reader dsl) throws DroolsParserException { return this.parse( false, source, dsl ); }
public PackageDescr parse(final boolean isEditor, final Resource resource) throws DroolsParserException, IOException { this.resource = resource; InputStream is = resource.getInputStream(); String encoding = null; if (resource instanceof ClassPathResource) { encoding = ((ClassPathResource) resource).getEncoding(); } if (resource instanceof ReaderResource) { encoding = ((ReaderResource) resource).getEncoding(); } if (resource instanceof InputStreamResource) { encoding = ((InputStreamResource) resource).getEncoding(); } final DRLParser parser = getParser( is, encoding ); return compile( isEditor, parser ); }
PackageDescr pmmlModelToPackageDescr( PMMLCompiler compiler, Resource resource ) throws DroolsParserException, IOException { String theory = compiler.compile(resource.getInputStream(), getPackageRegistry()); if ( ! compiler.getResults().isEmpty() ) { this.results.addAll( compiler.getResults() ); return null; } DrlParser parser = new DrlParser(); PackageDescr pkg = parser.parse( new StringReader( theory ) ); this.results.addAll( parser.getErrors() ); if ( pkg == null ) { this.results.add( new ParserError( resource, "Parser returned a null Package", 0, 0 ) ); return pkg; } else { return parser.hasErrors() ? null : pkg; } }