001: /**
002: * $RCSfile$
003: * $Revision: $
004: * $Date: $
005: *
006: * Copyright (C) 2007 Jive Software. All rights reserved.
007: *
008: * This software is published under the terms of the GNU Public License (GPL),
009: * a copy of which is included in this distribution.
010: */package org.jivesoftware.openfire.sip;
011:
012: import org.jivesoftware.openfire.container.Plugin;
013: import org.jivesoftware.openfire.container.PluginManager;
014: import org.jivesoftware.openfire.sip.log.LogComponent;
015: import org.jivesoftware.openfire.sip.log.LogListenerImpl;
016: import org.jivesoftware.openfire.sip.sipaccount.SipComponent;
017: import org.jivesoftware.util.JiveGlobals;
018: import org.jivesoftware.util.PropertyEventDispatcher;
019: import org.jivesoftware.util.PropertyEventListener;
020: import org.xmpp.component.ComponentManager;
021: import org.xmpp.component.ComponentManagerFactory;
022:
023: import java.util.Map;
024: import java.io.File;
025:
026: /**
027: * Remote management for users SIP account for Spark SIP Plugin
028: *
029: * @author Thiago Rocha Camargo
030: */
031: public class SipManager implements Plugin, PropertyEventListener {
032:
033: private String serviceName;
034:
035: private ComponentManager componentManager;
036:
037: private SipComponent sipComponent;
038:
039: private LogComponent logComponent;
040:
041: /**
042: * Constructs a new SIP Controller plugin.
043: */
044: public SipManager() {
045: serviceName = JiveGlobals.getProperty(SipComponent.PROPNAME,
046: SipComponent.NAME);
047: }
048:
049: public void initializePlugin(PluginManager manager,
050: File pluginDirectory) {
051: // Register as a component.
052: componentManager = ComponentManagerFactory
053: .getComponentManager();
054:
055: sipComponent = new SipComponent();
056: LogListenerImpl logListener = new LogListenerImpl(
057: componentManager);
058: logComponent = new LogComponent(logListener);
059:
060: // Register the logger and SIP components. Both components are cluster-safe
061: try {
062: componentManager.addComponent(serviceName, sipComponent);
063:
064: } catch (Exception e) {
065: componentManager.getLog().error(e);
066: }
067: try {
068: componentManager.addComponent(LogComponent.NAME,
069: logComponent);
070:
071: } catch (Exception e) {
072: componentManager.getLog().error(e);
073: }
074:
075: PropertyEventDispatcher.addListener(this );
076: componentManager.getLog().debug("SIPARK STARTED");
077: }
078:
079: public void destroyPlugin() {
080: PropertyEventDispatcher.removeListener(this );
081: // Unregister component.
082: if (componentManager != null) {
083: try {
084: componentManager.removeComponent(serviceName);
085: } catch (Exception e) {
086: componentManager.getLog().error(e);
087: }
088: try {
089: componentManager.removeComponent(LogComponent.NAME);
090: } catch (Exception e) {
091: componentManager.getLog().error(e);
092: }
093: }
094: sipComponent = null;
095: logComponent = null;
096: componentManager = null;
097: }
098:
099: /**
100: * Returns the service name of this component, which is "sipark" by default.
101: *
102: * @return the service name of this component.
103: */
104: public String getServiceName() {
105: return serviceName;
106: }
107:
108: /**
109: * Sets the service name of this component, which is "sipark" by default.
110: *
111: * @param serviceName the service name of this component.
112: */
113: public void setServiceName(String serviceName) {
114: JiveGlobals.setProperty(SipComponent.PROPNAME, serviceName);
115: }
116:
117: /**
118: * Changes the service name to a new value.
119: *
120: * @param serviceName the service name.
121: */
122: private void changeServiceName(String serviceName) {
123: if (serviceName == null) {
124: throw new NullPointerException(
125: "Service name cannot be null");
126: }
127: if (this .serviceName.equals(serviceName)) {
128: return;
129: }
130:
131: // Re-register the service.
132: try {
133: componentManager.removeComponent(this .serviceName);
134: } catch (Exception e) {
135: componentManager.getLog().error(e);
136: }
137: try {
138: componentManager.addComponent(serviceName, sipComponent);
139: } catch (Exception e) {
140: componentManager.getLog().error(e);
141: }
142: this .serviceName = serviceName;
143: }
144:
145: public void propertySet(String property, Map params) {
146: if (property.equals(SipComponent.NAMESPACE)) {
147: changeServiceName((String) params.get("value"));
148: }
149: }
150:
151: public void propertyDeleted(String property, Map params) {
152: if (property.equals(serviceName)) {
153: changeServiceName(SipComponent.NAME);
154: }
155: }
156:
157: public void xmlPropertySet(String property, Map params) {
158: // not used
159: }
160:
161: public void xmlPropertyDeleted(String property, Map params) {
162: // not used
163: }
164:
165: public ComponentManager getComponentManager() {
166: return componentManager;
167: }
168:
169: }
|