开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (2)
main
gh-pages
main
分支 (2)
main
gh-pages
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (2)
main
gh-pages
Beans.java 20.90 KB
一键复制 编辑 原始数据 按行查看 历史
cxylk 提交于 2021年01月21日 16:33 +08:00 . :rainbow: idea构建jdk源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
/*
* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package java.beans;
import com.sun.beans.finder.ClassFinder;
import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.applet.AudioClip;
import java.awt.Image;
import java.beans.beancontext.BeanContext;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import java.io.StreamCorruptedException;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
/**
* This class provides some general purpose beans control methods.
*/
public class Beans {
/**
* <p>
* Instantiate a JavaBean.
* </p>
* @return a JavaBean
* @param cls the class-loader from which we should create
* the bean. If this is null, then the system
* class-loader is used.
* @param beanName the name of the bean within the class-loader.
* For example "sun.beanbox.foobah"
*
* @exception ClassNotFoundException if the class of a serialized
* object could not be found.
* @exception IOException if an I/O error occurs.
*/
public static Object instantiate(ClassLoader cls, String beanName) throws IOException, ClassNotFoundException {
return Beans.instantiate(cls, beanName, null, null);
}
/**
* <p>
* Instantiate a JavaBean.
* </p>
* @return a JavaBean
*
* @param cls the class-loader from which we should create
* the bean. If this is null, then the system
* class-loader is used.
* @param beanName the name of the bean within the class-loader.
* For example "sun.beanbox.foobah"
* @param beanContext The BeanContext in which to nest the new bean
*
* @exception ClassNotFoundException if the class of a serialized
* object could not be found.
* @exception IOException if an I/O error occurs.
*/
public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext) throws IOException, ClassNotFoundException {
return Beans.instantiate(cls, beanName, beanContext, null);
}
/**
* Instantiate a bean.
* <p>
* The bean is created based on a name relative to a class-loader.
* This name should be a dot-separated name such as "a.b.c".
* <p>
* In Beans 1.0 the given name can indicate either a serialized object
* or a class. Other mechanisms may be added in the future. In
* beans 1.0 we first try to treat the beanName as a serialized object
* name then as a class name.
* <p>
* When using the beanName as a serialized object name we convert the
* given beanName to a resource pathname and add a trailing ".ser" suffix.
* We then try to load a serialized object from that resource.
* <p>
* For example, given a beanName of "x.y", Beans.instantiate would first
* try to read a serialized object from the resource "x/y.ser" and if
* that failed it would try to load the class "x.y" and create an
* instance of that class.
* <p>
* If the bean is a subtype of java.applet.Applet, then it is given
* some special initialization. First, it is supplied with a default
* AppletStub and AppletContext. Second, if it was instantiated from
* a classname the applet's "init" method is called. (If the bean was
* deserialized this step is skipped.)
* <p>
* Note that for beans which are applets, it is the caller's responsiblity
* to call "start" on the applet. For correct behaviour, this should be done
* after the applet has been added into a visible AWT container.
* <p>
* Note that applets created via beans.instantiate run in a slightly
* different environment than applets running inside browsers. In
* particular, bean applets have no access to "parameters", so they may
* wish to provide property get/set methods to set parameter values. We
* advise bean-applet developers to test their bean-applets against both
* the JDK appletviewer (for a reference browser environment) and the
* BDK BeanBox (for a reference bean container).
*
* @return a JavaBean
* @param cls the class-loader from which we should create
* the bean. If this is null, then the system
* class-loader is used.
* @param beanName the name of the bean within the class-loader.
* For example "sun.beanbox.foobah"
* @param beanContext The BeanContext in which to nest the new bean
* @param initializer The AppletInitializer for the new bean
*
* @exception ClassNotFoundException if the class of a serialized
* object could not be found.
* @exception IOException if an I/O error occurs.
*/
public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext, AppletInitializer initializer)
throws IOException, ClassNotFoundException {
InputStream ins;
ObjectInputStream oins = null;
Object result = null;
boolean serialized = false;
IOException serex = null;
// If the given classloader is null, we check if an
// system classloader is available and (if so)
// use that instead.
// Note that calls on the system class loader will
// look in the bootstrap class loader first.
if (cls == null) {
try {
cls = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {
// We're not allowed to access the system class loader.
// Drop through.
}
}
// Try to find a serialized object with this name
final String serName = beanName.replace('.','/').concat(".ser");
if (cls == null)
ins = ClassLoader.getSystemResourceAsStream(serName);
else
ins = cls.getResourceAsStream(serName);
if (ins != null) {
try {
if (cls == null) {
oins = new ObjectInputStream(ins);
} else {
oins = new ObjectInputStreamWithLoader(ins, cls);
}
result = oins.readObject();
serialized = true;
oins.close();
} 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.
serex = ex;
} catch (ClassNotFoundException ex) {
ins.close();
throw ex;
}
}
if (result == null) {
// No serialized object, try just instantiating the class
Class<?> cl;
try {
cl = ClassFinder.findClass(beanName, cls);
} catch (ClassNotFoundException ex) {
// There is no appropriate class. If we earlier tried to
// deserialize an object and got an IO exception, throw that,
// otherwise rethrow the ClassNotFoundException.
if (serex != null) {
throw serex;
}
throw ex;
}
if (!Modifier.isPublic(cl.getModifiers())) {
throw new ClassNotFoundException("" + cl + " : no public access");
}
/*
* Try to instantiate the class.
*/
try {
result = cl.newInstance();
} catch (Exception ex) {
// We have to remap the exception to one in our signature.
// But we pass extra information in the detail message.
throw new ClassNotFoundException("" + cl + " : " + ex, ex);
}
}
if (result != null) {
// Ok, if the result is an applet initialize it.
AppletStub stub = null;
if (result instanceof Applet) {
Applet applet = (Applet) result;
boolean needDummies = initializer == null;
if (needDummies) {
// Figure our the codebase and docbase URLs. We do this
// by locating the URL for a known resource, and then
// massaging the URL.
// First find the "resource name" corresponding to the bean
// itself. So a serialzied bean "a.b.c" would imply a
// resource name of "a/b/c.ser" and a classname of "x.y"
// would imply a resource name of "x/y.class".
final String resourceName;
if (serialized) {
// Serialized bean
resourceName = beanName.replace('.','/').concat(".ser");
} else {
// Regular class
resourceName = beanName.replace('.','/').concat(".class");
}
URL objectUrl = null;
URL codeBase = null;
URL docBase = null;
// Now get the URL correponding to the resource name.
if (cls == null) {
objectUrl = ClassLoader.getSystemResource(resourceName);
} else
objectUrl = cls.getResource(resourceName);
// If we found a URL, we try to locate the docbase by taking
// of the final path name component, and the code base by taking
// of the complete resourceName.
// So if we had a resourceName of "a/b/c.class" and we got an
// objectURL of "file://bert/classes/a/b/c.class" then we would
// want to set the codebase to "file://bert/classes/" and the
// docbase to "file://bert/classes/a/b/"
if (objectUrl != null) {
String s = objectUrl.toExternalForm();
if (s.endsWith(resourceName)) {
int ix = s.length() - resourceName.length();
codeBase = new URL(s.substring(0,ix));
docBase = codeBase;
ix = s.lastIndexOf('/');
if (ix >= 0) {
docBase = new URL(s.substring(0,ix+1));
}
}
}
// Setup a default context and stub.
BeansAppletContext context = new BeansAppletContext(applet);
stub = (AppletStub)new BeansAppletStub(applet, context, codeBase, docBase);
applet.setStub(stub);
} else {
initializer.initialize(applet, beanContext);
}
// now, if there is a BeanContext, add the bean, if applicable.
if (beanContext != null) {
unsafeBeanContextAdd(beanContext, result);
}
// If it was deserialized then it was already init-ed.
// Otherwise we need to initialize it.
if (!serialized) {
// We need to set a reasonable initial size, as many
// applets are unhappy if they are started without
// having been explicitly sized.
applet.setSize(100,100);
applet.init();
}
if (needDummies) {
((BeansAppletStub)stub).active = true;
} else initializer.activate(applet);
} else if (beanContext != null) unsafeBeanContextAdd(beanContext, result);
}
return result;
}
@SuppressWarnings("unchecked")
private static void unsafeBeanContextAdd(BeanContext beanContext, Object res) {
beanContext.add(res);
}
/**
* From a given bean, obtain an object representing a specified
* type view of that source object.
* <p>
* The result may be the same object or a different object. If
* the requested target view isn't available then the given
* bean is returned.
* <p>
* This method is provided in Beans 1.0 as a hook to allow the
* addition of more flexible bean behaviour in the future.
*
* @return an object representing a specified type view of the
* source object
* @param bean Object from which we want to obtain a view.
* @param targetType The type of view we'd like to get.
*
*/
public static Object getInstanceOf(Object bean, Class<?> targetType) {
return bean;
}
/**
* Check if a bean can be viewed as a given target type.
* The result will be true if the Beans.getInstanceof method
* can be used on the given bean to obtain an object that
* represents the specified targetType type view.
*
* @param bean Bean from which we want to obtain a view.
* @param targetType The type of view we'd like to get.
* @return "true" if the given bean supports the given targetType.
*
*/
public static boolean isInstanceOf(Object bean, Class<?> targetType) {
return Introspector.isSubclass(bean.getClass(), targetType);
}
/**
* Test if we are in design-mode.
*
* @return True if we are running in an application construction
* environment.
*
* @see DesignMode
*/
public static boolean isDesignTime() {
return ThreadGroupContext.getContext().isDesignTime();
}
/**
* Determines whether beans can assume a GUI is available.
*
* @return True if we are running in an environment where beans
* can assume that an interactive GUI is available, so they
* can pop up dialog boxes, etc. This will normally return
* true in a windowing environment, and will normally return
* false in a server environment or if an application is
* running as part of a batch job.
*
* @see Visibility
*
*/
public static boolean isGuiAvailable() {
return ThreadGroupContext.getContext().isGuiAvailable();
}
/**
* Used to indicate whether of not we are running in an application
* builder environment.
*
* <p>Note that this method is security checked
* and is not available to (for example) untrusted applets.
* More specifically, if there is a security manager,
* its <code>checkPropertiesAccess</code>
* method is called. This could result in a SecurityException.
*
* @param isDesignTime True if we're in an application builder tool.
* @exception SecurityException if a security manager exists and its
* <code>checkPropertiesAccess</code> method doesn't allow setting
* of system properties.
* @see SecurityManager#checkPropertiesAccess
*/
public static void setDesignTime(boolean isDesignTime)
throws SecurityException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPropertiesAccess();
}
ThreadGroupContext.getContext().setDesignTime(isDesignTime);
}
/**
* Used to indicate whether of not we are running in an environment
* where GUI interaction is available.
*
* <p>Note that this method is security checked
* and is not available to (for example) untrusted applets.
* More specifically, if there is a security manager,
* its <code>checkPropertiesAccess</code>
* method is called. This could result in a SecurityException.
*
* @param isGuiAvailable True if GUI interaction is available.
* @exception SecurityException if a security manager exists and its
* <code>checkPropertiesAccess</code> method doesn't allow setting
* of system properties.
* @see SecurityManager#checkPropertiesAccess
*/
public static void setGuiAvailable(boolean isGuiAvailable)
throws SecurityException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPropertiesAccess();
}
ThreadGroupContext.getContext().setGuiAvailable(isGuiAvailable);
}
}
/**
* This subclass of ObjectInputStream delegates loading of classes to
* an existing ClassLoader.
*/
class ObjectInputStreamWithLoader extends ObjectInputStream
{
private ClassLoader loader;
/**
* Loader must be non-null;
*/
public ObjectInputStreamWithLoader(InputStream in, ClassLoader loader)
throws IOException, StreamCorruptedException {
super(in);
if (loader == null) {
throw new IllegalArgumentException("Illegal null argument to ObjectInputStreamWithLoader");
}
this.loader = loader;
}
/**
* Use the given ClassLoader rather than using the system class
*/
@SuppressWarnings("rawtypes")
protected Class resolveClass(ObjectStreamClass classDesc)
throws IOException, ClassNotFoundException {
String cname = classDesc.getName();
return ClassFinder.resolveClass(cname, this.loader);
}
}
/**
* Package private support class. This provides a default AppletContext
* for beans which are applets.
*/
class BeansAppletContext implements AppletContext {
Applet target;
Hashtable<URL,Object> imageCache = new Hashtable<>();
BeansAppletContext(Applet target) {
this.target = target;
}
public AudioClip getAudioClip(URL url) {
// We don't currently support audio clips in the Beans.instantiate
// applet context, unless by some luck there exists a URL content
// class that can generate an AudioClip from the audio URL.
try {
return (AudioClip) url.getContent();
} catch (Exception ex) {
return null;
}
}
public synchronized Image getImage(URL url) {
Object o = imageCache.get(url);
if (o != null) {
return (Image)o;
}
try {
o = url.getContent();
if (o == null) {
return null;
}
if (o instanceof Image) {
imageCache.put(url, o);
return (Image) o;
}
// Otherwise it must be an ImageProducer.
Image img = target.createImage((java.awt.image.ImageProducer)o);
imageCache.put(url, img);
return img;
} catch (Exception ex) {
return null;
}
}
public Applet getApplet(String name) {
return null;
}
public Enumeration<Applet> getApplets() {
Vector<Applet> applets = new Vector<>();
applets.addElement(target);
return applets.elements();
}
public void showDocument(URL url) {
// We do nothing.
}
public void showDocument(URL url, String target) {
// We do nothing.
}
public void showStatus(String status) {
// We do nothing.
}
public void setStream(String key, InputStream stream)throws IOException{
// We do nothing.
}
public InputStream getStream(String key){
// We do nothing.
return null;
}
public Iterator<String> getStreamKeys(){
// We do nothing.
return null;
}
}
/**
* Package private support class. This provides an AppletStub
* for beans which are applets.
*/
class BeansAppletStub implements AppletStub {
transient boolean active;
transient Applet target;
transient AppletContext context;
transient URL codeBase;
transient URL docBase;
BeansAppletStub(Applet target,
AppletContext context, URL codeBase,
URL docBase) {
this.target = target;
this.context = context;
this.codeBase = codeBase;
this.docBase = docBase;
}
public boolean isActive() {
return active;
}
public URL getDocumentBase() {
// use the root directory of the applet's class-loader
return docBase;
}
public URL getCodeBase() {
// use the directory where we found the class or serialized object.
return codeBase;
}
public String getParameter(String name) {
return null;
}
public AppletContext getAppletContext() {
return context;
}
public void appletResize(int width, int height) {
// we do nothing.
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

Java学习过程中遇到的知识点总结,复习笔记
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cxylk/Java-Notes.git
git@gitee.com:cxylk/Java-Notes.git
cxylk
Java-Notes
Java-Notes
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /