Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell11
提交
8b97d3b4
D
dragonwell11
项目概览
openanolis
/
dragonwell11
通知
7
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell11
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8b97d3b4
编写于
2月 05, 2009
作者:
M
malenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6669869: Beans.isDesignTime() and other queries should be per-AppContext
Reviewed-by: peterz, rupashka
上级
445cc8dc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
158 addition
and
43 deletion
+158
-43
jdk/src/share/classes/java/beans/Beans.java
jdk/src/share/classes/java/beans/Beans.java
+53
-43
jdk/test/java/beans/Beans/6669869/TestDesignTime.java
jdk/test/java/beans/Beans/6669869/TestDesignTime.java
+52
-0
jdk/test/java/beans/Beans/6669869/TestGuiAvailable.java
jdk/test/java/beans/Beans/6669869/TestGuiAvailable.java
+53
-0
未找到文件。
jdk/src/share/classes/java/beans/Beans.java
浏览文件 @
8b97d3b4
/*
* Copyright 1996-200
6
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1996-200
9
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
...
...
@@ -27,26 +27,41 @@ package java.beans;
import
com.sun.beans.finder.ClassFinder
;
import
java.applet.*
;
import
java.applet.Applet
;
import
java.applet.AppletContext
;
import
java.applet.AppletStub
;
import
java.applet.AudioClip
;
import
java.awt.*
;
import
java.beans.AppletInitializer
;
import
java.awt.GraphicsEnvironment
;
import
java.awt.Image
;
import
java.beans.beancontext.BeanContext
;
import
java.io.*
;
import
java.lang.reflect.Constructor
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectStreamClass
;
import
java.io.StreamCorruptedException
;
import
java.net.URL
;
import
java.lang.reflect.Array
;
import
java.security.AccessController
;
import
java.security.PrivilegedAction
;
import
java.util.Enumeration
;
import
java.util.Hashtable
;
import
java.util.Iterator
;
import
java.util.Vector
;
import
sun.awt.AppContext
;
/**
* This class provides some general purpose beans control methods.
*/
public
class
Beans
{
private
static
final
Object
DESIGN_TIME
=
new
Object
();
private
static
final
Object
GUI_AVAILABLE
=
new
Object
();
/**
* <p>
...
...
@@ -59,12 +74,12 @@ public class Beans {
* @param beanName the name of the bean within the class-loader.
* For example "sun.beanbox.foobah"
*
* @exception
java.lang.
ClassNotFoundException if the class of a serialized
* @exception ClassNotFoundException if the class of a serialized
* object could not be found.
* @exception
java.io.
IOException if an I/O error occurs.
* @exception IOException if an I/O error occurs.
*/
public
static
Object
instantiate
(
ClassLoader
cls
,
String
beanName
)
throws
java
.
io
.
IOException
,
ClassNotFoundException
{
public
static
Object
instantiate
(
ClassLoader
cls
,
String
beanName
)
throws
IOException
,
ClassNotFoundException
{
return
Beans
.
instantiate
(
cls
,
beanName
,
null
,
null
);
}
...
...
@@ -80,12 +95,12 @@ public class Beans {
* For example "sun.beanbox.foobah"
* @param beanContext The BeanContext in which to nest the new bean
*
* @exception
java.lang.
ClassNotFoundException if the class of a serialized
* @exception ClassNotFoundException if the class of a serialized
* object could not be found.
* @exception
java.io.
IOException if an I/O error occurs.
* @exception IOException if an I/O error occurs.
*/
public
static
Object
instantiate
(
ClassLoader
cls
,
String
beanName
,
BeanContext
beanContext
)
throws
java
.
io
.
IOException
,
ClassNotFoundException
{
public
static
Object
instantiate
(
ClassLoader
cls
,
String
beanName
,
BeanContext
beanContext
)
throws
IOException
,
ClassNotFoundException
{
return
Beans
.
instantiate
(
cls
,
beanName
,
beanContext
,
null
);
}
...
...
@@ -135,19 +150,19 @@ public class Beans {
* @param beanContext The BeanContext in which to nest the new bean
* @param initializer The AppletInitializer for the new bean
*
* @exception
java.lang.
ClassNotFoundException if the class of a serialized
* @exception ClassNotFoundException if the class of a serialized
* object could not be found.
* @exception
java.io.
IOException if an I/O error occurs.
* @exception IOException if an I/O error occurs.
*/
public
static
Object
instantiate
(
ClassLoader
cls
,
String
beanName
,
BeanContext
beanContext
,
AppletInitializer
initializer
)
throws
java
.
io
.
IOException
,
ClassNotFoundException
{
throws
IOException
,
ClassNotFoundException
{
java
.
io
.
InputStream
ins
;
java
.
io
.
ObjectInputStream
oins
=
null
;
InputStream
ins
;
ObjectInputStream
oins
=
null
;
Object
result
=
null
;
boolean
serialized
=
false
;
java
.
io
.
IOException
serex
=
null
;
IOException
serex
=
null
;
// If the given classloader is null, we check if an
// system classloader is available and (if so)
...
...
@@ -166,8 +181,8 @@ public class Beans {
// Try to find a serialized object with this name
final
String
serName
=
beanName
.
replace
(
'.'
,
'/'
).
concat
(
".ser"
);
final
ClassLoader
loader
=
cls
;
ins
=
(
InputStream
)
java
.
security
.
AccessController
.
doPrivileged
(
new
java
.
security
.
PrivilegedAction
()
{
ins
=
(
InputStream
)
AccessController
.
doPrivileged
(
new
PrivilegedAction
()
{
public
Object
run
()
{
if
(
loader
==
null
)
return
ClassLoader
.
getSystemResourceAsStream
(
serName
);
...
...
@@ -185,7 +200,7 @@ public class Beans {
result
=
oins
.
readObject
();
serialized
=
true
;
oins
.
close
();
}
catch
(
java
.
io
.
IOException
ex
)
{
}
catch
(
IOException
ex
)
{
ins
.
close
();
// Drop through and try opening the class. But remember
// the exception in case we can't find the class either.
...
...
@@ -264,8 +279,8 @@ public class Beans {
final
ClassLoader
cloader
=
cls
;
objectUrl
=
(
URL
)
java
.
security
.
AccessController
.
doPrivileged
(
new
java
.
security
.
PrivilegedAction
()
{
AccessController
.
doPrivileged
(
new
PrivilegedAction
()
{
public
Object
run
()
{
if
(
cloader
==
null
)
return
ClassLoader
.
getSystemResource
...
...
@@ -377,10 +392,11 @@ public class Beans {
* @return True if we are running in an application construction
* environment.
*
* @see
java.beans.
DesignMode
* @see DesignMode
*/
public
static
boolean
isDesignTime
()
{
return
designTime
;
Object
value
=
AppContext
.
getAppContext
().
get
(
DESIGN_TIME
);
return
(
value
instanceof
Boolean
)
&&
(
Boolean
)
value
;
}
/**
...
...
@@ -393,11 +409,12 @@ public class Beans {
* false in a server environment or if an application is
* running as part of a batch job.
*
* @see
java.beans.
Visibility
* @see Visibility
*
*/
public
static
boolean
isGuiAvailable
()
{
return
guiAvailable
;
Object
value
=
AppContext
.
getAppContext
().
get
(
GUI_AVAILABLE
);
return
(
value
instanceof
Boolean
)
?
(
Boolean
)
value
:
!
GraphicsEnvironment
.
isHeadless
();
}
/**
...
...
@@ -423,7 +440,7 @@ public class Beans {
if
(
sm
!=
null
)
{
sm
.
checkPropertiesAccess
();
}
designTime
=
isDesignTime
;
AppContext
.
getAppContext
().
put
(
DESIGN_TIME
,
Boolean
.
valueOf
(
isDesignTime
))
;
}
/**
...
...
@@ -449,14 +466,7 @@ public class Beans {
if
(
sm
!=
null
)
{
sm
.
checkPropertiesAccess
();
}
guiAvailable
=
isGuiAvailable
;
}
private
static
boolean
designTime
;
private
static
boolean
guiAvailable
;
static
{
guiAvailable
=
!
GraphicsEnvironment
.
isHeadless
();
AppContext
.
getAppContext
().
put
(
GUI_AVAILABLE
,
Boolean
.
valueOf
(
isGuiAvailable
));
}
}
...
...
@@ -501,7 +511,7 @@ class ObjectInputStreamWithLoader extends ObjectInputStream
class
BeansAppletContext
implements
AppletContext
{
Applet
target
;
java
.
util
.
Hashtable
imageCache
=
new
java
.
util
.
Hashtable
();
Hashtable
imageCache
=
new
Hashtable
();
BeansAppletContext
(
Applet
target
)
{
this
.
target
=
target
;
...
...
@@ -546,8 +556,8 @@ class BeansAppletContext implements AppletContext {
return
null
;
}
public
java
.
util
.
Enumeration
getApplets
()
{
java
.
util
.
Vector
applets
=
new
java
.
util
.
Vector
();
public
Enumeration
getApplets
()
{
Vector
applets
=
new
Vector
();
applets
.
addElement
(
target
);
return
applets
.
elements
();
}
...
...
@@ -573,7 +583,7 @@ class BeansAppletContext implements AppletContext {
return
null
;
}
public
java
.
util
.
Iterator
getStreamKeys
(){
public
Iterator
getStreamKeys
(){
// We do nothing.
return
null
;
}
...
...
jdk/test/java/beans/Beans/6669869/TestDesignTime.java
0 → 100644
浏览文件 @
8b97d3b4
/*
* Copyright 2009 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
* @bug 6669869
* @summary Tests DesignTime property in different application contexts
* @author Sergey Malenkov
*/
import
java.beans.Beans
;
import
sun.awt.SunToolkit
;
public
class
TestDesignTime
implements
Runnable
{
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
if
(
Beans
.
isDesignTime
())
{
throw
new
Error
(
"unexpected DesignTime property"
);
}
Beans
.
setDesignTime
(!
Beans
.
isDesignTime
());
ThreadGroup
group
=
new
ThreadGroup
(
"$$$"
);
Thread
thread
=
new
Thread
(
group
,
new
TestDesignTime
());
thread
.
start
();
thread
.
join
();
}
public
void
run
()
{
SunToolkit
.
createNewAppContext
();
if
(
Beans
.
isDesignTime
())
{
throw
new
Error
(
"shared DesignTime property"
);
}
}
}
jdk/test/java/beans/Beans/6669869/TestGuiAvailable.java
0 → 100644
浏览文件 @
8b97d3b4
/*
* Copyright 2009 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
* @bug 6669869
* @summary Tests GuiAvailable property in different application contexts
* @author Sergey Malenkov
*/
import
java.awt.GraphicsEnvironment
;
import
java.beans.Beans
;
import
sun.awt.SunToolkit
;
public
class
TestGuiAvailable
implements
Runnable
{
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
if
(
Beans
.
isGuiAvailable
()
==
GraphicsEnvironment
.
isHeadless
())
{
throw
new
Error
(
"unexpected GuiAvailable property"
);
}
Beans
.
setGuiAvailable
(!
Beans
.
isGuiAvailable
());
ThreadGroup
group
=
new
ThreadGroup
(
"$$$"
);
Thread
thread
=
new
Thread
(
group
,
new
TestGuiAvailable
());
thread
.
start
();
thread
.
join
();
}
public
void
run
()
{
SunToolkit
.
createNewAppContext
();
if
(
Beans
.
isGuiAvailable
()
==
GraphicsEnvironment
.
isHeadless
())
{
throw
new
Error
(
"shared GuiAvailable property"
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录