Initial revision

From-SVN: r102074
This commit is contained in:
Tom Tromey
2005-07-16 00:30:23 +00:00
parent 6f4434b39b
commit f911ba985a
4557 changed files with 1000262 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
Makefile
Makefile.in
examples.zip

View File

@@ -0,0 +1,90 @@
## Input file for automake to generate the Makefile.in used by configure
# Setup the compiler to use the GNU Classpath library we just build
if FOUND_GCJ
JCOMPILER = $(GCJ) --bootclasspath '$(top_builddir)/lib' --classpath . -C
else
if FOUND_JIKES
JCOMPILER = $(JIKES) -bootclasspath '' -extdirs '' -sourcepath '' --classpath $(top_builddir)/lib:.
else
if FOUND_GCJX
JCOMPILER = $(GCJX) -bootclasspath '' -sourcepath '' -classpath $(top_builddir)/lib:.
else
if FOUND_ECJ
JCOMPILER = $(ECJ) -bootclasspath '$(top_builddir)/lib' -classpath .
else
error dunno how to setup the JCOMPILER and compile
endif
endif
endif
endif
# All our example java source files
EXAMPLE_JAVA_FILES = $(srcdir)/gnu/classpath/examples/*/*.java
# The zip files with classes we want to produce.
EXAMPLE_ZIP = examples.zip
# Extra objects that will not exist until configure-time
BUILT_SOURCES = $(EXAMPLE_ZIP)
# the png icons we use in some of the examples.
EXAMPLE_ICONS = $(srcdir)/gnu/classpath/examples/icons/*.png
# Some architecture independent data to be installed.
example_DATA = $(EXAMPLE_ZIP) README
# Where we want these data files installed.
exampledir = $(pkgdatadir)/examples
# Make sure all sources and icons are also installed so users can use them.
# (Be careful to strip off the srcdir part of the path when installing.)
install-data-local:
srcdir_cnt=`echo $(srcdir) | wc -c`; \
for file in $(EXAMPLE_JAVA_FILES) $(EXAMPLE_ICONS); do \
f=`echo $$file | cut -c$$srcdir_cnt-`; \
fdir=`dirname $$f`; \
if test ! -d $(DESTDIR)/$(pkgdatadir)/examples/$$fdir; then \
echo "$(mkinstalldirs) $(DESTDIR)/$(pkgdatadir)/examples/$$fdir"; \
$(mkinstalldirs) $(DESTDIR)/$(pkgdatadir)/examples/$$fdir; \
fi; \
echo "$(INSTALL_DATA) $$file $(DESTDIR)/$(pkgdatadir)/examples/$$f"; \
$(INSTALL_DATA) $$file $(DESTDIR)/$(pkgdatadir)/examples/$$f; \
done
uninstall-local:
srcdir_cnt=`echo $(srcdir) | wc -c`; \
for file in $(EXAMPLE_JAVA_FILES) $(EXAMPLE_ICONS); do \
f=`echo $$file | cut -c$$srcdir_cnt-`; \
echo "rm -f $(DESTDIR)/$(pkgdatadir)/examples/$$f"; \
rm -f $(DESTDIR)/$(pkgdatadir)/examples/$$f; \
done
# Make sure everything is included in the distribution.
EXTRA_DIST = README
dist-hook:
srcdir_cnt=`echo $(srcdir) | wc -c`; \
for file in $(EXAMPLE_JAVA_FILES) $(EXAMPLE_ICONS); do \
f=`echo $$file | cut -c$$srcdir_cnt-`; \
fdir=`dirname $$f`; \
if test ! -d $(distdir)/$$fdir; then \
echo "$(makeinstalldirs) $(distdir)/$$fdir"; \
$(mkinstalldirs) $(distdir)/$$fdir; \
fi; \
echo "cp -p $$file $(distdir)/$$f"; \
cp -p $$file $(distdir)/$$f; \
done
# To generate the example zip just depend on the sources and ignore the
# class files. Always regenerate all .class files and remove them immediatly.
# And copy the png icons we use to the classes dir so they get also included.
$(EXAMPLE_ZIP): $(EXAMPLE_JAVA_FILES)
mkdir -p classes/gnu/classpath/examples/icons
cp $(EXAMPLE_ICONS) classes/gnu/classpath/examples/icons
$(JCOMPILER) -d classes $(EXAMPLE_JAVA_FILES)
cd classes; $(ZIP) -r ../$(EXAMPLE_ZIP) .; cd ..
rm -rf classes
# Zip file be gone! (and make sure the classes are gone too)
clean-local:
rm -f $(EXAMPLE_ZIP) classes

View File

@@ -0,0 +1,48 @@
This directory contains example programs that show how the GNU Classpath
library can be used.
Each example has its own package under gnu.classpath.examples and has a
class Demo which contains a main() method to run that particular example.
The examples can be compiled and run with gcj as follows:
gcj -o swingdemo --main=gnu.classpath.examples.swing.Demo \
gnu/classpath/examples/swing/Demo.java
./swingdemo
Or with a traditional byte code interpreter like:
gcj -C gnu/classpath/examples/awt/Demo.java
gij gnu.classpath.examples.awt.Demo
The installation also comes with an examples.zip archive that contains
all needed resources and compiled byte code class files that can be
run as follows:
kaffe -classpath examples.zip gnu.classpath.examples.awt.Demo
kaffe -classpath examples.zip gnu.classpath.examples.swing.Demo
All example code is distributed under the GNU General Public License (GPL).
The example icons used in some of the examples come from gnome-icon-theme
version 1.2.3 and are also distributed under the GPL.
All these images are stored in the directory gnu/classpath/examples/icons/.
More free icons can be found in the gnome-icon-theme package:
http://ftp.gnome.org/pub/GNOME/sources/gnome-icon-theme/
GNU Classpath examples are free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
GNU Classpath examples are distributed in the hope that they will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath examples; see the file COPYING. If not,
write to the Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.

View File

@@ -0,0 +1,199 @@
/* Demo.java -- Shows how to use Classpath transient naming service.
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.NamingService;
import gnu.CORBA.IOR;
import gnu.CORBA.NamingService.NamingServiceTransient;
import org.omg.CORBA.ORB;
import org.omg.CORBA.Object;
import org.omg.CosNaming.Binding;
import org.omg.CosNaming.BindingHolder;
import org.omg.CosNaming.BindingIterator;
import org.omg.CosNaming.BindingIteratorHolder;
import org.omg.CosNaming.BindingListHolder;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.CosNaming.NamingContextHelper;
/**
* A simple test of the naming service.
*
* The main class of the GNU Classpath transient naming service is
* {@link gnu.CORBA.NamingService}. This class must be started
* before starting this example.
*
* This example should interoperate as with GNU Classpath naming
* service, as with Sun Microsystems transient and persistent
* naming services, included in releases 1.3 and 1.4 (tnameserv and
* orbd). To work with this example, the naming service must
* be started on the local host, at the port 900.
*
* The persistent naming service is currently under development.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public class Demo
{
public static void main(final String[] args)
{
// We create the following naming graph:
// <ROOT CONTEXT>
// |
// +--- <c.d context>
// | |
// | +--- obj
// |
// +--- xobj
//
// Where both obj and xobj are CORBA objects, representing the
// default naming service.
//
System.out.println("Starting the GNU Classpath " +
"built-in transient naming service"
);
new Thread()
{
public void run()
{
NamingServiceTransient.main(args);
}
}.start();
System.out.println("Waiting for three seconds for naming service to start:");
try
{
Thread.sleep(3000);
}
catch (InterruptedException ex)
{
}
try
{
ORB orb = ORB.init(args, null);
Object no = orb.resolve_initial_references("NameService");
System.out.println("Naming service IOR:" + orb.object_to_string(no));
System.out.println(IOR.parse(orb.object_to_string(no)));
NamingContextExt namer = NamingContextExtHelper.narrow(no);
System.out.println("Naming service: " + namer.getClass().getName());
NamingContext second = namer.new_context();
namer.rebind_context(namer.to_name("c.d"), second);
namer.rebind(namer.to_name("xobj"), no);
second.rebind(namer.to_name("obj"), no);
NamingContext nsec =
NamingContextHelper.narrow(namer.resolve_str("c.d"));
System.out.println(namer.resolve(namer.to_name("c.d/obj")));
// In all cases, this must be the same object (the naming
// service itself).
System.out.println(nsec.resolve(new NameComponent[]
{
new NameComponent("obj", "")
}
)
);
System.out.println(namer.resolve_str("xobj"));
// In all cases, this must be the same object (the naming
// service itself).
System.out.println(namer.resolve(new NameComponent[]
{
new NameComponent("c", "d"),
new NameComponent("obj", "")
}
)
);
System.out.println(namer.resolve_str("c.d/obj"));
System.out.println("Test binding list iterator:");
BindingListHolder lh = new BindingListHolder();
BindingIteratorHolder lih = new BindingIteratorHolder();
namer.list(0, lh, lih);
BindingIterator iter = lih.value;
BindingHolder binding = new BindingHolder();
while (iter.next_one(binding))
{
Binding b = binding.value;
System.out.println("NAME: " + namer.to_string(b.binding_name) +
" TYPE " + b.binding_type.value()
);
}
System.out.println("Testing binding list:");
iter.destroy();
namer.list(Integer.MAX_VALUE, lh, lih);
for (int i = 0; i < lh.value.length; i++)
{
Binding b = lh.value [ i ];
System.out.println("NAME: " + namer.to_string(b.binding_name) +
" TYPE " + b.binding_type.value()
);
}
}
catch (Exception ex)
{
ex.printStackTrace();
System.exit(1);
}
System.exit(0);
}
}

View File

@@ -0,0 +1,89 @@
/* Demo.java -- Demonstrates simple CORBA client-server communications.
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication;
import gnu.classpath.examples.CORBA.SimpleCommunication.communication.DirectTest;
import gnu.classpath.examples.CORBA.SimpleCommunication.communication.RequestTest;
/**
* This sample illustrates the CORBA communication between server
* and client. In this simple example both server and client are
* started on the same virtual machine. For the real interoperability
* tests, however, the server is started on the platform (library+jvm) of
* one vendor, and the client on the platform of another vendor.
*
* The interoperability is currently tested with Sun Microystems
* jre 1.4.
*
* This example required the current folder to be writable to pass
* the IOR references via shared file.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public class Demo
{
public static void main(final String[] args)
{
// Start the server.
new Thread()
{
public void run()
{
comServer.start_server(args);
}
}.start();
System.out.println("Waiting for three seconds for the server to start...");
// Pause some time for the server to start.
try {
Thread.sleep(3000);
}
catch (InterruptedException ex) {
}
// Test the stream oriented communication.
DirectTest.main(args);
// Test the request oriented communication.
RequestTest.main(args);
System.exit(0);
}
}

View File

@@ -0,0 +1,118 @@
/* comServer.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication;
import gnu.classpath.examples.CORBA.SimpleCommunication.communication.comServant;
import org.omg.CORBA.ORB;
import java.io.FileOutputStream;
import java.io.PrintStream;
/**
* This is the server class that handles the client requests,
* delegating the functionality to the {@link comServant}.
*
* When starting, the server writes the IOR.txt file into the current
* folder. With the information, stored in this file, the server
* should be reachable over Internet, unless blocked by security tools.
*
* This code is tested for interoperability with Sun Microsystems
* java implementation 1.4.2 (08.b03). Server, client of both can
* be started either on Sun's or on Classpath CORBA implementation,
* in any combinations.
*
* BE SURE TO START THIS SERVER BEFORE STARTING THE CLIENT.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public class comServer
{
public static void main(String[] args)
{
start_server(args);
}
public static ORB start_server(String[] args)
{
try
{
// Create and initialize the ORB.
final ORB orb = org.omg.CORBA.ORB.init(args, null);
// Create the servant and register it with the ORB.
comServant tester = new comServant();
orb.connect(tester);
// Storing the IOR reference.
String ior = orb.object_to_string(tester);
System.out.println("IOR: " + ior);
gnu.CORBA.IOR ii = gnu.CORBA.IOR.parse(ior);
System.out.println(ii);
// The file IOR.txt in the current folder will be used
// to find the object by clients.
FileOutputStream f = new FileOutputStream("IOR.txt");
PrintStream p = new PrintStream(f);
p.print(ior);
p.close();
System.out.println("The test server ready and waiting ...");
new Thread()
{
public void run()
{
// Start the thread, serving the invocations from clients.
orb.run();
}
}.start();
return orb;
}
catch (Exception e)
{
System.err.println("ERROR: " + e);
e.printStackTrace(System.out);
return null;
}
}
}

View File

@@ -0,0 +1,344 @@
/* DirectTest.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.BAD_OPERATION;
import org.omg.CORBA.ByteHolder;
import org.omg.CORBA.DoubleHolder;
import org.omg.CORBA.ORB;
import org.omg.CORBA.ShortHolder;
import org.omg.CORBA.StringHolder;
import org.omg.CORBA.UserException;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
/**
* This code uses CORBA to call various methods of the remote object,
* passing data structures in both directions. It finds the server by
* reading the IOR.txt file that must be present in the folder,
* where the program has been started.
*
* The IOR.txt file is written by the server
* {@link gnu.classpath.examples.CORBA.SimpleCommunication.comServer}.
* The server should be reachable over Internet, unless blocked by
* security tools.
*
* This code is tested for interoperability with Sun Microsystems
* java implementation 1.4.2 (08.b03). Server, client of both can
* be started either on Sun's or on Classpath CORBA implementation,
* in any combinations.
*
* BE SURE TO START THE SERVER BEFORE STARTING THE CLIENT.
*
* This version uses direct casting. This is the most convenient
* method, but it is normally used together with the IDL compiler.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public class DirectTest
{
/*
* The IOR.txt file, used to find the server and the object on the server. is written when starting the accompanying
*/
public static final String IOR_FILE = "IOR.txt";
/**
* The invocation target.
*/
comTester object;
/**
* Get the object reference.
*/
public static void main(String[] args)
{
try
{
ORB orb = org.omg.CORBA.ORB.init(args, null);
File f = new File(IOR_FILE);
char[] c = new char[ (int) f.length() ];
FileReader fr = new FileReader(f);
fr.read(c);
fr.close();
String ior = new String(c);
DirectTest we = new DirectTest();
we.object = (comTester) orb.string_to_object(ior);
we.Demo();
orb.shutdown(false);
}
catch (IOException ex)
{
System.out.println("Cannot find or read the IOR file " +
"in the current folder"
);
ex.printStackTrace();
}
}
/** Run all demos. */
public void Demo()
{
testHello();
testField();
testParameters();
testStringArray();
testStructure();
testWideNarrowStrings();
testTree();
testSystemException();
testUserException();
}
/**
* Test the field getter/setter.
*/
public void testField()
{
System.out.println("***** Test the remote field getter/setter.");
System.out.println("The field value is now " + object.theField());
System.out.println("Setting it to 555");
object.theField(555);
System.out.println("The field value is now " + object.theField());
}
/** The simple invocation of the parameterless remote method. */
public void testHello()
{
System.out.println("***** Say hello (see the server console).");
object.sayHello();
}
/**
* Test passing multiple parameters in both directions.
*/
public void testParameters()
{
System.out.println("***** Pass multiple parameters.");
// Holder classes are required to simulate passing
// "by reference" (modification is returned back to the server).
ByteHolder a_byte = new ByteHolder((byte) 0);
ShortHolder a_short = new ShortHolder((short) 3);
StringHolder a_string = new StringHolder("[string 4]");
// This is an 'out' parameter; the value must not be passed to servant.
DoubleHolder a_double = new DoubleHolder(56.789);
int returned = object.passSimple(a_byte, 2, a_short, a_string, a_double);
System.out.println(" Returned value " + returned);
System.out.println(" Returned parameters: ");
System.out.println(" octet " + a_byte.value);
System.out.println(" short " + a_short.value);
System.out.println(" string '" + a_string.value+"'");
System.out.println(" double " + a_double.value);
}
/**
* Test passing the string array, flexible size.
*/
public void testStringArray()
{
System.out.println("***** Pass string array.");
String[] x = new String[] { "one", "two" };
// The array is passed as CORBA sequence, variable size is supported.
String[] y = object.passStrings(x);
for (int i = 0; i < y.length; i++)
{
System.out.println(" Passed " + x [ i ] + ", returned: " + y [ i ]);
}
}
/**
* Test passing the structures.
*/
public void testStructure()
{
System.out.println("***** Pass structure");
passThis arg = new passThis();
arg.a = "A";
arg.b = "B";
returnThis r = object.passStructure(arg);
System.out.println(" Fields of the returned structure:");
System.out.println(" c: " + r.c);
System.out.println(" n: " + r.n);
// The field r.arra is declared as the fixed size CORBA array.
System.out.println(" r[0]: " + r.arra [ 0 ]);
System.out.println(" r[1]: " + r.arra [ 1 ]);
System.out.println(" r[3]: " + r.arra [ 2 ]);
}
/**
* Test catching the system exception, thrown on the remote side.
*/
public void testSystemException()
{
System.out.println("**** Test system exception:");
try
{
// Negative parameter = system exception.
object.throwException(-55);
}
catch (BAD_OPERATION ex)
{
System.out.println(" The expected BAD_OPERATION, minor code " +
ex.minor + ", has been thrown on remote side."
);
}
catch (UserException uex)
{
throw new InternalError();
}
}
/**
* Test passing the tree structure. Any shape of the tree is
* supported without rewriting the code.
*/
public void testTree()
{
// Manually create the tree of nodes:
// Root
// +-- a
// |
// +-- b
// +-- ba
// | |
// | +-- bac
// |
// +-- bb
System.out.println("***** Pass and return the tree.");
node n = nod("Root");
n.children = new node[] { nod("a"), nod("b") };
n.children [ 1 ].children = new node[] { nod("ba"), nod("bb") };
n.children [ 1 ].children [ 0 ].children = new node[] { nod("bac") };
nodeHolder nh = new nodeHolder(n);
// The server should add '++' to each node name.
object.passTree(nh);
// Convert the returned tree to some strig representation.
StringBuffer img = new StringBuffer();
getImage(img, nh.value);
System.out.println("Returned tree: " + img.toString());
}
/**
* Test catching the user exception, thrown on the remote side.
*/
public void testUserException()
{
System.out.println("**** Test user exception:");
try
{
// The user exception contains one user-defined field that will
// be initialised to the passed parameter.
object.throwException(123);
throw new InternalError();
}
catch (ourUserException uex)
{
System.out.println(" The user exception with field " + uex.ourField +
", has been thrown on remote side."
);
}
}
/**
* Passes wide (UTF-16) string and narrow (ISO8859_1) string.
* @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
* encodings.
*/
public void testWideNarrowStrings()
{
System.out.println("**** Test 8 bit and 16 bit char strings");
String r = object.passCharacters("wide string", "narrow string");
System.out.println(" returned: '" + r + "'");
}
/**
* Get the string representation of the passed tree.
* @param b the string buffer to accumulate the representation.
* @param n the tree (root node).
*/
private void getImage(StringBuffer b, node n)
{
b.append(n.name);
b.append(": (");
for (int i = 0; i < n.children.length; i++)
{
getImage(b, n.children [ i ]);
b.append(' ');
}
b.append(") ");
}
/**
* Create a node with the given header.
*
* @param hdr the node header.
* @return the created node.
*/
private node nod(String hdr)
{
node n = new node();
n.children = new node[ 0 ];
n.name = hdr;
return n;
}
}

