Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
d32431b9
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看板
提交
d32431b9
编写于
5月 24, 2013
作者:
M
malenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8013416: Java Bean Persistence with XMLEncoder
Reviewed-by: alexsch
上级
04afe8b1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
113 addition
and
96 deletion
+113
-96
src/share/classes/com/sun/beans/finder/AbstractFinder.java
src/share/classes/com/sun/beans/finder/AbstractFinder.java
+20
-26
src/share/classes/com/sun/beans/finder/ConstructorFinder.java
...share/classes/com/sun/beans/finder/ConstructorFinder.java
+1
-41
src/share/classes/com/sun/beans/finder/MethodFinder.java
src/share/classes/com/sun/beans/finder/MethodFinder.java
+2
-29
test/java/beans/XMLEncoder/Test8013416.java
test/java/beans/XMLEncoder/Test8013416.java
+90
-0
未找到文件。
src/share/classes/com/sun/beans/finder/AbstractFinder.java
浏览文件 @
d32431b9
/*
* Copyright (c) 2008, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 201
3
, Oracle and/or its affiliates. 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
...
...
@@ -24,6 +24,9 @@
*/
package
com.sun.beans.finder
;
import
java.lang.reflect.Executable
;
import
java.lang.reflect.Modifier
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -37,7 +40,7 @@ import java.util.Map;
*
* @author Sergey A. Malenkov
*/
abstract
class
AbstractFinder
<
T
>
{
abstract
class
AbstractFinder
<
T
extends
Executable
>
{
private
final
Class
<?>[]
args
;
/**
...
...
@@ -52,27 +55,6 @@ abstract class AbstractFinder<T> {
this
.
args
=
args
;
}
/**
* Returns an array of {@code Class} objects
* that represent the formal parameter types of the method.
* Returns an empty array if the method takes no parameters.
*
* @param method the object that represents method
* @return the parameter types of the method
*/
protected
abstract
Class
<?>[]
getParameters
(
T
method
);
/**
* Returns {@code true} if and only if the method
* was declared to take a variable number of arguments.
*
* @param method the object that represents method
* @return {@code true} if the method was declared
* to take a variable number of arguments;
* {@code false} otherwise
*/
protected
abstract
boolean
isVarArgs
(
T
method
);
/**
* Checks validness of the method.
* At least the valid method should be public.
...
...
@@ -81,7 +63,9 @@ abstract class AbstractFinder<T> {
* @return {@code true} if the method is valid,
* {@code false} otherwise
*/
protected
abstract
boolean
isValid
(
T
method
);
protected
boolean
isValid
(
T
method
)
{
return
Modifier
.
isPublic
(
method
.
getModifiers
());
}
/**
* Performs a search in the {@code methods} array.
...
...
@@ -109,7 +93,7 @@ abstract class AbstractFinder<T> {
for
(
T
newMethod
:
methods
)
{
if
(
isValid
(
newMethod
))
{
Class
<?>[]
newParams
=
getParameters
(
newMethod
);
Class
<?>[]
newParams
=
newMethod
.
getParameterTypes
(
);
if
(
newParams
.
length
==
this
.
args
.
length
)
{
PrimitiveWrapperMap
.
replacePrimitivesWithWrappers
(
newParams
);
if
(
isAssignable
(
newParams
,
this
.
args
))
{
...
...
@@ -120,6 +104,11 @@ abstract class AbstractFinder<T> {
boolean
useNew
=
isAssignable
(
oldParams
,
newParams
);
boolean
useOld
=
isAssignable
(
newParams
,
oldParams
);
if
(
useOld
&&
useNew
)
{
// only if parameters are equal
useNew
=
!
newMethod
.
isSynthetic
();
useOld
=
!
oldMethod
.
isSynthetic
();
}
if
(
useOld
==
useNew
)
{
ambiguous
=
true
;
}
else
if
(
useNew
)
{
...
...
@@ -130,7 +119,7 @@ abstract class AbstractFinder<T> {
}
}
}
if
(
isVarArgs
(
newMethod
))
{
if
(
newMethod
.
isVarArgs
(
))
{
int
length
=
newParams
.
length
-
1
;
if
(
length
<=
this
.
args
.
length
)
{
Class
<?>[]
array
=
new
Class
<?>[
this
.
args
.
length
];
...
...
@@ -160,6 +149,11 @@ abstract class AbstractFinder<T> {
boolean
useNew
=
isAssignable
(
oldParams
,
newParams
);
boolean
useOld
=
isAssignable
(
newParams
,
oldParams
);
if
(
useOld
&&
useNew
)
{
// only if parameters are equal
useNew
=
!
newMethod
.
isSynthetic
();
useOld
=
!
oldMethod
.
isSynthetic
();
}
if
(
useOld
==
useNew
)
{
if
(
oldParams
==
map
.
get
(
oldMethod
))
{
ambiguous
=
true
;
...
...
src/share/classes/com/sun/beans/finder/ConstructorFinder.java
浏览文件 @
d32431b9
/*
* Copyright (c) 2008, 201
2
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 201
3
, Oracle and/or its affiliates. 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
...
...
@@ -86,44 +86,4 @@ public final class ConstructorFinder extends AbstractFinder<Constructor<?>> {
private
ConstructorFinder
(
Class
<?>[]
args
)
{
super
(
args
);
}
/**
* Returns an array of {@code Class} objects
* that represent the formal parameter types of the constructor.
* Returns an empty array if the constructor takes no parameters.
*
* @param constructor the object that represents constructor
* @return the parameter types of the constructor
*/
@Override
protected
Class
<?>[]
getParameters
(
Constructor
<?>
constructor
)
{
return
constructor
.
getParameterTypes
();
}
/**
* Returns {@code true} if and only if the constructor
* was declared to take a variable number of arguments.
*
* @param constructor the object that represents constructor
* @return {@code true} if the constructor was declared
* to take a variable number of arguments;
* {@code false} otherwise
*/
@Override
protected
boolean
isVarArgs
(
Constructor
<?>
constructor
)
{
return
constructor
.
isVarArgs
();
}
/**
* Checks validness of the constructor.
* The valid constructor should be public.
*
* @param constructor the object that represents constructor
* @return {@code true} if the constructor is valid,
* {@code false} otherwise
*/
@Override
protected
boolean
isValid
(
Constructor
<?>
constructor
)
{
return
Modifier
.
isPublic
(
constructor
.
getModifiers
());
}
}
src/share/classes/com/sun/beans/finder/MethodFinder.java
浏览文件 @
d32431b9
/*
* Copyright (c) 2008, 201
2
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 201
3
, Oracle and/or its affiliates. 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
...
...
@@ -195,33 +195,6 @@ public final class MethodFinder extends AbstractFinder<Method> {
this
.
name
=
name
;
}
/**
* Returns an array of {@code Class} objects
* that represent the formal parameter types of the method.
* Returns an empty array if the method takes no parameters.
*
* @param method the object that represents method
* @return the parameter types of the method
*/
@Override
protected
Class
<?>[]
getParameters
(
Method
method
)
{
return
method
.
getParameterTypes
();
}
/**
* Returns {@code true} if and only if the method
* was declared to take a variable number of arguments.
*
* @param method the object that represents method
* @return {@code true} if the method was declared
* to take a variable number of arguments;
* {@code false} otherwise
*/
@Override
protected
boolean
isVarArgs
(
Method
method
)
{
return
method
.
isVarArgs
();
}
/**
* Checks validness of the method.
* The valid method should be public and
...
...
@@ -233,6 +206,6 @@ public final class MethodFinder extends AbstractFinder<Method> {
*/
@Override
protected
boolean
isValid
(
Method
method
)
{
return
!
method
.
isBridge
()
&&
Modifier
.
isPublic
(
method
.
getModifiers
()
)
&&
method
.
getName
().
equals
(
this
.
name
);
return
super
.
isValid
(
method
)
&&
method
.
getName
().
equals
(
this
.
name
);
}
}
test/java/beans/XMLEncoder/Test8013416.java
0 → 100644
浏览文件 @
d32431b9
/*
* Copyright (c) 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8013416
* @summary Tests public synthetic methods
* @author Sergey Malenkov
*/
import
java.beans.DefaultPersistenceDelegate
;
import
java.beans.Encoder
;
import
java.beans.Expression
;
import
java.beans.Statement
;
import
java.beans.XMLEncoder
;
import
java.util.HashMap
;
import
java.util.Map.Entry
;
import
java.util.Set
;
public
class
Test8013416
extends
AbstractTest
{
public
static
void
main
(
String
[]
args
)
{
new
Test8013416
().
test
(
true
);
}
protected
Object
getObject
()
{
Public
<
String
,
String
>
map
=
new
Public
<
String
,
String
>();
map
.
put
(
" pz1 "
,
" pz2 "
);
map
.
put
(
" pz3 "
,
" pz4 "
);
return
map
;
}
@Override
protected
void
initialize
(
XMLEncoder
encoder
)
{
super
.
initialize
(
encoder
);
encoder
.
setPersistenceDelegate
(
Public
.
class
,
new
PublicPersistenceDelegate
());
}
private
static
final
class
PublicPersistenceDelegate
extends
DefaultPersistenceDelegate
{
@Override
protected
Expression
instantiate
(
Object
oldInstance
,
Encoder
out
)
{
return
new
Expression
(
oldInstance
,
oldInstance
.
getClass
(),
"new"
,
null
);
}
@Override
protected
void
initialize
(
Class
<?>
type
,
Object
oldInstance
,
Object
newInstance
,
Encoder
out
)
{
super
.
initialize
(
type
,
oldInstance
,
newInstance
,
out
);
Public
<
String
,
String
>
map
=
(
Public
)
oldInstance
;
for
(
Entry
<
String
,
String
>
entry
:
map
.
getAll
())
{
String
[]
args
=
{
entry
.
getKey
(),
entry
.
getValue
()};
out
.
writeStatement
(
new
Statement
(
oldInstance
,
"put"
,
args
));
}
}
}
public
static
final
class
Public
<
K
,
V
>
extends
Private
<
K
,
V
>
{
}
private
static
class
Private
<
K
,
V
>
{
private
HashMap
<
K
,
V
>
map
=
new
HashMap
<
K
,
V
>();
public
void
put
(
K
key
,
V
value
)
{
this
.
map
.
put
(
key
,
value
);
}
public
Set
<
Entry
<
K
,
V
>>
getAll
()
{
return
this
.
map
.
entrySet
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录