All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.drools.compiler.kie.builder.impl.ResultsImpl Maven / Gradle / Ivy

There is a newer version: 10.0.0
Show newest version
package org.drools.compiler.kie.builder.impl;

import java.util.ArrayList;
import java.util.List;

import org.drools.compiler.commons.jci.problems.CompilationProblem;
import org.kie.internal.builder.KnowledgeBuilderResult;
import org.kie.api.builder.Message;
import org.kie.api.builder.Message.Level;
import org.kie.api.builder.Results;

public class ResultsImpl
    implements
    Results {
    private List messages    = new ArrayList();

    private long          idGenerator = 1L;

    public List getMessages() {
        return messages;
    }

    @Override
    public boolean hasMessages(Level... levels) {
        return !filterMessages( levels ).isEmpty();
    }

    @Override
    public List getMessages(Level... levels) {
        return filterMessages( levels );
    }

    public void addMessage(CompilationProblem problem) {
        messages.add( new MessageImpl( idGenerator++,
                                       problem ) );
    }

    public void addMessage(KnowledgeBuilderResult result) {
        messages.add( new MessageImpl( idGenerator++,
                                       result ) );
    }

    public void addMessage(Level level,
                           String path,
                           String text) {
        messages.add( new MessageImpl( idGenerator++,
                                       level,
                                       path,
                                       text ) );
    }

    public void setMessages(List messages) {
        this.messages = messages;
    }

    public long getIdGenerator() {
        return idGenerator;
    }

    public void setIdGenerator(long idGenerator) {
        this.idGenerator = idGenerator;
    }

    public List filterMessages(Level... levels) {
        return MessageImpl.filterMessages( messages,
                                           levels );
    }

    public String toString() {
        StringBuilder sBuilder = new StringBuilder();
        sBuilder.append( "Error Messages:\n" );
        for ( Message msg : filterMessages( Level.ERROR ) ) {
            sBuilder.append( msg.toString() );
            sBuilder.append( "\n" );
        }

        sBuilder.append( "---\n" );
        sBuilder.append( "Warning Messages:\n" );
        for ( Message msg : filterMessages( Level.WARNING ) ) {
            sBuilder.append( msg.toString() );
            sBuilder.append( "\n" );
        }
        
        sBuilder.append( "---\n" );
        sBuilder.append( "Info Messages:\n" );
        for ( Message msg : filterMessages( Level.INFO ) ) {
            sBuilder.append( msg.toString() );
            sBuilder.append( "\n" );
        }        
        return sBuilder.toString();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy