KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > resource > PortabilityUtils


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * PortabilityUtils.java
26  *
27  * Created on January 6, 2002, 3:42 PM
28  */

29
30 package com.sun.enterprise.resource;
31
32 import java.util.Timer JavaDoc;
33 import java.lang.reflect.Method JavaDoc;
34 import java.util.logging.*;
35 // START OF IASRI 4691850
36
import java.lang.reflect.Field JavaDoc;
37 // END OF IASRI 4691850
38

39
40 /**
41  *
42  * @author kg88722
43  * @version
44  */

45 /**
46  *This is a utility class.
47  */

48 public class PortabilityUtils extends java.lang.Object JavaDoc {
49
50     /** Creates new PortabilityUtils */
51     public PortabilityUtils() {
52     }
53
54     // START OF IASRI 4691850
55
// Create logger object per Java SDK 1.4 to log messages
56
// introduced Santanu De, Sun Microsystems, March 2002
57

58     /*static Logger _logger = null;
59     static{
60            _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
61           }*/

62     // END OF IASRI 4691850
63

64     /**
65      * @return Timer object.
66      */

67     public static Timer JavaDoc GetTimer() {
68         try {
69             //try to get the Class object, if we are running in iAS this will work
70
Class JavaDoc cls = Class.forName("com.sun.enterprise.Switch");
71             Class JavaDoc param[] = new Class JavaDoc[0];
72             //get the getSwitch method
73
Method JavaDoc meth = cls.getMethod("getSwitch",param);
74             //invoke the getSwitch method will return the Switch
75
Object JavaDoc obj = meth.invoke(cls,(java.lang.Object JavaDoc[])param);
76             //get the Switch class object
77
//cls = obj.getClass();
78
//get the getTimer method
79
meth = cls.getMethod("getTimer",param);
80             //invoke the getTimer method
81
obj = meth.invoke(obj,(java.lang.Object JavaDoc[])param);
82             //return the Timer
83
return (Timer JavaDoc)obj;
84         } catch (ClassNotFoundException JavaDoc ex) {
85              //if we are not running in iAS then create a new Timer
86
return new Timer JavaDoc(true);
87         } catch (Exception JavaDoc ex) {
88             //_logger.log(Level.FINE,ex.toString());
89
return new Timer JavaDoc(true);
90         }
91       }
92 }
93
Popular Tags