Source Code Cross Referenced for ParameterServiceImpl.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » kfs » service » impl » 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.kfs.service.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 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.kfs.service.impl;
017:
018:        import java.lang.reflect.Method;
019:        import java.util.ArrayList;
020:        import java.util.Arrays;
021:        import java.util.Collections;
022:        import java.util.HashMap;
023:        import java.util.List;
024:        import java.util.Map;
025:
026:        import org.apache.commons.lang.StringUtils;
027:        import org.kuali.RiceConstants;
028:        import org.kuali.core.KualiModule;
029:        import org.kuali.core.bo.BusinessObject;
030:        import org.kuali.core.bo.Parameter;
031:        import org.kuali.core.bo.ParameterDetailType;
032:        import org.kuali.core.datadictionary.BusinessObjectEntry;
033:        import org.kuali.core.datadictionary.DocumentEntry;
034:        import org.kuali.core.datadictionary.TransactionalDocumentEntry;
035:        import org.kuali.core.document.TransactionalDocument;
036:        import org.kuali.core.service.BusinessObjectService;
037:        import org.kuali.core.service.DataDictionaryService;
038:        import org.kuali.core.service.KualiModuleService;
039:        import org.kuali.core.util.cache.MethodCacheInterceptor;
040:        import org.kuali.core.util.spring.Cached;
041:        import org.kuali.kfs.batch.Step;
042:        import org.kuali.kfs.context.SpringContext;
043:        import org.kuali.kfs.service.ParameterEvaluator;
044:        import org.kuali.kfs.service.ParameterService;
045:        import org.kuali.kfs.service.impl.ParameterConstants.COMPONENT;
046:        import org.kuali.kfs.service.impl.ParameterConstants.NAMESPACE;
047:        import org.springframework.transaction.annotation.Transactional;
048:
049:        /**
050:         * See ParameterService. The componentClass must be the business object, document, or step class that the parameter is associated
051:         * with. Implementations of this class know how to translate that to a namespace (for ParameterService Impl, determine what module
052:         * the Class is associated with by parsing the package) and detail type (for ParameterServiceImpl, document Class --> use simple
053:         * class name minus the word Document / business object Class --> use simple class name, batch step class --> use the simple class
054:         * name). In cases where the parameter is applicable to all documents, all lookups, all batch steps, or all components in a
055:         * particular module, you should pass in the appropriate constant class in ParameterConstants for the component Class (e.g. all
056:         * purchasing documents = PURCHASING_DOCUMENT.class, all purchasing lookups = PURCHASING_LOOKUP.class, all purchasing batch steps =
057:         * PURCHASING_BATCH.class, and all purchasing components = PURCHASING_ALL.class). In addition, certain methods take
058:         * constrainingValue and constrainedValue Strings. The constrainedValue is the value that you want to compare to the Parameter
059:         * value, and the constrainingValue is used for complex parameters that limit one field value based on the value of another field,
060:         * e.g VALID_OBJECT_LEVELS_BY_OBJECT_TYPE.
061:         */
062:        @Transactional
063:        @Cached
064:        public class ParameterServiceImpl implements  ParameterService {
065:            private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
066:                    .getLogger(ParameterServiceImpl.class);
067:            private static List<ParameterDetailType> components = new ArrayList<ParameterDetailType>();
068:            private DataDictionaryService dataDictionaryService;
069:            private KualiModuleService moduleService;
070:            private BusinessObjectService businessObjectService;
071:
072:            /**
073:             * @see org.kuali.kfs.service.ParameterService#parameterExists(java.lang.Class componentClass, java.lang.String parameterName)
074:             */
075:            public boolean parameterExists(Class componentClass,
076:                    String parameterName) {
077:                return getParameterWithoutExceptions(
078:                        getNamespace(componentClass),
079:                        getDetailType(componentClass), parameterName) != null;
080:            }
081:
082:            /**
083:             * This method provides a convenient way to access the value of indicator parameters with Y/N values. Y is translated to true
084:             * and N is translated to false.
085:             * 
086:             * @param componentClass
087:             * @param parameterName
088:             * @return boolean value of Yes/No indicator parameter
089:             */
090:            public boolean getIndicatorParameter(Class componentClass,
091:                    String parameterName) {
092:                return "Y".equals(getParameter(componentClass, parameterName)
093:                        .getParameterValue());
094:            }
095:
096:            /**
097:             * @see org.kuali.kfs.service.ParameterService#getParameterValue(java.lang.Class componentClass, java.lang.String parameterName)
098:             */
099:            public String getParameterValue(Class componentClass,
100:                    String parameterName) {
101:                return getParameter(componentClass, parameterName)
102:                        .getParameterValue();
103:            }
104:
105:            /**
106:             * This will look for constrainingValue=<value to return> within the parameter text and return that if it is found. Otherwise,
107:             * it will return null. Note, that if constrainingValue=value1,value2... (commas specific to the ParameterServiceImpl
108:             * implementation) is found it will still return null, because calling this method states the assumption that there is only one
109:             * value within the parameter text that corresponds to the constraining value.
110:             * 
111:             * @param componentClass
112:             * @param parameterName
113:             * @param constrainingValue
114:             * @return derived value String or null
115:             */
116:            public String getParameterValue(Class componentClass,
117:                    String parameterName, String constrainingValue) {
118:                List<String> parameterValues = getParameterValues(
119:                        componentClass, parameterName, constrainingValue);
120:                if (parameterValues.size() == 1) {
121:                    return parameterValues.get(0);
122:                }
123:                return null;
124:            }
125:
126:            /**
127:             * This method can be used to parse the value of a parameter by splitting on a semi-colon.
128:             * 
129:             * @param componentClass
130:             * @param parameterName
131:             * @return parsed List of String parameter values
132:             */
133:            public List<String> getParameterValues(Class componentClass,
134:                    String parameterName) {
135:                return getParameterValues(getParameter(componentClass,
136:                        parameterName));
137:            }
138:
139:            /**
140:             * This method looks for constrainingValue=<some text> within the parameter text and splits that text on a comma to generate
141:             * the List to return.
142:             * 
143:             * @param componentClass
144:             * @param parameterName
145:             * @param constrainingValue
146:             * @return derived values List<String> or an empty list if no values are found
147:             */
148:            public List<String> getParameterValues(Class componentClass,
149:                    String parameterName, String constrainingValue) {
150:                return getParameterValues(getParameter(componentClass,
151:                        parameterName), constrainingValue);
152:            }
153:
154:            /**
155:             * This method will return an instance of the parameterEvaluator bean defined in Spring, initialized with the Parameter
156:             * corresponding to the specified componentClass and parameterName and the values of the Parameter.
157:             * 
158:             * @param componentClass
159:             * @param parameterName
160:             * @return ParameterEvaluator instance initialized with the Parameter corresponding to the specified componentClass and
161:             *         parameterName and the values of the Parameter
162:             */
163:            public ParameterEvaluator getParameterEvaluator(
164:                    Class componentClass, String parameterName) {
165:                return getParameterEvaluator(getParameter(componentClass,
166:                        parameterName));
167:            }
168:
169:            /**
170:             * This method will return an instance of the parameterEvaluator bean defined in Spring, initialized with the Parameter
171:             * corresponding to the specified componentClass and parameterName, the values of the Parameter, the knowledge of whether the
172:             * values are allowed or denied, and the constrainedValue.
173:             * 
174:             * @param componentClass
175:             * @param parameterName
176:             * @return ParameterEvaluator instance initialized with the Parameter corresponding to the specified componentClass and
177:             *         parameterName, the values of the Parameter, the knowledge of whether the values are allowed or denied, and the
178:             *         constrainedValue
179:             */
180:            public ParameterEvaluator getParameterEvaluator(
181:                    Class componentClass, String parameterName,
182:                    String constrainedValue) {
183:                return getParameterEvaluator(getParameter(componentClass,
184:                        parameterName), constrainedValue);
185:            }
186:
187:            /**
188:             * This method will return an instance of the parameterEvaluator bean defined in Spring, initialized with the Parameter
189:             * corresponding to the specified componentClass and parameterName, the values of the Parameter that correspond to the specified
190:             * constrainingValue, the knowledge of whether the values are allowed or denied, and the constrainedValue.
191:             * 
192:             * @param componentClass
193:             * @param parameterName
194:             * @return ParameterEvaluator instance initialized with the Parameter corresponding to the specified componentClass and
195:             *         parameterName, the values of the Parameter that correspond to the specified constrainingValue, the knowledge of
196:             *         whether the values are allowed or denied, and the constrainedValue
197:             */
198:            public ParameterEvaluator getParameterEvaluator(
199:                    Class componentClass, String parameterName,
200:                    String constrainingValue, String constrainedValue) {
201:                return getParameterEvaluator(getParameter(componentClass,
202:                        parameterName), constrainingValue, constrainedValue);
203:            }
204:
205:            /**
206:             * This method will return an instance of the parameterEvaluator bean defined in Spring, initialized with the Parameter
207:             * corresponding to the specified componentClass and allowParameterName or to the specified componentClass and denyParameterName
208:             * (depending on which restricts based on the constraining value) or an instance of AlwaysSucceedParameterEvaluatorImpl if
209:             * neither restricts, the values of the Parameter that correspond to the specified constrainingValue, the knowledge of whether
210:             * the values are allowed or denied, and the constrainedValue.
211:             * 
212:             * @param componentClass
213:             * @param allowParameterName
214:             * @param denyParameterName
215:             * @param constrainingValue
216:             * @param constrainedValue
217:             * @return AlwaysSucceedParameterEvaluatorImpl or ParameterEvaluator instance initialized with the Parameter that corresponds to
218:             *         the constrainingValue restriction, the values of the Parameter that correspond to the specified constrainingValue,
219:             *         the knowledge of whether the values are allowed or denied, and the constrainedValue
220:             */
221:            public ParameterEvaluator getParameterEvaluator(
222:                    Class componentClass, String allowParameterName,
223:                    String denyParameterName, String constrainingValue,
224:                    String constrainedValue) {
225:                Parameter allowParameter = getParameter(componentClass,
226:                        allowParameterName);
227:                Parameter denyParameter = getParameter(componentClass,
228:                        denyParameterName);
229:                if (!getParameterValues(allowParameter, constrainingValue)
230:                        .isEmpty()
231:                        && !getParameterValues(denyParameter, constrainingValue)
232:                                .isEmpty()) {
233:                    throw new IllegalArgumentException(
234:                            "The getParameterEvaluator(Class componentClass, String allowParameterName, String denyParameterName, String constrainingValue, String constrainedValue) method of ParameterServiceImpl does not facilitate evaluation of combination allow and deny parameters that both have values for the constraining value: "
235:                                    + allowParameterName
236:                                    + " / "
237:                                    + denyParameterName
238:                                    + " / "
239:                                    + constrainingValue);
240:                }
241:                if (getParameterValues(allowParameter, constrainingValue)
242:                        .isEmpty()
243:                        && getParameterValues(denyParameter, constrainingValue)
244:                                .isEmpty()) {
245:                    return AlwaysSucceedParameterEvaluatorImpl.getInstance();
246:                }
247:                return getParameterEvaluator(getParameterValues(denyParameter,
248:                        constrainingValue).isEmpty() ? allowParameter
249:                        : denyParameter, constrainingValue, constrainedValue);
250:            }
251:
252:            /**
253:             * @see org.kuali.kfs.service.ParameterService#getParameterEvaluators(java.lang.Class componentClass, java.lang.String
254:             *      constrainedValue)
255:             */
256:            public List<ParameterEvaluator> getParameterEvaluators(
257:                    Class componentClass, String constrainedValue) {
258:                List<ParameterEvaluator> parameterEvaluators = new ArrayList<ParameterEvaluator>();
259:                for (Parameter parameter : getParameters(componentClass)) {
260:                    parameterEvaluators.add(getParameterEvaluator(parameter,
261:                            constrainedValue));
262:                }
263:                return parameterEvaluators;
264:            }
265:
266:            /**
267:             * @see org.kuali.kfs.service.ParameterService#getParameterEvaluators(java.lang.Class componentClass, java.lang.String
268:             *      constrainingValue, java.lang.String constrainedValue)
269:             */
270:            public List<ParameterEvaluator> getParameterEvaluators(
271:                    Class componentClass, String constrainingValue,
272:                    String constrainedValue) {
273:                List<ParameterEvaluator> parameterEvaluators = new ArrayList<ParameterEvaluator>();
274:                for (Parameter parameter : getParameters(componentClass)) {
275:                    parameterEvaluators.add(getParameterEvaluator(parameter,
276:                            constrainingValue, constrainedValue));
277:                }
278:                return parameterEvaluators;
279:            }
280:
281:            /**
282:             * This method derived ParameterDetailedTypes from the DataDictionary for all BusinessObjects and Documents and from Spring for
283:             * all batch Steps.
284:             * 
285:             * @return List<ParameterDetailedType> containing the detailed types derived from the data dictionary and Spring
286:             */
287:            public List<ParameterDetailType> getNonDatabaseDetailTypes() {
288:                if (components.isEmpty()) {
289:                    Map<String, ParameterDetailType> uniqueParameterDetailTypeMap = new HashMap<String, ParameterDetailType>();
290:                    dataDictionaryService.getDataDictionary()
291:                            .forceCompleteDataDictionaryLoad();
292:                    for (BusinessObjectEntry businessObjectEntry : dataDictionaryService
293:                            .getDataDictionary().getBusinessObjectEntries()
294:                            .values()) {
295:                        ParameterDetailType parameterDetailType = getParameterDetailType(businessObjectEntry
296:                                .getBusinessObjectClass());
297:                        try {
298:                            uniqueParameterDetailTypeMap.put(
299:                                    parameterDetailType
300:                                            .getParameterDetailTypeCode(),
301:                                    parameterDetailType);
302:                        } catch (Exception e) {
303:                            LOG
304:                                    .error(
305:                                            "The getDataDictionaryAndSpringComponents method of ParameterUtils encountered an exception while trying to create the detail type for business object class: "
306:                                                    + businessObjectEntry
307:                                                            .getBusinessObjectClass(),
308:                                            e);
309:                        }
310:                    }
311:                    for (DocumentEntry documentEntry : dataDictionaryService
312:                            .getDataDictionary().getDocumentEntries().values()) {
313:                        if (documentEntry instanceof  TransactionalDocumentEntry) {
314:                            ParameterDetailType parameterDetailType = getParameterDetailType(documentEntry
315:                                    .getDocumentClass());
316:                            try {
317:                                uniqueParameterDetailTypeMap.put(
318:                                        parameterDetailType
319:                                                .getParameterDetailTypeCode(),
320:                                        parameterDetailType);
321:                            } catch (Exception e) {
322:                                LOG
323:                                        .error(
324:                                                "The getDataDictionaryAndSpringComponents method of ParameterUtils encountered an exception while trying to create the detail type for transactional document class: "
325:                                                        + documentEntry
326:                                                                .getDocumentClass(),
327:                                                e);
328:                            }
329:                        }
330:                    }
331:                    for (Step step : SpringContext.getBeansOfType(Step.class)
332:                            .values()) {
333:                        ParameterDetailType parameterDetailType = getParameterDetailType(step
334:                                .getClass());
335:                        try {
336:                            uniqueParameterDetailTypeMap.put(
337:                                    parameterDetailType
338:                                            .getParameterDetailTypeCode(),
339:                                    parameterDetailType);
340:                        } catch (Exception e) {
341:                            LOG
342:                                    .error(
343:                                            "The getDataDictionaryAndSpringComponents method of ParameterUtils encountered an exception while trying to create the detail type for step class: "
344:                                                    + step.getClass(), e);
345:                        }
346:                    }
347:                    components.addAll(uniqueParameterDetailTypeMap.values());
348:                }
349:                return Collections.unmodifiableList(components);
350:            }
351:
352:            /**
353:             * @see org.kuali.kfs.service.ParameterService#setParameterForTesting(java.lang.Class componentClass, java.lang.String
354:             *      parameterName, java.lang.String parameterText)
355:             */
356:            public void setParameterForTesting(Class componentClass,
357:                    String parameterName, String parameterText) {
358:                Parameter parameter = (Parameter) getParameter(componentClass,
359:                        parameterName);
360:                parameter.setParameterValue(parameterText);
361:                SpringContext.getBean(BusinessObjectService.class).save(
362:                        parameter);
363:                try {
364:                    removeCachedMethod(ParameterService.class.getMethod(
365:                            "getParameterValue", new Class[] { Class.class,
366:                                    String.class }), new Object[] {
367:                            componentClass, parameterName });
368:                    removeCachedMethod(ParameterService.class.getMethod(
369:                            "getIndicatorParameter", new Class[] { Class.class,
370:                                    String.class }), new Object[] {
371:                            componentClass, parameterName });
372:                    removeCachedMethod(ParameterService.class.getMethod(
373:                            "getParameterValues", new Class[] { Class.class,
374:                                    String.class }), new Object[] {
375:                            componentClass, parameterName });
376:                } catch (Exception e) {
377:                    throw new RuntimeException(
378:                            new StringBuffer(
379:                                    "The setParameterForTesting of ParameterServiceImpl failed: ")
380:                                    .append(componentClass).append(" / ")
381:                                    .append(parameterName).toString(), e);
382:                }
383:            }
384:
385:            private String getNamespace(Class documentOrStepClass) {
386:                if (documentOrStepClass != null) {
387:                    if (documentOrStepClass
388:                            .isAnnotationPresent(NAMESPACE.class)) {
389:                        return ((NAMESPACE) documentOrStepClass
390:                                .getAnnotation(NAMESPACE.class)).namespace();
391:                    }
392:                    KualiModule module = moduleService
393:                            .getResponsibleModule(documentOrStepClass);
394:                    if (module != null) {
395:                        return ParameterConstants.FINANCIAL_NAMESPACE_PREFIX
396:                                + module.getModuleCode();
397:                    }
398:                    if (documentOrStepClass.getName().startsWith(
399:                            "org.kuali.core")) {
400:                        return ParameterConstants.NERVOUS_SYSTEM_NAMESPACE;
401:                    }
402:                    if (documentOrStepClass.getName().startsWith(
403:                            "org.kuali.kfs")) {
404:                        return ParameterConstants.FINANCIAL_SYSTEM_NAMESPACE;
405:                    }
406:                    throw new IllegalArgumentException(
407:                            "The getNamespace method of ParameterUtils requires documentOrStepClass with a package prefix of org.kuali.core, org.kuali.kfs, or org.kuali.module");
408:                } else {
409:                    throw new IllegalArgumentException(
410:                            "The getNamespace method of ParameterUtils requires non-null documentOrStepClass");
411:                }
412:            }
413:
414:            private String getDetailType(Class documentOrStepClass) {
415:                if (documentOrStepClass.isAnnotationPresent(COMPONENT.class)) {
416:                    return ((COMPONENT) documentOrStepClass
417:                            .getAnnotation(COMPONENT.class)).component();
418:                }
419:                if (TransactionalDocument.class
420:                        .isAssignableFrom(documentOrStepClass)) {
421:                    return documentOrStepClass.getSimpleName().replace(
422:                            "Document", "");
423:                } else if (BusinessObject.class
424:                        .isAssignableFrom(documentOrStepClass)
425:                        || Step.class.isAssignableFrom(documentOrStepClass)) {
426:                    return documentOrStepClass.getSimpleName();
427:                }
428:                throw new IllegalArgumentException(
429:                        "The getDetailType method of ParameterServiceImpl requires TransactionalDocument, BusinessObject, or Step class");
430:            }
431:
432:            private String getDetailTypeName(Class documentOrStepClass) {
433:                if (documentOrStepClass.isAnnotationPresent(COMPONENT.class)) {
434:                    BusinessObjectEntry boe = dataDictionaryService
435:                            .getDataDictionary().getBusinessObjectEntry(
436:                                    documentOrStepClass.getName());
437:                    if (boe != null) {
438:                        return boe.getObjectLabel();
439:                    } else {
440:                        return ((COMPONENT) documentOrStepClass
441:                                .getAnnotation(COMPONENT.class)).component();
442:                    }
443:                }
444:                if (TransactionalDocument.class
445:                        .isAssignableFrom(documentOrStepClass)) {
446:                    return dataDictionaryService
447:                            .getDocumentLabelByClass(documentOrStepClass);
448:                } else if (BusinessObject.class
449:                        .isAssignableFrom(documentOrStepClass)
450:                        || Step.class.isAssignableFrom(documentOrStepClass)) {
451:                    BusinessObjectEntry boe = dataDictionaryService
452:                            .getDataDictionary().getBusinessObjectEntry(
453:                                    documentOrStepClass.getName());
454:                    if (boe != null) {
455:                        return boe.getObjectLabel();
456:                    } else {
457:                        return documentOrStepClass.getSimpleName();
458:                    }
459:                }
460:                throw new IllegalArgumentException(
461:                        "The getDetailTypeName method of ParameterServiceImpl requires TransactionalDocument, BusinessObject, or Step class");
462:            }
463:
464:            private ParameterEvaluator getParameterEvaluator(Parameter parameter) {
465:                ParameterEvaluatorImpl parameterEvaluator = new ParameterEvaluatorImpl();
466:                parameterEvaluator.setParameter(parameter);
467:                parameterEvaluator
468:                        .setConstraintIsAllow(constraintIsAllow(parameter));
469:                parameterEvaluator.setValues(getParameterValues(parameter));
470:                return parameterEvaluator;
471:            }
472:
473:            private ParameterEvaluator getParameterEvaluator(
474:                    Parameter parameter, String constrainedValue) {
475:                ParameterEvaluator parameterEvaluator = getParameterEvaluator(parameter);
476:                parameterEvaluator.setConstrainedValue(constrainedValue);
477:                return parameterEvaluator;
478:            }
479:
480:            private ParameterEvaluator getParameterEvaluator(
481:                    Parameter parameter, String constrainingValue,
482:                    String constrainedValue) {
483:                ParameterEvaluator parameterEvaluator = getParameterEvaluator(
484:                        parameter, constrainedValue);
485:                ((ParameterEvaluatorImpl) parameterEvaluator)
486:                        .setValues(getParameterValues(parameter,
487:                                constrainingValue));
488:                return parameterEvaluator;
489:            }
490:
491:            private ParameterDetailType getParameterDetailType(
492:                    Class documentOrStepClass) {
493:                String detailTypeString = getDetailType(documentOrStepClass);
494:                String detailTypeName = getDetailTypeName(documentOrStepClass);
495:                ParameterDetailType detailType = new ParameterDetailType(
496:                        getNamespace(documentOrStepClass), detailTypeString,
497:                        (detailTypeName == null) ? detailTypeString
498:                                : detailTypeName);
499:                detailType.refreshNonUpdateableReferences();
500:                return detailType;
501:            }
502:
503:            private Parameter getParameter(Class componentClass,
504:                    String parameterName) {
505:                Parameter parameter = getParameter(
506:                        getNamespace(componentClass),
507:                        getDetailType(componentClass), parameterName);
508:                if (parameter == null) {
509:                    throw new IllegalArgumentException(
510:                            "The getParameter method of ParameterServiceImpl requires a componentClass and parameterName that correspond to an existing parameter");
511:                }
512:                return parameter;
513:            }
514:
515:            private List<String> getParameterValues(Parameter parameter,
516:                    String constrainingValue) {
517:                List<String> constraintValuePairs = getParameterValues(parameter);
518:                for (String pair : constraintValuePairs) {
519:                    if (constrainingValue.equals(StringUtils.substringBefore(
520:                            pair, "="))) {
521:                        return Arrays.asList(StringUtils.substringAfter(pair,
522:                                "=").split(","));
523:                    }
524:                }
525:                return Collections.EMPTY_LIST;
526:            }
527:
528:            private List<String> getParameterValues(Parameter parameter) {
529:                if (parameter == null
530:                        || StringUtils.isBlank(parameter.getParameterValue())) {
531:                    return Collections.EMPTY_LIST;
532:                }
533:                return Arrays.asList(parameter.getParameterValue().split(";"));
534:            }
535:
536:            private List<Parameter> getParameters(Class componentClass) {
537:                Map<String, String> fieldValues = new HashMap<String, String>();
538:                fieldValues.put("parameterNamespaceCode",
539:                        getNamespace(componentClass));
540:                fieldValues.put("parameterDetailTypeCode",
541:                        getDetailType(componentClass));
542:                return new ArrayList<Parameter>(businessObjectService
543:                        .findMatching(Parameter.class, fieldValues));
544:            }
545:
546:            private Parameter getParameter(String namespaceCode,
547:                    String detailTypeCode, String parameterName) {
548:                if (StringUtils.isBlank(namespaceCode)
549:                        || StringUtils.isBlank(detailTypeCode)
550:                        || StringUtils.isBlank(parameterName)) {
551:                    throw new IllegalArgumentException(
552:                            "The getParameter method of KualiConfigurationServiceImpl requires a non-blank namespaceCode, parameterDetailTypeCode, and parameterName");
553:                }
554:                Parameter param = getParameterWithoutExceptions(namespaceCode,
555:                        detailTypeCode, parameterName);
556:                if (param == null) {
557:                    throw new IllegalArgumentException(
558:                            "The getParameter method of KualiConfigurationServiceImpl was unable to find parameter: "
559:                                    + namespaceCode
560:                                    + " / "
561:                                    + detailTypeCode
562:                                    + " / " + parameterName);
563:                }
564:                return param;
565:            }
566:
567:            private Parameter getParameterWithoutExceptions(
568:                    String namespaceCode, String detailTypeCode,
569:                    String parameterName) {
570:                HashMap<String, String> crit = new HashMap<String, String>(3);
571:                crit.put("parameterNamespaceCode", namespaceCode);
572:                crit.put("parameterDetailTypeCode", detailTypeCode);
573:                crit.put("parameterName", parameterName);
574:                Parameter param = (Parameter) businessObjectService
575:                        .findByPrimaryKey(Parameter.class, crit);
576:                return param;
577:            }
578:
579:            private void removeCachedMethod(Method method, Object[] arguments) {
580:                MethodCacheInterceptor methodCacheInterceptor = SpringContext
581:                        .getBean(MethodCacheInterceptor.class);
582:                String cacheKey = methodCacheInterceptor.buildCacheKey(method
583:                        .toString(), arguments);
584:                if (methodCacheInterceptor.containsCacheKey(cacheKey)) {
585:                    methodCacheInterceptor.removeCacheKey(cacheKey);
586:                }
587:            }
588:
589:            private boolean constraintIsAllow(Parameter parameter) {
590:                return RiceConstants.APC_ALLOWED_OPERATOR.equals(parameter
591:                        .getParameterConstraintCode());
592:            }
593:
594:            public void setDataDictionaryService(
595:                    DataDictionaryService dataDictionaryService) {
596:                this .dataDictionaryService = dataDictionaryService;
597:            }
598:
599:            public void setModuleService(KualiModuleService moduleService) {
600:                this .moduleService = moduleService;
601:            }
602:
603:            public void setBusinessObjectService(
604:                    BusinessObjectService businessObjectService) {
605:                this.businessObjectService = businessObjectService;
606:            }
607:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.