View File

@@ -0,0 +1,260 @@
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import org.omg.CORBA.BAD_OPERATION;
import org.omg.CORBA.ByteHolder;
import org.omg.CORBA.DoubleHolder;
import org.omg.CORBA.ExceptionList;
import org.omg.CORBA.NVList;
import org.omg.CORBA.ORB;
import org.omg.CORBA.Request;
import org.omg.CORBA.ShortHolder;
import org.omg.CORBA.StringHolder;
import org.omg.CORBA.TCKind;
import org.omg.CORBA.UnknownUserException;
/**
* This code uses CORBA to call various methods of the remote object,
* passing data structures in both directions. It finds the server by
* reading the IOR.txt file that must be present in the folder,
* where the program has been started.
*
* The IOR.txt file is written by the server
* {@link gnu.classpath.examples.CORBA.SimpleCommunication.comServer}.
* The server should be reachable over Internet, unless blocked by
* security tools.
*
* This code is tested for interoperability with Sun Microsystems
* java implementation 1.4.2 (08.b03). Server, client of both can
* be started either on Sun's or on Classpath CORBA implementation,
* in any combinations.
*
* BE SURE TO START THE SERVER BEFORE STARTING THE CLIENT.
*
* Test invocations using org.omg.CORBA.Request. The methods are
* called by "name", like in java.lang.reflect.
* No need to have the local pre-compiled stub classes.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public class RequestTest
{
/*
* The IOR.txt file, used to find the server and the object on the server. is written when starting the accompanying
*/
public static final String IOR_FILE = "IOR.txt";
/**
* The Object Request Brocker, used for various CORBA operations.
*/
ORB orb;
/**
* Our remote object - the invocation target.
*/
org.omg.CORBA.Object object;
/**
* Prepare for work. Read the file IOR.txt in the current folder
* and find the server using its information.
*/
public static void main(String[] args)
{
RequestTest we = new RequestTest();
we.orb = org.omg.CORBA.ORB.init(new String[ 0 ], null);
char[] c = null;
try
{
File f = new File(IOR_FILE);
c = new char[ (int) f.length() ];
FileReader fr = new FileReader(f);
fr.read(c);
fr.close();
}
catch (IOException ex)
{
System.out.println("Unable to write the IOR.txt into the current folder");
ex.printStackTrace();
}
String ior = new String(c);
we.object = we.orb.string_to_object(ior);
we.Demo();
we.orb.shutdown(false);
}
/** Run all demos. */
public void Demo()
{
testHello();
try
{
testParameters();
}
catch (Exception ex)
{
// Not expected.
throw new InternalError();
}
testSystemException();
testUserException();
testWideNarrowStrings();
}
/**
* Send the hello message, one way.
*/
public void testHello()
{
System.out.println("***** Test 'HELLO WORLD' (see the server console).");
Request hello =
object._create_request(null, "sayHello", orb.create_list(0), null);
// No response expected.
hello.send_oneway();
}
/**
* Test passing various parameters in both directions.
*/
public void testParameters()
throws Exception
{
System.out.println("***** Test passing multiple parameters:");
Request r =
object._create_request(null, "passSimple", orb.create_list(0), null);
ByteHolder a_byte = new ByteHolder((byte) 0);
ShortHolder a_short = new ShortHolder((short) 3);
StringHolder a_string = new StringHolder("[string 4]");
// This is an 'out' parameter; the value must not be passed to servant.
DoubleHolder a_double = new DoubleHolder(56.789);
r.add_inout_arg().insert_octet((byte) 0);
r.add_in_arg().insert_long(2);
r.add_inout_arg().insert_short((short) 3);
r.add_inout_arg().insert_string("[string 4]");
r.add_out_arg().type(orb.get_primitive_tc(TCKind.tk_double));
NVList para = r.arguments();
System.out.println(" --- Parameters before invocation: ");
System.out.println(" octet " + para.item(0).value().extract_octet());
System.out.println(" long (in parameter) " +
para.item(1).value().extract_long()
);
System.out.println(" short " + para.item(2).value().extract_short());
System.out.println(" string " + para.item(3).value().extract_string());
// For the last parameter, the value is not set.
r.set_return_type(orb.get_primitive_tc(TCKind.tk_long));
r.invoke();
para = r.arguments();
System.out.println(" --- Parameters after invocation:");
System.out.println(" octet " + para.item(0).value().extract_octet());
System.out.println(" long (in parameter, must not be changed) " +
para.item(1).value().extract_long()
);
System.out.println(" short " + para.item(2).value().extract_short());
System.out.println(" string " + para.item(3).value().extract_string());
System.out.println(" double " + para.item(4).value().extract_double());
System.out.println(" Returned value " + r.result().value().extract_long());
}
/**
* Test catching the system exception, thrown on the remote side.
*/
public void testSystemException()
{
System.out.println("**** Test system exception:");
try
{
ExceptionList exList = orb.create_exception_list();
exList.add(ourUserExceptionHelper.type());
Request rq =
object._create_request(null, "throwException", orb.create_list(1),
null, exList, null
);
rq.add_in_arg().insert_long(-55);
rq.invoke();
throw new InternalError();
}
catch (BAD_OPERATION ex)
{
System.out.println(" The expected BAD_OPERATION, minor code " +
ex.minor + ", has been thrown on remote side."
);
}
}
/**
* Test catching the user exception, thrown on the remote side.
*/
public void testUserException()
{
System.out.println("**** Test user exception:");
ExceptionList exList = orb.create_exception_list();
exList.add(ourUserExceptionHelper.type());
Request rq =
object._create_request(null, "throwException", orb.create_list(1), null,
exList, null
);
rq.add_in_arg().insert_long(123);
rq.invoke();
UnknownUserException uku = (UnknownUserException) rq.env().exception();
ourUserException our_exception = ourUserExceptionHelper.extract(uku.except);
System.out.println(" Our user exception, field " + our_exception.ourField +
", has been thrown on remote side."
);
}
/**
* Passes wide (UTF-16) string and narrow (ISO8859_1) string.
* @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
* encodings.
*/
public void testWideNarrowStrings()
throws BAD_OPERATION
{
System.out.println("**** Test 8 bit and 16 bit char strings");
Request rq =
object._create_request(null, "passCharacters", orb.create_list(0), null);
rq.add_in_arg().insert_wstring("wide string");
rq.add_in_arg().insert_string("narrow string");
rq.set_return_type(orb.get_primitive_tc(TCKind.tk_wstring));
rq.invoke();
System.out.println(" Returned ' " + rq.result().value().extract_wstring());
}
}

