Removed remote image capability (image manipulatino via RMI)
This commit is contained in:
parent
47debc3784
commit
c0417d5a6a
7 changed files with 48 additions and 317 deletions
|
@ -1,24 +0,0 @@
|
||||||
// IRemoteGenerator.java
|
|
||||||
// Copyright (c) Hannes Wallnöfer 1999-2000
|
|
||||||
|
|
||||||
package helma.image;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.rmi.*;
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RMI interface for accessing remote image generators.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public interface IRemoteGenerator extends Remote {
|
|
||||||
|
|
||||||
public IRemoteImage createPaintableImage (int w, int h) throws RemoteException;
|
|
||||||
|
|
||||||
public IRemoteImage createPaintableImage (byte src[]) throws RemoteException;
|
|
||||||
|
|
||||||
public IRemoteImage createPaintableImage (String urlstring) throws RemoteException;
|
|
||||||
|
|
||||||
public IRemoteImage createImage (byte src[]) throws RemoteException;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
// ActivatedImageWrapper.java
|
|
||||||
// Copyright (c) Hannes Wallnöfer 1999-2000
|
|
||||||
|
|
||||||
package helma.image;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.rmi.*;
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RMI interface for accessing images on remote image servers.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public interface IRemoteImage extends Remote {
|
|
||||||
|
|
||||||
public void setFont (String name, int style, int size) throws RemoteException;
|
|
||||||
public void setColor (int color) throws RemoteException;
|
|
||||||
public void setColor (int r, int g, int b) throws RemoteException;
|
|
||||||
|
|
||||||
public void reduceColors (int colors) throws RemoteException;
|
|
||||||
|
|
||||||
public void drawString (String str, int x, int y) throws RemoteException;
|
|
||||||
public void drawRect (int x, int y, int w, int h) throws RemoteException;
|
|
||||||
public void drawLine (int x1, int y1, int x2, int y2) throws RemoteException;
|
|
||||||
public void fillRect (int x, int y, int w, int h) throws RemoteException;
|
|
||||||
|
|
||||||
public int getWidth () throws RemoteException;
|
|
||||||
public int getHeight () throws RemoteException;
|
|
||||||
public void crop (int x, int y, int w, int h) throws RemoteException;
|
|
||||||
public void resize (int w, int h) throws RemoteException;
|
|
||||||
|
|
||||||
public void saveAs (String filename) throws RemoteException;
|
|
||||||
|
|
||||||
}
|
|
|
@ -29,8 +29,8 @@ public class ImageGenerator extends Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
this.setBounds (0, 0, 0, 0);
|
setBounds (0, 0, 0, 0);
|
||||||
this.setVisible (true);
|
setVisible (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageWrapper createPaintableImage (int w, int h) {
|
public ImageWrapper createPaintableImage (int w, int h) {
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
// RemoteImage.java
|
|
||||||
// Copyright (c) Hannes Wallnöfer 1999-2000
|
|
||||||
|
|
||||||
package helma.image;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.image.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.rmi.*;
|
|
||||||
import java.rmi.server.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of an image that is accessible via RMI.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class RemoteImage extends UnicastRemoteObject implements IRemoteImage {
|
|
||||||
|
|
||||||
ImageWrapper wrapped;
|
|
||||||
|
|
||||||
public RemoteImage (ImageWrapper wrapped) throws RemoteException {
|
|
||||||
this.wrapped = wrapped;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFont (String name, int style, int size) {
|
|
||||||
wrapped.setFont (name, style, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColor (int red, int green, int blue) {
|
|
||||||
wrapped.setColor (red, green, blue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColor (int color) {
|
|
||||||
wrapped.setColor (color);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawString (String str, int x, int y) {
|
|
||||||
wrapped.drawString (str, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawLine (int x1, int y1, int x2, int y2) {
|
|
||||||
wrapped.drawLine (x1, y1, x2, y2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawRect (int x, int y, int w, int h) {
|
|
||||||
wrapped.drawRect (x, y, w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawImage (String filename, int x, int y) {
|
|
||||||
wrapped.drawImage (filename, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fillRect (int x, int y, int w, int h) {
|
|
||||||
wrapped.fillRect (x, y, w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWidth () {
|
|
||||||
return wrapped.getWidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHeight () {
|
|
||||||
return wrapped.getHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void crop (int x, int y, int w, int h) {
|
|
||||||
wrapped.crop (x, y, w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void resize (int w, int h) {
|
|
||||||
wrapped.resize (w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reduceColors (int colors) {
|
|
||||||
wrapped.reduceColors (colors);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveAs (String filename) {
|
|
||||||
wrapped.saveAs (filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fillString (String str) {
|
|
||||||
wrapped.fillString (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fillString (String str, int x, int y, int w, int h) {
|
|
||||||
wrapped.fillString (str, x, y, w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,90 +0,0 @@
|
||||||
// Server.java
|
|
||||||
// Copyright (c) Hannes Wallnöfer 1999-2000
|
|
||||||
|
|
||||||
package helma.image;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.rmi.*;
|
|
||||||
import java.rmi.server.*;
|
|
||||||
import java.rmi.registry.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of RMI Image Generator. This accepts only connection from localhost.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class Server extends UnicastRemoteObject implements IRemoteGenerator {
|
|
||||||
|
|
||||||
static int port = 3033;
|
|
||||||
ImageGenerator imggen;
|
|
||||||
|
|
||||||
public static void main (String args[]) throws Exception {
|
|
||||||
new Server ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Server () throws Exception {
|
|
||||||
|
|
||||||
imggen = new ImageGenerator ();
|
|
||||||
|
|
||||||
// the following seems not to be necessary after all ...
|
|
||||||
// System.setSecurityManager(new RMISecurityManager());
|
|
||||||
|
|
||||||
System.out.println ("Starting server on port "+port);
|
|
||||||
LocateRegistry.createRegistry (port);
|
|
||||||
try {
|
|
||||||
Naming.bind ("//:"+port+"/server", this);
|
|
||||||
} catch (Exception x) {
|
|
||||||
System.out.println ("error binding remote objects: " + x);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public IRemoteImage createPaintableImage (int x, int y) throws RemoteException {
|
|
||||||
try {
|
|
||||||
String client = RemoteServer.getClientHost ();
|
|
||||||
if (!InetAddress.getLocalHost ().equals (InetAddress.getByName (client)))
|
|
||||||
throw new RemoteException ("Access Denied");
|
|
||||||
} catch (ServerNotActiveException ignore) {
|
|
||||||
} catch (UnknownHostException ignore) {}
|
|
||||||
return new RemoteImage (imggen.createPaintableImage (x, y));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IRemoteImage createPaintableImage (byte[] bytes) throws RemoteException {
|
|
||||||
try {
|
|
||||||
String client = RemoteServer.getClientHost ();
|
|
||||||
if (!InetAddress.getLocalHost ().equals (InetAddress.getByName (client)))
|
|
||||||
throw new RemoteException ("Access Denied");
|
|
||||||
} catch (ServerNotActiveException ignore) {
|
|
||||||
} catch (UnknownHostException ignore) {}
|
|
||||||
return new RemoteImage (imggen.createPaintableImage (bytes));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IRemoteImage createPaintableImage (String url) throws RemoteException {
|
|
||||||
try {
|
|
||||||
String client = RemoteServer.getClientHost ();
|
|
||||||
if (!InetAddress.getLocalHost ().equals (InetAddress.getByName (client)))
|
|
||||||
throw new RemoteException ("Access Denied");
|
|
||||||
} catch (ServerNotActiveException ignore) {
|
|
||||||
} catch (UnknownHostException ignore) {}
|
|
||||||
return new RemoteImage (imggen.createPaintableImage (url));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IRemoteImage createImage (byte[] bytes) throws RemoteException {
|
|
||||||
try {
|
|
||||||
String client = RemoteServer.getClientHost ();
|
|
||||||
if (!InetAddress.getLocalHost ().equals (InetAddress.getByName (client)))
|
|
||||||
throw new RemoteException ("Access Denied");
|
|
||||||
} catch (ServerNotActiveException ignore) {
|
|
||||||
} catch (UnknownHostException ignore) {}
|
|
||||||
return new RemoteImage (imggen.createImage (bytes));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class ImageExtension extends Extension {
|
||||||
|
|
||||||
protected Evaluator evaluator = null;
|
protected Evaluator evaluator = null;
|
||||||
|
|
||||||
static boolean remote = false;
|
static ImageGenerator imggen;
|
||||||
|
|
||||||
|
|
||||||
public ImageExtension () {
|
public ImageExtension () {
|
||||||
|
@ -37,7 +37,6 @@ public class ImageExtension extends Extension {
|
||||||
class GlobalObjectImage extends BuiltinFunctionObject {
|
class GlobalObjectImage extends BuiltinFunctionObject {
|
||||||
|
|
||||||
ImageExtension imagex;
|
ImageExtension imagex;
|
||||||
ImageGenerator imggen;
|
|
||||||
|
|
||||||
GlobalObjectImage (String name, Evaluator evaluator, FunctionPrototype fp, ImageExtension imagex) {
|
GlobalObjectImage (String name, Evaluator evaluator, FunctionPrototype fp, ImageExtension imagex) {
|
||||||
super(fp, evaluator, name, 1);
|
super(fp, evaluator, name, 1);
|
||||||
|
@ -50,33 +49,25 @@ public class ImageExtension extends Extension {
|
||||||
|
|
||||||
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
|
||||||
Object img = null;
|
Object img = null;
|
||||||
IRemoteGenerator rgen = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (imggen == null && !remote) {
|
if (imggen == null) {
|
||||||
try {
|
try {
|
||||||
imggen = new ImageGenerator ();
|
imggen = new ImageGenerator ();
|
||||||
} catch (UnsatisfiedLinkError noawt) {
|
} catch (UnsatisfiedLinkError noawt) {
|
||||||
remote = true;
|
System.err.println ("Error creating Image: "+noawt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remote)
|
|
||||||
rgen = (IRemoteGenerator) Naming.lookup ("//localhost:3033/server");
|
|
||||||
|
|
||||||
if (arguments.length == 1) {
|
if (arguments.length == 1) {
|
||||||
if (arguments[0] instanceof ESArrayWrapper) {
|
if (arguments[0] instanceof ESArrayWrapper) {
|
||||||
Object obj = ((ESArrayWrapper) arguments[0]).toJavaObject ();
|
Object obj = ((ESArrayWrapper) arguments[0]).toJavaObject ();
|
||||||
if (obj instanceof byte[]) {
|
if (obj instanceof byte[]) {
|
||||||
img = remote ?
|
img = imggen.createImage ((byte[]) obj);
|
||||||
(Object) rgen.createImage ((byte[]) obj) :
|
|
||||||
(Object) imggen.createImage ((byte[]) obj);
|
|
||||||
}
|
}
|
||||||
} else if (arguments[0] instanceof ESString) {
|
} else if (arguments[0] instanceof ESString) {
|
||||||
String imgurl = arguments[0].toString ();
|
String imgurl = arguments[0].toString ();
|
||||||
img = remote ?
|
img = imggen.createPaintableImage (imgurl);
|
||||||
(Object) rgen.createPaintableImage (imgurl) :
|
|
||||||
(Object) imggen.createPaintableImage (imgurl);
|
|
||||||
}
|
}
|
||||||
} else if (arguments.length == 2) {
|
} else if (arguments.length == 2) {
|
||||||
if (arguments[0] instanceof ESWrapper && arguments[1] instanceof ESWrapper) {
|
if (arguments[0] instanceof ESWrapper && arguments[1] instanceof ESWrapper) {
|
||||||
|
@ -85,9 +76,7 @@ public class ImageExtension extends Extension {
|
||||||
Object filter = arguments[1].toJavaObject ();
|
Object filter = arguments[1].toJavaObject ();
|
||||||
img = imggen.createPaintableImage ((ImageWrapper) image, (ImageFilter) filter);
|
img = imggen.createPaintableImage ((ImageWrapper) image, (ImageFilter) filter);
|
||||||
} else if (arguments[0].isNumberValue () && arguments[1].isNumberValue ()) {
|
} else if (arguments[0].isNumberValue () && arguments[1].isNumberValue ()) {
|
||||||
img = remote ?
|
img = imggen.createPaintableImage (arguments[0].toInt32(), arguments[1].toInt32());
|
||||||
(Object) rgen.createPaintableImage (arguments[0].toInt32(), arguments[1].toInt32()) :
|
|
||||||
(Object) imggen.createPaintableImage (arguments[0].toInt32(), arguments[1].toInt32());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception error) {
|
} catch (Exception error) {
|
||||||
|
@ -106,28 +95,12 @@ public class ImageExtension extends Extension {
|
||||||
* Called by the evaluator after the extension is loaded.
|
* Called by the evaluator after the extension is loaded.
|
||||||
*/
|
*/
|
||||||
public void initializeExtension(Evaluator evaluator) throws EcmaScriptException {
|
public void initializeExtension(Evaluator evaluator) throws EcmaScriptException {
|
||||||
|
|
||||||
this.evaluator = evaluator;
|
this.evaluator = evaluator;
|
||||||
GlobalObject go = evaluator.getGlobalObject();
|
GlobalObject go = evaluator.getGlobalObject();
|
||||||
FunctionPrototype fp = (FunctionPrototype) evaluator.getFunctionPrototype();
|
FunctionPrototype fp = (FunctionPrototype) evaluator.getFunctionPrototype();
|
||||||
|
|
||||||
ESObject image = new GlobalObjectImage ("Image", evaluator, fp, this); // the Image constructor
|
ESObject image = new GlobalObjectImage ("Image", evaluator, fp, this); // the Image constructor
|
||||||
|
|
||||||
go.putHiddenProperty("Image", image); // register the constructor for a Image object.
|
go.putHiddenProperty("Image", image); // register the constructor for a Image object.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue