Package org.drools.lang

Examples of org.drools.lang.Expander


            resolver = new DefaultExpanderResolver( dsl );
        } catch ( final IOException e ) {
            throw new DroolsParserException( "Error parsing the DSL.",
                                             e );
        }
        final Expander expander = resolver.get( "*",
                                          null );
        final String expanded = expander.expand( source );
       
        if ( expander.hasErrors() ) {
            String err = "";
            for ( Iterator iter = expander.getErrors().iterator(); iter.hasNext(); ) {
                ExpanderException ex = (ExpanderException) iter.next();
                err  = err + "\n Line:[" + ex.getLine() + "] " + ex.getMessage();
               
            }
            throw new DroolsParserException(err);
View Full Code Here


        }

        for (int index = 0; index < children.length; index++) {
            if (file.parseAndLoad(new StringReader(
                    loadResource(children[index])))) {
                final Expander expander = new DefaultExpander();
                expander.addDSLMapping(file.getMapping());
                resolver.addExpander("*", expander);
            } else {
                throw new RuntimeDroolsException(
                        "Error parsing and loading DSL file."
                                + file.getErrors());
View Full Code Here

     * This is the constructor most people should use.
     */
    public DefaultExpanderResolver(final Reader reader) throws IOException {
        final DSLMappingFile file = new DSLMappingFile();
        if ( file.parseAndLoad( reader ) ) {
            final Expander expander = new DefaultExpander();
            expander.addDSLMapping( file.getMapping() );
            this.expanders.put( "*",
                                expander );
        } else {
            throw new RuntimeDroolsException( "Error parsing and loading DSL file." + file.getErrors() );
        }
View Full Code Here

    public Expander get(final String name,
                        final String config) {
        if ( this.expanders.containsKey( name ) ) {
            return (Expander) this.expanders.get( name );
        } else {
            final Expander exp = (Expander) this.expanders.get( "*" );
            if ( exp == null ) {
                throw new IllegalArgumentException( "Unable to provide an expander for " + name + " or a default expander." );
            }
            return exp;
        }
View Full Code Here

    public PackageDescr parse(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( expanded );
    }
View Full Code Here

     * @param resolver - the DSL expander resolver itself.
     * @throws DroolsParserException If unable to expand in any way.
     */
    public String getExpandedDRL(final String source, final DefaultExpanderResolver resolver ) throws DroolsParserException {

      final Expander expander = resolver.get( "*",
                                          null );
        final String expanded = expander.expand( source );
       
        if ( expander.hasErrors() ) {
            String err = "";
            for ( Iterator iter = expander.getErrors().iterator(); iter.hasNext(); ) {
                ExpanderException ex = (ExpanderException) iter.next();
                err  = err + "\n Line:[" + ex.getLine() + "] " + ex.getMessage();
               
            }
            throw new DroolsParserException(err);
View Full Code Here

        DefaultExpanderResolver resolver = new DefaultExpanderResolver(new StringReader(dsl));
       
       
        final DSLMappingFile file = new DSLTokenizedMappingFile();
        if ( file.parseAndLoad( new StringReader(dsl) ) ) {
            final Expander expander = new DefaultExpander();
            expander.addDSLMapping( file.getMapping() );
            resolver.addExpander("*", expander);
        } else {
            throw new RuntimeDroolsException( "Error parsing and loading DSL file." + file.getErrors() );
        }       

View Full Code Here


    public void testMultiLineTemplates() throws Exception {
        final Reader source = new InputStreamReader( getClass().getResourceAsStream( "rule_with_expander_multiline.dslr" ) );
        final Reader dsl = new InputStreamReader( getClass().getResourceAsStream( "test_dsl_multiline.dsl" ) );
        Expander ex =  new DefaultExpanderResolver(dsl).get("*", null);
        String r = ex.expand(source);
        assertEquals("when Car(color==\"Red\") then doSomething();", r.trim());
    }
View Full Code Here

        DefaultExpanderResolver resolver = new DefaultExpanderResolver(new StringReader(dsl));
       
       
        final DSLMappingFile file = new DSLMappingFile();
        if ( file.parseAndLoad( new StringReader(dsl) ) ) {
            final Expander expander = new DefaultExpander();
            expander.addDSLMapping( file.getMapping() );
            resolver.addExpander("*", expander);
        } else {
            throw new RuntimeDroolsException( "Error parsing and loading DSL file." + file.getErrors() );
        }       

View Full Code Here

    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 );
    }
View Full Code Here

TOP

Related Classes of org.drools.lang.Expander

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.