View File

@@ -0,0 +1,206 @@
/* _comTesterImplBase.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.BAD_OPERATION;
import org.omg.CORBA.ByteHolder;
import org.omg.CORBA.CompletionStatus;
import org.omg.CORBA.DoubleHolder;
import org.omg.CORBA.ShortHolder;
import org.omg.CORBA.StringHolder;
import org.omg.CORBA.StringSeqHelper;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.InvokeHandler;
import org.omg.CORBA.portable.ObjectImpl;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.ResponseHandler;
/**
* The base for the class that is actually implementing the functionality
* of the object on the server side ({@link comServant} of our case).
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public abstract class _comTesterImplBase
extends ObjectImpl
implements comTester, InvokeHandler
{
/**
* When the server receives the request message from client, it
* calls this method.
*
* @param a_method the method name.
* @param in the CDR stream, from where the implementing code must
* read the method parameters.
* @param rh the response handler, used to get the stream where
* the returned values must be written.
*
* @return the stream, obtained from the response handler.
*/
public OutputStream _invoke(String a_method, InputStream in,
ResponseHandler rh
)
{
OutputStream out;
/* Get the field value. */
if (a_method.equals("_get_theField"))
{
int result = (int) 0;
result = theField();
out = rh.createReply();
out.write_long(result);
}
else
/* Set the field value. */
if (a_method.equals("_set_theField"))
{
int newTheField = in.read_long();
theField(newTheField);
out = rh.createReply();
}
else
/* Logs calls to the file. */
if (a_method.equals("sayHello"))
{
sayHello();
out = rh.createReply();
}
else
/* Passes various parameters in both directions. */
if (a_method.equals("passSimple"))
{
ByteHolder an_octet = new ByteHolder();
an_octet.value = in.read_octet();
int a_long = in.read_long();
ShortHolder a_short = new ShortHolder();
a_short.value = in.read_short();
StringHolder a_string = new StringHolder();
a_string.value = in.read_string();
DoubleHolder a_double = new DoubleHolder();
int result = passSimple(an_octet, a_long, a_short, a_string, a_double);
out = rh.createReply();
out.write_long(result);
out.write_octet(an_octet.value);
out.write_short(a_short.value);
out.write_string(a_string.value);
out.write_double(a_double.value);
}
else
/* Passes the 'wide' (usually Unicode) string and the ordinary string. */
if (a_method.equals("passCharacters"))
{
String wide = in.read_wstring();
String narrow = in.read_string();
String result = null;
result = passCharacters(wide, narrow);
out = rh.createReply();
out.write_wstring(result);
}
else
/*
Throws either 'ourUserException' with the 'ourField' field
initialised to the passed positive value
or system exception (if the parameter is zero or negative).
*/
if (a_method.equals("throwException"))
{
try
{
int parameter = in.read_long();
throwException(parameter);
out = rh.createReply();
}
catch (ourUserException exception)
{
out = rh.createExceptionReply();
ourUserExceptionHelper.write(out, exception);
}
}
else
/* Passes and returns the structures. */
if (a_method.equals("passStructure"))
{
passThis in_structure = passThisHelper.read(in);
returnThis result = null;
result = passStructure(in_structure);
out = rh.createReply();
returnThisHelper.write(out, result);
}
else
/* Passes and returns the string sequence. */
if (a_method.equals("passStrings"))
{
String[] arg = StringSeqHelper.read(in);
String[] result = null;
result = passStrings(arg);
out = rh.createReply();
StringSeqHelper.write(out, result);
}
else
/** Pass and return the tree structure */
if (a_method.equals("passTree"))
{
nodeHolder tree = new nodeHolder();
tree.value = nodeHelper.read(in);
passTree(tree);
out = rh.createReply();
nodeHelper.write(out, tree.value);
}
else
throw new BAD_OPERATION("No method: " + a_method, 0,
CompletionStatus.COMPLETED_MAYBE
);
return out;
}
/**
* Return an array of this object repository ids.
*/
public String[] _ids()
{
// They are the same as for the stub.
return _comTesterStub._ids;
}
}

