Package shocks.framework.workflow.sequence.repository

Source Code of shocks.framework.workflow.sequence.repository.CentralSequenceRepositoryLoader

/* ======================================================================= *
*                                               .:;tjfLLffji,             *
*                                          :,itLDKW#########Kj,           *
*                                    .:ijLGEW########KEEKKW###Kf,         *
*                              .,ifLGEK###########KDLfjjjffGE###Ei        *
*                    .:,;tLDEW#######WKEDGLfLK##KLjjjjjjjjjjjE###Wt       *
*                :;jLDEK#######WKEDGLffjjjjjD###DjjjjjjjjjjjjLW###L.      *
*            .;jGK#########WDGLffjjjjjjjjjjjD###DjjjjjjjjjjjjLW###G:      *
*           GW###WKDDDDEK#####KDLjjjjjjjjjjjfK##WGfjjjjjjjjjjK###Ei       *
*          i###WDLfjjjjjfLKW#####EGLfjjjjjjjjLK##WEGfjjjjjfLD###Kt.       *
*         ;E##KLjjjjjjjjjjjfGEW#####KEGfjjjjjjfW####WEDDEEK###WG;         *
*         f##WLjjjjjjjjjjjjjjjfLDW#####WGfjjjjjGW############Gi.          *
*        .f##KLjjjjjjjjjjjjjjjjjjjfLDEW####WW########KGLft;,.             *
*         iK##EfjjjjjjjjjjjjjjjjjjjjjjfGK#######WGjt;:                    *
*         .j###KGfjjjjjjjjjjjjjjjjjjjjjjfLDKW###WELt,                     *
*           jE#####DLfjjjjjjjjjjjjjjjjjjjjjjjfLEW#####Gj,.                *
*            ,jGK####KEGfjjjjjjjjjjjjjjjjjjjjjjjfGEK####WDj;              *
*               ,tLW####WKLfjjjjjjjjjjjjjjjjjjjjjjjfLDW####WL             *
*                  ;jGK####KEGfjjjjjjjjjjjjjjjjjjjjjjjfGEW###i            *
*             .,;itLDEK#########WGLfjjjjjjjjjjjjjjjjjjjjjfD##Wt           *
*          ,fGEKW#######WWEEEW#####KDLfjjjjjjjjjjjjjjjjjjjfK##G:          *
*       .iGK############ELjjjfGDK#####KEfjjjjjjjjjjjjjjjjjfE##G:          *
*     .fW###EGLffjfLDK####LjjjjjjfLDKW####WEGLfjjjjjjjjjjLK##Ki           *
*    .jW###EjjjjjjjjjfGW##KfjjjjjjjjjfGE######KGfjjjjjfLDW###t.           *
*    ;E###EfjjjjjjjjjjjGW##DjjjjjjjjjjjjLDKW####WEEEEEK####WG             *
*    tW###DjjjjjjjjjjjjfK##KfjjjjjjjjjjjjjfGE############KGi.             *
*    ;E###EfjjjjjjjjjjjGW##DjjjjfLGDEEKW########KEGLfj,.                  *
*    .jW###EjjjjjjjjjfDW##WDGEEKK#######WKEDLfj;,.                        *
*     .jK###EGffjjfLDK############WEDGLj;,:.                              *
*       .;LK#############WDLft;,:                                         *
*          ,fGEKKKKEGfjt;,.                                               *
*             ,jjjji,                                                     *
*                                                                         *
*                      Shocks Servlet Framework�                          *
*        Copyright (c) 2003, NRFX Technologies LLC (www.nrfx.com)         *
*                        All Rights Reserved.                             *
*                                                                         *
*  Licensed under the Academic Free License version 2.0; you may not use  *
*  this file except in compliance with the License. You may obtain a      *
*  copy of the License at http://www.opensource.org/licenses/afl-2.0.php  *
*                                                                         *
*  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 shocks.framework.workflow.sequence.repository;

import java.util.*;
import javax.servlet.ServletContext;
import shocks.dawp.*;
import shocks.framework.action.*;
import shocks.framework.meta.*;
import shocks.framework.workflow.filter.*;
import shocks.framework.workflow.filter.repository.Filter;
import shocks.framework.workflow.sequence.*;
import org.apache.log4j.*;

public class CentralSequenceRepositoryLoader {
  private static Logger log = Logger.getLogger("Shocks][CSRLoader");
 
  public static void load(ServletContext ctx) {
    MetadataRepository mdr = MetadataRepositoryFactory.getRepository(ctx);
    Set actions = mdr.getTypeSet("action");
    Iterator iter = actions.iterator();
    while(iter.hasNext()) {
      loadActionSequence(mdr, (DataSource)iter.next(), ctx);
    }
  }
 
  private static void loadActionSequence(
    MetadataRepository mdr,
    DataSource actionData,
    ServletContext ctx) {
 
    String filterName = (String)actionData.getAttribute("filter");
    String name = (String)actionData.getAttribute("name");
    String version = (String)actionData.getAttribute("version");
    SequenceRepository sr = SequenceRepositoryFactory.getRepository(ctx);
    ActionRepository ar = ActionRepositoryFactory.getRepository(ctx);
   
    log.info("");
    log.info("Building sequence for " + name + ", v" + version);
    log.info("  @filter.name = " + filterName);
   
    Action action = ar.leaseAction(actionData);
    SequenceTerminator actionSequence = new SequenceTerminator(action);   
   
    if(filterName.equals("null") || filterName==null) {
      // Create a basic sequence and add it to the sequence repository
      Sequence sequence = new Sequence(actionData, actionSequence);
      sr.addWorkflow(sequence);
    } else {
      // Build the workflow sequence using the actionSequence.
      Sequence sequence = new Sequence
        (actionData,
        filterSequence(mdr, actionSequence, filterName, ctx));
      sr.addWorkflow(sequence);
    }
  }
 
  private static Workflow filterSequence(
    MetadataRepository mdr,
    Workflow actionSequence,
    String filterName,
    ServletContext ctx) {
   
    FilterRepository fr = FilterRepositoryFactory.getRepository(ctx);
    //TODO: make certain we're getting the latest version of the filter metadata.
    DataSource filterData = mdr.leaseDataSource("filter", filterName);
    String dependencies = (String)filterData.getAttribute("depends");
    String version = (String)filterData.getAttribute("version");
    String incoming = (String)filterData.getAttribute("incoming");
    String outgoing = (String)filterData.getAttribute("outgoing");
    Workflow sequence = actionSequence;
   
    log.info("  @filter.version = " + version);
    log.info("  @filter.depends = " + dependencies);
    log.info("  @filter.incoming = " + incoming);
    log.info("  @filter.outgoing = " + outgoing);
   
    if(dependencies.equals("null") || dependencies == null) {
      // filter has no dependencies.
      Filter filter = (Filter)fr.leaseWorkflow(filterData);
      if(filter != null) {
        filter.init(sequence);
        log.info("adding " + filter.NAME + ", version " +
          filter.VERSION + " to sequence");
        sequence = filter;
        mdr.release(filterData);
      } else {
        log.info("Filter could not be obtained from the filter " +
          "repository.");
      }

    } else {
      // get a list of the filters to place in sequence.
      Stack filters = getFilterStack(mdr, dependencies, new Stack());

      while(!filters.isEmpty()) {
        DataSource metadata = (DataSource)(filters.pop());
        Filter filter = (Filter)fr.leaseWorkflow(metadata);
        if(filter != null) {
          filter.init(sequence);
          log.debug("adding " + filter.NAME + ", version " +
            filter.VERSION + " to sequence");
          sequence = filter;
          mdr.release(metadata);
        } else {
          log.info("Filter could not be obtained from the filter " +
            "repository.");
        }

      }
    }
    return sequence;
  }
 
  /**
   * recursively builds a stack of filter metadata components.
   *
   * @param mdr
   * @param depends
   * @param stack
   * @return
   */
  private static Stack getFilterStack(
    MetadataRepository mdr,
    String depends,
    Stack stack) {
   
    StringTokenizer st = new StringTokenizer(depends, ",", false);
    while(st.hasMoreTokens()){
      String token = st.nextToken().trim();
      DataSource filterData = mdr.leaseDataSource("filter", token);
      if(filterData != null){
        String fDepends = (String)filterData.getAttribute("depends");
        String name = (String)filterData.getAttribute("name");
        if(fDepends.equals("null") || fDepends == null) {
          //log.info(name);
          stack.push(filterData);
        } else {
          getFilterStack(mdr, fDepends, stack);
        }
      }
    }
    return stack;
  }
}
TOP

Related Classes of shocks.framework.workflow.sequence.repository.CentralSequenceRepositoryLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.