Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.drools.guvnor.server.contenthandler;
  
  /*
   * Copyright 2005 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.
  */
 
 import java.util.List;
 
 import  org.drools.guvnor.client.rpc.RuleAsset;
 import  org.drools.guvnor.client.rpc.RuleContentText;
 
 import  com.google.gwt.user.client.rpc.SerializableException;
 
 public class DSLRuleContentHandler extends ContentHandler
     implements
     IRuleAsset {
 
     public void retrieveAssetContent(RuleAsset asset,
                                      PackageItem pkg,
                                      AssetItem itemthrows SerializableException {
         RuleContentText text = new RuleContentText();
         text.content = item.getContent();
 
         asset.content = text;
 
     }
 
     public void storeAssetContent(RuleAsset asset,
                                   AssetItem repoAssetthrows SerializableException {
 
         RuleContentText text = (RuleContentText) asset.content;
         repoAsset.updateContenttext.content );
 
     }
 
     public void compile(BRMSPackageBuilder builder,
                         AssetItem asset,
                         ContentPackageAssembler.ErrorLogger loggerthrows DroolsParserException,
                                                                    IOException {
         DefaultExpander expander = getExpanderbuilder,
                                                 asset,
                                                 logger );
 
         //add the rule keyword if its 'stand alone'
         String source = asset.getContent();
         if ( DRLFileContentHandler.isStandAloneRulesource ) ) {
             String parentName = this.parentNameFromCategoryasset,
                                                              "" );
             source = wrapRuleasset,
                                parentName,
                                source );
         }
 
         //expand and check for errors
         String drl = expander.expandsource );
         if ( expander.hasErrors() ) {
             List exErrs = expander.getErrors();
             for ( Iterator iter = exErrs.iterator(); iter.hasNext(); ) {
                 ExpanderException ex = (ExpanderExceptioniter.next();
                 logger.logErrornew ContentAssemblyErrorasset,
                                                            ex.getMessage() ) );
             }
             return;
         }
 
         builder.addPackageFromDrlnew StringReaderdrl ) );
     }
 
     private DefaultExpander getExpander(BRMSPackageBuilder builder,
                                         AssetItem asset,
                                         ContentPackageAssembler.ErrorLogger logger) {
 
         if ( !builder.hasDSL() ) {
             logger.logErrornew ContentAssemblyErrorasset,
                                                        "This rule asset requires a DSL, yet none were configured in the package." ) );
         }
        return builder.getDSLExpander();
    }
    public void assembleDRL(BRMSPackageBuilder builder,
                            AssetItem asset,
                            StringBuffer buf) {
        //add the rule keyword if its 'stand alone'
        String source = asset.getContent();
        if ( DRLFileContentHandler.isStandAloneRulesource ) ) {
            String parentName = this.parentNameFromCategoryasset,
                                                             "" );
            source = wrapRuleasset,
                               parentName,
                               source );
        }
        DefaultExpander expander = builder.getDSLExpander();
        buf.appendexpander.expandsource ) );
    }
    private String wrapRule(AssetItem asset,
                            String parentName,
                            String source) {
        if ( parentName == null || "".equalsparentName ) ) {
            return "rule '" + asset.getName() + "' \n" + source + "\nend";
        } else {
            return "rule '" + asset.getName() + "' extends " + parentName + " \n" + source + "\nend";
        }
    }
New to GrepCode? Check out our FAQ X