View File

@@ -0,0 +1,426 @@
/* _comTesterStub.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.ByteHolder;
import org.omg.CORBA.DoubleHolder;
import org.omg.CORBA.MARSHAL;
import org.omg.CORBA.ShortHolder;
import org.omg.CORBA.StringHolder;
import org.omg.CORBA.StringSeqHelper;
import org.omg.CORBA.portable.ApplicationException;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.ObjectImpl;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.RemarshalException;
/**
* The stub (proxy) class, representing the remote object on the client
* side. It has all the same methods as the actual implementation
* on the server side. These methods contain the code for remote
* invocation.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public class _comTesterStub
extends ObjectImpl
implements comTester
{
/**
* A string array of comTester repository ids.
*/
public static String[] _ids =
{
"IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/comTester:1.0"
};
/**
* Return an array of comTester repository ids.
*/
public String[] _ids()
{
return _ids;
}
/**
* Passes wide (UTF-16) string and narrow (ISO8859_1) string.
* @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
* encodings.
*/
public String passCharacters(String wide, String narrow)
{
InputStream in = null;
try
{
// Get the output stream.
OutputStream out = _request("passCharacters", true);
// Write the parameters.
// The first string is passed as "wide"
// (usually 16 bit UTF-16) string.
out.write_wstring(wide);
// The second string is passed as "narrow"
// (usually 8 bit ISO8859_1) string.
out.write_string(narrow);
// Do the invocation.
in = _invoke(out);
// Read the method return value.
String result = in.read_wstring();
return result;
}
catch (ApplicationException ex)
{
// The exception has been throws on remote side, but we
// do not expect any. Throw the MARSHAL exception.
in = ex.getInputStream();
throw new MARSHAL(ex.getId());
}
catch (RemarshalException _rm)
{
// This exception means that the parameters must be re-written.
return passCharacters(wide, narrow);
}
finally
{
// Release the resources, associated with the reply stream.
_releaseReply(in);
}
}
/**
* Passes various parameters in both directions. The parameters that
* shoud also return the values are wrapped into holders.
*/
public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
StringHolder a_string, DoubleHolder a_double
)
{
InputStream in = null;
try
{
// Get the stream where the parameters must be written:
OutputStream out = _request("passSimple", true);
// Write the parameters.
out.write_octet(an_octet.value);
out.write_long(a_long);
out.write_short(a_short.value);
out.write_string(a_string.value);
// Invoke the method.
in = _invoke(out);
// Read the returned values.
int result = in.read_long();
// Read the inout and out parameters.
an_octet.value = in.read_octet();
a_short.value = in.read_short();
a_string.value = in.read_string();
a_double.value = in.read_double();
return result;
}
catch (ApplicationException ex)
{
// Handle excepion on remote side.
in = ex.getInputStream();
throw new MARSHAL(ex.getId());
}
catch (RemarshalException _rm)
{
// Handle instruction to resend the parameters.
return passSimple(an_octet, a_long, a_short, a_string, a_double);
}
finally
{
_releaseReply(in);
}
}
/**
Passes and returns the string sequence.
*/
public String[] passStrings(String[] arg)
{
InputStream in = null;
try
{
// Get the stream where the parameters must be written:
OutputStream out = _request("passStrings", true);
// Wrap the string array using the string sequence helper.
StringSeqHelper.write(out, arg);
// Invoke the method.
in = _invoke(out);
// Read the returned result using the string sequence helper.
String[] result = StringSeqHelper.read(in);
return result;
}
catch (ApplicationException ex)
{
// Handle the exception, thrown on remote side.
in = ex.getInputStream();
throw new MARSHAL(ex.getId());
}
catch (RemarshalException _rm)
{
return passStrings(arg);
}
finally
{
_releaseReply(in);
}
}
/**
Passes and returns the structures.
*/
public returnThis passStructure(passThis in_structure)
{
InputStream in = null;
try
{
// Get the stream where the parameters must be written.
OutputStream out = _request("passStructure", true);
// Write the structure, using its helper.
passThisHelper.write(out, in_structure);
// Invoke the method.
in = _invoke(out);
// Read the returned structer, using another helper.
returnThis result = returnThisHelper.read(in);
return result;
}
catch (ApplicationException ex)
{
in = ex.getInputStream();
throw new MARSHAL(ex.getId());
}
catch (RemarshalException _rm)
{
return passStructure(in_structure);
}
finally
{
_releaseReply(in);
}
}
/**
* Pass and return the tree structure
*/
public void passTree(nodeHolder tree)
{
InputStream in = null;
try
{
// Get the stream where the parameters must be written.
OutputStream out = _request("passTree", true);
// Write the tree (node with its chilred, grandchildren and so on),
// using the appropriate helper.
nodeHelper.write(out, tree.value);
// Call the method.
in = _invoke(out);
// Read the returned tree.
tree.value = nodeHelper.read(in);
}
catch (ApplicationException ex)
{
// Handle eception on remote side.
in = ex.getInputStream();
throw new MARSHAL(ex.getId());
}
catch (RemarshalException _rm)
{
passTree(tree);
}
finally
{
_releaseReply(in);
}
}
/**
* One way call of the remote method.
*/
public void sayHello()
{
InputStream in = null;
try
{
// As we do not expect any response, the second
// parameter is 'false'.
OutputStream out = _request("sayHello", false);
in = _invoke(out);
}
catch (ApplicationException ex)
{
in = ex.getInputStream();
throw new MARSHAL(ex.getId());
}
catch (RemarshalException _rm)
{
sayHello();
}
finally
{
_releaseReply(in);
}
}
/**
* Get the field value.
*/
public int theField()
{
InputStream in = null;
try
{
// The special name of operation instructs just to get
// the field value rather than calling the method.
OutputStream out = _request("_get_theField", true);
in = _invoke(out);
int result = in.read_long();
return result;
}
catch (ApplicationException ex)
{
in = ex.getInputStream();
throw new MARSHAL(ex.getId());
}
catch (RemarshalException _rm)
{
return theField();
}
finally
{
_releaseReply(in);
}
}
/**
* Set the field value.
*/
public void theField(int newTheField)
{
InputStream in = null;
try
{
// The special name of operation instructs just to set
// the field value rather than calling the method.
OutputStream out = _request("_set_theField", true);
out.write_long(newTheField);
in = _invoke(out);
}
catch (ApplicationException ex)
{
in = ex.getInputStream();
throw new MARSHAL(ex.getId());
}
catch (RemarshalException _rm)
{
theField(newTheField);
}
finally
{
_releaseReply(in);
}
}
/**
* The server side exception tests.
*
* @param parameter the server throws the user exception in the case
* of the positive value of this argument, and system
* exception otherwise.
*
* @throws ourUserException
*/
public void throwException(int parameter)
throws ourUserException
{
InputStream in = null;
try
{
// Get stream.
OutputStream out = _request("throwException", true);
// Write parameter.
out.write_long(parameter);
// Call method.
in = _invoke(out);
}
catch (ApplicationException ex)
{
in = ex.getInputStream();
// Get the exception id.
String id = ex.getId();
// If this is the user exception we expect to catch, read and throw
// it here. The system exception, if thrown, is handled by _invoke.
if (id.equals("IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserException:1.0")
)
throw ourUserExceptionHelper.read(in);
else
throw new MARSHAL(id);
}
catch (RemarshalException _rm)
{
throwException(parameter);
}
finally
{
_releaseReply(in);
}
}
}

View File

