Source Code Cross Referenced for OJBUtility.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » gl » util » 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.module.gl.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-2007 The Kuali Foundation.
003:         * 
004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         * http://www.opensource.org/licenses/ecl1.php
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.kuali.module.gl.util;
017:
018:        import java.util.Collection;
019:        import java.util.Iterator;
020:        import java.util.LinkedHashMap;
021:        import java.util.Map;
022:
023:        import org.apache.commons.beanutils.DynaClass;
024:        import org.apache.commons.beanutils.DynaProperty;
025:        import org.apache.commons.beanutils.PropertyUtils;
026:        import org.apache.commons.beanutils.WrapDynaClass;
027:        import org.apache.ojb.broker.query.Criteria;
028:        import org.apache.ojb.broker.query.Query;
029:        import org.kuali.core.dao.LookupDao;
030:        import org.kuali.kfs.KFSConstants;
031:        import org.kuali.kfs.context.SpringContext;
032:        import org.kuali.kfs.service.ParameterService;
033:        import org.kuali.kfs.service.impl.ParameterConstants;
034:
035:        /**
036:         * This class provides a set of utilities that can handle common tasks related to business objects.
037:         */
038:        public class OJBUtility {
039:            private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
040:                    .getLogger(OJBUtility.class);
041:
042:            public static final String LOOKUP_DAO = "lookupDao";
043:
044:            /**
045:             * This method builds a map of business object with its property names and values
046:             * 
047:             * @param businessObject the given business object
048:             * @return the map of business object with its property names and values
049:             */
050:            public static LinkedHashMap buildPropertyMap(Object businessObject) {
051:                DynaClass dynaClass = WrapDynaClass
052:                        .createDynaClass(businessObject.getClass());
053:                DynaProperty[] properties = dynaClass.getDynaProperties();
054:                LinkedHashMap propertyMap = new LinkedHashMap();
055:
056:                try {
057:                    for (int numOfProperty = 0; numOfProperty < properties.length; numOfProperty++) {
058:                        String propertyName = properties[numOfProperty]
059:                                .getName();
060:                        if (PropertyUtils.isWriteable(businessObject,
061:                                propertyName)) {
062:                            Object propertyValue = PropertyUtils.getProperty(
063:                                    businessObject, propertyName);
064:                            propertyMap.put(propertyName, propertyValue);
065:                        }
066:                    }
067:                } catch (Exception e) {
068:                    LOG.error("OJBUtility.buildPropertyMap()" + e);
069:                }
070:                return propertyMap;
071:            }
072:
073:            /**
074:             * This method builds an OJB query criteria based on the input field map
075:             * 
076:             * @param fieldValues the input field map
077:             * @param businessObject the given business object
078:             * @return an OJB query criteria
079:             */
080:            public static Criteria buildCriteriaFromMap(Map fieldValues,
081:                    Object businessObject) {
082:                Criteria criteria = new Criteria();
083:
084:                try {
085:                    Iterator propsIter = fieldValues.keySet().iterator();
086:                    while (propsIter.hasNext()) {
087:                        String propertyName = (String) propsIter.next();
088:                        Object propertyValueObject = fieldValues
089:                                .get(propertyName);
090:                        String propertyValue = (propertyValueObject != null) ? propertyValueObject
091:                                .toString().trim()
092:                                : "";
093:
094:                        // if searchValue is empty and the key is not a valid property ignore
095:                        boolean isCreated = createCriteria(businessObject,
096:                                propertyValue, propertyName, criteria);
097:                        if (!isCreated) {
098:                            continue;
099:                        }
100:                    }
101:                } catch (Exception e) {
102:                    LOG.error("OJBUtility.buildCriteriaFromMap()" + e);
103:                }
104:                return criteria;
105:            }
106:
107:            /**
108:             * Limit the size of the result set from the given query operation
109:             * 
110:             * @param query the given query operation
111:             */
112:            public static void limitResultSize(Query query) {
113:                int startingIndex = 1;
114:                int endingIndex = getResultLimit().intValue();
115:
116:                query.setStartAtIndex(startingIndex);
117:                query.setEndAtIndex(endingIndex);
118:            }
119:
120:            /**
121:             * This method calculates the actual size of given selection results
122:             * 
123:             * @param result the given selection results
124:             * @param recordCount the possible number of the given results
125:             * @param fieldValues the input field map
126:             * @param businessObject the given business object
127:             * @return the actual size of given selection results
128:             */
129:            public static Long getResultActualSize(Collection result,
130:                    Integer recordCount, Map fieldValues, Object businessObject) {
131:                int resultSize = result.size();
132:                Integer limit = getResultLimit();
133:                Long resultActualSize = new Long(resultSize);
134:
135:                if (recordCount > limit) {
136:                    long actualCount = recordCount.longValue() + resultSize
137:                            - limit.longValue();
138:                    resultActualSize = new Long(actualCount);
139:                }
140:                return resultActualSize;
141:            }
142:
143:            /**
144:             * This method gets the size of a result set from the given search criteria
145:             * 
146:             * @param fieldValues the input field map
147:             * @param businessObject the given business object
148:             * @return the size of a result set from the given search criteria
149:             */
150:            public static Long getResultSizeFromMap(Map fieldValues,
151:                    Object businessObject) {
152:                LookupDao lookupDao = SpringContext.getBean(LookupDao.class);
153:                return lookupDao.findCountByMap(businessObject, fieldValues);
154:            }
155:
156:            /**
157:             * This method gets the limit of the selection results
158:             * 
159:             * @return the limit of the selection results
160:             */
161:            public static Integer getResultLimit() {
162:                // get the result limit number from configuration
163:                String limitConfig = SpringContext.getBean(
164:                        ParameterService.class).getParameterValue(
165:                        ParameterConstants.NERVOUS_SYSTEM_LOOKUP.class,
166:                        KFSConstants.LOOKUP_RESULTS_LIMIT_URL_KEY);
167:
168:                Integer limit = Integer.MAX_VALUE;
169:                if (limitConfig != null) {
170:                    limit = Integer.valueOf(limitConfig);
171:                }
172:                return limit;
173:            }
174:
175:            /**
176:             * This method build OJB criteria from the given property value and name
177:             */
178:            public static boolean createCriteria(Object businessObject,
179:                    String propertyValue, String propertyName, Criteria criteria) {
180:                LookupDao lookupDao = SpringContext.getBean(LookupDao.class);
181:                return lookupDao.createCriteria(businessObject, propertyValue,
182:                        propertyName, criteria);
183:            }
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.