additional extension points and hooks for better custom object support
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 17 Jan 2013 13:18:44 +0000 (13:18 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 17 Jan 2013 13:18:44 +0000 (13:18 +0000)
.gitattributes
doc/internal/nxcp_command_ranges.txt
src/java/netxms-client/src/main/java/org/netxms/client/NXCSession.java
src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/CreateCluster.java
src/java/netxms-eclipse/core/plugin.xml
src/java/netxms-eclipse/core/schema/org.netxms.ui.eclipse.sessionproviders.exsd [new file with mode: 0644]
src/java/netxms-eclipse/core/src/org/netxms/ui/eclipse/console/LoginJob.java
src/java/netxms-eclipse/core/src/org/netxms/ui/eclipse/console/api/SessionProvider.java [new file with mode: 0644]
src/server/core/container.cpp
src/server/core/template.cpp

index b938f6d..9fa0fcc 100644 (file)
@@ -2034,6 +2034,7 @@ src/java/netxms-eclipse/core/plugin.xml -text
 src/java/netxms-eclipse/core/plugin_customization.ini -text
 src/java/netxms-eclipse/core/schema/org.netxms.ui.eclipse.branding.exsd -text
 src/java/netxms-eclipse/core/schema/org.netxms.ui.eclipse.loginlisteners.exsd -text
+src/java/netxms-eclipse/core/schema/org.netxms.ui.eclipse.sessionproviders.exsd -text
 src/java/netxms-eclipse/core/schema/org.netxms.ui.eclipse.tweaklets.exsd -text
 src/java/netxms-eclipse/core/src/org/netxms/ui/eclipse/console/Activator.java -text
 src/java/netxms-eclipse/core/src/org/netxms/ui/eclipse/console/BrandingManager.java -text
index f55a5e8..37f69be 100644 (file)
@@ -1,2 +1,3 @@
 0000 .. 0FFF   Core system commands
 1000 .. 100F   NXVS
+5000 .. 5FFF    TTC Marconi
index 4cf3e8e..7378908 100644 (file)
@@ -272,12 +272,26 @@ public class NXCSession implements Session, ScriptLibraryManager, UserManager, S
                byte[] bytes = addr.getAddress();\r
                return ((long)bytes[0] << 24) | ((long)bytes[1] << 16) | ((long)bytes[2] << 8) | (long)bytes[3];\r
        }\r
+       \r
+       /**\r
+        * Create custom object from NXCP message. May be overridden by derived classes to create custom\r
+        * NetXMS objects. Default implementation will always create GenericObject class. Implementation\r
+        * in derived class must either always return object or call base implementation for unknown \r
+        * NetXMS object classes.\r
+        * \r
+        * @param objectClass NetXMS object class ID\r
+        * @param msg Source NXCP message\r
+        * @return NetXMS object\r
+        */\r
+       protected GenericObject createCustomObjectFromMessage(int objectClass, NXCPMessage msg)\r
+       {\r
+               return new GenericObject(msg, this);\r
+       }\r
 \r
        /**\r
         * Create object from message\r
         * \r
-        * @param msg\r
-        *           Source NXCP message\r
+        * @param msg Source NXCP message\r
         * @return NetXMS object\r
         */\r
        private GenericObject createObjectFromMessage(NXCPMessage msg)\r
@@ -378,7 +392,7 @@ public class NXCSession implements Session, ScriptLibraryManager, UserManager, S
                                object = new ServiceCheck(msg, this);\r
                                break;\r
                        default:\r
-                               object = new GenericObject(msg, this);\r
+                               object = createCustomObjectFromMessage(objectClass, msg);\r
                                break;\r
                }\r
 \r
@@ -3067,19 +3081,29 @@ public class NXCSession implements Session, ScriptLibraryManager, UserManager, S
                final NXCPMessage response = waitForRCC(msg.getMessageId());\r
                return new Table(response);\r
        }\r