@@ -0,0 +1,236 @@
/* comServant.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.BAD_OPERATION;
import org.omg.CORBA.ByteHolder;
import org.omg.CORBA.CompletionStatus;
import org.omg.CORBA.DoubleHolder;
import org.omg.CORBA.ShortHolder;
import org.omg.CORBA.StringHolder;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.PrintStream;
/**
* This class handles the actual server functionality in this test
* application. When the client calls the remote method, this
* finally results calling the method of this class.
*
* The parameters, passed to the server only, are just parameters of the
* java methods. The parameters that shuld be returned to client
* are wrapped into holder classes.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public class comServant
extends _comTesterImplBase
{
/**
* The field, that can be set and checked by remote client.
*/
private int m_theField = 17;
/**
* Passes wide (UTF-16) string and narrow (ISO8859_1) string.
* @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
* encodings. Returs they generalization as a wide string.
*/
public String passCharacters(String wide, String narrow)
{
System.out.println("SERVER: **** Wide and narrow string test.");
System.out.println("SERVER: Received '" + narrow + "' and '" + wide +
"'"
);
return "return '" + narrow + "' and '" + wide + "'";
}
/**
* Accept and return parameters, having various types.
*/
public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
StringHolder a_string, DoubleHolder a_double
)
{
System.out.println("SERVER: ***** Test passing multiple parameters");
System.out.println("SERVER: Received:");
System.out.println("SERVER: octet " + an_octet.value);
System.out.println("SERVER: short " + a_short.value);
System.out.println("SERVER: string " + a_string.value);
// Returning incremented values.
an_octet.value++;
a_short.value++;
// OUT parameter, return only.
a_double.value = 1;
a_string.value += " [return]";
return 452572;
}
/**
* Accept and return the string arrays.
*/
public String[] passStrings(String[] args)
{
System.out.println("SERVER: ***** Transferring string arrays");
String[] rt = new String[ args.length ];
for (int i = 0; i < args.length; i++)
{
System.out.println("SERVER: " + args [ i ]);
// Returning the changed content.
rt [ i ] = args [ i ] + ":" + args [ i ];
}
return rt;
}
/**
* Accept and return the structures.
*/
public returnThis passStructure(passThis in_structure)
{
System.out.println("SERVER: ***** Transferring structures");
System.out.println("SERVER: Received " + in_structure.a + ":" +
in_structure.b
);
// Create and send back the returned structure.
returnThis r = new returnThis();
r.c = in_structure.a + in_structure.b;
r.n = 555;
r.arra = new int[] { 11, 22, 33 };
return r;
}
/**
* Pass and return the tree structure
*/
public void passTree(nodeHolder tree)
{
System.out.println("SERVER: ***** Transferring tree");
StringBuffer b = new StringBuffer();
// This both creates the tree string representation
// and changes the node names.
getImage(b, tree.value);
System.out.println("SERVER: The tree was: " + b + ", returning changed.");
}
/**
* Just prints the hello message.
*/
public void sayHello()
{
System.out.println("SERVER: ***** Hello, world!");
}
/**
* Get the value of our field.
*/
public int theField()
{
System.out.println("SERVER: ***** Getting the field value, " + m_theField);
return m_theField;
}
/**
* Set the value of our field.
*/
public void theField(int a_field)
{
System.out.println("SERVER: ***** Setting the field value to " + a_field);
m_theField = a_field;
}
/**
* Throw an exception.
*
* @param parameter specifies which exception will be thrown.
*
* @throws ourUserException for the non negative parameter.
* @throws BAD_OPERATION for the negative parameter.
*/
public void throwException(int parameter)
throws ourUserException
{
System.out.println("SERVER: ***** Testing exceptions");
if (parameter > 0)
{
System.out.println("SERVER: Throwing the user exception, " +
"specific field = "+parameter
);
throw new ourUserException(parameter);
}
else
{
System.out.println("SERVER: Throwing " +
"the BAD_OPERATION, minor 456, completed"
);
throw new BAD_OPERATION(456, CompletionStatus.COMPLETED_YES);
}
}
/**
* Visit all tree nodes, getting the string representation
* and adding '++' to the node names.
*
* @param b the buffer to collect the string representation.
* @param n the rott tree node.
*/
private void getImage(StringBuffer b, node n)
{
b.append(n.name);
n.name = n.name + "++";
b.append(": (");
for (int i = 0; i < n.children.length; i++)
{
getImage(b, n.children [ i ]);
b.append(' ');
}
b.append(") ");
}
}

View File

@@ -0,0 +1,111 @@
/* comTester.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.ByteHolder;
import org.omg.CORBA.DoubleHolder;
import org.omg.CORBA.ShortHolder;
import org.omg.CORBA.StringHolder;
/**
* The interface of our remote object. Some IDL compiles split it
* into "comTester" and "comTesterOperations", but we do not see
* much sense in doing this here.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public interface comTester
{
/**
* Passes wide (UTF-16) string and narrow (ISO8859_1) string.
* Both types are mapped into java String.
*
* @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
* encodings.
*/
String passCharacters(String wide, String narrow);
/**
* Passes various parameters in both directions.
* The parameters that must return the value are wrapped in holders.
*/
int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
StringHolder a_string, DoubleHolder a_double
);
/**
* Passes and returns the string sequence (flexible length).
*/
String[] passStrings(String[] arg);
/**
* Passes and returns the structures.
*/
returnThis passStructure(passThis in_structure);
/**
* Pass and return the tree structure
*
* @param tree the root node of the tree.
*/
void passTree(nodeHolder tree);
/**
* Just prints the "Hello" message.
*/
void sayHello();
/**
* Gets the value of the field in our object.
*/
int theField();
/**
* Sets the value for the field in our object.
*/
void theField(int newTheField);
/**
* Throws either 'ourUserException' with the 'ourField' field
* initialised to the passed positive value
* or system exception (if the parameter is zero or negative).
*/
void throwException(int parameter)
throws ourUserException;
}

View File

@@ -0,0 +1,55 @@
/* node.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
/**
* The support for the tree structure, used in the test of
* ability to pass and return the tree structure.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class node
implements org.omg.CORBA.portable.IDLEntity
{
/** The node name */
public String name = null;
/** The node children. */
public node[] children = null;
}

View File

@@ -0,0 +1,160 @@
/* nodeHelper.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.Any;
import org.omg.CORBA.ORB;
import org.omg.CORBA.StructMember;
import org.omg.CORBA.TypeCode;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.OutputStream;
/**
* This class is used for various helper operations around the
* tree {@link} structure.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public abstract class nodeHelper
{
/**
* The node repository id, used to identify the structure.
*/
private static String _id =
"IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/node:1.0";
/**
* Caches the typecode, allowing to compute it only once.
*/
private static TypeCode typeCode;
/**
* This is used to handle the recursive object references in
* CORBA - supported way. The tree node definition is recursive,
* as the node contains the sequence of the nodes as its field.
*/
private static boolean active;
/**
* Extract the tree node from the unversal CORBA wrapper, Any.
*/
public static node extract(Any a)
{
return read(a.create_input_stream());
}
/**
* Get the node string identifer.
*/
public static String id()
{
return _id;
}
/**
* Insert the node into the universal CORBA wrapper, Any.
*/
public static void insert(Any a, node that)
{
OutputStream out = a.create_output_stream();
a.type(type());
write(out, that);
a.read_value(out.create_input_stream(), type());
}
/**
* Read the node from the common data reprentation (CDR) stream.
*/
public static node read(InputStream istream)
{
node value = new node();
value.name = istream.read_string();
int _len0 = istream.read_long();
value.children = new node[ _len0 ];
for (int i = 0; i < value.children.length; ++i)
value.children [ i ] = nodeHelper.read(istream);
return value;
}
/**
* Get the node type code definition.
*/
public static synchronized TypeCode type()
{
// Compute the type code only once.
if (typeCode == null)
{
synchronized (TypeCode.class)
{
if (typeCode == null)
{
// To avoid the infinite recursion loop, the
// recursive reference is handled in specific way.
if (active)
return ORB.init().create_recursive_tc(_id);
active = true;
// List all memebers of the node structure.
StructMember[] members = new StructMember[ 2 ];
TypeCode memberType;
memberType = ORB.init().create_string_tc(0);
members [ 0 ] = new StructMember("name", memberType, null);
memberType = ORB.init().create_recursive_tc("");
members [ 1 ] = new StructMember("children", memberType, null);
typeCode =
ORB.init().create_struct_tc(nodeHelper.id(), "node", members);
active = false;
}
}
}
return typeCode;
}
/**
* Write the node into the common data reprentation (CDR) stream.
*/
public static void write(OutputStream ostream, node value)
{
ostream.write_string(value.name);
ostream.write_long(value.children.length);
for (int i = 0; i < value.children.length; ++i)
nodeHelper.write(ostream, value.children [ i ]);
}
}

View File

@@ -0,0 +1,100 @@
/* nodeHolder.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.TypeCode;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.Streamable;
/**
* The node holder is a wrapper about the node data structure. It
* can be used where the node must be passed both to and from
* the method being called. The same structure holds the tree,
* as it can be represented as a root node with children.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public class nodeHolder
implements Streamable
{
/**
* Stores the node value.
*/
public node value;
/**
* Creates the node holder with the null initial value.
*/
public nodeHolder()
{
}
/**
* Creates the node holder with the given initial value.
*/
public nodeHolder(node initialValue)
{
value = initialValue;
}
/**
* Reads the node value from the common data representation (CDR)
* stream.
*/
public void _read(InputStream in)
{
value = nodeHelper.read(in);
}
/**
* Writes the node value into common data representation (CDR)
* stream.
* @return
*/
public TypeCode _type()
{
return nodeHelper.type();
}
public void _write(OutputStream out)
{
nodeHelper.write(out, value);
}
}

View File

@@ -0,0 +1,70 @@
/* ourUserException.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.UserException;
import org.omg.CORBA.portable.IDLEntity;
/**
* Our user exception, thrown in the tests of handling the exceptions,
* thrown on remote side. The exception contains the user - defined
* data field that is transferred from client to the server when the
* exception is thrown.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public class ourUserException
extends UserException
implements IDLEntity
{
/**
* Our specific field, transferred to client.
*/
public int ourField;
/**
* Create the exception.
*
* @param _ourField the value of our specific field.
*/
public ourUserException(int _ourField)
{
ourField = _ourField;
}
}

