// 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 (ins) { if (cls == null) {
oins = new ObjectInputStream(ins);
} else {
oins = new ObjectInputStreamWithLoader(ins, cls);
}
result = oins.readObject();
serialized = true;
oins.close();
} catch (IOException ex) { // Drop through and try opening the class. But remember // the exception in case we can't find the class either.
serex = 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())) { thrownew ClassNotFoundException("" + cl + " : no public access");
}
/* *Trytoinstantiatetheclass.
*/
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. thrownew ClassNotFoundException("" + cl + " : " + ex, ex);
}
}
// 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");
}
// Now get the URL corresponding 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 = newURL(s.substring(0,ix));
docBase = codeBase;
// 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);
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) { returnnull;
}
}
publicsynchronized Image getImage(URL url) {
Object o = imageCache.get(url); if (o != null) { return (Image)o;
} try {
o = url.getContent(); if (o == null) { returnnull;
} 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) { returnnull;
}
}
public Applet getApplet(String name) { returnnull;
}
public Enumeration<Applet> getApplets() {
Vector<Applet> applets = new Vector<>();
applets.addElement(target); return applets.elements();
}
publicvoid showDocument(URL url) { // We do nothing.
}
publicvoid showDocument(URL url, String target) { // We do nothing.
}
publicvoid showStatus(String status) { // We do nothing.
}
publicvoid setStream(String key, InputStream stream)throws IOException{ // We do nothing.
}
public InputStream getStream(String key){ // We do nothing. returnnull;
}
public Iterator<String> getStreamKeys(){ // We do nothing. returnnull;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.