Package org.drools.lang.dsl

Examples of org.drools.lang.dsl.DSLTokenizedMappingFile


       
       
        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() );
        }

        DrlParser parser = new DrlParser();
        String result = parser.getExpandedDRL( drl, resolver);
        assertEqualsIgnoreWhitespace( "rule 'foo' \n when \n Something() \n then \n another(); \nend", result );
View Full Code Here


    }

   
    /** This will load in the DSL config file, using the DSLMapping from drools-compiler */
    void readConfig(InputStream stream) throws IOException, CoreException {
        DSLTokenizedMappingFile file = new DSLTokenizedMappingFile();
        file.parseAndLoad(new InputStreamReader(stream));

        DSLMapping grammar = file.getMapping();
        List conditions = grammar.getEntries( DSLMappingEntry.CONDITION );
        List consequences = grammar.getEntries( DSLMappingEntry.CONSEQUENCE );
       
        conditionProposals = buildProposals(conditions);
        consequenceProposals = buildProposals(consequences);
View Full Code Here

    @Test
    public void testTestAnyEnum() throws Exception {
        SuggestionCompletionLoader suggestionCompletionLoader = new SuggestionCompletionLoader();
        ArrayList<DSLTokenizedMappingFile> dsls = new ArrayList<DSLTokenizedMappingFile>();

        DSLTokenizedMappingFile dslTokenizedMappingFile = new DSLTokenizedMappingFile();

        DSLMappingEntry dslMappingEntry = mock( DSLMappingEntry.class );
        when( dslMappingEntry.getSection() ).thenReturn( DSLMappingEntry.ANY );

        dslTokenizedMappingFile.getMapping().addEntry( dslMappingEntry );
        dsls.add( dslTokenizedMappingFile );

        SuggestionCompletionEngine suggestionEngine = suggestionCompletionLoader.getSuggestionEngine( "",
                                                                                                      Collections.<JarInputStream> emptyList(),
                                                                                                      dsls );
View Full Code Here

        return pkg;
    }

    public void addDsl( Resource resource ) throws IOException {
        this.resource = resource;
        DSLTokenizedMappingFile file = new DSLTokenizedMappingFile();

        Reader reader = null;
        try {
            reader = resource.getReader();
            if (!file.parseAndLoad( reader )) {
                this.results.addAll( file.getErrors() );
            }
            if (this.dslFiles == null) {
                this.dslFiles = new ArrayList<DSLTokenizedMappingFile>();
            }
            this.dslFiles.add( file );
View Full Code Here

    private DefaultExpanderResolver resolveDSLFiles() throws IOException {

        DefaultExpanderResolver resolver = new DefaultExpanderResolver();
        final File dir = new File( this.srcdir.getAbsolutePath() );
        DSLMappingFile file = new DSLTokenizedMappingFile();

        FilenameFilter filter = new FilenameFilter() {
            public boolean accept(File dir,
                                  String name) {
                return name.endsWith( ".dsl" );
            }
        };

        String[] children = dir.list( filter );
        if ( children.length == 0 ) {
            throw new BuildException( "There are no DSL files for this directory:" + this.srcdir.getAbsolutePath() );
        }

        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() );
            }
        }

        return resolver;
    }
View Full Code Here

    }

    public void testGetExpander() {
        BRMSPackageBuilder builder = new BRMSPackageBuilder();
        List<DSLTokenizedMappingFile> files = new ArrayList<DSLTokenizedMappingFile>();
        files.add( new DSLTokenizedMappingFile() );
        builder.setDSLFiles( files );
        assertTrue(builder.hasDSL());
        assertNotNull(builder.getDSLExpander());
    }
View Full Code Here

                String content = dslRuleEditor.getContent();
                Reader reader = DSLAdapter.getDSLContent(content, dslRuleEditor.getResource());
                if (reader == null) {
                    throw new IllegalArgumentException("Could not find dsl definition.");
                }
                DSLMappingFile mapping = new DSLTokenizedMappingFile();
                mapping.parseAndLoad(reader);
                reader.close();
                expander.addDSLMapping(mapping.getMapping());
                expander.expand(content);
                // if translation succeeds, change to drl viewer
                drlRuleViewer.setInput(getEditorInput());
                drlRuleViewer.setSelectedRange(selection);
            } catch (Throwable t) {
View Full Code Here

    protected String transformInput(String content) {
        DefaultExpander expander = new DefaultExpander();
        try {
            Reader reader = DSLAdapter.getDSLContent(content, viewer.getResource());
            DSLMappingFile mapping = new DSLTokenizedMappingFile();
            mapping.parseAndLoad(reader);
            reader.close();
            expander.addDSLMapping(mapping.getMapping());
            return expander.expand(content);
        } catch (Throwable t) {
            //viewer.handleError(t);
            return content;
        }
View Full Code Here

                IStorageEditorInput input = (IStorageEditorInput) editorInput;
                stream = input.getStorage().getContents();
            }

            model = new NLGrammarModel();
            DSLMappingFile file = new DSLTokenizedMappingFile();
            file.parseAndLoad( new InputStreamReader( stream ) );
            model.addEntries( file.getMapping().getEntries() );
            stream.close();

        } catch ( CoreException e ) {
            throw new IllegalStateException( "Unable to load DSL configuration file. (CoreException: " + e.getMessage() + ")" );
        } catch ( IOException e ) {
View Full Code Here

            for ( int i = 0; i < files.length; i++ ) {
                String fn = files[i].getName();
                if ( fn.endsWith( ".dsl" ) ) {
                    String contents = getFileContents( (IFile) files[i] );
                    DSLTokenizedMappingFile dsl = new DSLTokenizedMappingFile();

                    if ( dsl.parseAndLoad( new StringReader( contents ) ) ) {
                        dslList.add( dsl );
                    } else {
                        //TODO report dsl parse error
                    }
                } else if ( fn.endsWith( ".enumeration" ) ) {
View Full Code Here

TOP

Related Classes of org.drools.lang.dsl.DSLTokenizedMappingFile

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.