Source Code Cross Referenced for LegacyHandlerProxy.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » handlers » 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 » IDE Eclipse » ui workbench » org.eclipse.ui.internal.handlers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.handlers;
011:
012:        import java.util.Collections;
013:        import java.util.Map;
014:
015:        import org.eclipse.core.runtime.CoreException;
016:        import org.eclipse.core.runtime.IConfigurationElement;
017:        import org.eclipse.core.runtime.IStatus;
018:        import org.eclipse.core.runtime.Status;
019:        import org.eclipse.ui.commands.AbstractHandler;
020:        import org.eclipse.ui.commands.ExecutionException;
021:        import org.eclipse.ui.commands.IHandler;
022:        import org.eclipse.ui.internal.WorkbenchPlugin;
023:
024:        /**
025:         * <p>
026:         * A proxy for a handler that has been defined in XML. This delays the class
027:         * loading until the handler is really asked for information (besides the
028:         * priority or the command identifier). Asking a proxy for anything but the
029:         * attributes defined publicly in this class will cause the proxy to instantiate
030:         * the proxied handler.
031:         * </p>
032:         * 
033:         * @since 3.0
034:         */
035:        public final class LegacyHandlerProxy extends AbstractHandler {
036:
037:            /**
038:             * The name of the configuration element attribute which contains the
039:             * information necessary to instantiate the real handler.
040:             */
041:            private static final String HANDLER_ATTRIBUTE_NAME = "handler"; //$NON-NLS-1$
042:
043:            /**
044:             * The configuration element from which the handler can be created. This
045:             * value will exist until the element is converted into a real class -- at
046:             * which point this value will be set to <code>null</code>.
047:             */
048:            private IConfigurationElement configurationElement;
049:
050:            /**
051:             * The real handler. This value is <code>null</code> until the proxy is
052:             * forced to load the real handler. At this point, the configuration element
053:             * is converted, nulled out, and this handler gains a reference.
054:             */
055:            private IHandler handler;
056:
057:            /**
058:             * Constructs a new instance of <code>HandlerProxy</code> with all the
059:             * information it needs to try to avoid loading until it is needed.
060:             * 
061:             * @param newConfigurationElement
062:             *            The configuration element from which the real class can be
063:             *            loaded at run-time.
064:             */
065:            public LegacyHandlerProxy(
066:                    final IConfigurationElement newConfigurationElement) {
067:                configurationElement = newConfigurationElement;
068:                handler = null;
069:            }
070:
071:            /**
072:             * Passes the dipose on to the proxied handler, if it has been loaded.
073:             */
074:            public void dispose() {
075:                if (handler != null) {
076:                    handler.dispose();
077:                }
078:            }
079:
080:            /**
081:             * @see IHandler#execute(Map)
082:             */
083:            public Object execute(Map parameters) throws ExecutionException {
084:                if (loadHandler()) {
085:                    return handler.execute(parameters);
086:                }
087:
088:                return null;
089:            }
090:
091:            /**
092:             * @see IHandler#getAttributeValuesByName()
093:             */
094:            public Map getAttributeValuesByName() {
095:                if (loadHandler()) {
096:                    return handler.getAttributeValuesByName();
097:                } else {
098:                    return Collections.EMPTY_MAP;
099:                }
100:            }
101:
102:            /**
103:             * Loads the handler, if possible. If the handler is loaded, then the member
104:             * variables are updated accordingly.
105:             * 
106:             * @return <code>true</code> if the handler is now non-null;
107:             *         <code>false</code> otherwise.
108:             */
109:            private final boolean loadHandler() {
110:                if (handler == null) {
111:                    // Load the handler.
112:                    try {
113:                        handler = (IHandler) configurationElement
114:                                .createExecutableExtension(HANDLER_ATTRIBUTE_NAME);
115:                        configurationElement = null;
116:                        return true;
117:                    } catch (final CoreException e) {
118:                        /*
119:                         * TODO If it can't be instantiated, should future attempts to
120:                         * instantiate be blocked?
121:                         */
122:                        final String message = "The proxied handler for '" + configurationElement.getAttribute(HANDLER_ATTRIBUTE_NAME) //$NON-NLS-1$
123:                                + "' could not be loaded"; //$NON-NLS-1$
124:                        IStatus status = new Status(IStatus.ERROR,
125:                                WorkbenchPlugin.PI_WORKBENCH, 0, message, e);
126:                        WorkbenchPlugin.log(message, status);
127:                        return false;
128:                    }
129:                }
130:
131:                return true;
132:            }
133:
134:            public final String toString() {
135:                final StringBuffer buffer = new StringBuffer();
136:
137:                buffer.append("LegacyProxy("); //$NON-NLS-1$
138:                if (handler == null) {
139:                    final String className = configurationElement
140:                            .getAttribute(HANDLER_ATTRIBUTE_NAME);
141:                    buffer.append(className);
142:                } else {
143:                    buffer.append(handler);
144:                }
145:                buffer.append(')');
146:
147:                return buffer.toString();
148:            }
149:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.