зеркало из https://github.com/mozilla/gecko-dev.git
Added Adaptor classes and Generic factory. Now we do not need to implement
PlugletFactory for simple pluglets.
This commit is contained in:
Родитель
d4e4f10d14
Коммит
988e4302ee
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче