[jboss-cvs] jboss-seam/src/main/org/jboss/seam/drools ...

Norman Richards norman.richards at jboss.com
Mon Aug 27 20:54:22 EDT 2007


  User: nrichards
  Date: 07/08/27 20:54:22

  Added:       src/main/org/jboss/seam/drools  BrmsRuleBase.java
  Log:
  JBSEAM-1764
  
  Revision  Changes    Path
  1.1      date: 2007/08/28 00:54:21;  author: nrichards;  state: Exp;jboss-seam/src/main/org/jboss/seam/drools/BrmsRuleBase.java
  
  Index: BrmsRuleBase.java
  ===================================================================
  package org.jboss.seam.drools;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.Properties;
  
  import org.drools.agent.RuleAgent;
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Create;
  import org.jboss.seam.annotations.Scope;
  import org.jboss.seam.annotations.Unwrap;
  import org.jboss.seam.annotations.intercept.BypassInterceptors;
  import org.jboss.seam.log.LogProvider;
  import org.jboss.seam.log.Logging;
  import org.jboss.seam.util.Resources;
  
  /**
   * Manager component for a BRMS RuleBase
   */
  @Scope(ScopeType.APPLICATION)
  @BypassInterceptors
  public class BrmsRuleBase
  {
     private static final LogProvider log = Logging.getLogProvider(BrmsRuleBase.class);
     
     private org.drools.RuleBase ruleBase;
     private String configurationFile;  
     
     
     private String newInstance;
     private String files;
     private String url;
     private String localCacheDir;
     private String poll;
     private String configName;
     
     
     public String getNewInstance()
     {
        return newInstance;
     }
  
     public void setNewInstance(String newInstance)
     {
        this.newInstance = newInstance;
     }
  
     public String getFiles()
     {
        return files;
     }
  
     public void setFiles(String files)
     {
        this.files = files;
     }
  
     public String getUrl()
     {
        return url;
     }
  
     public void setUrl(String url)
     {
        this.url = url;
     }
  
     public String getLocalCacheDir()
     {
        return localCacheDir;
     }
  
     public void setLocalCacheDir(String localCacheDir)
     {
        this.localCacheDir = localCacheDir;
     }
  
     public String getPoll()
     {
        return poll;
     }
  
     public void setPoll(String poll)
     {
        this.poll = poll;
     }
  
     public String getConfigName()
     {
        return configName;
     }
  
     public void setConfigName(String name)
     {
        this.configName = name;
     }
  
     public void setRuleBase(org.drools.RuleBase ruleBase)
     {
        this.ruleBase = ruleBase;
     }
  
     @Create
     public void compileRuleBase() throws Exception
     {  
        Properties properties = new Properties();
        
        loadFromPath(properties, configurationFile);
        setLocalProperties(properties);
        
        RuleAgent agent = RuleAgent.newRuleAgent(properties);
        ruleBase = agent.getRuleBase();       
     }
     
     protected void setLocalProperties(Properties properties)
     {
        if (newInstance != null) {
           properties.setProperty(RuleAgent.NEW_INSTANCE, newInstance);
        }
        if (files != null) {
           properties.setProperty(RuleAgent.FILES, files);
        }
        if (url != null) {
           properties.setProperty(RuleAgent.URLS, url);
        }
        if (localCacheDir != null) {
           properties.setProperty(RuleAgent.LOCAL_URL_CACHE, localCacheDir);
        }
        if (poll != null) {
           properties.setProperty(RuleAgent.POLL_INTERVAL, poll);
        }
        if (files != null) {
           properties.setProperty(RuleAgent.CONFIG_NAME, configName);
        }
  
     }
  
     protected void loadFromPath(Properties properties, String configurationFile)
        throws IOException
        {
        if (configurationFile != null) {
           InputStream inputStream = Resources.getResourceAsStream(configurationFile, null);
           if (inputStream != null) {
              try {
                 properties.load(inputStream);
              } finally {
                 inputStream.close();
              }         
           }
        }
     }
  
     @Unwrap
     public org.drools.RuleBase getRuleBase()
     {
        return ruleBase;
     }
     
   
     public String getConfigurationFile()
     {
        return configurationFile;
     }
  
     public void setConfigurationFile(String brmsConfig)
     {
        this.configurationFile = brmsConfig;
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list