001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.core.eventframework;
043:
044: import org.netbeans.modules.uml.core.coreapplication.ICoreProduct;
045: import org.netbeans.modules.uml.core.support.umlsupport.ProductRetriever;
046:
047: /**
048: * @author sumitabhk
049: *
050: */
051: public class EventDispatchRetriever {
052:
053: private static EventDispatchRetriever m_Instance = null;
054: private IEventDispatchController m_Controller = null;
055:
056: public static EventDispatchRetriever instance() {
057: if (m_Instance == null) {
058: m_Instance = new EventDispatchRetriever();
059: }
060: return m_Instance;
061: }
062:
063: private EventDispatchRetriever() {
064: super ();
065: }
066:
067: /**
068: * Simple constructor that can handle the setting of the internal
069: * product used for dispatch retrieval.
070: *
071: * @param prod[in] The product to use for dispatch retrieval. Can
072: * be 0. If 0 and GetDispatcher() is called, the
073: * current product on the ROT for the current process
074: * will be used.
075: */
076:
077: public EventDispatchRetriever(ICoreProduct prod) {
078: setController(prod);
079: }
080:
081: /**
082: *
083: * Establishes the dispatch controller on this object
084: *
085: * @param controller[in] The controller to use when retrieving
086: * dispatchers.
087: *
088: */
089:
090: public EventDispatchRetriever(IEventDispatchController controller) {
091: m_Controller = controller;
092: }
093:
094: /**
095: * Retrieves the dispatcher indicated by dispName
096: *
097: * @param dispName[in] The name of the dispatcher to retrieve
098: * @param type[out] The actual dispatcher, else 0 if not found
099: *
100: * @result HRESULT
101: */
102:
103: public <T extends IEventDispatcher> T getDispatcher(String dispName) {
104: IEventDispatcher retObj = null;
105: // If our internal product is not set, pull the product
106: // off the ROT
107: if (m_Controller == null) {
108: ICoreProduct prod = ProductRetriever.retrieveProduct();
109: if (prod != null) {
110: m_Controller = prod.getEventDispatchController();
111: }
112: }
113: if (m_Controller != null) {
114: retObj = m_Controller.retrieveDispatcher(dispName);
115: }
116: return (T) retObj;
117: }
118:
119: /**
120: *
121: * Sets a product on this retriever. The retriever will now use
122: * that product when retrieving dispatchers.
123: *
124: * @param prod[in] The product to retrieve dispatchers from.
125: *
126: * @return HRESULT
127: *
128: */
129: public void setController(IEventDispatchController cont) {
130: m_Controller = cont;
131: }
132:
133: public void setController(ICoreProduct prod) {
134: if (prod != null) {
135: m_Controller = prod.getEventDispatchController();
136: }
137: }
138:
139: /**
140: *
141: * Retrieves controller that this retriever is pulling dispatchers from.
142: *
143: * @param cont[out] The controller.
144: *
145: * @return HRESULT
146: *
147: */
148:
149: public IEventDispatchController getController() {
150: return m_Controller;
151: }
152:
153: // hack to know if RequestProcessor has established its processors
154: private static boolean firstRequest = false;
155:
156: public static boolean isFirstRequest() {
157: if (firstRequest) {
158: firstRequest = false;
159: }
160: return firstRequest;
161: }
162: }
|