80 }
81
82 /**
83 * <p>
84 * Instantiate a JavaBean.
85 * </p>
86 * @return a JavaBean
87 *
88 * @param cls the class-loader from which we should create
89 * the bean. If this is null, then the system
90 * class-loader is used.
91 * @param beanName the name of the bean within the class-loader.
92 * For example "sun.beanbox.foobah"
93 * @param beanContext The BeanContext in which to nest the new bean
94 *
95 * @exception ClassNotFoundException if the class of a serialized
96 * object could not be found.
97 * @exception IOException if an I/O error occurs.
98 * @since 1.2
99 */
100
101 public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext) throws IOException, ClassNotFoundException {
102 return Beans.instantiate(cls, beanName, beanContext, null);
103 }
104
105 /**
106 * Instantiate a bean.
107 * <p>
108 * The bean is created based on a name relative to a class-loader.
109 * This name should be a dot-separated name such as "a.b.c".
110 * <p>
111 * In Beans 1.0 the given name can indicate either a serialized object
112 * or a class. Other mechanisms may be added in the future. In
113 * beans 1.0 we first try to treat the beanName as a serialized object
114 * name then as a class name.
115 * <p>
116 * When using the beanName as a serialized object name we convert the
117 * given beanName to a resource pathname and add a trailing ".ser" suffix.
118 * We then try to load a serialized object from that resource.
119 * <p>
120 * For example, given a beanName of "x.y", Beans.instantiate would first
121 * try to read a serialized object from the resource "x/y.ser" and if
136 * different environment than applets running inside browsers. In
137 * particular, bean applets have no access to "parameters", so they may
138 * wish to provide property get/set methods to set parameter values. We
139 * advise bean-applet developers to test their bean-applets against both
140 * the JDK appletviewer (for a reference browser environment) and the
141 * BDK BeanBox (for a reference bean container).
142 *
143 * @return a JavaBean
144 * @param cls the class-loader from which we should create
145 * the bean. If this is null, then the system
146 * class-loader is used.
147 * @param beanName the name of the bean within the class-loader.
148 * For example "sun.beanbox.foobah"
149 * @param beanContext The BeanContext in which to nest the new bean
150 * @param initializer The AppletInitializer for the new bean
151 *
152 * @exception ClassNotFoundException if the class of a serialized
153 * object could not be found.
154 * @exception IOException if an I/O error occurs.
155 * @since 1.2
156 */
157 @SuppressWarnings("deprecation")
158 public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext, AppletInitializer initializer)
159 throws IOException, ClassNotFoundException {
160
161 InputStream ins;
162 ObjectInputStream oins = null;
163 Object result = null;
164 boolean serialized = false;
165 IOException serex = null;
166
167 // If the given classloader is null, we check if an
168 // system classloader is available and (if so)
169 // use that instead.
170 // Note that calls on the system class loader will
171 // look in the bootstrap class loader first.
172 if (cls == null) {
173 try {
174 cls = ClassLoader.getSystemClassLoader();
175 } catch (SecurityException ex) {
176 // We're not allowed to access the system class loader.
177 // Drop through.
178 }
484 }
485 this.loader = loader;
486 }
487
488 /**
489 * Use the given ClassLoader rather than using the system class
490 */
491 @SuppressWarnings("rawtypes")
492 protected Class resolveClass(ObjectStreamClass classDesc)
493 throws IOException, ClassNotFoundException {
494
495 String cname = classDesc.getName();
496 return ClassFinder.resolveClass(cname, this.loader);
497 }
498 }
499
500 /**
501 * Package private support class. This provides a default AppletContext
502 * for beans which are applets.
503 */
504 @SuppressWarnings("deprecation")
505 class BeansAppletContext implements AppletContext {
506 Applet target;
507 Hashtable<URL,Object> imageCache = new Hashtable<>();
508
509 BeansAppletContext(Applet target) {
510 this.target = target;
511 }
512
513 public AudioClip getAudioClip(URL url) {
514 // We don't currently support audio clips in the Beans.instantiate
515 // applet context, unless by some luck there exists a URL content
516 // class that can generate an AudioClip from the audio URL.
517 try {
518 return (AudioClip) url.getContent();
519 } catch (Exception ex) {
520 return null;
521 }
522 }
523
524 public synchronized Image getImage(URL url) {
569
570 public void setStream(String key, InputStream stream)throws IOException{
571 // We do nothing.
572 }
573
574 public InputStream getStream(String key){
575 // We do nothing.
576 return null;
577 }
578
579 public Iterator<String> getStreamKeys(){
580 // We do nothing.
581 return null;
582 }
583 }
584
585 /**
586 * Package private support class. This provides an AppletStub
587 * for beans which are applets.
588 */
589 @SuppressWarnings("deprecation")
590 class BeansAppletStub implements AppletStub {
591 transient boolean active;
592 transient Applet target;
593 transient AppletContext context;
594 transient URL codeBase;
595 transient URL docBase;
596
597 BeansAppletStub(Applet target,
598 AppletContext context, URL codeBase,
599 URL docBase) {
600 this.target = target;
601 this.context = context;
602 this.codeBase = codeBase;
603 this.docBase = docBase;
604 }
605
606 public boolean isActive() {
607 return active;
608 }
609
|
80 }
81
82 /**
83 * <p>
84 * Instantiate a JavaBean.
85 * </p>
86 * @return a JavaBean
87 *
88 * @param cls the class-loader from which we should create
89 * the bean. If this is null, then the system
90 * class-loader is used.
91 * @param beanName the name of the bean within the class-loader.
92 * For example "sun.beanbox.foobah"
93 * @param beanContext The BeanContext in which to nest the new bean
94 *
95 * @exception ClassNotFoundException if the class of a serialized
96 * object could not be found.
97 * @exception IOException if an I/O error occurs.
98 * @since 1.2
99 */
100 @SuppressWarnings("deprecation")
101 public static Object instantiate(ClassLoader cls, String beanName,
102 BeanContext beanContext)
103 throws IOException, ClassNotFoundException {
104 return Beans.instantiate(cls, beanName, beanContext, null);
105 }
106
107 /**
108 * Instantiate a bean.
109 * <p>
110 * The bean is created based on a name relative to a class-loader.
111 * This name should be a dot-separated name such as "a.b.c".
112 * <p>
113 * In Beans 1.0 the given name can indicate either a serialized object
114 * or a class. Other mechanisms may be added in the future. In
115 * beans 1.0 we first try to treat the beanName as a serialized object
116 * name then as a class name.
117 * <p>
118 * When using the beanName as a serialized object name we convert the
119 * given beanName to a resource pathname and add a trailing ".ser" suffix.
120 * We then try to load a serialized object from that resource.
121 * <p>
122 * For example, given a beanName of "x.y", Beans.instantiate would first
123 * try to read a serialized object from the resource "x/y.ser" and if
138 * different environment than applets running inside browsers. In
139 * particular, bean applets have no access to "parameters", so they may
140 * wish to provide property get/set methods to set parameter values. We
141 * advise bean-applet developers to test their bean-applets against both
142 * the JDK appletviewer (for a reference browser environment) and the
143 * BDK BeanBox (for a reference bean container).
144 *
145 * @return a JavaBean
146 * @param cls the class-loader from which we should create
147 * the bean. If this is null, then the system
148 * class-loader is used.
149 * @param beanName the name of the bean within the class-loader.
150 * For example "sun.beanbox.foobah"
151 * @param beanContext The BeanContext in which to nest the new bean
152 * @param initializer The AppletInitializer for the new bean
153 *
154 * @exception ClassNotFoundException if the class of a serialized
155 * object could not be found.
156 * @exception IOException if an I/O error occurs.
157 * @since 1.2
158 *
159 * @deprecated It s recommended to use
160 * {@link #instantiate(ClassLoader, String, BeanContext)}, because the
161 * Applet API is deprecated. See the
162 * <a href="../../java/applet/package-summary.html"> java.applet package
163 * documentation</a> for further information.
164 */
165 @Deprecated(since = "9")
166 public static Object instantiate(ClassLoader cls, String beanName,
167 BeanContext beanContext,
168 AppletInitializer initializer)
169 throws IOException, ClassNotFoundException {
170
171 InputStream ins;
172 ObjectInputStream oins = null;
173 Object result = null;
174 boolean serialized = false;
175 IOException serex = null;
176
177 // If the given classloader is null, we check if an
178 // system classloader is available and (if so)
179 // use that instead.
180 // Note that calls on the system class loader will
181 // look in the bootstrap class loader first.
182 if (cls == null) {
183 try {
184 cls = ClassLoader.getSystemClassLoader();
185 } catch (SecurityException ex) {
186 // We're not allowed to access the system class loader.
187 // Drop through.
188 }
494 }
495 this.loader = loader;
496 }
497
498 /**
499 * Use the given ClassLoader rather than using the system class
500 */
501 @SuppressWarnings("rawtypes")
502 protected Class resolveClass(ObjectStreamClass classDesc)
503 throws IOException, ClassNotFoundException {
504
505 String cname = classDesc.getName();
506 return ClassFinder.resolveClass(cname, this.loader);
507 }
508 }
509
510 /**
511 * Package private support class. This provides a default AppletContext
512 * for beans which are applets.
513 */
514 @Deprecated(since = "9")
515 class BeansAppletContext implements AppletContext {
516 Applet target;
517 Hashtable<URL,Object> imageCache = new Hashtable<>();
518
519 BeansAppletContext(Applet target) {
520 this.target = target;
521 }
522
523 public AudioClip getAudioClip(URL url) {
524 // We don't currently support audio clips in the Beans.instantiate
525 // applet context, unless by some luck there exists a URL content
526 // class that can generate an AudioClip from the audio URL.
527 try {
528 return (AudioClip) url.getContent();
529 } catch (Exception ex) {
530 return null;
531 }
532 }
533
534 public synchronized Image getImage(URL url) {
579
580 public void setStream(String key, InputStream stream)throws IOException{
581 // We do nothing.
582 }
583
584 public InputStream getStream(String key){
585 // We do nothing.
586 return null;
587 }
588
589 public Iterator<String> getStreamKeys(){
590 // We do nothing.
591 return null;
592 }
593 }
594
595 /**
596 * Package private support class. This provides an AppletStub
597 * for beans which are applets.
598 */
599 @Deprecated(since = "9")
600 class BeansAppletStub implements AppletStub {
601 transient boolean active;
602 transient Applet target;
603 transient AppletContext context;
604 transient URL codeBase;
605 transient URL docBase;
606
607 BeansAppletStub(Applet target,
608 AppletContext context, URL codeBase,
609 URL docBase) {
610 this.target = target;
611 this.context = context;
612 this.codeBase = codeBase;
613 this.docBase = docBase;
614 }
615
616 public boolean isActive() {
617 return active;
618 }
619
|