author | mkos |
Sun, 30 Dec 2012 00:00:00 +0100 | |
changeset 22678 | ac1ea46be942 |
parent 12009 | 4abb694f273a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22678
ac1ea46be942
8029237: Update copyright year to match last edit in jaxws repository for 2012
mkos
parents:
12009
diff
changeset
|
2 |
* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. |
12009 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
||
27 |
||
28 |
package com.sun.org.glassfish.gmbal ; |
|
29 |
||
30 |
import java.lang.reflect.Method ; |
|
31 |
||
32 |
import java.security.AccessController; |
|
33 |
import java.security.PrivilegedActionException; |
|
34 |
import java.security.PrivilegedExceptionAction; |
|
35 |
import java.util.logging.Level; |
|
36 |
import java.util.logging.Logger; |
|
37 |
import com.sun.org.glassfish.gmbal.util.GenericConstructor ; |
|
38 |
||
39 |
import javax.management.ObjectName; |
|
40 |
||
41 |
/** Factory used to create ManagedObjectManager instances. |
|
42 |
*/ |
|
43 |
public final class ManagedObjectManagerFactory { |
|
44 |
private ManagedObjectManagerFactory() {} |
|
45 |
||
46 |
private static GenericConstructor<ManagedObjectManager> objectNameCons = |
|
47 |
new GenericConstructor<ManagedObjectManager>( |
|
48 |
ManagedObjectManager.class, |
|
49 |
"com.sun.org.glassfish.gmbal.impl.ManagedObjectManagerImpl", |
|
50 |
ObjectName.class ) ; |
|
51 |
||
52 |
||
53 |
private static GenericConstructor<ManagedObjectManager> stringCons = |
|
54 |
new GenericConstructor<ManagedObjectManager>( |
|
55 |
ManagedObjectManager.class, |
|
56 |
"com.sun.org.glassfish.gmbal.impl.ManagedObjectManagerImpl", |
|
57 |
String.class ) ; |
|
58 |
||
59 |
/** Convenience method for getting access to a method through reflection. |
|
60 |
* Same as Class.getDeclaredMethod, but only throws RuntimeExceptions. |
|
61 |
* @param cls The class to search for a method. |
|
62 |
* @param name The method name. |
|
63 |
* @param types The array of argument types. |
|
64 |
* @return The Method if found. |
|
65 |
* @throws GmbalException if no such method is found. |
|
66 |
*/ |
|
67 |
public static Method getMethod( final Class<?> cls, final String name, |
|
68 |
final Class<?>... types ) { |
|
69 |
||
70 |
try { |
|
71 |
return AccessController.doPrivileged( |
|
72 |
new PrivilegedExceptionAction<Method>() { |
|
73 |
public Method run() throws Exception { |
|
74 |
return cls.getDeclaredMethod(name, types); |
|
75 |
} |
|
76 |
}); |
|
77 |
} catch (PrivilegedActionException ex) { |
|
78 |
throw new GmbalException( "Unexpected exception", ex ) ; |
|
79 |
} catch (SecurityException exc) { |
|
80 |
throw new GmbalException( "Unexpected exception", exc ) ; |
|
81 |
} |
|
82 |
} |
|
83 |
||
84 |
/** Create a new ManagedObjectManager. All objectnames created will share |
|
85 |
* the domain value passed on this call. This ManagedObjectManager is |
|
86 |
* at the top of the containment hierarchy: the parent of the root is null. |
|
87 |
* @param domain The domain to use for all ObjectNames created when |
|
88 |
* MBeans are registered. |
|
89 |
* @return A new ManagedObjectManager. |
|
90 |
*/ |
|
91 |
public static ManagedObjectManager createStandalone( |
|
92 |
final String domain ) { |
|
93 |
||
94 |
ManagedObjectManager result = stringCons.create( domain ) ; |
|
95 |
if (result == null) { |
|
96 |
return ManagedObjectManagerNOPImpl.self ; |
|
97 |
} else { |
|
98 |
return result ; |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
/** Alternative form of the create method to be used when the |
|
103 |
* rootName is not needed explicitly. If the root name is available |
|
104 |
* from an @ObjectNameKey annotation, it is used; otherwise the |
|
105 |
* type is used as the name, since the root is a singleton. |
|
106 |
* |
|
107 |
* @param rootParentName The JMX ObjectName of the parent of the root. |
|
108 |
* The parent is outside of the control of this ManagedObjectManager. |
|
109 |
* The ManagedObjectManager root is a child of the MBean identified |
|
110 |
* by the rootParentName. |
|
111 |
* @return The ManagedObjectManager. |
|
112 |
*/ |
|
113 |
public static ManagedObjectManager createFederated( |
|
114 |
final ObjectName rootParentName ) { |
|
115 |
||
116 |
ManagedObjectManager result = objectNameCons.create( rootParentName ) ; |
|
117 |
if (result == null) { |
|
118 |
return ManagedObjectManagerNOPImpl.self ; |
|
119 |
} else { |
|
120 |
return result ; |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
/** Return a ManagedObjectManager that performs no operations. Useful to |
|
125 |
* allow the same code to run with or without creating MBeans through |
|
126 |
* gmbal. |
|
127 |
* @return ManagedObjectManager that performs no operations. |
|
128 |
*/ |
|
129 |
public static ManagedObjectManager createNOOP() { |
|
130 |
return ManagedObjectManagerNOPImpl.self ; |
|
131 |
} |
|
132 |
} |