Source Code Cross Referenced for AbstractBehavior.java in  » Inversion-of-Control » PicoContainer » org » picocontainer » behaviors » 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 » Inversion of Control » PicoContainer » org.picocontainer.behaviors 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*****************************************************************************
002:         * Copyright (C) PicoContainer Organization. All rights reserved.            *
003:         * ------------------------------------------------------------------------- *
004:         * The software in this package is published under the terms of the BSD      *
005:         * style license a copy of which has been included with this distribution in *
006:         * the LICENSE.txt file.                                                     *
007:         *                                                                           *
008:         * Original code by Jon Tirsen                                               *
009:         *****************************************************************************/package org.picocontainer.behaviors;
010:
011:        import java.io.Serializable;
012:
013:        import org.picocontainer.ComponentAdapter;
014:        import org.picocontainer.ComponentMonitor;
015:        import org.picocontainer.Behavior;
016:        import org.picocontainer.PicoContainer;
017:        import org.picocontainer.PicoCompositionException;
018:        import org.picocontainer.PicoVisitor;
019:        import org.picocontainer.ComponentMonitorStrategy;
020:        import org.picocontainer.LifecycleStrategy;
021:
022:        /**
023:         * <p>
024:         * Component adapter which decorates another adapter.
025:         * </p>
026:         * <p>
027:         * This adapter supports a {@link org.picocontainer.ComponentMonitorStrategy component monitor strategy}
028:         * and will propagate change of monitor to the delegate if the delegate itself
029:         * support the monitor strategy.
030:         * </p>
031:         * <p>
032:         * This adapter also supports a {@link Behavior lifecycle manager} and a
033:         * {@link org.picocontainer.LifecycleStrategy lifecycle strategy} if the delegate does.
034:         * </p>
035:         * 
036:         * @author Jon Tirsen
037:         * @author Aslak Hellesoy
038:         * @author Mauro Talevi
039:         */
040:        public abstract class AbstractBehavior<T> implements  Behavior<T>,
041:                ComponentMonitorStrategy, LifecycleStrategy, Serializable {
042:
043:            protected final ComponentAdapter<T> delegate;
044:
045:            public AbstractBehavior(ComponentAdapter<T> delegate) {
046:                this .delegate = delegate;
047:            }
048:
049:            public Object getComponentKey() {
050:                return delegate.getComponentKey();
051:            }
052:
053:            public Class<T> getComponentImplementation() {
054:                return delegate.getComponentImplementation();
055:            }
056:
057:            public T getComponentInstance(PicoContainer container)
058:                    throws PicoCompositionException {
059:                return (T) delegate.getComponentInstance(container);
060:            }
061:
062:            public void verify(PicoContainer container)
063:                    throws PicoCompositionException {
064:                delegate.verify(container);
065:            }
066:
067:            public final ComponentAdapter<T> getDelegate() {
068:                return delegate;
069:            }
070:
071:            @SuppressWarnings("unchecked")
072:            public final <U extends ComponentAdapter> U findAdapterOfType(
073:                    Class<U> componentAdapterType) {
074:                if (componentAdapterType.isAssignableFrom(this .getClass())) {
075:                    return (U) this ;
076:                } else if (componentAdapterType.isAssignableFrom(delegate
077:                        .getClass())) {
078:                    return (U) delegate;
079:                } else {
080:                    return delegate.findAdapterOfType(componentAdapterType);
081:                }
082:            }
083:
084:            public void accept(PicoVisitor visitor) {
085:                visitor.visitComponentAdapter(this );
086:                delegate.accept(visitor);
087:            }
088:
089:            /**
090:             * Delegates change of monitor if the delegate supports 
091:             * a component monitor strategy.
092:             * {@inheritDoc}
093:             */
094:            public void changeMonitor(ComponentMonitor monitor) {
095:                if (delegate instanceof  ComponentMonitorStrategy) {
096:                    ((ComponentMonitorStrategy) delegate)
097:                            .changeMonitor(monitor);
098:                }
099:            }
100:
101:            /**
102:             * Returns delegate's current monitor if the delegate supports 
103:             * a component monitor strategy.
104:             * {@inheritDoc}
105:             * @throws PicoCompositionException if no component monitor is found in delegate
106:             */
107:            public ComponentMonitor currentMonitor() {
108:                if (delegate instanceof  ComponentMonitorStrategy) {
109:                    return ((ComponentMonitorStrategy) delegate)
110:                            .currentMonitor();
111:                }
112:                throw new PicoCompositionException(
113:                        "No component monitor found in delegate");
114:            }
115:
116:            /**
117:             * Invokes delegate start method if the delegate is a Behavior
118:             * {@inheritDoc}
119:             */
120:            public void start(PicoContainer container) {
121:                if (delegate instanceof  Behavior) {
122:                    ((Behavior<?>) delegate).start(container);
123:                }
124:            }
125:
126:            /**
127:             * Invokes delegate stop method if the delegate is a Behavior
128:             * {@inheritDoc}
129:             */
130:            public void stop(PicoContainer container) {
131:                if (delegate instanceof  Behavior) {
132:                    ((Behavior<?>) delegate).stop(container);
133:                }
134:            }
135:
136:            /**
137:             * Invokes delegate dispose method if the delegate is a Behavior
138:             * {@inheritDoc}
139:             */
140:            public void dispose(PicoContainer container) {
141:                if (delegate instanceof  Behavior) {
142:                    ((Behavior<?>) delegate).dispose(container);
143:                }
144:            }
145:
146:            /**
147:             * Invokes delegate hasLifecycle method if the delegate is a Behavior
148:             * {@inheritDoc}
149:             */
150:            public boolean componentHasLifecycle() {
151:                if (delegate instanceof  Behavior) {
152:                    return ((Behavior<?>) delegate).componentHasLifecycle();
153:                }
154:                return false;
155:            }
156:
157:            // ~~~~~~~~ LifecycleStrategy ~~~~~~~~
158:
159:            /**
160:             * Invokes delegate start method if the delegate is a LifecycleStrategy
161:             * {@inheritDoc}
162:             */
163:            public void start(Object component) {
164:                if (delegate instanceof  LifecycleStrategy) {
165:                    ((LifecycleStrategy) delegate).start(component);
166:                }
167:            }
168:
169:            /**
170:             * Invokes delegate stop method if the delegate is a LifecycleStrategy
171:             * {@inheritDoc}
172:             */
173:            public void stop(Object component) {
174:                if (delegate instanceof  LifecycleStrategy) {
175:                    ((LifecycleStrategy) delegate).stop(component);
176:                }
177:            }
178:
179:            /**
180:             * Invokes delegate dispose method if the delegate is a LifecycleStrategy
181:             * {@inheritDoc}
182:             */
183:            public void dispose(Object component) {
184:                if (delegate instanceof  LifecycleStrategy) {
185:                    ((LifecycleStrategy) delegate).dispose(component);
186:                }
187:            }
188:
189:            /**
190:             * Invokes delegate hasLifecycle(Class) method if the delegate is a LifecycleStrategy
191:             * {@inheritDoc}
192:             */
193:            public boolean hasLifecycle(Class<?> type) {
194:                return delegate instanceof  LifecycleStrategy
195:                        && ((LifecycleStrategy) delegate).hasLifecycle(type);
196:            }
197:
198:            public String toString() {
199:                return getDescriptor() + ":" + delegate.toString();
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.