View File

@@ -0,0 +1,116 @@
/* ourUserExceptionHelper.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.Any;
import org.omg.CORBA.ORB;
import org.omg.CORBA.StructMember;
import org.omg.CORBA.TCKind;
import org.omg.CORBA.TypeCode;
/**
* The class, providing various helper operations with our user
* exception.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public abstract class ourUserExceptionHelper
{
/**
* The exception repository id. This name is also used to find the
* mapping local CORBA class.
*/
private static String _id =
"IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserException:1.0";
/**
* Get the exception repository id.
*/
public static String id()
{
return _id;
}
/**
* Extract the exception from the given Any where it might be
* wrapped.
*/
public static ourUserException extract(Any a)
{
return read(a.create_input_stream());
}
/**
* Read the exception from the CDR stream.
*/
public static ourUserException read(org.omg.CORBA.portable.InputStream istream)
{
ourUserException value = new ourUserException(0);
// The repository ID is not used
istream.read_string();
value.ourField = istream.read_long();
return value;
}
/**
* Create the type code of this exception.
*/
public static synchronized TypeCode type()
{
StructMember[] members = new StructMember[ 1 ];
TypeCode member = null;
member = ORB.init().get_primitive_tc(TCKind.tk_long);
members [ 0 ] = new StructMember("ourField", member, null);
return ORB.init().create_struct_tc(ourUserExceptionHelper.id(),
"ourUserException", members
);
}
/**
* Write the exception into the CDR stream.
*/
public static void write(org.omg.CORBA.portable.OutputStream ostream,
ourUserException value
)
{
ostream.write_string(id());
ostream.write_long(value.ourField);
}
}

View File

@@ -0,0 +1,61 @@
/* passThis.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
/**
* The data structure, passed from to the server from client in our tests.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public class passThis
implements org.omg.CORBA.portable.IDLEntity
{
/**
* The first string, stored in this structure (defined as
* "narrow string").
*/
public String a;
/**
* The second string, stored in this structure (define as
* "wide" (usually Unicode) string.
*/
public String b;
}

View File

@@ -0,0 +1,102 @@
/* passThisHelper.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.Any;
import org.omg.CORBA.ORB;
import org.omg.CORBA.StructMember;
import org.omg.CORBA.TypeCode;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.OutputStream;
/**
* The helper operations for the {@link passThis}.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public abstract class passThisHelper
{
/**
* The repository ID of the {@link passThis}.
*/
private static String id =
"IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThis:1.0";
/**
* Get the repository id.
*/
public static String id()
{
return id;
}
/**
* Read the structure from the CDR stram.
*/
public static passThis read(InputStream istream)
{
passThis value = new passThis();
value.a = istream.read_string();
value.b = istream.read_wstring();
return value;
}
/**
* Get the type code of this structure.
*/
public static synchronized TypeCode type()
{
StructMember[] members = new StructMember[ 2 ];
TypeCode member = null;
member = ORB.init().create_string_tc(0);
members [ 0 ] = new StructMember("a", member, null);
member = ORB.init().create_string_tc(0);
members [ 1 ] = new StructMember("b", member, null);
return ORB.init().create_struct_tc(passThisHelper.id(), "passThis", members);
}
/**
* Write the structure into the CDR stream.
*/
public static void write(OutputStream ostream, passThis value)
{
ostream.write_string(value.a);
ostream.write_wstring(value.b);
}
}

View File

@@ -0,0 +1,37 @@
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.Streamable;
public final class passThisHolder
implements Streamable
{
public passThis value;
public passThisHolder()
{
}
public passThisHolder(passThis initialValue)
{
value = initialValue;
}
public void _read(InputStream i)
{
value = passThisHelper.read(i);
}
public org.omg.CORBA.TypeCode _type()
{
return passThisHelper.type();
}
public void _write(OutputStream o)
{
passThisHelper.write(o, value);
}
}

View File

@@ -0,0 +1,66 @@
/* returnThis.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.portable.IDLEntity;
/**
* This data structure is returned from the server to client in our tests.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public class returnThis
implements IDLEntity
{
/**
* The string field.
*/
public String c;
/**
* The CORBA array field. This field is handled as the fixed
* size CORBA array, but structures can also have the variable
* size CORBA sequences.
*/
public int[] arra = new int[3];
/**
* The int (CORBA long) field.
*/
public int n;
}

View File

@@ -0,0 +1,115 @@
/* returnThisHelper.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.Any;
import org.omg.CORBA.ORB;
import org.omg.CORBA.StructMember;
import org.omg.CORBA.TCKind;
import org.omg.CORBA.TypeCode;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.OutputStream;
/**
* This class defines the helper operations for {@link returnThis}.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public abstract class returnThisHelper
{
/**
* The repository id.
*/
private static String _id =
"IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThis:1.0";
/**
* Return the repository id.
*/
public static String id()
{
return _id;
}
/**
* Read the structure from the CDR stream.
*/
public static returnThis read(InputStream istream)
{
returnThis value = new returnThis();
value.n = istream.read_long();
value.c = istream.read_wstring();
value.arra = new int[ 3 ];
// Read the fixed size array.
for (int i = 0; i < 3; i++)
value.arra [ i ] = istream.read_long();
return value;
}
/**
* Create the typecode.
*/
public static synchronized TypeCode type()
{
StructMember[] members = new StructMember[ 3 ];
TypeCode member = ORB.init().get_primitive_tc(TCKind.tk_long);
members [ 0 ] = new StructMember("n", member, null);
member = ORB.init().create_string_tc(0);
members [ 1 ] = new StructMember("c", member, null);
member = ORB.init().get_primitive_tc(TCKind.tk_long);
member = ORB.init().create_array_tc(3, member);
members [ 2 ] = new StructMember("arra", member, null);
return ORB.init().create_struct_tc(returnThisHelper.id(), "returnThis",
members
);
}
/**
* Write the structure to the CDR stream.
*/
public static void write(OutputStream ostream, returnThis value)
{
ostream.write_long(value.n);
ostream.write_wstring(value.c);
// Write the fixed size array.
for (int i = 0; i < 3; i++)
ostream.write_long(value.arra [ i ]);
}
}

View File

@@ -0,0 +1,60 @@
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
import org.omg.CORBA.TypeCode;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.Streamable;
/**
* The holder for the structure, returned from the server.
*/
public final class returnThisHolder
implements Streamable
{
/**
* The enclosed structure.
*/
public returnThis value = null;
/**
* Create the empty holder.
*/
public returnThisHolder()
{
}
/**
* Crate the holder with the defined initial value.
*/
public returnThisHolder(returnThis initialValue)
{
value = initialValue;
}
/**
* Read the value from the CDR stream.
*/
public void _read(InputStream in)
{
value = returnThisHelper.read(in);
}
/**
* Get the typecode of this structure.
*/
public TypeCode _type()
{
return returnThisHelper.type();
}
/**
* Write the value from the CDR stream.
* @param out
*/
public void _write(OutputStream out)
{
returnThisHelper.write(out, value);
}
}

View File

