KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > client > StatusClient


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.client;
15
16 import java.util.*;
17
18 import javax.naming.*;
19 import javax.management.*;
20
21 import javax.rmi.PortableRemoteObject JavaDoc;
22 import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
23
24 import org.compiere.interfaces.*;
25 import org.compiere.interfaces.StatusHome;
26
27 /**
28  *
29  *
30  * @author Jorg Janke
31  * @version $Id: StatusClient.java,v 1.8 2003/10/10 01:04:25 jjanke Exp $
32  */

33 public class StatusClient
34 {
35     private static InitialContext s_Context = null;
36
37     /**
38      * Test
39      * @param args arguments - host
40      */

41     public static void main(String JavaDoc[] args)
42     {
43         String JavaDoc serverName = "localhost";
44         if (args.length > 0 && args[0].length() > 0)
45             serverName = args[0];
46
47         System.out.println("ServerName=" + serverName);
48
49         System.out.println("JMX");
50         try
51         {
52             String JavaDoc connectorName = "jmx:" + serverName + ":rmi";
53             RMIAdaptor server = (RMIAdaptor) new InitialContext().lookup(connectorName);
54             System.out.println("- have Server");
55             System.out.println("- Default Domain=" + server.getDefaultDomain());
56             System.out.println("- MBeanCount = " + server.getMBeanCount());
57
58             ObjectName serviceName = new ObjectName ("Compiere:service=CompiereCtrl");
59             System.out.println("- " + serviceName + " is registered=" + server.isRegistered(serviceName));
60
61             MBeanOperationInfo[] opInfo = server.getMBeanInfo(serviceName).getOperations();
62             for (int i = 0; i < opInfo.length; i++)
63                 System.out.println(" - Operation: " + opInfo[i].getName());
64             MBeanAttributeInfo[] attInfo = server.getMBeanInfo(serviceName).getAttributes();
65             for (int i = 0; i < attInfo.length; i++)
66                 System.out.println(" - Attribute: " + attInfo[i].getName() + " = "
67                     + server.getAttribute(serviceName, attInfo[i].getName()));
68
69             Object JavaDoc[] params = {};
70             String JavaDoc[] signature = {};
71         // String summary = (String) server.invoke (serviceName, "getCompiereSummary", params, signature);
72
// System.out.println("- Invoked CompiereCtrl.getCompiereSummary() " + summary);
73
}
74         catch (Exception JavaDoc e)
75         {
76             e.printStackTrace();
77         }
78
79
80
81         Hashtable env = new Hashtable();
82         env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
83         env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
84         env.put(Context.PROVIDER_URL, serverName);
85
86         //
87
try
88         {
89             s_Context = new InitialContext(env);
90         }
91         catch (Exception JavaDoc e)
92         {
93             System.out.println(e);
94             System.exit(1);
95         }
96
97
98         try
99         {
100             System.out.println(s_Context.getNameInNamespace());
101             System.out.println("-- Context Environment:");
102             System.out.println(s_Context.getEnvironment());
103
104             System.out.println("");
105             System.out.println("-- /");
106             NamingEnumeration ne = s_Context.list("/");
107             while (ne.hasMore())
108                 System.out.println(" " + ne.nextElement());
109
110             System.out.println("");
111             System.out.println("-- java:");
112             ne = s_Context.list("java:");
113             while (ne.hasMore())
114                 System.out.println(" " + ne.nextElement());
115
116             System.out.println("");
117             System.out.println("-- java:comp/env");
118             ne = s_Context.list("java:comp/env");
119             while (ne.hasMore())
120                 System.out.println(" " + ne.nextElement());
121
122             System.out.println("");
123             System.out.println("-- ejb");
124             ne = s_Context.list("ejb");
125             while (ne.hasMore())
126                 System.out.println(" " + ne.nextElement());
127
128             StatusHome statusHome = (StatusHome)s_Context.lookup ("ejb/compiere/Status");
129             Status status = statusHome.create();
130             // Get a new Id of the Test Entity
131
System.out.println ("Version is: " + status.getDateVersion() );
132             status.remove();
133
134
135         // s_Context.lookup("java:OracleDS");
136

137         }
138         catch( Exception JavaDoc e )
139         {
140             e.printStackTrace();
141         }
142         /**
143             Properties env = new Properties();
144             env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");
145             env.setProperty(Context.PROVIDER_URL, "http://localhost:8080/invoker/JNDIFactory");
146             InitialContext ctx = new InitialContext(env);
147         **/

148
149     } // main
150
} // StatusClient
151
Popular Tags