Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/jbpm/workflow/delegation/impl/DelegationImpl.java


1   package org.jbpm.workflow.delegation.impl;
2   
3   import java.util.*;
4   import org.apache.log4j.*;
5   import org.jbpm.util.xml.*;
6   import org.jbpm.workflow.definition.*;
7   import org.jbpm.workflow.definition.impl.*;
8   import org.jbpm.workflow.delegation.*;
9   
10  /**
11   * manages all information for one delegation.
12   * @author Tom Baeyens
13   *
14   * @hibernate.class table="JBPM_DELEGATION"
15   */
16  public class DelegationImpl implements Delegation {
17    
18    public DelegationImpl() {}
19    
20    public void readProcessData(XmlElement xmlElement, CreationContext creationContext) {
21      this.processDefinition = creationContext.getProcessDefinition();
22      
23      Class delegatingObjectClass = creationContext.getDelegatingObject().getClass();
24      if ( delegatingObjectClass == AttributeImpl.class ) {
25        String type = xmlElement.getProperty( "type" );
26        if ( type != null ) {
27          this.className = (String) attributeTypes.get( type );
28          creationContext.check( (this.className!=null), "attribute type '" + type + "' is not supported : " + attributeTypes );
29        } else {
30          this.className = xmlElement.getProperty( "serializer" );
31          creationContext.check( (this.className!=null), "for an attribute, you must specify either a type or a serializer" );
32        }
33      } else if ( delegatingObjectClass == FieldImpl.class ) {
34        this.className = xmlElement.getProperty( "class" );
35        creationContext.check( (this.className!=null), "no class specified for a delegation : " + xmlElement );
36      } else {
37        this.className = xmlElement.getProperty( "handler" );
38        creationContext.check( (this.className!=null), "no handler specified for a delegation : " + xmlElement );
39      }
40      
41      log.debug( "parsing delegation for tag '" + xmlElement.getName() + "' : " + this.className );
42  
43      // parse the exception handler    
44      String exceptionHandlerText = xmlElement.getAttribute( "on-exception" );
45      if ( exceptionHandlerText != null ) {
46        exceptionHandlingType = ExceptionHandlingType.fromText( exceptionHandlerText );
47        creationContext.check( (exceptionHandlingType!=null), "unknown exception handler '" + exceptionHandlerText + "' in delegation " + xmlElement );
48      }
49      
50      // create the configuration string
51      XmlElement configurationXml = new XmlElement( "cfg" );
52      Iterator iter = xmlElement.getChildElements( "parameter" ).iterator();
53      while (iter.hasNext()) {
54        configurationXml.addChild( (XmlElement) iter.next() );
55      }
56      configuration = configurationXml.toString();
57    }
58    
59    /**
60     * @hibernate.id column="id" type="long" unsaved-value="null" 
61     *  generator-class="org.jbpm.util.db.IdGenerator"
62     */ 
63    public Long getId() { return id; }
64    public void setId( Long id ) { this.id = id; }
65    
66    /**
67     * @hibernate.many-to-one class="org.jbpm.workflow.definition.impl.ProcessDefinitionImpl"
68     *  cascade="none"
69     */
70    public ProcessDefinition getProcessDefinition() { return this.processDefinition; }
71    public void setProcessDefinition(ProcessDefinition processDefinition) { this.processDefinition = processDefinition; }
72    
73    /**
74     * @hibernate.property type="string" column="className"
75     */
76    public String getClassName() { return className; }
77    public void setClassName( String className ) { this.className = className; }
78    
79    /**
80     * @hibernate.property type="string" column="configuration"
81     */
82    public String getConfiguration() { return configuration; }
83    public void setConfiguration( String configuration ) { this.configuration = configuration; }
84    
85    /**
86     * @hibernate.property type="org.jbpm.workflow.delegation.impl.ExceptionHandlingType" column="exceptionHandler"
87     */
88    public ExceptionHandlingType getExceptionHandlingType() { return exceptionHandlingType; }
89    public void setExceptionHandlingType( ExceptionHandlingType exceptionHandler ) { this.exceptionHandlingType = exceptionHandler; }
90    
91    public String toString() {
92      return "delegation[" + id + "|" + className + "|" + processDefinition.getId() + "]";
93    }
94    
95    public Object getDelegate() {
96      return DelegationHelper.getInstance().getDelegate( this );
97    }
98  
99    private Long id = null;
100   private ProcessDefinition processDefinition = null;
101   private String className = null;
102   private String configuration = null;
103   private ExceptionHandlingType exceptionHandlingType = null;
104 
105   public static final Map attributeTypes = new HashMap();
106   static {
107     attributeTypes.put( "actor", "org.jbpm.workflow.delegation.impl.serializer.ActorSerializer" );
108     attributeTypes.put( "text", "org.jbpm.workflow.delegation.impl.serializer.TextSerializer" );
109     attributeTypes.put( "long", "org.jbpm.workflow.delegation.impl.serializer.LongSerializer" );
110     attributeTypes.put( "float", "org.jbpm.workflow.delegation.impl.serializer.FloatSerializer" );
111     attributeTypes.put( "date", "org.jbpm.workflow.delegation.impl.serializer.DateSerializer" );
112     attributeTypes.put( "evaluation", "org.jbpm.workflow.delegation.impl.serializer.EvaluationSerializer" );
113   }
114   
115   private static Logger log = Logger.getLogger( DelegationImpl.class );
116 }