@@ -0,0 +1,867 @@
/* Demo.java -- Shows examples of AWT components
Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath examples.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA. */
package gnu.classpath.examples.awt;
import java.awt.*;
import java.awt.List;
import java.awt.event.*;
import java.net.URL;
import java.util.*;
class Demo
{
public static void main(String args[])
{
MainWindow f = new MainWindow();
f.show();
}
static interface SubWindow
{
public void init ();
}
static class PrettyPanel extends Panel
{
Insets myInsets;
public PrettyPanel ()
{
myInsets = new Insets (10, 10, 10, 10);
}
public Insets getInsets ()
{
return myInsets;
}
}
static abstract class PrettyFrame extends Frame
{
public PrettyFrame ()
{
((BorderLayout) getLayout ()).setHgap (5);
((BorderLayout) getLayout ()).setVgap (5);
}
public Insets getInsets()
{
Insets oldInsets = super.getInsets ();
return new Insets (oldInsets.top+10,
oldInsets.left+10,
oldInsets.bottom+10,
oldInsets.right+10);
}
}
static abstract class SubFrame extends PrettyFrame implements SubWindow
{
boolean initted = false;
public void setVisible (boolean visible)
{
if (!initted && visible)
init();
super.setVisible (visible);
}
}
static class MainWindow extends PrettyFrame implements ActionListener
{
Button closeButton;
Hashtable windows;
Vector buttons;
void addSubWindow (String name, SubWindow w)
{
Button b = new Button (name);
b.addActionListener (this);
buttons.addElement (b);
windows.put (b, w);
}
MainWindow ()
{
MenuBar mb = new MenuBar ();
Menu menu = new Menu ("File");
Menu submenu = new Menu ("Testing", true);
submenu.add (new CheckboxMenuItem ("FooBar"));
submenu.add (new CheckboxMenuItem ("BarFoo"));
menu.add (submenu);
menu.add (new MenuItem("Orange"));
MenuItem quit = new MenuItem("Quit", new MenuShortcut('Q'));
quit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
menu.add(quit);
mb.add (menu);
menu = new Menu("Edit", true);
menu.add(new MenuItem("Cut"));
menu.add(new MenuItem("Copy"));
menu.add(new MenuItem("Paste"));
mb.add (menu);
Menu helpMenu = new Menu("Help");
helpMenu.add(new MenuItem("About"));
mb.add(helpMenu);
mb.setHelpMenu(helpMenu);
setMenuBar (mb);
String version = System.getProperty("gnu.classpath.version");
add (new Label ("GNU Classpath " + version), "North");
closeButton = new Button ("Close");
closeButton.addActionListener (this);
closeButton.setFont (new Font ("Serif", Font.BOLD | Font.ITALIC, 18));
add (closeButton, "South");
windows = new Hashtable ();
buttons = new Vector ();
addSubWindow ("Buttons", new ButtonsWindow ());
addSubWindow ("Cursors", new CursorsWindow ());
addSubWindow ("Dialog", new DialogWindow (this));
addSubWindow ("File", new FileWindow (this));
addSubWindow ("Labels", new LabelWindow ());
addSubWindow ("List", new ListWindow ());
addSubWindow ("Radio Buttons", new RadioWindow ());
addSubWindow ("TextField", new TextFieldWindow ());
addSubWindow ("RandomTests", new TestWindow (this));
addSubWindow ("RoundRect", new RoundRectWindow ());
Panel sp = new Panel();
PrettyPanel p = new PrettyPanel();
p.setLayout (new GridLayout (windows.size(), 1));
for (Enumeration e = buttons.elements (); e.hasMoreElements (); )
{
p.add ((Button) e.nextElement ());
}
sp.add (p);
add (sp, "Center");
setTitle ("AWT Demo");
pack();
}
public void actionPerformed (ActionEvent evt)
{
Button source = (Button) evt.getSource ();
if (source==closeButton)
{
dispose();
System.exit (0);
}
Window w = (Window) windows.get (source);
if (w.isVisible ())
w.dispose ();
else
{
if (w instanceof Dialog)
{
w.show();
}
else
{
w.setVisible (true);
}
}
}
}
static class ButtonsWindow extends SubFrame implements ActionListener
{
Button b[] = new Button [9];
public void init ()
{
initted = true;
Panel p = new Panel ();
p.setLayout (new GridLayout (0, 3, 5, 5));
for (int i=0; i<9; i++)
{
b[i]=new Button ("button" + (i+1));
b[i].addActionListener (this);
}
p.add (b[0]);
p.add (b[6]);
p.add (b[4]);
p.add (b[8]);
p.add (b[1]);
p.add (b[7]);
p.add (b[3]);
p.add (b[5]);
p.add (b[2]);
add (p, "North");
Button cb = new Button ("close");
cb.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
dispose();
}
});
add (cb, "South");
setTitle ("Buttons");
pack();
}
public void actionPerformed (ActionEvent evt)
{
Button source = (Button) evt.getSource ();
for (int i = 0; i < 9; i++)
{
if (source == b[i])
{
int i2 = ((i + 1) == 9) ? 0 : (i + 1);
if (b[i2].isVisible())
b[i2].setVisible(false);
else
b[i2].setVisible(true);
}
}
}
}
static class DialogWindow extends Dialog implements SubWindow
{
Label text;
Frame parent;
boolean initted = false;
public DialogWindow (Frame f)
{
super (f, true);
this.parent = f;
addWindowListener (new WindowAdapter ()
{
public void windowClosing (WindowEvent e)
{
text.setVisible (false);
hide ();
}
});
}
public void setVisible (boolean visible)
{
if (!initted && visible)
init();
super.setVisible (visible);
}
public void show ()
{
if (!initted)
init();
super.show ();
}
public void init ()
{
text = new Label ("Dialog Test");
text.setAlignment (Label.CENTER);
add (text, "North");
text.setVisible (false);
Panel p = new PrettyPanel();
Button cb = new Button ("OK");
cb.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e)
{
text.setVisible (false);
hide();
}
});
p.setLayout (new GridLayout (1, 3));
((GridLayout) p.getLayout ()).setHgap (5);
((GridLayout) p.getLayout ()).setVgap (5);
p.add (cb);
Button toggle = new Button ("Toggle");
p.add (toggle);
toggle.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e)
{
if (text.isVisible ())
text.setVisible (false);
else
text.setVisible (true);
doLayout();
}
});
Button subdlg = new Button ("SubDialog");
p.add (subdlg);
subdlg.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e)
{
DialogWindow sw = new DialogWindow (parent);
sw.show ();
}
});
add (p, "South");
setTitle ("Dialog");
pack();
}
}
static class CursorsWindow extends SubFrame implements ItemListener
{
Choice cursorChoice;
Canvas cursorCanvas;
public void init ()
{
cursorChoice = new Choice();
cursorChoice.add ("Default");
cursorChoice.add ("Crosshair");
cursorChoice.add ("Text");
cursorChoice.add ("Wait");
cursorChoice.add ("Southwest Resize");
cursorChoice.add ("Southeast Resize");
cursorChoice.add ("Northwest Resize");
cursorChoice.add ("Northeast Resize");
cursorChoice.add ("North Resize");
cursorChoice.add ("South Resize");
cursorChoice.add ("West Resize");
cursorChoice.add ("East Resize");
cursorChoice.add ("Hand");
cursorChoice.add ("Move");
cursorChoice.addItemListener(this);
add (cursorChoice, "North");
cursorCanvas = new Canvas ()
{
public void paint (Graphics g)
{
Dimension d = this.getSize();
g.setColor(Color.white);
g.fillRect(0, 0, d.width, d.height/2);
g.setColor(Color.black);
g.fillRect(0, d.height/2, d.width, d.height/2);
g.setColor(this.getBackground());
g.fillRect(d.width/3, d.height/3, d.width/3,
d.height/3);
}
};
cursorCanvas.setSize (80,80);
add (cursorCanvas, "Center");
Button cb = new Button ("Close");
cb.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
dispose();
}
});
add (cb, "South");
setTitle ("Cursors");
pack();
}
public void itemStateChanged (ItemEvent e)
{
int index = cursorChoice.getSelectedIndex();
cursorCanvas.setCursor(Cursor.getPredefinedCursor(index));
}
}
static class TextFieldWindow extends SubFrame implements ItemListener
{
Checkbox editable, visible, sensitive;
TextField text;
public void init ()
{
initted = true;
text = new TextField ("hello world");
add (text, "North");
Panel p = new Panel();
p.setLayout (new GridLayout (3, 1));
((GridLayout) p.getLayout ()).setHgap (5);
((GridLayout) p.getLayout ()).setVgap (5);
editable = new Checkbox("Editable", true);
p.add (editable);
editable.addItemListener (this);
visible = new Checkbox("Visible", true);
p.add (visible);
visible.addItemListener (this);
sensitive = new Checkbox("Sensitive", true);
p.add (sensitive);
sensitive.addItemListener (this);
add (p, "Center");
Button cb = new Button ("Close");
cb.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
dispose();
}
});
add (cb, "South");
setTitle ("TextField");
pack();
}
public void itemStateChanged (ItemEvent e)
{
boolean on=true;
if (e.getStateChange () == ItemEvent.DESELECTED)
on=false;
if (e.getSource() == editable)
text.setEditable (on);
if (e.getSource() == visible)
if (on)
text.setEchoChar ((char) 0);
else
text.setEchoChar ('*');
if (e.getSource() == sensitive)
text.setEnabled (on);
}
}
static class FileWindow extends FileDialog implements SubWindow
{
boolean initted = false;
public FileWindow (MainWindow mw)
{
super (mw);
}
public void setVisible (boolean visible)
{
if (!initted && visible)
init();
super.setVisible (visible);
}
public void init()
{
initted = true;
}
}
static class LabelWindow extends SubFrame
{
public void init ()
{
initted = true;
Panel p = new Panel();
p.setLayout (new GridLayout (3, 1));
((GridLayout) p.getLayout ()).setHgap (5);
((GridLayout) p.getLayout ()).setVgap (5);
p.add (new Label ("left justified label", Label.LEFT));
p.add (new Label ("center justified label", Label.CENTER));
p.add (new Label ("right justified label", Label.RIGHT));
add (p, "Center");
Button cb = new Button ("Close");
cb.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
dispose();
}
});
add (cb, "South");
setTitle ("Labels");
pack();
}
}
static class ListWindow extends SubFrame
{
public void init ()
{
initted = true;
Panel p = new Panel ();
p.setLayout (new GridLayout (3, 1));
List l = new List (5, true);
for (int i = 0; i < 10; i++)
l.add ("List item " + i);
p.add (l);
add (p, "Center");
Button cb = new Button ("Close");
cb.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
dispose();
}
});
add (cb, "South");
setTitle ("List");
pack();
}
}
static class RadioWindow extends SubFrame
{
public void init ()
{
initted = true;
Panel p = new Panel();
p.setLayout (new GridLayout (3, 1));
((GridLayout) p.getLayout ()).setHgap (5);
((GridLayout) p.getLayout ()).setVgap (5);
final CheckboxGroup cg = new CheckboxGroup();
final Checkbox[] boxes = new Checkbox[3];
for (int i = 0; i < 3; ++i)
{
boxes[i] = new Checkbox("button" + i, cg, i == 0);
p.add(boxes[i]);
}
add (p, "North");
p = new Panel();
p.setLayout (new GridLayout (1, 3));
((GridLayout) p.getLayout ()).setHgap (5);
((GridLayout) p.getLayout ()).setVgap (5);
for (int i = 0; i < 3; ++i)
{
final int val = i;
Button tweak = new Button ("Set " + i);
tweak.addActionListener(new ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
cg.setSelectedCheckbox(boxes[val]);
}
});
p.add(tweak);
}
add (p, "Center");
Button cb = new Button ("Close");
cb.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
dispose();
}
});
add (cb, "South");
setTitle ("Radio Buttons");
pack();
}
}
static class TestWindow extends SubFrame
{
static int xs = 5, ys = 5;
final Frame parent;
public TestWindow(Frame f)
{
parent = f;
}
public void init()
{
initted = true;
addWindowListener (new WindowAdapter ()
{
public void windowClosing (WindowEvent e)
{
hide ();
}
});
Panel pan = new Panel();
final Label l = new Label ("Pithy Message:");
l.setCursor (Cursor.getPredefinedCursor (Cursor.WAIT_CURSOR));
pan.add (l);
TextField tf = new TextField("Hello world!");
pan.add(tf);
add(pan,"North");
final Image img;
URL imageurl;
imageurl = this.getClass()
.getResource("/gnu/classpath/examples/icons/big-warning.png");
img = Toolkit.getDefaultToolkit().createImage(imageurl);
final Canvas ch = new Canvas()
{
public void paint (Graphics g)
{
g.drawImage(img, xs + 25, ys + 25, this);
Font font = new Font ("Serif", Font.PLAIN, 18);
g.setFont (font);
g.setXORMode (Color.red);
g.drawString("Hi Red!", xs + 15, ys + 10);
g.setColor (Color.blue);
g.drawLine (xs, ys, xs + 100, ys + 100);
}
};
ch.setSize(150, 150);
add(ch, "Center");
final ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
final Panel p = new Panel();
p.add(new Button("Stop"));
p.add(new Button("evil"));
p.add(new Button("hoarders"));
p.add(new Button("use"));
p.add(new Button("GNU!"));
sp.add(p);
add(sp, "South");
Panel east_panel = new Panel();
east_panel.setLayout(new GridLayout (0,1));
CheckboxGroup group = new CheckboxGroup();
Checkbox cb = new Checkbox("one", group, true);
east_panel.add(cb);
cb = new Checkbox("two", group, false);
east_panel.add(cb);
add(east_panel,"East");
final Button wb = new Button();
wb.setLabel("Hello World!");
wb.addActionListener(new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
l.setText ("Hello World!");
final Dialog d = new Dialog(parent);
d.setLayout(new FlowLayout());
d.setModal(true);
Button b = new Button("foobar");
b.addMouseListener(new MouseAdapter()
{
public void mousePressed (MouseEvent me)
{
d.hide ();
}
});
d.add (b);
List ch = new List();
ch.add("Ding");
ch.add("September");
ch.add("Red");
ch.add("Quassia");
ch.add("Pterodactyl");
d.add(ch);
d.pack ();
d.show ();
}
});
wb.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e) {
xs++;
ys++;
ch.repaint ();
}
});
add(wb,"West");
pack();
show();
sp.setScrollPosition (10,0);
Toolkit t = Toolkit.getDefaultToolkit();
t.beep();
}
}
static class RoundRectWindow extends SubFrame
{
public void init ()
{
initted = true;
setTitle("RoundRect");
setLayout(new BorderLayout());
add(new DrawRoundRect(), "West");
Button cb = new Button ("Close");
cb.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
dispose();
}
});
add(cb, "Center");
add(new FillRoundRect(), "East");
pack();
}
static class DrawRoundRect extends Panel
{
public Dimension getPreferredSize()
{
return new Dimension(500, 500);
}
public void paint( Graphics g )
{
// left side
// rectangles should be identical
g.setColor(Color.red);
g.drawRect(50, 50, 300, 100);
g.setColor(Color.black);
g.drawRoundRect(50, 50, 300, 100, 0, 0);
// small round corners
g.setColor(Color.red);
g.drawRect(50, 200, 300, 100);
g.setColor(Color.black);
g.drawRoundRect(50, 200, 300, 100, 25, 25);
// round ends
g.setColor(Color.red);
g.drawRect(50, 350, 300, 100);
g.setColor(Color.black);
g.drawRoundRect(50, 350, 300, 100, 25, 100);
// right side
// circle only
g.setColor(Color.blue);
g.drawOval(375, 50, 100, 100);
// round rectangle should exactly cover circle
g.setColor(Color.blue);
g.drawOval(375, 200, 100, 100);
g.setColor(Color.black);
g.drawRoundRect(375, 200, 100, 100, 100, 100);
// round rectangle should look like a circle
g.setColor(Color.red);
g.drawRect(375, 350, 100, 100);
g.setColor(Color.black);
g.drawRoundRect(375, 350, 100, 100, 100, 100);
}
}
static class FillRoundRect extends Panel
{
public Dimension getPreferredSize()
{
return new Dimension(500, 500);
}
public void paint( Graphics g )
{
// left side
// rectangles should be identical
g.setColor(Color.red);
g.fillRect(50, 50, 300, 100);
g.setColor(Color.black);
g.fillRoundRect(50, 50, 300, 100, 0, 0);
// small round corners
g.setColor(Color.red);
g.fillRect(50, 200, 300, 100);
g.setColor(Color.black);
g.fillRoundRect(50, 200, 300, 100, 25, 25);
// round ends
g.setColor(Color.red);
g.fillRect(50, 350, 300, 100);
g.setColor(Color.black);
g.fillRoundRect(50, 350, 300, 100, 25, 100);
// right side
// circle only
g.setColor(Color.blue);
g.fillOval(375, 50, 100, 100);
// round rectangle should exactly cover circle
g.setColor(Color.blue);
g.fillOval(375, 200, 100, 100);
g.setColor(Color.black);
g.fillRoundRect(375, 200, 100, 100, 100, 100);
// round rectangle should look like a circle
g.setColor(Color.red);
g.fillRect(375, 350, 100, 100);
g.setColor(Color.black);
g.fillRoundRect(375, 350, 100, 100, 100, 100);
}
}
}
}

