Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 JBoss Inc
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
   * use this file except in compliance with the License. You may obtain a copy of
   * the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  * License for the specific language governing permissions and limitations under
  * the License.
  */
 package org.drools.workbench.models.guided.dtable.backend.util;
 
 
 import java.util.Map;
A specialised implementation of BRDELPersistence that can expand Template Keys to values
 
 public class GuidedDTBRDRLPersistence extends BRDRLPersistence {
 
 
     private static final Pattern patternTemplateKey = Pattern.compile"@\\{(.+?)\\}" );
 
     public GuidedDTBRDRLPersistenceTemplateDataProvider rowDataProvider ) {
         if ( rowDataProvider == null ) {
             throw new NullPointerException"rowDataProvider cannot be null" );
         }
         this. = rowDataProvider;
     }
 
     @Override
     protected LHSPatternVisitor getLHSPatternVisitorboolean isDSLEnhanced,
                                                       StringBuilder buf,
                                                       String nestedIndentation,
                                                       boolean isNegated ) {
         return new LHSPatternVisitorisDSLEnhanced,
                                       ,
                                       ,
                                       ,
                                       ,
                                       buf,
                                       nestedIndentation,
                                       isNegated );
     }
 
     @Override
     protected RHSActionVisitor getRHSActionVisitorboolean isDSLEnhanced,
                                                     StringBuilder buf,
                                                     String indentation ) {
         return new RHSActionVisitorisDSLEnhanced,
                                      ,
                                      ,
                                      ,
                                      ,
                                      buf,
                                      indentation );
     }
 
     //Substitutes Template Keys for values
     public static class LHSPatternVisitor extends BRDRLPersistence.LHSPatternVisitor {
 
         private TemplateDataProvider rowDataProvider;
 
         public LHSPatternVisitorboolean isDSLEnhanced,
                                   TemplateDataProvider rowDataProvider,
                                   Map<StringIFactPatternbindingsPatterns,
                                   Map<StringFieldConstraintbindingsFields,
                                   DRLConstraintValueBuilder constraintValueBuilder,
                                   StringBuilder b,
                                   String indentation,
                                   boolean isPatternNegated ) {
             superisDSLEnhanced,
                    bindingsPatterns,
                    bindingsFields,
                    constraintValueBuilder,
                    b,
                    indentation,
                    isPatternNegated );
             this. = rowDataProvider;
         }
 
         @Override
         protected void buildTemplateFieldValueint type,
                                                 String fieldType,
                                                String value,
                                                StringBuilder buf ) {
            buf.append" " );
            .buildLHSFieldValuebuf,
                                                       type,
                                                       fieldType,
                                                       .getTemplateKeyValuevalue ) );
            buf.append" " );
        }
        @Override
        public void visitFreeFormLineFreeFormLine ffl ) {
            StringBuffer interpolatedResult = new StringBuffer();
            final Matcher matcherTemplateKey = .matcherffl.getText() );
            while ( matcherTemplateKey.find() ) {
                String varName = matcherTemplateKey.group( 1 );
                matcherTemplateKey.appendReplacementinterpolatedResult,
                                                      .getTemplateKeyValuevarName ) );
            }
            matcherTemplateKey.appendTailinterpolatedResult );
            //Don't update the original FreeFormLine object
            FreeFormLine fflClone = new FreeFormLine();
            fflClone.setTextinterpolatedResult.toString() );
            super.visitFreeFormLinefflClone );
        }
    }
    //Substitutes Template Keys for values
    public static class RHSActionVisitor extends BRDRLPersistence.RHSActionVisitor {
        private TemplateDataProvider rowDataProvider;
        public RHSActionVisitorboolean isDSLEnhanced,
                                 TemplateDataProvider rowDataProvider,
                                 Map<StringIFactPatternbindingsPatterns,
                                 Map<StringFieldConstraintbindingsFields,
                                 DRLConstraintValueBuilder constraintValueBuilder,
                                 StringBuilder b,
                                 String indentation ) {
            superisDSLEnhanced,
                   bindingsPatterns,
                   bindingsFields,
                   constraintValueBuilder,
                   b,
                   indentation );
            this. = rowDataProvider;
        }
        @Override
        protected void buildTemplateFieldValueActionFieldValue fieldValue,
                                                StringBuilder buf ) {
            .buildRHSFieldValuebuf,
                                                       fieldValue.getType(),
                                                       .getTemplateKeyValuefieldValue.getValue() ) );
        }
        @Override
        public void visitFreeFormLineFreeFormLine ffl ) {
            StringBuffer interpolatedResult = new StringBuffer();
            final Matcher matcherTemplateKey = .matcherffl.getText() );
            while ( matcherTemplateKey.find() ) {
                String varName = matcherTemplateKey.group( 1 );
                matcherTemplateKey.appendReplacementinterpolatedResult,
                                                      .getTemplateKeyValuevarName ) );
            }
            matcherTemplateKey.appendTailinterpolatedResult );
            //Don't update the original FreeFormLine object
            FreeFormLine fflClone = new FreeFormLine();
            fflClone.setTextinterpolatedResult.toString() );
            super.visitFreeFormLinefflClone );
        }
    }
New to GrepCode? Check out our FAQ X