private void logErrors(DrlParser parser) { if ( parser.hasErrors() ) { for ( DroolsError droolsError : parser.getErrors() ) { this.errors.add( droolsError.getMessage() ); } } }
private void logErrors(DrlParser parser) { if ( parser.hasErrors() ) { for ( DroolsError droolsError : parser.getErrors() ) { this.errors.add( droolsError.getMessage() ); } } }
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; }
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; }
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 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; } }
/** * 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; }
/** * 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; }
PackageDescr dslrToPackageDescr(Resource resource) throws DroolsParserException { boolean hasErrors; PackageDescr pkg; DrlParser parser = new DrlParser(); DefaultExpander expander = getDslExpander(); Reader reader = null; try { if (expander == null) { expander = new DefaultExpander(); } reader = resource.getReader(); String str = expander.expand( reader ); if (expander.hasErrors()) { this.results.addAll( expander.getErrors() ); } pkg = parser.parse( str ); this.results.addAll( parser.getErrors() ); hasErrors = parser.hasErrors(); } catch (IOException e) { throw new RuntimeException( e ); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } } return hasErrors ? null : pkg; }
PackageDescr brlToPackageDescr(Resource resource) throws Exception { BusinessRuleProvider provider = BusinessRuleProviderFactory.getInstance().getProvider(); Reader knowledge = provider.getKnowledgeReader( resource ); DrlParser parser = new DrlParser(); if (provider.hasDSLSentences()) { DefaultExpander expander = getDslExpander(); if (null != expander) { knowledge = new StringReader( expander.expand( knowledge ) ); if (expander.hasErrors()) this.results.addAll( expander.getErrors() ); } } PackageDescr pkg = parser.parse( knowledge ); if (parser.hasErrors()) { this.results.addAll( parser.getErrors() ); return null; } return pkg; }