Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
1b26e8f9
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1b26e8f9
编写于
10月 23, 2008
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removed commons atts support for JMX, made ModelMap generic
上级
edf0d8eb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
3 addition
and
206 deletion
+3
-206
org.springframework.context/src/main/java/org/springframework/jmx/export/metadata/AttributesJmxAttributeSource.java
...ork/jmx/export/metadata/AttributesJmxAttributeSource.java
+0
-203
org.springframework.context/src/main/java/org/springframework/ui/ModelMap.java
...ontext/src/main/java/org/springframework/ui/ModelMap.java
+3
-3
未找到文件。
org.springframework.context/src/main/java/org/springframework/jmx/export/metadata/AttributesJmxAttributeSource.java
已删除
100644 → 0
浏览文件 @
edf0d8eb
/*
* Copyright 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.jmx.export.metadata
;
import
java.beans.PropertyDescriptor
;
import
java.lang.reflect.Method
;
import
java.util.Collection
;
import
java.util.Iterator
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.metadata.Attributes
;
import
org.springframework.util.Assert
;
/**
* Implementation of the <code>JmxAttributeSource</code> interface that
* reads metadata via Spring's <code>Attributes</code> abstraction.
*
* <p>Typically used for reading in source-level attributes via
* Commons Attributes.
*
* @author Rob Harrop
* @since 1.2
* @see org.springframework.metadata.Attributes
* @see org.springframework.metadata.commons.CommonsAttributes
*/
public
class
AttributesJmxAttributeSource
implements
JmxAttributeSource
,
InitializingBean
{
/**
* Underlying Attributes implementation that we're using.
*/
private
Attributes
attributes
;
/**
* Create a new AttributesJmxAttributeSource.
* @see #setAttributes
*/
public
AttributesJmxAttributeSource
()
{
}
/**
* Create a new AttributesJmxAttributeSource.
* @param attributes the Attributes implementation to use
* @see org.springframework.metadata.commons.CommonsAttributes
*/
public
AttributesJmxAttributeSource
(
Attributes
attributes
)
{
if
(
attributes
==
null
)
{
throw
new
IllegalArgumentException
(
"Attributes is required"
);
}
this
.
attributes
=
attributes
;
}
/**
* Set the Attributes implementation to use.
* @see org.springframework.metadata.commons.CommonsAttributes
*/
public
void
setAttributes
(
Attributes
attributes
)
{
this
.
attributes
=
attributes
;
}
public
void
afterPropertiesSet
()
{
if
(
this
.
attributes
==
null
)
{
throw
new
IllegalArgumentException
(
"'attributes' is required"
);
}
}
/**
* If the specified class has a <code>ManagedResource</code> attribute,
* then it is returned. Otherwise returns null.
* @param clazz the class to read the attribute data from
* @return the attribute, or <code>null</code> if not found
* @throws InvalidMetadataException if more than one attribute exists
*/
public
ManagedResource
getManagedResource
(
Class
clazz
)
{
Assert
.
notNull
(
this
.
attributes
,
"'attributes' is required"
);
Collection
attrs
=
this
.
attributes
.
getAttributes
(
clazz
,
ManagedResource
.
class
);
if
(
attrs
.
isEmpty
())
{
return
null
;
}
else
if
(
attrs
.
size
()
==
1
)
{
return
(
ManagedResource
)
attrs
.
iterator
().
next
();
}
else
{
throw
new
InvalidMetadataException
(
"A Class can have only one ManagedResource attribute"
);
}
}
/**
* If the specified method has a <code>ManagedAttribute</code> attribute,
* then it is returned. Otherwise returns null.
* @param method the method to read the attribute data from
* @return the attribute, or <code>null</code> if not found
* @throws InvalidMetadataException if more than one attribute exists,
* or if the supplied method does not represent a JavaBean property
*/
public
ManagedAttribute
getManagedAttribute
(
Method
method
)
throws
InvalidMetadataException
{
Assert
.
notNull
(
this
.
attributes
,
"'attributes' is required"
);
PropertyDescriptor
pd
=
BeanUtils
.
findPropertyForMethod
(
method
);
if
(
pd
==
null
)
{
throw
new
InvalidMetadataException
(
"The ManagedAttribute attribute is only valid for JavaBean properties: "
+
"use ManagedOperation for methods"
);
}
Collection
attrs
=
this
.
attributes
.
getAttributes
(
method
,
ManagedAttribute
.
class
);
if
(
attrs
.
isEmpty
())
{
return
null
;
}
else
if
(
attrs
.
size
()
==
1
)
{
return
(
ManagedAttribute
)
attrs
.
iterator
().
next
();
}
else
{
throw
new
InvalidMetadataException
(
"A Method can have only one ManagedAttribute attribute"
);
}
}
/**
* If the specified method has a <code>ManagedOperation</code> attribute,
* then it is returned. Otherwise return null.
* @param method the method to read the attribute data from
* @return the attribute, or <code>null</code> if not found
* @throws InvalidMetadataException if more than one attribute exists,
* or if the supplied method represents a JavaBean property
*/
public
ManagedOperation
getManagedOperation
(
Method
method
)
{
Assert
.
notNull
(
this
.
attributes
,
"'attributes' is required"
);
PropertyDescriptor
pd
=
BeanUtils
.
findPropertyForMethod
(
method
);
if
(
pd
!=
null
)
{
throw
new
InvalidMetadataException
(
"The ManagedOperation attribute is not valid for JavaBean properties: "
+
"use ManagedAttribute instead"
);
}
Collection
attrs
=
this
.
attributes
.
getAttributes
(
method
,
ManagedOperation
.
class
);
if
(
attrs
.
isEmpty
())
{
return
null
;
}
else
if
(
attrs
.
size
()
==
1
)
{
return
(
ManagedOperation
)
attrs
.
iterator
().
next
();
}
else
{
throw
new
InvalidMetadataException
(
"A Method can have only one ManagedAttribute attribute"
);
}
}
/**
* If the specified method has <code>ManagedOperationParameter</code> attributes,
* then these are returned, otherwise a zero length array is returned.
* @param method the method to get the managed operation parameters for
* @return the array of ManagedOperationParameter objects
* @throws InvalidMetadataException if the number of ManagedOperationParameter
* attributes does not match the number of parameters in the method
*/
public
ManagedOperationParameter
[]
getManagedOperationParameters
(
Method
method
)
throws
InvalidMetadataException
{
Assert
.
notNull
(
this
.
attributes
,
"'attributes' is required"
);
Collection
attrs
=
this
.
attributes
.
getAttributes
(
method
,
ManagedOperationParameter
.
class
);
if
(
attrs
.
size
()
==
0
)
{
return
new
ManagedOperationParameter
[
0
];
}
else
if
(
attrs
.
size
()
!=
method
.
getParameterTypes
().
length
)
{
throw
new
InvalidMetadataException
(
"Method ["
+
method
+
"] has an incorrect number of ManagedOperationParameters specified"
);
}
else
{
ManagedOperationParameter
[]
params
=
new
ManagedOperationParameter
[
attrs
.
size
()];
for
(
Iterator
it
=
attrs
.
iterator
();
it
.
hasNext
();)
{
ManagedOperationParameter
param
=
(
ManagedOperationParameter
)
it
.
next
();
if
(
param
.
getIndex
()
<
0
||
param
.
getIndex
()
>=
params
.
length
)
{
throw
new
InvalidMetadataException
(
"ManagedOperationParameter index for ["
+
param
.
getName
()
+
"] is out of bounds"
);
}
params
[
param
.
getIndex
()]
=
param
;
}
return
params
;
}
}
/**
* If the specified has {@link ManagedNotification} attributes these are returned, otherwise
* a zero-length array is returned.
*/
public
ManagedNotification
[]
getManagedNotifications
(
Class
clazz
)
{
Assert
.
notNull
(
this
.
attributes
,
"'attributes' is required"
);
Collection
attrs
=
this
.
attributes
.
getAttributes
(
clazz
,
ManagedNotification
.
class
);
return
attrs
.
isEmpty
()
?
new
ManagedNotification
[
0
]
:
(
ManagedNotification
[])
attrs
.
toArray
(
new
ManagedNotification
[
attrs
.
size
()]);
}
}
org.springframework.context/src/main/java/org/springframework/ui/ModelMap.java
浏览文件 @
1b26e8f9
...
...
@@ -100,7 +100,7 @@ public class ModelMap extends LinkedHashMap {
* <code>Map</code>, using attribute name generation for each element.
* @see #addAttribute(Object)
*/
public
ModelMap
addAllAttributes
(
Collection
attributeValues
)
{
public
ModelMap
addAllAttributes
(
Collection
<?>
attributeValues
)
{
if
(
attributeValues
!=
null
)
{
for
(
Iterator
it
=
attributeValues
.
iterator
();
it
.
hasNext
();)
{
addAttribute
(
it
.
next
());
...
...
@@ -113,7 +113,7 @@ public class ModelMap extends LinkedHashMap {
* Copy all attributes in the supplied <code>Map</code> into this <code>Map</code>.
* @see #addAttribute(String, Object)
*/
public
ModelMap
addAllAttributes
(
Map
attributes
)
{
public
ModelMap
addAllAttributes
(
Map
<
String
,
?>
attributes
)
{
if
(
attributes
!=
null
)
{
putAll
(
attributes
);
}
...
...
@@ -125,7 +125,7 @@ public class ModelMap extends LinkedHashMap {
* with existing objects of the same name taking precedence (i.e. not getting
* replaced).
*/
public
ModelMap
mergeAttributes
(
Map
attributes
)
{
public
ModelMap
mergeAttributes
(
Map
<
String
,
?>
attributes
)
{
if
(
attributes
!=
null
)
{
for
(
Iterator
it
=
attributes
.
keySet
().
iterator
();
it
.
hasNext
();)
{
Object
key
=
it
.
next
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录