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


001:        /*
002:         * $Id: SimpleCallableJavaComponent.java 11379 2008-03-17 02:46:56Z 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:
011:        package org.mule.component;
012:
013:        import org.mule.DefaultMuleEventContext;
014:        import org.mule.VoidResult;
015:        import org.mule.api.DefaultMuleException;
016:        import org.mule.api.MuleEvent;
017:        import org.mule.api.MuleException;
018:        import org.mule.api.MuleMessage;
019:        import org.mule.api.MuleRuntimeException;
020:        import org.mule.api.component.JavaComponent;
021:        import org.mule.api.component.LifecycleAdapter;
022:        import org.mule.api.lifecycle.Callable;
023:        import org.mule.api.lifecycle.Disposable;
024:        import org.mule.api.lifecycle.Startable;
025:        import org.mule.api.lifecycle.Stoppable;
026:        import org.mule.api.model.ModelException;
027:        import org.mule.api.object.ObjectFactory;
028:        import org.mule.config.i18n.CoreMessages;
029:        import org.mule.object.SingletonObjectFactory;
030:        import org.mule.transformer.TransformerTemplate;
031:
032:        import edu.emory.mathcs.backport.java.util.Collections;
033:
034:        /**
035:         * Simple {@link JavaComponent} implementation to be used when
036:         * {@link LifecycleAdapter} is not required because i) the object instance implements
037:         * {@link Callable} and so entry-point resolution is required and ii) nested-routers
038:         * are not used.<br/> An {@link ObjectFactory} can be set but must return object
039:         * instances that implement {@link Callable}. If one of the constructors that takes
040:         * just a Class or the instance itself is used then the
041:         * {@link SingletonObjectFactory} is used by default. <br/> This implementation
042:         * replaces and improves on <code>OptimizedComponent</code>/<code>OptimizedMuleProxy</code>
043:         */
044:        public class SimpleCallableJavaComponent extends AbstractJavaComponent {
045:
046:            private boolean started = false;
047:            private boolean disposed = false;
048:
049:            public SimpleCallableJavaComponent() {
050:                // for spring
051:            }
052:
053:            /**
054:             * Create an SimpleCallableJavaComponent instance using an object instance that
055:             * implements {@link Callable}
056:             * 
057:             * @param callable
058:             */
059:            public SimpleCallableJavaComponent(Callable callable) {
060:                objectFactory = new SingletonObjectFactory(callable);
061:            }
062:
063:            /**
064:             * Create an SimpleCallableJavaComponent instance using an object class. This
065:             * class should implement {@link Callable}.
066:             * 
067:             * @param callable
068:             * @throws DefaultMuleException if the Class specified does not implement
069:             *             {@link Callable}
070:             */
071:            public SimpleCallableJavaComponent(Class callable)
072:                    throws DefaultMuleException {
073:                if (!(Callable.class.isAssignableFrom(callable))) {
074:                    throw new DefaultMuleException(CoreMessages
075:                            .objectNotOfCorrectType(callable, Callable.class));
076:                }
077:                objectFactory = new SingletonObjectFactory(callable);
078:            }
079:
080:            public SimpleCallableJavaComponent(ObjectFactory objectFactory)
081:                    throws DefaultMuleException {
082:                if (!(Callable.class.isAssignableFrom(objectFactory
083:                        .getObjectClass()))) {
084:                    throw new DefaultMuleException(CoreMessages
085:                            .objectNotOfCorrectType(objectFactory
086:                                    .getObjectClass(), Callable.class));
087:                }
088:                this .objectFactory = objectFactory;
089:            }
090:
091:            protected void doStart() throws MuleException {
092:                super .doStart();
093:                if (Startable.class.isAssignableFrom(objectFactory
094:                        .getObjectClass())) {
095:                    try {
096:                        ((Startable) objectFactory.getInstance()).start();
097:                    } catch (Exception e) {
098:                        throw new ModelException(CoreMessages
099:                                .failedToStart("Service '" + service.getName()
100:                                        + "'"), e);
101:                    }
102:                }
103:            }
104:
105:            protected void doStop() throws MuleException {
106:                super .doStop();
107:                if (started
108:                        && Stoppable.class.isAssignableFrom(objectFactory
109:                                .getObjectClass())) {
110:                    try {
111:                        ((Stoppable) objectFactory.getInstance()).stop();
112:                    } catch (Exception e) {
113:                        throw new ModelException(CoreMessages
114:                                .failedToStop("Service '" + service.getName()
115:                                        + "'"), e);
116:                    }
117:                }
118:            }
119:
120:            protected void doDispose() {
121:                super .doDispose();
122:                if (Disposable.class.isAssignableFrom(objectFactory
123:                        .getObjectClass())) {
124:                    try {
125:                        ((Disposable) objectFactory.getInstance()).dispose();
126:                    } catch (Exception e) {
127:                        logger.error("Unable to dispose component instance", e);
128:                    }
129:                }
130:            }
131:
132:            public Class getObjectType() {
133:                if (objectFactory != null) {
134:                    return objectFactory.getObjectClass();
135:                } else {
136:                    return Callable.class;
137:                }
138:            }
139:
140:            protected LifecycleAdapter borrowComponentLifecycleAdaptor()
141:                    throws Exception {
142:                // no-op
143:                return null;
144:            }
145:
146:            protected void returnComponentLifecycleAdaptor(
147:                    LifecycleAdapter lifecycleAdapter) {
148:                // no-op
149:            }
150:
151:            protected MuleMessage invokeComponentInstance(MuleEvent event)
152:                    throws Exception {
153:                Object result = ((Callable) objectFactory.getInstance())
154:                        .onCall(new DefaultMuleEventContext(event));
155:                if (result instanceof  VoidResult) {
156:                    // This will rewire the current message
157:                    event.transformMessage();
158:                    return event.getMessage();
159:                } else if (result != null) {
160:                    if (result instanceof  MuleMessage) {
161:                        return (MuleMessage) result;
162:                    } else {
163:                        event
164:                                .getMessage()
165:                                .applyTransformers(
166:                                        Collections
167:                                                .singletonList(new TransformerTemplate(
168:                                                        new TransformerTemplate.OverwitePayloadCallback(
169:                                                                result))));
170:                        return event.getMessage();
171:                    }
172:                } else {
173:                    return null;
174:                }
175:            }
176:
177:            // @Override
178:            public void setObjectFactory(ObjectFactory objectFactory) {
179:                if (!(Callable.class.isAssignableFrom(objectFactory
180:                        .getObjectClass()))) {
181:                    throw new MuleRuntimeException(CoreMessages
182:                            .objectNotOfCorrectType(objectFactory
183:                                    .getObjectClass(), Callable.class));
184:                }
185:                super.setObjectFactory(objectFactory);
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.