Source Code Cross Referenced for WorkgroupTypeXmlParser.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » workflow » workgroup » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » org.kuali.workflow.workgroup 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2006 The Kuali Foundation.
003:         *
004:         *
005:         * Licensed under the Educational Community License, Version 1.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         * http://www.opensource.org/licenses/ecl1.php
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.kuali.workflow.workgroup;
018:
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.util.ArrayList;
022:        import java.util.Iterator;
023:        import java.util.List;
024:        import java.util.Vector;
025:
026:        import javax.xml.parsers.ParserConfigurationException;
027:
028:        import org.jdom.Document;
029:        import org.jdom.Element;
030:        import org.jdom.JDOMException;
031:        import org.xml.sax.SAXException;
032:
033:        import edu.iu.uis.eden.KEWServiceLocator;
034:        import edu.iu.uis.eden.exception.InvalidXmlException;
035:        import edu.iu.uis.eden.routetemplate.RuleAttribute;
036:        import edu.iu.uis.eden.util.Utilities;
037:        import edu.iu.uis.eden.util.XmlHelper;
038:        import edu.iu.uis.eden.xml.XmlConstants;
039:
040:        /**
041:         * Parses {@link WorkgroupType}s from XML.
042:         *
043:         * @see WorkgroupType
044:         *
045:         * @author ewestfal
046:         */
047:        public class WorkgroupTypeXmlParser implements  XmlConstants {
048:
049:            private WorkgroupTypeService workgroupTypeService;
050:
051:            public List<WorkgroupType> parseWorkgroupTypes(InputStream input)
052:                    throws IOException, InvalidXmlException {
053:
054:                try {
055:                    Document doc = XmlHelper.trimSAXXml(input);
056:                    Element root = doc.getRootElement();
057:                    return parseWorkgroupTypes(root);
058:                } catch (JDOMException e) {
059:                    throw new InvalidXmlException("Parse error.", e);
060:                } catch (SAXException e) {
061:                    throw new InvalidXmlException("Parse error.", e);
062:                } catch (ParserConfigurationException e) {
063:                    throw new InvalidXmlException("Parse error.", e);
064:                }
065:            }
066:
067:            public List<WorkgroupType> parseWorkgroupTypes(Element element)
068:                    throws InvalidXmlException {
069:                List<WorkgroupType> workgroupTypes = new ArrayList<WorkgroupType>();
070:
071:                Vector workgroupTypesElements = XmlHelper.findElements(element,
072:                        WORKGROUP_TYPES);
073:                for (Iterator iterator = workgroupTypesElements.iterator(); iterator
074:                        .hasNext();) {
075:                    Element workgroupTypesElement = (Element) iterator.next();
076:                    Vector workgroupTypeElements = XmlHelper.findElements(
077:                            workgroupTypesElement, WORKGROUP_TYPE);
078:                    for (Iterator typeIt = workgroupTypeElements.iterator(); typeIt
079:                            .hasNext();) {
080:                        workgroupTypes.add(parseWorkgroupType((Element) typeIt
081:                                .next()));
082:                    }
083:                }
084:                return workgroupTypes;
085:            }
086:
087:            private WorkgroupType parseWorkgroupType(Element element)
088:                    throws InvalidXmlException {
089:                String name = element.getChildText(NAME,
090:                        WORKGROUP_TYPE_NAMESPACE);
091:                String label = element.getChildText(LABEL,
092:                        WORKGROUP_TYPE_NAMESPACE);
093:                String description = element.getChildText(DESCRIPTION,
094:                        WORKGROUP_TYPE_NAMESPACE);
095:                String documentTypeName = element.getChildText(DOCUMENT_TYPE,
096:                        WORKGROUP_TYPE_NAMESPACE);
097:                if (Utilities.isEmpty(name)) {
098:                    throw new InvalidXmlException(
099:                            "WorkgroupType must have a name");
100:                }
101:                if (Utilities.isEmpty(label)) {
102:                    label = name;
103:                }
104:                WorkgroupType workgroupType = new WorkgroupType();
105:                WorkgroupType existingType = workgroupTypeService
106:                        .findByName(name);
107:                if (existingType != null) {
108:                    workgroupType = existingType;
109:                }
110:                workgroupType.setName(name);
111:                workgroupType.setLabel(label);
112:                workgroupType.setDescription(description);
113:                workgroupType.setDocumentTypeName(documentTypeName);
114:
115:                Element attributesElement = element.getChild(ATTRIBUTES,
116:                        WORKGROUP_TYPE_NAMESPACE);
117:                if (attributesElement != null) {
118:                    List<WorkgroupTypeAttribute> attributes = parseAttributes(
119:                            attributesElement, workgroupType);
120:                    updateAttributes(workgroupType, attributes);
121:                }
122:
123:                return workgroupType;
124:            }
125:
126:            private List<WorkgroupTypeAttribute> parseAttributes(
127:                    Element element, WorkgroupType workgroupType)
128:                    throws InvalidXmlException {
129:                List<WorkgroupTypeAttribute> attributes = new ArrayList<WorkgroupTypeAttribute>();
130:                Vector attributeElements = XmlHelper.findElements(element,
131:                        ATTRIBUTE);
132:                for (Iterator iterator = attributeElements.iterator(); iterator
133:                        .hasNext();) {
134:                    attributes.add(parseAttribute((Element) iterator.next(),
135:                            workgroupType));
136:                }
137:                return attributes;
138:            }
139:
140:            private WorkgroupTypeAttribute parseAttribute(Element element,
141:                    WorkgroupType workgroupType) throws InvalidXmlException {
142:                String attributeName = element.getChildText(NAME,
143:                        WORKGROUP_TYPE_NAMESPACE);
144:                if (Utilities.isEmpty(attributeName)) {
145:                    throw new InvalidXmlException(
146:                            "Attribute name must be non-empty on for Workgroup Type '"
147:                                    + workgroupType.getName() + "'");
148:                }
149:                RuleAttribute ruleAttribute = KEWServiceLocator
150:                        .getRuleAttributeService().findByName(attributeName);
151:                if (ruleAttribute == null) {
152:                    throw new InvalidXmlException(
153:                            "Could not locate rule attribute for name '"
154:                                    + attributeName + "'");
155:                }
156:                WorkgroupTypeAttribute attribute = new WorkgroupTypeAttribute();
157:                attribute.setAttribute(ruleAttribute);
158:                attribute.setWorkgroupType(workgroupType);
159:                return attribute;
160:            }
161:
162:            protected void updateAttributes(WorkgroupType workgroupType,
163:                    List<WorkgroupTypeAttribute> newAttributes) {
164:                List<WorkgroupTypeAttribute> activeAttributes = new ArrayList<WorkgroupTypeAttribute>();
165:                List<WorkgroupTypeAttribute> inactiveAttributes = new ArrayList<WorkgroupTypeAttribute>();
166:                for (WorkgroupTypeAttribute newAttribute : newAttributes) {
167:                    // determine if this is an existing attribute
168:                    boolean isExistingAttribute = false;
169:                    for (WorkgroupTypeAttribute existingAttribute : workgroupType
170:                            .getAttributes()) {
171:                        if (existingAttribute.getAttribute().getName().equals(
172:                                newAttribute.getAttribute().getName())) {
173:                            existingAttribute.setActive(true);
174:                            activeAttributes.add(existingAttribute);
175:                            isExistingAttribute = true;
176:                        }
177:                    }
178:                    if (!isExistingAttribute) {
179:                        newAttribute.setActive(true);
180:                        activeAttributes.add(newAttribute);
181:                    }
182:                }
183:                // find attributes that are no longer on the workgroup type and mark them as inactive
184:                outer: for (WorkgroupTypeAttribute existingAttribute : workgroupType
185:                        .getAttributes()) {
186:                    for (WorkgroupTypeAttribute activeAttribute : activeAttributes) {
187:                        if (existingAttribute.getAttribute().getName().equals(
188:                                activeAttribute.getAttribute().getName())) {
189:                            continue outer;
190:                        }
191:                    }
192:                    existingAttribute.setActive(false);
193:                    inactiveAttributes.add(existingAttribute);
194:                }
195:
196:                // clear out the current attributes and add the new ones
197:                workgroupType.getAttributes().clear();
198:                workgroupType.getAttributes().addAll(activeAttributes);
199:                workgroupType.getAttributes().addAll(inactiveAttributes);
200:                int orderIndex = 0;
201:                for (WorkgroupTypeAttribute attribute : workgroupType
202:                        .getAttributes()) {
203:                    attribute.setOrderIndex(orderIndex++);
204:                }
205:            }
206:
207:            public WorkgroupTypeService getWorkgroupTypeService() {
208:                return workgroupTypeService;
209:            }
210:
211:            public void setWorkgroupTypeService(
212:                    WorkgroupTypeService workgroupTypeService) {
213:                this.workgroupTypeService = workgroupTypeService;
214:            }
215:
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.