diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletAdaptor.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletAdaptor.java new file mode 100644 index 00000000000..bafb3f242a9 --- /dev/null +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletAdaptor.java @@ -0,0 +1,46 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are + * Copyright (C) 1999 Sun Microsystems, Inc. All + * Rights Reserved. + * + * Contributor(s): + */ +package org.mozilla.pluglet; + +import org.mozilla.pluglet.mozilla.*; +import java.awt.Frame; +import java.awt.print.PrinterJob; + + +public class PlugletAdaptor implements Pluglet { + public void initialize(PlugletPeer peer) { + } + public void start() { + } + public void stop() { + } + public void destroy() { + } + public PlugletStreamListener newStream() { + return null; + } + public void setWindow(Frame frame) { + return; + } + public void print(PrinterJob printerJob) { + return; + } +} diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletFactoryAdaptor.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletFactoryAdaptor.java new file mode 100644 index 00000000000..3962920e578 --- /dev/null +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletFactoryAdaptor.java @@ -0,0 +1,33 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are + * Copyright (C) 1999 Sun Microsystems, Inc. All + * Rights Reserved. + * + * Contributor(s): + */ +package org.mozilla.pluglet; + +import org.mozilla.pluglet.mozilla.*; + +public class PlugletFactoryAdaptor implements PlugletFactory { + public Pluglet createPluglet(String mimeType) { + return null; + } + public void initialize(PlugletManager manager) { + } + public void shutdown() { + } +} diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletFactoryGeneric.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletFactoryGeneric.java new file mode 100644 index 00000000000..f8b64b7c74e --- /dev/null +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletFactoryGeneric.java @@ -0,0 +1,44 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are + * Copyright (C) 1999 Sun Microsystems, Inc. All + * Rights Reserved. + * + * Contributor(s): + */ +package org.mozilla.pluglet; + +class PlugletFactoryGeneric extends PlugletFactoryAdaptor { + Class plugletClass; + public PlugletFactoryGeneric(Class _plugletClass) { + plugletClass = _plugletClass; + } + public Pluglet createPluglet(String mimeType) { + Pluglet res = null; + Object o = null; + try { + o = plugletClass.newInstance(); + } catch (InstantiationException e) { + } catch (IllegalAccessException e) { + } + + if (o instanceof Pluglet) { + res = (Pluglet)o; + } + return res; + } +} + + diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletLoader.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletLoader.java index ec58d04687a..b3ff9d48eea 100644 --- a/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletLoader.java +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletLoader.java @@ -36,7 +36,6 @@ public class PlugletLoader { Dimension screenSize = new Button().getToolkit().getScreenSize(); } - // path to jar file. Name of main class sould to be in MANIFEST. public static PlugletFactory getPluglet(String path) { try { @@ -75,13 +74,24 @@ public class PlugletLoader { PermissionCollection collection = perm.newPermissionCollection(); collection.add(perm); policy.grantPermission(codesource,collection); - Object pluglet = loader.loadClass(plugletClassName).newInstance(); - if (pluglet instanceof PlugletFactory) { + Class clazz = loader.loadClass(plugletClassName); + if (plugletClass == null) { + plugletClass = Class.forName("org.mozilla.pluglet.Pluglet"); + plugletFactoryClass = Class.forName("org.mozilla.pluglet.PlugletFactory"); + } + if (isSubclassOf(clazz, plugletFactoryClass)) { org.mozilla.util.DebugPluglet.print("-- ok we have a PlugletFactory"+"\n"); - return (PlugletFactory) pluglet; + return (PlugletFactory)clazz.newInstance(); } else { - org.mozilla.util.DebugPluglet.print("-- oups we do not have a PlugletFactory"+"\n"); - return null; + org.mozilla.util.DebugPluglet.print("-- we do not have a PlugletFactory. Maybe it is Pluglet"+"\n"); + if (isSubclassOf(clazz,plugletClass)) { + org.mozilla.util.DebugPluglet.print("-- it is Pluglet. Creating Generic Factory"+"\n"); + return new PlugletFactoryGeneric(clazz); + } else { + org.mozilla.util.DebugPluglet.print("-- That is nor Pluglet nor PlugletFactory\n"); + return null; + } + } } catch (Exception e) { org.mozilla.util.DebugPluglet.print("-- PlugletLoader.getPluglet exc "+e); @@ -106,7 +116,36 @@ public class PlugletLoader { return null; } } + + private static boolean isSubclassOf(Class a, Class b) { + if (a == null + || b == null) { + return false; + } + Class[] interfaces = a.getInterfaces(); + //org.mozilla.util.DebugPluglet.print("-- PlugletLoader.isSubclassOf "+interfaces.length+" "+a+" "+b+"\n"); + boolean res = false; + if (isSubclassOf(a.getSuperclass(),b)) { + res = true; + } else { + for (int i = 0; i < interfaces.length; i++) { + //org.mozilla.util.DebugPluglet.print("-- PlugletLoader.isSubclassOf "+interfaces[i]+"\n"); + if (b.equals(interfaces[i])) { + res = true; + break; + } else if (isSubclassOf(interfaces[i],b)) { + res = true; + break; + } + } + } + return res; + } private static PlugletPolicy policy = null; + private static Class plugletClass = null; + private static Class plugletFactoryClass = null; + } + diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletStreamListenerAdaptor.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletStreamListenerAdaptor.java new file mode 100644 index 00000000000..dd3f0e3a85e --- /dev/null +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/PlugletStreamListenerAdaptor.java @@ -0,0 +1,43 @@ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are + * Copyright (C) 1999 Sun Microsystems, Inc. All + * Rights Reserved. + * + * Contributor(s): + */ +package org.mozilla.pluglet; + +import java.io.InputStream; +import org.mozilla.pluglet.mozilla.*; + +public class PlugletStreamListenerAdaptor implements PlugletStreamListener { + public void onStartBinding(PlugletStreamInfo streamInfo) { + } + public void onDataAvailable(PlugletStreamInfo streamInfo, InputStream input,int length) { + } + public void onFileAvailable(PlugletStreamInfo streamInfo, String fileName) { + } + public void onStopBinding(PlugletStreamInfo streamInfo,int status) { + } + public int getStreamType() { + return PlugletStreamListener.STREAM_TYPE_NORMAL; + } +} + + + + +