-\r
+       \r
+       /**\r
+        * Hook method to allow adding of custom object creation data to NXCP message.\r
+        * Default implementation does nothing.\r
+        *  \r
+        * @param data object creation data passed to createObject\r
+        * @param userData user-defined data for object creation passed to createObject\r
+        * @param msg NXCP message that will be sent to server\r
+        */\r
+       protected void createCustomObject(NXCObjectCreationData data, Object userData, NXCPMessage msg)\r
+       {\r
+       }\r
+       \r
        /**\r
-        * Create object\r
+        * Create new NetXMS object.\r
         * \r
-        * @param data\r
-        *           Object creation data\r
+        * @param data Object creation data\r
+        * @param userData User-defined data for custom object creation\r
         * @return ID of new object\r
-        * @throws IOException\r
-        *            if socket I/O error occurs\r
-        * @throws NXCException\r
-        *            if NetXMS server returns an error or operation was timed out\r
+        * @throws IOException if socket I/O error occurs\r
+        * @throws NXCException if NetXMS server returns an error or operation was timed out\r
         */\r
-       public long createObject(final NXCObjectCreationData data) throws IOException, NXCException\r
+       public long createObject(final NXCObjectCreationData data, final Object userData) throws IOException, NXCException\r
        {\r
                final NXCPMessage msg = newMessage(NXCPCodes.CMD_CREATE_OBJECT);\r
 \r
@@ -3137,6 +3161,9 @@ public class NXCSession implements Session, ScriptLibraryManager, UserManager, S
                                msg.setVariable(NXCPCodes.VID_DEVICE_ID, data.getDeviceId());\r
                                break;\r
                }\r
+               \r
+               if (userData != null)\r
+                       createCustomObject(data, userData, msg);\r
 \r
                sendMessage(msg);\r
                final NXCPMessage response = waitForRCC(msg.getMessageId());\r
@@ -3144,6 +3171,19 @@ public class NXCSession implements Session, ScriptLibraryManager, UserManager, S
        }\r
 \r
        /**\r
+        * Create new NetXMS object. Equivalent of calling createObject(data, null).\r
+        * \r
+        * @param data Object creation data\r
+        * @return ID of new object\r
+        * @throws IOException if socket I/O error occurs\r
+        * @throws NXCException if NetXMS server returns an error or operation was timed out\r
+        */\r
+       public long createObject(final NXCObjectCreationData data) throws IOException, NXCException\r
+       {\r
+               return createObject(data, null);\r
+       }\r
+\r
+       /**\r
         * Delete object\r
         * \r
         * @param objectId\r
@@ -3170,17 +3210,27 @@ public class NXCSession implements Session, ScriptLibraryManager, UserManager, S
        }\r
 \r
        /**\r
+        * Hook method to populate NXCP message with custom object's data on object modification.\r
+        * Default implementation does nothing.\r
+        * \r
+        * @param data object modification data passed to modifyObject\r
+        * @param userData user-defined data passed to modifyObject\r
+        * @param msg NXCP message to be sent to server\r
+        */\r
+       protected void modifyCustomObject(NXCObjectModificationData data, Object userData, NXCPMessage msg)\r
+       {\r
+       }\r
+       \r
+       /**\r
         * Modify object (generic interface, in most cases wrapper functions should\r
-        * be used instead)\r
+        * be used instead).\r
         * \r
-        * @param data\r
-        *           Object modification data\r
-        * @throws IOException\r
-        *            if socket I/O error occurs\r
-        * @throws NXCException\r
-        *            if NetXMS server returns an error or operation was timed out\r
+        * @param data Object modification data\r
+        * @param userData user-defined data for custom object modification\r
+        * @throws IOException if socket I/O error occurs\r
+        * @throws NXCException if NetXMS server returns an error or operation was timed out\r
         */\r
-       public void modifyObject(final NXCObjectModificationData data) throws IOException, NXCException\r
+       public void modifyObject(final NXCObjectModificationData data, final Object userData) throws IOException, NXCException\r
        {\r
                NXCPMessage msg = newMessage(NXCPCodes.CMD_MODIFY_OBJECT);\r
                msg.setVariableInt32(NXCPCodes.VID_OBJECT_ID, (int)data.getObjectId());\r
@@ -3536,11 +3586,27 @@ public class NXCSession implements Session, ScriptLibraryManager, UserManager, S
                        msg.setVariableInt32(NXCPCodes.VID_DISCOVERY_RADIUS, data.getDiscoveryRadius());\r
                }\r
 \r