View File

@@ -0,0 +1,131 @@
/* Demo.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.html;
import gnu.javax.swing.text.html.parser.HTML_401F;
import gnu.xml.dom.html2.DomHTMLParser;
import java.io.IOException;
import java.io.PrintStream;
import java.io.StringReader;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.html2.HTMLDocument;
/**
* This example demonstrates how to parse HTML input into
* org.w3c.dom.html2 document model.
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class Demo
{
/**
* The sample HTML to parse.
*/
static String input = "<!--2-->a<b iD=1>x</b>y<b><i>c</b>d</i>e";
public static void main(String[] args)
{
try
{
// Create a parser, using our DTD.
DomHTMLParser p = new DomHTMLParser(HTML_401F.getInstance());
HTMLDocument d = p.parseDocument(new StringReader(input));
// Print the input HTML.
System.out.println(input);
// Print the parsed data structure.
print(System.out, d, 0);
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
/**
* Print the parsed data structure.
*
* @param stream the output
* @param node the node
* @param ident the identation
*/
static void print(PrintStream stream, Node node, int ident)
{
if (node == null)
return;
StringBuffer tab = new StringBuffer();
stream.println();
for (int i = 0; i < ident; i++)
{
tab.append(' ');
}
stream.print(tab + node.getNodeName());
if (node.getNodeValue() != null)
{
stream.println();
stream.print(tab + " '" + node.getNodeValue() + "'");
}
NamedNodeMap attributes = node.getAttributes();
if (attributes != null && attributes.getLength() != 0)
{
stream.print(' ');
for (int i = 0; i < attributes.getLength(); i++)
{
Node a = attributes.item(i);
stream.print(a.getNodeName() + "='" + a.getNodeValue() + "'");
}
}
ident += 2;
NodeList childs = node.getChildNodes();
if (childs != null)
for (int i = 0; i < childs.getLength(); i++)
{
print(stream, childs.item(i), ident);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 523 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 536 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 563 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 507 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 751 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,85 @@
/* GNULookAndFeel.java -- An example of using the javax.swing UI.
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath examples.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
package gnu.classpath.examples.swing;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.UIDefaults;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.IconUIResource;
import javax.swing.plaf.basic.BasicLookAndFeel;
public class GNULookAndFeel extends BasicLookAndFeel
{
static Color blueGray = new Color(0xdc, 0xda, 0xd5);
public boolean isNativeLookAndFeel() { return true; }
public boolean isSupportedLookAndFeel() { return true; }
public String getDescription() { return "GNU Look and Feel"; }
public String getID() { return "GNULookAndFeel"; }
public String getName() { return "GNU"; }
static UIDefaults LAF_defaults;
private final static String iconspath = "/gnu/javax/swing/plaf/gtk/icons/";
public UIDefaults getDefaults()
{
if (LAF_defaults == null)
{
LAF_defaults = super.getDefaults();
Object[] myDefaults = new Object[] {
"Button.background", new ColorUIResource(blueGray),
"CheckBox.background", new ColorUIResource(blueGray),
"CheckBoxMenuItem.background", new ColorUIResource(blueGray),
"ToolBar.background", new ColorUIResource(blueGray),
"Panel.background", new ColorUIResource(blueGray),
"Slider.background", new ColorUIResource(blueGray),
"OptionPane.background", new ColorUIResource(blueGray),
"ProgressBar.background", new ColorUIResource(blueGray),
"TabbedPane.background", new ColorUIResource(blueGray),
"Label.background", new ColorUIResource(blueGray),
"Menu.background", new ColorUIResource(blueGray),
"MenuBar.background", new ColorUIResource(blueGray),
"MenuItem.background", new ColorUIResource(blueGray),
"ScrollBar.background", new ColorUIResource(blueGray),
"Tree.closedIcon",
new IconUIResource(new ImageIcon
(getClass().getResource
(iconspath + "TreeClosed.png"))),
"Tree.leafIcon",
new IconUIResource(new ImageIcon
(getClass().getResource
(iconspath + "TreeLeaf.png"))),
"Tree.openIcon",
new IconUIResource(new ImageIcon
(getClass().getResource
(iconspath + "TreeOpen.png"))),
};
LAF_defaults.putDefaults(myDefaults);
}
return LAF_defaults;
}
}