Source Code Cross Referenced for FunctionExpressionEvaluator.java in  » ESB » mule » org » mule » util » expression » 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 » ESB » mule » org.mule.util.expression 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: FunctionExpressionEvaluator.java 11246 2008-03-07 12:27:48Z dfeist $
003:         * --------------------------------------------------------------------------------------
004:         * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
005:         *
006:         * The software in this package is published under the terms of the CPAL v1.0
007:         * license, a copy of which has been included with this distribution in the
008:         * LICENSE.txt file.
009:         */
010:        package org.mule.util.expression;
011:
012:        import org.mule.api.MuleRuntimeException;
013:        import org.mule.config.i18n.CoreMessages;
014:        import org.mule.util.DateUtils;
015:        import org.mule.util.UUID;
016:
017:        import java.net.InetAddress;
018:        import java.net.UnknownHostException;
019:        import java.sql.Timestamp;
020:        import java.util.Date;
021:
022:        import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicLong;
023:
024:        /**
025:         * This property extractor doesn't actually extract a property from the message, instead it allows for certain functions
026:         * to be called and returns a result. The functions it supports are -
027:         * <ul>
028:         * <li>now - returns an {@link java.sql.Timestamp} with the current time.</li>
029:         * <li>date - returns a {@link java.util.Date} with the current time.</li>
030:         * <li>dateStamp - returns a {@link java.lang.String} that contains the current date formatted according to {@link #DEFAULT_DATE_FORMAT}.</li>
031:         * <li>dateStamp(dd-MM-yyyy) - returns a {@link java.lang.String} that contains the current date formatted according to the format passed into the function.</li>
032:         * <li>uuid - returns a globally unique identifier</li>
033:         * <li>hostname - returns the hostname of the machine Mule is running on</li>
034:         * <li>ip - returns the ip address of the machine Mule is running on</li>
035:         * <li>count - returns a local count that will increment for each call.  If the server is re-started the counter will return to zero</li>
036:         * </ul>
037:         */
038:        public class FunctionExpressionEvaluator implements  ExpressionEvaluator {
039:            public static final String NAME = "function";
040:
041:            public static final String DEFAULT_DATE_FORMAT = "dd-MM-yy_HH-mm-ss.SSS";
042:
043:            /**
044:             * A local counter that will increment for each call.  If the server is re-started the
045:             * counter will return to zero
046:             */
047:            private final AtomicLong count = new AtomicLong(0);
048:
049:            public static final String NOW_FUNCTION = "now";
050:            public static final String DATE_FUNCTION = "date";
051:            public static final String DATESTAMP_FUNCTION = "datestamp";
052:            public static final String SYSTIME_FUNCTION = "systime";
053:            public static final String UUID_FUNCTION = "uuid";
054:            public static final String HOSTNAME_FUNCTION = "hostname";
055:            public static final String IP_FUNCTION = "ip";
056:            public static final String COUNT_FUNCTION = "count";
057:
058:            public Object evaluate(String name, Object message) {
059:                if (name.equalsIgnoreCase(NOW_FUNCTION)) {
060:                    return new Timestamp(System.currentTimeMillis());
061:                } else if (name.equalsIgnoreCase(DATE_FUNCTION)) {
062:                    return new Date(System.currentTimeMillis());
063:                } else if (name.toLowerCase().startsWith(DATESTAMP_FUNCTION)) {
064:                    String temp = name.substring(DATESTAMP_FUNCTION.length());
065:                    if (temp.length() == 0) {
066:                        return DateUtils.getTimeStamp(DEFAULT_DATE_FORMAT);
067:                    } else {
068:                        temp = temp.substring(1);
069:                        return DateUtils.getTimeStamp(temp);
070:                    }
071:                } else if (name.equalsIgnoreCase(UUID_FUNCTION)) {
072:                    return UUID.getUUID();
073:                } else if (name.equalsIgnoreCase(SYSTIME_FUNCTION)) {
074:                    return new Long(System.currentTimeMillis());
075:                } else if (name.equalsIgnoreCase(HOSTNAME_FUNCTION)) {
076:                    try {
077:                        return InetAddress.getLocalHost().getHostName();
078:                    } catch (UnknownHostException e) {
079:                        throw new MuleRuntimeException(CoreMessages
080:                                .failedToProcessExtractorFunction(name), e);
081:                    }
082:                } else if (name.equalsIgnoreCase(IP_FUNCTION)) {
083:                    try {
084:                        return InetAddress.getLocalHost().getHostAddress();
085:                    } catch (UnknownHostException e) {
086:                        throw new MuleRuntimeException(CoreMessages
087:                                .failedToProcessExtractorFunction(name), e);
088:                    }
089:                } else if (name.equalsIgnoreCase(COUNT_FUNCTION)) {
090:                    return new Long(count.getAndIncrement());
091:                } else {
092:                    throw new IllegalArgumentException(name);
093:                }
094:            }
095:
096:            /**
097:             * Gts the name of the object
098:             *
099:             * @return the name of the object
100:             */
101:            public String getName() {
102:                return NAME;
103:            }
104:
105:            /**
106:             * Sets the name of the object
107:             *
108:             * @param name the name of the object
109:             */
110:            public void setName(String name) {
111:                throw new UnsupportedOperationException("setName");
112:            }
113:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.