+               if (userData != null)\r
+                       modifyCustomObject(data, userData, msg);\r
+               \r
                sendMessage(msg);\r
                waitForRCC(msg.getMessageId());\r
        }\r
 \r
        /**\r
+        * Modify object (generic interface, in most cases wrapper functions should\r
+        * be used instead). Equivalent of calling modifyObject(data, null).\r
+        * \r
+        * @param data Object modification data\r
+        * @throws IOException if socket I/O error occurs\r
+        * @throws NXCException if NetXMS server returns an error or operation was timed out\r
+        */\r
+       public void modifyObject(final NXCObjectModificationData data) throws IOException, NXCException\r
+       {\r
+               modifyObject(data, null);\r
+       }\r
+       \r
+       /**\r
         * Change object's name (wrapper for modifyObject())\r
         * \r
         * @param objectId\r
index 59fa354..4e8080e 100644 (file)
@@ -28,7 +28,6 @@ import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.IWorkbenchWindow;\r
 import org.netxms.client.NXCObjectCreationData;\r
 import org.netxms.client.NXCSession;\r
-import org.netxms.client.objects.Cluster;\r
 import org.netxms.client.objects.Container;\r
 import org.netxms.client.objects.GenericObject;\r
 import org.netxms.client.objects.ServiceRoot;\r
index c2971c9..bda5a50 100644 (file)
@@ -4,6 +4,7 @@
    <extension-point id="org.netxms.ui.eclipse.tweaklets" name="NXMC Tweaklets" schema="schema/org.netxms.ui.eclipse.tweaklets.exsd"/>\r
    <extension-point id="org.netxms.ui.eclipse.loginlisteners" name="NXMC Login Listeners" schema="schema/org.netxms.ui.eclipse.loginlisteners.exsd"/>\r
    <extension-point id="org.netxms.ui.eclipse.branding" name="NetXMS Console Branding" schema="schema/org.netxms.ui.eclipse.branding.exsd"/>\r
+   <extension-point id="org.netxms.ui.eclipse.sessionproviders" name="Session Providers" schema="schema/org.netxms.ui.eclipse.sessionproviders.exsd"/>\r
    <extension\r
          id="org.netxms.ui.eclipse.console.application"\r
          point="org.eclipse.core.runtime.applications">\r
diff --git a/src/java/netxms-eclipse/core/schema/org.netxms.ui.eclipse.sessionproviders.exsd b/src/java/netxms-eclipse/core/schema/org.netxms.ui.eclipse.sessionproviders.exsd
new file mode 100644 (file)
index 0000000..5b37feb
--- /dev/null
@@ -0,0 +1,117 @@
+<?xml version='1.0' encoding='UTF-8'?>\r
+<!-- Schema file written by PDE -->\r
+<schema targetNamespace="org.netxms.ui.eclipse.console" xmlns="http://www.w3.org/2001/XMLSchema">\r
+<annotation>\r
+      <appInfo>\r
+         <meta.schema plugin="org.netxms.ui.eclipse.console" id="org.netxms.ui.eclipse.sessionproviders" name="Session Providers"/>\r
+      </appInfo>\r
+      <documentation>\r
+         Communication session providers.\r
+      </documentation>\r
+   </annotation>\r
+\r
+   <element name="extension">\r
+      <annotation>\r
+         <appInfo>\r
+            <meta.element />\r
+         </appInfo>\r
+      </annotation>\r
+      <complexType>\r
+         <sequence>\r
+            <element ref="provider" minOccurs="1" maxOccurs="unbounded"/>\r
+         </sequence>\r
+         <attribute name="point" type="string" use="required">\r
+            <annotation>\r
+               <documentation>\r
+                  \r
+               </documentation>\r
+            </annotation>\r
+         </attribute>\r
+         <attribute name="id" type="string">\r
+            <annotation>\r
+               <documentation>\r
+                  \r
+               </documentation>\r
+            </annotation>\r
+         </attribute>\r
+         <attribute name="name" type="string">\r
+            <annotation>\r
+               <documentation>\r
+                  \r
+               </documentation>\r
+               <appInfo>\r
+                  <meta.attribute translatable="true"/>\r
+               </appInfo>\r
+            </annotation>\r
+         </attribute>\r
+      </complexType>\r
+   </element>\r
+\r
+   <element name="provider">\r
+      <complexType>\r
+         <attribute name="class" type="string" use="required">\r
+            <annotation>\r
+               <documentation>\r
+                  Implementing class for session provider\r
+               </documentation>\r
+               <appInfo>\r
+                  <meta.attribute kind="java" basedOn=":org.netxms.ui.eclipse.console.api.SessionProvider"/>\r
+               </appInfo>\r
+            </annotation>\r
+         </attribute>\r
+         <attribute name="priority" type="string">\r
+            <annotation>\r
+               <documentation>\r
+                  Priority for this provider. 0 is highest, 65535 is lowest. Provider with highest priority will be choosen for session creation. Default is 65535.\r
+               </documentation>\r
+            </annotation>\r
+         </attribute>\r
+      </complexType>\r
+   </element>\r
+\r
+   <annotation>\r
+      <appInfo>\r
+         <meta.section type="since"/>\r
+      </appInfo>\r
+      <documentation>\r
+         1.2.6\r
+      </documentation>\r
+   </annotation>\r
+\r
+   <annotation>\r
+      <appInfo>\r
+         <meta.section type="examples"/>\r
+      </appInfo>\r
+      <documentation>\r
+         [Enter extension point usage example here.]\r
+      </documentation>\r
+   </annotation>\r
+\r
+   <annotation>\r
+      <appInfo>\r
+         <meta.section type="apiinfo"/>\r
+      </appInfo>\r
+      <documentation>\r
+         [Enter API information here.]\r
+      </documentation>\r
+   </annotation>\r
+\r
+   <annotation>\r
+      <appInfo>\r
+         <meta.section type="implementation"/>\r
+      </appInfo>\r
+      <documentation>\r
+         [Enter information about supplied implementation of this extension point.]\r
+      </documentation>\r
+   </annotation>\r
+\r
+   <annotation>\r
+      <appInfo>\r
+         <meta.section type="copyright"/>\r
+      </appInfo>\r
+      <documentation>\r
+         Copyright (c) 2003-2013 Raden Solutions\r
+      </documentation>\r
+   </annotation>\r
+\r
+</schema>\r
index 15471b3..dc1d776 100644 (file)
@@ -30,6 +30,7 @@ import org.netxms.api.client.Session;
 import org.netxms.base.NXCommon;\r
 import org.netxms.client.NXCSession;\r
 import org.netxms.ui.eclipse.console.api.ConsoleLoginListener;\r
+import org.netxms.ui.eclipse.console.api.SessionProvider;\r
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;\r
 \r
 /**\r
@@ -105,7 +106,7 @@ public class LoginJob implements IRunnableWithProgress
                                hostName = server;\r
                        }\r
 \r
-                       NXCSession session = new NXCSession(hostName, port, loginName, password, encryptSession);\r
+                       NXCSession session = createSession(hostName, port);\r
                        session.setConnClientInfo("nxmc/" + NXCommon.VERSION); //$NON-NLS-1$\r
                        monitor.worked(10);\r
 \r
@@ -151,6 +152,59 @@ public class LoginJob implements IRunnableWithProgress
        }\r
        \r
        /**\r
+        * Create new session object.\r
+        * \r
+        * @param hostName\r
+        * @param port\r
+        * @return\r
+        */\r
+       private NXCSession createSession(String hostName, int port)\r
+       {\r
+               // Read all registered extensions and create provider with minimal priority\r
+               IConfigurationElement currentElement = null;\r
+               int currentPriotity = 65536;\r
+               \r
+               final IExtensionRegistry reg = Platform.getExtensionRegistry();\r
+               IConfigurationElement[] elements = reg.getConfigurationElementsFor("org.netxms.ui.eclipse.sessionproviders"); //$NON-NLS-1$\r
+               for(int i = 0; i < elements.length; i++)\r
+               {\r
+                       int priority = 65535;\r
+                       String value = elements[i].getAttribute("priority"); //$NON-NLS-1$\r
+                       if (value != null)\r
+                       {\r
+                               try\r
+                               {\r
+                                       priority = Integer.parseInt(value);\r
+                                       if ((priority < 0) || (priority > 65535))\r
+                                               priority = 65535;\r
+                               }\r
+                               catch(NumberFormatException e)\r
+                               {\r
+                               }\r
+                       }\r
+                       if (priority < currentPriotity)\r
+                       {\r
+                               currentElement = elements[i];\r
+                               currentPriotity = priority;\r
+                       }\r
+               }\r
+               \r
+               if (currentElement != null)\r
+               {\r
+                       try\r
+                       {\r
+                               SessionProvider p = (SessionProvider)currentElement.createExecutableExtension("class");\r
+                               return p.createSession(hostName, port, loginName, password, encryptSession);\r
+                       }\r
+                       catch(CoreException e)\r
+                       {\r
+                       }\r
+               }\r
+               \r
+               return new NXCSession(hostName, port, loginName, password, encryptSession);\r
+       }\r
+       \r
+       /**\r
         * Inform all registered login listeners about successful login\r
         * \r
         * @param session new client session\r
diff --git a/src/java/netxms-eclipse/core/src/org/netxms/ui/eclipse/console/api/SessionProvider.java b/src/java/netxms-eclipse/core/src/org/netxms/ui/eclipse/console/api/SessionProvider.java
new file mode 100644 (file)
index 0000000..f58ad3c
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2013 Victor Kirhenshtein
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.netxms.ui.eclipse.console.api;
+
+import org.netxms.client.NXCSession;
+
+/**
+ * Session provider interface
+ */
+public interface SessionProvider
+{
+       /**
+        * Create communication session object.
+        * 
+        * @param connAddress
+        * @param connPort
+        * @param connLoginName
+        * @param connPassword
+        * @param connUseEncryption
+        * @return
+        */
+       public NXCSession createSession(String connAddress, int connPort, String connLoginName, String connPassword, boolean connUseEncryption);
+}
index a82dd38..23c06fd 100644 (file)
@@ -83,11 +83,11 @@ Container::~Container()
        delete m_bindFilter;
 }
 
