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.support.umlmessagingcore;
043:
044: import java.util.HashMap;
045: import java.util.Iterator;
046: import java.util.Map;
047: import java.util.Set;
048:
049: import org.netbeans.modules.uml.core.coreapplication.CoreProductManager;
050: import org.netbeans.modules.uml.core.coreapplication.ICoreProduct;
051: import org.netbeans.modules.uml.core.coreapplication.ICoreProductManager;
052: import org.netbeans.modules.uml.core.eventframework.EventDispatchNameKeeper;
053: import org.netbeans.modules.uml.core.eventframework.IEventDispatchController;
054: import org.netbeans.modules.uml.core.eventframework.IEventDispatcher;
055: import org.netbeans.modules.uml.core.eventframework.IEventPayload;
056: import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
057: import org.netbeans.modules.uml.core.support.umlutils.ETList;
058:
059: /**
060: * @author sumitabhk
061: *
062: */
063: public class MessageService implements IMessageService {
064: private IUMLMessagingEventDispatcher m_EventDispatcher = null;
065: // The facilities that have added messages or ones that we know about beforehand (hardcoded)
066: private Map<String, IMessageFacility> m_FacilityMap = new HashMap<String, IMessageFacility>();
067:
068: /**
069: * Fires the message added connection point to let those listening know that a new
070: * message should be responded to.
071: *
072: * @param pMessage The message to be added
073: */
074: public void addMessage(IMessageData pMessage) {
075: ICoreProductManager pProductManager = CoreProductManager
076: .instance();
077: ICoreProduct pCoreProduct = pProductManager.getCoreProduct();
078:
079: // Now get the core event dispatcher so we can dispatch events
080: IEventDispatchController cont = pCoreProduct
081: .getEventDispatchController();
082:
083: IEventDispatcher disp = pCoreProduct
084: .getEventDispatcher(EventDispatchNameKeeper
085: .messagingName());
086:
087: if (disp != null
088: && (disp instanceof IUMLMessagingEventDispatcher)) {
089: m_EventDispatcher = (IUMLMessagingEventDispatcher) disp;
090: }
091:
092: if (m_EventDispatcher != null) {
093: IEventPayload payload = m_EventDispatcher
094: .createPayload("MessageAdded");
095: m_EventDispatcher.fireMessageAdded(pMessage, payload);
096: }
097: }
098:
099: /**
100: * Fires the message added connection point to let those listening know that a new
101: * message should be responded to. This routine constructs a message based on
102: * the arguments and then fires AddMessage.
103: *
104: * @param nMessageType The message type for the message to be added
105: * @param sFacility The facility that generated this message
106: * @param sMessageString The text of the message
107: *
108: * @see MessageService::AddMessage
109: */
110: public void addMessage(int nMessageType, String sFacility,
111: String sMessageString) {
112: IMessageData pMessageData = new MessageData();
113: if (sMessageString != null) {
114: pMessageData.setMessageString(sMessageString);
115: pMessageData.setMessageType(nMessageType);
116: pMessageData.setFacility(sFacility);
117: }
118: addMessage(pMessageData);
119: }
120:
121: /**
122: * Fires the message added connection point to let those listening that a new
123: * message should be responded to. This routine constructs a message based on
124: * the arguments and then fires AddMessage.
125: *
126: * @param nMessageType The message type for the message to be added
127: * @param hInstance The HINSTANCE where the facility string can be found
128: * @param nFacilityStringID The id of the facility string
129: * @param sMessageString The text of the message
130: *
131: * @see MessageService::AddMessage
132: */
133: public void addMessage(int nMessageType, int hInstance,
134: int nFacilityStringID, String sMessageString) {
135: //AZTEC: need to be replaced
136: // Get the facility string
137: //sFacilityString.LoadString((HINSTANCE)hInstance, (UINT)nFacilityStringID);
138: String sFacilityString = "";
139: if (sFacilityString == null || sFacilityString.length() == 0) {
140: sFacilityString = "Unknown";
141: }
142: addMessage(nMessageType, sFacilityString, sMessageString);
143: }
144:
145: /**
146: * MessageService keeps a list of all facilities that it knows about. This is helpful
147: * for the filter object which can then create filters based on user preferences. This
148: * routine verifies that the facility that generated this message is known. If not
149: * then a new facility is added to our list.
150: *
151: * @param pMessage The message that should be verified
152: */
153: protected void addFacility(IMessageData pMessage) {
154: String facility = pMessage.getFacility();
155: if (facility != null) {
156: addFacility(facility);
157: }
158: }
159:
160: /**
161: * MessageService keeps a list of all facilities that it knows about. This is helpful
162: * for the filter object which can then create filters based on user preferences. This
163: * routine verifies that the facility that generated this message is known. If not
164: * then a new facility is added to our list.
165: *
166: * @param sFacility The facility that we should verify is in our list
167: */
168: protected void addFacility(String sFacility) {
169: if (sFacility != null && sFacility.length() > 0) {
170: if (!m_FacilityMap.containsKey(sFacility)) {
171: IMessageFacility msgFacility = new MessageFacility();
172: m_FacilityMap.put(sFacility, msgFacility);
173: }
174: }
175: }
176:
177: /**
178: * CMessenger keeps a list of all facilities that it knows about. This is helpful
179: * for the filter object which can then create filters based on user preferences. This
180: * routine returns a list of all known facilities.
181: *
182: * @param pFacilities A returned list containing all our known facilities
183: */
184: public ETList<IMessageFacility> getMessageFacilities() {
185: ETList<IMessageFacility> facilities = new ETArrayList<IMessageFacility>();
186: Set keys = m_FacilityMap.keySet();
187: Iterator iter = keys.iterator();
188: while (iter.hasNext()) {
189: String key = (String) iter.next();
190: if (m_FacilityMap.get(key) != null) {
191: facilities.add((IMessageFacility) m_FacilityMap
192: .get(key));
193: }
194: }
195: return facilities;
196: }
197:
198: }
|