View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.spring.datadictionary;
17  
18  import java.util.ArrayList;
19  
20  import org.kuali.rice.krad.datadictionary.WorkflowProperty;
21  import org.kuali.rice.krad.datadictionary.WorkflowPropertyGroup;
22  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
23  import org.springframework.beans.factory.xml.ParserContext;
24  import org.springframework.util.StringUtils;
25  import org.w3c.dom.Element;
26  import org.w3c.dom.Node;
27  import org.w3c.dom.NodeList;
28  
29  public class WorkflowPropertiesBeanDefinitionParser extends KualiBeanDefinitionParserBase {
30  
31      @Override
32      protected String getBaseBeanTypeParent(Element element) {
33          return "WorkflowProperties";
34      }
35      
36      @Override
37      protected void doParse(Element element, ParserContext context, BeanDefinitionBuilder bean) {
38          // get all attributes
39          handleAbstractAttribute(element, bean);
40          
41          // parse groups
42          NodeList children = element.getChildNodes();
43          ArrayList<WorkflowPropertyGroup> groups = new ArrayList<WorkflowPropertyGroup>();
44          for ( int i = 0; i < children.getLength(); i++ ) {
45              Node child = children.item(i);
46              if ( child.getLocalName() != null && child.getLocalName().equals("group") ) {
47                  WorkflowPropertyGroup group = new WorkflowPropertyGroup();
48                  Element groupElement = (Element)child;                
49                  String basePath = groupElement.getAttribute("basePath");
50                  if ( StringUtils.hasText(basePath) ) {
51                      group.setBasePath(basePath);
52                  }
53                  groups.add( group );
54                  // parse group paths
55                  NodeList groupChildren = groupElement.getChildNodes();
56                  for ( int j = 0 ; j < groupChildren.getLength(); j++ ) {
57                      Node groupChild = groupChildren.item(j);
58                      if ( groupChild.getLocalName() != null && groupChild.getLocalName().equals("path") ) {
59                          Element pathElement = (Element)groupChild;                
60                          String path = pathElement.getAttribute("path");
61                          if ( StringUtils.hasText( path ) ) {
62                              WorkflowProperty prop = new WorkflowProperty();
63                              prop.setPath(path);
64                              group.getWorkflowProperties().add( prop );
65                          }
66                      }
67                      
68                  }
69              }
70          }        
71          bean.addPropertyValue("workflowPropertyGroups", groups);
72      }
73  
74      
75  }