-
-//
-// Create object from database data
-//
-
+/**
+ * Create container object from database data.
+ *
+ * @param dwId object ID
+ */
 BOOL Container::CreateFromDB(DWORD dwId)
 {
    TCHAR szQuery[256];
@@ -152,11 +152,11 @@ BOOL Container::CreateFromDB(DWORD dwId)
    return TRUE;
 }
 
-
-//
-// Save object to database
-//
-
+/**
+ * Save object to database
+ *
+ * @param hdb database connection handle
+ */
 BOOL Container::SaveToDB(DB_HANDLE hdb)
 {
    // Lock object's access
index b590718..2ce7d83 100644 (file)
@@ -62,11 +62,9 @@ Template::Template(const TCHAR *pszName) : NetObj()
        m_mutexDciAccess = MutexCreateRecursive();
 }
 
-
-//
-// Create template object from import file
-//
-
+/**
+ * Create template object from import file
+ */
 Template::Template(ConfigEntry *config) : NetObj()
 {
    m_bIsHidden = TRUE;
@@ -99,11 +97,9 @@ Template::Template(ConfigEntry *config) : NetObj()
        }
 }
 
-
-//
-// Destructor
-//
-
+/**
+ * Destructor
+ */
 Template::~Template()
 {
        delete m_dcObjects;
@@ -112,21 +108,19 @@ Template::~Template()
        MutexDestroy(m_mutexDciAccess);
 }
 
-
-//
-// Destroy all related data collection items
-//
-
+/**
+ * Destroy all related data collection items.
+ */
 void Template::destroyItems()
 {
        m_dcObjects->clear();
 }
 
-
-//
-// Set auto apply filter
-//
-
+/**
+ * Set auto apply filter.
+ *
+ * @param filter new filter script code or NULL to clear filter
+ */
 void Template::setAutoApplyFilter(const TCHAR *filter)
 {
        LockData();
@@ -150,11 +144,11 @@ void Template::setAutoApplyFilter(const TCHAR *filter)
        UnlockData();
 }
 
-
-//
-// Create object from database data
-//
-
+/**
+ * Create template object from database data
+ *
+ * @param dwId object ID
+ */
 BOOL Template::CreateFromDB(DWORD dwId)
 {
    TCHAR szQuery[256];