Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
e8ca8567
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e8ca8567
编写于
12月 09, 2008
作者:
J
jfdenise
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6250014: MBeanOperationInfo Descriptor field for exceptions
Reviewed-by: emcmanus
上级
1589d57e
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
320 addition
and
9 deletion
+320
-9
src/share/classes/com/sun/jmx/mbeanserver/ConvertingMethod.java
...are/classes/com/sun/jmx/mbeanserver/ConvertingMethod.java
+1
-1
src/share/classes/com/sun/jmx/mbeanserver/Introspector.java
src/share/classes/com/sun/jmx/mbeanserver/Introspector.java
+39
-2
src/share/classes/com/sun/jmx/mbeanserver/MBeanIntrospector.java
...re/classes/com/sun/jmx/mbeanserver/MBeanIntrospector.java
+1
-1
src/share/classes/com/sun/jmx/mbeanserver/MXBeanIntrospector.java
...e/classes/com/sun/jmx/mbeanserver/MXBeanIntrospector.java
+1
-1
src/share/classes/javax/management/Descriptor.java
src/share/classes/javax/management/Descriptor.java
+15
-0
src/share/classes/javax/management/JMX.java
src/share/classes/javax/management/JMX.java
+12
-0
src/share/classes/javax/management/MBeanAttributeInfo.java
src/share/classes/javax/management/MBeanAttributeInfo.java
+4
-2
src/share/classes/javax/management/MBeanConstructorInfo.java
src/share/classes/javax/management/MBeanConstructorInfo.java
+1
-1
src/share/classes/javax/management/MBeanOperationInfo.java
src/share/classes/javax/management/MBeanOperationInfo.java
+1
-1
test/javax/management/Introspector/ExceptionsDescriptorTest.java
...vax/management/Introspector/ExceptionsDescriptorTest.java
+245
-0
未找到文件。
src/share/classes/com/sun/jmx/mbeanserver/ConvertingMethod.java
浏览文件 @
e8ca8567
...
...
@@ -53,7 +53,7 @@ final class ConvertingMethod {
}
Descriptor
getDescriptor
()
{
return
Introspector
.
descriptorForElement
(
method
);
return
Introspector
.
descriptorForElement
(
method
,
false
);
}
Type
getGenericReturnType
()
{
...
...
src/share/classes/com/sun/jmx/mbeanserver/Introspector.java
浏览文件 @
e8ca8567
...
...
@@ -63,7 +63,10 @@ import java.beans.BeanInfo;
import
java.beans.PropertyDescriptor
;
import
java.lang.reflect.Array
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
import
javax.management.AttributeNotFoundException
;
import
javax.management.JMX
;
import
javax.management.openmbean.CompositeData
;
import
javax.management.openmbean.MXBeanMappingFactory
;
...
...
@@ -462,11 +465,31 @@ public class Introspector {
return
null
;
}
public
static
Descriptor
descriptorForElement
(
final
AnnotatedElement
elmt
)
{
public
static
Descriptor
descriptorForElement
(
final
AnnotatedElement
elmt
,
boolean
isSetter
)
{
if
(
elmt
==
null
)
return
ImmutableDescriptor
.
EMPTY_DESCRIPTOR
;
final
Annotation
[]
annots
=
elmt
.
getAnnotations
();
return
descriptorForAnnotations
(
annots
);
Descriptor
descr
=
descriptorForAnnotations
(
annots
);
String
[]
exceptions
=
{};
if
(
elmt
instanceof
Method
)
exceptions
=
getAllExceptions
(((
Method
)
elmt
).
getExceptionTypes
());
else
if
(
elmt
instanceof
Constructor
<?>)
exceptions
=
getAllExceptions
(((
Constructor
<?>)
elmt
).
getExceptionTypes
());
if
(
exceptions
.
length
>
0
)
{
String
fieldName
=
isSetter
?
JMX
.
SET_EXCEPTIONS_FIELD
:
JMX
.
EXCEPTIONS_FIELD
;
String
[]
fieldNames
=
{
fieldName
};
Object
[]
fieldValues
=
{
exceptions
};
descr
=
ImmutableDescriptor
.
union
(
descr
,
new
ImmutableDescriptor
(
fieldNames
,
fieldValues
));
}
return
descr
;
}
public
static
Descriptor
descriptorForAnnotation
(
Annotation
annot
)
{
...
...
@@ -489,6 +512,20 @@ public class Introspector {
return
new
ImmutableDescriptor
(
descriptorMap
);
}
/**
* Array of thrown excepions.
* @param exceptions can be null;
* @return An Array of Exception class names. Size is 0 if method is null.
*/
private
static
String
[]
getAllExceptions
(
Class
<?>[]
exceptions
)
{
Set
<
String
>
set
=
new
LinkedHashSet
<
String
>();
for
(
Class
<?>
ex
:
exceptions
)
set
.
add
(
ex
.
getName
());
String
[]
arr
=
new
String
[
set
.
size
()];
return
set
.
toArray
(
arr
);
}
private
static
void
addDescriptorFieldsToMap
(
Map
<
String
,
Object
>
descriptorMap
,
DescriptorFields
df
)
{
for
(
String
field
:
df
.
value
())
{
...
...
src/share/classes/com/sun/jmx/mbeanserver/MBeanIntrospector.java
浏览文件 @
e8ca8567
...
...
@@ -403,7 +403,7 @@ public abstract class MBeanIntrospector<M> {
new
ImmutableDescriptor
(
interfaceClassName
);
final
Descriptor
mbeanDescriptor
=
getBasicMBeanDescriptor
();
final
Descriptor
annotatedDescriptor
=
Introspector
.
descriptorForElement
(
mbeanInterface
);
Introspector
.
descriptorForElement
(
mbeanInterface
,
false
);
final
Descriptor
descriptor
=
DescriptorCache
.
getInstance
().
union
(
classNameDescriptor
,
...
...
src/share/classes/com/sun/jmx/mbeanserver/MXBeanIntrospector.java
浏览文件 @
e8ca8567
...
...
@@ -292,7 +292,7 @@ class MXBeanIntrospector extends MBeanIntrospector<ConvertingMethod> {
Descriptor
descriptor
=
typeDescriptor
(
returnType
,
originalReturnType
);
descriptor
=
ImmutableDescriptor
.
union
(
descriptor
,
Introspector
.
descriptorForElement
(
method
));
Introspector
.
descriptorForElement
(
method
,
false
));
final
MBeanOperationInfo
oi
;
if
(
openReturnType
&&
openParameterTypes
)
{
/* If the return value and all the parameters can be faithfully
...
...
src/share/classes/javax/management/Descriptor.java
浏览文件 @
e8ca8567
...
...
@@ -147,6 +147,14 @@ import javax.management.openmbean.OpenType;
* might be disabled if it cannot currently be emitted but could be in
* other circumstances.</td>
*
* <tr id="exceptions"><td><i>exceptions</i><td>String[]</td>
* <td>MBeanAttributeInfo, MBeanConstructorInfo, MBeanOperationInfo</td>
*
* <td>The class names of the exceptions that can be thrown when invoking a
* constructor or operation, or getting an attribute. Exceptions thrown when
* setting an attribute are specified by the field
* <a href="#setExceptions">{@code setExceptions}</a>.
*
* <tr id="immutableInfo"><td><i>immutableInfo</i><td>String</td>
* <td>MBeanInfo</td>
*
...
...
@@ -270,6 +278,13 @@ import javax.management.openmbean.OpenType;
* href="MXBean.html#type-names">Type Names</a> of the MXBean
* specification.</p>
*
* <tr id="setExceptions"><td><i>setExceptions</i><td>String[]</td>
* <td>MBeanAttributeInfo</td>
*
* <td>The class names of the exceptions that can be thrown when setting
* an attribute. Exceptions thrown when getting an attribute are specified
* by the field <a href="#exceptions">{@code exceptions}</a>.
*
* <tr><td>severity</td><td>String<br>Integer</td>
* <td>MBeanNotificationInfo</td>
*
...
...
src/share/classes/javax/management/JMX.java
浏览文件 @
e8ca8567
...
...
@@ -75,6 +75,12 @@ public class JMX {
public
static
final
String
DESCRIPTION_RESOURCE_KEY_FIELD
=
"descriptionResourceKey"
;
/**
* The name of the <a href="Descriptor.html#exceptions">{@code
* exceptions}</a> field.
*/
public
static
final
String
EXCEPTIONS_FIELD
=
"exceptions"
;
/**
* The name of the <a href="Descriptor.html#immutableInfo">{@code
* immutableInfo}</a> field.
...
...
@@ -137,6 +143,12 @@ public class JMX {
*/
public
static
final
String
ORIGINAL_TYPE_FIELD
=
"originalType"
;
/**
* The name of the <a href="Descriptor.html#setExceptions">{@code
* setExceptions}</a> field.
*/
public
static
final
String
SET_EXCEPTIONS_FIELD
=
"setExceptions"
;
/**
* <p>Options to apply to an MBean proxy or to an instance of {@link
* StandardMBean}.</p>
...
...
src/share/classes/javax/management/MBeanAttributeInfo.java
浏览文件 @
e8ca8567
...
...
@@ -186,8 +186,10 @@ public class MBeanAttributeInfo extends MBeanFeatureInfo implements Cloneable {
(
getter
!=
null
),
(
setter
!=
null
),
isIs
(
getter
),
ImmutableDescriptor
.
union
(
Introspector
.
descriptorForElement
(
getter
),
Introspector
.
descriptorForElement
(
setter
)));
ImmutableDescriptor
.
union
(
Introspector
.
descriptorForElement
(
getter
,
false
),
Introspector
.
descriptorForElement
(
setter
,
true
)));
}
/**
...
...
src/share/classes/javax/management/MBeanConstructorInfo.java
浏览文件 @
e8ca8567
...
...
@@ -67,7 +67,7 @@ public class MBeanConstructorInfo extends MBeanFeatureInfo implements Cloneable
public
MBeanConstructorInfo
(
String
description
,
Constructor
<?>
constructor
)
{
this
(
constructor
.
getName
(),
description
,
constructorSignature
(
constructor
),
Introspector
.
descriptorForElement
(
constructor
));
Introspector
.
descriptorForElement
(
constructor
,
false
));
}
/**
...
...
src/share/classes/javax/management/MBeanOperationInfo.java
浏览文件 @
e8ca8567
...
...
@@ -113,7 +113,7 @@ public class MBeanOperationInfo extends MBeanFeatureInfo implements Cloneable {
methodSignature
(
method
),
method
.
getReturnType
().
getName
(),
UNKNOWN
,
Introspector
.
descriptorForElement
(
method
));
Introspector
.
descriptorForElement
(
method
,
false
));
}
/**
...
...
test/javax/management/Introspector/ExceptionsDescriptorTest.java
0 → 100644
浏览文件 @
e8ca8567
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test %M% %I%
* @bug 6250014
* @summary Test that Exceptions are added to the MbeanInfo
* @author Jean-Francois Denise
* @run main/othervm ExceptionsDescriptorTest
*/
import
java.lang.management.ManagementFactory
;
import
java.util.HashSet
;
import
java.util.Set
;
import
javax.management.Descriptor
;
import
javax.management.JMX
;
import
javax.management.MBeanAttributeInfo
;
import
javax.management.MBeanConstructorInfo
;
import
javax.management.MBeanInfo
;
import
javax.management.MBeanOperationInfo
;
import
javax.management.ObjectName
;
public
class
ExceptionsDescriptorTest
{
private
static
final
ObjectName
OBJECT_NAME
=
ObjectName
.
valueOf
(
":type=Foo"
);
final
static
String
EXCEPTION_NAME
=
Exception
.
class
.
getName
();
final
static
String
ILLEGAL_ARGUMENT_EXCEPTION_NAME
=
IllegalArgumentException
.
class
.
getName
();
final
static
Set
<
String
>
ONE_EXCEPTION
=
new
HashSet
<
String
>();
final
static
Set
<
String
>
TWO_EXCEPTION
=
new
HashSet
<
String
>();
static
{
ONE_EXCEPTION
.
add
(
EXCEPTION_NAME
);
TWO_EXCEPTION
.
add
(
EXCEPTION_NAME
);
TWO_EXCEPTION
.
add
(
ILLEGAL_ARGUMENT_EXCEPTION_NAME
);
}
public
interface
TestMBean
{
public
void
doIt
();
public
void
doIt
(
String
str
)
throws
Exception
;
public
void
doIt
(
String
str
,
boolean
b
)
throws
Exception
,
IllegalArgumentException
;
public
String
getThat
();
public
void
setThat
(
String
that
);
public
String
getThe
()
throws
Exception
;
public
void
setThe
(
String
the
);
public
String
getThese
();
public
void
setThese
(
String
the
)
throws
Exception
;
public
String
getIt
()
throws
Exception
;
public
void
setIt
(
String
str
)
throws
Exception
;
public
String
getThis
()
throws
Exception
,
IllegalArgumentException
;
public
void
setThose
(
String
str
)
throws
Exception
,
IllegalArgumentException
;
}
public
static
class
Test
implements
TestMBean
{
public
Test
()
{
}
public
Test
(
int
i
)
throws
Exception
{
}
public
Test
(
int
i
,
int
j
)
throws
Exception
,
IllegalArgumentException
{
}
public
void
doIt
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
void
doIt
(
String
str
)
throws
Exception
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
void
doIt
(
String
str
,
boolean
b
)
throws
Exception
,
IllegalArgumentException
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
String
getThat
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
void
setThat
(
String
that
)
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
String
getThe
()
throws
Exception
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
void
setThe
(
String
the
)
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
String
getThese
()
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
void
setThese
(
String
the
)
throws
Exception
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
String
getIt
()
throws
Exception
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
void
setIt
(
String
str
)
throws
Exception
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
String
getThis
()
throws
Exception
,
IllegalArgumentException
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
public
void
setThose
(
String
str
)
throws
Exception
,
IllegalArgumentException
{
throw
new
UnsupportedOperationException
(
"Not supported yet."
);
}
}
private
static
void
check
(
Descriptor
d
,
Set
<
String
>
exceptionsExpectedValue
,
boolean
exceptionsExpected
,
Set
<
String
>
setExceptionsExpectedValue
,
boolean
setExceptionsExpected
)
throws
Exception
{
String
[]
exceptionsValues
=
(
String
[])
d
.
getFieldValue
(
JMX
.
EXCEPTIONS_FIELD
);
String
[]
setExceptionsValues
=
(
String
[])
d
.
getFieldValue
(
JMX
.
SET_EXCEPTIONS_FIELD
);
if
(
exceptionsExpected
&&
exceptionsValues
==
null
)
{
throw
new
Exception
(
"exceptions is expected but null value"
);
}
if
(!
exceptionsExpected
&&
exceptionsValues
!=
null
)
{
throw
new
Exception
(
"exceptions is not expected but non null value"
);
}
if
(
setExceptionsExpected
&&
setExceptionsValues
==
null
)
{
throw
new
Exception
(
"setExceptions is expected but null value"
);
}
if
(!
setExceptionsExpected
&&
setExceptionsValues
!=
null
)
{
throw
new
Exception
(
"setExceptions is not expected but non null value"
);
}
if
(
exceptionsExpected
)
{
checkValues
(
exceptionsExpectedValue
,
exceptionsValues
);
}
if
(
setExceptionsExpected
)
{
checkValues
(
setExceptionsExpectedValue
,
setExceptionsValues
);
}
}
private
static
void
checkValues
(
Set
<
String
>
expectedValuesSet
,
String
[]
realValues
)
throws
Exception
{
Set
<
String
>
realValuesSet
=
new
HashSet
<
String
>();
for
(
String
ex
:
realValues
)
{
realValuesSet
.
add
(
ex
);
}
if
(!
realValuesSet
.
equals
(
expectedValuesSet
))
{
throw
new
Exception
(
"Invalid content for exceptions. Was expecting "
+
expectedValuesSet
+
". Found "
+
realValuesSet
);
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Test
t
=
new
Test
();
ManagementFactory
.
getPlatformMBeanServer
().
registerMBean
(
t
,
OBJECT_NAME
);
MBeanInfo
info
=
ManagementFactory
.
getPlatformMBeanServer
().
getMBeanInfo
(
OBJECT_NAME
);
//Constructors
for
(
MBeanConstructorInfo
ctr
:
info
.
getConstructors
())
{
if
(
ctr
.
getSignature
().
length
==
0
)
{
check
(
ctr
.
getDescriptor
(),
null
,
false
,
null
,
false
);
}
if
(
ctr
.
getSignature
().
length
==
1
)
{
check
(
ctr
.
getDescriptor
(),
ONE_EXCEPTION
,
true
,
null
,
false
);
}
if
(
ctr
.
getSignature
().
length
==
2
)
{
check
(
ctr
.
getDescriptor
(),
TWO_EXCEPTION
,
true
,
null
,
false
);
}
}
//Attributes
for
(
MBeanAttributeInfo
attr
:
info
.
getAttributes
())
{
if
(
attr
.
getName
().
equals
(
"That"
))
{
check
(
attr
.
getDescriptor
(),
null
,
false
,
null
,
false
);
}
if
(
attr
.
getName
().
equals
(
"The"
))
{
check
(
attr
.
getDescriptor
(),
ONE_EXCEPTION
,
true
,
null
,
false
);
}
if
(
attr
.
getName
().
equals
(
"These"
))
{
check
(
attr
.
getDescriptor
(),
null
,
false
,
ONE_EXCEPTION
,
true
);
}
if
(
attr
.
getName
().
equals
(
"It"
))
{
check
(
attr
.
getDescriptor
(),
ONE_EXCEPTION
,
true
,
ONE_EXCEPTION
,
true
);
}
if
(
attr
.
getName
().
equals
(
"This"
))
{
check
(
attr
.
getDescriptor
(),
TWO_EXCEPTION
,
true
,
null
,
false
);
}
if
(
attr
.
getName
().
equals
(
"Those"
))
{
check
(
attr
.
getDescriptor
(),
null
,
false
,
TWO_EXCEPTION
,
true
);
}
}
//Operations
for
(
MBeanOperationInfo
oper
:
info
.
getOperations
())
{
if
(
oper
.
getSignature
().
length
==
0
)
{
check
(
oper
.
getDescriptor
(),
null
,
false
,
null
,
false
);
}
if
(
oper
.
getSignature
().
length
==
1
)
{
check
(
oper
.
getDescriptor
(),
ONE_EXCEPTION
,
true
,
null
,
false
);
}
if
(
oper
.
getSignature
().
length
==
2
)
{
check
(
oper
.
getDescriptor
(),
TWO_EXCEPTION
,
true
,
null
,
false
);
}
}
System
.
out
.
println
(
"Test passed"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录