Ejemplo n.º 1
0
  /**
   * This prepares the package builder, loads the jars/classpath.
   *
   * @return true if everything is good to go, false if its all gone horribly wrong, and we can't
   *     even get the package header up.
   */
  private boolean preparePackage() {

    // firstly we loadup the classpath
    builder.addPackage(new PackageDescr(pkg.getName()));

    // now we deal with the header (imports, templates, globals).
    addDrl(ServiceImplementation.getDroolsHeader(pkg));
    loadDeclaredTypes();
    if (builder.hasErrors()) {
      recordBuilderErrors(pkg);
      // if we have any failures, lets drop out now, no point in going
      // any further
      return false;
    }

    loadDSLFiles();

    // finally, any functions we will load at this point.
    AssetItemIterator it = this.pkg.listAssetsByFormat(new String[] {AssetFormats.FUNCTION});
    while (it.hasNext()) {
      AssetItem func = (AssetItem) it.next();
      addDrl(func.getContent());
      if (builder.hasErrors()) {
        recordBuilderErrors(func);
        builder.clearErrors();
      }
    }

    return errors.size() == 0;
  }
Ejemplo n.º 2
0
 private void loadDSLFiles() {
   // now we load up the DSL files
   builder.setDSLFiles(
       BRMSPackageBuilder.getDSLMappingFiles(
           pkg,
           new BRMSPackageBuilder.DSLErrorEvent() {
             public void recordError(AssetItem asset, String message) {
               errors.add(new ContentAssemblyError(asset, message));
             }
           }));
 }
Ejemplo n.º 3
0
 /** Builds assets that are "rule" assets (ie things that are not functions etc). */
 private void buildAsset(AssetItem asset) {
   ContentHandler h = ContentManager.getHandler(asset.getFormat());
   if (h instanceof IRuleAsset) {
     try {
       ((IRuleAsset) h).compile(builder, asset, new ErrorLogger());
       if (builder.hasErrors()) {
         this.recordBuilderErrors(asset);
         // clear the errors, so we don't double report.
         builder.clearErrors();
       }
     } catch (DroolsParserException e) {
       throw new RulesRepositoryException(e);
     } catch (IOException e) {
       throw new RulesRepositoryException(e);
     }
   }
 }
Ejemplo n.º 4
0
  public String getDRL() {
    StringBuffer src = new StringBuffer();
    src.append("package " + this.pkg.getName() + "\n");
    src.append(ServiceImplementation.getDroolsHeader(this.pkg) + "\n\n");

    // now we load up the DSL files
    builder.setDSLFiles(
        BRMSPackageBuilder.getDSLMappingFiles(
            pkg,
            new BRMSPackageBuilder.DSLErrorEvent() {
              public void recordError(AssetItem asset, String message) {
                errors.add(new ContentAssemblyError(asset, message));
              }
            }));

    // do the functions and declared types.
    AssetItemIterator it =
        this.pkg.listAssetsByFormat(new String[] {AssetFormats.FUNCTION, AssetFormats.DRL_MODEL});
    while (it.hasNext()) {
      AssetItem func = (AssetItem) it.next();
      if (!func.isArchived()) {
        src.append(func.getContent() + "\n\n");
      }
    }

    // now the rules
    Iterator iter = pkg.getAssets();
    while (iter.hasNext()) {
      AssetItem asset = (AssetItem) iter.next();
      if (!asset.isArchived()) {

        ContentHandler h = ContentManager.getHandler(asset.getFormat());
        if (h instanceof IRuleAsset) {
          IRuleAsset ruleAsset = (IRuleAsset) h;
          ruleAsset.assembleDRL(builder, asset, src);
        }

        src.append("\n\n");
      }
    }

    return src.toString();
  }
Ejemplo n.º 5
0
 private void addDrl(String drl) {
   if ("".equals(drl)) {
     return;
   }
   try {
     builder.addPackageFromDrl(new StringReader(drl));
   } catch (DroolsParserException e) {
     throw new RulesRepositoryException("Unexpected error when parsing package.", e);
   } catch (IOException e) {
     throw new RulesRepositoryException("IO Exception occurred when parsing package.", e);
   }
 }
Ejemplo n.º 6
0
 private void loadDeclaredTypes() {
   AssetItemIterator it = this.pkg.listAssetsByFormat(new String[] {AssetFormats.DRL_MODEL});
   while (it.hasNext()) {
     AssetItem as = it.next();
     try {
       builder.addPackageFromDrl(new StringReader(as.getContent()));
     } catch (DroolsParserException e) {
       this.errors.add(new ContentAssemblyError(as, "Parser exception: " + e.getMessage()));
     } catch (IOException e) {
       this.errors.add(new ContentAssemblyError(as, "IOException: " + e.getMessage()));
     }
   }
 }
Ejemplo n.º 7
0
 public void createBuilder() {
   List<JarInputStream> jars = BRMSPackageBuilder.getJars(pkg);
   builder = BRMSPackageBuilder.getInstance(jars);
 }
Ejemplo n.º 8
0
 /** I've got a package people ! */
 public Package getBinaryPackage() {
   if (this.hasErrors()) {
     throw new IllegalStateException("There is no package available, as there were errors.");
   }
   return builder.getPackage();
 }
Ejemplo n.º 9
0
 /** This will accumulate the errors. */
 private void recordBuilderErrors(VersionableItem asset) {
   DroolsError[] errs = builder.getErrors().getErrors();
   for (int i = 0; i < errs.length; i++) {
     this.errors.add(new ContentAssemblyError(asset, errs[i].getMessage()));
   }
 }