mirror of git://gcc.gnu.org/git/gcc.git
parent
acff2da93c
commit
9b044d1951
|
|
@ -0,0 +1,3 @@
|
|||
<?xml version='1.0'?>
|
||||
<?eclipse-cdt version="2.0"?>
|
||||
<cdtproject/>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0'?>
|
||||
<launchConfiguration type='org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType'><stringAttribute key='org.eclipse.debug.core.ATTR_REFRESH_SCOPE' value='${working_set:<?xml version="1.0" encoding="UTF-8"?> <launchConfigurationWorkingSet factoryID="org.eclipse.ui.internal.WorkingSetFactory" name="working set" editPageId="org.eclipse.ui.resourceWorkingSetPage"> <item factoryID="org.eclipse.ui.internal.model.ResourceFactory" path="/classpath/native" type="2"/> </launchConfigurationWorkingSet>}'/><stringAttribute key='org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS' value='full,incremental,'/><stringAttribute key='org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE' value='${working_set:<?xml version="1.0" encoding="UTF-8"?> <launchConfigurationWorkingSet factoryID="org.eclipse.ui.internal.WorkingSetFactory" name="workingSet" editPageId="org.eclipse.ui.resourceWorkingSetPage"> <item factoryID="org.eclipse.ui.internal.model.ResourceFactory" path="/classpath/native" type="2"/> </launchConfigurationWorkingSet>}'/><stringAttribute key='org.eclipse.ui.externaltools.ATTR_LOCATION' value='${system_path:make}'/><booleanAttribute key='org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED' value='true'/><stringAttribute key='org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY' value='${build_project}'/><stringAttribute key='org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS' value='-C ${build_project}/native all install'/><booleanAttribute key='org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND' value='false'/><booleanAttribute key='org.eclipse.debug.core.appendEnvironmentVariables' value='true'/></launchConfiguration>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0'?>
|
||||
<launchConfiguration type='org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType'><stringAttribute key='org.eclipse.debug.core.ATTR_REFRESH_SCOPE' value='${working_set:<?xml version="1.0" encoding="UTF-8"?> <launchConfigurationWorkingSet factoryID="org.eclipse.ui.internal.WorkingSetFactory" name="working set" editPageId="org.eclipse.ui.resourceWorkingSetPage"> <item factoryID="org.eclipse.ui.internal.model.ResourceFactory" path="/classpath/java/util" type="2"/> </launchConfigurationWorkingSet>}'/><stringAttribute key='org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS' value='full,incremental,'/><stringAttribute key='org.eclipse.ui.externaltools.ATTR_LOCATION' value='${system_path:make}'/><booleanAttribute key='org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED' value='true'/><stringAttribute key='org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY' value='${build_project}'/><stringAttribute key='org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS' value='-C ${build_project}/lib ../java/util/LocaleData.java'/><booleanAttribute key='org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND' value='false'/><booleanAttribute key='org.eclipse.debug.core.appendEnvironmentVariables' value='true'/></launchConfiguration>
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
#include "include/layout.wml"
|
||||
|
||||
<subject "GNU Classpath Bug Reports">
|
||||
|
||||
<box>
|
||||
|
||||
<boxtitle>GNU Classpath::Bugs</boxtitle>
|
||||
<boxitem>
|
||||
Unfortunately GNU Classpath is not bug free yet.
|
||||
<br>
|
||||
But you can help!
|
||||
<br>
|
||||
If you find a bug please report it here.
|
||||
</boxitem>
|
||||
|
||||
<boxtitle>Query</boxtitle>
|
||||
<boxitem>
|
||||
Please first check the following lists:
|
||||
<ul>
|
||||
<li><a href="http://gcc.gnu.org/bugzilla/query.cgi?product=classpath">Query bugs</a></li>
|
||||
<li><a href="http://gcc.gnu.org/bugzilla/buglist.cgi?product=classpath&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=SUSPENDED&bug_status=WAITING&bug_status=REOPENED">All open bugs</a></li>
|
||||
<li><a href="http://gcc.gnu.org/bugzilla/duplicates.cgi?sortby=count&product=classpath">Most Frequently Reported Bugs</a></li>
|
||||
</ul>
|
||||
<p>
|
||||
</boxitem>
|
||||
|
||||
<boxtitle>Report</boxtitle>
|
||||
<boxitem>
|
||||
If your bug wasn't in any of the above lists, please
|
||||
<ul>
|
||||
<li><a href="http://gcc.gnu.org/bugzilla/enter_bug.cgi?product=classpath">Report it</a></li>
|
||||
<ul>
|
||||
<p>
|
||||
</boxitem>
|
||||
|
||||
<boxtitle>Overview</boxtitle>
|
||||
<boxitem>
|
||||
You can also look at some pretty
|
||||
<ul>
|
||||
<li><a href="http://gcc.gnu.org/bugzilla/reports.cgi?product=classpath&datasets=NEW%3A&datasets=ASSIGNED%3A&datasets=REOPENED%3A&datasets=UNCONFIRMED%3A&datasets=RESOLVED%3A&datasets=VERIFIED%3A&datasets=CLOSED%3A&datasets=FIXED%3A&datasets=INVALID%3A&datasets=WONTFIX%3A&datasets=DUPLICATE%3A&datasets=WORKSFORME%3A">Status Counts</a></li>
|
||||
<li><a href="http://gcc.gnu.org/bugzilla/report.cgi?bug_file_loc_type=allwordssubstr&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=SUSPENDED&bug_status=WAITING&bug_status=REOPENED&bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&cumulate=1&gccbuild_type=allwordssubstr&gcchost_type=allwordssubstr&gcctarget_type=allwordssubstr&keywords_type=allwords&known_to_fail_type=allwordssubstr&known_to_work_type=allwordssubstr&long_desc_type=substring&product=classpath&short_desc_type=allwordssubstr&x_axis_field=component&y_axis_field=bug_status&width=600&height=350&action=wrap&format=table">Component/Status Tables</a></li>
|
||||
</ul>
|
||||
<p>
|
||||
</boxitem>
|
||||
|
||||
</box>
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
# @configure_input@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
includedir = @includedir@
|
||||
libdir = @libdir@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
|
||||
all: gnu/classpath/examples/jawt/DemoJAWT.class libDemoJAWT.so
|
||||
@echo "RUN with:"
|
||||
@echo " LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:.:$(pkglibdir) jamvm \\"
|
||||
@echo " gnu.classpath.examples.jawt.DemoJAWT"
|
||||
|
||||
gnu/classpath/examples/jawt/DemoJAWT.class: gnu/classpath/examples/jawt/DemoJAWT.java
|
||||
gcj -C gnu/classpath/examples/jawt/DemoJAWT.java
|
||||
|
||||
DemoJAWT.h: gnu/classpath/examples/jawt/DemoJAWT.class
|
||||
gcjh -jni gnu.classpath.examples.jawt.DemoJAWT -o DemoJAWT.h
|
||||
|
||||
libDemoJAWT.so: gnu/classpath/examples/jawt/DemoJAWT.c DemoJAWT.h
|
||||
gcc -g -O0 -Wall -I. -I/usr/X11R6/include -L. -L/usr/X11R6/lib \
|
||||
-I$(includedir) -L$(pkglibdir) \
|
||||
-lX11 -ljawtgnu -shared -o libDemoJAWT.so \
|
||||
gnu/classpath/examples/jawt/DemoJAWT.c
|
||||
|
||||
clean:
|
||||
rm -f DemoJAWT.h
|
||||
rm -f gnu/classpath/examples/jawt/DemoJAWT*.class
|
||||
rm -f libDemoJAWT.so
|
||||
|
|
@ -0,0 +1,652 @@
|
|||
/* Demo.java -- And example of copy/paste datatransfer
|
||||
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.datatransfer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.datatransfer.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* An example how datatransfer works for copying and pasting data to
|
||||
* and from other programs.
|
||||
*/
|
||||
class Demo
|
||||
extends Frame
|
||||
implements ActionListener, ItemListener, FlavorListener
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
new Demo();
|
||||
}
|
||||
|
||||
private TextArea text;
|
||||
private Button copyText;
|
||||
private Button pasteText;
|
||||
|
||||
private ImageComponent image;
|
||||
private Button copyImage;
|
||||
private Button pasteImage;
|
||||
|
||||
private ObjectComponent object;
|
||||
private Button copyObject;
|
||||
private Button pasteObject;
|
||||
|
||||
private FilesComponent files;
|
||||
private Button copyFiles;
|
||||
private Button pasteFiles;
|
||||
|
||||
private FlavorsComponent flavors;
|
||||
private FlavorDetailsComponent details;
|
||||
|
||||
private Demo()
|
||||
{
|
||||
super("GNU Classpath datatransfer");
|
||||
|
||||
/* Add all the different panel to the main window in one row. */
|
||||
setLayout(new GridLayout(5, 1, 10, 10));
|
||||
add(createTextPanel());
|
||||
add(createImagePanel());
|
||||
add(createObjectPanel());
|
||||
add(createFilesPanel());
|
||||
add(createFlavorsPanel());
|
||||
|
||||
/* Add listeners for the various buttons and events we are
|
||||
interested in. */
|
||||
addWindowListener(new WindowAdapter ()
|
||||
{
|
||||
public void windowClosing (WindowEvent e)
|
||||
{
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
flavors.addItemListener(this);
|
||||
Toolkit t = Toolkit.getDefaultToolkit();
|
||||
Clipboard c = t.getSystemClipboard();
|
||||
c.addFlavorListener(this);
|
||||
|
||||
/* Show time! */
|
||||
pack();
|
||||
show();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Text Panel will show simple text that can be copied and pasted.
|
||||
*/
|
||||
private Panel createTextPanel()
|
||||
{
|
||||
Panel textPanel = new Panel();
|
||||
textPanel.setLayout(new BorderLayout());
|
||||
text = new TextArea("GNU Everywhere!",
|
||||
2, 80,
|
||||
TextArea.SCROLLBARS_VERTICAL_ONLY);
|
||||
text.setEditable(false);
|
||||
text.setEnabled(true);
|
||||
Panel textButtons = new Panel();
|
||||
textButtons.setLayout(new FlowLayout());
|
||||
copyText = new Button("Copy text");
|
||||
copyText.addActionListener(this);
|
||||
pasteText = new Button("Paste text");
|
||||
pasteText.addActionListener(this);
|
||||
textButtons.add(copyText);
|
||||
textButtons.add(pasteText);
|
||||
textPanel.add(text, BorderLayout.CENTER);
|
||||
textPanel.add(textButtons, BorderLayout.SOUTH);
|
||||
return textPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Image Panel shows an image that can be copied to another
|
||||
* program or be replaced by pasting in an image from another
|
||||
* application.
|
||||
*/
|
||||
private Panel createImagePanel()
|
||||
{
|
||||
Panel imagePanel = new Panel();
|
||||
imagePanel.setLayout(new BorderLayout());
|
||||
URL imageurl = this.getClass()
|
||||
.getResource("/gnu/classpath/examples/icons/big-fullscreen.png");
|
||||
Image img = Toolkit.getDefaultToolkit().createImage(imageurl);
|
||||
image = new ImageComponent(img);
|
||||
Panel imageButtons = new Panel();
|
||||
copyImage = new Button("Copy image");
|
||||
copyImage.addActionListener(this);
|
||||
pasteImage = new Button("Paste image");
|
||||
pasteImage.addActionListener(this);
|
||||
imageButtons.add(copyImage);
|
||||
imageButtons.add(pasteImage);
|
||||
imagePanel.add(image, BorderLayout.CENTER);
|
||||
imagePanel.add(imageButtons, BorderLayout.SOUTH);
|
||||
return imagePanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Object Panel holds a simple (Point) object that can be copied
|
||||
* and pasted to another program that supports exchanging serialized
|
||||
* objects.
|
||||
*/
|
||||
private Panel createObjectPanel()
|
||||
{
|
||||
Panel objectPanel = new Panel();
|
||||
objectPanel.setLayout(new BorderLayout());
|
||||
Random random = new Random();
|
||||
int x = (byte) random.nextInt();
|
||||
int y = (byte) random.nextInt();
|
||||
object = new ObjectComponent(new Point(x, y));
|
||||
Panel objectButtons = new Panel();
|
||||
copyObject = new Button("Copy object");
|
||||
copyObject.addActionListener(this);
|
||||
pasteObject = new Button("Paste object");
|
||||
pasteObject.addActionListener(this);
|
||||
objectButtons.add(copyObject);
|
||||
objectButtons.add(pasteObject);
|
||||
objectPanel.add(object, BorderLayout.CENTER);
|
||||
objectPanel.add(objectButtons, BorderLayout.SOUTH);
|
||||
return objectPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Files Panel shows the files from the current working
|
||||
* directory. They can be copied and pasted between other
|
||||
* applications that support the exchange of file lists.
|
||||
*/
|
||||
private Panel createFilesPanel()
|
||||
{
|
||||
Panel filesPanel = new Panel();
|
||||
filesPanel.setLayout(new BorderLayout());
|
||||
files = new FilesComponent(new File(".").listFiles());
|
||||
Panel filesButtons = new Panel();
|
||||
copyFiles = new Button("Copy files");
|
||||
copyFiles.addActionListener(this);
|
||||
pasteFiles = new Button("Paste files");
|
||||
pasteFiles.addActionListener(this);
|
||||
filesButtons.add(copyFiles);
|
||||
filesButtons.add(pasteFiles);
|
||||
filesPanel.add(files, BorderLayout.CENTER);
|
||||
filesPanel.add(filesButtons, BorderLayout.SOUTH);
|
||||
return filesPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Flavors Panel shows the different formats (mime-types) that
|
||||
* data on the clipboard is available in. By clicking on a flavor
|
||||
* details about the representation class and object is given.
|
||||
*/
|
||||
private Panel createFlavorsPanel()
|
||||
{
|
||||
Panel flavorsPanel = new Panel();
|
||||
flavorsPanel.setLayout(new BorderLayout());
|
||||
Label flavorsHeader = new Label("Flavors on clipboard:");
|
||||
Toolkit t = Toolkit.getDefaultToolkit();
|
||||
Clipboard c = t.getSystemClipboard();
|
||||
DataFlavor[] dataflavors = c.getAvailableDataFlavors();
|
||||
flavors = new FlavorsComponent(dataflavors);
|
||||
details = new FlavorDetailsComponent(null);
|
||||
flavorsPanel.add(flavorsHeader, BorderLayout.NORTH);
|
||||
flavorsPanel.add(flavors, BorderLayout.CENTER);
|
||||
flavorsPanel.add(details, BorderLayout.SOUTH);
|
||||
return flavorsPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* FlavorListener implementation that updates the Flavors Panel
|
||||
* whenever a change in the mime-types available has been detected.
|
||||
*/
|
||||
public void flavorsChanged(FlavorEvent event)
|
||||
{
|
||||
Toolkit t = Toolkit.getDefaultToolkit();
|
||||
Clipboard c = t.getSystemClipboard();
|
||||
DataFlavor[] dataflavors = c.getAvailableDataFlavors();
|
||||
flavors.setFlavors(dataflavors);
|
||||
details.setDataFlavor(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* ItemChangeListener implementation that updates the flavor details
|
||||
* whenever the user selects a different representation of the data
|
||||
* available on the clipboard.
|
||||
*/
|
||||
public void itemStateChanged(ItemEvent evt)
|
||||
{
|
||||
DataFlavor df = null;
|
||||
String s = flavors.getSelectedItem();
|
||||
if (s != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
df = new DataFlavor(s);
|
||||
}
|
||||
catch (ClassNotFoundException cnfe)
|
||||
{
|
||||
cnfe.printStackTrace();
|
||||
}
|
||||
}
|
||||
details.setDataFlavor(df);
|
||||
}
|
||||
|
||||
/**
|
||||
* ActionListener implementations that will copy or past data
|
||||
* to/from the clipboard when the user requests that for the text,
|
||||
* image, object of file component.
|
||||
*/
|
||||
public void actionPerformed (ActionEvent evt)
|
||||
{
|
||||
Button b = (Button) evt.getSource();
|
||||
Toolkit t = Toolkit.getDefaultToolkit();
|
||||
Clipboard c = t.getSystemClipboard();
|
||||
if (b == copyText)
|
||||
c.setContents(new StringSelection(text.getText()), null);
|
||||
|
||||
if (b == pasteText)
|
||||
{
|
||||
String s = null;
|
||||
try
|
||||
{
|
||||
s = (String) c.getData(DataFlavor.stringFlavor);
|
||||
}
|
||||
catch (UnsupportedFlavorException dfnse)
|
||||
{
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
catch (ClassCastException cce)
|
||||
{
|
||||
}
|
||||
if (s == null)
|
||||
t.beep();
|
||||
else
|
||||
text.setText(s);
|
||||
}
|
||||
|
||||
if (b == copyImage)
|
||||
c.setContents(new ImageSelection(image.getImage()), null);
|
||||
|
||||
if (b == pasteImage)
|
||||
{
|
||||
Image i = null;
|
||||
try
|
||||
{
|
||||
i = (Image) c.getData(DataFlavor.imageFlavor);
|
||||
}
|
||||
catch (UnsupportedFlavorException dfnse)
|
||||
{
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
catch (ClassCastException cce)
|
||||
{
|
||||
}
|
||||
if (i == null)
|
||||
t.beep();
|
||||
else
|
||||
image.setImage(i);
|
||||
}
|
||||
|
||||
if (b == copyObject)
|
||||
c.setContents(new ObjectSelection(object.getObject()), null);
|
||||
|
||||
if (b == pasteObject)
|
||||
{
|
||||
Serializable o = null;
|
||||
try
|
||||
{
|
||||
o = (Serializable) c.getData(ObjectSelection.objFlavor);
|
||||
}
|
||||
catch (UnsupportedFlavorException dfnse)
|
||||
{
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
catch (ClassCastException cce)
|
||||
{
|
||||
}
|
||||
if (o == null)
|
||||
t.beep();
|
||||
else
|
||||
object.setObject(o);
|
||||
}
|
||||
|
||||
if (b == copyFiles)
|
||||
c.setContents(new FilesSelection(files.getFiles()), null);
|
||||
|
||||
if (b == pasteFiles)
|
||||
{
|
||||
java.util.List fs = null;
|
||||
try
|
||||
{
|
||||
fs = (java.util.List) c.getData(DataFlavor.javaFileListFlavor);
|
||||
}
|
||||
catch (UnsupportedFlavorException dfnse)
|
||||
{
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
catch (ClassCastException cce)
|
||||
{
|
||||
}
|
||||
if (fs == null)
|
||||
t.beep();
|
||||
else
|
||||
files.setFiles(fs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple awt component that shows an settable image.
|
||||
*/
|
||||
static class ImageComponent extends Component
|
||||
{
|
||||
private Image image;
|
||||
|
||||
ImageComponent(Image image)
|
||||
{
|
||||
setSize(20, 20);
|
||||
setImage(image);
|
||||
}
|
||||
|
||||
Image getImage()
|
||||
{
|
||||
return image;
|
||||
}
|
||||
|
||||
void setImage(Image image)
|
||||
{
|
||||
this.image = image;
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple awt component that shows a settable Serializable object.
|
||||
*/
|
||||
static class ObjectComponent extends TextArea
|
||||
{
|
||||
private Serializable object;
|
||||
|
||||
ObjectComponent(Serializable object)
|
||||
{
|
||||
super("", 2, 80, TextArea.SCROLLBARS_NONE);
|
||||
setEditable(false);
|
||||
setEnabled(false);
|
||||
setObject(object);
|
||||
}
|
||||
|
||||
Serializable getObject()
|
||||
{
|
||||
return object;
|
||||
}
|
||||
|
||||
void setObject(Serializable object)
|
||||
{
|
||||
this.object = object;
|
||||
setText("Class: " + object.getClass().getName()
|
||||
+ "\n"
|
||||
+ "toString(): " + object.toString());
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple awt component that shows a settable list of Files.
|
||||
*/
|
||||
static class FilesComponent extends List
|
||||
{
|
||||
private File[] files;
|
||||
|
||||
FilesComponent(File[] files)
|
||||
{
|
||||
super(4, true);
|
||||
setFiles(files);
|
||||
}
|
||||
|
||||
File[] getFiles()
|
||||
{
|
||||
String[] strings = getSelectedItems();
|
||||
if (strings == null || strings.length == 0)
|
||||
return (File[]) files.clone();
|
||||
|
||||
File[] fs = new File[strings.length];
|
||||
for (int i = 0; i < strings.length; i++)
|
||||
fs[i] = new File(strings[i]);
|
||||
return fs;
|
||||
}
|
||||
|
||||
void setFiles(File[] files)
|
||||
{
|
||||
this.files = files;
|
||||
removeAll();
|
||||
for (int i = 0; i < files.length; i++)
|
||||
{
|
||||
addItem(files[i].toString());
|
||||
select(i);
|
||||
}
|
||||
}
|
||||
|
||||
void setFiles(java.util.List list)
|
||||
{
|
||||
File[] fs = new File[list.size()];
|
||||
int i = 0;
|
||||
Iterator it = list.iterator();
|
||||
while (it.hasNext())
|
||||
fs[i++] = (File) it.next();
|
||||
|
||||
setFiles(fs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple awt component that shows a settable list of DataFlavors.
|
||||
*/
|
||||
static class FlavorsComponent extends List
|
||||
{
|
||||
FlavorsComponent(DataFlavor[] flavors)
|
||||
{
|
||||
super(4);
|
||||
setFlavors(flavors);
|
||||
}
|
||||
|
||||
void setFlavors(DataFlavor[] flavors)
|
||||
{
|
||||
removeAll();
|
||||
for (int i = 0; i < flavors.length; i++)
|
||||
{
|
||||
addItem(flavors[i].getMimeType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple awt component that shows the details for and an object as
|
||||
* found on the system clipboard as represented by a given
|
||||
* DataFlavor.
|
||||
*/
|
||||
static class FlavorDetailsComponent extends TextArea
|
||||
{
|
||||
private DataFlavor df;
|
||||
|
||||
FlavorDetailsComponent(DataFlavor df)
|
||||
{
|
||||
super("", 2, 80, TextArea.SCROLLBARS_NONE);
|
||||
setEditable(false);
|
||||
setEnabled(false);
|
||||
setDataFlavor(df);
|
||||
}
|
||||
|
||||
void setDataFlavor(DataFlavor df)
|
||||
{
|
||||
if (df == this.df
|
||||
|| (df != null && df.equals(this.df)))
|
||||
return;
|
||||
|
||||
this.df = df;
|
||||
|
||||
if (df == null)
|
||||
setText("No flavor selected");
|
||||
else
|
||||
{
|
||||
Object o = null;
|
||||
Throwable exception = null;
|
||||
try
|
||||
{
|
||||
Toolkit t = Toolkit.getDefaultToolkit();
|
||||
Clipboard c = t.getSystemClipboard();
|
||||
o = c.getData(df);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
exception = t;
|
||||
}
|
||||
if (o != null)
|
||||
{
|
||||
setText("Data: " + o.getClass().getName()
|
||||
+ "\n"
|
||||
+ o);
|
||||
}
|
||||
else
|
||||
{
|
||||
setText("Error retrieving: " + df
|
||||
+ "\n"
|
||||
+ exception != null ? exception.toString() : "");
|
||||
}
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class to put an Image on a clipboard as
|
||||
* DataFlavor.imageFlavor.
|
||||
*/
|
||||
static class ImageSelection implements Transferable
|
||||
{
|
||||
private final Image img;
|
||||
|
||||
ImageSelection(Image img)
|
||||
{
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
static DataFlavor[] flavors = new DataFlavor[] { DataFlavor.imageFlavor };
|
||||
public DataFlavor[] getTransferDataFlavors()
|
||||
{
|
||||
return (DataFlavor[]) flavors.clone();
|
||||
}
|
||||
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor)
|
||||
{
|
||||
return flavor.equals(DataFlavor.imageFlavor);
|
||||
}
|
||||
|
||||
public Object getTransferData(DataFlavor flavor)
|
||||
throws UnsupportedFlavorException
|
||||
{
|
||||
if (!isDataFlavorSupported(flavor))
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
|
||||
return img;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class to put an Object on a clipboard as Serializable
|
||||
* object.
|
||||
*/
|
||||
static class ObjectSelection implements Transferable
|
||||
{
|
||||
private final Serializable obj;
|
||||
|
||||
ObjectSelection(Serializable obj)
|
||||
{
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
static DataFlavor objFlavor = new DataFlavor(Serializable.class,
|
||||
"Serialized Object");
|
||||
static DataFlavor[] flavors = new DataFlavor[] { objFlavor };
|
||||
public DataFlavor[] getTransferDataFlavors()
|
||||
{
|
||||
return (DataFlavor[]) flavors.clone();
|
||||
}
|
||||
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor)
|
||||
{
|
||||
return flavor.equals(objFlavor);
|
||||
}
|
||||
|
||||
public Object getTransferData(DataFlavor flavor)
|
||||
throws UnsupportedFlavorException
|
||||
{
|
||||
if (!isDataFlavorSupported(flavor))
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class to put a List of Files on the clipboard as
|
||||
* DataFlavor.javaFileListFlavor.
|
||||
*/
|
||||
static class FilesSelection implements Transferable
|
||||
{
|
||||
private final File[] files;
|
||||
|
||||
FilesSelection(File[] files)
|
||||
{
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
static DataFlavor[] flavors = new DataFlavor[]
|
||||
{ DataFlavor.javaFileListFlavor };
|
||||
public DataFlavor[] getTransferDataFlavors()
|
||||
{
|
||||
return (DataFlavor[]) flavors.clone();
|
||||
}
|
||||
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor)
|
||||
{
|
||||
return flavor.equals(DataFlavor.javaFileListFlavor);
|
||||
}
|
||||
|
||||
public Object getTransferData(DataFlavor flavor)
|
||||
throws UnsupportedFlavorException
|
||||
{
|
||||
if (!isDataFlavorSupported(flavor))
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
|
||||
return Arrays.asList(files);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
/* DemoJAWT.c -- native portion of AWT Native Interface demo
|
||||
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. */
|
||||
|
||||
#include "DemoJAWT.h"
|
||||
#include "jawt_md.h"
|
||||
#include <string.h>
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_gnu_classpath_examples_jawt_DemoJAWT_paintIt (JNIEnv* env,
|
||||
jobject canvas,
|
||||
jobject graphics,
|
||||
jboolean on)
|
||||
{
|
||||
JAWT awt;
|
||||
JAWT_DrawingSurface* surface;
|
||||
JAWT_DrawingSurfaceInfo* surface_info;
|
||||
JAWT_X11DrawingSurfaceInfo* surface_info_x11;
|
||||
jint lock;
|
||||
GC gc;
|
||||
int c;
|
||||
char* test_string = "JAWT";
|
||||
XColor orange;
|
||||
XColor yellow;
|
||||
XColor blue;
|
||||
Display* display;
|
||||
Drawable drawable;
|
||||
Status status;
|
||||
|
||||
awt.version = JAWT_VERSION_1_3;
|
||||
if (JAWT_GetAWT (env, &awt) == JNI_FALSE)
|
||||
{
|
||||
printf ("couldn't find AWT\n");
|
||||
return;
|
||||
}
|
||||
|
||||
surface = awt.GetDrawingSurface (env, canvas);
|
||||
if (surface == NULL)
|
||||
{
|
||||
printf ("drawing surface is NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
lock = surface->Lock (surface);
|
||||
if ((lock & JAWT_LOCK_ERROR) != 0)
|
||||
{
|
||||
printf ("couldn't lock drawing surface\n");
|
||||
awt.FreeDrawingSurface (surface);
|
||||
return;
|
||||
}
|
||||
|
||||
surface_info = surface->GetDrawingSurfaceInfo (surface);
|
||||
if (surface_info == NULL)
|
||||
{
|
||||
printf ("couldn't get surface information\n");
|
||||
surface->Unlock (surface);
|
||||
awt.FreeDrawingSurface (surface);
|
||||
return;
|
||||
}
|
||||
|
||||
surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface_info->platformInfo;
|
||||
|
||||
display = surface_info_x11->display;
|
||||
drawable = surface_info_x11->drawable;
|
||||
|
||||
gc = XCreateGC (display, drawable, 0, 0);
|
||||
XSetBackground (display, gc, 0);
|
||||
|
||||
orange.red = 254 * 65535 / 255;
|
||||
orange.green = 90 * 65535 / 255;
|
||||
orange.blue = 16 * 65535 / 255;
|
||||
|
||||
/* assume color lookups succeed */
|
||||
status = XAllocColor (display, DefaultColormap (display,
|
||||
DefaultScreen (display)),
|
||||
&orange);
|
||||
|
||||
if (!status)
|
||||
{
|
||||
printf ("color allocation failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
yellow.red = 255 * 65535 / 255;
|
||||
yellow.green = 255 * 65535 / 255;
|
||||
yellow.blue = 0 * 65535 / 255;
|
||||
|
||||
XAllocColor (display, DefaultColormap (display,
|
||||
DefaultScreen (display)),
|
||||
&yellow);
|
||||
|
||||
if (!status)
|
||||
{
|
||||
printf ("color allocation failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
blue.red = 16 * 65535 / 255;
|
||||
blue.green = 30 * 65535 / 255;
|
||||
blue.blue = 137 * 65535 / 255;
|
||||
|
||||
XAllocColor (display, DefaultColormap (display,
|
||||
DefaultScreen (display)),
|
||||
&blue);
|
||||
|
||||
if (!status)
|
||||
{
|
||||
printf ("color allocation failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
for (c = 5; c >= 0; c--)
|
||||
{
|
||||
if (c % 2 == on)
|
||||
XSetForeground (display, gc, yellow.pixel);
|
||||
else
|
||||
XSetForeground (display, gc, orange.pixel);
|
||||
|
||||
XFillArc (display, drawable, gc, 140 - c * 15, 140 - c * 15, c * 30, c * 30, 0, 360 * 64);
|
||||
}
|
||||
|
||||
XSetForeground (display, gc, blue.pixel);
|
||||
XDrawString (display, drawable,
|
||||
gc, 129, 145, test_string, strlen (test_string));
|
||||
|
||||
cleanup:
|
||||
XFreeGC (display, gc);
|
||||
|
||||
surface->FreeDrawingSurfaceInfo (surface_info);
|
||||
|
||||
surface->Unlock (surface);
|
||||
|
||||
awt.FreeDrawingSurface (surface);
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/* DemoJAWT.java -- AWT Native Interface demo
|
||||
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.jawt;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class DemoJAWT extends Canvas
|
||||
{
|
||||
static
|
||||
{
|
||||
System.loadLibrary ("DemoJAWT");
|
||||
}
|
||||
|
||||
public native void paintIt (Graphics g, boolean on);
|
||||
|
||||
public void paint (Graphics g)
|
||||
{
|
||||
paintIt (g, on);
|
||||
}
|
||||
|
||||
private boolean on;
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Frame f = new Frame ("GNU Classpath JAWT Demo");
|
||||
|
||||
f.setBounds (0, 0, 300, 300);
|
||||
|
||||
f.setResizable (false);
|
||||
|
||||
DemoJAWT jawtDemo = new DemoJAWT ();
|
||||
f.add (jawtDemo);
|
||||
|
||||
f.addWindowListener (new WindowAdapter ()
|
||||
{
|
||||
public void windowClosing (WindowEvent evt)
|
||||
{
|
||||
System.exit (0);
|
||||
}
|
||||
});
|
||||
|
||||
f.show ();
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep (500);
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
jawtDemo.on = ! jawtDemo.on;
|
||||
f.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
/* noHeaderInput.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.CORBA.CDR;
|
||||
|
||||
import org.omg.CORBA.CustomMarshal;
|
||||
import org.omg.CORBA.DataInputStream;
|
||||
import org.omg.CORBA.MARSHAL;
|
||||
import org.omg.CORBA.portable.BoxedValueHelper;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.CORBA.portable.ValueFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Substitutes the main stream in factories when the header is already
|
||||
* behind. Overrides methods that may be invoked from the factory,
|
||||
* forcing not to read the header if called first time on this stream.
|
||||
*
|
||||
* This stream reverts to default behavior if one or more call are
|
||||
* made (reading value types that are nested fields of the value type).
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
class noHeaderInput
|
||||
extends cdrBufInput
|
||||
implements DataInputStream
|
||||
{
|
||||
/**
|
||||
* If true, this is not the first call.
|
||||
*/
|
||||
boolean notFirst;
|
||||
|
||||
/**
|
||||
* Create an instance, reading from the given buffer.
|
||||
*/
|
||||
public noHeaderInput(byte[] buffer)
|
||||
{
|
||||
super(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read when knowning the class instance.
|
||||
*/
|
||||
public Serializable read_value(Class clz)
|
||||
{
|
||||
if (notFirst)
|
||||
return super.read_value(clz);
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
notFirst = true;
|
||||
return read_value((Serializable) clz.newInstance());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MARSHAL m = new MARSHAL("Unable to create an instance");
|
||||
m.initCause(ex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to read using boxed value helper.
|
||||
*/
|
||||
public Serializable read_value(BoxedValueHelper helper)
|
||||
{
|
||||
if (notFirst)
|
||||
return super.read_value(helper);
|
||||
else
|
||||
{
|
||||
notFirst = true;
|
||||
return helper.read_value(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to locate a factory using repository id.
|
||||
*/
|
||||
public Serializable read_value(String repository_id)
|
||||
{
|
||||
if (notFirst)
|
||||
return super.read_value(repository_id);
|
||||
else
|
||||
{
|
||||
notFirst = true;
|
||||
|
||||
ValueFactory factory =
|
||||
((org.omg.CORBA_2_3.ORB) orb()).lookup_value_factory(repository_id);
|
||||
if (factory == null)
|
||||
throw new MARSHAL("No factory");
|
||||
return factory.read_value(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to read when having an unitialised value.
|
||||
*/
|
||||
public Serializable read_value(Serializable value)
|
||||
{
|
||||
if (notFirst)
|
||||
return super.read_value(value);
|
||||
else
|
||||
{
|
||||
notFirst = true;
|
||||
|
||||
// The user-defines io operations are implemented.
|
||||
if (value instanceof CustomMarshal)
|
||||
{
|
||||
CustomMarshal marsh = (CustomMarshal) value;
|
||||
try
|
||||
{
|
||||
marsh.unmarshal((DataInputStream) this);
|
||||
}
|
||||
catch (ClassCastException ex)
|
||||
{
|
||||
Vio.incorrect_plug_in(ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
// The IDL-generated io operations are implemented.
|
||||
if (value instanceof Streamable)
|
||||
{
|
||||
((Streamable) value)._read(this);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,177 @@
|
|||
/* abstractDynAny.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.CORBA.DynAn;
|
||||
|
||||
import gnu.CORBA.typeNamer;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.LocalObject;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The top of our DynAny implementation, this class provides ORB that is
|
||||
* required to create anys and factory that is required to initialise DynAnys.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public abstract class abstractDynAny
|
||||
extends LocalObject
|
||||
implements Serializable
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The "initial final_type" that can be an alias of the known final_type.
|
||||
*/
|
||||
public TypeCode official_type;
|
||||
|
||||
/**
|
||||
* The "basic" final_type to that the final_type finally evaluates.
|
||||
*/
|
||||
public final TypeCode final_type;
|
||||
|
||||
/**
|
||||
* The DynAny factory, required in initializations.
|
||||
*/
|
||||
public final gnuDynAnyFactory factory;
|
||||
|
||||
/**
|
||||
* The ORB, to that this DynAny belongs.
|
||||
*/
|
||||
public final ORB orb;
|
||||
|
||||
/**
|
||||
* The minor code, indicating the error, related to work with non - GNU
|
||||
* Classpath DynAny.
|
||||
*/
|
||||
short MINOR = 8148;
|
||||
|
||||
/**
|
||||
* The message about the empty structure or exception.
|
||||
*/
|
||||
static final String EMPTY = "Empty structure with no fields.";
|
||||
|
||||
/**
|
||||
* The message about the structure or exception size mismatch.
|
||||
*/
|
||||
static final String SIZE = "Size mismatch.";
|
||||
|
||||
/**
|
||||
* The message about the content of this DynAny being equal to
|
||||
* <code>null</code>
|
||||
*/
|
||||
static final String ISNULL = "The content is null";
|
||||
|
||||
/**
|
||||
* The change value listener.
|
||||
*/
|
||||
valueChangedListener listener;
|
||||
|
||||
/**
|
||||
* Create the abstract dyn any.
|
||||
*/
|
||||
public abstractDynAny(TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory, ORB anOrb
|
||||
)
|
||||
{
|
||||
official_type = oType;
|
||||
final_type = aType;
|
||||
factory = aFactory;
|
||||
orb = anOrb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the typecode.
|
||||
*/
|
||||
public TypeCode type()
|
||||
{
|
||||
return official_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the Any.
|
||||
*/
|
||||
public Any createAny()
|
||||
{
|
||||
return orb.create_any();
|
||||
}
|
||||
|
||||
/**
|
||||
* The "value changed" listener.
|
||||
*/
|
||||
protected void valueChanged()
|
||||
{
|
||||
if (listener != null)
|
||||
listener.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the type.
|
||||
*/
|
||||
void checkType(TypeCode expected, TypeCode actual)
|
||||
throws TypeMismatch
|
||||
{
|
||||
if (!expected.equal(actual))
|
||||
throw new TypeMismatch(typeMismatch(expected, actual));
|
||||
}
|
||||
|
||||
/**
|
||||
* Format "Type mismatch" string.
|
||||
*/
|
||||
String typeMismatch(TypeCode expected, TypeCode actual)
|
||||
{
|
||||
return typeNamer.nameIt(expected) + " expected " +
|
||||
typeNamer.nameIt(actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format "size mismatch" string.
|
||||
*/
|
||||
String sizeMismatch(int here, int other)
|
||||
{
|
||||
return "Size mismatch, " + other + " (expected " + here + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,405 @@
|
|||
/* abstractRecord.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.CORBA.DynAn;
|
||||
|
||||
import gnu.CORBA.Unexpected;
|
||||
import gnu.CORBA.holderFactory;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.TCKind;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.TypeCodePackage.BadKind;
|
||||
import org.omg.CORBA.TypeCodePackage.Bounds;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
||||
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
||||
import org.omg.DynamicAny.DynStruct;
|
||||
import org.omg.DynamicAny.DynValueCommonOperations;
|
||||
import org.omg.DynamicAny.NameDynAnyPair;
|
||||
import org.omg.DynamicAny.NameValuePair;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* A shared base for both dynamic structure an dynamic value final_type.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public abstract class abstractRecord
|
||||
extends anyDivideable
|
||||
implements DynAny, Serializable
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
String[] fNames;
|
||||
|
||||
/**
|
||||
* Creates the structure with the given typecode.
|
||||
*
|
||||
* @param fields The DynAny's, representing the fields of the structure.
|
||||
*/
|
||||
public abstractRecord(TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory, ORB anOrb
|
||||
)
|
||||
{
|
||||
super(oType, aType, aFactory, anOrb);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public TCKind current_member_kind()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
if (array.length == 0)
|
||||
throw new TypeMismatch(EMPTY);
|
||||
try
|
||||
{
|
||||
return final_type.member_type(pos).kind();
|
||||
}
|
||||
catch (BadKind e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
catch (Bounds e)
|
||||
{
|
||||
InvalidValue t = new InvalidValue();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public String current_member_name()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
if (array.length == 0)
|
||||
throw new TypeMismatch(EMPTY);
|
||||
try
|
||||
{
|
||||
return final_type.member_name(pos);
|
||||
}
|
||||
catch (BadKind e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
catch (Bounds e)
|
||||
{
|
||||
InvalidValue t = new InvalidValue();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content of the structure. This method must be defined on a different
|
||||
* name because get_members_as_dyn_any() throws exception only in some of the
|
||||
* supported interfaces.
|
||||
*/
|
||||
public NameDynAnyPair[] gnu_get_members_as_dyn_any()
|
||||
{
|
||||
NameDynAnyPair[] r = new NameDynAnyPair[ array.length ];
|
||||
for (int i = 0; i < r.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
r [ i ] = new NameDynAnyPair(fNames [ i ], array [ i ]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Unexpected(ex);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content of the structure. This method must be defined on a different
|
||||
* name because get_members_as_dyn_any() throws exception only in some of the
|
||||
* supported interfaces.
|
||||
*/
|
||||
public NameValuePair[] gnu_get_members()
|
||||
{
|
||||
NameValuePair[] r = new NameValuePair[ array.length ];
|
||||
for (int i = 0; i < r.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
r [ i ] = new NameValuePair(fNames [ i ], array [ i ].to_any());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Unexpected(ex);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set members from the provided array.
|
||||
*/
|
||||
public void set_members_as_dyn_any(NameDynAnyPair[] value)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
if (value.length != array.length)
|
||||
throw new InvalidValue(sizeMismatch(array.length, value.length));
|
||||
|
||||
for (int i = 0; i < value.length; i++)
|
||||
{
|
||||
DynAny dynAny = value [ i ].value;
|
||||
checkType(dynAny.type(), i);
|
||||
checkName(value [ i ].id, i);
|
||||
|
||||
array [ i ] = dynAny;
|
||||
}
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the name at the given position ("" matches everything).
|
||||
*/
|
||||
private void checkName(String xName, int i)
|
||||
throws TypeMismatch
|
||||
{
|
||||
if (xName.length() > 0 && fNames [ i ].length() > 0)
|
||||
if (!xName.equals(fNames [ i ]))
|
||||
throw new TypeMismatch("Field name mismatch " + xName + " expected " +
|
||||
fNames [ i ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the type at the given position.
|
||||
*/
|
||||
private void checkType(TypeCode t, int i)
|
||||
throws TypeMismatch
|
||||
{
|
||||
if (!array [ i ].type().equal(t))
|
||||
throw new TypeMismatch(typeMismatch(array [ i ].type(), t) + " field " +
|
||||
i
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set members from the provided array.
|
||||
*/
|
||||
public void set_members(NameValuePair[] value)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
if (value.length != array.length)
|
||||
throw new InvalidValue(sizeMismatch(array.length, value.length));
|
||||
|
||||
for (int i = 0; i < value.length; i++)
|
||||
{
|
||||
Any any = value [ i ].value;
|
||||
checkType(any.type(), i);
|
||||
checkName(value [ i ].id, i);
|
||||
|
||||
array [ i ].from_any(any);
|
||||
}
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void assign(DynAny from)
|
||||
throws TypeMismatch
|
||||
{
|
||||
checkType(official_type, from.type());
|
||||
if (from instanceof DynStruct)
|
||||
{
|
||||
try
|
||||
{
|
||||
set_members_as_dyn_any(((DynStruct) from).get_members_as_dyn_any());
|
||||
}
|
||||
catch (InvalidValue e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch("Invalid value");
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new TypeMismatch("Not a DynStruct");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a copy.
|
||||
*/
|
||||
public DynAny copy()
|
||||
{
|
||||
DynAny[] c = new DynAny[ array.length ];
|
||||
for (int i = 0; i < c.length; i++)
|
||||
{
|
||||
c [ i ] = array [ i ].copy();
|
||||
}
|
||||
|
||||
abstractRecord d = newInstance(official_type, final_type, factory, orb);
|
||||
d.array = c;
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance when copying.
|
||||
*/
|
||||
protected abstract abstractRecord newInstance(TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory,
|
||||
ORB anOrb
|
||||
);
|
||||
|
||||
/**
|
||||
* Done via reflection.
|
||||
*/
|
||||
public Any to_any()
|
||||
{
|
||||
try
|
||||
{
|
||||
Streamable sHolder = holderFactory.createHolder(official_type);
|
||||
|
||||
Class sHolderClass = sHolder.getClass();
|
||||
Field sHolderValue = sHolderClass.getField("value");
|
||||
Class sClass = sHolderValue.getType();
|
||||
|
||||
Object structure = sClass.newInstance();
|
||||
Object member;
|
||||
Any am;
|
||||
Field vread;
|
||||
Field vwrite;
|
||||
Streamable memberHolder;
|
||||
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
am = array [ i ].to_any();
|
||||
memberHolder = am.extract_Streamable();
|
||||
vwrite = structure.getClass().getField(final_type.member_name(i));
|
||||
vread = memberHolder.getClass().getField("value");
|
||||
member = vread.get(memberHolder);
|
||||
vwrite.set(structure, member);
|
||||
}
|
||||
|
||||
Any g = createAny();
|
||||
sHolderValue.set(sHolder, structure);
|
||||
g.insert_Streamable(sHolder);
|
||||
g.type(official_type);
|
||||
return g;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Done via reflection.
|
||||
*/
|
||||
public void from_any(Any an_any)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
checkType(official_type, an_any.type());
|
||||
try
|
||||
{
|
||||
Streamable s = an_any.extract_Streamable();
|
||||
if (s == null)
|
||||
{
|
||||
if (this instanceof DynValueCommonOperations)
|
||||
{
|
||||
((DynValueCommonOperations) this).set_to_null();
|
||||
return;
|
||||
}
|
||||
else
|
||||
throw new InvalidValue(ISNULL);
|
||||
}
|
||||
|
||||
Object structure = s.getClass().getField("value").get(s);
|
||||
if (structure == null && (this instanceof DynValueCommonOperations))
|
||||
{
|
||||
((DynValueCommonOperations) this).set_to_null();
|
||||
return;
|
||||
}
|
||||
|
||||
Any member;
|
||||
Streamable holder;
|
||||
Object field;
|
||||
TypeCode fType;
|
||||
Field fField;
|
||||
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
fField = structure.getClass().getField(fNames [ i ]);
|
||||
field = fField.get(structure);
|
||||
fType = array [ i ].type();
|
||||
holder = holderFactory.createHolder(fType);
|
||||
|
||||
member = createAny();
|
||||
holder.getClass().getField("value").set(holder, field);
|
||||
member.insert_Streamable(holder);
|
||||
member.type(fType);
|
||||
|
||||
array [ i ].from_any(member);
|
||||
}
|
||||
|
||||
if (this instanceof DynValueCommonOperations)
|
||||
((DynValueCommonOperations) this).set_to_value();
|
||||
}
|
||||
catch (InvalidValue v)
|
||||
{
|
||||
throw v;
|
||||
}
|
||||
catch (NoSuchFieldException ex)
|
||||
{
|
||||
TypeMismatch v =
|
||||
new TypeMismatch("holder value does not match typecode");
|
||||
v.initCause(ex);
|
||||
throw v;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(ex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,514 @@
|
|||
/* anyDivideable.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.CORBA.DynAn;
|
||||
|
||||
import gnu.CORBA.typeNamer;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.CompletionStatus;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.Object;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.UNKNOWN;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
||||
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
||||
import org.omg.DynamicAny.DynValueCommon;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Provides a base for DynAnys, having multiple components.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public abstract class anyDivideable
|
||||
extends abstractDynAny
|
||||
implements Serializable
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The array of the components that in general case may have different
|
||||
* final_type.
|
||||
*/
|
||||
protected DynAny[] array;
|
||||
|
||||
/**
|
||||
* The internal pointer.
|
||||
*/
|
||||
protected int pos = 0;
|
||||
|
||||
public anyDivideable(TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory, ORB anOrb
|
||||
)
|
||||
{
|
||||
super(oType, aType, aFactory, anOrb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Advance forward.
|
||||
*/
|
||||
public boolean next()
|
||||
{
|
||||
pos++;
|
||||
return array.length > pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set zero position.
|
||||
*/
|
||||
public void rewind()
|
||||
{
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a position.
|
||||
*/
|
||||
public boolean seek(int p)
|
||||
{
|
||||
pos = p;
|
||||
return pos >= 0 && array.length > pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the insertion point as DynAny. This method may throw exceptions if the
|
||||
* current insertion point does not support reading or insertion of the
|
||||
* primitive types.
|
||||
*
|
||||
* @return the focused component, from where the primitve value can be read or
|
||||
* where it can be inserted.
|
||||
* @throws InvalidValue if the primitive value cannot be inserted at the given
|
||||
* point.
|
||||
*/
|
||||
protected DynAny focused()
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
if (pos >= 0 && pos < array.length)
|
||||
{
|
||||
if (array [ pos ].component_count() == 0)
|
||||
return array [ pos ];
|
||||
else
|
||||
throw new TypeMismatch("Multiple coponents at " + pos);
|
||||
}
|
||||
else
|
||||
throw new InvalidValue("Out of bounds at " + pos + " valid 0.." +
|
||||
(array.length - 1)
|
||||
);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public int component_count()
|
||||
{
|
||||
return array.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the second (enclosed any) that is stored in the wrapped Any.
|
||||
*/
|
||||
public Any get_any()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_any();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public boolean get_boolean()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_boolean();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public char get_char()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_char();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double get_double()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_double();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public float get_float()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_float();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public int get_long()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_long();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public long get_longlong()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_longlong();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public byte get_octet()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_octet();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Object get_reference()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_reference();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public short get_short()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_short();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public String get_string()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_string();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public TypeCode get_typecode()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_typecode();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public int get_ulong()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_ulong();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public long get_ulonglong()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_ulonglong();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public short get_ushort()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_ushort();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Serializable get_val()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
if (pos >= 0 && pos < array.length)
|
||||
{
|
||||
if (array [ pos ] instanceof DynValueCommon)
|
||||
return array [ pos ].get_val();
|
||||
else
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
else
|
||||
throw new InvalidValue("Out of bounds at " + pos + " valid 0.." +
|
||||
(array.length - 1)
|
||||
);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public char get_wchar()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_wchar();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public String get_wstring()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_wstring();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_any(Any a_x)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
focused().insert_any(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_boolean(boolean a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_boolean(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_char(char a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_char(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_double(double a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_double(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_float(float a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_float(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_long(int a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_long(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_longlong(long a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_longlong(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_octet(byte a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_octet(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_reference(Object a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_reference(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_short(short a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_short(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_string(String a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_string(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_typecode(TypeCode a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_typecode(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_ulong(int a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_ulong(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_ulonglong(long a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_ulonglong(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_ushort(short a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_ushort(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_val(Serializable a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
if (pos >= 0 && pos < array.length)
|
||||
{
|
||||
if (array [ pos ] instanceof DynValueCommon)
|
||||
array [ pos ].insert_val(a_x);
|
||||
else
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
else
|
||||
throw new InvalidValue("Out of bounds at " + pos + " valid 0.." +
|
||||
(array.length - 1)
|
||||
);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_wchar(char a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_wchar(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_wstring(String a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
focused().insert_wstring(a_x);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public DynAny get_dyn_any()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return focused().get_dyn_any();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_dyn_any(DynAny insert_it)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
focused().insert_dyn_any(insert_it);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current component.
|
||||
*
|
||||
* @return current component or <code>null</code> if the pointer is out of
|
||||
* bounds.
|
||||
*/
|
||||
public DynAny current_component()
|
||||
throws TypeMismatch
|
||||
{
|
||||
if (array.length == 0)
|
||||
throw new TypeMismatch("empty");
|
||||
return (pos >= 0 && pos < array.length) ? array [ pos ] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* No action, cleanup is done by garbage collector in java.
|
||||
*/
|
||||
public void destroy()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Involved in equal(DynAny).
|
||||
*/
|
||||
public abstract Any to_any()
|
||||
throws TypeMismatch;
|
||||
|
||||
/**
|
||||
* Compares with other DynAny for equality. The final_type, array size and
|
||||
* array members must match.
|
||||
*/
|
||||
public boolean equal(DynAny other)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!official_type.equal(other.type()))
|
||||
return false;
|
||||
else if (other instanceof anyDivideable)
|
||||
{
|
||||
anyDivideable x = (anyDivideable) other;
|
||||
if (x.array.length != array.length)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
if (!array [ i ].equal(x.array [ i ]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (other == null || other instanceof abstractDynAny)
|
||||
return false;
|
||||
else
|
||||
return other.to_any().equal(to_any());
|
||||
}
|
||||
catch (TypeMismatch e)
|
||||
{
|
||||
UNKNOWN u = new UNKNOWN(MINOR, CompletionStatus.COMPLETED_NO);
|
||||
u.initCause(e);
|
||||
throw u;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,493 @@
|
|||
/* Undivideable.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.CORBA.DynAn;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.Object;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
||||
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
||||
|
||||
/**
|
||||
* Represent DynAny that has no internal components (DynEnum and so on). The
|
||||
* methods, related to internal components, throw exceptions or return agreed
|
||||
* values like null.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public abstract class anyUndivideable
|
||||
extends abstractDynAny
|
||||
implements Serializable
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* Create a new instance with the given typecode.
|
||||
*/
|
||||
public anyUndivideable(TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory, ORB anOrb)
|
||||
{
|
||||
super(oType, aType, aFactory, anOrb);
|
||||
}
|
||||
|
||||
/**
|
||||
* There are no components.
|
||||
*
|
||||
* @return 0, always.
|
||||
*/
|
||||
public int component_count()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* There is no current component.
|
||||
*
|
||||
* @throws TypeMismatch, always.
|
||||
*/
|
||||
public DynAny current_component()
|
||||
throws TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch("Not applicable");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns without action.
|
||||
*/
|
||||
public void destroy()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public Any get_any()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public boolean get_boolean()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public char get_char()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public double get_double()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public DynAny get_dyn_any()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public float get_float()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public int get_long()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public long get_longlong()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public byte get_octet()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public Object get_reference()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public short get_short()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public String get_string()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public TypeCode get_typecode()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public int get_ulong()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public long get_ulonglong()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public short get_ushort()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public Serializable get_val()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public char get_wchar()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public String get_wstring()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_any(Any an_any)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_boolean(boolean a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_char(char a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_double(double a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_dyn_any(DynAny insert_it)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_float(float a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_long(int a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_longlong(long a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_octet(byte a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_reference(Object a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_short(short a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_string(String a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_typecode(TypeCode a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_ulong(int a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_ulonglong(long a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_ushort(short a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_val(Serializable a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_wchar(char a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void insert_wstring(String a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public boolean next()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public void rewind()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public boolean seek(int p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the typecode of this enumeration.
|
||||
*/
|
||||
public TypeCode type()
|
||||
{
|
||||
return official_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares with other DynAny for equality.
|
||||
*/
|
||||
public boolean equals(java.lang.Object other)
|
||||
{
|
||||
if (other instanceof DynAny)
|
||||
return equal((DynAny) other);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This depends on an object.
|
||||
*/
|
||||
public abstract boolean equal(DynAny other);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,945 @@
|
|||
/* gnuDynAny.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.CORBA.DynAn;
|
||||
|
||||
import gnu.CORBA.CDR.cdrBufOutput;
|
||||
import gnu.CORBA.OctetHolder;
|
||||
import gnu.CORBA.Unexpected;
|
||||
import gnu.CORBA.WCharHolder;
|
||||
import gnu.CORBA.WStringHolder;
|
||||
import gnu.CORBA.holderFactory;
|
||||
import gnu.CORBA.typeNamer;
|
||||
import gnu.CORBA.universalHolder;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.AnyHolder;
|
||||
import org.omg.CORBA.BooleanHolder;
|
||||
import org.omg.CORBA.CharHolder;
|
||||
import org.omg.CORBA.DoubleHolder;
|
||||
import org.omg.CORBA.FloatHolder;
|
||||
import org.omg.CORBA.IntHolder;
|
||||
import org.omg.CORBA.LongHolder;
|
||||
import org.omg.CORBA.MARSHAL;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.Object;
|
||||
import org.omg.CORBA.ObjectHolder;
|
||||
import org.omg.CORBA.ShortHolder;
|
||||
import org.omg.CORBA.StringHolder;
|
||||
import org.omg.CORBA.TCKind;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.TypeCodeHolder;
|
||||
import org.omg.CORBA.TypeCodePackage.BadKind;
|
||||
import org.omg.CORBA.ValueBaseHolder;
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
||||
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* The primitive dynamic Any holds the value basic final_type that cannot be
|
||||
* traversed.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuDynAny extends abstractDynAny implements DynAny, Serializable
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The enclosed Streamable, holding the actual value.
|
||||
*/
|
||||
protected Streamable holder;
|
||||
|
||||
/**
|
||||
* Create DynAny providing the holder.
|
||||
*
|
||||
* @param a_holder
|
||||
*/
|
||||
public gnuDynAny(Streamable aHolder, TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory, ORB anOrb
|
||||
)
|
||||
{
|
||||
super(oType, aType, aFactory, anOrb);
|
||||
holder = aHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign the contents of the given {@link DynAny} to this DynAny.
|
||||
*
|
||||
* @param from the source to assign from.
|
||||
*/
|
||||
public void assign(DynAny from) throws TypeMismatch
|
||||
{
|
||||
checkType(official_type, from.type());
|
||||
|
||||
if (from instanceof gnuDynAny)
|
||||
holder = ((gnuDynAny) from).holder;
|
||||
else
|
||||
holder = from.to_any().extract_Streamable();
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a copy of this {@link DynAny} via buffer read/write.
|
||||
*/
|
||||
public DynAny copy()
|
||||
{
|
||||
if (holder != null)
|
||||
{
|
||||
cdrBufOutput buffer = new cdrBufOutput();
|
||||
holder._write(buffer);
|
||||
|
||||
gnuDynAny other;
|
||||
try
|
||||
{
|
||||
other =
|
||||
new gnuDynAny((Streamable) (holder.getClass().newInstance()),
|
||||
official_type, final_type, factory, orb
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Holder must have parameterless constructor.
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
other.holder._read(buffer.create_input_stream());
|
||||
return other;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new gnuDynAny(null, official_type, final_type, factory, orb);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns <code>null</code>.
|
||||
*
|
||||
* @return <code>null</code>, always.
|
||||
*/
|
||||
public DynAny current_component() throws TypeMismatch
|
||||
{
|
||||
throw new TypeMismatch("Not applicable for " +
|
||||
typeNamer.nameIt(final_type)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns without action, leaving all work to the garbage collector.
|
||||
*/
|
||||
public void destroy()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the passed parameter as the enclosed {@link Any} reference.
|
||||
*
|
||||
* @param an_any the {@link Any} that will be used as an enclosed reference.
|
||||
*
|
||||
* @throws TypeMismatch if the final_type of the passed Any is not the same as
|
||||
* the final_type, currently stored in this Any.
|
||||
*/
|
||||
public void from_any(Any an_any) throws TypeMismatch, InvalidValue
|
||||
{
|
||||
checkType(official_type, an_any.type());
|
||||
|
||||
Streamable a_holder = an_any.extract_Streamable();
|
||||
if (a_holder == null)
|
||||
{
|
||||
throw new InvalidValue(ISNULL);
|
||||
}
|
||||
else if (a_holder instanceof universalHolder)
|
||||
{
|
||||
holder = holderFactory.createHolder(official_type);
|
||||
if (holder == null)
|
||||
holder = holderFactory.createHolder(final_type);
|
||||
|
||||
if (holder == null)
|
||||
holder = ((universalHolder) a_holder).Clone();
|
||||
else
|
||||
{
|
||||
InputStream in = an_any.create_input_stream();
|
||||
holder._read(in);
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new Unexpected(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
InputStream in = an_any.create_input_stream();
|
||||
holder = (Streamable) a_holder.getClass().newInstance();
|
||||
holder._read(in);
|
||||
in.close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(ex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the second (enclosed any) that is stored in the wrapped Any.
|
||||
*/
|
||||
public Any get_any() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((AnyHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public boolean get_boolean() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((BooleanHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public char get_char() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((CharHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double get_double() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((DoubleHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public float get_float() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((FloatHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public int get_long() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((IntHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public long get_longlong() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((LongHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public byte get_octet() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((OctetHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Object get_reference() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((ObjectHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public short get_short() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((ShortHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public String get_string() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((StringHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public TypeCode get_typecode() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((TypeCodeHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public int get_ulong() throws TypeMismatch
|
||||
{
|
||||
check(TCKind.tk_ulong);
|
||||
return get_long();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public long get_ulonglong() throws TypeMismatch
|
||||
{
|
||||
check(TCKind.tk_ulonglong);
|
||||
return get_longlong();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public short get_ushort() throws TypeMismatch
|
||||
{
|
||||
check(TCKind.tk_ushort);
|
||||
return get_short();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Serializable get_val() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((ValueBaseHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public char get_wchar() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((WCharHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public String get_wstring() throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((WStringHolder) holder).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch m = new TypeMismatch();
|
||||
m.initCause(cex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_any(Any a_x) throws TypeMismatch, InvalidValue
|
||||
{
|
||||
try
|
||||
{
|
||||
if (a_x.type().kind().value() == TCKind._tk_null)
|
||||
((AnyHolder) holder).value = a_x;
|
||||
else
|
||||
{
|
||||
OutputStream buf = a_x.create_output_stream();
|
||||
buf.write_any(a_x);
|
||||
holder._read(buf.create_input_stream());
|
||||
buf.close();
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
catch (MARSHAL m)
|
||||
{
|
||||
InvalidValue v = new InvalidValue();
|
||||
v.initCause(m);
|
||||
throw v;
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new Unexpected(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_boolean(boolean a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((BooleanHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_char(char a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((CharHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_double(double a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((DoubleHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_float(float a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((FloatHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_long(int a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((IntHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_longlong(long a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((LongHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_octet(byte a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((OctetHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_reference(Object a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((ObjectHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_short(short a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((ShortHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_string(String a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
if (a_x != null &&
|
||||
final_type.length() > 0 &&
|
||||
a_x.length() > final_type.length()
|
||||
)
|
||||
throw new InvalidValue(a_x.length() + " exceeds bound, " +
|
||||
final_type.length()
|
||||
);
|
||||
((StringHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
catch (BadKind e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_typecode(TypeCode a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((TypeCodeHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_ulong(int a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((IntHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_ulonglong(long a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((LongHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_ushort(short a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((ShortHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_val(Serializable a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((ValueBaseHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_wchar(char a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
((WCharHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_wstring(String a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
if (a_x != null &&
|
||||
final_type.length() > 0 &&
|
||||
a_x.length() > type().length()
|
||||
)
|
||||
throw new InvalidValue(a_x.length() + " exceeds bound, " +
|
||||
final_type.length()
|
||||
);
|
||||
((WStringHolder) holder).value = a_x;
|
||||
valueChanged();
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(cex);
|
||||
throw t;
|
||||
}
|
||||
catch (BadKind e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The objects, enclosed inside this class, have only one component (self).
|
||||
*
|
||||
* @return false, always (no other action).
|
||||
*/
|
||||
public boolean next()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns without action.
|
||||
*/
|
||||
public void rewind()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This objects, stored in this wrapper, never have multiple internal
|
||||
* components to seek.
|
||||
*
|
||||
* @return false, always (no other action).
|
||||
*/
|
||||
public boolean seek(int p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enclosed {@link Any}.
|
||||
*
|
||||
* @return the enclosed {@link Any}.
|
||||
*/
|
||||
public Any to_any()
|
||||
{
|
||||
Any a = createAny();
|
||||
a.insert_Streamable(holder);
|
||||
a.type(official_type);
|
||||
return a;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public TypeCode type()
|
||||
{
|
||||
return official_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute hashcode in a trivial way.
|
||||
*/
|
||||
protected int getHashCodeSimple(int maximum)
|
||||
{
|
||||
int h = super.hashCode() / 2;
|
||||
if (h < 0)
|
||||
h = -h;
|
||||
return h % maximum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts Any, contained in the parameter, into Any, contained in this
|
||||
* DynAny.
|
||||
*/
|
||||
public void insert_dyn_any(DynAny d) throws TypeMismatch, InvalidValue
|
||||
{
|
||||
check(d.type().kind());
|
||||
|
||||
Any a = d.to_any();
|
||||
holder = a.extract_Streamable();
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for equality. The DynAnys are equal if the stored Anys are equal.
|
||||
*/
|
||||
public boolean equal(DynAny other)
|
||||
{
|
||||
if (other instanceof abstractDynAny)
|
||||
{
|
||||
if (other instanceof gnuDynAny)
|
||||
{
|
||||
gnuDynAny x = (gnuDynAny) other;
|
||||
|
||||
if (!x.holder.getClass().equals(holder.getClass()))
|
||||
return false;
|
||||
|
||||
cdrBufOutput b1 = new cdrBufOutput();
|
||||
x.holder._write(b1);
|
||||
|
||||
cdrBufOutput b2 = new cdrBufOutput(b1.buffer.size() + 10);
|
||||
holder._write(b2);
|
||||
|
||||
return Arrays.equals(b1.buffer.toByteArray(),
|
||||
b2.buffer.toByteArray()
|
||||
);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
if (other == null)
|
||||
return false;
|
||||
else if (other.component_count() != component_count() ||
|
||||
!official_type.equal(other.type())
|
||||
)
|
||||
return false;
|
||||
else
|
||||
return other.to_any().equal(to_any());
|
||||
}
|
||||
|
||||
/**
|
||||
* This final_type has no components.
|
||||
*
|
||||
* @return 0, always.
|
||||
*/
|
||||
public int component_count()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public DynAny get_dyn_any() throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return new gnuDynAny(holder, official_type, final_type, factory, orb);
|
||||
}
|
||||
|
||||
private void check(TCKind t) throws TypeMismatch
|
||||
{
|
||||
if (t.value() != final_type.kind().value())
|
||||
throw new TypeMismatch(t.value() + "!=" + final_type.kind().value());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,356 @@
|
|||
/* gnuDynAnyFactory.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.CORBA.DynAn;
|
||||
|
||||
import gnu.CORBA.Poa.ORB_1_4;
|
||||
import gnu.CORBA.Unexpected;
|
||||
import gnu.CORBA.holderFactory;
|
||||
import gnu.CORBA.typeNamer;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.LocalObject;
|
||||
import org.omg.CORBA.TCKind;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.TypeCodePackage.BadKind;
|
||||
import org.omg.CORBA.UserException;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnyFactory;
|
||||
import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode;
|
||||
import org.omg.DynamicAny.DynArray;
|
||||
import org.omg.DynamicAny.DynEnum;
|
||||
import org.omg.DynamicAny.DynFixed;
|
||||
import org.omg.DynamicAny.DynSequence;
|
||||
import org.omg.DynamicAny.DynStruct;
|
||||
import org.omg.DynamicAny.DynUnion;
|
||||
import org.omg.DynamicAny.DynValue;
|
||||
import org.omg.DynamicAny.DynValueBox;
|
||||
|
||||
/**
|
||||
* This class is returned by ORB when resolving
|
||||
* initial reference "DynAnyFactory".
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuDynAnyFactory
|
||||
extends LocalObject
|
||||
implements DynAnyFactory
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The ORB, to that the factory belongs.
|
||||
*/
|
||||
final ORB_1_4 orb;
|
||||
|
||||
/**
|
||||
* Create a new factory, specifying the ORB to that the factory belongs.
|
||||
*
|
||||
* @param anOrb
|
||||
*/
|
||||
public gnuDynAnyFactory(ORB_1_4 anOrb)
|
||||
{
|
||||
orb = anOrb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the orb.
|
||||
*/
|
||||
public ORB_1_4 getOrb()
|
||||
{
|
||||
return orb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an initialised array.
|
||||
*/
|
||||
public DynArray create_array(TypeCode official, TypeCode type)
|
||||
{
|
||||
return new gnuDynArray(official, type, this, orb, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty sequence.
|
||||
*/
|
||||
public DynSequence create_sequence(TypeCode official, TypeCode type)
|
||||
{
|
||||
return new gnuDynSequence(official, type, this, orb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create structure.
|
||||
*
|
||||
* @param official the type that was originally passed as a parameter by user.
|
||||
* May be alias of some other type.
|
||||
* @param type the type into that the "official type" evaluates during alias
|
||||
* resolving. Initially equal to "official type".
|
||||
*/
|
||||
public DynStruct create_structure(TypeCode official, TypeCode type)
|
||||
{
|
||||
return new gnuDynStruct(official, type, this, orb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create union.
|
||||
*
|
||||
* @param official the type that was originally passed as a parameter by user.
|
||||
* May be alias of some other type.
|
||||
* @param type the type into that the "official type" evaluates during alias
|
||||
* resolving. Initially equal to "official type".
|
||||
*/
|
||||
public DynUnion create_union(TypeCode official, TypeCode type)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new gnuDynUnion(official, type, this, orb);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Unexpected(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create value.
|
||||
*
|
||||
* @param official the type that was originally passed as a parameter by user.
|
||||
* May be alias of some other type.
|
||||
* @param type the type into that the "official type" evaluates during alias
|
||||
* resolving. Initially equal to "official type".
|
||||
*/
|
||||
public DynValue create_value(TypeCode official, TypeCode type)
|
||||
{
|
||||
return new gnuDynValue(official, type, this, orb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create value box.
|
||||
*
|
||||
* @param official the type that was originally passed as a parameter by user.
|
||||
* May be alias of some other type.
|
||||
* @param type the type into that the "official type" evaluates during alias
|
||||
* resolving. Initially equal to "official type".
|
||||
*/
|
||||
public DynValueBox create_value_box(TypeCode official, TypeCode type)
|
||||
{
|
||||
return new gnuDynValueBox(official, type, this, orb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create enumeration.
|
||||
*
|
||||
* @param official the type that was originally passed as a parameter by user.
|
||||
* May be alias of some other type.
|
||||
* @param type the type into that the "official type" evaluates during alias
|
||||
* resolving. Initially equal to "official type".
|
||||
*/
|
||||
public DynEnum create_enumeration(TypeCode official, TypeCode type)
|
||||
{
|
||||
return new gnuDynEnum(official, type, this, orb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create fixed.
|
||||
*
|
||||
* @param official the type that was originally passed as a parameter by user.
|
||||
* May be alias of some other type.
|
||||
* @param type the type into that the "official type" evaluates during alias
|
||||
* resolving. Initially equal to "official type".
|
||||
*/
|
||||
public DynFixed create_fixed(TypeCode official, TypeCode type)
|
||||
{
|
||||
return new gnuDynFixed(official, type, this, orb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create alias.
|
||||
*
|
||||
* @param official the type that was originally passed as a parameter by user.
|
||||
* May be alias of some other type.
|
||||
* @param type the type into that the "official type" evaluates during alias
|
||||
* resolving. Initially equal to "official type".
|
||||
*/
|
||||
public DynAny create_alias(TypeCode official, TypeCode type)
|
||||
throws InconsistentTypeCode
|
||||
{
|
||||
try
|
||||
{
|
||||
return create_dyn_any_from_type_code(official, type.content_type());
|
||||
}
|
||||
catch (BadKind e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the undivideable DynAny.
|
||||
*/
|
||||
public DynAny create_simple(TypeCode official, TypeCode type)
|
||||
{
|
||||
Streamable holder = holderFactory.createHolder(type);
|
||||
return new gnuDynAny(holder, official, type, this, orb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the DynAny from typecode.
|
||||
*/
|
||||
public DynAny create_dyn_any_from_type_code(TypeCode type)
|
||||
throws InconsistentTypeCode
|
||||
{
|
||||
return create_dyn_any_from_type_code(type, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the DynAny from typecode.
|
||||
*
|
||||
* @param official the type that was originally passed as a parameter by user.
|
||||
* May be alias of some other type.
|
||||
* @param type the type into that the "official type" evaluates during alias
|
||||
* resolving. Initially equal to "official type".
|
||||
*/
|
||||
public DynAny create_dyn_any_from_type_code(TypeCode official, TypeCode type)
|
||||
throws InconsistentTypeCode
|
||||
{
|
||||
DynAny d;
|
||||
try
|
||||
{
|
||||
switch (type.kind().value())
|
||||
{
|
||||
case TCKind._tk_array :
|
||||
return create_array(official, type);
|
||||
|
||||
case TCKind._tk_sequence :
|
||||
return create_sequence(official, type);
|
||||
|
||||
case TCKind._tk_struct :
|
||||
case TCKind._tk_except :
|
||||
return create_structure(official, type);
|
||||
|
||||
case TCKind._tk_union :
|
||||
return create_union(official, type);
|
||||
|
||||
case TCKind._tk_value :
|
||||
return create_value(official, type);
|
||||
|
||||
case TCKind._tk_value_box :
|
||||
return create_value_box(official, type);
|
||||
|
||||
case TCKind._tk_enum :
|
||||
return create_enumeration(official, type);
|
||||
|
||||
case TCKind._tk_fixed :
|
||||
return create_fixed(official, type);
|
||||
|
||||
case TCKind._tk_alias :
|
||||
return create_alias(official, type);
|
||||
|
||||
case TCKind._tk_null :
|
||||
return new gnuDynAny(null, official, type, this, orb);
|
||||
|
||||
case TCKind._tk_TypeCode :
|
||||
d = create_simple(official, type);
|
||||
d.insert_typecode(orb.get_primitive_tc(TCKind.tk_null));
|
||||
return d;
|
||||
|
||||
case TCKind._tk_any :
|
||||
d = create_simple(official, type);
|
||||
|
||||
Any empty_any = orb.create_any();
|
||||
empty_any.type(orb.get_primitive_tc(TCKind.tk_null));
|
||||
d.insert_any(empty_any);
|
||||
return d;
|
||||
|
||||
case TCKind._tk_wstring :
|
||||
d = create_simple(official, type);
|
||||
d.insert_wstring("");
|
||||
return d;
|
||||
|
||||
case TCKind._tk_string :
|
||||
d = create_simple(official, type);
|
||||
d.insert_string("");
|
||||
return d;
|
||||
|
||||
case TCKind._tk_native :
|
||||
case TCKind._tk_Principal :
|
||||
case TCKind._tk_abstract_interface :
|
||||
throw new InconsistentTypeCode("Following API, the " +
|
||||
typeNamer.nameIt(type) +
|
||||
" must not be supported."
|
||||
);
|
||||
|
||||
default :
|
||||
return create_simple(official, type);
|
||||
}
|
||||
}
|
||||
catch (UserException uex)
|
||||
{
|
||||
InconsistentTypeCode it = new InconsistentTypeCode();
|
||||
it.initCause(uex);
|
||||
throw it;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the DynAny using the passed value as template and assign this value.
|
||||
*/
|
||||
public DynAny create_dyn_any(Any value)
|
||||
throws InconsistentTypeCode
|
||||
{
|
||||
DynAny created = create_dyn_any_from_type_code(value.type());
|
||||
try
|
||||
{
|
||||
created.from_any(value);
|
||||
}
|
||||
catch (UserException uex)
|
||||
{
|
||||
InconsistentTypeCode t = new InconsistentTypeCode("Inconsistent Any");
|
||||
t.initCause(uex);
|
||||
throw t;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
return created;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,338 @@
|
|||
/* gnuDynArray.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.CORBA.DynAn;
|
||||
|
||||
import gnu.CORBA.Unexpected;
|
||||
import gnu.CORBA.holderFactory;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.TCKind;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.TypeCodePackage.BadKind;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode;
|
||||
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
||||
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
||||
import org.omg.DynamicAny.DynArray;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Provides support for dynamic array or sequence, where all members have the
|
||||
* same final_type.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuDynArray
|
||||
extends anyDivideable
|
||||
implements DynArray, Serializable
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The component "official" type (may be alias).
|
||||
*/
|
||||
final TypeCode official_components;
|
||||
|
||||
/**
|
||||
* The component "final" type, after resolving any aliases.
|
||||
*/
|
||||
final TypeCode final_components;
|
||||
|
||||
/**
|
||||
* Creates new array.
|
||||
*
|
||||
* @param aType the final_type of array.
|
||||
* @param aFactory the factory, used to initialise default values.
|
||||
* @param orb the ORB to that this DynAny belongs.
|
||||
* @param initialise_array if false, the array is not initialised in
|
||||
* constructor.
|
||||
*
|
||||
*
|
||||
* @throws BAD_PARAM if the passed typecode does not provide the length().
|
||||
*/
|
||||
public gnuDynArray(TypeCode oType, TypeCode aType, gnuDynAnyFactory aFactory,
|
||||
ORB anOrb, boolean initialise_array
|
||||
)
|
||||
throws BAD_PARAM
|
||||
{
|
||||
super(oType, aType, aFactory, anOrb);
|
||||
|
||||
try
|
||||
{
|
||||
official_components = final_type.content_type();
|
||||
|
||||
TypeCode component = official_components;
|
||||
while (component.kind().value() == TCKind._tk_alias)
|
||||
component = component.content_type();
|
||||
final_components = component;
|
||||
|
||||
if (initialise_array)
|
||||
{
|
||||
array = new DynAny[ aType.length() ];
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
array [ i ] =
|
||||
factory.create_dyn_any_from_type_code(official_components);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BAD_PARAM bad = new BAD_PARAM("Unable to initialise array");
|
||||
bad.initCause(e);
|
||||
throw bad;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy one DynAny into another.
|
||||
*/
|
||||
public void assign(DynAny from)
|
||||
throws TypeMismatch
|
||||
{
|
||||
checkType(official_type, from.type());
|
||||
if (from instanceof DynArray && from.component_count() == array.length)
|
||||
{
|
||||
DynArray dyn = (DynArray) from;
|
||||
array = dyn.get_elements_as_dyn_any();
|
||||
}
|
||||
else
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a copy.
|
||||
*/
|
||||
public DynAny copy()
|
||||
{
|
||||
DynAny[] c = new DynAny[ array.length ];
|
||||
for (int i = 0; i < c.length; i++)
|
||||
{
|
||||
c [ i ] = array [ i ].copy();
|
||||
}
|
||||
|
||||
gnuDynArray d =
|
||||
new gnuDynArray(official_type, final_type, factory, orb, false);
|
||||
d.array = c;
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements as array of anys.
|
||||
*/
|
||||
public Any[] get_elements()
|
||||
{
|
||||
Any[] r = new Any[ array.length ];
|
||||
for (int i = 0; i < r.length; i++)
|
||||
r [ i ] = array [ i ].to_any();
|
||||
return r;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public DynAny[] get_elements_as_dyn_any()
|
||||
{
|
||||
DynAny[] a = new DynAny[ array.length ];
|
||||
for (int i = 0; i < a.length; i++)
|
||||
{
|
||||
a [ i ] = array [ i ].copy();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set elements when array of dyn anys is provided. This method can set nested
|
||||
* data structures as an array components.
|
||||
*/
|
||||
public void set_elements_as_dyn_any(DynAny[] value)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
if (value.length != array.length)
|
||||
throw new InvalidValue(sizeMismatch(array.length, value.length));
|
||||
for (int i = 0; i < value.length; i++)
|
||||
{
|
||||
checkType(official_components, value [ i ].type());
|
||||
array [ i ].assign(value [ i ]);
|
||||
}
|
||||
pos = 0;
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set elements when array of ordinary anys is provided.
|
||||
*/
|
||||
public void set_elements(Any[] value)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
if (value.length != array.length)
|
||||
throw new InvalidValue(sizeMismatch(array.length, value.length));
|
||||
|
||||
for (int i = 0; i < value.length; i++)
|
||||
{
|
||||
checkType(official_components, value [ i ].type());
|
||||
try
|
||||
{
|
||||
array [ i ] = factory.create_dyn_any(value [ i ]);
|
||||
}
|
||||
catch (InconsistentTypeCode e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
pos = 0;
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Done via reflection.
|
||||
*/
|
||||
public Any to_any()
|
||||
{
|
||||
try
|
||||
{
|
||||
Streamable memberHolder =
|
||||
holderFactory.createHolder(official_components);
|
||||
|
||||
if (memberHolder == null)
|
||||
memberHolder = holderFactory.createHolder(final_components);
|
||||
|
||||
Class memberHolderClass = memberHolder.getClass();
|
||||
Class memberClass = memberHolderClass.getField("value").getType();
|
||||
|
||||
Object members = Array.newInstance(memberClass, array.length);
|
||||
Object member;
|
||||
Any am;
|
||||
Field value = memberHolder.getClass().getField("value");
|
||||
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
// Recursive call should support multidimensional arrays.
|
||||
am = array [ i ].to_any();
|
||||
memberHolder = am.extract_Streamable();
|
||||
member = value.get(memberHolder);
|
||||
Array.set(members, i, member);
|
||||
}
|
||||
|
||||
Streamable arrayHolder = holderFactory.createHolder(official_type);
|
||||
arrayHolder.getClass().getField("value").set(arrayHolder, members);
|
||||
|
||||
Any g = createAny();
|
||||
g.insert_Streamable(arrayHolder);
|
||||
g.type(official_type);
|
||||
return g;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Done via reflection.
|
||||
*/
|
||||
public void from_any(Any an_any)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
checkType(official_type, an_any.type());
|
||||
try
|
||||
{
|
||||
Streamable s = an_any.extract_Streamable();
|
||||
Object members = s.getClass().getField("value").get(s);
|
||||
|
||||
checkArrayValid(members);
|
||||
|
||||
Any member;
|
||||
Streamable holder;
|
||||
Class holderClass = null;
|
||||
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
if (holderClass == null)
|
||||
{
|
||||
holder = holderFactory.createHolder(official_components);
|
||||
if (holder == null)
|
||||
holder = holderFactory.createHolder(final_components);
|
||||
holderClass = holder.getClass();
|
||||
}
|
||||
else
|
||||
holder = (Streamable) holderClass.newInstance();
|
||||
|
||||
member = createAny();
|
||||
holder.getClass().getField("value").set(holder,
|
||||
Array.get(members, i)
|
||||
);
|
||||
member.insert_Streamable(holder);
|
||||
member.type(official_components);
|
||||
|
||||
// This may lead to recursion, supporting multidimensional
|
||||
// arrays.
|
||||
array [ i ].from_any(member);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(ex);
|
||||
throw t;
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if array size is valid and (for sequences) resized
|
||||
* if required. Called from from_any.
|
||||
*/
|
||||
protected void checkArrayValid(Object members)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
if (array.length != Array.getLength(members))
|
||||
throw new InvalidValue(sizeMismatch(array.length, Array.getLength(members)));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,244 @@
|
|||
/* gnuDynEnum.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.CORBA.DynAn;
|
||||
|
||||
import gnu.CORBA.Unexpected;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.MARSHAL;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
||||
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
||||
import org.omg.DynamicAny.DynEnum;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Our implementation of dynamic enumeration.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuDynEnum extends anyUndivideable implements DynEnum
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The valid string values of the enumeration. Most of enumerations are short,
|
||||
* counting 2-5 memebers. With so small number of memebers, it seems not
|
||||
* reasonable to use hashtables.
|
||||
*/
|
||||
final String[] values;
|
||||
|
||||
/**
|
||||
* The current value of enum.
|
||||
*/
|
||||
int current;
|
||||
|
||||
/**
|
||||
* Create a new dyn enum from the given typecode.
|
||||
*/
|
||||
public gnuDynEnum(TypeCode oType, TypeCode aType, gnuDynAnyFactory aFactory,
|
||||
ORB anOrb
|
||||
)
|
||||
{
|
||||
super(oType, aType, aFactory, anOrb);
|
||||
try
|
||||
{
|
||||
values = new String[ final_type.member_count() ];
|
||||
|
||||
for (int i = 0; i < values.length; i++)
|
||||
{
|
||||
values [ i ] = final_type.member_name(i);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new BAD_PARAM("Not enum");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a clone of the given enum, sharing values and final_type.
|
||||
*/
|
||||
public gnuDynEnum(gnuDynEnum from)
|
||||
{
|
||||
super(from.official_type, from.final_type, from.factory, from.orb);
|
||||
values = from.values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign the Enum from the passed value. The passed DynAny must hold the
|
||||
* enumeration of exactly the same final_type.
|
||||
*/
|
||||
public void assign(DynAny from) throws TypeMismatch
|
||||
{
|
||||
checkType(official_type, from.type());
|
||||
if (!(from instanceof DynEnum))
|
||||
throw new TypeMismatch("Not a DynEnum");
|
||||
try
|
||||
{
|
||||
set_as_ulong(((DynEnum) from).get_as_ulong());
|
||||
}
|
||||
catch (InvalidValue e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy this DynEnum.
|
||||
*/
|
||||
public DynAny copy()
|
||||
{
|
||||
gnuDynEnum other = new gnuDynEnum(this);
|
||||
other.current = current;
|
||||
return other;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares for equality.
|
||||
*/
|
||||
public boolean equal(DynAny other)
|
||||
{
|
||||
if (other instanceof gnuDynEnum)
|
||||
{
|
||||
gnuDynEnum oe = (gnuDynEnum) other;
|
||||
return current == oe.current &&
|
||||
(oe.values == values || Arrays.equals(values, oe.values));
|
||||
}
|
||||
else if (other instanceof DynEnum)
|
||||
{
|
||||
DynEnum oe = (DynEnum) other;
|
||||
return current == oe.get_as_ulong() && official_type.equal(oe.type());
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value from any that must contain enumeration.
|
||||
*/
|
||||
public void from_any(Any an_any) throws TypeMismatch, InvalidValue
|
||||
{
|
||||
checkType(official_type, an_any.type());
|
||||
try
|
||||
{
|
||||
InputStream in = an_any.create_input_stream();
|
||||
set_as_ulong(in.read_long());
|
||||
in.close();
|
||||
}
|
||||
catch (MARSHAL eof)
|
||||
{
|
||||
throw new InvalidValue();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new Unexpected(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of this enumeration as string.
|
||||
*/
|
||||
public String get_as_string()
|
||||
{
|
||||
return values [ current ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of this enumeration as int.
|
||||
*/
|
||||
public int get_as_ulong()
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of this enumeration as string.
|
||||
*/
|
||||
public void set_as_string(String value) throws InvalidValue
|
||||
{
|
||||
for (int i = 0; i < values.length; i++)
|
||||
{
|
||||
if (values [ i ].equals(value))
|
||||
{
|
||||
current = i;
|
||||
valueChanged();
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new InvalidValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of this enumeration as int.
|
||||
*/
|
||||
public void set_as_ulong(int value) throws InvalidValue
|
||||
{
|
||||
if (value < 0 || value >= values.length)
|
||||
throw new InvalidValue(value + " not in [0.." + values.length);
|
||||
else
|
||||
{
|
||||
current = value;
|
||||
valueChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the enumeration value into any.
|
||||
*/
|
||||
public Any to_any()
|
||||
{
|
||||
Any a = createAny();
|
||||
a.insert_long(current);
|
||||
a.type(official_type);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,252 @@
|
|||
/* gnuDynFixed.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.CORBA.DynAn;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_OPERATION;
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
||||
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
||||
import org.omg.DynamicAny.DynFixed;
|
||||
import org.omg.DynamicAny.DynFixedOperations;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Implements DynAny, holding CORBA <code>fixed</code>. This class is derived
|
||||
* from gnuDynEnm to avoid repetetive inclusion of unused DynAny methods.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuDynFixed extends anyUndivideable implements DynFixed
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The default value, assigned in the new instance.
|
||||
*/
|
||||
static final BigDecimal ZERO = new BigDecimal("0.0");
|
||||
|
||||
/**
|
||||
* The content of the dyn fixed, wrapped in this DynAny.
|
||||
*/
|
||||
BigDecimal value;
|
||||
|
||||
/**
|
||||
* The number of digits after the decimal point.
|
||||
*/
|
||||
final int scale;
|
||||
|
||||
/**
|
||||
* The number of digits.
|
||||
*/
|
||||
final int digits;
|
||||
|
||||
/**
|
||||
* Create a new instance of the dyn fixed.
|
||||
*/
|
||||
public gnuDynFixed(TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory, ORB anOrb
|
||||
)
|
||||
{
|
||||
super(oType, aType, aFactory, anOrb);
|
||||
try
|
||||
{
|
||||
digits = final_type.fixed_digits();
|
||||
scale = final_type.fixed_scale();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new BAD_PARAM("Not a fixed");
|
||||
}
|
||||
value = ZERO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the current instance.
|
||||
*/
|
||||
public gnuDynFixed(gnuDynFixed from)
|
||||
{
|
||||
super(from.official_type, from.final_type, from.factory, from.orb);
|
||||
digits = from.digits;
|
||||
scale = from.scale;
|
||||
value = from.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the wrapped dyn fixed, as string.
|
||||
*/
|
||||
public String get_value()
|
||||
{
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value.
|
||||
*/
|
||||
public boolean set_value(String fixed_value)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
// Count the digits till decimal point.
|
||||
int digs = 0;
|
||||
char c;
|
||||
boolean leading0 = true;
|
||||
Digs:
|
||||
for (int i = 0; i < fixed_value.length(); i++)
|
||||
{
|
||||
c = fixed_value.charAt(i);
|
||||
if (Character.isDigit(c))
|
||||
{
|
||||
if (!(c == '0' && leading0))
|
||||
digs++;
|
||||
if (c != '0')
|
||||
leading0 = false;
|
||||
}
|
||||
else if (c == '.')
|
||||
break Digs;
|
||||
}
|
||||
if (digs > (digits - scale))
|
||||
throw new InvalidValue("Too many digits: " + digs + " for " + digits +
|
||||
"." + scale
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
value = new BigDecimal(fixed_value);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
if (fixed_value.trim().length() == 0)
|
||||
throw new InvalidValue("Empty string passed");
|
||||
|
||||
TypeMismatch inva =
|
||||
new TypeMismatch("Not a number: '" + fixed_value + "'");
|
||||
inva.initCause(ex);
|
||||
throw inva;
|
||||
}
|
||||
|
||||
valueChanged();
|
||||
return value.scale() <= scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign the value from another BigDecimal.
|
||||
*/
|
||||
public void assign(DynAny from) throws TypeMismatch
|
||||
{
|
||||
checkType(official_type, from.type());
|
||||
|
||||
if (from instanceof gnuDynFixed)
|
||||
{
|
||||
gnuDynFixed other = (gnuDynFixed) from;
|
||||
value = other.value;
|
||||
}
|
||||
else if (from instanceof DynFixedOperations)
|
||||
{
|
||||
value = new BigDecimal(((DynFixedOperations) from).get_value());
|
||||
}
|
||||
else
|
||||
throw new TypeMismatch("Not a DynFixed");
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a copy.
|
||||
*/
|
||||
public DynAny copy()
|
||||
{
|
||||
return new gnuDynFixed(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare for equality.
|
||||
*/
|
||||
public boolean equal(DynAny other)
|
||||
{
|
||||
if (other instanceof gnuDynFixed)
|
||||
{
|
||||
// Normally, this code would be executed.
|
||||
return value.equals(((gnuDynFixed) other).value);
|
||||
}
|
||||
if (other instanceof DynFixedOperations)
|
||||
{
|
||||
// This may be involved when mixing implementations.
|
||||
return ((DynFixedOperations) other).get_value().equals(get_value());
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value from Any (must hold <code>fixed</code> with the matching
|
||||
* typecode.).
|
||||
*/
|
||||
public void from_any(Any an_any) throws TypeMismatch, InvalidValue
|
||||
{
|
||||
try
|
||||
{
|
||||
checkType(official_type, an_any.type());
|
||||
|
||||
value = an_any.extract_fixed();
|
||||
valueChanged();
|
||||
}
|
||||
catch (BAD_OPERATION e)
|
||||
{
|
||||
InvalidValue t = new InvalidValue();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return Any, holding this DynFixed value.
|
||||
*/
|
||||
public Any to_any()
|
||||
{
|
||||
Any g = createAny();
|
||||
g.insert_fixed(value, official_type);
|
||||
return g;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,254 @@
|
|||
/* gnuDynSequence.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.CORBA.DynAn;
|
||||
|
||||
import gnu.CORBA.Unexpected;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.TypeCodePackage.BadKind;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode;
|
||||
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
||||
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
||||
import org.omg.DynamicAny.DynSequence;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
public class gnuDynSequence
|
||||
extends gnuDynArray
|
||||
implements DynSequence, Serializable
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The bound of the sequence, as defined in typecode.
|
||||
*/
|
||||
final int bound;
|
||||
|
||||
/**
|
||||
* Create a new gnuDynSequence with the given typecode.
|
||||
*
|
||||
* @throws BAD_PARAM if the passed typecode is probably not a sequence
|
||||
* typecode.
|
||||
*/
|
||||
public gnuDynSequence(TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory, ORB anOrb
|
||||
)
|
||||
throws BAD_PARAM
|
||||
{
|
||||
super(oType, aType, aFactory, anOrb, false);
|
||||
array = new DynAny[ 0 ];
|
||||
try
|
||||
{
|
||||
bound = final_type.length();
|
||||
}
|
||||
catch (BadKind ex)
|
||||
{
|
||||
throw new Unexpected(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length of the sequence.
|
||||
*/
|
||||
public int get_length()
|
||||
{
|
||||
return array.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the sequence, preserving components.
|
||||
*/
|
||||
public void set_length(int length)
|
||||
throws InvalidValue
|
||||
{
|
||||
checkBound(length);
|
||||
if (length == array.length)
|
||||
return; // Nothing to do.
|
||||
else if (length < array.length)
|
||||
{
|
||||
// Truncate.
|
||||
DynAny[] d = new DynAny[ length ];
|
||||
for (int i = 0; i < d.length; i++)
|
||||
d [ i ] = array [ i ];
|
||||
array = d;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Expand.
|
||||
DynAny[] d = new DynAny[ length ];
|
||||
for (int i = 0; i < array.length; i++)
|
||||
d [ i ] = array [ i ];
|
||||
|
||||
for (int i = array.length; i < d.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
d [ i ] =
|
||||
factory.create_dyn_any_from_type_code(official_components);
|
||||
}
|
||||
catch (InconsistentTypeCode e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
}
|
||||
array = d;
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy one DynAny into another.
|
||||
*/
|
||||
public void assign(DynAny from)
|
||||
throws TypeMismatch
|
||||
{
|
||||
checkType(official_type, from.type());
|
||||
if (from instanceof DynSequence)
|
||||
{
|
||||
DynSequence dyn = (DynSequence) from;
|
||||
array = dyn.get_elements_as_dyn_any();
|
||||
}
|
||||
else
|
||||
throw new TypeMismatch();
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the contenst of the sequence, resizing if required.
|
||||
*/
|
||||
public void set_elements_as_dyn_any(DynAny[] value)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
checkBound(value.length);
|
||||
if (array.length != value.length)
|
||||
set_length(value.length);
|
||||
|
||||
for (int i = 0; i < value.length; i++)
|
||||
{
|
||||
checkType(official_components, value [ i ].type());
|
||||
array [ i ].assign(value [ i ]);
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the elements from array of Any's.
|
||||
*/
|
||||
public void set_elements(Any[] value)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
checkBound(value.length);
|
||||
|
||||
DynAny[] prev = array;
|
||||
|
||||
array = new DynAny[ value.length ];
|
||||
try
|
||||
{
|
||||
super.set_elements(value);
|
||||
|
||||
// valueChanged() is called in super.set_elements(value).
|
||||
}
|
||||
|
||||
// On the problem, value does not change.
|
||||
catch (TypeMismatch ex)
|
||||
{
|
||||
array = prev;
|
||||
throw ex;
|
||||
}
|
||||
catch (InvalidValue ex)
|
||||
{
|
||||
array = prev;
|
||||
throw ex;
|
||||
}
|
||||
catch (RuntimeException rex)
|
||||
{
|
||||
array = prev;
|
||||
throw rex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a copy.
|
||||
*/
|
||||
public DynAny copy()
|
||||
{
|
||||
DynAny[] c = new DynAny[ array.length ];
|
||||
for (int i = 0; i < c.length; i++)
|
||||
{
|
||||
c [ i ] = array [ i ].copy();
|
||||
}
|
||||
|
||||
gnuDynSequence d =
|
||||
new gnuDynSequence(official_type, final_type, factory, orb);
|
||||
d.array = c;
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the bound.
|
||||
*
|
||||
* @param x the value to check.
|
||||
*/
|
||||
void checkBound(int x)
|
||||
throws InvalidValue
|
||||
{
|
||||
if (bound != 0)
|
||||
if (x < 0 || x > bound)
|
||||
throw new InvalidValue(x + " out of bounds, valid [0.." + bound + "]");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if array size is valid. Called from from_any.
|
||||
*/
|
||||
protected void checkArrayValid(Object members)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
checkBound(Array.getLength(members));
|
||||
if (get_length() != Array.getLength(members))
|
||||
set_length(Array.getLength(members));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/* gnuDynStruct.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.CORBA.DynAn;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.DynamicAny.DynStruct;
|
||||
import org.omg.DynamicAny.NameDynAnyPair;
|
||||
import org.omg.DynamicAny.NameValuePair;
|
||||
import gnu.CORBA.Unexpected;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
|
||||
/**
|
||||
* Implementation of the DynStruct.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuDynStruct
|
||||
extends abstractRecord
|
||||
implements DynStruct, Serializable
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* Create an instance.
|
||||
*/
|
||||
public gnuDynStruct(TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory, ORB anOrb)
|
||||
{
|
||||
super(oType, aType, aFactory, anOrb);
|
||||
|
||||
// Initialise fields.
|
||||
try
|
||||
{
|
||||
array = new DynAny[ final_type.member_count() ];
|
||||
fNames = new String[ array.length ];
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
array [ i ] =
|
||||
factory.create_dyn_any_from_type_code(final_type.member_type(i));
|
||||
fNames [ i ] = final_type.member_name(i);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
protected abstractRecord newInstance(TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory, ORB anOrb)
|
||||
{
|
||||
return new gnuDynStruct(oType, aType, aFactory, anOrb);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public NameDynAnyPair[] get_members_as_dyn_any()
|
||||
{
|
||||
return super.gnu_get_members_as_dyn_any();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public NameValuePair[] get_members()
|
||||
{
|
||||
return super.gnu_get_members();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,439 @@
|
|||
/* gnuDynUnion.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.CORBA.DynAn;
|
||||
|
||||
import gnu.CORBA.Unexpected;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.MARSHAL;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.TCKind;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.TypeCodePackage.BadKind;
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode;
|
||||
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
||||
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
||||
import org.omg.DynamicAny.DynUnion;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Implementation of DynUnion.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuDynUnion
|
||||
extends anyDivideable
|
||||
implements DynUnion, Serializable, valueChangedListener
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The discrimintor of this union.
|
||||
*/
|
||||
DynAny discriminator;
|
||||
|
||||
/**
|
||||
* The message string that occurs several times throwing exception.
|
||||
*/
|
||||
static String NOAM = "No active member";
|
||||
|
||||
/**
|
||||
* Create a new instance with the given typecode.
|
||||
*
|
||||
* @param aType the final_type, must be final_type of the union.
|
||||
*/
|
||||
public gnuDynUnion(TypeCode oType, TypeCode aType, gnuDynAnyFactory aFactory,
|
||||
ORB anOrb
|
||||
)
|
||||
throws InconsistentTypeCode
|
||||
{
|
||||
super(oType, aType, aFactory, anOrb);
|
||||
try
|
||||
{
|
||||
discriminator =
|
||||
factory.create_dyn_any_from_type_code(final_type.discriminator_type());
|
||||
|
||||
((abstractDynAny) discriminator).listener = this;
|
||||
|
||||
if (final_type.default_index() >= 0)
|
||||
set_to_default_member();
|
||||
else
|
||||
set_to_no_active_member();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
InconsistentTypeCode inc = new InconsistentTypeCode("discriminator");
|
||||
inc.initCause(ex);
|
||||
throw inc;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see gnu.CORBA.DynAn.anyDivideable#to_any()
|
||||
*/
|
||||
public Any to_any()
|
||||
{
|
||||
Any a = createAny();
|
||||
OutputStream ou = a.create_output_stream();
|
||||
discriminator.to_any().write_value(ou);
|
||||
if (array.length == 2)
|
||||
array [ 1 ].to_any().write_value(ou);
|
||||
a.read_value(ou.create_input_stream(), final_type);
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign from another identical structure.
|
||||
*/
|
||||
public void assign(DynAny from)
|
||||
throws TypeMismatch
|
||||
{
|
||||
checkType(official_type, from.type());
|
||||
if (!(from instanceof DynUnion))
|
||||
throw new TypeMismatch("DynUnion required");
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
DynUnion u = (DynUnion) from;
|
||||
discriminator.assign(u.get_discriminator());
|
||||
if (u.has_no_active_member())
|
||||
{
|
||||
if (array.length != 1)
|
||||
array = new DynAny[] { discriminator };
|
||||
}
|
||||
else
|
||||
{
|
||||
if (array.length != 2)
|
||||
array = new DynAny[] { discriminator, u.member().copy() };
|
||||
else
|
||||
array [ 1 ] = u.member().copy();
|
||||
}
|
||||
}
|
||||
catch (InvalidValue e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public DynAny copy()
|
||||
{
|
||||
try
|
||||
{
|
||||
gnuDynUnion other =
|
||||
new gnuDynUnion(official_type, final_type, factory, orb);
|
||||
other.discriminator = discriminator.copy();
|
||||
((abstractDynAny) other.discriminator).listener = other;
|
||||
if (array.length == 1)
|
||||
{
|
||||
other.array = new DynAny[] { other.discriminator };
|
||||
}
|
||||
else
|
||||
{
|
||||
other.array =
|
||||
new DynAny[] { other.discriminator, array [ 1 ].copy() };
|
||||
}
|
||||
return other;
|
||||
}
|
||||
catch (InconsistentTypeCode ex)
|
||||
{
|
||||
throw new Unexpected(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Done via reading from stream.
|
||||
*/
|
||||
public void from_any(Any an_any)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
checkType(official_type, an_any.type());
|
||||
|
||||
Any adis = createAny();
|
||||
try
|
||||
{
|
||||
InputStream stream = an_any.create_input_stream();
|
||||
adis.read_value(stream, final_type.discriminator_type());
|
||||
|
||||
DynAny nd = factory.create_dyn_any(adis);
|
||||
|
||||
set_discriminator(nd);
|
||||
if (array.length == 2)
|
||||
{
|
||||
// Reusing the same Any <code>adis</code>.
|
||||
adis.read_value(stream, array [ 1 ].type());
|
||||
array [ 1 ].from_any(adis);
|
||||
}
|
||||
}
|
||||
catch (InconsistentTypeCode it)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(it);
|
||||
throw t;
|
||||
}
|
||||
catch (MARSHAL m)
|
||||
{
|
||||
InvalidValue t = new InvalidValue();
|
||||
t.initCause(m);
|
||||
throw t;
|
||||
}
|
||||
catch (BadKind b)
|
||||
{
|
||||
throw new Unexpected(b);
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public TCKind discriminator_kind()
|
||||
{
|
||||
return discriminator.type().kind();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public DynAny get_discriminator()
|
||||
{
|
||||
return discriminator;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public boolean has_no_active_member()
|
||||
{
|
||||
return array.length == 1;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public TCKind member_kind()
|
||||
throws InvalidValue
|
||||
{
|
||||
return member().type().kind();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the current variant of the union.
|
||||
*/
|
||||
public String member_name()
|
||||
throws InvalidValue
|
||||
{
|
||||
if (array.length == 1)
|
||||
throw new InvalidValue(NOAM);
|
||||
try
|
||||
{
|
||||
Any da = discriminator.to_any();
|
||||
|
||||
|
||||
// Get the discriminator variant.
|
||||
Variants:
|
||||
for (int i = 0; i < final_type.member_count(); i++)
|
||||
{
|
||||
if (final_type.member_label(i).equal(da))
|
||||
return final_type.member_name(i);
|
||||
}
|
||||
throw new InvalidValue(NOAM);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
InvalidValue t = new InvalidValue("Err");
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public DynAny member()
|
||||
throws InvalidValue
|
||||
{
|
||||
if (array.length < 2)
|
||||
throw new InvalidValue(NOAM);
|
||||
else
|
||||
return array [ 1 ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the union discriminator.
|
||||
*/
|
||||
public void set_discriminator(DynAny aDiscriminator)
|
||||
throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!aDiscriminator.type().equal(final_type.discriminator_type()))
|
||||
throw new TypeMismatch("Wrong discriminator final_type for " +
|
||||
final_type.name()
|
||||
);
|
||||
|
||||
// Seting the same discriminator value again should not change
|
||||
// the fields of the current member.
|
||||
if (!discriminator.equal(aDiscriminator))
|
||||
{
|
||||
discriminator.assign(aDiscriminator);
|
||||
updateMember();
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = array.length == 2 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to default member, if one exists.
|
||||
*/
|
||||
public void set_to_default_member()
|
||||
throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
int di = final_type.default_index();
|
||||
if (di < 0)
|
||||
throw new TypeMismatch("Union " + final_type.name() +
|
||||
"has no default index"
|
||||
);
|
||||
|
||||
Any da = final_type.member_label(di);
|
||||
discriminator.from_any(da);
|
||||
updateMember();
|
||||
}
|
||||
catch (TypeMismatch m)
|
||||
{
|
||||
// This one OK.
|
||||
throw m;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void set_to_no_active_member()
|
||||
throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
if (final_type.default_index() >= 0)
|
||||
{
|
||||
throw new TypeMismatch("Explicit default case defined.");
|
||||
}
|
||||
}
|
||||
catch (BadKind ex)
|
||||
{
|
||||
// The default index is not set.
|
||||
}
|
||||
array = new DynAny[] { discriminator };
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update member, in accordance with discriminator value.
|
||||
*/
|
||||
public void updateMember()
|
||||
throws TypeMismatch
|
||||
{
|
||||
try
|
||||
{
|
||||
Any da = discriminator.to_any();
|
||||
|
||||
|
||||
// Get the discriminator variant.
|
||||
Variants:
|
||||
for (int i = 0; i < final_type.member_count(); i++)
|
||||
{
|
||||
if (final_type.member_label(i).equal(da))
|
||||
{
|
||||
array =
|
||||
new DynAny[]
|
||||
{
|
||||
discriminator,
|
||||
factory.create_dyn_any_from_type_code(final_type.member_type(i))
|
||||
};
|
||||
pos = 1;
|
||||
valueChanged();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
|
||||
// Discrimintator does not point to valid member.
|
||||
array = new DynAny[] { discriminator };
|
||||
pos = 0;
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the discriminator is changed.
|
||||
*/
|
||||
public void changed()
|
||||
{
|
||||
try
|
||||
{
|
||||
updateMember();
|
||||
}
|
||||
catch (TypeMismatch ex)
|
||||
{
|
||||
throw new Unexpected(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,382 @@
|
|||
/* gnuDynValue.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.CORBA.DynAn;
|
||||
|
||||
import gnu.CORBA.Unexpected;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.MARSHAL;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.TCKind;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.VM_TRUNCATABLE;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
import org.omg.CORBA.portable.ValueFactory;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
||||
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
||||
import org.omg.DynamicAny.DynStruct;
|
||||
import org.omg.DynamicAny.DynValue;
|
||||
import org.omg.DynamicAny.DynValueCommon;
|
||||
import org.omg.DynamicAny.DynValueOperations;
|
||||
import org.omg.DynamicAny.NameDynAnyPair;
|
||||
import org.omg.DynamicAny.NameValuePair;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Implementation of DynValue.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuDynValue extends abstractRecord implements DynValue,
|
||||
Serializable
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* If true, the value of this ValueType is set to null.
|
||||
*/
|
||||
boolean isNull;
|
||||
|
||||
/**
|
||||
* Create an instance.
|
||||
*/
|
||||
public gnuDynValue(TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory, ORB anOrb
|
||||
)
|
||||
{
|
||||
super(oType, aType, aFactory, anOrb);
|
||||
|
||||
// Initialise fields. The array of fields also includes all inherited
|
||||
// fields.
|
||||
try
|
||||
{
|
||||
array = new DynAny[ final_type.member_count() ];
|
||||
fNames = new String[ array.length ];
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
array [ i ] =
|
||||
factory.create_dyn_any_from_type_code(final_type.member_type(i));
|
||||
fNames [ i ] = final_type.member_name(i);
|
||||
}
|
||||
|
||||
// Search of inherited members.
|
||||
if (final_type.type_modifier() == VM_TRUNCATABLE.value)
|
||||
{
|
||||
TypeCode parent = final_type.concrete_base_type();
|
||||
DynAny ancestor = factory.create_dyn_any_from_type_code(parent);
|
||||
|
||||
if (ancestor instanceof DynValue)
|
||||
{
|
||||
// Add members of ancestor in front of the curren members.
|
||||
DynValue anc = (DynValue) ancestor;
|
||||
anc.set_to_value();
|
||||
|
||||
NameDynAnyPair[] aar = anc.get_members_as_dyn_any();
|
||||
inheritFields(aar);
|
||||
}
|
||||
else if (ancestor instanceof DynStruct)
|
||||
{
|
||||
// Add members of ancestor in front of the curren members.
|
||||
DynStruct anc = (DynStruct) ancestor;
|
||||
NameDynAnyPair[] aar = anc.get_members_as_dyn_any();
|
||||
inheritFields(aar);
|
||||
}
|
||||
else
|
||||
throw new BAD_PARAM("The parent of " + final_type.id() + ", " +
|
||||
parent.id() + ", is not structure nor value."
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
|
||||
set_to_null();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit the provided fields.
|
||||
*/
|
||||
private void inheritFields(NameDynAnyPair[] aar)
|
||||
{
|
||||
DynAny[] nArray = new DynAny[ array.length + aar.length ];
|
||||
String[] nNames = new String[ array.length + aar.length ];
|
||||
int p = 0;
|
||||
for (int i = 0; i < aar.length; i++)
|
||||
{
|
||||
nArray [ p ] = aar [ i ].value;
|
||||
nNames [ p ] = aar [ i ].id;
|
||||
p++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
nArray [ p ] = array [ i ];
|
||||
nNames [ p ] = fNames [ i ];
|
||||
p++;
|
||||
}
|
||||
|
||||
array = nArray;
|
||||
fNames = nNames;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public TCKind current_member_kind() throws TypeMismatch, InvalidValue
|
||||
{
|
||||
if (isNull)
|
||||
throw new TypeMismatch(ISNULL);
|
||||
else
|
||||
return super.current_member_kind();
|
||||
}
|
||||
;
|
||||
|
||||
/** @inheritDoc */
|
||||
public String current_member_name() throws TypeMismatch, InvalidValue
|
||||
{
|
||||
if (isNull)
|
||||
throw new TypeMismatch(ISNULL);
|
||||
else
|
||||
return super.current_member_name();
|
||||
}
|
||||
;
|
||||
|
||||
/** @inheritDoc */
|
||||
public NameDynAnyPair[] get_members_as_dyn_any() throws InvalidValue
|
||||
{
|
||||
if (isNull)
|
||||
throw new InvalidValue(ISNULL);
|
||||
return super.gnu_get_members_as_dyn_any();
|
||||
}
|
||||
;
|
||||
|
||||
/** @inheritDoc */
|
||||
public NameValuePair[] get_members() throws InvalidValue
|
||||
{
|
||||
if (isNull)
|
||||
throw new InvalidValue(ISNULL);
|
||||
else
|
||||
return super.gnu_get_members();
|
||||
}
|
||||
;
|
||||
|
||||
/** @inheritDoc */
|
||||
public void set_members_as_dyn_any(NameDynAnyPair[] value)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
super.set_members_as_dyn_any(value);
|
||||
isNull = false;
|
||||
}
|
||||
;
|
||||
|
||||
/** @inheritDoc */
|
||||
public void set_members(NameValuePair[] value)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
super.set_members(value);
|
||||
isNull = false;
|
||||
}
|
||||
;
|
||||
|
||||
/** @inheritDoc */
|
||||
public boolean is_null()
|
||||
{
|
||||
return isNull;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void set_to_null()
|
||||
{
|
||||
isNull = true;
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void set_to_value()
|
||||
{
|
||||
isNull = false;
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
protected abstractRecord newInstance(TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory, ORB anOrb
|
||||
)
|
||||
{
|
||||
gnuDynValue v = new gnuDynValue(oType, aType, aFactory, anOrb);
|
||||
if (isNull)
|
||||
v.set_to_null();
|
||||
else
|
||||
v.set_to_value();
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare for equality, minding null values.
|
||||
*/
|
||||
public boolean equal(DynAny other)
|
||||
{
|
||||
if (other instanceof DynValueOperations)
|
||||
{
|
||||
DynValueCommon o = (DynValueCommon) other;
|
||||
if (isNull)
|
||||
return o.is_null() && o.type().equal(official_type);
|
||||
else
|
||||
return !o.is_null() && super.equal(other);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the focused component, throwing exception if the current value is null.
|
||||
*/
|
||||
protected DynAny focused() throws InvalidValue, TypeMismatch
|
||||
{
|
||||
if (isNull)
|
||||
throw new TypeMismatch(ISNULL);
|
||||
else
|
||||
return super.focused();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert into Any.
|
||||
*/
|
||||
public Any to_any()
|
||||
{
|
||||
if (isNull)
|
||||
{
|
||||
Any a0 = createAny();
|
||||
a0.type(orb.get_primitive_tc(TCKind.tk_null));
|
||||
return a0;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
ValueFactory factory =
|
||||
((org.omg.CORBA_2_3.ORB) orb).lookup_value_factory(official_type.id());
|
||||
if (factory == null)
|
||||
throw new MARSHAL("Factory for " + official_type.id() +
|
||||
" not registered."
|
||||
);
|
||||
|
||||
OutputStream out = orb.create_output_stream();
|
||||
|
||||
for (int i = 0; i < array.length; i++)
|
||||
array [ i ].to_any().write_value(out);
|
||||
|
||||
org.omg.CORBA_2_3.portable.InputStream in =
|
||||
(org.omg.CORBA_2_3.portable.InputStream) out.create_input_stream();
|
||||
Serializable v = factory.read_value(in);
|
||||
|
||||
Any g = createAny();
|
||||
g.type(official_type);
|
||||
g.insert_Value(v, official_type);
|
||||
|
||||
return g;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void assign(DynAny from) throws TypeMismatch
|
||||
{
|
||||
checkType(official_type, from.type());
|
||||
|
||||
if (from instanceof DynValue)
|
||||
{
|
||||
DynValue other = (DynValue) from;
|
||||
if (other.is_null())
|
||||
set_to_null();
|
||||
else
|
||||
{
|
||||
set_to_value();
|
||||
try
|
||||
{
|
||||
DynValueOperations src = (DynValueOperations) from;
|
||||
set_members_as_dyn_any(src.get_members_as_dyn_any());
|
||||
}
|
||||
catch (InvalidValue e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch("Invalid value");
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new TypeMismatch("Not a DynValue");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of components.
|
||||
*/
|
||||
public int component_count()
|
||||
{
|
||||
return isNull ? 0 : super.component_count();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Serializable get_val() throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return to_any().extract_Value();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_val(Serializable a_x) throws InvalidValue, TypeMismatch
|
||||
{
|
||||
Any a = to_any();
|
||||
a.insert_Value(a_x);
|
||||
from_any(a);
|
||||
valueChanged();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,389 @@
|
|||
/* gnuDynValueBox.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.CORBA.DynAn;
|
||||
|
||||
import gnu.CORBA.Unexpected;
|
||||
import gnu.CORBA.holderFactory;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.TCKind;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.TypeCodePackage.BadKind;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode;
|
||||
import org.omg.DynamicAny.DynAnyPackage.InvalidValue;
|
||||
import org.omg.DynamicAny.DynAnyPackage.TypeMismatch;
|
||||
import org.omg.DynamicAny.DynValueBox;
|
||||
import org.omg.DynamicAny.DynValueBoxOperations;
|
||||
import org.omg.DynamicAny.DynValueCommon;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Implementation of the DynValueBox.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuDynValueBox
|
||||
extends anyDivideable
|
||||
implements DynValueBox, Serializable
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The final_type of contents of this value box.
|
||||
*/
|
||||
final TypeCode content;
|
||||
|
||||
/**
|
||||
* The string for some TypeMismatch exceptions.
|
||||
*/
|
||||
String CONTENT = "Box content final_type mismatch";
|
||||
|
||||
/**
|
||||
* Create a new instance of gnuDynValueBox.
|
||||
*/
|
||||
public gnuDynValueBox(TypeCode oType, TypeCode aType,
|
||||
gnuDynAnyFactory aFactory, ORB anOrb
|
||||
)
|
||||
{
|
||||
super(oType, aType, aFactory, anOrb);
|
||||
try
|
||||
{
|
||||
content = final_type.content_type();
|
||||
array = new DynAny[] { factory.create_dyn_any_from_type_code(content) };
|
||||
set_to_null();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void assign(DynAny from)
|
||||
throws TypeMismatch
|
||||
{
|
||||
checkType(official_type, from.type());
|
||||
if (from instanceof DynValueBoxOperations)
|
||||
{
|
||||
DynValueBoxOperations other = (DynValueBoxOperations) from;
|
||||
if (other.is_null())
|
||||
set_to_null();
|
||||
else
|
||||
{
|
||||
DynAny inBox;
|
||||
try
|
||||
{
|
||||
inBox = other.get_boxed_value_as_dyn_any();
|
||||
}
|
||||
catch (InvalidValue e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch("Invalid value");
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
if (!content.equal(inBox.type()))
|
||||
throw new TypeMismatch(CONTENT);
|
||||
array = new DynAny[] { inBox.copy() };
|
||||
}
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public DynAny copy()
|
||||
{
|
||||
gnuDynValueBox other =
|
||||
new gnuDynValueBox(official_type, final_type, factory, orb);
|
||||
if (is_null())
|
||||
other.set_to_null();
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
other.array = new DynAny[] { array [ 0 ].copy() };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null for null value, delegates to super. otherwise.
|
||||
*/
|
||||
public DynAny current_component()
|
||||
throws TypeMismatch
|
||||
{
|
||||
if (is_null())
|
||||
return null;
|
||||
else
|
||||
return super.current_component();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare for equality, minding null values.
|
||||
*/
|
||||
public boolean equal(DynAny other)
|
||||
{
|
||||
if (other instanceof DynValueCommon)
|
||||
{
|
||||
DynValueCommon o = (DynValueCommon) other;
|
||||
if (is_null())
|
||||
return o.is_null() && o.type().equal(official_type);
|
||||
else
|
||||
return !o.is_null() && super.equal(other);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void from_any(Any an_any)
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
checkType(official_type, an_any.type());
|
||||
try
|
||||
{
|
||||
if (!an_any.type().content_type().equal(content))
|
||||
throw new InvalidValue(CONTENT);
|
||||
}
|
||||
catch (BadKind e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch("Not a box");
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
|
||||
Serializable s = an_any.extract_Value();
|
||||
if (s == null)
|
||||
set_to_null();
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
Streamable holder = holderFactory.createHolder(content);
|
||||
Field v = holder.getClass().getField("value");
|
||||
v.set(holder, s);
|
||||
|
||||
Any cont = createAny();
|
||||
cont.insert_Streamable(holder);
|
||||
|
||||
array = new DynAny[] { factory.create_dyn_any(cont) };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Unexpected(ex);
|
||||
}
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public Any get_boxed_value()
|
||||
throws InvalidValue
|
||||
{
|
||||
try
|
||||
{
|
||||
if (is_null())
|
||||
throw new InvalidValue(ISNULL);
|
||||
else
|
||||
return array [ 0 ].to_any();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
InvalidValue t = new InvalidValue();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public DynAny get_boxed_value_as_dyn_any()
|
||||
throws InvalidValue
|
||||
{
|
||||
if (is_null())
|
||||
throw new InvalidValue(ISNULL);
|
||||
else
|
||||
return array [ 0 ].copy();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Serializable get_val()
|
||||
throws TypeMismatch, InvalidValue
|
||||
{
|
||||
return to_any().extract_Value();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void insert_val(Serializable a_x)
|
||||
throws InvalidValue, TypeMismatch
|
||||
{
|
||||
Any a = to_any();
|
||||
a.insert_Value(a_x);
|
||||
from_any(a);
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public boolean is_null()
|
||||
{
|
||||
return array.length == 0;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void set_boxed_value(Any boxIt)
|
||||
throws TypeMismatch
|
||||
{
|
||||
if (!content.equal(boxIt.type()))
|
||||
throw new TypeMismatch(CONTENT);
|
||||
try
|
||||
{
|
||||
if (is_null())
|
||||
{
|
||||
array = new DynAny[] { factory.create_dyn_any(boxIt) };
|
||||
}
|
||||
else
|
||||
{
|
||||
array [ 0 ].from_any(boxIt);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void set_boxed_value_as_dyn_any(DynAny boxIt)
|
||||
throws TypeMismatch
|
||||
{
|
||||
if (!content.equal(boxIt.type()))
|
||||
throw new TypeMismatch(CONTENT);
|
||||
try
|
||||
{
|
||||
if (is_null())
|
||||
{
|
||||
array = new DynAny[] { boxIt.copy() };
|
||||
}
|
||||
else
|
||||
{
|
||||
array [ 0 ].assign(boxIt);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TypeMismatch t = new TypeMismatch();
|
||||
t.initCause(e);
|
||||
throw t;
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void set_to_null()
|
||||
{
|
||||
array = new DynAny[ 0 ];
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void set_to_value()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (array.length == 0)
|
||||
{
|
||||
array =
|
||||
new DynAny[] { factory.create_dyn_any_from_type_code(content) };
|
||||
}
|
||||
}
|
||||
catch (InconsistentTypeCode e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public Any to_any()
|
||||
{
|
||||
Any a = createAny();
|
||||
|
||||
if (!is_null())
|
||||
{
|
||||
try
|
||||
{
|
||||
Streamable holder;
|
||||
if (array [ 0 ] instanceof gnuDynAny)
|
||||
holder = ((gnuDynAny) array [ 0 ]).holder;
|
||||
else
|
||||
{
|
||||
Any uan = array [ 0 ].to_any();
|
||||
holder = uan.extract_Streamable();
|
||||
}
|
||||
|
||||
Field v = holder.getClass().getField("value");
|
||||
Serializable value = (Serializable) v.get(holder);
|
||||
a.type(official_type);
|
||||
a.insert_Value(value, content);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Unexpected(ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
a.type(orb.get_primitive_tc(TCKind.tk_null));
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/* valueChangedListener.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.CORBA.DynAn;
|
||||
|
||||
/**
|
||||
* An interface, able to receive notification about the change of value
|
||||
* of some DynAny.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public interface valueChangedListener
|
||||
{
|
||||
void changed();
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
/* DynAnySeqHolder.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.CORBA;
|
||||
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.DynamicAny.DynAny;
|
||||
import org.omg.DynamicAny.DynAnySeqHelper;
|
||||
|
||||
/**
|
||||
* A holder for the sequence of {@link DynAny}
|
||||
* ({@link DynAnySeq}).
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class DynAnySeqHolder
|
||||
implements Streamable
|
||||
{
|
||||
/**
|
||||
* The stored array of <code>DynAny</code>.
|
||||
*/
|
||||
public DynAny[] value;
|
||||
|
||||
/**
|
||||
* Create the unitialised instance, leaving the value array
|
||||
* with default <code>null</code> value.
|
||||
*/
|
||||
public DynAnySeqHolder()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the initialised instance.
|
||||
* @param initialValue the array that will be assigned to
|
||||
* the <code>value</code> array.
|
||||
*/
|
||||
public DynAnySeqHolder(DynAny[] initialValue)
|
||||
{
|
||||
value = initialValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* The method should read this object from the CDR input stream, but
|
||||
* (following the JDK 1.5 API) it does not.
|
||||
*
|
||||
* @param input a org.omg.CORBA.portable stream to read from.
|
||||
*
|
||||
* @specenote Sun throws the same exception.
|
||||
*
|
||||
* @throws MARSHAL always.
|
||||
*/
|
||||
public void _read(InputStream input)
|
||||
{
|
||||
value = DynAnySeqHelper.read(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* The method should write this object to the CDR input stream, but
|
||||
* (following the JDK 1.5 API) it does not.
|
||||
*
|
||||
* @param input a org.omg.CORBA.portable stream to read from.
|
||||
*
|
||||
* @specenote Sun throws the same exception.
|
||||
*
|
||||
* @throws MARSHAL always.
|
||||
*/
|
||||
public void _write(OutputStream output)
|
||||
{
|
||||
DynAnySeqHelper.write(output, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the typecode of the DynAny.
|
||||
*/
|
||||
public org.omg.CORBA.TypeCode _type()
|
||||
{
|
||||
return DynAnySeqHelper.type();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
/* ForwardRequestHelper.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.CORBA;
|
||||
|
||||
import gnu.CORBA.Poa.ForwardRequestHolder;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_OPERATION;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.ObjectHelper;
|
||||
import org.omg.CORBA.StructMember;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
import org.omg.PortableServer.ForwardRequest;
|
||||
|
||||
/**
|
||||
* The helper operations for the exception {@link ForwardRequest}.
|
||||
*
|
||||
* @specnote The helper must be here and not in POA subpackage as it must
|
||||
* be discovered by the {@link ObjectCreator} when reading this remote
|
||||
* exception.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public abstract class ForwardRequestHelper
|
||||
{
|
||||
/**
|
||||
* The cached typecode value, computed only once.
|
||||
*/
|
||||
private static TypeCode typeCode;
|
||||
|
||||
/**
|
||||
* Extract the ForwardRequest from given Any.
|
||||
* This method uses the ForwardRequestHolder.
|
||||
*
|
||||
* @throws BAD_OPERATION if the passed Any does not contain ForwardRequest.
|
||||
*/
|
||||
public static ForwardRequest extract(Any any)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((ForwardRequestHolder) any.extract_Streamable()).value;
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
BAD_OPERATION bad = new BAD_OPERATION("ForwardRequest expected");
|
||||
bad.initCause(cex);
|
||||
throw bad;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ForwardRequest repository id.
|
||||
*
|
||||
* @return "ForwardRequest", always.
|
||||
*/
|
||||
public static String id()
|
||||
{
|
||||
return "ForwardRequest";
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the ForwardRequest into the given Any.
|
||||
* This method uses the ForwardRequestHolder.
|
||||
*
|
||||
* @param any the Any to insert into.
|
||||
* @param that the ForwardRequest to insert.
|
||||
*/
|
||||
public static void insert(Any any, ForwardRequest that)
|
||||
{
|
||||
any.insert_Streamable(new ForwardRequestHolder(that));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the exception from the CDR intput stream.
|
||||
*
|
||||
* @param input a org.omg.CORBA.portable stream to read from.
|
||||
*/
|
||||
public static ForwardRequest read(InputStream input)
|
||||
{
|
||||
// Read the exception repository id.
|
||||
String id = input.read_string();
|
||||
ForwardRequest value = new ForwardRequest();
|
||||
|
||||
value.forward_reference = input.read_Object();
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the ForwardRequest typecode (structure,
|
||||
* named "ForwardRequest").
|
||||
* The typecode states that the structure contains the
|
||||
* following fields: forward_reference.
|
||||
*/
|
||||
public static TypeCode type()
|
||||
{
|
||||
if (typeCode == null)
|
||||
{
|
||||
ORB orb = ORB.init();
|
||||
StructMember[] members = new StructMember[ 1 ];
|
||||
|
||||
TypeCode field;
|
||||
|
||||
field = ObjectHelper.type();
|
||||
members [ 0 ] = new StructMember("forward_reference", field, null);
|
||||
typeCode = orb.create_exception_tc(id(), "ForwardRequest", members);
|
||||
}
|
||||
return typeCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the exception to the CDR output stream.
|
||||
*
|
||||
* @param output a org.omg.CORBA.portable stream stream to write into.
|
||||
* @param value a value to write.
|
||||
*/
|
||||
public static void write(OutputStream output, ForwardRequest value)
|
||||
{
|
||||
// Write the exception repository id.
|
||||
output.write_string(id());
|
||||
output.write_Object(value.forward_reference);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/* contextSupportingHeader.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.CORBA.GIOP;
|
||||
|
||||
import org.omg.CORBA.BAD_INV_ORDER;
|
||||
|
||||
/**
|
||||
* A header, supporting the service contexts. Such header has a context field
|
||||
* and methods for adding the new contexts.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public abstract class contextSupportingHeader
|
||||
{
|
||||
|
||||
/**
|
||||
* Empty array, indicating that no service context is available.
|
||||
*/
|
||||
protected static final ServiceContext[] NO_CONTEXT = new ServiceContext[0];
|
||||
|
||||
/**
|
||||
* The context data.
|
||||
*/
|
||||
public ServiceContext[] service_context = NO_CONTEXT;
|
||||
|
||||
/**
|
||||
* Add service context to this header.
|
||||
*
|
||||
* @param context_to_add context to add.
|
||||
* @param replace if true, the existing context with this ID is replaced.
|
||||
* Otherwise, BAD_INV_ORDER is throwsn.
|
||||
*/
|
||||
public void addContext(org.omg.IOP.ServiceContext context_to_add,
|
||||
boolean replace)
|
||||
throws BAD_INV_ORDER
|
||||
{
|
||||
service_context = ServiceContext.add(service_context, context_to_add,
|
||||
replace);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
/* ClientRequestInterceptors.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.CORBA.Interceptor;
|
||||
|
||||
import org.omg.PortableInterceptor.ClientRequestInfo;
|
||||
import org.omg.PortableInterceptor.ClientRequestInterceptor;
|
||||
import org.omg.PortableInterceptor.ClientRequestInterceptorOperations;
|
||||
import org.omg.PortableInterceptor.ForwardRequest;
|
||||
|
||||
/**
|
||||
* A block of the all registered ClientRequest interceptors.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class ClientRequestInterceptors
|
||||
implements ClientRequestInterceptorOperations
|
||||
{
|
||||
/**
|
||||
* The array of all registered ClientRequest interceptors.
|
||||
*/
|
||||
private final ClientRequestInterceptor[] interceptors;
|
||||
|
||||
/**
|
||||
* Create the interceptor pack with the registerend interceptor array,
|
||||
* obtained from the registrator.
|
||||
*/
|
||||
public ClientRequestInterceptors(Registrator registrator)
|
||||
{
|
||||
interceptors = registrator.getClientRequestInterceptors();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void receive_exception(ClientRequestInfo info)
|
||||
throws ForwardRequest
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
interceptors [ i ].receive_exception(info);
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void receive_other(ClientRequestInfo info) throws ForwardRequest
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
interceptors [ i ].receive_other(info);
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void receive_reply(ClientRequestInfo info)
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
interceptors [ i ].receive_reply(info);
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void send_poll(ClientRequestInfo info)
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
interceptors [ i ].send_poll(info);
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void send_request(ClientRequestInfo info) throws ForwardRequest
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
interceptors [ i ].send_request(info);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call destroy on all registered interceptors.
|
||||
*/
|
||||
public void destroy()
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
interceptors [ i ].destroy();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
// OMG states we should ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class name.
|
||||
*/
|
||||
public String name()
|
||||
{
|
||||
return getClass().getName();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/* ForwardRequestHolder.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.CORBA.Interceptor;
|
||||
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.PortableInterceptor.ForwardRequest;
|
||||
import org.omg.PortableInterceptor.ForwardRequestHelper;
|
||||
|
||||
/**
|
||||
* A holder for the exception {@link ForwardRequest}.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class ForwardRequestHolder implements Streamable
|
||||
{
|
||||
/**
|
||||
* The stored ForwardRequest value.
|
||||
*/
|
||||
public ForwardRequest value;
|
||||
|
||||
/**
|
||||
* Create the unitialised instance, leaving the value field with default
|
||||
* <code>null</code> value.
|
||||
*/
|
||||
public ForwardRequestHolder()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the initialised instance.
|
||||
*
|
||||
* @param initialValue the value that will be assigned to the
|
||||
* <code>value</code> field.
|
||||
*/
|
||||
public ForwardRequestHolder(ForwardRequest initialValue)
|
||||
{
|
||||
value = initialValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in the {@link value} by data from the CDR stream.
|
||||
*
|
||||
* @param input the org.omg.CORBA.portable stream to read.
|
||||
*/
|
||||
public void _read(InputStream input)
|
||||
{
|
||||
value = ForwardRequestHelper.read(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the stored value into the CDR stream.
|
||||
*
|
||||
* @param output the org.omg.CORBA.portable stream to write.
|
||||
*/
|
||||
public void _write(OutputStream output)
|
||||
{
|
||||
ForwardRequestHelper.write(output, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the typecode of the ForwardRequest.
|
||||
*/
|
||||
public TypeCode _type()
|
||||
{
|
||||
return ForwardRequestHelper.type();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/* IORInterceptors.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.CORBA.Interceptor;
|
||||
|
||||
import org.omg.PortableInterceptor.IORInfo;
|
||||
import org.omg.PortableInterceptor.IORInterceptor;
|
||||
import org.omg.PortableInterceptor.IORInterceptorOperations;
|
||||
|
||||
/**
|
||||
* A block of the all registered IOR interceptors.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class IORInterceptors implements IORInterceptorOperations
|
||||
{
|
||||
/**
|
||||
* The array of all registered IOR interceptors.
|
||||
*/
|
||||
private final IORInterceptor[] interceptors;
|
||||
|
||||
/**
|
||||
* Create the interceptor pack with the registerend interceptor array,
|
||||
* obtained from the registrator.
|
||||
*/
|
||||
public IORInterceptors(Registrator registrator)
|
||||
{
|
||||
interceptors = registrator.getIORInterceptors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this method for all registered interceptors.
|
||||
*/
|
||||
public void establish_components(IORInfo info)
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
interceptors [ i ].establish_components(info);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
// OMG states we should ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call destroy on all registered interceptors.
|
||||
*/
|
||||
public void destroy()
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
interceptors [ i ].destroy();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
// OMG states we should ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class name.
|
||||
*/
|
||||
public String name()
|
||||
{
|
||||
return getClass().getName();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,470 @@
|
|||
/* Registrator.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.CORBA.Interceptor;
|
||||
|
||||
import gnu.CORBA.Poa.ORB_1_4;
|
||||
import gnu.CORBA.gnuCodecFactory;
|
||||
|
||||
import org.omg.CORBA.BAD_INV_ORDER;
|
||||
import org.omg.CORBA.CompletionStatus;
|
||||
import org.omg.CORBA.LocalObject;
|
||||
import org.omg.CORBA.Object;
|
||||
import org.omg.IOP.CodecFactory;
|
||||
import org.omg.PortableInterceptor.ClientRequestInterceptor;
|
||||
import org.omg.PortableInterceptor.IORInterceptor;
|
||||
import org.omg.PortableInterceptor.Interceptor;
|
||||
import org.omg.PortableInterceptor.ORBInitInfo;
|
||||
import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName;
|
||||
import org.omg.PortableInterceptor.ORBInitInfoPackage.InvalidName;
|
||||
import org.omg.PortableInterceptor.ORBInitializer;
|
||||
import org.omg.PortableInterceptor.ORBInitializerOperations;
|
||||
import org.omg.PortableInterceptor.PolicyFactory;
|
||||
import org.omg.PortableInterceptor.ServerRequestInterceptor;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* Collects interceptors, references and factories into arrays during
|
||||
* registration. As the class is security sensitive, the most of the fields are
|
||||
* private.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class Registrator extends LocalObject implements ORBInitInfo
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The agreed properties prefix.
|
||||
*/
|
||||
public final static String m_prefix =
|
||||
"org.omg.PortableInterceptor.ORBInitializerClass.";
|
||||
|
||||
/**
|
||||
* The initialization - time server request interceptors.
|
||||
*/
|
||||
private ArrayList m_server = new ArrayList();
|
||||
|
||||
/**
|
||||
* The initialization - time client request interceptors.
|
||||
*/
|
||||
private ArrayList m_client = new ArrayList();
|
||||
|
||||
/**
|
||||
* The initialization - time ior interceptors.
|
||||
*/
|
||||
private ArrayList m_ior = new ArrayList();
|
||||
|
||||
/**
|
||||
* The policy factories.
|
||||
*/
|
||||
public Hashtable m_policyFactories = new Hashtable();
|
||||
|
||||
/**
|
||||
* The registered references. To avoid exposing the ORB's references map, the
|
||||
* are added by ORB from inside the ORB code. The ORB is responsible for
|
||||
* taking them from this field between pre_init and post_init.
|
||||
*/
|
||||
public TreeMap m_references = new TreeMap();
|
||||
|
||||
/**
|
||||
* The initializers.
|
||||
*/
|
||||
public ArrayList m_initializers = new ArrayList();
|
||||
|
||||
/**
|
||||
* The ORB being intialised.
|
||||
*/
|
||||
final ORB_1_4 orb;
|
||||
|
||||
/**
|
||||
* The argument string array, passed to ORB.init.
|
||||
*/
|
||||
final String[] m_args;
|
||||
|
||||
/**
|
||||
* The codec factory.
|
||||
*/
|
||||
final gnuCodecFactory m_codecFactory;
|
||||
|
||||
/**
|
||||
* Create the interceptor collection from the given properties, using the
|
||||
* agreed naming convention.
|
||||
*
|
||||
* @param orb the ORB being initialised.
|
||||
* @param props the cumulated set of properties where the orb initializer
|
||||
* pattern is searched.
|
||||
* @param an_args the argument string array, passed to ORB.init.
|
||||
*/
|
||||
public Registrator(ORB_1_4 an_orb, Properties props, String[] an_args)
|
||||
{
|
||||
orb = an_orb;
|
||||
m_args = an_args;
|
||||
m_codecFactory = new gnuCodecFactory(orb);
|
||||
checkProperties(props);
|
||||
checkProperties(System.getProperties());
|
||||
checkFile("user.home", null);
|
||||
checkFile("java.home", "lib");
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan the given properties for the possible interceptors.
|
||||
*/
|
||||
private void checkProperties(Properties props)
|
||||
{
|
||||
if (props == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Enumeration names = props.propertyNames();
|
||||
java.lang.Object key;
|
||||
String sk;
|
||||
|
||||
while (names.hasMoreElements())
|
||||
{
|
||||
key = names.nextElement();
|
||||
if (key != null)
|
||||
{
|
||||
sk = key.toString();
|
||||
if (sk.startsWith(m_prefix))
|
||||
{
|
||||
try
|
||||
{
|
||||
String cn = sk.substring(m_prefix.length());
|
||||
Class iClass = Class.forName(cn);
|
||||
ORBInitializer initializer =
|
||||
(ORBInitializer) iClass.newInstance();
|
||||
m_initializers.add(initializer);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
// OMG states we should not throw an exception, but
|
||||
// this will help the user to detect his error
|
||||
// in initialiser properties. Should never print during
|
||||
// normal run.
|
||||
System.err.println(sk + " failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the property is defined in the existsting file orb.properties.
|
||||
*/
|
||||
private void checkFile(String dir, String subdir)
|
||||
{
|
||||
try
|
||||
{
|
||||
File f = new File(dir);
|
||||
if (!f.exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (subdir != null)
|
||||
{
|
||||
f = new File(f, subdir);
|
||||
}
|
||||
f = new File(f, "orb.properties");
|
||||
|
||||
if (!f.exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Properties p = new Properties();
|
||||
p.load(new BufferedInputStream(new FileInputStream(f)));
|
||||
|
||||
checkProperties(p);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by ORB as a pre_init for all initializers.
|
||||
*/
|
||||
public void pre_init()
|
||||
{
|
||||
Iterator iter = m_initializers.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
ORBInitializerOperations initializer =
|
||||
(ORBInitializerOperations) iter.next();
|
||||
initializer.pre_init(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the map of the registered references. The ORB calls this method to
|
||||
* import the references into its references map.
|
||||
*/
|
||||
public Map getRegisteredReferences()
|
||||
{
|
||||
return m_references;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by ORB as a post-init for all initializers. After this call, the
|
||||
* interceptor sets are fixed and redundant information is discarded.
|
||||
*/
|
||||
public void post_init()
|
||||
{
|
||||
Iterator iter = m_initializers.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
ORBInitializerOperations initializer =
|
||||
(ORBInitializerOperations) iter.next();
|
||||
initializer.post_init(this);
|
||||
}
|
||||
}
|
||||
|
||||
public ServerRequestInterceptor[] getServerRequestInterceptors()
|
||||
{
|
||||
ServerRequestInterceptor[] iServer =
|
||||
new ServerRequestInterceptor[ m_server.size() ];
|
||||
for (int i = 0; i < iServer.length; i++)
|
||||
{
|
||||
iServer [ i ] = (ServerRequestInterceptor) m_server.get(i);
|
||||
}
|
||||
return iServer;
|
||||
}
|
||||
|
||||
public ClientRequestInterceptor[] getClientRequestInterceptors()
|
||||
{
|
||||
ClientRequestInterceptor[] iClient =
|
||||
new ClientRequestInterceptor[ m_client.size() ];
|
||||
for (int i = 0; i < iClient.length; i++)
|
||||
{
|
||||
iClient [ i ] = (ClientRequestInterceptor) m_client.get(i);
|
||||
}
|
||||
return iClient;
|
||||
}
|
||||
|
||||
public IORInterceptor[] getIORInterceptors()
|
||||
{
|
||||
IORInterceptor[] iIor = new IORInterceptor[ m_ior.size() ];
|
||||
for (int i = 0; i < iIor.length; i++)
|
||||
{
|
||||
iIor [ i ] = (IORInterceptor) m_ior.get(i);
|
||||
}
|
||||
return iIor;
|
||||
}
|
||||
|
||||
public void add_client_request_interceptor(
|
||||
ClientRequestInterceptor interceptor
|
||||
) throws DuplicateName
|
||||
{
|
||||
add(m_client, interceptor);
|
||||
}
|
||||
|
||||
public void add_ior_interceptor(IORInterceptor interceptor)
|
||||
throws DuplicateName
|
||||
{
|
||||
add(m_ior, interceptor);
|
||||
}
|
||||
|
||||
public void add_server_request_interceptor(
|
||||
ServerRequestInterceptor interceptor
|
||||
) throws DuplicateName
|
||||
{
|
||||
add(m_server, interceptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a new slot for request - specific records.
|
||||
*/
|
||||
public int allocate_slot_id()
|
||||
{
|
||||
return orb.icSlotSize++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the interceptor to the given collection.
|
||||
*
|
||||
* @param list the collection to add.
|
||||
* @param interceptor the interceptor to add.
|
||||
*/
|
||||
private void add(ArrayList list, Interceptor interceptor)
|
||||
throws DuplicateName
|
||||
{
|
||||
if (interceptor.name().length() > 0)
|
||||
{
|
||||
Iterator iter = list.iterator();
|
||||
Interceptor ic;
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
ic = (Interceptor) iter.next();
|
||||
if (ic.name().equals(interceptor.name()))
|
||||
{
|
||||
throw new DuplicateName(interceptor.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
list.add(interceptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string array, passed to ORB.init.
|
||||
*/
|
||||
public String[] arguments()
|
||||
{
|
||||
return m_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the codec factory.
|
||||
*/
|
||||
public CodecFactory codec_factory()
|
||||
{
|
||||
return m_codecFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ORB's id, currently using .toString.
|
||||
*/
|
||||
public String orb_id()
|
||||
{
|
||||
return "orb_" + orb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register reference.
|
||||
*/
|
||||
public void register_initial_reference(String object_name, Object object)
|
||||
throws InvalidName
|
||||
{
|
||||
if (object_name == null)
|
||||
{
|
||||
throw new InvalidName("null");
|
||||
}
|
||||
else if (object_name.length() == 0)
|
||||
{
|
||||
throw new InvalidName("Empty string");
|
||||
}
|
||||
else if (m_references.containsKey(object_name))
|
||||
{
|
||||
throw new InvalidName(object_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_references.put(object_name, object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accumulates the policy factory map.
|
||||
*/
|
||||
public void register_policy_factory(int policy_type,
|
||||
PolicyFactory policy_factory
|
||||
)
|
||||
{
|
||||
Integer it = new Integer(policy_type);
|
||||
if (m_policyFactories.containsKey(it))
|
||||
{
|
||||
throw new BAD_INV_ORDER(
|
||||
"Repetetive registration of the policy factory for type " +
|
||||
policy_type,
|
||||
16,
|
||||
CompletionStatus.COMPLETED_NO
|
||||
);
|
||||
}
|
||||
m_policyFactories.put(it, policy_factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to ORB.
|
||||
*/
|
||||
public org.omg.CORBA.Object resolve_initial_references(String object_name)
|
||||
throws InvalidName
|
||||
{
|
||||
try
|
||||
{
|
||||
return orb.resolve_initial_references(object_name);
|
||||
}
|
||||
catch (org.omg.CORBA.ORBPackage.InvalidName e)
|
||||
{
|
||||
InvalidName in = new InvalidName(e.getMessage());
|
||||
in.initCause(e);
|
||||
throw in;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any interceptors of this type were registered.
|
||||
*/
|
||||
public boolean hasClientRequestInterceptors()
|
||||
{
|
||||
return m_client.size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any interceptors of this type were registered.
|
||||
*/
|
||||
public boolean hasServerRequestInterceptors()
|
||||
{
|
||||
return m_server.size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any interceptors of this type were registered.
|
||||
*/
|
||||
public boolean hasIorInterceptors()
|
||||
{
|
||||
return m_ior.size() > 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
/* ServerRequestInterceptors.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.CORBA.Interceptor;
|
||||
|
||||
import org.omg.PortableInterceptor.ForwardRequest;
|
||||
import org.omg.PortableInterceptor.ServerRequestInfo;
|
||||
import org.omg.PortableInterceptor.ServerRequestInterceptor;
|
||||
import org.omg.PortableInterceptor.ServerRequestInterceptorOperations;
|
||||
|
||||
/**
|
||||
* A block of the all registered ServerRequest interceptors.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class ServerRequestInterceptors
|
||||
implements ServerRequestInterceptorOperations
|
||||
{
|
||||
/**
|
||||
* The array of all registered ServerRequest interceptors.
|
||||
*/
|
||||
private final ServerRequestInterceptor[] interceptors;
|
||||
|
||||
/**
|
||||
* Create the interceptor pack with the registerend interceptor array,
|
||||
* obtained from the registrator.
|
||||
*/
|
||||
public ServerRequestInterceptors(Registrator registrator)
|
||||
{
|
||||
interceptors = registrator.getServerRequestInterceptors();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void receive_request_service_contexts(ServerRequestInfo info)
|
||||
throws ForwardRequest
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
interceptors [ i ].receive_request_service_contexts(info);
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void receive_request(ServerRequestInfo info) throws ForwardRequest
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
interceptors [ i ].receive_request(info);
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void send_exception(ServerRequestInfo info) throws ForwardRequest
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
interceptors [ i ].send_exception(info);
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void send_other(ServerRequestInfo info) throws ForwardRequest
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
interceptors [ i ].send_other(info);
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void send_reply(ServerRequestInfo info)
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
interceptors [ i ].send_reply(info);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call destroy on all registered interceptors.
|
||||
*/
|
||||
public void destroy()
|
||||
{
|
||||
for (int i = 0; i < interceptors.length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
interceptors [ i ].destroy();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
// OMG states we should ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class name.
|
||||
*/
|
||||
public String name()
|
||||
{
|
||||
return getClass().getName();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,337 @@
|
|||
/* gnuClientRequestInfo.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.CORBA.Interceptor;
|
||||
|
||||
import gnu.CORBA.Unexpected;
|
||||
import gnu.CORBA.gnuRequest;
|
||||
|
||||
import org.omg.CORBA.ARG_IN;
|
||||
import org.omg.CORBA.ARG_INOUT;
|
||||
import org.omg.CORBA.ARG_OUT;
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.Bounds;
|
||||
import org.omg.CORBA.ExceptionList;
|
||||
import org.omg.CORBA.INV_POLICY;
|
||||
import org.omg.CORBA.LocalObject;
|
||||
import org.omg.CORBA.NVList;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.ParameterMode;
|
||||
import org.omg.CORBA.Policy;
|
||||
import org.omg.CORBA.TCKind;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.TypeCodePackage.BadKind;
|
||||
import org.omg.Dynamic.Parameter;
|
||||
import org.omg.IOP.ServiceContext;
|
||||
import org.omg.IOP.TaggedComponent;
|
||||
import org.omg.IOP.TaggedProfile;
|
||||
import org.omg.PortableInterceptor.ClientRequestInfo;
|
||||
import org.omg.PortableInterceptor.InvalidSlot;
|
||||
|
||||
/**
|
||||
* Client request info. All requests on the client side in Classpath
|
||||
* implementations are handled via gnuRequest class. This class holds the
|
||||
* instance of the gnuRequest, accessing the request info this way.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuClientRequestInfo extends LocalObject
|
||||
implements ClientRequestInfo
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The request structure, from that some methods take the needed information
|
||||
* directly. The same request structure cannot be reused in parallel threads,
|
||||
* the submission methods are synchronized.
|
||||
*/
|
||||
private final gnuRequest request;
|
||||
|
||||
/**
|
||||
* Provides possibility to set the wrapped thrown exception explicitly, where
|
||||
* applicable.
|
||||
*/
|
||||
public Any m_wrapped_exception;
|
||||
|
||||
/**
|
||||
* Create the info on the given request.
|
||||
*/
|
||||
public gnuClientRequestInfo(gnuRequest a_request)
|
||||
{
|
||||
request = a_request;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void add_request_service_context(ServiceContext service_context,
|
||||
boolean replace
|
||||
)
|
||||
{
|
||||
request.add_request_service_context(service_context, replace);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public TaggedProfile effective_profile()
|
||||
{
|
||||
return request.effective_profile();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public org.omg.CORBA.Object effective_target()
|
||||
{
|
||||
return request.effective_target();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public TaggedComponent get_effective_component(int id)
|
||||
throws BAD_PARAM
|
||||
{
|
||||
return request.get_effective_component(id);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public TaggedComponent[] get_effective_components(int id)
|
||||
throws BAD_PARAM
|
||||
{
|
||||
return request.get_effective_components(id);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public Policy get_request_policy(int type) throws INV_POLICY
|
||||
{
|
||||
return request.get_request_policy(type);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public String received_exception_id()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (m_wrapped_exception != null)
|
||||
{
|
||||
return m_wrapped_exception.type().id();
|
||||
}
|
||||
else
|
||||
{
|
||||
return request.received_exception_id();
|
||||
}
|
||||
}
|
||||
catch (BadKind e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public Any received_exception()
|
||||
{
|
||||
if (m_wrapped_exception != null)
|
||||
{
|
||||
return m_wrapped_exception;
|
||||
}
|
||||
else
|
||||
{
|
||||
return request.received_exception();
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public org.omg.CORBA.Object target()
|
||||
{
|
||||
return request.target();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public Parameter[] arguments()
|
||||
{
|
||||
request.checkDii();
|
||||
|
||||
NVList args = request.arguments();
|
||||
Parameter[] p = new Parameter[ args.count() ];
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < p.length; i++)
|
||||
{
|
||||
ParameterMode mode;
|
||||
|
||||
switch (args.item(i).flags())
|
||||
{
|
||||
case ARG_IN.value :
|
||||
mode = ParameterMode.PARAM_IN;
|
||||
break;
|
||||
|
||||
case ARG_OUT.value :
|
||||
mode = ParameterMode.PARAM_OUT;
|
||||
break;
|
||||
|
||||
case ARG_INOUT.value :
|
||||
mode = ParameterMode.PARAM_INOUT;
|
||||
break;
|
||||
|
||||
default :
|
||||
throw new Unexpected();
|
||||
}
|
||||
|
||||
p [ i ] = new Parameter(args.item(i).value(), mode);
|
||||
}
|
||||
}
|
||||
catch (Bounds e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public Any result()
|
||||
{
|
||||
request.checkDii();
|
||||
|
||||
Any rt = request.return_value();
|
||||
|
||||
if (rt == null)
|
||||
{
|
||||
ORB orb = request.orb();
|
||||
rt = orb.create_any();
|
||||
rt.type(orb.get_primitive_tc(TCKind.tk_void));
|
||||
return rt;
|
||||
}
|
||||
|
||||
return request.return_value();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public String[] contexts()
|
||||
{
|
||||
return request.ice_contexts();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public TypeCode[] exceptions()
|
||||
{
|
||||
request.checkDii();
|
||||
|
||||
ExceptionList ex = request.exceptions();
|
||||
TypeCode[] et = new TypeCode[ ex.count() ];
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < et.length; i++)
|
||||
{
|
||||
et [ i ] = ex.item(i);
|
||||
}
|
||||
}
|
||||
catch (Bounds e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
return et;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public org.omg.CORBA.Object forward_reference()
|
||||
{
|
||||
return request.forward_reference();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public String[] operation_context()
|
||||
{
|
||||
return request.operation_context();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public Any get_slot(int id) throws InvalidSlot
|
||||
{
|
||||
return request.get_slot(id);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public String operation()
|
||||
{
|
||||
return request.operation();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public short reply_status()
|
||||
{
|
||||
return request.reply_status();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public int request_id()
|
||||
{
|
||||
return request.request_id();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public boolean response_expected()
|
||||
{
|
||||
return request.response_expected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines how far the request shall progress before control is returned to
|
||||
* the client. However up till JDK 1.5 inclusive this method always returns
|
||||
* SYNC_WITH_TRANSPORT.
|
||||
*
|
||||
* @return {@link org.omg.Messaging.SYNC_WITH_TRANSPORT.value (1), always.
|
||||
*
|
||||
* @specnote as defined in the Suns 1.5 JDK API.
|
||||
*/
|
||||
public short sync_scope()
|
||||
{
|
||||
return request.sync_scope();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public ServiceContext get_reply_service_context(int ctx_name)
|
||||
throws BAD_PARAM
|
||||
{
|
||||
return request.get_reply_service_context(ctx_name);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public ServiceContext get_request_service_context(int ctx_name)
|
||||
throws BAD_PARAM
|
||||
{
|
||||
return request.get_request_service_context(ctx_name);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,255 @@
|
|||
/* gnuIcCurrent.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.CORBA.Interceptor;
|
||||
|
||||
import gnu.CORBA.CDR.cdrBufOutput;
|
||||
import gnu.CORBA.Poa.ORB_1_4;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_INV_ORDER;
|
||||
import org.omg.CORBA.TCKind;
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.ObjectImpl;
|
||||
import org.omg.PortableInterceptor.Current;
|
||||
import org.omg.PortableInterceptor.CurrentHelper;
|
||||
import org.omg.PortableInterceptor.InvalidSlot;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Supports the "Interceptor current" concept, providing the slot value
|
||||
* information for the current thread. When making the invocation, this
|
||||
* information is copied to the Current, returned by ClientRequestInfo.
|
||||
*
|
||||
* There is only one instance of this class per ORB. It maintains a thread to
|
||||
* information map.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuIcCurrent extends ObjectImpl implements Current
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The ORB, controllin this Current. It provides data about the required size
|
||||
* of the slot array.
|
||||
*/
|
||||
final ORB_1_4 orb;
|
||||
|
||||
/**
|
||||
* The table, mapping threads to records.
|
||||
*/
|
||||
private Hashtable threads = new Hashtable();
|
||||
|
||||
/**
|
||||
* An empty array when no slots are defined, computed once.
|
||||
*/
|
||||
static final Any[] NO_SLOTS = new Any[ 0 ];
|
||||
|
||||
/**
|
||||
* Create the IC current.
|
||||
*/
|
||||
public gnuIcCurrent(ORB_1_4 an_orb)
|
||||
{
|
||||
orb = an_orb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array of POA current repository ids.
|
||||
*
|
||||
* @return a single member array, containing value, returned by the
|
||||
* {@link CurrentHelper#id}, normally
|
||||
* "IDL:omg.org/PortableInterceptor/Current:1.0".
|
||||
*/
|
||||
public String[] _ids()
|
||||
{
|
||||
return new String[] { CurrentHelper.id() };
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the entry to the map.
|
||||
*/
|
||||
public void put(Thread t, Any[] record)
|
||||
{
|
||||
synchronized (threads)
|
||||
{
|
||||
threads.put(t, record);
|
||||
|
||||
// Remove non-running threads, avoiding memory leak.
|
||||
if (threads.size() > 12)
|
||||
{
|
||||
Iterator it = threads.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
Map.Entry e = (Map.Entry) it.next();
|
||||
Thread tx = (Thread) e.getKey();
|
||||
if (!tx.isAlive())
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this thread is registered.
|
||||
*/
|
||||
public boolean has(Thread t)
|
||||
{
|
||||
synchronized (threads)
|
||||
{
|
||||
return threads.containsKey(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the entry from the map.
|
||||
*/
|
||||
public void remove(Thread t)
|
||||
{
|
||||
synchronized (threads)
|
||||
{
|
||||
threads.remove(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array of all slots, as it is applicable for the current thread. If the
|
||||
* slots were not previously allocated, they are allocated during this call.
|
||||
*/
|
||||
Any[] get_slots()
|
||||
{
|
||||
Any[] r;
|
||||
synchronized (threads)
|
||||
{
|
||||
r = (Any[]) threads.get(Thread.currentThread());
|
||||
if (r == null)
|
||||
{
|
||||
r = new Any[ orb.icSlotSize ];
|
||||
|
||||
for (int i = 0; i < r.length; i++)
|
||||
{
|
||||
Any a = orb.create_any();
|
||||
a.type(orb.get_primitive_tc(TCKind.tk_null));
|
||||
r [ i ] = a;
|
||||
}
|
||||
|
||||
put(Thread.currentThread(), r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get copu array of all slots, as it is applicable for the current thread. If
|
||||
* the slots were not previously allocated, they are allocated during this
|
||||
* call.
|
||||
*/
|
||||
public Any[] clone_slots()
|
||||
{
|
||||
if (orb.icSlotSize == 0)
|
||||
{
|
||||
return NO_SLOTS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Any[] r = get_slots();
|
||||
Any[] copy = new Any[ r.length ];
|
||||
|
||||
cdrBufOutput buf = new cdrBufOutput();
|
||||
buf.setOrb(orb);
|
||||
|
||||
for (int i = 0; i < copy.length; i++)
|
||||
{
|
||||
r [ i ].write_value(buf);
|
||||
}
|
||||
|
||||
InputStream input = buf.create_input_stream();
|
||||
|
||||
for (int i = 0; i < copy.length; i++)
|
||||
{
|
||||
copy [ i ] = orb.create_any();
|
||||
copy [ i ].read_value(input, r [ i ].type());
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value for the slot with the given id. If the array of Currents has not
|
||||
* been yet allocated for the current thread, it is allocated during the
|
||||
* invocation of this method.
|
||||
*/
|
||||
public Any get_slot(int slot_id) throws InvalidSlot, BAD_INV_ORDER
|
||||
{
|
||||
try
|
||||
{
|
||||
return get_slots() [ slot_id ];
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e)
|
||||
{
|
||||
throw new InvalidSlot("Slot " + slot_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value for the slot with the given id. If the array of Currents has not
|
||||
* been yet allocated for the current thread, it is allocated during the
|
||||
* invocation of this method.
|
||||
*/
|
||||
public void set_slot(int slot_id, Any data)
|
||||
throws InvalidSlot, BAD_INV_ORDER
|
||||
{
|
||||
try
|
||||
{
|
||||
get_slots() [ slot_id ] = data;
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e)
|
||||
{
|
||||
throw new InvalidSlot("Slot " + slot_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
/* gnuIorInfo.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.CORBA.Interceptor;
|
||||
|
||||
import gnu.CORBA.IOR;
|
||||
import gnu.CORBA.Poa.ORB_1_4;
|
||||
|
||||
import org.omg.CORBA.LocalObject;
|
||||
import org.omg.CORBA.Policy;
|
||||
import org.omg.IOP.TaggedComponent;
|
||||
import org.omg.PortableInterceptor.IORInfo;
|
||||
import org.omg.PortableServer.POA;
|
||||
|
||||
/**
|
||||
* Implements IORInfo.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuIorInfo extends LocalObject implements IORInfo
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* The ORB, to that the IOR is related.
|
||||
*/
|
||||
public final ORB_1_4 orb;
|
||||
|
||||
/**
|
||||
* The POA, to that IOR is related.
|
||||
*/
|
||||
public final POA poa;
|
||||
|
||||
/**
|
||||
* The IOR itself.
|
||||
*/
|
||||
private final IOR ior;
|
||||
|
||||
/**
|
||||
* Create an instance.
|
||||
*/
|
||||
public gnuIorInfo(ORB_1_4 an_orb, POA a_poa, IOR an_ior)
|
||||
{
|
||||
orb = an_orb;
|
||||
poa = a_poa;
|
||||
ior = an_ior;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add component to tje specified profile of this IOR.
|
||||
*/
|
||||
public void add_ior_component_to_profile(TaggedComponent tagged_component,
|
||||
int profile_id
|
||||
)
|
||||
{
|
||||
ior.add_ior_component_to_profile(tagged_component, profile_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add component to all found profiles in this IOR.
|
||||
*/
|
||||
public void add_ior_component(TaggedComponent tagged_component)
|
||||
{
|
||||
ior.add_ior_component(tagged_component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the POA policy.
|
||||
*/
|
||||
public Policy get_effective_policy(int policy_type)
|
||||
{
|
||||
return poa._get_policy(policy_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the state of the object POA.
|
||||
*/
|
||||
short state()
|
||||
{
|
||||
return (short) poa.the_POAManager().get_state().value();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,456 @@
|
|||
/* gnuServerRequestInfo.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.CORBA.Interceptor;
|
||||
|
||||
import gnu.CORBA.GIOP.ReplyHeader;
|
||||
import gnu.CORBA.GIOP.RequestHeader;
|
||||
import gnu.CORBA.ObjectCreator;
|
||||
import gnu.CORBA.Poa.gnuServantObject;
|
||||
import gnu.CORBA.Unexpected;
|
||||
import gnu.CORBA.gnuRequest;
|
||||
|
||||
import org.omg.CORBA.ARG_IN;
|
||||
import org.omg.CORBA.ARG_INOUT;
|
||||
import org.omg.CORBA.ARG_OUT;
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.Bounds;
|
||||
import org.omg.CORBA.CompletionStatus;
|
||||
import org.omg.CORBA.ExceptionList;
|
||||
import org.omg.CORBA.INV_POLICY;
|
||||
import org.omg.CORBA.LocalObject;
|
||||
import org.omg.CORBA.NO_RESOURCES;
|
||||
import org.omg.CORBA.NVList;
|
||||
import org.omg.CORBA.Object;
|
||||
import org.omg.CORBA.ParameterMode;
|
||||
import org.omg.CORBA.Policy;
|
||||
import org.omg.CORBA.TCKind;
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.Dynamic.Parameter;
|
||||
import org.omg.IOP.ServiceContext;
|
||||
import org.omg.Messaging.SYNC_WITH_TRANSPORT;
|
||||
import org.omg.PortableInterceptor.InvalidSlot;
|
||||
import org.omg.PortableInterceptor.ServerRequestInfo;
|
||||
|
||||
/**
|
||||
* Implementation of the ServerRequestInfo, associacted with gnuServantObject.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuServerRequestInfo extends LocalObject
|
||||
implements ServerRequestInfo
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* A local object that will serve the invocation.
|
||||
*/
|
||||
final gnuServantObject m_object;
|
||||
|
||||
/**
|
||||
* A message that the given resource is not available using this metod of
|
||||
* invocation.
|
||||
*/
|
||||
static final String not_available =
|
||||
"The used invocation method provides" + "no access to this resource.";
|
||||
|
||||
/**
|
||||
* An array of slots.
|
||||
*/
|
||||
Any[] m_slots;
|
||||
|
||||
/**
|
||||
* The request header.
|
||||
*/
|
||||
public final RequestHeader m_request_header;
|
||||
|
||||
/**
|
||||
* The reply header.
|
||||
*/
|
||||
public final ReplyHeader m_reply_header;
|
||||
|
||||
/**
|
||||
* The forward reference, if applicable.
|
||||
*/
|
||||
public Object m_forward_reference;
|
||||
|
||||
/**
|
||||
* The thrown systen exception.
|
||||
*/
|
||||
public Exception m_sys_exception;
|
||||
|
||||
/**
|
||||
* The Any, containing the thrown user exception.
|
||||
*/
|
||||
public Any m_usr_exception;
|
||||
|
||||
/**
|
||||
* The associated request, if any.
|
||||
*/
|
||||
public gnuRequest m_request;
|
||||
|
||||
/**
|
||||
* Create a new instance at the time when it is known which object will serve
|
||||
* the invocation.
|
||||
*
|
||||
* @param an_object a local object, connected to the local servant that will
|
||||
* serve the invocation.
|
||||
*/
|
||||
public gnuServerRequestInfo(gnuServantObject an_object,
|
||||
RequestHeader a_request_header, ReplyHeader a_reply_header
|
||||
)
|
||||
{
|
||||
m_object = an_object;
|
||||
m_request_header = a_request_header;
|
||||
m_reply_header = a_reply_header;
|
||||
m_slots = new Any[ m_object.orb.icSlotSize ];
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the give slot.
|
||||
*/
|
||||
public void set_slot(int id, Any data) throws InvalidSlot
|
||||
{
|
||||
try
|
||||
{
|
||||
m_slots [ id ] = data;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
InvalidSlot ex = new InvalidSlot("Cannot set slot " + id);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the given slot.
|
||||
*/
|
||||
public Any get_slot(int id) throws InvalidSlot
|
||||
{
|
||||
try
|
||||
{
|
||||
return m_slots [ id ];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
InvalidSlot ex = new InvalidSlot("Cannot get slot " + id);
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset slot data.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
TypeCode tkNull = m_object.orb.get_primitive_tc(TCKind.tk_null);
|
||||
for (int i = 0; i < m_slots.length; i++)
|
||||
{
|
||||
Any a = m_object.orb.create_any();
|
||||
a.type(tkNull);
|
||||
m_slots [ i ] = a;
|
||||
}
|
||||
m_sys_exception = null;
|
||||
m_usr_exception = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object id (not the object IOR key).
|
||||
*/
|
||||
public byte[] object_id()
|
||||
{
|
||||
return m_object.Id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the target is an instance of the type, represented by the given
|
||||
* repository Id.
|
||||
*/
|
||||
public boolean target_is_a(String id)
|
||||
{
|
||||
return m_object._is_a(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the POA id.
|
||||
*/
|
||||
public byte[] adapter_id()
|
||||
{
|
||||
return m_object.poa.id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the POA policy of the given type that applies to the object being
|
||||
* served (request being handled).
|
||||
*/
|
||||
public Policy get_server_policy(int type) throws INV_POLICY
|
||||
{
|
||||
return m_object.poa._get_policy(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first member of the object repository id array.
|
||||
*/
|
||||
public String target_most_derived_interface()
|
||||
{
|
||||
return m_object._ids() [ 0 ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the operation being performed.
|
||||
*/
|
||||
public String operation()
|
||||
{
|
||||
if (m_request != null)
|
||||
{
|
||||
return m_request.operation();
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_request_header.operation;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not available.
|
||||
*/
|
||||
public TypeCode[] exceptions()
|
||||
{
|
||||
if (m_request == null)
|
||||
{
|
||||
throw new NO_RESOURCES(not_available, 1,
|
||||
CompletionStatus.COMPLETED_MAYBE
|
||||
);
|
||||
}
|
||||
|
||||
m_request.checkDii();
|
||||
|
||||
ExceptionList ex = m_request.exceptions();
|
||||
TypeCode[] et = new TypeCode[ ex.count() ];
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < et.length; i++)
|
||||
{
|
||||
et [ i ] = ex.item(i);
|
||||
}
|
||||
}
|
||||
catch (Bounds e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
return et;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reply status.
|
||||
*/
|
||||
public short reply_status()
|
||||
{
|
||||
return (short) m_reply_header.reply_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request id. All local requests have request id = -1.
|
||||
*/
|
||||
public int request_id()
|
||||
{
|
||||
return m_request_header.request_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the client expected any response.
|
||||
*/
|
||||
public boolean response_expected()
|
||||
{
|
||||
return m_request_header.isResponseExpected();
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public void add_reply_service_context(ServiceContext service_context,
|
||||
boolean replace
|
||||
)
|
||||
{
|
||||
m_reply_header.addContext(service_context, replace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an exception, wrapped into Any.
|
||||
*/
|
||||
public Any sending_exception()
|
||||
{
|
||||
if (m_usr_exception != null)
|
||||
{
|
||||
return m_usr_exception;
|
||||
}
|
||||
else if (m_sys_exception != null)
|
||||
{
|
||||
Any a = m_object.orb.create_any();
|
||||
ObjectCreator.insertException(a, m_sys_exception);
|
||||
return a;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public org.omg.CORBA.Object forward_reference()
|
||||
{
|
||||
return m_forward_reference;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public ServiceContext get_reply_service_context(int ctx_name)
|
||||
throws BAD_PARAM
|
||||
{
|
||||
return gnu.CORBA.GIOP.ServiceContext.findContext(ctx_name,
|
||||
m_reply_header.service_context
|
||||
);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public ServiceContext get_request_service_context(int ctx_name)
|
||||
throws BAD_PARAM
|
||||
{
|
||||
return gnu.CORBA.GIOP.ServiceContext.findContext(ctx_name,
|
||||
m_request_header.service_context
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not available
|
||||
*/
|
||||
public String[] operation_context()
|
||||
{
|
||||
if (m_request == null)
|
||||
{
|
||||
throw new NO_RESOURCES(not_available);
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_request.operation_context();
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public Any result()
|
||||
{
|
||||
if (m_request == null)
|
||||
{
|
||||
throw new NO_RESOURCES(not_available);
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_request.return_value();
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public String[] contexts()
|
||||
{
|
||||
if (m_request == null)
|
||||
{
|
||||
throw new NO_RESOURCES(not_available);
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_request.ice_contexts();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns "with transport".
|
||||
*/
|
||||
public short sync_scope()
|
||||
{
|
||||
return SYNC_WITH_TRANSPORT.value;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public Parameter[] arguments()
|
||||
{
|
||||
if (m_request == null)
|
||||
{
|
||||
throw new NO_RESOURCES(not_available);
|
||||
}
|
||||
|
||||
m_request.checkDii();
|
||||
|
||||
NVList args = m_request.arguments();
|
||||
Parameter[] p = new Parameter[ args.count() ];
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < p.length; i++)
|
||||
{
|
||||
ParameterMode mode;
|
||||
|
||||
switch (args.item(i).flags())
|
||||
{
|
||||
case ARG_IN.value :
|
||||
mode = ParameterMode.PARAM_IN;
|
||||
break;
|
||||
|
||||
case ARG_OUT.value :
|
||||
mode = ParameterMode.PARAM_OUT;
|
||||
break;
|
||||
|
||||
case ARG_INOUT.value :
|
||||
mode = ParameterMode.PARAM_INOUT;
|
||||
break;
|
||||
|
||||
default :
|
||||
throw new Unexpected();
|
||||
}
|
||||
|
||||
p [ i ] = new Parameter(args.item(i).value(), mode);
|
||||
}
|
||||
}
|
||||
catch (Bounds e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/* NameDynAnyPairHolder.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.CORBA;
|
||||
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.DynamicAny.NameDynAnyPair;
|
||||
import org.omg.DynamicAny.NameDynAnyPairHelper;
|
||||
|
||||
/**
|
||||
* A holder for the structure {@link NameDynAnyPair}.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class NameDynAnyPairHolder
|
||||
implements Streamable
|
||||
{
|
||||
/**
|
||||
* The stored NameDynAnyPair value.
|
||||
*/
|
||||
public NameDynAnyPair value;
|
||||
|
||||
/**
|
||||
* Create the unitialised instance, leaving the value field
|
||||
* with default <code>null</code> value.
|
||||
*/
|
||||
public NameDynAnyPairHolder()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the initialised instance.
|
||||
* @param initialValue the value that will be assigned to
|
||||
* the <code>value</code> field.
|
||||
*/
|
||||
public NameDynAnyPairHolder(NameDynAnyPair initialValue)
|
||||
{
|
||||
value = initialValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* The method should read this object from the CDR input stream, but
|
||||
* (following the JDK 1.5 API) it does not.
|
||||
*
|
||||
* @param input a org.omg.CORBA.portable stream to read from.
|
||||
*
|
||||
* @specenote Sun throws the same exception.
|
||||
*
|
||||
* @throws MARSHAL always.
|
||||
*/
|
||||
public void _read(InputStream input)
|
||||
{
|
||||
value = NameDynAnyPairHelper.read(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* The method should write this object to the CDR input stream, but
|
||||
* (following the JDK 1.5 API) it does not.
|
||||
*
|
||||
* @param input a org.omg.CORBA.portable stream to read from.
|
||||
*
|
||||
* @specenote Sun throws the same exception.
|
||||
*
|
||||
* @throws MARSHAL always.
|
||||
*/
|
||||
public void _write(OutputStream output)
|
||||
{
|
||||
NameDynAnyPairHelper.write(output, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the typecode of the NameDynAnyPair.
|
||||
*/
|
||||
public org.omg.CORBA.TypeCode _type()
|
||||
{
|
||||
return NameDynAnyPairHelper.type();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/* NameDynAnyPairSeqHolder.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.CORBA;
|
||||
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.DynamicAny.NameDynAnyPair;
|
||||
import org.omg.DynamicAny.NameDynAnyPairSeqHelper;
|
||||
|
||||
/**
|
||||
* A holder for the sequence of {@link NameDynAnyPair}.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class NameDynAnyPairSeqHolder
|
||||
implements Streamable
|
||||
{
|
||||
/**
|
||||
* The stored array of <code>NameDynAnyPair</code>.
|
||||
*/
|
||||
public NameDynAnyPair[] value;
|
||||
|
||||
/**
|
||||
* Create the unitialised instance, leaving the value array
|
||||
* with default <code>null</code> value.
|
||||
*/
|
||||
public NameDynAnyPairSeqHolder()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the initialised instance.
|
||||
* @param initialValue the array that will be assigned to
|
||||
* the <code>value</code> array.
|
||||
*/
|
||||
public NameDynAnyPairSeqHolder(NameDynAnyPair[] initialValue)
|
||||
{
|
||||
value = initialValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* The method should read this object from the CDR input stream, but
|
||||
* (following the JDK 1.5 API) it does not.
|
||||
*
|
||||
* @param input a org.omg.CORBA.portable stream to read from.
|
||||
*
|
||||
* @specenote Sun throws the same exception.
|
||||
*
|
||||
* @throws MARSHAL always.
|
||||
*/
|
||||
public void _read(InputStream input)
|
||||
{
|
||||
value = NameDynAnyPairSeqHelper.read(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* The method should write this object to the CDR input stream, but
|
||||
* (following the JDK 1.5 API) it does not.
|
||||
*
|
||||
* @param input a org.omg.CORBA.portable stream to read from.
|
||||
*
|
||||
* @specenote Sun throws the same exception.
|
||||
*
|
||||
* @throws MARSHAL always.
|
||||
*/
|
||||
public void _write(OutputStream output)
|
||||
{
|
||||
NameDynAnyPairSeqHelper.write(output, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the typecode of the NameDynAnyPair.
|
||||
*/
|
||||
public org.omg.CORBA.TypeCode _type()
|
||||
{
|
||||
return NameDynAnyPairSeqHelper.type();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
/* NameValuePairHolder.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.CORBA;
|
||||
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.DynamicAny.NameValuePair;
|
||||
import org.omg.DynamicAny.NameValuePairHelper;
|
||||
|
||||
/**
|
||||
* A holder for the structure {@link NameValuePair}.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class NameValuePairHolder
|
||||
implements Streamable
|
||||
{
|
||||
/**
|
||||
* The stored NameValuePair value.
|
||||
*/
|
||||
public NameValuePair value;
|
||||
|
||||
/**
|
||||
* Create the unitialised instance, leaving the value field
|
||||
* with default <code>null</code> value.
|
||||
*/
|
||||
public NameValuePairHolder()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the initialised instance.
|
||||
* @param initialValue the value that will be assigned to
|
||||
* the <code>value</code> field.
|
||||
*/
|
||||
public NameValuePairHolder(NameValuePair initialValue)
|
||||
{
|
||||
value = initialValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in the {@link value} by data from the CDR stream.
|
||||
*
|
||||
* @param input the org.omg.CORBA.portable stream to read.
|
||||
*/
|
||||
public void _read(InputStream input)
|
||||
{
|
||||
value = NameValuePairHelper.read(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the stored value into the CDR stream.
|
||||
*
|
||||
* @param output the org.omg.CORBA.portable stream to write.
|
||||
*/
|
||||
public void _write(OutputStream output)
|
||||
{
|
||||
NameValuePairHelper.write(output, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the typecode of the NameValuePair.
|
||||
*/
|
||||
public org.omg.CORBA.TypeCode _type()
|
||||
{
|
||||
return NameValuePairHelper.type();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
/* NameValuePairSeqHolder.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.CORBA;
|
||||
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.DynamicAny.NameValuePair;
|
||||
import org.omg.DynamicAny.NameValuePairSeqHelper;
|
||||
|
||||
/**
|
||||
* A holder for the sequence of {@link NameValuePair}.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class NameValuePairSeqHolder
|
||||
implements Streamable
|
||||
{
|
||||
/**
|
||||
* The stored array of <code>NameValuePair</code>.
|
||||
*/
|
||||
public NameValuePair[] value;
|
||||
|
||||
/**
|
||||
* Create the unitialised instance, leaving the value array
|
||||
* with default <code>null</code> value.
|
||||
*/
|
||||
public NameValuePairSeqHolder()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the initialised instance.
|
||||
* @param initialValue the array that will be assigned to
|
||||
* the <code>value</code> array.
|
||||
*/
|
||||
public NameValuePairSeqHolder(NameValuePair[] initialValue)
|
||||
{
|
||||
value = initialValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the {@link value} array from the CDR stream.
|
||||
*
|
||||
* @param input the org.omg.CORBA.portable stream to read.
|
||||
*/
|
||||
public void _read(InputStream input)
|
||||
{
|
||||
value = NameValuePairSeqHelper.read(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the stored value into the CDR stream.
|
||||
*
|
||||
* @param output the org.omg.CORBA.portable stream to write.
|
||||
*/
|
||||
public void _write(OutputStream output)
|
||||
{
|
||||
NameValuePairSeqHelper.write(output, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the typecode of the NameValuePair.
|
||||
*/
|
||||
public org.omg.CORBA.TypeCode _type()
|
||||
{
|
||||
return NameValuePairSeqHelper.type();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,419 @@
|
|||
/* NameParser.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.CORBA.NamingService;
|
||||
|
||||
import gnu.CORBA.Functional_ORB;
|
||||
import gnu.CORBA.IOR;
|
||||
import gnu.CORBA.Unexpected;
|
||||
import gnu.CORBA.Version;
|
||||
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.DATA_CONVERSION;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.Object;
|
||||
import org.omg.CORBA.ORBPackage.InvalidName;
|
||||
import org.omg.CORBA.portable.Delegate;
|
||||
import org.omg.CORBA.portable.ObjectImpl;
|
||||
import org.omg.CosNaming.NamingContext;
|
||||
import org.omg.CosNaming.NamingContextExtHelper;
|
||||
import org.omg.CosNaming.NamingContextHelper;
|
||||
import org.omg.CosNaming._NamingContextStub;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Parses the alternative IOR representations into our IOR structure.
|
||||
*
|
||||
* TODO This parser currently supports only one address per target string. A
|
||||
* string with the multiple addresses will be accepted, but only the last
|
||||
* address will be taken into consideration. The fault tolerance is not yet
|
||||
* implemented.
|
||||
*
|
||||
* The key string is filtered using {@link java.net.URLDecoder} that replaces
|
||||
* the agreed escape sequences by the corresponding non alphanumeric characters.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class NameParser
|
||||
extends snConverter
|
||||
{
|
||||
/**
|
||||
* The corbaloc prefix.
|
||||
*/
|
||||
public static final String pxCORBALOC = "corbaloc";
|
||||
|
||||
/**
|
||||
* The corbaname prefix.
|
||||
*/
|
||||
public static final String pxCORBANAME = "corbaname";
|
||||
|
||||
/**
|
||||
* The IOR prefix.
|
||||
*/
|
||||
public static final String pxIOR = "ior";
|
||||
|
||||
/**
|
||||
* Marks iiop protocol.
|
||||
*/
|
||||
public static final String IIOP = "iiop";
|
||||
|
||||
/**
|
||||
* Marks rir protocol.
|
||||
*/
|
||||
public static final String RIR = "rir";
|
||||
|
||||
/**
|
||||
* The default port value, as specified in OMG documentation.
|
||||
*/
|
||||
public static final int DEFAULT_PORT = 2809;
|
||||
|
||||
/**
|
||||
* The default name.
|
||||
*/
|
||||
public static final String DEFAULT_NAME = "NameService";
|
||||
|
||||
/**
|
||||
* The string to name converter, initialized on demand.
|
||||
*/
|
||||
static snConverter converter;
|
||||
|
||||
/**
|
||||
* The current position.
|
||||
*/
|
||||
int p;
|
||||
|
||||
/**
|
||||
* The address being parsed, splitted into tokens.
|
||||
*/
|
||||
String[] t;
|
||||
|
||||
/**
|
||||
* Parse CORBALOC.
|
||||
*
|
||||
* The expected format is: <br>
|
||||
* 1. corbaloc:[iiop][version.subversion@]:host[:port]/key <br>
|
||||
* 2. corbaloc:rir:[/key] <br>
|
||||
* 3. corbaname:[iiop][version.subversion@]:host[:port]/key <br>
|
||||
* 4. corbaname:rir:[/key] <br>
|
||||
*
|
||||
* Protocol defaults to IOP, the object key defaults to the NameService.
|
||||
*
|
||||
* @param corbaloc the string to parse.
|
||||
* @param orb the ORB, needed to create IORs and resolve rir references.
|
||||
*
|
||||
* @return the resolved object.
|
||||
*/
|
||||
public synchronized org.omg.CORBA.Object corbaloc(String corbaloc,
|
||||
Functional_ORB orb)
|
||||
throws BAD_PARAM
|
||||
{
|
||||
boolean corbaname;
|
||||
|
||||
// The alternative addresses, if given.
|
||||
ArrayList alt_addr = new ArrayList();
|
||||
|
||||
// The version numbers with default values.
|
||||
int major = 1;
|
||||
int minor = 0;
|
||||
|
||||
// The host address.
|
||||
String host;
|
||||
|
||||
// The port.
|
||||
int port = DEFAULT_PORT;
|
||||
|
||||
// The object key as string.
|
||||
String key;
|
||||
|
||||
StringTokenizer st = new StringTokenizer(corbaloc, ":@/.,#", true);
|
||||
|
||||
t = new String[st.countTokens()];
|
||||
|
||||
for (int i = 0; i < t.length; i++)
|
||||
{
|
||||
t[i] = st.nextToken();
|
||||
}
|
||||
|
||||
p = 0;
|
||||
|
||||
if (t[p].startsWith(pxCORBANAME))
|
||||
corbaname = true;
|
||||
else if (t[p].equalsIgnoreCase(pxCORBALOC))
|
||||
corbaname = false;
|
||||
else if (t[p].equalsIgnoreCase(pxIOR))
|
||||
{
|
||||
IOR ior = IOR.parse(corbaloc);
|
||||
return orb.ior_to_object(ior);
|
||||
}
|
||||
else
|
||||
throw new DATA_CONVERSION("Unsupported protocol: '" + t[p] + "'");
|
||||
|
||||
p++;
|
||||
|
||||
if (!t[p++].equals(":"))
|
||||
throw new BAD_PARAM("Syntax (':' expected after name prefix)");
|
||||
|
||||
// Check for rir:
|
||||
if (t[p].equals(RIR))
|
||||
{
|
||||
p++;
|
||||
if (!t[p++].equals(":"))
|
||||
throw new BAD_PARAM("':' expected after 'rir'");
|
||||
|
||||
key = readKey("/");
|
||||
|
||||
Object object;
|
||||
try
|
||||
{
|
||||
object = orb.resolve_initial_references(key);
|
||||
return corbaname ? resolve(object) : object;
|
||||
}
|
||||
catch (InvalidName e)
|
||||
{
|
||||
throw new BAD_PARAM("Unknown initial reference '" + key + "'");
|
||||
}
|
||||
}
|
||||
else
|
||||
// Check for iiop.
|
||||
if (t[p].equals(IIOP) || t[p].equals(":"))
|
||||
{
|
||||
IOR ior = new IOR();
|
||||
|
||||
Addresses: do
|
||||
{ // Read addresses.
|
||||
if (t[p].equals(":"))
|
||||
{
|
||||
p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
p++;
|
||||
if (!t[p++].equals(":"))
|
||||
throw new BAD_PARAM("':' expected after 'iiop'");
|
||||
// Check if version is present.
|
||||
if (t[p + 1].equals("."))
|
||||
if (t[p + 3].equals("@"))
|
||||
{
|
||||
// Version info present.
|
||||
try
|
||||
{
|
||||
major = Integer.parseInt(t[p++]);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new BAD_PARAM("Major version number '"
|
||||
+ t[p - 1] + "'");
|
||||
}
|
||||
p++; // '.' at this point.
|
||||
try
|
||||
{
|
||||
minor = Integer.parseInt(t[p++]);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new BAD_PARAM("Major version number '"
|
||||
+ t[p - 1] + "'");
|
||||
}
|
||||
p++; // '@' at this point.
|
||||
}
|
||||
}
|
||||
|
||||
ior.Internet.version = new Version(major, minor);
|
||||
|
||||
// Then host data goes till '/' or ':'.
|
||||
StringBuffer bhost = new StringBuffer(corbaloc.length());
|
||||
while (!t[p].equals(":") && !t[p].equals("/") && !t[p].equals(","))
|
||||
bhost.append(t[p++]);
|
||||
|
||||
host = bhost.toString();
|
||||
|
||||
ior.Internet.host = host;
|
||||
|
||||
if (t[p].equals(":"))
|
||||
{
|
||||
// Port specified.
|
||||
p++;
|
||||
try
|
||||
{
|
||||
port = Integer.parseInt(t[p++]);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new BAD_PARAM("Invalid port '" + t[p - 1] + "'");
|
||||
}
|
||||
}
|
||||
|
||||
ior.Internet.port = port;
|
||||
|
||||
// Id is not listed.
|
||||
ior.Id = "";
|
||||
|
||||
if (t[p].equals(","))
|
||||
p++;
|
||||
else
|
||||
break Addresses;
|
||||
}
|
||||
while (true);
|
||||
|
||||
key = readKey("/");
|
||||
ior.key = key.getBytes();
|
||||
|
||||
org.omg.CORBA.Object object = orb.ior_to_object(ior);
|
||||
return corbaname ? resolve(object) : object;
|
||||
}
|
||||
|
||||
else
|
||||
throw new DATA_CONVERSION("Unsupported protocol '" + t[p] + "'");
|
||||
}
|
||||
|
||||
private org.omg.CORBA.Object resolve(org.omg.CORBA.Object object)
|
||||
{
|
||||
NamingContext ns;
|
||||
String key = "?";
|
||||
try
|
||||
{
|
||||
if (object instanceof NamingContext)
|
||||
ns = (NamingContext) object;
|
||||
else
|
||||
{
|
||||
Delegate delegate = ((ObjectImpl) object)._get_delegate();
|
||||
ns = new _NamingContextStub(delegate);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BAD_PARAM bad = new BAD_PARAM("The CORBANAME target " + object
|
||||
+ " is not a NamingContext");
|
||||
bad.minor = 10;
|
||||
bad.initCause(ex);
|
||||
throw bad;
|
||||
}
|
||||
|
||||
if (converter == null)
|
||||
converter = new snConverter();
|
||||
|
||||
try
|
||||
{
|
||||
key = readKey("#");
|
||||
object = ns.resolve(converter.toName(key));
|
||||
return object;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BAD_PARAM bad = new BAD_PARAM("Wrong CORBANAME '" + key + "'");
|
||||
bad.minor = 10;
|
||||
bad.initCause(ex);
|
||||
throw bad;
|
||||
}
|
||||
}
|
||||
|
||||
private String readKey(String delimiter)
|
||||
throws BAD_PARAM
|
||||
{
|
||||
if (p < t.length)
|
||||
if (!t[p].equals(delimiter))
|
||||
{
|
||||
if (t[p].equals("#"))
|
||||
return DEFAULT_NAME;
|
||||
else
|
||||
throw new BAD_PARAM("'" + delimiter + "String' expected '" + t[p]
|
||||
+ "' found");
|
||||
}
|
||||
|
||||
StringBuffer bKey = new StringBuffer();
|
||||
p++;
|
||||
|
||||
while (p < t.length && !t[p].equals("#"))
|
||||
bKey.append(t[p++]);
|
||||
|
||||
if (bKey.length() == 0)
|
||||
return DEFAULT_NAME;
|
||||
|
||||
try
|
||||
{
|
||||
return URLDecoder.decode(bKey.toString(), "UTF-8");
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
throw new Unexpected("URLDecoder does not support UTF-8", e);
|
||||
}
|
||||
}
|
||||
|
||||
static NameParser n = new NameParser();
|
||||
|
||||
static void corbalocT(String ior, Functional_ORB orb)
|
||||
{
|
||||
System.out.println(ior);
|
||||
System.out.println(n.corbaloc(ior, orb));
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
Functional_ORB orb = (Functional_ORB) ORB.init(args, null);
|
||||
corbalocT("corbaloc:iiop:1.3@155axyz.com/Prod/aTradingService", orb);
|
||||
corbalocT("corbaloc:iiop:2.7@255bxyz.com/Prod/bTradingService", orb);
|
||||
corbalocT("corbaloc:iiop:355cxyz.com/Prod/cTradingService", orb);
|
||||
corbalocT("corbaloc:iiop:2.7@255bxyz.com/Prod/bTradingService", orb);
|
||||
corbalocT("corbaloc:iiop:355cxyz.com:7777/Prod/cTradingService", orb);
|
||||
|
||||
corbalocT("corbaloc::556xyz.com:80/Dev/NameService", orb);
|
||||
corbalocT("corbaloc:iiop:1.2@host1:3076/0", orb);
|
||||
|
||||
corbalocT("corbaloc:rir:/NameService", orb);
|
||||
corbalocT("corbaloc:rir:/", orb);
|
||||
corbalocT("corbaloc:rir:", orb);
|
||||
|
||||
corbalocT("corbaloc:rir:/NameService", orb);
|
||||
corbalocT("corbaloc:rir:/", orb);
|
||||
corbalocT("corbaloc:rir:", orb);
|
||||
|
||||
corbalocT("corbaloc::555xyz.com,:556xyz.com:80/Dev/NameService", orb);
|
||||
}
|
||||
catch (BAD_PARAM e)
|
||||
{
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
/* ForwardRequestHolder.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA.ForwardRequestHelper;
|
||||
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
import org.omg.CORBA.portable.Streamable;
|
||||
import org.omg.PortableServer.ForwardRequest;
|
||||
|
||||
/**
|
||||
* A holder for the exception {@link ForwardRequest}.
|
||||
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class ForwardRequestHolder
|
||||
implements Streamable
|
||||
{
|
||||
/**
|
||||
* The stored ForwardRequest value.
|
||||
*/
|
||||
public ForwardRequest value;
|
||||
|
||||
/**
|
||||
* Create the unitialised instance, leaving the value field
|
||||
* with default <code>null</code> value.
|
||||
*/
|
||||
public ForwardRequestHolder()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the initialised instance.
|
||||
* @param initialValue the value that will be assigned to
|
||||
* the <code>value</code> field.
|
||||
*/
|
||||
public ForwardRequestHolder(ForwardRequest initialValue)
|
||||
{
|
||||
value = initialValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in the {@link value} by data from the CDR stream.
|
||||
*
|
||||
* @param input the org.omg.CORBA.portable stream to read.
|
||||
*/
|
||||
public void _read(InputStream input)
|
||||
{
|
||||
value = ForwardRequestHelper.read(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the typecode of the ForwardRequest.
|
||||
*/
|
||||
public TypeCode _type()
|
||||
{
|
||||
return ForwardRequestHelper.type();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the stored value into the CDR stream.
|
||||
*
|
||||
* @param output the org.omg.CORBA.portable stream to write.
|
||||
*/
|
||||
public void _write(OutputStream output)
|
||||
{
|
||||
ForwardRequestHelper.write(output, value);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,207 @@
|
|||
/* ForwardedServant.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA.IOR;
|
||||
import gnu.CORBA.IOR_Delegate;
|
||||
import gnu.CORBA.IOR_contructed_object;
|
||||
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.CompletionStatus;
|
||||
import org.omg.CORBA.MARSHAL;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.SystemException;
|
||||
import org.omg.CORBA.portable.ApplicationException;
|
||||
import org.omg.CORBA.portable.Delegate;
|
||||
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.RemarshalException;
|
||||
import org.omg.CORBA.portable.ResponseHandler;
|
||||
import org.omg.PortableServer.POA;
|
||||
import org.omg.PortableServer.Servant;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A "virtual servant", delegating all invocation to the wrapped
|
||||
* object (usually remote). Used in cases when it is necessary to
|
||||
* handle the request forwarding.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class ForwardedServant
|
||||
extends Servant
|
||||
implements InvokeHandler
|
||||
{
|
||||
/**
|
||||
* The reference object, handling requests.
|
||||
*/
|
||||
public final ObjectImpl ref;
|
||||
|
||||
/**
|
||||
* Create an instance, forwarding requests to the given object.
|
||||
*/
|
||||
ForwardedServant(ObjectImpl a_ref)
|
||||
{
|
||||
ref = a_ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the forwarded servant.
|
||||
*
|
||||
* @param a_ref a reference where request should be forwarded.
|
||||
*
|
||||
* @return a created forwarded servant or null if the parameter
|
||||
* forwards request to itself. Returning null will force to find
|
||||
* a right servant in one of many possible ways, depending on
|
||||
* policies.
|
||||
*/
|
||||
public static Servant create(org.omg.CORBA.Object a_ref)
|
||||
{
|
||||
try
|
||||
{
|
||||
ObjectImpl fto = (ObjectImpl) a_ref;
|
||||
|
||||
// Check maybe the remote side forwarded back to our local object.
|
||||
if (fto instanceof IOR_contructed_object)
|
||||
{
|
||||
IOR_contructed_object iref = (IOR_contructed_object) fto;
|
||||
|
||||
// Check maybe the IOR is local.
|
||||
ORB t_orb = iref._orb();
|
||||
if (t_orb instanceof ORB_1_4)
|
||||
{
|
||||
ORB_1_4 orb = (ORB_1_4) t_orb;
|
||||
Delegate d = iref._get_delegate();
|
||||
if (d instanceof IOR_Delegate)
|
||||
{
|
||||
IOR_Delegate ird = (IOR_Delegate) iref._get_delegate();
|
||||
IOR ior = ird.getIor();
|
||||
if (orb.LOCAL_HOST.equalsIgnoreCase(ior.Internet.host))
|
||||
{
|
||||
activeObjectMap.Obj rx = orb.rootPOA.findIorKey(ior.key);
|
||||
if (rx != null)
|
||||
{
|
||||
if (rx.object == fto ||
|
||||
rx.object._is_equivalent(fto)
|
||||
)
|
||||
return rx.primary_servant;
|
||||
else
|
||||
fto = (ObjectImpl) rx.object;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ForwardedServant(fto);
|
||||
}
|
||||
catch (ClassCastException ex)
|
||||
{
|
||||
throw new BAD_PARAM("ObjectImpl required but " + a_ref + " passed ",
|
||||
0x5005, CompletionStatus.COMPLETED_NO
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward the call to the wrapped object.
|
||||
*/
|
||||
public OutputStream _invoke(String method, InputStream input,
|
||||
ResponseHandler handler
|
||||
)
|
||||
throws SystemException
|
||||
{
|
||||
org.omg.CORBA.portable.InputStream in = null;
|
||||
org.omg.CORBA.portable.OutputStream out = null;
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
out = ref._request(method, true);
|
||||
|
||||
// Transfer request information.
|
||||
int b;
|
||||
while ((b = input.read()) >= 0)
|
||||
{
|
||||
out.write(b);
|
||||
}
|
||||
in = ref._invoke(out);
|
||||
|
||||
// Read the returned data.
|
||||
out = handler.createReply();
|
||||
while ((b = in.read()) >= 0)
|
||||
{
|
||||
out.write(b);
|
||||
}
|
||||
}
|
||||
catch (IOException io_ex)
|
||||
{
|
||||
MARSHAL m = new MARSHAL();
|
||||
m.initCause(io_ex);
|
||||
throw m;
|
||||
}
|
||||
}
|
||||
catch (ApplicationException ex)
|
||||
{
|
||||
in = ex.getInputStream();
|
||||
|
||||
String _id = ex.getId();
|
||||
throw new MARSHAL(_id, 5101, CompletionStatus.COMPLETED_NO);
|
||||
}
|
||||
catch (RemarshalException remarsh)
|
||||
{
|
||||
_invoke(method, input, handler);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ref._releaseReply(in);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to the wrapped object.
|
||||
*/
|
||||
public String[] _all_interfaces(POA poa, byte[] key)
|
||||
{
|
||||
return ref._ids();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,382 @@
|
|||
/* LocalDelegate.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA.CDR.cdrOutput;
|
||||
import gnu.CORBA.streamRequest;
|
||||
|
||||
import org.omg.CORBA.ARG_INOUT;
|
||||
import org.omg.CORBA.Bounds;
|
||||
import org.omg.CORBA.Context;
|
||||
import org.omg.CORBA.ContextList;
|
||||
import org.omg.CORBA.ExceptionList;
|
||||
import org.omg.CORBA.NO_IMPLEMENT;
|
||||
import org.omg.CORBA.NVList;
|
||||
import org.omg.CORBA.NamedValue;
|
||||
import org.omg.CORBA.OBJECT_NOT_EXIST;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.Request;
|
||||
import org.omg.CORBA.TypeCodePackage.BadKind;
|
||||
import org.omg.CORBA.UnknownUserException;
|
||||
import org.omg.CORBA.portable.ApplicationException;
|
||||
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.RemarshalException;
|
||||
import org.omg.PortableServer.ServantLocatorPackage.CookieHolder;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A local delegate, transferring all object requests to the locally available
|
||||
* servant. This class is involved in handling the method invocations on the
|
||||
* local object, obtained by POA.create_reference_with_id.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class LocalDelegate extends org.omg.CORBA_2_3.portable.Delegate
|
||||
{
|
||||
/**
|
||||
* The same servant as an invocation handler.
|
||||
*/
|
||||
gnuServantObject object;
|
||||
String operation;
|
||||
final gnuPOA poa;
|
||||
final byte[] Id;
|
||||
|
||||
/**
|
||||
* Create a local delegate, forwarding requests to the servant that must also
|
||||
* be an invocation handler.
|
||||
*/
|
||||
public LocalDelegate(gnuServantObject an_object, gnuPOA a_poa, byte[] an_id)
|
||||
{
|
||||
object = an_object;
|
||||
poa = a_poa;
|
||||
Id = an_id;
|
||||
}
|
||||
|
||||
public Request request(org.omg.CORBA.Object target, String method)
|
||||
{
|
||||
operation = method;
|
||||
|
||||
LocalRequest rq = new LocalRequest(object, poa, Id);
|
||||
rq.setOperation(method);
|
||||
rq.setORB(orb(target));
|
||||
return rq;
|
||||
}
|
||||
|
||||
public void release(org.omg.CORBA.Object target)
|
||||
{
|
||||
}
|
||||
|
||||
public boolean is_equivalent(org.omg.CORBA.Object target,
|
||||
org.omg.CORBA.Object other
|
||||
)
|
||||
{
|
||||
if (target == other)
|
||||
return true;
|
||||
else if (target instanceof ObjectImpl && other instanceof ObjectImpl)
|
||||
{
|
||||
org.omg.CORBA.portable.Delegate a = null;
|
||||
org.omg.CORBA.portable.Delegate b = null;
|
||||
try
|
||||
{
|
||||
a = ((ObjectImpl) target)._get_delegate();
|
||||
b = ((ObjectImpl) other)._get_delegate();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Unable to get one of the delegates.
|
||||
return false;
|
||||
}
|
||||
if (a instanceof LocalDelegate && b instanceof LocalDelegate)
|
||||
{
|
||||
byte[] k1 = ((LocalDelegate) a).Id;
|
||||
byte[] k2 = ((LocalDelegate) b).Id;
|
||||
return Arrays.equals(k1, k2);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always return false.
|
||||
*/
|
||||
public boolean non_existent(org.omg.CORBA.Object target)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hash code.
|
||||
*/
|
||||
public int hash(org.omg.CORBA.Object target, int maximum)
|
||||
{
|
||||
return hashCode() % maximum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this object could be named by the given repository id.
|
||||
*
|
||||
* @param idl_id the repository id to check.
|
||||
*
|
||||
* @return true if it is one of the possible repository ids of this object.
|
||||
*/
|
||||
public boolean is_a(org.omg.CORBA.Object a_servant, String idl_id)
|
||||
{
|
||||
String[] maybe = object._ids();
|
||||
for (int i = 0; i < maybe.length; i++)
|
||||
{
|
||||
if (maybe [ i ].equals(idl_id))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>this</code>.
|
||||
*/
|
||||
public org.omg.CORBA.Object duplicate(org.omg.CORBA.Object target)
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create request for using with DII.
|
||||
*/
|
||||
public Request create_request(org.omg.CORBA.Object target, Context context,
|
||||
String method, NVList parameters, NamedValue returns,
|
||||
ExceptionList exceptions, ContextList ctx_list
|
||||
)
|
||||
{
|
||||
operation = method;
|
||||
|
||||
LocalRequest rq = new LocalRequest(object, poa, Id);
|
||||
rq.setOperation(method);
|
||||
rq.set_args(parameters);
|
||||
rq.set_result(returns);
|
||||
rq.set_exceptions(exceptions);
|
||||
rq.set_context_list(ctx_list);
|
||||
return rq;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create request for using with DII.
|
||||
*/
|
||||
public Request create_request(org.omg.CORBA.Object target, Context context,
|
||||
String method, NVList parameters, NamedValue returns
|
||||
)
|
||||
{
|
||||
operation = method;
|
||||
|
||||
LocalRequest rq = new LocalRequest(object, poa, Id);
|
||||
rq.setOperation(method);
|
||||
rq.set_args(parameters);
|
||||
rq.set_result(returns);
|
||||
return rq;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not in use.
|
||||
*/
|
||||
public org.omg.CORBA.Object get_interface_def(org.omg.CORBA.Object target)
|
||||
{
|
||||
throw new NO_IMPLEMENT();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a request to invoke the method of this CORBA object.
|
||||
*
|
||||
* @param operation the name of the method to invoke.
|
||||
* @param response_expected specifies if this is one way message or the
|
||||
* response to the message is expected.
|
||||
*
|
||||
* @return the stream where the method arguments should be written.
|
||||
*/
|
||||
public org.omg.CORBA.portable.OutputStream request(
|
||||
org.omg.CORBA.Object target,
|
||||
String method,
|
||||
boolean response_expected
|
||||
)
|
||||
{
|
||||
operation = method;
|
||||
|
||||
// Check if the object is not explicitly deactivated.
|
||||
activeObjectMap.Obj e = poa.aom.get(Id);
|
||||
if (e != null && e.isDeactiveted())
|
||||
{
|
||||
if (poa.servant_activator != null || poa.servant_locator != null)
|
||||
{
|
||||
// This will force the subsequent activation.
|
||||
object.setServant(null);
|
||||
e.setServant(null);
|
||||
e.setDeactivated(false);
|
||||
}
|
||||
else
|
||||
throw new OBJECT_NOT_EXIST("Deactivated");
|
||||
}
|
||||
|
||||
LocalRequest rq = new LocalRequest(object, poa, Id);
|
||||
rq.setOperation(method);
|
||||
rq.setORB(orb(target));
|
||||
return rq.getParameterStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the associated invocation handler.
|
||||
*/
|
||||
public InvokeHandler getHandler(String method, CookieHolder cookie)
|
||||
{
|
||||
return object.getHandler(method, cookie, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ORB of the associated POA. The parameter is not in use.
|
||||
*/
|
||||
public ORB orb(org.omg.CORBA.Object target)
|
||||
{
|
||||
return poa.orb();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an invocation.
|
||||
*
|
||||
* @param target not in use.
|
||||
* @param output the stream request that should be returned by
|
||||
* {@link #m_request} in this method.
|
||||
* @throws ApplicationException if the use exception is thrown by the servant
|
||||
* method.
|
||||
*/
|
||||
public InputStream invoke(org.omg.CORBA.Object target, OutputStream output)
|
||||
throws ApplicationException
|
||||
{
|
||||
try
|
||||
{
|
||||
streamRequest sr = (streamRequest) output;
|
||||
|
||||
LocalRequest lr = (LocalRequest) sr.request;
|
||||
InvokeHandler handler =
|
||||
lr.object.getHandler(lr.operation(), lr.cookie, false);
|
||||
|
||||
if (handler instanceof dynImpHandler)
|
||||
{
|
||||
// The local request known how to handle it, but the different
|
||||
// method must be called.
|
||||
lr.invoke();
|
||||
|
||||
// The encapsulation will inherit orb, endian, charsets, etc.
|
||||
cdrOutput buf = sr.createEncapsulation();
|
||||
|
||||
// Write all request parameters to the buffer stream.
|
||||
if (lr.env().exception() != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
UnknownUserException uex =
|
||||
(UnknownUserException) lr.env().exception();
|
||||
throw new ApplicationException(uex.except.type().id(),
|
||||
uex.except.create_input_stream()
|
||||
);
|
||||
}
|
||||
catch (BadKind ex)
|
||||
{
|
||||
InternalError ierr = new InternalError();
|
||||
ierr.initCause(ex);
|
||||
throw ierr;
|
||||
}
|
||||
}
|
||||
if (lr.return_value() != null)
|
||||
lr.return_value().write_value(buf);
|
||||
|
||||
NamedValue a;
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < lr.arguments().count(); i++)
|
||||
{
|
||||
a = lr.arguments().item(i);
|
||||
if (a.flags() == ARG_INOUT.value ||
|
||||
a.flags() == ARG_INOUT.value
|
||||
)
|
||||
{
|
||||
a.value().write_value(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Bounds ex)
|
||||
{
|
||||
InternalError ierr = new InternalError();
|
||||
ierr.initCause(ex);
|
||||
throw ierr;
|
||||
}
|
||||
|
||||
return buf.create_input_stream();
|
||||
}
|
||||
else
|
||||
{
|
||||
LocalRequest lrq = (LocalRequest) sr.request;
|
||||
return lrq.s_invoke(handler);
|
||||
}
|
||||
}
|
||||
catch (gnuForwardRequest f)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((ObjectImpl) f.forward_reference)._invoke(f.forward_reference._request(
|
||||
operation,
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
catch (RemarshalException e)
|
||||
{
|
||||
// Never thrown in this place by Classpath implementation.
|
||||
throw new NO_IMPLEMENT();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void releaseReply(org.omg.CORBA.Object target, InputStream input)
|
||||
{
|
||||
release(target);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,684 @@
|
|||
/* LocalRequest.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA.CDR.cdrBufOutput;
|
||||
import gnu.CORBA.GIOP.MessageHeader;
|
||||
import gnu.CORBA.GIOP.v1_2.ReplyHeader;
|
||||
import gnu.CORBA.GIOP.v1_2.RequestHeader;
|
||||
import gnu.CORBA.Interceptor.gnuClientRequestInfo;
|
||||
import gnu.CORBA.Interceptor.gnuServerRequestInfo;
|
||||
import gnu.CORBA.ObjectCreator;
|
||||
import gnu.CORBA.Unexpected;
|
||||
import gnu.CORBA.gnuAny;
|
||||
import gnu.CORBA.gnuRequest;
|
||||
import gnu.CORBA.recordTypeCode;
|
||||
import gnu.CORBA.streamReadyHolder;
|
||||
import gnu.CORBA.streamRequest;
|
||||
|
||||
import org.omg.CORBA.ARG_OUT;
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_INV_ORDER;
|
||||
import org.omg.CORBA.BAD_OPERATION;
|
||||
import org.omg.CORBA.Bounds;
|
||||
import org.omg.CORBA.NamedValue;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.SystemException;
|
||||
import org.omg.CORBA.TCKind;
|
||||
import org.omg.CORBA.UnknownUserException;
|
||||
import org.omg.CORBA.UserException;
|
||||
import org.omg.CORBA.portable.ApplicationException;
|
||||
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;
|
||||
import org.omg.PortableInterceptor.ClientRequestInterceptorOperations;
|
||||
import org.omg.PortableInterceptor.ForwardRequest;
|
||||
import org.omg.PortableInterceptor.ServerRequestInterceptorOperations;
|
||||
import org.omg.PortableServer.CurrentOperations;
|
||||
import org.omg.PortableServer.CurrentPackage.NoContext;
|
||||
import org.omg.PortableServer.DynamicImplementation;
|
||||
import org.omg.PortableServer.POA;
|
||||
import org.omg.PortableServer.Servant;
|
||||
import org.omg.PortableServer.ServantLocatorPackage.CookieHolder;
|
||||
import org.omg.PortableServer.portable.Delegate;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Directs the invocation to the locally available servant. The POA servant does
|
||||
* not longer implement the CORBA object and cannot be substituted directly.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class LocalRequest extends gnuRequest implements ResponseHandler,
|
||||
CurrentOperations
|
||||
{
|
||||
/**
|
||||
* Used by servant locator, if involved.
|
||||
*/
|
||||
CookieHolder cookie;
|
||||
|
||||
/**
|
||||
* The object Id.
|
||||
*/
|
||||
final byte[] Id;
|
||||
|
||||
/**
|
||||
* The message header (singleton is sufficient).
|
||||
*/
|
||||
private static final MessageHeader header = new MessageHeader();
|
||||
|
||||
/**
|
||||
* True if the stream was obtained by invoking {@link #createExceptionReply()},
|
||||
* false otherwise.
|
||||
*/
|
||||
boolean exceptionReply;
|
||||
|
||||
/**
|
||||
* The buffer to write into.
|
||||
*/
|
||||
cdrBufOutput buffer;
|
||||
|
||||
/**
|
||||
* The responsible POA.
|
||||
*/
|
||||
final gnuPOA poa;
|
||||
|
||||
/**
|
||||
* The servant delegate to obtain the handler.
|
||||
*/
|
||||
gnuServantObject object;
|
||||
|
||||
/**
|
||||
* Used (reused) with dynamic implementation.
|
||||
*/
|
||||
LocalServerRequest serverRequest;
|
||||
|
||||
/**
|
||||
* Create an instance of the local request.
|
||||
*/
|
||||
public LocalRequest(gnuServantObject local_object, gnuPOA a_poa, byte[] an_id)
|
||||
{
|
||||
Id = an_id;
|
||||
poa = a_poa;
|
||||
|
||||
// Instantiate the cookie holder only if required.
|
||||
if (poa.servant_locator != null)
|
||||
{
|
||||
cookie = new CookieHolder();
|
||||
}
|
||||
object = local_object;
|
||||
prepareStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an invocation and return a stream from where the results can be read
|
||||
* and throw ApplicationException, where applicable.
|
||||
*/
|
||||
org.omg.CORBA.portable.InputStream s_invoke(InvokeHandler handler)
|
||||
throws ApplicationException
|
||||
{
|
||||
try
|
||||
{
|
||||
poa.m_orb.currents.put(Thread.currentThread(), this);
|
||||
|
||||
org.omg.CORBA.portable.InputStream input = v_invoke(handler);
|
||||
|
||||
if (!exceptionReply)
|
||||
{
|
||||
return input;
|
||||
}
|
||||
else
|
||||
{
|
||||
input.mark(500);
|
||||
|
||||
String id = input.read_string();
|
||||
try
|
||||
{
|
||||
input.reset();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
InternalError ierr = new InternalError();
|
||||
ierr.initCause(ex);
|
||||
throw ierr;
|
||||
}
|
||||
throw new ApplicationException(id, input);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
poa.m_orb.currents.remove(Thread.currentThread());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an invocation and return a stream from where the results can be read.
|
||||
*
|
||||
* @param the invoke handler (can be null, then it is obtained self
|
||||
* dependently).
|
||||
*/
|
||||
public org.omg.CORBA.portable.InputStream v_invoke(InvokeHandler handler)
|
||||
{
|
||||
// Local request must be intercepted both by server and request
|
||||
// interceptors.
|
||||
boolean s_intercept = false;
|
||||
ServerRequestInterceptorOperations s_interceptor = null;
|
||||
gnuServerRequestInfo s_info = null;
|
||||
|
||||
boolean c_intercept = false;
|
||||
ClientRequestInterceptorOperations c_interceptor = null;
|
||||
gnuClientRequestInfo c_info = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (poa.m_orb.iServer != null || poa.m_orb.iClient != null)
|
||||
{
|
||||
setORB(poa.m_orb);
|
||||
|
||||
// These two are only needed with interceptors.
|
||||
m_rqh = new RequestHeader();
|
||||
m_rqh.operation = m_operation;
|
||||
m_rph = new ReplyHeader();
|
||||
|
||||
m_rqh.object_key = object.Id;
|
||||
m_rph.request_id = m_rqh.request_id;
|
||||
}
|
||||
|
||||
if (poa.m_orb.iClient != null)
|
||||
{
|
||||
c_interceptor = poa.m_orb.iClient;
|
||||
|
||||
c_info = new gnuClientRequestInfo(this);
|
||||
c_intercept = true;
|
||||
|
||||
c_interceptor.send_request(c_info);
|
||||
|
||||
m_target = object;
|
||||
}
|
||||
|
||||
if (poa.m_orb.iServer != null)
|
||||
{
|
||||
s_interceptor = poa.m_orb.iServer;
|
||||
|
||||
s_info = new gnuServerRequestInfo(object, m_rqh, m_rph);
|
||||
s_info.m_request = this;
|
||||
|
||||
s_intercept = true;
|
||||
|
||||
s_interceptor.receive_request_service_contexts(s_info);
|
||||
}
|
||||
|
||||
if (handler == null)
|
||||
{
|
||||
handler = object.getHandler(operation(), cookie, false);
|
||||
}
|
||||
|
||||
cdrBufOutput request_part = new cdrBufOutput();
|
||||
|
||||
request_part.setOrb(orb());
|
||||
|
||||
if (m_args != null && m_args.count() > 0)
|
||||
{
|
||||
write_parameters(header, request_part);
|
||||
|
||||
if (m_parameter_buffer != null)
|
||||
{
|
||||
throw new BAD_INV_ORDER("Please either add parameters or " +
|
||||
"write them into stream, but not both " + "at once."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_parameter_buffer != null)
|
||||
{
|
||||
write_parameter_buffer(header, request_part);
|
||||
}
|
||||
|
||||
Servant servant;
|
||||
|
||||
if (handler instanceof Servant)
|
||||
{
|
||||
servant = (Servant) handler;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BAD_OPERATION("Unexpected handler type " + handler);
|
||||
}
|
||||
|
||||
org.omg.CORBA.portable.InputStream input =
|
||||
request_part.create_input_stream();
|
||||
|
||||
// Ensure the servant (handler) has a delegate set.
|
||||
servantDelegate sd = null;
|
||||
|
||||
Delegate d = null;
|
||||
|
||||
try
|
||||
{
|
||||
d = servant._get_delegate();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// In some cases exception is thrown if the delegate is not set.
|
||||
}
|
||||
if (d instanceof servantDelegate)
|
||||
{
|
||||
// If the delegate is already set, try to reuse the existing
|
||||
// instance.
|
||||
sd = (servantDelegate) d;
|
||||
if (sd.object != object)
|
||||
{
|
||||
sd = new servantDelegate(servant, poa, Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sd = new servantDelegate(servant, poa, Id);
|
||||
}
|
||||
servant._set_delegate(sd);
|
||||
|
||||
try
|
||||
{
|
||||
ORB o = orb();
|
||||
if (o instanceof ORB_1_4)
|
||||
{
|
||||
((ORB_1_4) o).currents.put(Thread.currentThread(), this);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (s_intercept)
|
||||
{
|
||||
s_interceptor.receive_request(s_info);
|
||||
}
|
||||
handler._invoke(m_operation, input, this);
|
||||
|
||||
// Handler is casted into i_handler.
|
||||
if ((s_intercept || c_intercept) && isExceptionReply())
|
||||
{
|
||||
s_info.m_reply_header.reply_status =
|
||||
ReplyHeader.USER_EXCEPTION;
|
||||
m_rph.reply_status = ReplyHeader.USER_EXCEPTION;
|
||||
|
||||
// Make Any, holding the user exception.
|
||||
Any a = new gnuAny();
|
||||
OutputStream buf = getBuffer();
|
||||
InputStream in = buf.create_input_stream();
|
||||
String uex_idl = "unknown";
|
||||
try
|
||||
{
|
||||
in.mark(Integer.MAX_VALUE);
|
||||
uex_idl = in.read_string();
|
||||
m_exception_id = uex_idl;
|
||||
in.reset();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
UserException exception =
|
||||
ObjectCreator.readUserException(uex_idl, in);
|
||||
|
||||
m_environment.exception(exception);
|
||||
ObjectCreator.insertWithHelper(a, exception);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Failed due any reason, insert without
|
||||
// helper.
|
||||
a.insert_Streamable(new streamReadyHolder(
|
||||
buf.create_input_stream()
|
||||
)
|
||||
);
|
||||
|
||||
recordTypeCode r =
|
||||
new recordTypeCode(TCKind.tk_except);
|
||||
r.setId(uex_idl);
|
||||
r.setName(ObjectCreator.getDefaultName(uex_idl));
|
||||
}
|
||||
|
||||
s_info.m_usr_exception = a;
|
||||
c_info.m_wrapped_exception = a;
|
||||
s_interceptor.send_exception(s_info);
|
||||
c_interceptor.receive_exception(c_info);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_intercept)
|
||||
{
|
||||
s_info.m_reply_header.reply_status =
|
||||
ReplyHeader.NO_EXCEPTION;
|
||||
s_interceptor.send_reply(s_info);
|
||||
}
|
||||
if (c_intercept)
|
||||
{
|
||||
m_rph.reply_status = ReplyHeader.NO_EXCEPTION;
|
||||
c_interceptor.receive_reply(c_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SystemException sys_ex)
|
||||
{
|
||||
if (s_intercept)
|
||||
{
|
||||
s_info.m_reply_header.reply_status =
|
||||
ReplyHeader.SYSTEM_EXCEPTION;
|
||||
s_info.m_sys_exception = sys_ex;
|
||||
s_interceptor.send_exception(s_info);
|
||||
}
|
||||
|
||||
if (c_intercept)
|
||||
{
|
||||
m_rph.reply_status = ReplyHeader.SYSTEM_EXCEPTION;
|
||||
|
||||
Any a = new gnuAny();
|
||||
if (ObjectCreator.insertSysException(a, sys_ex))
|
||||
{
|
||||
c_info.m_wrapped_exception = a;
|
||||
}
|
||||
c_interceptor.receive_exception(c_info);
|
||||
}
|
||||
|
||||
throw sys_ex;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ORB o = orb();
|
||||
if (o instanceof ORB_1_4)
|
||||
{
|
||||
((ORB_1_4) o).currents.remove(Thread.currentThread());
|
||||
}
|
||||
}
|
||||
|
||||
if (poa.servant_locator != null)
|
||||
{
|
||||
poa.servant_locator.postinvoke(object.Id, poa, operation(),
|
||||
cookie.value, object.getServant()
|
||||
);
|
||||
}
|
||||
return buffer.create_input_stream();
|
||||
}
|
||||
|
||||
catch (ForwardRequest fex)
|
||||
{
|
||||
// May be thrown by interceptor.
|
||||
if (s_intercept)
|
||||
{
|
||||
Forwarding:
|
||||
while (true)
|
||||
{
|
||||
s_info.m_reply_header.reply_status =
|
||||
ReplyHeader.LOCATION_FORWARD;
|
||||
s_info.m_forward_reference = fex.forward;
|
||||
try
|
||||
{
|
||||
s_interceptor.send_other(s_info);
|
||||
break Forwarding;
|
||||
}
|
||||
catch (ForwardRequest fex2)
|
||||
{
|
||||
s_info.m_forward_reference = fex2.forward;
|
||||
fex.forward = s_info.m_forward_reference;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (c_intercept)
|
||||
{
|
||||
this.m_rph.reply_status = ReplyHeader.LOCATION_FORWARD;
|
||||
this.m_forwarding_target = fex.forward;
|
||||
try
|
||||
{
|
||||
c_interceptor.receive_other(c_info);
|
||||
}
|
||||
catch (ForwardRequest fex2)
|
||||
{
|
||||
fex.forward = fex2.forward;
|
||||
}
|
||||
}
|
||||
throw new gnuForwardRequest(fex.forward);
|
||||
}
|
||||
catch (gnuForwardRequest fex)
|
||||
{
|
||||
// May be thrown during activation.
|
||||
// May be thrown during activation.
|
||||
if (s_intercept)
|
||||
{
|
||||
Forwarding:
|
||||
while (true)
|
||||
{
|
||||
s_info.m_reply_header.reply_status =
|
||||
ReplyHeader.LOCATION_FORWARD;
|
||||
s_info.m_forward_reference = fex.forward_reference;
|
||||
try
|
||||
{
|
||||
s_interceptor.send_other(s_info);
|
||||
break Forwarding;
|
||||
}
|
||||
catch (ForwardRequest fex2)
|
||||
{
|
||||
s_info.m_forward_reference = fex2.forward;
|
||||
fex.forward_reference = (ObjectImpl) fex2.forward;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (c_intercept)
|
||||
{
|
||||
this.m_rph.reply_status = ReplyHeader.LOCATION_FORWARD;
|
||||
this.m_forwarding_target = fex.forward_reference;
|
||||
try
|
||||
{
|
||||
c_interceptor.receive_other(c_info);
|
||||
}
|
||||
catch (ForwardRequest fex2)
|
||||
{
|
||||
fex.forward_reference = (ObjectImpl) fex2.forward;
|
||||
}
|
||||
}
|
||||
throw fex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an invocation and store the result in the fields of this Request. Used
|
||||
* with DII only.
|
||||
*/
|
||||
public void invoke()
|
||||
{
|
||||
InvokeHandler handler = object.getHandler(operation(), cookie, false);
|
||||
|
||||
if (handler instanceof dynImpHandler)
|
||||
{
|
||||
DynamicImplementation dyn = ((dynImpHandler) handler).servant;
|
||||
if (serverRequest == null)
|
||||
{
|
||||
serverRequest = new LocalServerRequest(this);
|
||||
}
|
||||
try
|
||||
{
|
||||
poa.m_orb.currents.put(Thread.currentThread(), this);
|
||||
dyn.invoke(serverRequest);
|
||||
}
|
||||
finally
|
||||
{
|
||||
poa.m_orb.currents.remove(Thread.currentThread());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
org.omg.CORBA.portable.InputStream input = v_invoke(handler);
|
||||
|
||||
if (!exceptionReply)
|
||||
{
|
||||
NamedValue arg;
|
||||
|
||||
// Read return value, if set.
|
||||
if (m_result != null)
|
||||
{
|
||||
m_result.value().read_value(input, m_result.value().type());
|
||||
}
|
||||
|
||||
// Read returned parameters, if set.
|
||||
if (m_args != null)
|
||||
{
|
||||
for (int i = 0; i < m_args.count(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
arg = m_args.item(i);
|
||||
|
||||
// Both ARG_INOUT and ARG_OUT have this binary flag set.
|
||||
if ((arg.flags() & ARG_OUT.value) != 0)
|
||||
{
|
||||
arg.value().read_value(input, arg.value().type());
|
||||
}
|
||||
}
|
||||
catch (Bounds ex)
|
||||
{
|
||||
Unexpected.error(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else// User exception reply
|
||||
{
|
||||
// Prepare an Any that will hold the exception.
|
||||
gnuAny exc = new gnuAny();
|
||||
|
||||
exc.insert_Streamable(new streamReadyHolder(input));
|
||||
|
||||
UnknownUserException unuex = new UnknownUserException(exc);
|
||||
m_environment.exception(unuex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an output stream for providing details about the exception. Before
|
||||
* returning the stream, the handler automatically writes the message header
|
||||
* and the reply about exception header, but not the message header.
|
||||
*
|
||||
* @return the stream to write exception details into.
|
||||
*/
|
||||
public OutputStream createExceptionReply()
|
||||
{
|
||||
exceptionReply = true;
|
||||
prepareStream();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an output stream for writing a regular reply (not an exception).
|
||||
*
|
||||
* Before returning the stream, the handler automatically writes the regular
|
||||
* reply header, but not the message header.
|
||||
*
|
||||
* @return the output stream for writing a regular reply.
|
||||
*/
|
||||
public OutputStream createReply()
|
||||
{
|
||||
exceptionReply = false;
|
||||
prepareStream();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the buffer, normally containing the written reply. The reply includes
|
||||
* the reply header (or the exception header) but does not include the message
|
||||
* header.
|
||||
*
|
||||
* The stream buffer can also be empty if no data have been written into
|
||||
* streams, returned by {@link #createReply()} or
|
||||
* {@link #createExceptionReply()}.
|
||||
*
|
||||
* @return the CDR output stream, containing the written output.
|
||||
*/
|
||||
cdrBufOutput getBuffer()
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the stream was obtained by invoking {@link #createExceptionReply()},
|
||||
* false otherwise (usually no-exception reply).
|
||||
*/
|
||||
boolean isExceptionReply()
|
||||
{
|
||||
return exceptionReply;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the header offset, set the correct version number and codeset.
|
||||
*/
|
||||
private void prepareStream()
|
||||
{
|
||||
buffer = new cdrBufOutput();
|
||||
buffer.setOrb(orb());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parameter stream, where the invocation arguments should be written
|
||||
* if they are written into the stream directly.
|
||||
*/
|
||||
public streamRequest getParameterStream()
|
||||
{
|
||||
m_parameter_buffer = new streamRequest();
|
||||
m_parameter_buffer.request = this;
|
||||
m_parameter_buffer.setOrb(poa.orb());
|
||||
return m_parameter_buffer;
|
||||
}
|
||||
|
||||
public byte[] get_object_id() throws NoContext
|
||||
{
|
||||
return Id;
|
||||
}
|
||||
|
||||
public POA get_POA() throws NoContext
|
||||
{
|
||||
return poa;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
/* LocalServerRequest.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA.gnuNamedValue;
|
||||
|
||||
import org.omg.CORBA.ARG_INOUT;
|
||||
import org.omg.CORBA.ARG_OUT;
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.Bounds;
|
||||
import org.omg.CORBA.Context;
|
||||
import org.omg.CORBA.NVList;
|
||||
import org.omg.CORBA.NamedValue;
|
||||
import org.omg.CORBA.ServerRequest;
|
||||
import org.omg.CORBA.UnknownUserException;
|
||||
|
||||
/**
|
||||
* Used to make local invocations via LocalRequest.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class LocalServerRequest
|
||||
extends ServerRequest
|
||||
{
|
||||
/**
|
||||
* The local request, on the base of that this instance is created.
|
||||
*/
|
||||
final LocalRequest request;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
public LocalServerRequest(LocalRequest _request)
|
||||
{
|
||||
request = _request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the argument list that can be modified.
|
||||
*/
|
||||
public void params(NVList args)
|
||||
{
|
||||
arguments(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get contexts.
|
||||
*/
|
||||
public Context ctx()
|
||||
{
|
||||
return request.ctx();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the operatin being performed.
|
||||
*/
|
||||
public String operation()
|
||||
{
|
||||
return request.operation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the argument list that can be modified.
|
||||
* The direction depends on the size of the passed list.
|
||||
* The empty list is filled with the request arguments.
|
||||
* The non-empty list is used to set the request arguments.
|
||||
*/
|
||||
public void arguments(NVList args)
|
||||
{
|
||||
NVList l = request.arguments();
|
||||
NamedValue a;
|
||||
|
||||
try
|
||||
{
|
||||
if (args.count() == 0)
|
||||
{
|
||||
// Transfer to the passed parameter.
|
||||
for (int i = 0; i < l.count(); i++)
|
||||
{
|
||||
a = l.item(i);
|
||||
args.add_value(a.name(), a.value(), a.flags());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Transfer from the passed parameter.
|
||||
if (l.count() != args.count())
|
||||
throw new BAD_PARAM("Argument number mismatch, current " +
|
||||
l.count() + ", passed " + args.count()
|
||||
);
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < l.count(); i++)
|
||||
{
|
||||
a = l.item(i);
|
||||
if (a.flags() == ARG_INOUT.value ||
|
||||
a.flags() == ARG_OUT.value
|
||||
)
|
||||
{
|
||||
((gnuNamedValue) a).setValue(args.item(i).value());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ClassCastException cex)
|
||||
{
|
||||
InternalError ierr = new InternalError();
|
||||
ierr.initCause(cex);
|
||||
throw ierr;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Bounds ex)
|
||||
{
|
||||
InternalError ierr = new InternalError();
|
||||
ierr.initCause(ex);
|
||||
throw ierr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the result.
|
||||
*/
|
||||
public void set_result(Any result)
|
||||
{
|
||||
gnuNamedValue g = new gnuNamedValue();
|
||||
g.setValue(result);
|
||||
g.setFlags(ARG_OUT.value);
|
||||
request.set_result(g);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the method being called.
|
||||
*/
|
||||
public String op_name()
|
||||
{
|
||||
return request.operation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the exception that has been thrown.
|
||||
*/
|
||||
public void set_exception(Any exc)
|
||||
{
|
||||
request.env().exception(new UnknownUserException(exc));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the result.
|
||||
*/
|
||||
public void result(Any r)
|
||||
{
|
||||
set_result(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the exception.
|
||||
*/
|
||||
public void except(Any exc)
|
||||
{
|
||||
set_exception(exc);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,256 @@
|
|||
/* ORB_1_4.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA.Functional_ORB;
|
||||
import gnu.CORBA.IOR;
|
||||
import gnu.CORBA.Connected_objects.cObject;
|
||||
import gnu.CORBA.DynAn.gnuDynAnyFactory;
|
||||
import gnu.CORBA.Interceptor.ClientRequestInterceptors;
|
||||
import gnu.CORBA.Interceptor.IORInterceptors;
|
||||
import gnu.CORBA.Interceptor.Registrator;
|
||||
import gnu.CORBA.Interceptor.ServerRequestInterceptors;
|
||||
import gnu.CORBA.Interceptor.gnuIcCurrent;
|
||||
import gnu.CORBA.Interceptor.gnuIorInfo;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_OPERATION;
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.OBJECT_NOT_EXIST;
|
||||
import org.omg.CORBA.Policy;
|
||||
import org.omg.CORBA.PolicyError;
|
||||
import org.omg.CORBA.portable.ObjectImpl;
|
||||
import org.omg.PortableInterceptor.PolicyFactory;
|
||||
import org.omg.PortableServer.POA;
|
||||
import org.omg.PortableServer.POAPackage.InvalidPolicy;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* The ORB, supporting POAs that are the feature of jdk 1.4.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class ORB_1_4
|
||||
extends Functional_ORB
|
||||
{
|
||||
/**
|
||||
* The root POA.
|
||||
*/
|
||||
public final gnuPOA rootPOA;
|
||||
|
||||
/**
|
||||
* Maps the active threads to the invocation data ("POA Current's").
|
||||
*/
|
||||
public gnuPoaCurrent currents = new gnuPoaCurrent();
|
||||
|
||||
/**
|
||||
* Maps the active threads to the interceptor data ("Interceptor Current's").
|
||||
*/
|
||||
public gnuIcCurrent ic_current = new gnuIcCurrent(this);
|
||||
|
||||
/**
|
||||
* Creates dynamic anys.
|
||||
*/
|
||||
public gnuDynAnyFactory factory = new gnuDynAnyFactory(this);
|
||||
|
||||
/**
|
||||
* Calls the parent constructor and additionally puts the "RootPOA",
|
||||
* "RootPOAManager", "POACurrent" and "DynAnyFactory" into initial references.
|
||||
*/
|
||||
public ORB_1_4()
|
||||
{
|
||||
super();
|
||||
try
|
||||
{
|
||||
rootPOA = new gnuPOA(null, "RootPOA", null, policySets.rootPoa(), this);
|
||||
}
|
||||
catch (InvalidPolicy ex)
|
||||
{
|
||||
// Invalid default policy set.
|
||||
InternalError ierr = new InternalError();
|
||||
ierr.initCause(ex);
|
||||
throw ierr;
|
||||
}
|
||||
initial_references.put("RootPOA", rootPOA);
|
||||
initial_references.put("RootPOAManager", rootPOA.the_POAManager());
|
||||
initial_references.put("POACurrent", currents);
|
||||
initial_references.put("DynAnyFactory", factory);
|
||||
initial_references.put("PICurrent", ic_current);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the super method detects that the object is not connected to this ORB,
|
||||
* try to find and activate the object.
|
||||
*/
|
||||
public String object_to_string(org.omg.CORBA.Object forObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
return super.object_to_string(forObject);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
activeObjectMap.Obj exists = rootPOA.findObject(forObject);
|
||||
if (exists == null)
|
||||
throw new OBJECT_NOT_EXIST(forObject == null ? "null"
|
||||
: forObject.toString());
|
||||
else if (exists.poa instanceof gnuPOA)
|
||||
((gnuPOA) exists.poa).connect_to_orb(exists.key, forObject);
|
||||
else
|
||||
exists.poa.create_reference_with_id(exists.key,
|
||||
((ObjectImpl) exists.object)._ids()[0]);
|
||||
}
|
||||
catch (Exception bex)
|
||||
{
|
||||
BAD_PARAM bad = new BAD_PARAM("Unable to activate " + forObject);
|
||||
bad.initCause(bex);
|
||||
throw bad;
|
||||
}
|
||||
|
||||
return super.object_to_string(forObject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all poas and then call the superclass method.
|
||||
*/
|
||||
public void destroy()
|
||||
{
|
||||
// This will propagate through the whole POA tree.
|
||||
rootPOA.destroy(true, false);
|
||||
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do interceptor registration.
|
||||
*
|
||||
* @param properties the properties, between those names the agreed prefix
|
||||
* "org.omg.PortableInterceptor.ORBInitializerClass." is searched.
|
||||
*
|
||||
* @param args the string array, passed to the ORB.init
|
||||
*/
|
||||
protected void registerInterceptors(Properties properties, String[] args)
|
||||
{
|
||||
Registrator registrator = new Registrator(this, properties, args);
|
||||
|
||||
policyFactories = registrator.m_policyFactories;
|
||||
|
||||
registrator.pre_init();
|
||||
initial_references.putAll(registrator.getRegisteredReferences());
|
||||
registrator.post_init();
|
||||
|
||||
if (registrator.hasIorInterceptors())
|
||||
iIor = new IORInterceptors(registrator);
|
||||
|
||||
if (registrator.hasServerRequestInterceptors())
|
||||
iServer = new ServerRequestInterceptors(registrator);
|
||||
|
||||
if (registrator.hasClientRequestInterceptors())
|
||||
iClient = new ClientRequestInterceptors(registrator);
|
||||
|
||||
policyFactories = registrator.m_policyFactories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create IOR and allow registered interceptors to add additional components.
|
||||
*/
|
||||
protected IOR createIOR(cObject ref)
|
||||
throws BAD_OPERATION
|
||||
{
|
||||
IOR ior = super.createIOR(ref);
|
||||
if (iIor != null)
|
||||
{
|
||||
activeObjectMap.Obj obj = rootPOA.findIorKey(ior.key);
|
||||
|
||||
POA poa;
|
||||
|
||||
// Null means that the object was connected to the ORB directly.
|
||||
if (obj == null)
|
||||
poa = rootPOA;
|
||||
else
|
||||
poa = obj.poa;
|
||||
|
||||
gnuIorInfo info = new gnuIorInfo(this, poa, ior);
|
||||
|
||||
// This may modify the ior.
|
||||
iIor.establish_components(info);
|
||||
}
|
||||
return ior;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create policy using the previously registered factory.
|
||||
*/
|
||||
public Policy create_policy(int type, Any value)
|
||||
throws PolicyError
|
||||
{
|
||||
Integer policy = new Integer(type);
|
||||
|
||||
PolicyFactory forge = (PolicyFactory) policyFactories.get(policy);
|
||||
if (forge == null)
|
||||
throw new PolicyError("No factory registered for policy " + type,
|
||||
(short) type);
|
||||
else
|
||||
return forge.create_policy(type, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the parameters and then register interceptors.
|
||||
*/
|
||||
protected void set_parameters(Applet app, Properties props)
|
||||
{
|
||||
super.set_parameters(app, props);
|
||||
registerInterceptors(props, new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the parameters and then register interceptors.
|
||||
*/
|
||||
protected void set_parameters(String[] para, Properties props)
|
||||
{
|
||||
super.set_parameters(para, props);
|
||||
registerInterceptors(props, para);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,394 @@
|
|||
/* activeObjectMap.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA.ByteArrayComparator;
|
||||
|
||||
import org.omg.PortableServer.POA;
|
||||
import org.omg.PortableServer.Servant;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* Implements the conception of the Active Object Map.
|
||||
* If the POA supports the RETAIN policy, it maintains an Active
|
||||
* Object Map, that associates Object Ids with active servants.
|
||||
* Each association constitutes an active object. We use a single map
|
||||
* for all POAs on the given orb.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class activeObjectMap
|
||||
{
|
||||
/**
|
||||
* The reference data about the object, placed on the AOM.
|
||||
*/
|
||||
public class Obj
|
||||
{
|
||||
/**
|
||||
* Create an initialised instance.
|
||||
*/
|
||||
Obj(org.omg.CORBA.Object _object, byte[] _key, Servant _servant, POA _poa)
|
||||
{
|
||||
object = _object;
|
||||
key = _key;
|
||||
servant = _servant;
|
||||
poa = _poa;
|
||||
}
|
||||
|
||||
/**
|
||||
* The object.
|
||||
*/
|
||||
public final org.omg.CORBA.Object object;
|
||||
|
||||
/**
|
||||
* The servant, serving the given object.
|
||||
*/
|
||||
public Servant servant;
|
||||
|
||||
/**
|
||||
* The local servant that once served this object.
|
||||
* This field is used by {@link ForwardedServant} when it discovers that
|
||||
* the forwarding chaing returns back to the original location.
|
||||
* It should not be used anywhere else.
|
||||
*/
|
||||
Servant primary_servant;
|
||||
|
||||
/**
|
||||
* The POA, where the object is connected.
|
||||
*/
|
||||
public final POA poa;
|
||||
|
||||
/**
|
||||
* The object key.
|
||||
*/
|
||||
public final byte[] key;
|
||||
|
||||
/**
|
||||
* If true, this entry is deactivated.
|
||||
*/
|
||||
public boolean deactivated;
|
||||
|
||||
/**
|
||||
* Set the servant value, preserving any non null
|
||||
* value as the primary servant.
|
||||
*/
|
||||
public void setServant(Servant s)
|
||||
{
|
||||
if (primary_servant == null)
|
||||
primary_servant = s;
|
||||
servant = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the servant.
|
||||
*/
|
||||
public Servant getServant()
|
||||
{
|
||||
return servant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the deactivation state.
|
||||
*/
|
||||
public boolean isDeactiveted()
|
||||
{
|
||||
return deactivated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the deactivation state.
|
||||
*/
|
||||
public void setDeactivated(boolean state)
|
||||
{
|
||||
deactivated = state;
|
||||
}
|
||||
|
||||
public boolean equals(java.lang.Object other)
|
||||
{
|
||||
if (other instanceof Obj)
|
||||
{
|
||||
Obj o = (Obj) other;
|
||||
return o.object.equals(object);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The free number to give for the next instance.
|
||||
* This field is incremented each time the
|
||||
* new collection of the connected objects is created.
|
||||
* Each collection has its own unique instance number.
|
||||
*/
|
||||
private static long free_id;
|
||||
|
||||
/**
|
||||
* The map of the all connected objects, maps the object key to the
|
||||
* object.
|
||||
*/
|
||||
Map objects = new TreeMap(new ByteArrayComparator());
|
||||
|
||||
/**
|
||||
* Get the record of the stored object. If the object is mapped
|
||||
* several times under the different keys, one of the mappings
|
||||
* is used.
|
||||
*
|
||||
* @param object the stored object
|
||||
*
|
||||
* @return the record about the stored object, null if
|
||||
* this object is not stored here.
|
||||
*/
|
||||
public Obj findObject(org.omg.CORBA.Object stored_object)
|
||||
{
|
||||
if (stored_object == null)
|
||||
return null;
|
||||
|
||||
Map.Entry item;
|
||||
Iterator iter = objects.entrySet().iterator();
|
||||
Obj ref;
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
item = (Map.Entry) iter.next();
|
||||
ref = (Obj) item.getValue();
|
||||
if (stored_object.equals(ref.object))
|
||||
return ref;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the reference info for the given servant.
|
||||
* If the servant is mapped to several objects, this
|
||||
* returns the first found occurence.
|
||||
*
|
||||
* @param servant a servant to find.
|
||||
*
|
||||
* @return the servant/object/POA binding or null if no such found.
|
||||
*/
|
||||
public Obj findServant(Servant servant)
|
||||
{
|
||||
if (servant == null)
|
||||
return null;
|
||||
|
||||
Map.Entry item;
|
||||
Iterator iter = objects.entrySet().iterator();
|
||||
Obj ref;
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
item = (Map.Entry) iter.next();
|
||||
ref = (Obj) item.getValue();
|
||||
if (servant.equals(ref.servant))
|
||||
return ref;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the reference info for the given servant.
|
||||
* If the servant is mapped to several objects, this
|
||||
* returns the first found occurence.
|
||||
*
|
||||
* @param servant a servant to find.
|
||||
* @param speficies if to search for the inactive (true) or active
|
||||
* (false) servant. A servant with unmatching activity is ignored
|
||||
* by this method.
|
||||
*
|
||||
* @return the servant/object/POA binding or null if no such found.
|
||||
*/
|
||||
public Obj findServant(Servant servant, boolean inactive)
|
||||
{
|
||||
if (servant == null)
|
||||
return null;
|
||||
|
||||
Map.Entry item;
|
||||
Iterator iter = objects.entrySet().iterator();
|
||||
Obj ref;
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
item = (Map.Entry) iter.next();
|
||||
ref = (Obj) item.getValue();
|
||||
if (ref.deactivated == inactive)
|
||||
if (ref.servant != null)
|
||||
if (servant.equals(ref.servant))
|
||||
return ref;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the new object to the repository. The object key is
|
||||
* generated automatically.
|
||||
*
|
||||
* @param object the object to add.
|
||||
* @param servant a servant, serving the given object.
|
||||
* @param poa the poa, where the object is connected.
|
||||
*
|
||||
* @return the newly created object record.
|
||||
*/
|
||||
public Obj add(org.omg.CORBA.Object object, Servant servant, POA poa)
|
||||
{
|
||||
return add(generateObjectKey(object), object, servant, poa);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the new object to the repository.
|
||||
*
|
||||
* @param key the object key.
|
||||
* @param object the object to add.
|
||||
* @param servant a servant, serving the given object.
|
||||
* @param poa the POA, where the object is connected.
|
||||
*/
|
||||
public Obj add(byte[] key, org.omg.CORBA.Object object, Servant servant,
|
||||
POA poa
|
||||
)
|
||||
{
|
||||
Obj rec = new Obj(object, key, servant, poa);
|
||||
objects.put(key, rec);
|
||||
return rec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the new object to the repository.
|
||||
*
|
||||
* @param delegate the delegate, providing data about the servant, key, POA
|
||||
* and object.
|
||||
* @param port the port that this object would take.
|
||||
*/
|
||||
public Obj add(servantDelegate delegate)
|
||||
{
|
||||
Obj rec =
|
||||
new Obj(delegate.object, delegate.servant_id, delegate.servant,
|
||||
delegate.poa
|
||||
);
|
||||
objects.put(delegate.servant_id, rec);
|
||||
return rec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put back the definition structure that has probably been removed earlier.
|
||||
*/
|
||||
public void put(Obj obj)
|
||||
{
|
||||
objects.put(obj.key, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stored object.
|
||||
*
|
||||
* @param key the key (in the byte array form).
|
||||
*
|
||||
* @return the matching object, null if none is matching.
|
||||
*/
|
||||
public Obj get(byte[] key)
|
||||
{
|
||||
return (Obj) objects.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the map key set.
|
||||
*/
|
||||
public Set keySet()
|
||||
{
|
||||
return objects.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given object, indiciating it by the key.
|
||||
*
|
||||
* @param object the object to remove.
|
||||
*/
|
||||
public void remove(byte[] key)
|
||||
{
|
||||
objects.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the object key, unique in the currently
|
||||
* running java virtual machine. The passed object
|
||||
* parameter is currently not in use.
|
||||
*
|
||||
* @return the generated key.
|
||||
*/
|
||||
protected byte[] generateObjectKey(org.omg.CORBA.Object object)
|
||||
{
|
||||
byte[] key;
|
||||
|
||||
// The repetetive keys cannot be generated, but theoretically
|
||||
// the same keys can be passed when calling add(byte[]...).
|
||||
// Hence we check if the key is not already in the map and,
|
||||
// if it is, use the subsequent value.
|
||||
do
|
||||
{
|
||||
key = getFreeId();
|
||||
}
|
||||
while (objects.containsKey(key));
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next free 8 byte id, surely unique between calls of this
|
||||
* method for the currently running virtual machine.
|
||||
*/
|
||||
public static synchronized byte[] getFreeId()
|
||||
{
|
||||
byte[] r = new byte[ 8 ];
|
||||
|
||||
// Start from the faster-changing.
|
||||
r [ 0 ] = ((byte) (0xff & free_id));
|
||||
r [ 1 ] = ((byte) (0xff & (free_id >> 8)));
|
||||
r [ 2 ] = ((byte) (0xff & (free_id >> 16)));
|
||||
r [ 3 ] = ((byte) (0xff & (free_id >> 24)));
|
||||
r [ 4 ] = ((byte) (0xff & (free_id >> 32)));
|
||||
r [ 5 ] = ((byte) (0xff & (free_id >> 40)));
|
||||
r [ 6 ] = ((byte) (0xff & (free_id >> 48)));
|
||||
r [ 7 ] = ((byte) (0xff & (free_id >> 56)));
|
||||
|
||||
free_id++;
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/* dynImpHandler.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.CORBA.Poa;
|
||||
|
||||
import org.omg.CORBA.BAD_OPERATION;
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.InvokeHandler;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
import org.omg.CORBA.portable.ResponseHandler;
|
||||
import org.omg.PortableServer.DynamicImplementation;
|
||||
|
||||
/**
|
||||
* The InvokeHandler, indicating, that the target is a dynamic
|
||||
* implementation rather than an invoke handler. These two
|
||||
* types are not substitutable, but in some methods have possibility
|
||||
* just to handle them differently.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class dynImpHandler
|
||||
implements InvokeHandler
|
||||
{
|
||||
/**
|
||||
* The servant that is a dynamic implementation rather than
|
||||
* invoke handler.
|
||||
*/
|
||||
public final DynamicImplementation servant;
|
||||
|
||||
/**
|
||||
* Create a new instance, wrapping some dyn implementation.
|
||||
* @param _servant
|
||||
*/
|
||||
public dynImpHandler(DynamicImplementation _servant)
|
||||
{
|
||||
servant = _servant;
|
||||
}
|
||||
|
||||
/**
|
||||
* We cannot invoke properly without having parameter info.
|
||||
*
|
||||
* @throws BAD_OPERATION, always.
|
||||
*/
|
||||
public OutputStream _invoke(String method, InputStream input,
|
||||
ResponseHandler handler
|
||||
)
|
||||
{
|
||||
throw new BAD_OPERATION(servant + " is not an InvokeHandler.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/* gnuAdapterActivator.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.CORBA.Poa;
|
||||
|
||||
import org.omg.CORBA.LocalObject;
|
||||
import org.omg.PortableServer.AdapterActivator;
|
||||
import org.omg.PortableServer.POA;
|
||||
|
||||
/**
|
||||
* Defines a simple adapter activator.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuAdapterActivator
|
||||
extends LocalObject
|
||||
implements AdapterActivator
|
||||
{
|
||||
/**
|
||||
* Create a new POA on the parent, using the parent policy set
|
||||
* from the suitable parent of grandparend and with independent
|
||||
* POA manager (passing null to the createPOA).
|
||||
*
|
||||
* @param parent a parent. Either this parent or one of its
|
||||
* grandparents must be gnuAbstractPOA, able to provide a
|
||||
* policy set.
|
||||
*
|
||||
* @param child_name the name of the child being created.
|
||||
*
|
||||
* @return true on success or false if no gnuAbstractPOA
|
||||
* found till the root poa.
|
||||
*/
|
||||
public boolean unknown_adapter(POA parent, String child_name)
|
||||
{
|
||||
try
|
||||
{
|
||||
POA n = parent.create_POA(child_name, null, policySets.rootPoa());
|
||||
n.the_POAManager().activate();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
/* gnuForwardRequest.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA.GIOP.ReplyHeader;
|
||||
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.portable.ObjectImpl;
|
||||
|
||||
/**
|
||||
* The class, indicating that the request should be forwarded to another
|
||||
* target. We cannot use ForwardRequest because the exception is throws
|
||||
* from methods that does not declare throwing it. Hence must be
|
||||
* RuntimeException.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuForwardRequest
|
||||
extends RuntimeException
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID (v1.4) for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = -1L;
|
||||
|
||||
/**
|
||||
* The object reference, indicating the new location of the invocation target.
|
||||
*/
|
||||
public ObjectImpl forward_reference;
|
||||
|
||||
/**
|
||||
* This information shows if we use LOCATION_FORWARD or
|
||||
* LOCATION_FORWARD_PERM in request. By defalult, LOCATION_FORWARD
|
||||
* is always used. To use LOCATION_FORWARD_PERM, this exception should
|
||||
* be thrown from the servant manager instead of ForwardRequest,
|
||||
* with this field set to ReplyHeader.LOCATION_FORWARD_PERM.
|
||||
*/
|
||||
public byte forwarding_code = ReplyHeader.LOCATION_FORWARD;
|
||||
|
||||
/**
|
||||
* Create the ForwardRequest with explaining message and
|
||||
* initialising the object reference to the given value.
|
||||
*
|
||||
* @param why a string, explaining, why this exception has been thrown.
|
||||
* @param a_forward_reference a value for forward_reference.
|
||||
*/
|
||||
public gnuForwardRequest(org.omg.CORBA.Object a_forward_reference)
|
||||
{
|
||||
if (a_forward_reference instanceof ObjectImpl)
|
||||
this.forward_reference = (ObjectImpl) a_forward_reference;
|
||||
else
|
||||
throw new BAD_PARAM("ObjectImpl expected");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/* gnuIdAssignmentPolicy.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA._PolicyImplBase;
|
||||
|
||||
import org.omg.PortableServer.ID_ASSIGNMENT_POLICY_ID;
|
||||
import org.omg.PortableServer.IdAssignmentPolicy;
|
||||
import org.omg.PortableServer.IdAssignmentPolicyValue;
|
||||
|
||||
/**
|
||||
* Implementation of the id assignment policy.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuIdAssignmentPolicy
|
||||
extends _PolicyImplBase
|
||||
implements IdAssignmentPolicy, vPolicy
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Create the policy.
|
||||
*
|
||||
* @param v a value for the policy.
|
||||
*/
|
||||
public gnuIdAssignmentPolicy(IdAssignmentPolicyValue v)
|
||||
{
|
||||
super(ID_ASSIGNMENT_POLICY_ID.value, v, v.value(),
|
||||
"IDL:org.omg/PortableServer/IdAssignmentPolicy:1.0"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for the policy that was passed in a constructor.
|
||||
*/
|
||||
public IdAssignmentPolicyValue value()
|
||||
{
|
||||
return (IdAssignmentPolicyValue) getValue();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/* gnuIdUniquenessPolicy.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA._PolicyImplBase;
|
||||
|
||||
import org.omg.PortableServer.ID_UNIQUENESS_POLICY_ID;
|
||||
import org.omg.PortableServer.IdUniquenessPolicy;
|
||||
import org.omg.PortableServer.IdUniquenessPolicyValue;
|
||||
|
||||
/**
|
||||
* Implementation of the id uniqueness policy.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuIdUniquenessPolicy
|
||||
extends _PolicyImplBase
|
||||
implements IdUniquenessPolicy, vPolicy
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Create the policy.
|
||||
*
|
||||
* @param v a value for the policy.
|
||||
*/
|
||||
public gnuIdUniquenessPolicy(IdUniquenessPolicyValue v)
|
||||
{
|
||||
super(ID_UNIQUENESS_POLICY_ID.value, v, v.value(),
|
||||
"IDL:org.omg/PortableServer/IdUniquenessPolicy:1.0"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for the policy that was passed in a constructor.
|
||||
*/
|
||||
public IdUniquenessPolicyValue value()
|
||||
{
|
||||
return (IdUniquenessPolicyValue) getValue();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/* gnuImplicitActivationPolicy.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA._PolicyImplBase;
|
||||
|
||||
import org.omg.PortableServer.IMPLICIT_ACTIVATION_POLICY_ID;
|
||||
import org.omg.PortableServer.ImplicitActivationPolicy;
|
||||
import org.omg.PortableServer.ImplicitActivationPolicyValue;
|
||||
|
||||
/**
|
||||
* Implementation of the implicit activation policy.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuImplicitActivationPolicy
|
||||
extends _PolicyImplBase
|
||||
implements ImplicitActivationPolicy, vPolicy
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Create the policy.
|
||||
*
|
||||
* @param v a value for the policy.
|
||||
*/
|
||||
public gnuImplicitActivationPolicy(ImplicitActivationPolicyValue v)
|
||||
{
|
||||
super(IMPLICIT_ACTIVATION_POLICY_ID.value, v, v.value(),
|
||||
"IDL:org.omg/PortableServer/ImplicitActivationPolicy:1.0"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for the policy that was passed in a constructor.
|
||||
*/
|
||||
public ImplicitActivationPolicyValue value()
|
||||
{
|
||||
return (ImplicitActivationPolicyValue) getValue();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/* gnuLifespanPolicy.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA._PolicyImplBase;
|
||||
|
||||
import org.omg.PortableServer.LIFESPAN_POLICY_ID;
|
||||
import org.omg.PortableServer.LifespanPolicy;
|
||||
import org.omg.PortableServer.LifespanPolicyValue;
|
||||
|
||||
/**
|
||||
* The implementation of the life span policy.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuLifespanPolicy
|
||||
extends _PolicyImplBase
|
||||
implements LifespanPolicy, vPolicy
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Create the policy.
|
||||
*
|
||||
* @param v a value for the policy.
|
||||
*/
|
||||
public gnuLifespanPolicy(LifespanPolicyValue v)
|
||||
{
|
||||
super(LIFESPAN_POLICY_ID.value, v, v.value(),
|
||||
"IDL:org.omg/PortableServer/LifespanPolicy:1.0"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for the policy that was passed in a constructor.
|
||||
*/
|
||||
public LifespanPolicyValue value()
|
||||
{
|
||||
return (LifespanPolicyValue) getValue();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,225 @@
|
|||
/* gnuPOAManager.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.CORBA.Poa;
|
||||
|
||||
import org.omg.CORBA.BAD_INV_ORDER;
|
||||
import org.omg.CORBA.LocalObject;
|
||||
import org.omg.PortableServer.POAManager;
|
||||
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
|
||||
import org.omg.PortableServer.POAManagerPackage.State;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* The implementation of the POA manager. The manager is a controlled
|
||||
* switch that can change its states in response to the method calls
|
||||
* and throw exceptions if the requested change is invalid. It is possible
|
||||
* to check the state this switch. It does not do anything else.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuPOAManager
|
||||
extends LocalObject
|
||||
implements POAManager
|
||||
{
|
||||
/**
|
||||
* The POAs, controlled by this manager. The members must be instances of
|
||||
* the gnuAbstractPOA.
|
||||
*/
|
||||
HashSet POAs = new HashSet();
|
||||
|
||||
/**
|
||||
* The state of the manager. The newly created manager is always
|
||||
* in the holding state.
|
||||
*/
|
||||
State state = State.HOLDING;
|
||||
|
||||
/**
|
||||
* Get the state of the POA manager.
|
||||
*/
|
||||
public State get_state()
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the associated POAs into active state, allowing them to receive
|
||||
* and process requests.
|
||||
*
|
||||
* @throws if the POAs are in the inactive state. If once inactivated,
|
||||
* the POA cannot be activated again. This method can only be called
|
||||
* to leave the holding or discarding state.
|
||||
*/
|
||||
public void activate()
|
||||
throws AdapterInactive
|
||||
{
|
||||
if (state != State.INACTIVE)
|
||||
state = State.ACTIVE;
|
||||
else
|
||||
throw new AdapterInactive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the associated POAs into holding state. In this state, the POAs
|
||||
* queue incoming requests but do not process them.
|
||||
*
|
||||
* @param wait_for_completion if true, the method call suspends the current
|
||||
* thread till POAs complete the requests they are currently processing. If
|
||||
* false, the method returns immediately.
|
||||
|
||||
* @throws AdapterInactive if the POAs are in the inactive state.
|
||||
*/
|
||||
public void hold_requests(boolean wait_for_completion)
|
||||
throws AdapterInactive
|
||||
{
|
||||
if (state != State.INACTIVE)
|
||||
state = State.HOLDING;
|
||||
else
|
||||
throw new AdapterInactive();
|
||||
if (wait_for_completion)
|
||||
waitForIdle();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Turns the asociated POAs into inactive state. The POAs in the incative
|
||||
* state will reject new requests. If the POA is once inactivated, it
|
||||
* cannot be activated again. The operation is used when
|
||||
* the associated POAs are to be shut down.
|
||||
*
|
||||
* @param etherealize_objects if true, the servant managers of the
|
||||
* associated POAs, having RETAIN and USE_SERVANT_MANAGER policies,
|
||||
* will receive a call of {@link ServantActivatorOperations#etherealize}.
|
||||
*
|
||||
* @param wait_for_completion if true, the method call suspends the current
|
||||
* thread till POAs complete the requests they are currently processing. If
|
||||
* false, the method returns immediately.
|
||||
*
|
||||
* @throws AdapterInactive if the POAs are already in the inactive state.
|
||||
*
|
||||
* @see POAOperations#destroy
|
||||
*/
|
||||
public void deactivate(boolean etherealize_objects,
|
||||
boolean wait_for_completion
|
||||
)
|
||||
throws AdapterInactive
|
||||
{
|
||||
if (state == State.INACTIVE)
|
||||
throw new AdapterInactive("Repetetive inactivation");
|
||||
state = State.INACTIVE;
|
||||
if (wait_for_completion)
|
||||
waitForIdle();
|
||||
|
||||
Iterator iter = POAs.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
gnuPOA poa = (gnuPOA) iter.next();
|
||||
|
||||
// If the servant activator is non null, this means it has been
|
||||
// set - hence the policies are appropriate.
|
||||
if (poa.servant_activator != null)
|
||||
poa.etherealizeAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the associated POAs into discaring state. In this state, the POAs
|
||||
* discard the incoming requests. This mode is used in situations when
|
||||
* the server is flooded with requests. The client receives remote exception
|
||||
* ({@link org.omg.CORBA.TRANSIENT}, minor code 1).
|
||||
*
|
||||
* @param wait_for_completion if true, the method call suspends the current
|
||||
* thread till POAs complete the requests they are currently processing. If
|
||||
* false, the method returns immediately.
|
||||
|
||||
* @throws AdapterInactive if the POAs are in the inactive state.
|
||||
*/
|
||||
public void discard_requests(boolean wait_for_completion)
|
||||
throws AdapterInactive
|
||||
{
|
||||
if (state != State.INACTIVE)
|
||||
state = State.DISCARDING;
|
||||
else
|
||||
throw new AdapterInactive();
|
||||
if (wait_for_completion)
|
||||
waitForIdle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend the current thread while at least one of the associated POA is
|
||||
* actively processing some requests. The method assumes that the POAs
|
||||
* are not accepting the <i>new</i> requests due manager state.
|
||||
*
|
||||
* @throws BAD_INV_ORDER if the POAs are in the active state.
|
||||
*/
|
||||
public void waitForIdle()
|
||||
{
|
||||
if (state == State.ACTIVE)
|
||||
throw new BAD_INV_ORDER("The state is active");
|
||||
|
||||
Iterator iter = POAs.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
gnuPOA poa = (gnuPOA) iter.next();
|
||||
poa.waitWhileRunning();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the POA that will be controlled by this manager.
|
||||
*
|
||||
* @param poa the POA.
|
||||
*/
|
||||
public void addPoa(gnuPOA poa)
|
||||
{
|
||||
POAs.add(poa);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the POA, releasing it from the control of this manager.
|
||||
* Called in POA finaliser.
|
||||
*
|
||||
* @param poa the POA to remove.
|
||||
*/
|
||||
public void removePOA(gnuPOA poa)
|
||||
{
|
||||
POAs.remove(poa);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
/* gnuPoaCurrent.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.CORBA.Poa;
|
||||
|
||||
import org.omg.CORBA.CurrentHelper;
|
||||
import org.omg.CORBA.portable.ObjectImpl;
|
||||
import org.omg.PortableServer.Current;
|
||||
import org.omg.PortableServer.CurrentOperations;
|
||||
import org.omg.PortableServer.CurrentPackage.NoContext;
|
||||
import org.omg.PortableServer.POA;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* Supports the "Poa current" concept, providing the id and poa of
|
||||
* the object currently being served. There is only one instance
|
||||
* of this class per ORB. It maintains a thread to information map.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuPoaCurrent
|
||||
extends ObjectImpl
|
||||
implements Current
|
||||
{
|
||||
/**
|
||||
* The table, mapping threads to records.
|
||||
*/
|
||||
private TreeMap threads = new TreeMap();
|
||||
|
||||
/**
|
||||
* Get the array of POA current repository ids.
|
||||
*
|
||||
* @return a single member array, containing value, returned
|
||||
* by the {@link CurrentHelper#id}, normally
|
||||
* "IDL:omg.org/PortableServer/Current:2.3".
|
||||
*/
|
||||
public String[] _ids()
|
||||
{
|
||||
return new String[] { CurrentHelper.id() };
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object id, associated with the thread currently being served.
|
||||
*
|
||||
* @throws NoContext if the current thread is not associated with any
|
||||
* object.
|
||||
*/
|
||||
public byte[] get_object_id()
|
||||
throws NoContext
|
||||
{
|
||||
CurrentOperations r;
|
||||
synchronized (threads)
|
||||
{
|
||||
r = (CurrentOperations) threads.get(Thread.currentThread().getName());
|
||||
}
|
||||
if (r != null)
|
||||
return r.get_object_id();
|
||||
else
|
||||
throw new NoContext(Thread.currentThread().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object POA, associated with the thread currently being served.
|
||||
*
|
||||
* @throws NoContext if the current thread is not associated with any
|
||||
* object.
|
||||
*/
|
||||
public POA get_POA()
|
||||
throws NoContext
|
||||
{
|
||||
CurrentOperations r;
|
||||
synchronized (threads)
|
||||
{
|
||||
r = (CurrentOperations) threads.get(Thread.currentThread().getName());
|
||||
}
|
||||
if (r != null)
|
||||
return r.get_POA();
|
||||
else
|
||||
throw new NoContext(Thread.currentThread().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the entry to the map.
|
||||
*/
|
||||
public void put(Thread t, CurrentOperations record)
|
||||
{
|
||||
synchronized (threads)
|
||||
{
|
||||
threads.put(t.getName(), record);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this Poa has some running threads.
|
||||
*/
|
||||
public boolean has(POA poa)
|
||||
{
|
||||
synchronized (threads)
|
||||
{
|
||||
Iterator iter = threads.entrySet().iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
Map.Entry item = (Map.Entry) iter.next();
|
||||
try
|
||||
{
|
||||
if (((CurrentOperations) item.getValue()).get_POA() == poa)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (NoContext ex)
|
||||
{
|
||||
throw new InternalError();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this thread is registered.
|
||||
*/
|
||||
public boolean has(Thread t)
|
||||
{
|
||||
synchronized (threads)
|
||||
{
|
||||
return threads.containsKey(t.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the entry from the map.
|
||||
*/
|
||||
public void remove(Thread t)
|
||||
{
|
||||
synchronized (threads)
|
||||
{
|
||||
threads.remove(t.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/* gnuRequestProcessingPolicy.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA._PolicyImplBase;
|
||||
|
||||
import org.omg.PortableServer.REQUEST_PROCESSING_POLICY_ID;
|
||||
import org.omg.PortableServer.RequestProcessingPolicy;
|
||||
import org.omg.PortableServer.RequestProcessingPolicyValue;
|
||||
|
||||
/**
|
||||
* The implementation of the request processing policy.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuRequestProcessingPolicy
|
||||
extends _PolicyImplBase
|
||||
implements RequestProcessingPolicy, vPolicy
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Create the policy.
|
||||
*
|
||||
* @param v a value for the policy.
|
||||
*/
|
||||
public gnuRequestProcessingPolicy(RequestProcessingPolicyValue v)
|
||||
{
|
||||
super(REQUEST_PROCESSING_POLICY_ID.value, v, v.value(),
|
||||
"IDL:org.omg/PortableServer/RequestProcessingPolicy:1.0"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for the policy that was passed in a constructor.
|
||||
*/
|
||||
public RequestProcessingPolicyValue value()
|
||||
{
|
||||
return (RequestProcessingPolicyValue) getValue();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,802 @@
|
|||
/* gnuServantObject.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA.GIOP.ReplyHeader;
|
||||
import gnu.CORBA.IOR_Delegate;
|
||||
import gnu.CORBA.IOR_contructed_object;
|
||||
import gnu.CORBA.Interceptor.gnuServerRequestInfo;
|
||||
import gnu.CORBA.ObjectCreator;
|
||||
import gnu.CORBA.Unexpected;
|
||||
import gnu.CORBA.bufferedResponseHandler;
|
||||
import gnu.CORBA.recordTypeCode;
|
||||
import gnu.CORBA.streamReadyHolder;
|
||||
|
||||
import org.omg.CORBA.Any;
|
||||
import org.omg.CORBA.BAD_OPERATION;
|
||||
import org.omg.CORBA.BAD_PARAM;
|
||||
import org.omg.CORBA.CompletionStatus;
|
||||
import org.omg.CORBA.OBJECT_NOT_EXIST;
|
||||
import org.omg.CORBA.OBJ_ADAPTER;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.SystemException;
|
||||
import org.omg.CORBA.TCKind;
|
||||
import org.omg.CORBA.TRANSIENT;
|
||||
import org.omg.CORBA.UserException;
|
||||
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;
|
||||
import org.omg.PortableInterceptor.ForwardRequest;
|
||||
import org.omg.PortableInterceptor.ServerRequestInterceptorOperations;
|
||||
import org.omg.PortableServer.CurrentOperations;
|
||||
import org.omg.PortableServer.DynamicImplementation;
|
||||
import org.omg.PortableServer.ImplicitActivationPolicyValue;
|
||||
import org.omg.PortableServer.POA;
|
||||
import org.omg.PortableServer.POAManager;
|
||||
import org.omg.PortableServer.POAManagerPackage.State;
|
||||
import org.omg.PortableServer.Servant;
|
||||
import org.omg.PortableServer.ServantLocatorPackage.CookieHolder;
|
||||
import org.omg.PortableServer.ServantRetentionPolicyValue;
|
||||
import org.omg.PortableServer.portable.Delegate;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Represents a CORBA object, being locally served by the associated servant.
|
||||
* The calls to the object are forwarded to the calls to the servant.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuServantObject extends ObjectImpl
|
||||
implements org.omg.CORBA.Object,
|
||||
InvokeHandler,
|
||||
CurrentOperations
|
||||
{
|
||||
/**
|
||||
* The associated servant that must also implement the {@link InvokeHandler}
|
||||
* interface. This value can be temporary null if the object was created using
|
||||
* POA.create_reference or POA.create_reference_with_id, private to force
|
||||
* always to use {@link setServant}.
|
||||
*/
|
||||
private Servant servant;
|
||||
|
||||
/**
|
||||
* The Id of this object.
|
||||
*/
|
||||
public final byte[] Id;
|
||||
|
||||
/**
|
||||
* The poa that takes care about this object.
|
||||
*/
|
||||
public final gnuPOA poa;
|
||||
|
||||
/**
|
||||
* The POA manager, used to control the work of this object.
|
||||
*/
|
||||
public final POAManager manager;
|
||||
|
||||
/**
|
||||
* The orb.
|
||||
*/
|
||||
public final ORB_1_4 orb;
|
||||
|
||||
/**
|
||||
* The object repository ids, if they were specified separately. Normally, the
|
||||
* ids are requested from the servant.
|
||||
*/
|
||||
public final String[] repository_ids;
|
||||
|
||||
/**
|
||||
* Create an object with no connected servant. The servant must be set later.
|
||||
*
|
||||
* @param a_repository_ids an array of repository ids, can be null (then ids
|
||||
* will be requested from the servant).
|
||||
* @param an_id the object id.
|
||||
* @param a_poa the POA.
|
||||
*/
|
||||
public gnuServantObject(String[] a_repository_ids, byte[] an_id,
|
||||
gnuPOA a_poa, ORB_1_4 an_orb
|
||||
)
|
||||
{
|
||||
repository_ids = a_repository_ids;
|
||||
Id = an_id;
|
||||
manager = a_poa.the_POAManager();
|
||||
poa = a_poa;
|
||||
orb = an_orb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a servant object, associated with the passed servant.
|
||||
*
|
||||
* @param a_servant a servant, serving this object.
|
||||
* @param an_id an Object Id for this object.
|
||||
*
|
||||
* @throws BAD_PARAM if the passed servant is not an {@link InvokeHandler}.
|
||||
*/
|
||||
public gnuServantObject(Servant a_servant, byte[] an_id, ORB_1_4 an_orb,
|
||||
gnuPOA a_poa
|
||||
)
|
||||
{
|
||||
Id = an_id;
|
||||
setServant(a_servant);
|
||||
poa = a_poa;
|
||||
if (poa != null)
|
||||
{
|
||||
manager = poa.the_POAManager();
|
||||
}
|
||||
else
|
||||
{
|
||||
manager = null;
|
||||
}
|
||||
repository_ids = null;
|
||||
orb = an_orb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a servant, if it has not been previously set.
|
||||
*
|
||||
* @param a_servant a servant to set, can be null to indicate the necessity
|
||||
* for the subsequent activation.
|
||||
*
|
||||
* @throws BAD_PARAM if the passed servant is not an {@link InvokeHandler} or
|
||||
* {@link DynamicImplementation} and also not null.
|
||||
*/
|
||||
public void setServant(Servant a_servant)
|
||||
{
|
||||
if (a_servant != null &&
|
||||
!(a_servant instanceof InvokeHandler) &&
|
||||
!(a_servant instanceof DynamicImplementation)
|
||||
)
|
||||
{
|
||||
throw new BAD_PARAM("Must be either InvokeHandler or " +
|
||||
"DynamicImplementation, but is " + a_servant
|
||||
);
|
||||
}
|
||||
servant = a_servant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the associated servant.
|
||||
*/
|
||||
public Servant getServant()
|
||||
{
|
||||
return servant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the associated invocation handler.
|
||||
*/
|
||||
public InvokeHandler getHandler(String operation, CookieHolder cookie,
|
||||
boolean forwarding_allowed
|
||||
) throws gnuForwardRequest
|
||||
{
|
||||
if (servant != null)
|
||||
{
|
||||
return servantToHandler(servant);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use servant locator to locate the servant.
|
||||
if (poa.servant_locator != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
servant =
|
||||
poa.servant_locator.preinvoke(Id, poa, operation, cookie);
|
||||
return servantToHandler(servant);
|
||||
}
|
||||
catch (org.omg.PortableServer.ForwardRequest forw_ex)
|
||||
{
|
||||
if (forwarding_allowed)
|
||||
{
|
||||
throw new gnuForwardRequest(forw_ex.forward_reference);
|
||||
}
|
||||
else
|
||||
{
|
||||
servant =
|
||||
ForwardedServant.create(forw_ex.forward_reference);
|
||||
return servantToHandler(servant);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
// Use servant activator to locate the servant.
|
||||
if (poa.applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) &&
|
||||
poa.applies(ServantRetentionPolicyValue.RETAIN)
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
poa.activate_object_with_id(Id, servant, forwarding_allowed);
|
||||
servant = poa.id_to_servant(Id);
|
||||
return servantToHandler(servant);
|
||||
}
|
||||
catch (gnuForwardRequest forwarded)
|
||||
{
|
||||
throw forwarded;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
|
||||
BAD_OPERATION bad =
|
||||
new BAD_OPERATION("Unable to activate", 0x5004,
|
||||
CompletionStatus.COMPLETED_NO
|
||||
);
|
||||
bad.initCause(ex);
|
||||
throw bad;
|
||||
}
|
||||
}
|
||||
else if (poa.default_servant != null)
|
||||
{
|
||||
servant = poa.default_servant;
|
||||
return servantToHandler(servant);
|
||||
}
|
||||
|
||||
// No servant and no servant manager - throw exception.
|
||||
else
|
||||
{
|
||||
throw new BAD_OPERATION("Unable to activate", 0x5002,
|
||||
CompletionStatus.COMPLETED_NO
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the servant to invocation handler.
|
||||
*/
|
||||
public InvokeHandler servantToHandler(Servant a_servant)
|
||||
{
|
||||
if (a_servant instanceof InvokeHandler)
|
||||
{
|
||||
return (InvokeHandler) a_servant;
|
||||
}
|
||||
else if (a_servant instanceof DynamicImplementation)
|
||||
{
|
||||
return new dynImpHandler((DynamicImplementation) a_servant);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BAD_OPERATION(a_servant +
|
||||
" must be either InvokeHandler or " + "POA DynamicImplementation"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a servant object, associated with the passed servant. Requests the
|
||||
* object id from the servant. Depending on the policies of the servants POA,
|
||||
* the calls are eithe not synchronized or synchronized on POA or ORB.
|
||||
*
|
||||
* @param a_servant a servant, serving this object.
|
||||
* @param an_id an Object Id for this object.
|
||||
*/
|
||||
public gnuServantObject(Servant a_servant, gnuPOA a_poa)
|
||||
{
|
||||
this(a_servant, a_servant._object_id(), (ORB_1_4) a_servant._orb(), a_poa);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates call to servant, passing the poa and Id.
|
||||
*/
|
||||
public String[] _ids()
|
||||
{
|
||||
if (repository_ids == null)
|
||||
{
|
||||
return getServant()._all_interfaces(poa, Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
return repository_ids;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string representation.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer b = new StringBuffer("Servant object (");
|
||||
for (int i = 0; i < Id.length; i++)
|
||||
{
|
||||
b.append(Integer.toHexString(Id [ i ] & 0xFF));
|
||||
b.append(' ');
|
||||
}
|
||||
b.append(')');
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns true.
|
||||
*/
|
||||
public boolean _is_local()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this object could be named by the given repository id.
|
||||
*
|
||||
* @param idl_id the repository id to check.
|
||||
*
|
||||
* @return true if it is one of the possible repository ids of this object.
|
||||
*/
|
||||
public boolean _is_a(String idl_id)
|
||||
{
|
||||
String[] maybe = _ids();
|
||||
for (int i = 0; i < maybe.length; i++)
|
||||
{
|
||||
if (maybe [ i ].equals(idl_id))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an ORB, associated with the servant of this object.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ORB _orb()
|
||||
{
|
||||
return getServant()._orb();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the invocation (delegates to servant).
|
||||
*
|
||||
* @throws TRANSIENT minor 0x535503e9 if the POA is in discarding mode.
|
||||
* @throws OBJ_ADAPTER minor 0x535503ea if the POA is inactivated.
|
||||
* @throws OBJECT_NOT_EXISTS minor 0x535503ec if this object is inactivated.
|
||||
*
|
||||
* @specnote see {@link POAManagerOperations} for specnotes about the minor
|
||||
* codes.
|
||||
*/
|
||||
public OutputStream _invoke(String method, InputStream input,
|
||||
ResponseHandler r_handler
|
||||
) throws SystemException
|
||||
{
|
||||
boolean intercept = false;
|
||||
ServerRequestInterceptorOperations interceptor = null;
|
||||
gnuServerRequestInfo info = null;
|
||||
bufferedResponseHandler i_handler = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (orb.iServer != null &&
|
||||
r_handler instanceof bufferedResponseHandler
|
||||
)
|
||||
{
|
||||
interceptor = orb.iServer;
|
||||
|
||||
i_handler = (bufferedResponseHandler) r_handler;
|
||||
|
||||
info =
|
||||
new gnuServerRequestInfo(this, i_handler.request_header,
|
||||
i_handler.reply_header
|
||||
);
|
||||
intercept = true;
|
||||
|
||||
interceptor.receive_request_service_contexts(info);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CookieHolder cookie = null;
|
||||
activeObjectMap.Obj self = poa.aom.get(Id);
|
||||
|
||||
if (poa.servant_locator != null)
|
||||
{
|
||||
// If the servant locator is in use, it is always responsible
|
||||
// for providing the servant.
|
||||
self.servant = servant = null;
|
||||
cookie = new CookieHolder();
|
||||
}
|
||||
else if (self != null && self.isDeactiveted())
|
||||
{
|
||||
if (poa.applies(
|
||||
ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION
|
||||
) &&
|
||||
poa.servant_activator != null
|
||||
)
|
||||
{
|
||||
// Reset the servant, forcing the subsequent activation.
|
||||
servant = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new OBJECT_NOT_EXIST("Object deactivated",
|
||||
0x535503ec, CompletionStatus.COMPLETED_NO
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
InvokeHandler handler = getHandler(method, cookie, true);
|
||||
|
||||
Delegate d = null;
|
||||
|
||||
try
|
||||
{
|
||||
d = servant._get_delegate();
|
||||
orb.currents.put(Thread.currentThread(), this);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// In some cases exception is thrown if the delegate is not set.
|
||||
}
|
||||
if (d instanceof servantDelegate)
|
||||
{
|
||||
// If the delegate is already set, check maybe we can
|
||||
// reuse the existing instance.
|
||||
if (((servantDelegate) d).object != this)
|
||||
{
|
||||
servant._set_delegate(new servantDelegate(servant, poa, Id));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
servant._set_delegate(new servantDelegate(servant, poa, Id));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
switch (manager.get_state().value())
|
||||
{
|
||||
case State._ACTIVE :
|
||||
|
||||
OutputStream rt;
|
||||
try
|
||||
{
|
||||
if (intercept)
|
||||
{
|
||||
interceptor.receive_request(info);
|
||||
}
|
||||
|
||||
rt = handler._invoke(method, input, r_handler);
|
||||
|
||||
if (intercept)
|
||||
{
|
||||
// Handler is casted into i_handler.
|
||||
if (i_handler.isExceptionReply())
|
||||
{
|
||||
info.m_reply_header.reply_status =
|
||||
ReplyHeader.USER_EXCEPTION;
|
||||
|
||||
// Make Any, holding the user exception.
|
||||
Any a = orb.create_any();
|
||||
OutputStream buf = i_handler.getBuffer();
|
||||
InputStream in = buf.create_input_stream();
|
||||
String uex_idl = "unknown";
|
||||
try
|
||||
{
|
||||
in.mark(Integer.MAX_VALUE);
|
||||
uex_idl = in.read_string();
|
||||
in.reset();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new Unexpected(e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
UserException exception =
|
||||
ObjectCreator.readUserException(uex_idl,
|
||||
in
|
||||
);
|
||||
|
||||
ObjectCreator.insertWithHelper(a,
|
||||
exception
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Failed due any reason, insert without
|
||||
// helper.
|
||||
a.insert_Streamable(new streamReadyHolder(
|
||||
buf.create_input_stream()
|
||||
)
|
||||
);
|
||||
|
||||
recordTypeCode r =
|
||||
new recordTypeCode(TCKind.tk_except);
|
||||
r.setId(uex_idl);
|
||||
r.setName(ObjectCreator.getDefaultName(
|
||||
uex_idl
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
info.m_usr_exception = a;
|
||||
interceptor.send_exception(info);
|
||||
}
|
||||
else
|
||||
{
|
||||
info.m_reply_header.reply_status =
|
||||
ReplyHeader.NO_EXCEPTION;
|
||||
interceptor.send_reply(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SystemException sys_ex)
|
||||
{
|
||||
if (intercept)
|
||||
{
|
||||
info.m_reply_header.reply_status =
|
||||
ReplyHeader.SYSTEM_EXCEPTION;
|
||||
info.m_sys_exception = sys_ex;
|
||||
interceptor.send_exception(info);
|
||||
}
|
||||
throw sys_ex;
|
||||
}
|
||||
|
||||
return rt;
|
||||
|
||||
case State._HOLDING :
|
||||
|
||||
// The holding mode is implemented
|
||||
// relying on the holding capabilites of the network
|
||||
// support (if any).
|
||||
// TODO FIXME in more recent CORBA applications, the
|
||||
// client
|
||||
// ORB can free the connection and wait for a server side
|
||||
// notification about the completed request. Implement
|
||||
// this
|
||||
// as soon as JDK specification would allow bidirectional
|
||||
// policy.
|
||||
int sleep = 5;
|
||||
int max = 500;
|
||||
|
||||
// Wait till the state will be switched into some other
|
||||
// mode.
|
||||
while (manager.get_state().value() == State._HOLDING)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(sleep);
|
||||
if (sleep < max)
|
||||
{
|
||||
sleep = max;
|
||||
}
|
||||
}
|
||||
catch (InterruptedException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Handle another mode.
|
||||
return _invoke(method, input, r_handler);
|
||||
|
||||
case State._DISCARDING :
|
||||
throw new TRANSIENT("Discarding mode", 0x535503e9,
|
||||
CompletionStatus.COMPLETED_NO
|
||||
);
|
||||
|
||||
case State._INACTIVE :
|
||||
throw new OBJ_ADAPTER("POA deactivated", 0x535503ea,
|
||||
CompletionStatus.COMPLETED_NO
|
||||
);
|
||||
|
||||
default :
|
||||
throw new InternalError(); // No more states.
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (poa.servant_locator != null)
|
||||
{
|
||||
poa.servant_locator.postinvoke(Id, poa, method,
|
||||
cookie.value, servant
|
||||
);
|
||||
servant = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
orb.currents.remove(Thread.currentThread());
|
||||
}
|
||||
}
|
||||
catch (ForwardRequest fex)
|
||||
{
|
||||
// May be thrown by interceptor.
|
||||
if (intercept)
|
||||
{
|
||||
Forwarding:
|
||||
while (true)
|
||||
{
|
||||
info.m_reply_header.reply_status =
|
||||
ReplyHeader.LOCATION_FORWARD;
|
||||
info.m_forward_reference = fex.forward;
|
||||
try
|
||||
{
|
||||
interceptor.send_other(info);
|
||||
break Forwarding;
|
||||
}
|
||||
catch (ForwardRequest fex2)
|
||||
{
|
||||
info.m_forward_reference = fex2.forward;
|
||||
fex.forward = info.m_forward_reference;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new gnuForwardRequest(fex.forward);
|
||||
}
|
||||
catch (gnuForwardRequest fex)
|
||||
{
|
||||
// May be thrown during activation.
|
||||
if (intercept)
|
||||
{
|
||||
Forwarding:
|
||||
while (true)
|
||||
{
|
||||
info.m_reply_header.reply_status =
|
||||
ReplyHeader.LOCATION_FORWARD;
|
||||
info.m_forward_reference = fex.forward_reference;
|
||||
try
|
||||
{
|
||||
interceptor.send_other(info);
|
||||
break Forwarding;
|
||||
}
|
||||
catch (ForwardRequest fex2)
|
||||
{
|
||||
info.m_forward_reference = fex2.forward;
|
||||
fex.forward_reference = (ObjectImpl) fex2.forward;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw fex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare with another object for equality, comparing the object keys.
|
||||
*/
|
||||
public boolean equals(java.lang.Object other)
|
||||
{
|
||||
if (other instanceof gnuServantObject)
|
||||
{
|
||||
gnuServantObject o = (gnuServantObject) other;
|
||||
|
||||
return Arrays.equals(o.Id, Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hash code, based on the object key.
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
long s = 0;
|
||||
int v = 1;
|
||||
for (int i = 0; i < Id.length; i++)
|
||||
{
|
||||
s += Id [ i ] * v;
|
||||
if (s > Integer.MAX_VALUE)
|
||||
{
|
||||
s = s % Integer.MAX_VALUE;
|
||||
v = 1;
|
||||
}
|
||||
v = v * 8;
|
||||
}
|
||||
return (int) (s % Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object id.
|
||||
*/
|
||||
public byte[] get_object_id()
|
||||
{
|
||||
return Id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get POA.
|
||||
*/
|
||||
public POA get_POA()
|
||||
{
|
||||
return poa;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns without action.
|
||||
*/
|
||||
public void _release()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns without action.
|
||||
*/
|
||||
public void _releaseReply(InputStream stream)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this object is equivalent to another instance. These objects are
|
||||
* assumed equal if they are connected to the same orb and poa under the same
|
||||
* Id, regardless of they delegates.
|
||||
*
|
||||
* @param another instance to check.
|
||||
* @return
|
||||
*/
|
||||
public boolean _is_equivalent(org.omg.CORBA.Object other)
|
||||
{
|
||||
if (other instanceof gnuServantObject)
|
||||
{
|
||||
gnuServantObject g = (gnuServantObject) other;
|
||||
return orb == g.orb && poa == g.poa && Arrays.equals(Id, g.Id);
|
||||
}
|
||||
else if (other instanceof IOR_contructed_object)
|
||||
{
|
||||
IOR_contructed_object ir = ((IOR_contructed_object) other);
|
||||
try
|
||||
{
|
||||
IOR_Delegate ird = (IOR_Delegate) ir._get_delegate();
|
||||
byte[] ior_id = poa.idFormIor(ird.getIor().key);
|
||||
if (ior_id != null && Arrays.equals(ior_id, Id))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Non - typical delegate or very specific subclass of
|
||||
// IOR_constructed_object.
|
||||
return super._is_equivalent(other);
|
||||
}
|
||||
}
|
||||
return super._is_equivalent(other);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/* gnuServantRetentionPolicy.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA._PolicyImplBase;
|
||||
|
||||
import org.omg.PortableServer.SERVANT_RETENTION_POLICY_ID;
|
||||
import org.omg.PortableServer.ServantRetentionPolicy;
|
||||
import org.omg.PortableServer.ServantRetentionPolicyValue;
|
||||
|
||||
/**
|
||||
* The implementation of the servant retention policy.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuServantRetentionPolicy
|
||||
extends _PolicyImplBase
|
||||
implements ServantRetentionPolicy, vPolicy
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Create the policy.
|
||||
*
|
||||
* @param v a value for the policy.
|
||||
*/
|
||||
public gnuServantRetentionPolicy(ServantRetentionPolicyValue v)
|
||||
{
|
||||
super(SERVANT_RETENTION_POLICY_ID.value, v, v.value(),
|
||||
"IDL:org.omg/PortableServer/ServantRetentionPolicy:1.0"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for the policy that was passed in a constructor.
|
||||
*/
|
||||
public ServantRetentionPolicyValue value()
|
||||
{
|
||||
return (ServantRetentionPolicyValue) getValue();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/* gnuThreadPolicy.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA._PolicyImplBase;
|
||||
|
||||
import org.omg.PortableServer.THREAD_POLICY_ID;
|
||||
import org.omg.PortableServer.ThreadPolicy;
|
||||
import org.omg.PortableServer.ThreadPolicyValue;
|
||||
|
||||
/**
|
||||
* The implementation of the thread policy.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuThreadPolicy
|
||||
extends _PolicyImplBase
|
||||
implements ThreadPolicy, vPolicy
|
||||
{
|
||||
/**
|
||||
* Use serialVersionUID for interoperability.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Create the policy.
|
||||
*
|
||||
* @param v a value for the policy.
|
||||
*/
|
||||
public gnuThreadPolicy(ThreadPolicyValue v)
|
||||
{
|
||||
super(THREAD_POLICY_ID.value, v, v.value(),
|
||||
"IDL:org.omg/PortableServer/ThreadPolicy:1.0"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for the policy that was passed in a constructor.
|
||||
*/
|
||||
public ThreadPolicyValue value()
|
||||
{
|
||||
return (ThreadPolicyValue) getValue();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
/* policySets.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.CORBA.Poa;
|
||||
|
||||
import org.omg.CORBA.Policy;
|
||||
import org.omg.PortableServer.IdAssignmentPolicyValue;
|
||||
import org.omg.PortableServer.IdUniquenessPolicyValue;
|
||||
import org.omg.PortableServer.ImplicitActivationPolicyValue;
|
||||
import org.omg.PortableServer.LifespanPolicyValue;
|
||||
import org.omg.PortableServer.RequestProcessingPolicyValue;
|
||||
import org.omg.PortableServer.ServantRetentionPolicyValue;
|
||||
import org.omg.PortableServer.ThreadPolicyValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Contains the frequently uset POA policy sets. The policy
|
||||
* arrays are package private for security reasons, the cloned
|
||||
* copies are returned.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class policySets
|
||||
{
|
||||
/**
|
||||
* The default policy set, as defined in OMG specs. This is also
|
||||
* the policy set for the root POA.
|
||||
*/
|
||||
private static final vPolicy[] rootPOASet =
|
||||
new vPolicy[]
|
||||
{
|
||||
new gnuThreadPolicy(ThreadPolicyValue.ORB_CTRL_MODEL),
|
||||
new gnuLifespanPolicy(LifespanPolicyValue.TRANSIENT),
|
||||
new gnuIdUniquenessPolicy(IdUniquenessPolicyValue.UNIQUE_ID),
|
||||
new gnuIdAssignmentPolicy(IdAssignmentPolicyValue.SYSTEM_ID),
|
||||
new gnuServantRetentionPolicy(ServantRetentionPolicyValue.RETAIN),
|
||||
new gnuRequestProcessingPolicy(RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY),
|
||||
new gnuImplicitActivationPolicy(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the policy set, applicable for the root POA, as defined
|
||||
* in OMG specs.
|
||||
*/
|
||||
public static Policy[] rootPoa()
|
||||
{
|
||||
Policy[] p = new Policy[ rootPOASet.length ];
|
||||
System.arraycopy(rootPOASet, 0, p, 0, p.length);
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the potentially incomplete policy array into array, containing
|
||||
* the complete policy set.
|
||||
*
|
||||
* @param policies the policy list, may be incomplete (even zero size).
|
||||
*
|
||||
* @return the complete policy array. The missing, but needed policies
|
||||
* are added with they default values.
|
||||
*/
|
||||
public static Policy[] withDefault(Policy[] policies)
|
||||
{
|
||||
ArrayList current = new ArrayList(rootPOASet.length);
|
||||
Policy p_default;
|
||||
boolean specified;
|
||||
|
||||
for (int i = 0; i < rootPOASet.length; i++)
|
||||
{
|
||||
p_default = rootPOASet [ i ];
|
||||
specified = false;
|
||||
ForThis:
|
||||
for (int j = 0; j < policies.length; j++)
|
||||
{
|
||||
if (policies [ j ].policy_type() == p_default.policy_type())
|
||||
{
|
||||
specified = true;
|
||||
current.add(policies [ j ]);
|
||||
break ForThis;
|
||||
}
|
||||
}
|
||||
if (!specified)
|
||||
current.add(p_default.copy());
|
||||
}
|
||||
|
||||
Policy[] complete = new Policy[ current.size() ];
|
||||
for (int i = 0; i < complete.length; i++)
|
||||
{
|
||||
complete [ i ] = (Policy) current.get(i);
|
||||
}
|
||||
return complete;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,232 @@
|
|||
/* servantDelegate.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.CORBA.Poa;
|
||||
|
||||
import gnu.CORBA.Unexpected;
|
||||
|
||||
import org.omg.CORBA.NO_IMPLEMENT;
|
||||
import org.omg.CORBA.ORB;
|
||||
import org.omg.CORBA.ORBPackage.InvalidName;
|
||||
import org.omg.CORBA.Object;
|
||||
import org.omg.PortableServer.CurrentPackage.NoContext;
|
||||
import org.omg.PortableServer.POA;
|
||||
import org.omg.PortableServer.POAHelper;
|
||||
import org.omg.PortableServer.Servant;
|
||||
import org.omg.PortableServer.portable.Delegate;
|
||||
|
||||
/**
|
||||
* The implementation of the servant delegate for the locally existing
|
||||
* servant.The associated servant that must also implement the
|
||||
* {@link InvokeHandler} interface. Each servant requires a separate
|
||||
* instance of this delegate and can serve a single object only.
|
||||
* Hence the fields are final, but the delegate is typically reused
|
||||
* unless the same servant is connected to different objects.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class servantDelegate
|
||||
implements Delegate
|
||||
{
|
||||
/**
|
||||
* The servant, associated with this object.
|
||||
*/
|
||||
final Servant servant;
|
||||
|
||||
/**
|
||||
* The servant (not object) id.
|
||||
*/
|
||||
final byte[] servant_id;
|
||||
|
||||
/**
|
||||
* The POA, where the servant is connected.
|
||||
*/
|
||||
final gnuPOA poa;
|
||||
|
||||
/**
|
||||
* The object, exposed as an object, served by this servant.
|
||||
*/
|
||||
final gnuServantObject object;
|
||||
|
||||
/**
|
||||
* Create the delegat for the servant that will be connected to the
|
||||
* given poa. The method is normally called from inside of gnuPOA.
|
||||
* The constructor sets the newly created delegate as the delegate to this
|
||||
* servant by calling Servant._set_delegate.
|
||||
*
|
||||
* @param a_poa the poa.
|
||||
* @param a_servant the servant.
|
||||
* @param a_servant_id the servant id.
|
||||
*/
|
||||
public servantDelegate(Servant a_servant, gnuPOA a_poa, byte[] a_servant_id)
|
||||
{
|
||||
poa = a_poa;
|
||||
servant = a_servant;
|
||||
servant_id = a_servant_id;
|
||||
servant._set_delegate(this);
|
||||
object =
|
||||
new gnuServantObject(servant, servant_id, (ORB_1_4) servant._orb(), a_poa);
|
||||
object._set_delegate(new LocalDelegate(object, poa, a_servant_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this object could be named by the given repository id.
|
||||
* @param idl_id the repository id to check.
|
||||
*
|
||||
* @return true if it is one of the possible repository ids of this
|
||||
* object.
|
||||
*/
|
||||
public boolean is_a(Servant a_servant, String idl_id)
|
||||
{
|
||||
same(a_servant);
|
||||
|
||||
String[] maybe = object.repository_ids;
|
||||
if (maybe == null)
|
||||
maybe = servant._all_interfaces(poa, object.Id);
|
||||
for (int i = 0; i < maybe.length; i++)
|
||||
{
|
||||
if (maybe [ i ].equals(idl_id))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ORB's default POA.
|
||||
*/
|
||||
public POA default_POA(Servant a_servant)
|
||||
{
|
||||
same(a_servant);
|
||||
try
|
||||
{
|
||||
return POAHelper.narrow(orb(a_servant).resolve_initial_references("RootPOA"));
|
||||
}
|
||||
catch (InvalidName ex)
|
||||
{
|
||||
throw new Unexpected(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ORB.
|
||||
*/
|
||||
public ORB orb(Servant a_servant)
|
||||
{
|
||||
same(a_servant);
|
||||
return poa.orb();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object, exposing the servant.
|
||||
*/
|
||||
public Object this_object(Servant a_servant)
|
||||
{
|
||||
same(a_servant);
|
||||
try
|
||||
{
|
||||
return poa.aom.get(poa.m_orb.currents.get_object_id()).object;
|
||||
}
|
||||
catch (NoContext ex)
|
||||
{
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported.
|
||||
*
|
||||
* @specnote Same as for Sun up till 1.5 inclusive.
|
||||
*/
|
||||
public Object get_interface_def(Servant a_servant)
|
||||
{
|
||||
same(a_servant);
|
||||
throw new NO_IMPLEMENT();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Id of the object being currently served.
|
||||
*/
|
||||
public byte[] object_id(Servant a_servant)
|
||||
{
|
||||
same(a_servant);
|
||||
try
|
||||
{
|
||||
byte[] id = poa.m_orb.currents.get_object_id();
|
||||
return id;
|
||||
}
|
||||
catch (NoContext ex)
|
||||
{
|
||||
return object.Id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns false;
|
||||
*/
|
||||
public boolean non_existent(Servant a_servant)
|
||||
{
|
||||
same(a_servant);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the associated POA.
|
||||
*/
|
||||
public POA poa(Servant a_servant)
|
||||
{
|
||||
same(a_servant);
|
||||
try
|
||||
{
|
||||
return poa.m_orb.currents.get_POA();
|
||||
}
|
||||
catch (NoContext ex)
|
||||
{
|
||||
return poa;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the passed servant is the same as the servant, associated with
|
||||
* this delegate. This class requires a single servant per delegate.
|
||||
*/
|
||||
void same(Servant some_servant)
|
||||
{
|
||||
if (servant != some_servant)
|
||||
throw new InternalError("Only one servant per delegate is supported.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/* vPolicy.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.CORBA.Poa;
|
||||
|
||||
import org.omg.CORBA.Policy;
|
||||
|
||||
/**
|
||||
* The Classpath implementation of the policy, providing the policy
|
||||
* value and the code of the policy type.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public interface vPolicy
|
||||
extends Policy
|
||||
{
|
||||
/**
|
||||
* Get the value of this policy
|
||||
*/
|
||||
java.lang.Object getValue();
|
||||
|
||||
/**
|
||||
* Get the integer code of this policy value.
|
||||
*/
|
||||
int getCode();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
/* gnuValueHolder.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.CORBA;
|
||||
|
||||
import gnu.CORBA.CDR.Vio;
|
||||
|
||||
import org.omg.CORBA.TypeCode;
|
||||
import org.omg.CORBA.ValueBaseHolder;
|
||||
import org.omg.CORBA.portable.BoxedValueHelper;
|
||||
import org.omg.CORBA.portable.InputStream;
|
||||
import org.omg.CORBA.portable.OutputStream;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Boxed value holder that also remembers the value type and the value helper.
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class gnuValueHolder
|
||||
extends ValueBaseHolder
|
||||
{
|
||||
/**
|
||||
* The type code of the stored value.
|
||||
*/
|
||||
TypeCode type;
|
||||
|
||||
/**
|
||||
* The helper that could read and write fields of the boxed value.
|
||||
*/
|
||||
transient BoxedValueHelper helper;
|
||||
|
||||
/**
|
||||
* If true, the helper not available.
|
||||
*/
|
||||
transient boolean helper_NA;
|
||||
|
||||
/**
|
||||
* Create a new instance for the given value and given type.
|
||||
*/
|
||||
public gnuValueHolder(Serializable value, TypeCode a_type)
|
||||
{
|
||||
super(value);
|
||||
type = a_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the true type, as it was passed in the constructor.
|
||||
*/
|
||||
public TypeCode _type()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write content to the output stream. Tries to locate the
|
||||
* corresponding helper class.
|
||||
*/
|
||||
public void _write(OutputStream output)
|
||||
{
|
||||
findHelper();
|
||||
if (helper == null)
|
||||
super._write(output);
|
||||
else
|
||||
Vio.write(output, value, helper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read, trying to locate helper, if possible.
|
||||
*/
|
||||
public void _read(InputStream input)
|
||||
{
|
||||
findHelper();
|
||||
if (helper == null)
|
||||
super._read(input);
|
||||
else
|
||||
value = Vio.read(input, helper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the read and write methods.
|
||||
*/
|
||||
void findHelper()
|
||||
{
|
||||
if (helper != null || helper_NA)
|
||||
return;
|
||||
try
|
||||
{
|
||||
Class helperClass =
|
||||
Class.forName(ObjectCreator.toHelperName(type.id()));
|
||||
|
||||
helper = (BoxedValueHelper) helperClass.newInstance();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
helper_NA = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/* Pointer.java -- Pointer to VM specific data
|
||||
Copyright (C) 1999, 2000, 2004 Free Software Foundation
|
||||
|
||||
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. */
|
||||
|
||||
/* This file is originally part of libgcj. */
|
||||
|
||||
package gnu.classpath;
|
||||
|
||||
/** A type used to indicate special data used by native code that should not
|
||||
be marked by the garbage collector. */
|
||||
|
||||
public abstract class Pointer
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/* Pointer32.java -- 32 bit Pointer
|
||||
Copyright (C) 2004 Free Software Foundation
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* A type used to indicate special data used by native code that should not
|
||||
* be marked by the garbage collector.
|
||||
*/
|
||||
public final class Pointer32 extends Pointer
|
||||
{
|
||||
final int data;
|
||||
|
||||
public Pointer32(int data)
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/* Pointer64.java -- 64 bit Pointer
|
||||
Copyright (C) 2004 Free Software Foundation
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* A type used to indicate special data used by native code that should not
|
||||
* be marked by the garbage collector.
|
||||
*/
|
||||
public final class Pointer64 extends Pointer
|
||||
{
|
||||
final long data;
|
||||
|
||||
public Pointer64(long data)
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,302 @@
|
|||
/* Jdwp.java -- Virtual machine to JDWP back-end programming interface
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp;
|
||||
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.event.EventManager;
|
||||
import gnu.classpath.jdwp.event.EventRequest;
|
||||
import gnu.classpath.jdwp.id.ThreadId;
|
||||
import gnu.classpath.jdwp.processor.PacketProcessor;
|
||||
import gnu.classpath.jdwp.transport.ITransport;
|
||||
import gnu.classpath.jdwp.transport.JdwpConnection;
|
||||
import gnu.classpath.jdwp.transport.TransportException;
|
||||
import gnu.classpath.jdwp.transport.TransportFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.AccessController;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Main interface from the virtual machine to the JDWP back-end.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class Jdwp
|
||||
extends Thread
|
||||
{
|
||||
// The single instance of the back-end
|
||||
private static Jdwp _instance = null;
|
||||
|
||||
/**
|
||||
* Are we debugging?
|
||||
*/
|
||||
public static boolean isDebugging = false;
|
||||
|
||||
// Packet processor
|
||||
private PacketProcessor _packetProcessor;
|
||||
private Thread _ppThread;
|
||||
|
||||
// JDWP configuration properties
|
||||
private HashMap _properties;
|
||||
|
||||
// The suspend property of the configure string
|
||||
// (-Xrunjdwp:..suspend=<boolean>)
|
||||
private static final String _PROPERTY_SUSPEND = "suspend";
|
||||
|
||||
// User's main application thread
|
||||
private Thread _mainThread;
|
||||
|
||||
// Connection to debugger
|
||||
private JdwpConnection _connection;
|
||||
|
||||
// Are we shutting down the current session?
|
||||
private boolean _shutdown;
|
||||
|
||||
// A thread group for the JDWP threads
|
||||
private ThreadGroup _group;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
public Jdwp ()
|
||||
{
|
||||
_shutdown = false;
|
||||
isDebugging = true;
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JDWP back-end, creating an instance of it
|
||||
* if one does not already exist.
|
||||
*/
|
||||
public static Jdwp getDefault ()
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the virtual machine suspend on startup?
|
||||
*/
|
||||
public static boolean suspendOnStartup ()
|
||||
{
|
||||
Jdwp jdwp = getDefault ();
|
||||
if (jdwp != null)
|
||||
{
|
||||
String suspend = (String) jdwp._properties.get (_PROPERTY_SUSPEND);
|
||||
if (suspend != null && suspend.equals ("y"))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the back-end
|
||||
*
|
||||
* @param configArgs a string of configury options
|
||||
* @param mainThread the main application thread
|
||||
*/
|
||||
public void configure (String configArgs, Thread mainThread)
|
||||
{
|
||||
_mainThread = mainThread;
|
||||
_processConfigury (configArgs);
|
||||
}
|
||||
|
||||
// A helper function to initialize the transport layer
|
||||
private void _doInitialization ()
|
||||
throws TransportException
|
||||
{
|
||||
_group = new ThreadGroup ("JDWP threads");
|
||||
// initialize transport
|
||||
ITransport transport = TransportFactory.newInstance (_properties);
|
||||
_connection = new JdwpConnection (_group, transport);
|
||||
_connection.initialize ();
|
||||
_connection.start ();
|
||||
|
||||
// Create processor
|
||||
_packetProcessor = new PacketProcessor (_connection);
|
||||
_ppThread = new Thread (_group, new Runnable ()
|
||||
{
|
||||
public void run ()
|
||||
{
|
||||
AccessController.doPrivileged (_packetProcessor);
|
||||
}
|
||||
});
|
||||
_ppThread.start ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the JDWP back-end
|
||||
*
|
||||
* NOTE: This does not quite work properly. See notes in
|
||||
* run() on this subject (catch of InterruptedException).
|
||||
*/
|
||||
public void shutdown ()
|
||||
{
|
||||
if (!_shutdown)
|
||||
{
|
||||
_packetProcessor.shutdown ();
|
||||
_ppThread.interrupt ();
|
||||
_connection.shutdown ();
|
||||
_shutdown = true;
|
||||
isDebugging = false;
|
||||
|
||||
/* FIXME: probably need to check state of user's
|
||||
program -- if it is suspended, we need to either
|
||||
resume or kill them. */
|
||||
|
||||
interrupt ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the debugger of an event. This method should not
|
||||
* be called if debugging is not active (but it would not
|
||||
* cause any harm). Places where event notifications occur
|
||||
* should check isDebugging before doing anything.
|
||||
*
|
||||
* The event is filtered through the event manager before being
|
||||
* sent.
|
||||
*
|
||||
* FIXME: Probably need logic to send multiple events
|
||||
* @param event the event to report
|
||||
*/
|
||||
public static void notify (Event event)
|
||||
{
|
||||
Jdwp jdwp = getDefault ();
|
||||
if (jdwp != null)
|
||||
{
|
||||
EventManager em = EventManager.getDefault ();
|
||||
EventRequest request = em.getEventRequest (event);
|
||||
if (request != null)
|
||||
sendEvent (request, event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the event to the debugger.
|
||||
*
|
||||
* This method bypasses the event manager's filtering.
|
||||
*
|
||||
* @param request the debugger request for the event
|
||||
* @param event the event to send
|
||||
*/
|
||||
public static void sendEvent (EventRequest request, Event event)
|
||||
{
|
||||
Jdwp jdwp = getDefault ();
|
||||
if (jdwp != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// !! May need to implement send queue?
|
||||
synchronized (jdwp._connection)
|
||||
{
|
||||
jdwp._connection.sendEvent (request, event);
|
||||
}
|
||||
|
||||
// Follow suspend policy
|
||||
jdwp._enforceSuspendPolicy (request.getSuspendPolicy ());
|
||||
}
|
||||
catch (IOException ie)
|
||||
{
|
||||
System.out.println ("Jdwp.notify: caught exception: " + ie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to enforce suspend policies on event notification
|
||||
private void _enforceSuspendPolicy (byte suspendPolicy)
|
||||
{
|
||||
switch (suspendPolicy)
|
||||
{
|
||||
case EventRequest.SUSPEND_NONE:
|
||||
// do nothing
|
||||
break;
|
||||
|
||||
case EventRequest.SUSPEND_THREAD:
|
||||
VMVirtualMachine.suspendThread (this);
|
||||
break;
|
||||
|
||||
case EventRequest.SUSPEND_ALL:
|
||||
VMVirtualMachine.suspendAllThreads ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void run ()
|
||||
{
|
||||
try
|
||||
{
|
||||
_doInitialization ();
|
||||
|
||||
_mainThread.start ();
|
||||
|
||||
_mainThread.join ();
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
/* Shutting down. If we're in server mode, we should
|
||||
prepare for a new connection. Otherwise, we should
|
||||
simply exit. */
|
||||
// FIXME
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
System.out.println ("Exception in JDWP back-end: " + t);
|
||||
System.exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
// A helper function to process the configure string "-Xrunjdwp:..."
|
||||
private void _processConfigury (String configString)
|
||||
{
|
||||
// Loop through configuration arguments looking for a
|
||||
// transport name
|
||||
_properties = new HashMap ();
|
||||
String[] options = configString.split (",");
|
||||
for (int i = 0; i < options.length; ++i)
|
||||
{
|
||||
String[] property = options[i].split ("=");
|
||||
if (property.length == 2)
|
||||
_properties.put (property[0], property[1]);
|
||||
// ignore malformed options
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,901 @@
|
|||
/* JdwpConstants.java -- Constants defined by JDWP 1.4 specification
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp;
|
||||
|
||||
/**
|
||||
* Constants defined by JDWP specification.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class JdwpConstants
|
||||
{
|
||||
public static final class Version
|
||||
{
|
||||
public static final int MAJOR = 1;
|
||||
public static final int MINOR = 4;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Commands/Sets //
|
||||
////////////////////////////////////////
|
||||
|
||||
public static final class CommandSet
|
||||
{
|
||||
public static final class VirtualMachine
|
||||
{
|
||||
public static final byte CS_VALUE = 1;
|
||||
|
||||
// commands
|
||||
public static final byte VERSION = 1;
|
||||
public static final byte CLASSES_BY_SIGNATURE = 2;
|
||||
public static final byte ALL_CLASSES = 3;
|
||||
public static final byte ALL_THREADS = 4;
|
||||
public static final byte TOP_LEVEL_THREAD_GROUPS = 5;
|
||||
public static final byte DISPOSE = 6;
|
||||
public static final byte IDSIZES = 7;
|
||||
public static final byte SUSPEND = 8;
|
||||
public static final byte RESUME = 9;
|
||||
public static final byte EXIT = 10;
|
||||
public static final byte CREATE_STRING = 11;
|
||||
public static final byte CAPABILITIES = 12;
|
||||
public static final byte CLASS_PATHS = 13;
|
||||
public static final byte DISPOSE_OBJECTS = 14;
|
||||
public static final byte HOLD_EVENTS = 15;
|
||||
public static final byte RELEASE_EVENTS = 16;
|
||||
public static final byte CAPABILITIES_NEW = 17;
|
||||
public static final byte REDEFINE_CLASSES = 18;
|
||||
public static final byte SET_DEFAULT_STRATUM = 19;
|
||||
public static final byte ALL_CLASSES_WITH_GENERIC = 20;
|
||||
}
|
||||
|
||||
public static final class ReferenceType
|
||||
{
|
||||
public static final byte CS_VALUE = 2;
|
||||
|
||||
// commands
|
||||
public static final byte SIGNATURE= 1;
|
||||
public static final byte CLASS_LOADER= 2;
|
||||
public static final byte MODIFIERS = 3;
|
||||
public static final byte FIELDS = 4;
|
||||
public static final byte METHODS = 5;
|
||||
public static final byte GET_VALUES = 6;
|
||||
public static final byte SOURCE_FILE = 7;
|
||||
public static final byte NESTED_TYPES = 8;
|
||||
public static final byte STATUS = 9;
|
||||
public static final byte INTERFACES= 10;
|
||||
public static final byte CLASS_OBJECT = 11;
|
||||
public static final byte SOURCE_DEBUG_EXTENSION = 12;
|
||||
public static final byte SIGNATURE_WITH_GENERIC = 13;
|
||||
public static final byte FIELDS_WITH_GENERIC = 14;
|
||||
public static final byte METHODS_WITH_GENERIC = 15;
|
||||
}
|
||||
|
||||
public static final class ClassType
|
||||
{
|
||||
public static final byte CS_VALUE = 3;
|
||||
|
||||
// commands
|
||||
public static final byte SUPERCLASS = 1;
|
||||
public static final byte SET_VALUES = 2;
|
||||
public static final byte INVOKE_METHOD = 3;
|
||||
public static final byte NEW_INSTANCE = 4;
|
||||
}
|
||||
|
||||
public static final class ArrayType
|
||||
{
|
||||
public static final byte CS_VALUE = 4;
|
||||
|
||||
// commands
|
||||
public static final byte NEW_INSTANCE = 1;
|
||||
}
|
||||
|
||||
public static final class InterfaceType
|
||||
{
|
||||
public static final byte CS_VALUE = 5;
|
||||
|
||||
// commands
|
||||
}
|
||||
|
||||
public static final class Method
|
||||
{
|
||||
public static final byte CS_VALUE = 6;
|
||||
|
||||
// commands
|
||||
public static final byte LINE_TABLE = 1;
|
||||
public static final byte VARIABLE_TABLE = 2;
|
||||
public static final byte BYTE_CODES = 3;
|
||||
public static final byte IS_OBSOLETE = 4;
|
||||
public static final byte VARIABLE_TABLE_WITH_GENERIC = 5;
|
||||
}
|
||||
|
||||
public static final class Field
|
||||
{
|
||||
public static final byte CS_VALUE = 8;
|
||||
|
||||
// commands
|
||||
}
|
||||
|
||||
public static final class ObjectReference
|
||||
{
|
||||
public static final byte CS_VALUE = 9;
|
||||
|
||||
// commands
|
||||
public static final byte REFERENCE_TYPE = 1;
|
||||
public static final byte GET_VALUES = 2;
|
||||
public static final byte SET_VALUES = 3;
|
||||
public static final byte MONITOR_INFO = 5;
|
||||
public static final byte INVOKE_METHOD = 6;
|
||||
public static final byte DISABLE_COLLECTION = 7;
|
||||
public static final byte ENABLE_COLLECTION = 8;
|
||||
public static final byte IS_COLLECTED = 9;
|
||||
}
|
||||
|
||||
public static final class StringReference
|
||||
{
|
||||
public static final byte CS_VALUE = 10;
|
||||
|
||||
// commands
|
||||
public static final byte VALUE = 1;
|
||||
}
|
||||
|
||||
public static final class ThreadReference
|
||||
{
|
||||
public static final byte CS_VALUE = 11;
|
||||
|
||||
// commands
|
||||
public static final byte NAME = 1;
|
||||
public static final byte SUSPEND = 2;
|
||||
public static final byte RESUME = 3;
|
||||
public static final byte STATUS = 4;
|
||||
public static final byte THREAD_GROUP = 5;
|
||||
public static final byte FRAMES = 6;
|
||||
public static final byte FRAME_COUNT = 7;
|
||||
public static final byte OWNED_MONITORS = 8;
|
||||
public static final byte CURRENT_CONTENDED_MONITOR = 9;
|
||||
public static final byte STOP = 10;
|
||||
public static final byte INTERRUPT = 11;
|
||||
public static final byte SUSPEND_COUNT = 12;
|
||||
}
|
||||
|
||||
public static final class ThreadGroupReference
|
||||
{
|
||||
public static final byte CS_VALUE = 12;
|
||||
|
||||
// commands
|
||||
public static final byte NAME = 1;
|
||||
public static final byte PARENT = 2;
|
||||
public static final byte CHILDREN = 3;
|
||||
}
|
||||
|
||||
public static final class ArrayReference
|
||||
{
|
||||
public static final byte CS_VALUE = 13;
|
||||
|
||||
// commands
|
||||
public static final byte LENGTH = 1;
|
||||
public static final byte GET_VALUES = 2;
|
||||
public static final byte SET_VALUES = 3;
|
||||
}
|
||||
|
||||
public static final class ClassLoaderReference
|
||||
{
|
||||
public static final byte CS_VALUE = 14;
|
||||
|
||||
// commands
|
||||
public static final byte VISIBLE_CLASSES = 1;
|
||||
}
|
||||
|
||||
public static final class EventRequest
|
||||
{
|
||||
public static final byte CS_VALUE = 15;
|
||||
|
||||
// commands
|
||||
public static final byte SET = 1;
|
||||
public static final byte CLEAR = 2;
|
||||
public static final byte CLEAR_ALL_BREAKPOINTS = 3;
|
||||
}
|
||||
|
||||
public static final class StackFrame
|
||||
{
|
||||
public static final byte CS_VALUE = 16;
|
||||
|
||||
// commands
|
||||
public static final byte GET_VALUES = 1;
|
||||
public static final byte SET_VALUES = 2;
|
||||
public static final byte THIS_OBJECT = 3;
|
||||
public static final byte POP_FRAMES = 4;
|
||||
}
|
||||
|
||||
public static final class ClassObjectReference
|
||||
{
|
||||
public static final byte CS_VALUE = 17;
|
||||
|
||||
// commands
|
||||
public static final byte REFLECTED_TYPE = 1;
|
||||
}
|
||||
|
||||
public static final int MAXIMUM = ClassObjectReference.CS_VALUE;
|
||||
|
||||
public static final class Event
|
||||
{
|
||||
public static final byte CS_VALUE = 64;
|
||||
|
||||
// commands
|
||||
public static final byte COMPOSITE = 100;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Constants //
|
||||
////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* Error constants
|
||||
*/
|
||||
public static final class Error
|
||||
{
|
||||
/**
|
||||
* No error has occurred
|
||||
*/
|
||||
public static final short NONE = 0;
|
||||
|
||||
/**
|
||||
* Passed thread is null, is not a valid thread or has exited
|
||||
*/
|
||||
public static final short INVALID_THREAD = 10;
|
||||
|
||||
/**
|
||||
* Thread group invalid
|
||||
*/
|
||||
public static final short INVALID_THREAD_GROUP = 11;
|
||||
|
||||
/**
|
||||
* Invalid priority
|
||||
*/
|
||||
public static final short INVALID_PRIORITY = 12;
|
||||
|
||||
/**
|
||||
* Specified thread has not been suspended by an event
|
||||
*/
|
||||
public static final short THREAD_NOT_SUSPENDED = 13;
|
||||
|
||||
/**
|
||||
* Thread already suspended
|
||||
*/
|
||||
public static final short THREAD_SUSPENDED = 14;
|
||||
|
||||
/**
|
||||
* Reference type has been unloaded and garbage collected
|
||||
*/
|
||||
public static final short INVALID_OBJECT = 20;
|
||||
|
||||
/**
|
||||
* Invalid class
|
||||
*/
|
||||
public static final short INVALID_CLASS = 21;
|
||||
|
||||
/**
|
||||
* Class has been loaded but not yet prepared
|
||||
*/
|
||||
public static final short CLASS_NOT_PREPARED = 22;
|
||||
|
||||
/**
|
||||
* Invalid method
|
||||
*/
|
||||
public static final short INVALID_METHODID = 23;
|
||||
|
||||
/**
|
||||
* Invalid location
|
||||
*/
|
||||
public static final short INVALID_LOCATION = 24;
|
||||
|
||||
/**
|
||||
* Invalid field
|
||||
*/
|
||||
public static final short INVALID_FIELDID = 25;
|
||||
|
||||
/**
|
||||
* Invaliid frame
|
||||
*/
|
||||
public static final short INVALID_FRAMEID = 30;
|
||||
|
||||
/**
|
||||
* There are no more Java or JNI frames on the call stack
|
||||
*/
|
||||
public static final short NO_MORE_FRAMES = 31;
|
||||
|
||||
/**
|
||||
* Information about the frame is not available
|
||||
*/
|
||||
public static final short OPAQUE_FRAME = 32;
|
||||
|
||||
/**
|
||||
* Operation can only be performed on current frame
|
||||
*/
|
||||
public static final short NOT_CURRENT_FRAME = 33;
|
||||
|
||||
/**
|
||||
* Variable is not an appropriate type for the function used
|
||||
*/
|
||||
public static final short TYPE_MISMATCH = 34;
|
||||
|
||||
/**
|
||||
* Invalid slot
|
||||
*/
|
||||
public static final short INVALID_SLOT = 35;
|
||||
|
||||
/**
|
||||
* Item already set
|
||||
*/
|
||||
public static final short DUPLICATE = 40;
|
||||
|
||||
/**
|
||||
* Desired element not found
|
||||
*/
|
||||
public static final short NOT_FOUND = 41;
|
||||
|
||||
/**
|
||||
* Invalid monitor
|
||||
*/
|
||||
public static final short INVALID_MONITOR = 50;
|
||||
|
||||
/**
|
||||
* Thread doesn't own the monitor
|
||||
*/
|
||||
public static final short NOT_MONITOR_OWNER = 51;
|
||||
|
||||
/**
|
||||
* Call has been interrupted before completion
|
||||
*/
|
||||
public static final short INTERRUPT = 52;
|
||||
|
||||
/**
|
||||
* Virtual machine attempted to read a class file and determined that
|
||||
* the file is malformed or otherwise cannot be interpreted as a class
|
||||
* file
|
||||
*/
|
||||
public static final short INVALID_CLASS_FORMAT = 60;
|
||||
|
||||
/**
|
||||
* Circularity has been detected while initializing a class
|
||||
*/
|
||||
public static final short CIRCULAR_CLASS_DEFINITION = 61;
|
||||
|
||||
/**
|
||||
* Verifier detected that a class file, though well formed, contained
|
||||
* some sort of internal inconsistency or security problem
|
||||
*/
|
||||
public static final short FAILS_VERIFICATION = 62;
|
||||
|
||||
/**
|
||||
* Adding methods has not been implemented
|
||||
*/
|
||||
public static final short ADD_METHOD_NOT_IMPLEMENTED = 63;
|
||||
|
||||
/**
|
||||
* Schema change has not been implemented
|
||||
*/
|
||||
public static final short SCHEMA_CHANGE_NOT_IMPLEMENTED = 64;
|
||||
|
||||
/**
|
||||
* State of the thread has been modified and is now inconsistent
|
||||
*/
|
||||
public static final short INVALID_TYPESTATE = 65;
|
||||
|
||||
/**
|
||||
* A direct superclass is different for the new class version, or the set
|
||||
* of directly implemented interfaces is different and
|
||||
* <code>canUnrestrictedlyRedefineClasses</code> is false
|
||||
*/
|
||||
public static final short HIERARCHY_CHANGE_NOT_IMPLEMENTED = 66;
|
||||
|
||||
/**
|
||||
* New class version does not declare a method declared in the old
|
||||
* class version and <code>canUnrestrictedlyRedefineClasses</code>
|
||||
* is false
|
||||
*/
|
||||
public static final short DELETE_METHOD_NOT_IMPLEMENTED = 67;
|
||||
|
||||
/**
|
||||
* Class file has a version number not supported by this VM
|
||||
*/
|
||||
public static final short UNSUPPORTED_VERSION = 68;
|
||||
|
||||
/**
|
||||
* Class name defined in the new class file is different from the name
|
||||
* in the old class object
|
||||
*/
|
||||
public static final short NAMES_DONT_MATCH = 69;
|
||||
|
||||
/**
|
||||
* New class version has different modifiers and
|
||||
* <code>canUnrestrictedlyRedefineClasses</code> is false
|
||||
*/
|
||||
public static final short CLASS_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 70;
|
||||
|
||||
/**
|
||||
* A method in the new class version has different modifiers than its
|
||||
* counterpart in the old class version and
|
||||
* <code>canUnrestrictedlyRedefineClasses</code> is false.
|
||||
*/
|
||||
public static final short METHOD_MODIFIERS_CHANGE_NOT_IMPLEMENTED = 71;
|
||||
|
||||
/**
|
||||
* Functionality is not implemented in this virtual machine
|
||||
*/
|
||||
public static final short NOT_IMPLEMENTED = 99;
|
||||
|
||||
/**
|
||||
* Invalid pointer
|
||||
*/
|
||||
public static final short NULL_POINTER = 100;
|
||||
|
||||
/**
|
||||
* Desired information is not available
|
||||
*/
|
||||
public static final short ABSENT_INFORMATION = 101;
|
||||
|
||||
/**
|
||||
* Specified event type id is not recognized
|
||||
*/
|
||||
public static final short INVALID_EVENT_TYPE = 102;
|
||||
|
||||
/**
|
||||
* Illegal argument
|
||||
*/
|
||||
public static final short ILLEGAL_ARGUMENT = 103;
|
||||
|
||||
/**
|
||||
* The function needed to allocate memory and no more memory was
|
||||
* available for allocation
|
||||
*/
|
||||
public static final short OUT_OF_MEMORY = 110;
|
||||
|
||||
/**
|
||||
* Debugging has not been enabled in this virtual machine. JVMDI cannot
|
||||
* be used
|
||||
*/
|
||||
public static final short ACCESS_DENIED = 111;
|
||||
|
||||
/**
|
||||
* The virtual machine is not running
|
||||
*/
|
||||
public static final short VM_DEAD = 112;
|
||||
|
||||
/**
|
||||
* An unexpected internal error has occurred
|
||||
*/
|
||||
public static final short INTERNAL = 113;
|
||||
|
||||
/**
|
||||
* The thread being used to call this function is not attached to the
|
||||
* virtual machine. Calls must be made from attached threads.
|
||||
*/
|
||||
public static final short UNATTACHED_THREAD = 115;
|
||||
|
||||
/**
|
||||
* Invalid object type id or class tag
|
||||
*/
|
||||
public static final short INVALID_TAG = 500;
|
||||
|
||||
/**
|
||||
* Previous invoke not complete
|
||||
*/
|
||||
public static final short ALREADY_INVOKING = 502;
|
||||
|
||||
/**
|
||||
* Invalid index
|
||||
*/
|
||||
public static final short INVALID_INDEX = 503;
|
||||
|
||||
/**
|
||||
* Invalid length
|
||||
*/
|
||||
public static final short INVALID_LENGTH = 504;
|
||||
|
||||
/**
|
||||
* Invalid string
|
||||
*/
|
||||
public static final short INVALID_STRING = 506;
|
||||
|
||||
/**
|
||||
* Invalid class loader
|
||||
*/
|
||||
public static final short INVALID_CLASS_LOADER = 507;
|
||||
|
||||
/**
|
||||
* Invalid array
|
||||
*/
|
||||
public static final short INVALID_ARRAY = 508;
|
||||
|
||||
/**
|
||||
* Unable to load the transport
|
||||
*/
|
||||
public static final short TRANSPORT_LOAD = 509;
|
||||
|
||||
/**
|
||||
* Unablie to initialize the transport
|
||||
*/
|
||||
public static final short TRANSPORT_INIT = 510;
|
||||
|
||||
/**
|
||||
* Method is native
|
||||
*/
|
||||
public static final short NATIVE_METHOD = 511;
|
||||
|
||||
/**
|
||||
* Invalid count
|
||||
*/
|
||||
public static final short INVALID_COUNT = 512;
|
||||
}
|
||||
|
||||
/*
|
||||
* EventKind constants
|
||||
*/
|
||||
public static final class EventKind
|
||||
{
|
||||
public static final byte SINGLE_STEP = 1;
|
||||
public static final byte BREAKPOINT = 2;
|
||||
public static final byte FRAME_POP = 3;
|
||||
public static final byte EXCEPTION = 4;
|
||||
public static final byte USER_DEFINED = 5;
|
||||
public static final byte THREAD_START = 6;
|
||||
public static final byte THREAD_END = 7;
|
||||
public static final byte CLASS_PREPARE = 8;
|
||||
public static final byte CLASS_UNLOAD = 9;
|
||||
public static final byte CLASS_LOAD = 10;
|
||||
public static final byte FIELD_ACCESS = 20;
|
||||
public static final byte FIELD_MODIFICATION = 21;
|
||||
public static final byte EXCEPTION_CATCH = 30;
|
||||
public static final byte METHOD_ENTRY = 40;
|
||||
public static final byte METHOD_EXIT = 41;
|
||||
public static final byte VM_INIT = 90;
|
||||
public static final byte VM_DEATH = 99;
|
||||
public static final byte VM_DISCONNECTED = 100;
|
||||
|
||||
public static final byte VM_START = VM_INIT;
|
||||
public static final byte THREAD_DEATH = THREAD_END;
|
||||
}
|
||||
|
||||
/*
|
||||
* ModKind constants (event filters)
|
||||
*/
|
||||
public static final class ModKind
|
||||
{
|
||||
/**
|
||||
* Limit the requested event to be reported at most once after a
|
||||
* given number of occurrences. May be used with any event.
|
||||
*/
|
||||
public static final byte COUNT = 1;
|
||||
|
||||
/**
|
||||
* Conditional on expression
|
||||
*/
|
||||
public static final byte CONDITIONAL = 2;
|
||||
|
||||
/**
|
||||
* Restricts reported events to those in the given thread.
|
||||
* May be used with any event except for class unload.
|
||||
*/
|
||||
public static final byte THREAD_ONLY = 3;
|
||||
|
||||
/**
|
||||
* For class prepare events, restricts generated events
|
||||
* to be the preparation of the given reference type and any
|
||||
* subtypes.
|
||||
*
|
||||
* For other events, restricts the generated events to those where
|
||||
* location is in the given reference type or any of its subtypes.
|
||||
*
|
||||
* An event will be generated for any location in a reference type
|
||||
* that can be safely cast to the given reference type.
|
||||
*
|
||||
* May be used with any event except class unload, thread start,
|
||||
* and thread end.
|
||||
*/
|
||||
public static final byte CLASS_ONLY = 4;
|
||||
|
||||
/**
|
||||
* Restricts reported events to those for classes whose name matches
|
||||
* the given restricted regular expression.
|
||||
*
|
||||
* For class prepare events, the prepared class name is matched.
|
||||
* For class unload events, the unloaded class name is matched.
|
||||
* For other events, the class name of the event's location is matched.
|
||||
*
|
||||
* May be used with any event except thread start and thread end.
|
||||
*/
|
||||
public static final byte CLASS_MATCH = 5;
|
||||
|
||||
/**
|
||||
* Restricts reported events to those for classes whose name does not
|
||||
* match the given restricted regular expression.
|
||||
*
|
||||
* For class prepare events, the prepared class name is matched.
|
||||
* For class unload events, the unloaded class name is matched.
|
||||
* For other events, the class name of the event's location is matched.
|
||||
*
|
||||
* May be used with any event except thread start and thread end.
|
||||
*/
|
||||
public static final byte CLASS_EXCLUDE = 6;
|
||||
|
||||
/**
|
||||
* Restricts reported events to those that occur at the given location.
|
||||
*
|
||||
* May be used with breakpoint, field access, field modification, step,
|
||||
* and exception event kinds.
|
||||
*/
|
||||
public static final byte LOCATION_ONLY = 7;
|
||||
|
||||
/**
|
||||
* Restricts reported exceptions by their class and whether they are
|
||||
* caught or uncaught.
|
||||
*
|
||||
* May be used with exception event kinds only.
|
||||
*/
|
||||
public static final byte EXCEPTION_ONLY = 8;
|
||||
|
||||
/**
|
||||
* Restricts reported events to those that occur for a given field.
|
||||
*
|
||||
* May be used with field access and field modification event kinds only.
|
||||
*/
|
||||
public static final byte FIELD_ONLY = 9;
|
||||
|
||||
/**
|
||||
* Restricts reported step events to those which satisfy depth and
|
||||
* size constraints.
|
||||
*
|
||||
* May be used with step event kinds only.
|
||||
*/
|
||||
public static final byte STEP = 10;
|
||||
|
||||
/**
|
||||
* Restricts reported events to those whose active 'this' object is
|
||||
* the given object. Match value is the null object for static methods.
|
||||
*
|
||||
* May be used with any event except class prepare, class unload,
|
||||
* thread start, and thread end.
|
||||
*/
|
||||
public static final byte INSTANCE_ONLY = 11;
|
||||
}
|
||||
|
||||
/*
|
||||
* ThreadStatus constants
|
||||
*/
|
||||
public static final class ThreadStatus
|
||||
{
|
||||
public static final int ZOMBIE = 0;
|
||||
public static final int RUNNING = 1;
|
||||
public static final int SLEEPING = 2;
|
||||
public static final int MONITOR = 3;
|
||||
public static final int WAIT = 4;
|
||||
}
|
||||
|
||||
/*
|
||||
* SuspendStatus constants
|
||||
*/
|
||||
public static final class SuspendStatus
|
||||
{
|
||||
public static final byte SUSPENDED = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* ClassStatus constants
|
||||
*/
|
||||
public static final class ClassStatus
|
||||
{
|
||||
public static final int VERIFIED = 1;
|
||||
public static final int PREPARED = 2;
|
||||
public static final int INITIALIZED = 4;
|
||||
public static final int ERROR = 8;
|
||||
}
|
||||
|
||||
/*
|
||||
* TypeTag constants
|
||||
*/
|
||||
public static final class TypeTag
|
||||
{
|
||||
public static final byte CLASS = 1;
|
||||
public static final byte INTERFACE = 2;
|
||||
public static final byte ARRAY = 3;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tag constants
|
||||
*/
|
||||
public static final class Tag
|
||||
{
|
||||
/**
|
||||
* Array object (objectID size)
|
||||
*/
|
||||
public static final byte ARRAY = '[';
|
||||
|
||||
/**
|
||||
* Byte value (1 byte)
|
||||
*/
|
||||
public static final byte BYTE = 'B';
|
||||
|
||||
/**
|
||||
* Character value (2 bytes)
|
||||
*/
|
||||
public static final byte CHAR = 'C';
|
||||
|
||||
/**
|
||||
* Object (objectID size)
|
||||
*/
|
||||
public static final byte OBJECT = 'L';
|
||||
|
||||
/**
|
||||
* Float value (4 bytes)
|
||||
*/
|
||||
public static final byte FLOAT = 'F';
|
||||
|
||||
/**
|
||||
* Double value (8 bytes)
|
||||
*/
|
||||
public static final byte DOUBLE = 'D';
|
||||
|
||||
/**
|
||||
* Int value (4 bytes)
|
||||
*/
|
||||
public static final byte INT = 'I';
|
||||
|
||||
/**
|
||||
* Long value (8 bytes)
|
||||
*/
|
||||
public static final byte LONG = 'J';
|
||||
|
||||
/**
|
||||
* Short value (2 bytes)
|
||||
*/
|
||||
public static final byte SHORT = 'S';
|
||||
|
||||
/**
|
||||
* Void value (no bytes)
|
||||
*/
|
||||
public static final byte VOID = 'V';
|
||||
|
||||
/**
|
||||
* Boolean value (1 byte)
|
||||
*/
|
||||
public static final byte BOOLEAN = 'Z';
|
||||
|
||||
/**
|
||||
* String object (objectID size)
|
||||
*/
|
||||
public static final byte STRING = 's';
|
||||
|
||||
/**
|
||||
* Thread object (objectID size)
|
||||
*/
|
||||
public static final byte THREAD = 't';
|
||||
|
||||
/**
|
||||
* ThreadGroup object (objectID size)
|
||||
*/
|
||||
public static final byte THREAD_GROUP = 'g';
|
||||
|
||||
/**
|
||||
* ClassLoader object (objectID size)
|
||||
*/
|
||||
public static final byte CLASS_LOADER = 'l';
|
||||
|
||||
/**
|
||||
* Class object object (objectID size)
|
||||
*/
|
||||
public static final byte CLASS_OBJECT = 'c';
|
||||
}
|
||||
|
||||
/*
|
||||
* StepDepth constants
|
||||
*/
|
||||
public static final class StepDepth
|
||||
{
|
||||
/**
|
||||
* Step into any method calls that occur before the end of the step
|
||||
*/
|
||||
public static final int INTO = 0;
|
||||
|
||||
/**
|
||||
* Step over any method calls that occur before the end of the step
|
||||
*/
|
||||
public static final int OVER = 1;
|
||||
|
||||
/**
|
||||
* Step out of the current method
|
||||
*/
|
||||
public static final int OUT = 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* StepSize constants
|
||||
*/
|
||||
public static final class StepSize
|
||||
{
|
||||
/**
|
||||
* Step by the minimum possible amount (often a bytecode instruction)
|
||||
*/
|
||||
public static final int MIN = 0;
|
||||
|
||||
/**
|
||||
* Step to the next source line unless there is no line number information,
|
||||
* in which case MIN step is done instead
|
||||
*/
|
||||
public static final int LINE = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* SuspendPolicy constants
|
||||
*/
|
||||
public static final class SuspendPolicy
|
||||
{
|
||||
/**
|
||||
* Suspend no threads when this event is encountered
|
||||
*/
|
||||
public static final byte NONE = 0;
|
||||
|
||||
/**
|
||||
* Suspend the event thread when this event is encountered
|
||||
*/
|
||||
public static final byte EVENT_THREAD = 1;
|
||||
|
||||
/**
|
||||
* Suspend all threads when this event is encountered
|
||||
*/
|
||||
public static final byte ALL = 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* InvokeOptions flag constants
|
||||
*/
|
||||
public static final class InvokeOptions
|
||||
{
|
||||
/**
|
||||
* otherwise, all threads started
|
||||
*/
|
||||
public static final int INVOKE_SINGLE_THREADED = 0x1;
|
||||
|
||||
/**
|
||||
* otherwise, normal virtual invoke (instance methods only)
|
||||
*/
|
||||
public static final int INVOKE_NONVIRTUAL = 0x2;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
/* ClassPrepareEvent.java -- An event specifying that a class has been
|
||||
prepared by the virtual machine
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.VMIdManager;
|
||||
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
||||
import gnu.classpath.jdwp.id.ThreadId;
|
||||
import gnu.classpath.jdwp.util.JdwpString;
|
||||
import gnu.classpath.jdwp.util.Signature;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* "Notification of a class prepare in the target VM. See the JVM
|
||||
* specification for a definition of class preparation. Class prepare
|
||||
* events are not generated for primtiive classes (for example,
|
||||
* <code>java.lang.Integer.TYPE</code>)." -- JDWP 1.4.2
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class ClassPrepareEvent
|
||||
extends Event
|
||||
{
|
||||
// The thread in which this event occurred
|
||||
private Thread _thread;
|
||||
|
||||
// The class that was prepared
|
||||
private Class _class;
|
||||
|
||||
// Prepare flags
|
||||
private int _status;
|
||||
|
||||
/**
|
||||
* Class has been verified
|
||||
*/
|
||||
public static final int STATUS_VERIFIED
|
||||
= JdwpConstants.ClassStatus.VERIFIED;
|
||||
|
||||
/**
|
||||
* Class has been prepared
|
||||
*/
|
||||
public static final int STATUS_PREPARED
|
||||
= JdwpConstants.ClassStatus.PREPARED;
|
||||
|
||||
/**
|
||||
* Class has been initialized
|
||||
*/
|
||||
public static final int STATUS_INITIALIZED
|
||||
= JdwpConstants.ClassStatus.INITIALIZED;
|
||||
|
||||
/**
|
||||
* Error preparing class
|
||||
*/
|
||||
public static final int STATUS_ERROR
|
||||
= JdwpConstants.ClassStatus.ERROR;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ClassPrepareEvent</code>
|
||||
*
|
||||
* @param thread thread in which event occurred
|
||||
* @param clazz class which was prepared
|
||||
* @param flags prepare status flags
|
||||
*/
|
||||
public ClassPrepareEvent (Thread thread, Class clazz, int flags)
|
||||
{
|
||||
super (JdwpConstants.EventKind.CLASS_PREPARE);
|
||||
_thread = thread;
|
||||
_class = clazz;
|
||||
_status = flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specific filtering parameter for this event.
|
||||
* Valid types are thread and class.
|
||||
*
|
||||
* @param type the type of parameter desired
|
||||
* @returns the desired parameter or <code>null</code>
|
||||
*/
|
||||
public Object getParameter (Class type)
|
||||
{
|
||||
if (type == ThreadId.class)
|
||||
return _thread;
|
||||
else if (type == ReferenceTypeId.class)
|
||||
return _class;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the event to the given stream
|
||||
*
|
||||
* @param outStream the output stream to write the event to
|
||||
*/
|
||||
protected void _writeData (DataOutputStream outStream)
|
||||
throws IOException
|
||||
{
|
||||
VMIdManager idm = VMIdManager.getDefault();
|
||||
ThreadId tid = (ThreadId) idm.getObjectId (_thread);
|
||||
ReferenceTypeId rid = idm.getReferenceTypeId (_class);
|
||||
|
||||
tid.write (outStream);
|
||||
rid.writeTagged (outStream);
|
||||
JdwpString.writeString (outStream,
|
||||
Signature.computeClassSignature (_class));
|
||||
outStream.writeInt (_status);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
/* Event.java -- a base class for all event types
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.transport.JdwpCommandPacket;
|
||||
import gnu.classpath.jdwp.transport.JdwpPacket;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This class is a base class for all VM->debugger event
|
||||
* notifications.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public abstract class Event
|
||||
{
|
||||
// The kind of event represented by this event
|
||||
private byte _eventKind;
|
||||
|
||||
/**
|
||||
* Constructs an <code>Event</code> of the given kind
|
||||
*
|
||||
* @param kind the type of event
|
||||
*/
|
||||
public Event (byte kind)
|
||||
{
|
||||
_eventKind = kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the event type of this event
|
||||
*
|
||||
* @returns the event kind
|
||||
*/
|
||||
public byte getEventKind ()
|
||||
{
|
||||
return _eventKind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract function used by implementing classes to fill in the
|
||||
* event-specific data. Note that request ID is automatically added
|
||||
* by this class (since it appears in all event notifications).
|
||||
*
|
||||
* @param outStream the stream to which to write data
|
||||
*/
|
||||
protected abstract void _writeData (DataOutputStream outStream)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns a specific filtering parameter for this event. For example,
|
||||
* most events may be filtered by thread. Consequently, a call to this
|
||||
* method with <code>ThreadId.class</code> should return a
|
||||
* <code>Thread</code>.
|
||||
*
|
||||
* @param type the type of parameter to return
|
||||
* @returns the parameter (not the ID) or <code>null</code> if none is
|
||||
* is defined for this event
|
||||
*/
|
||||
public abstract Object getParameter (Class type);
|
||||
|
||||
/**
|
||||
* Converts this event into to a JDWP packet
|
||||
*
|
||||
* @param dos the stream to which to write data
|
||||
* @param request the request the wanted this notification
|
||||
* @returns a <code>JdwpPacket</code> of the events
|
||||
*/
|
||||
public JdwpPacket toPacket (DataOutputStream dos, EventRequest request)
|
||||
{
|
||||
JdwpPacket pkt;
|
||||
try
|
||||
{
|
||||
dos.writeByte (request.getSuspendPolicy ());
|
||||
dos.writeInt (1);
|
||||
dos.writeByte (_eventKind);
|
||||
dos.writeInt (request.getId ());
|
||||
_writeData (dos);
|
||||
|
||||
pkt = new JdwpCommandPacket (JdwpConstants.CommandSet.Event.CS_VALUE,
|
||||
JdwpConstants.CommandSet.Event.COMPOSITE);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
pkt = null;
|
||||
}
|
||||
|
||||
return pkt;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,293 @@
|
|||
/* EventManager.java -- event management and notification infrastructure
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event;
|
||||
|
||||
import gnu.classpath.jdwp.VMVirtualMachine;
|
||||
import gnu.classpath.jdwp.exception.InvalidEventTypeException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Manages event requests and filters event notifications.
|
||||
*
|
||||
* The purpose of this class is actually two-fold:
|
||||
*
|
||||
* 1) Maintain a list of event requests from the debugger
|
||||
* 2) Filter event notifications from the VM
|
||||
*
|
||||
* If an event request arrives from the debugger, the back-end will
|
||||
* call {@link #reqestEvent}, which will first check for a valid event.
|
||||
* If it is valid, <code>EventManager</code> will record the request
|
||||
* internally and register the event with the virtual machine, which may
|
||||
* choose to handle the request itself (as is likely the case with
|
||||
* breakpoints and other execution-related events), or it may decide to
|
||||
* allow the <code>EventManager</code> to handle notifications and all
|
||||
* filtering (which is convenient for other events such as class (un)loading).
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class EventManager
|
||||
{
|
||||
// Single instance
|
||||
private static EventManager _instance = new EventManager ();
|
||||
|
||||
// maps event (EVENT_*) to lists of EventRequests
|
||||
private Hashtable _requests = null;
|
||||
|
||||
/**
|
||||
* Returns an instance of the event manager
|
||||
*
|
||||
* @return the event manager
|
||||
*/
|
||||
public static EventManager getDefault ()
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
// Private constructs a new <code>EventManager</code>
|
||||
private EventManager ()
|
||||
{
|
||||
_requests = new Hashtable ();
|
||||
|
||||
// Add lists for all the event types
|
||||
_requests.put (new Byte (EventRequest.EVENT_SINGLE_STEP),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_BREAKPOINT),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_FRAME_POP),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_EXCEPTION),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_USER_DEFINED),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_THREAD_START),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_THREAD_END),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_CLASS_PREPARE),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_CLASS_UNLOAD),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_CLASS_LOAD),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_FIELD_ACCESS),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_FIELD_MODIFY),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_METHOD_ENTRY),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_METHOD_EXIT),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_VM_INIT),
|
||||
new Hashtable ());
|
||||
_requests.put (new Byte (EventRequest.EVENT_VM_DEATH),
|
||||
new Hashtable ());
|
||||
|
||||
// Add auto-generated event notifications
|
||||
// only two: VM_INIT, VM_DEATH
|
||||
try
|
||||
{
|
||||
requestEvent (new EventRequest (0,
|
||||
EventRequest.EVENT_VM_INIT,
|
||||
EventRequest.SUSPEND_NONE));
|
||||
requestEvent (new EventRequest (0,
|
||||
EventRequest.EVENT_VM_DEATH,
|
||||
EventRequest.SUSPEND_NONE));
|
||||
}
|
||||
catch (InvalidEventTypeException e)
|
||||
{
|
||||
// This can't happen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a request for the given event. This method will only
|
||||
* be used if the <code>EventManager</code> is handling event filtering.
|
||||
*
|
||||
* @param event the event
|
||||
* @return request that was interested in this event
|
||||
* or <code>null</code> if none (and event should not be sent)
|
||||
* @throws IllegalArgumentException for invalid event kind
|
||||
*/
|
||||
public EventRequest getEventRequest (Event event)
|
||||
{
|
||||
EventRequest interestedRequest = null;
|
||||
Hashtable requests;
|
||||
Byte kind = new Byte (event.getEventKind ());
|
||||
requests = (Hashtable) _requests.get (kind);
|
||||
if (requests == null)
|
||||
{
|
||||
// Did not get a valid event type
|
||||
throw new IllegalArgumentException ("invalid event kind: " + kind);
|
||||
}
|
||||
boolean match = false;
|
||||
|
||||
// Loop through the requests. Must look at ALL requests in order
|
||||
// to evaluate all filters (think count filter).
|
||||
// TODO: What if multiple matches? Spec isn't so clear on this.
|
||||
Iterator rIter = requests.values().iterator ();
|
||||
while (rIter.hasNext ())
|
||||
{
|
||||
EventRequest request = (EventRequest) rIter.next ();
|
||||
if (request.matches (event))
|
||||
interestedRequest = request;
|
||||
}
|
||||
|
||||
return interestedRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests monitoring of an event.
|
||||
*
|
||||
* The debugger registers for event notification through
|
||||
* an event filter. If no event filter is specified for an event
|
||||
* in the VM, it is assumed that the debugger is not interested in
|
||||
* receiving notifications of this event.
|
||||
*
|
||||
* The virtual machine will be notified of the request.
|
||||
*
|
||||
* @param request the request to monitor
|
||||
* @throws InvalidEventTypeException for invalid event kind
|
||||
*/
|
||||
public void requestEvent (EventRequest request)
|
||||
throws InvalidEventTypeException
|
||||
{
|
||||
// Add request to request list
|
||||
Hashtable requests;
|
||||
Byte kind = new Byte (request.getEventKind ());
|
||||
requests = (Hashtable) _requests.get (kind);
|
||||
if (requests == null)
|
||||
{
|
||||
// Did not get a valid event type
|
||||
throw new InvalidEventTypeException (request.getEventKind ());
|
||||
}
|
||||
|
||||
// Register the event with the VM
|
||||
VMVirtualMachine.registerEvent (request);
|
||||
requests.put (new Integer (request.getId ()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given request from the management table
|
||||
*
|
||||
* @param kind the event kind
|
||||
* @param id the ID of the request to delete
|
||||
* @throws IllegalArgumentException for invalid event kind
|
||||
*/
|
||||
public void deleteRequest (byte kind, int id)
|
||||
{
|
||||
Hashtable requests;
|
||||
requests = (Hashtable) _requests.get (new Byte (kind));
|
||||
if (requests == null)
|
||||
{
|
||||
// Did not get a valid event type
|
||||
throw new IllegalArgumentException ("invalid event kind: " + kind);
|
||||
}
|
||||
|
||||
Integer iid = new Integer (id);
|
||||
EventRequest request = (EventRequest) requests.get (iid);
|
||||
if (request != null)
|
||||
{
|
||||
VMVirtualMachine.unregisterEvent (request);
|
||||
requests.remove (iid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all the requests for a given event
|
||||
*
|
||||
* @param kind the event kind
|
||||
* @throws IllegalArgumentException for invalid event kind
|
||||
*/
|
||||
public void clearRequests (byte kind)
|
||||
{
|
||||
Hashtable requests = (Hashtable) _requests.get (new Byte (kind));
|
||||
if (requests == null)
|
||||
{
|
||||
// Did not get a valid event type
|
||||
throw new IllegalArgumentException ("invalid event kind: " + kind);
|
||||
}
|
||||
|
||||
VMVirtualMachine.clearEvents (kind);
|
||||
requests.clear ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a given event request for an event
|
||||
*
|
||||
* @param kind the kind of event for the request
|
||||
* @param id the integer request id to return
|
||||
* @return the request for the given event kind with the given id
|
||||
* (or <code>null</code> if not found)
|
||||
* @throws IllegalArgumentException for invalid event kind
|
||||
*/
|
||||
public EventRequest getRequest (byte kind, int id)
|
||||
{
|
||||
Hashtable requests = (Hashtable) _requests.get (new Byte (kind));
|
||||
if (requests == null)
|
||||
{
|
||||
// Did not get a valid event type
|
||||
throw new IllegalArgumentException ("invalid event kind: " + kind);
|
||||
}
|
||||
|
||||
return (EventRequest) requests.get (new Integer (id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all requests of the given event kind
|
||||
*
|
||||
* @param kind the event kind
|
||||
* @returns a <code>Collection</code> of all the registered requests
|
||||
* @throws IllegalArgumentException for invalid event kind
|
||||
*/
|
||||
public Collection getRequests (byte kind)
|
||||
{
|
||||
Hashtable requests = (Hashtable) _requests.get (new Byte (kind));
|
||||
if (requests == null)
|
||||
{
|
||||
// Did not get a valid event type
|
||||
throw new IllegalArgumentException ("invalid event kind: " + kind);
|
||||
}
|
||||
|
||||
return requests.values ();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,376 @@
|
|||
/* EventRequest.java -- an event request from the debugger
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.event.filters.*;
|
||||
import gnu.classpath.jdwp.exception.JdwpIllegalArgumentException;
|
||||
import gnu.classpath.jdwp.id.*;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
* A class which represents a request by the debugger for an event
|
||||
* in the VM. <code>EventRequest</code>s usually have event filters
|
||||
* associated with them, which allow the debugger to specify conditions
|
||||
* under which the notification should be sent (specific thread, specific
|
||||
* class, ignore count, etc).
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class EventRequest
|
||||
{
|
||||
/*
|
||||
* Event types
|
||||
*/
|
||||
|
||||
/**
|
||||
* Single step event
|
||||
*/
|
||||
public static final byte EVENT_SINGLE_STEP =
|
||||
JdwpConstants.EventKind.SINGLE_STEP;
|
||||
|
||||
/**
|
||||
* Breakpoint event
|
||||
*/
|
||||
public static final byte EVENT_BREAKPOINT =
|
||||
JdwpConstants.EventKind.BREAKPOINT;
|
||||
|
||||
/**
|
||||
* Frame pop event
|
||||
*/
|
||||
public static final byte EVENT_FRAME_POP =
|
||||
JdwpConstants.EventKind.FRAME_POP;
|
||||
|
||||
/**
|
||||
* Exception event
|
||||
*/
|
||||
public static final byte EVENT_EXCEPTION =
|
||||
JdwpConstants.EventKind.EXCEPTION;
|
||||
|
||||
/**
|
||||
* User-defined event
|
||||
*/
|
||||
public static final byte EVENT_USER_DEFINED =
|
||||
JdwpConstants.EventKind.USER_DEFINED;
|
||||
|
||||
/**
|
||||
* Thread start event
|
||||
*/
|
||||
public static final byte EVENT_THREAD_START =
|
||||
JdwpConstants.EventKind.THREAD_START;
|
||||
|
||||
/**
|
||||
* Thread end/death event
|
||||
*/
|
||||
public static final byte EVENT_THREAD_END =
|
||||
JdwpConstants.EventKind.THREAD_END;
|
||||
|
||||
/**
|
||||
* Class prepare event
|
||||
*/
|
||||
public static final byte EVENT_CLASS_PREPARE =
|
||||
JdwpConstants.EventKind.CLASS_PREPARE;
|
||||
|
||||
/**
|
||||
* Class unload event
|
||||
*/
|
||||
public static final byte EVENT_CLASS_UNLOAD =
|
||||
JdwpConstants.EventKind.CLASS_UNLOAD;
|
||||
|
||||
/**
|
||||
* Class load event
|
||||
*/
|
||||
public static final byte EVENT_CLASS_LOAD =
|
||||
JdwpConstants.EventKind.CLASS_LOAD;
|
||||
|
||||
/**
|
||||
* Field access event
|
||||
*/
|
||||
public static final byte EVENT_FIELD_ACCESS =
|
||||
JdwpConstants.EventKind.FIELD_ACCESS;
|
||||
|
||||
/**
|
||||
* Field modify event
|
||||
*/
|
||||
public static final byte EVENT_FIELD_MODIFY =
|
||||
JdwpConstants.EventKind.FIELD_MODIFICATION;
|
||||
|
||||
/**
|
||||
* Method entry event
|
||||
*/
|
||||
public static final byte EVENT_METHOD_ENTRY =
|
||||
JdwpConstants.EventKind.METHOD_ENTRY;
|
||||
|
||||
/**
|
||||
* Method exit event
|
||||
*/
|
||||
public static final byte EVENT_METHOD_EXIT =
|
||||
JdwpConstants.EventKind.METHOD_EXIT;
|
||||
|
||||
/**
|
||||
* Virtual machine initialization/start
|
||||
*/
|
||||
public static final byte EVENT_VM_INIT =
|
||||
JdwpConstants.EventKind.VM_INIT;
|
||||
|
||||
/**
|
||||
* Virutal machine death
|
||||
*/
|
||||
public static final byte EVENT_VM_DEATH =
|
||||
JdwpConstants.EventKind.VM_DEATH;
|
||||
|
||||
|
||||
/*
|
||||
* Suspend policies
|
||||
*/
|
||||
|
||||
/**
|
||||
* Do not suspend any threads
|
||||
*/
|
||||
public static final byte SUSPEND_NONE =
|
||||
JdwpConstants.SuspendPolicy.NONE;
|
||||
|
||||
/**
|
||||
* Suspend the thread in which the event occurred
|
||||
*/
|
||||
public static final byte SUSPEND_THREAD =
|
||||
JdwpConstants.SuspendPolicy.EVENT_THREAD;
|
||||
|
||||
/**
|
||||
* Suspend all threads
|
||||
*/
|
||||
public static final byte SUSPEND_ALL =
|
||||
JdwpConstants.SuspendPolicy.ALL;
|
||||
|
||||
// ID of last EventRequest
|
||||
private static int _last_id = 0;
|
||||
private static Object _idLock = new Object ();
|
||||
|
||||
// A list of filters
|
||||
private LinkedList _filters;
|
||||
|
||||
// The ID of this request
|
||||
private int _id;
|
||||
|
||||
// The suspend policy to enforce when this event occurs
|
||||
private byte _suspendPolicy;
|
||||
|
||||
// Kind of event requested
|
||||
private byte _kind;
|
||||
|
||||
/**
|
||||
* Construct a new <code>EventRequest</code>
|
||||
*
|
||||
* @param kind the kind of event requested
|
||||
* @param suspendPolicy how to suspend threads when event occurs
|
||||
*/
|
||||
public EventRequest (byte kind, byte suspendPolicy)
|
||||
{
|
||||
_filters = new LinkedList ();
|
||||
synchronized (_idLock)
|
||||
{
|
||||
_id = ++_last_id;
|
||||
}
|
||||
_kind = kind;
|
||||
_suspendPolicy = suspendPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new <code>EventRequest</code> with the given ID
|
||||
*
|
||||
* @param id the id of the request to create
|
||||
* @param kind the kind of event requested
|
||||
* @param suspendPolicy how to suspend threads when event occurs
|
||||
*/
|
||||
public EventRequest (int id, byte kind, byte suspendPolicy)
|
||||
{
|
||||
_filters = new LinkedList ();
|
||||
_kind = kind;
|
||||
_suspendPolicy = suspendPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new event filter, adding it to this request
|
||||
*
|
||||
* @param filter the filter to add
|
||||
* @throws JdwpIllegalArgumentException if an invalid or illegal filter
|
||||
* is added to the request
|
||||
*/
|
||||
public void addFilter (IEventFilter filter)
|
||||
throws JdwpIllegalArgumentException
|
||||
{
|
||||
// Check validity of filter for this request
|
||||
boolean valid = true;
|
||||
|
||||
Class clazz = filter.getClass ();
|
||||
if (clazz == ClassExcludeFilter.class)
|
||||
{
|
||||
if (_kind == EVENT_THREAD_START
|
||||
|| _kind == EVENT_THREAD_END)
|
||||
valid = false;
|
||||
}
|
||||
else if (clazz == ClassMatchFilter.class)
|
||||
{
|
||||
if (_kind == EVENT_THREAD_START
|
||||
|| _kind == EVENT_THREAD_END)
|
||||
valid = false;
|
||||
}
|
||||
else if (clazz == ClassOnlyFilter.class)
|
||||
{
|
||||
if (_kind == EVENT_CLASS_UNLOAD
|
||||
|| _kind == EVENT_THREAD_START
|
||||
|| _kind == EVENT_THREAD_END)
|
||||
valid = false;
|
||||
}
|
||||
else if (clazz == ConditionalFilter.class)
|
||||
{
|
||||
// JDWP 1.4 does not say much about this
|
||||
}
|
||||
else if (clazz == CountFilter.class)
|
||||
{
|
||||
// may be used with any event
|
||||
}
|
||||
else if (clazz == ExceptionOnlyFilter.class)
|
||||
{
|
||||
if (_kind != EVENT_EXCEPTION)
|
||||
valid = false;
|
||||
}
|
||||
else if (clazz == FieldOnlyFilter.class)
|
||||
{
|
||||
if (_kind != EVENT_FIELD_ACCESS
|
||||
&& _kind != EVENT_FIELD_MODIFY)
|
||||
valid = false;
|
||||
}
|
||||
else if (clazz == InstanceOnlyFilter.class)
|
||||
{
|
||||
if (_kind == EVENT_CLASS_PREPARE
|
||||
|| _kind == EVENT_CLASS_UNLOAD
|
||||
|| _kind == EVENT_THREAD_START
|
||||
|| _kind == EVENT_THREAD_END)
|
||||
valid = false;
|
||||
}
|
||||
else if (clazz == LocationOnlyFilter.class)
|
||||
{
|
||||
if (_kind != EVENT_BREAKPOINT
|
||||
&& _kind != EVENT_FIELD_ACCESS
|
||||
&& _kind != EVENT_FIELD_MODIFY
|
||||
&& _kind != EVENT_SINGLE_STEP
|
||||
&& _kind != EVENT_EXCEPTION)
|
||||
valid = false;
|
||||
}
|
||||
else if (clazz == StepFilter.class)
|
||||
{
|
||||
if (_kind != EVENT_SINGLE_STEP)
|
||||
valid = false;
|
||||
}
|
||||
else if (clazz == ThreadOnlyFilter.class)
|
||||
{
|
||||
if (_kind == EVENT_CLASS_UNLOAD)
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
String msg = ("cannot use " + filter.getClass ().getName ()
|
||||
+ " with class unload events");
|
||||
throw new JdwpIllegalArgumentException (msg);
|
||||
}
|
||||
|
||||
// Add filter to list
|
||||
_filters.add (filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the suspend policy for this request
|
||||
*/
|
||||
public byte getSuspendPolicy ()
|
||||
{
|
||||
return _suspendPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request id of this request
|
||||
*/
|
||||
public int getId ()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the id of the request (used for auto-generated events)
|
||||
*/
|
||||
public void setId (int id)
|
||||
{
|
||||
_id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind of event for this request
|
||||
*/
|
||||
public byte getEventKind ()
|
||||
{
|
||||
return _kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given event matches this request
|
||||
*
|
||||
* @param theEvent the event to compare to
|
||||
*/
|
||||
public boolean matches (Event theEvent)
|
||||
{
|
||||
boolean matches = true;
|
||||
|
||||
// Loop through filters; all must match
|
||||
// Note that we must allow EVERY filter to evaluate. This way
|
||||
// things like CountFilter will work.
|
||||
ListIterator iter = _filters.listIterator ();
|
||||
while (iter.hasNext ())
|
||||
{
|
||||
IEventFilter filter = (IEventFilter) iter.next ();
|
||||
if (!filter.matches (theEvent))
|
||||
matches = false;
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
/* ThreadEndEvent.java -- An event specifying that a thread has died
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.VMIdManager;
|
||||
import gnu.classpath.jdwp.id.ThreadId;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* "Notification of a completed thread in the target VM. The notification
|
||||
* is generated by the dying thread before it terminates. Because of this
|
||||
* timing, it is possible for VirtualMachine.allThreads to return this
|
||||
* thread after this event is received.
|
||||
*
|
||||
* <p>Note that this event gives no information about the lifetime of the
|
||||
* thread object. It may or may not be collected soon depending on what
|
||||
* references exist in the target VM." -- JDWP 1.4.2
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class ThreadEndEvent
|
||||
extends Event
|
||||
{
|
||||
private Thread _thread;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ThreadEndEvent</code>
|
||||
*
|
||||
* @param thread the deceased thread
|
||||
*/
|
||||
public ThreadEndEvent (Thread thread)
|
||||
{
|
||||
super (JdwpConstants.EventKind.THREAD_END);
|
||||
_thread = thread;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specific filtering parameter for this event.
|
||||
* Valid types are ThreadId.
|
||||
*
|
||||
* @param type the type of parameter desired
|
||||
* @returns the desired parameter or <code>null</code>
|
||||
*/
|
||||
public Object getParameter (Class type)
|
||||
{
|
||||
if (type == ThreadId.class)
|
||||
return _thread;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the event to the given stream
|
||||
*
|
||||
* @param outStream the output stream to write the event to
|
||||
*/
|
||||
protected void _writeData (DataOutputStream outStream)
|
||||
throws IOException
|
||||
{
|
||||
VMIdManager idm = VMIdManager.getDefault();
|
||||
ThreadId tid = (ThreadId) idm.getObjectId (_thread);
|
||||
tid.write (outStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/* ThreadStartEvent.java -- An event specifying that a new thread
|
||||
has started in the virtual machine
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.VMIdManager;
|
||||
import gnu.classpath.jdwp.id.ThreadId;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* "Notification of a new running thread in the target VM. The new
|
||||
* thread can be the result of a call to {@link java.lang.Thread.start} or
|
||||
* the result of attaching a new thread to the VM though JNI. The
|
||||
* notification is generated by the new thread some time before its
|
||||
* execution starts. Because of this timing, it is possible to receive
|
||||
* other events for the thread before this event is received. (Notably,
|
||||
* Method Entry Events and Method Exit Events might occur during thread
|
||||
* initialization. It is also possible for the VirtualMachine AllThreads
|
||||
* command to return a thread before its thread start event is received.
|
||||
*
|
||||
* <p>Note that this event gives no information about the creation of the
|
||||
* thread object which may have happened much earlier, depending on the
|
||||
* VM being debugged." -- JDWP 1.4.2
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class ThreadStartEvent
|
||||
extends Event
|
||||
{
|
||||
private Thread _thread;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ThreadStartEvent</code>
|
||||
*
|
||||
* @param tid the thread ID in which event occurred
|
||||
*/
|
||||
public ThreadStartEvent (Thread thread) {
|
||||
super (JdwpConstants.EventKind.THREAD_END);
|
||||
_thread = thread;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specific filtering parameter for this event.
|
||||
* Valid types are ThreadId.
|
||||
*
|
||||
* @param type the type of parameter desired
|
||||
* @returns the desired parameter or <code>null</code>
|
||||
*/
|
||||
public Object getParameter (Class type)
|
||||
{
|
||||
if (type == ThreadId.class)
|
||||
return _thread;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the event to the given stream
|
||||
*
|
||||
* @param outStream the output stream to write the event to
|
||||
*/
|
||||
protected void _writeData (DataOutputStream outStream)
|
||||
throws IOException
|
||||
{
|
||||
VMIdManager idm = VMIdManager.getDefault();
|
||||
ThreadId tid = (ThreadId) idm.getObjectId (_thread);
|
||||
tid.write (outStream);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/* VmInitEvent.java -- An event specifying that the VM has started
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.VMIdManager;
|
||||
import gnu.classpath.jdwp.id.ThreadId;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* "Notification of initialization of a target VM. This event is
|
||||
* received before the main thread is started and before any application
|
||||
* code has been executed." -- JDWP 1.4.2
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class VmInitEvent
|
||||
extends Event
|
||||
{
|
||||
private Thread _initialThread;
|
||||
|
||||
/**
|
||||
* Constructs a <code>VmInitEvent</code> object
|
||||
*
|
||||
* @param thread the initial thread
|
||||
*/
|
||||
public VmInitEvent (Thread thread)
|
||||
{
|
||||
super (JdwpConstants.EventKind.VM_INIT);
|
||||
_initialThread = thread;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specific filtering parameter for this event.
|
||||
* This event has no valid types.
|
||||
*
|
||||
* @param type the type of parameter desired
|
||||
* @returns the desired parameter or <code>null</code>
|
||||
*/
|
||||
public Object getParameter (Class type)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes out event-specific data
|
||||
*/
|
||||
protected void _writeData (DataOutputStream outStream)
|
||||
throws IOException
|
||||
{
|
||||
VMIdManager idm = VMIdManager.getDefault();
|
||||
ThreadId tid = (ThreadId) idm.getObjectId (_initialThread);
|
||||
tid.write (outStream);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/* ClassExcludeFilter.java -- filter on class name (exclusive)
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event.filters;
|
||||
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.exception.InvalidStringException;
|
||||
|
||||
/**
|
||||
* An event filter which excludes events matching a
|
||||
* specified class pattern (exact match or start/end with "*").
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class ClassExcludeFilter
|
||||
extends ClassMatchFilter
|
||||
{
|
||||
/**
|
||||
* Constructs a new <code>ClassExcludeFilter</code>
|
||||
*
|
||||
* @param pattern the pattern to use
|
||||
* @throws InvalidStringException if pattern is invalid
|
||||
*/
|
||||
public ClassExcludeFilter (String pattern)
|
||||
throws InvalidStringException
|
||||
{
|
||||
super (pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given event match the filter?
|
||||
*
|
||||
* @param event the <code>Event</code> to scrutinize
|
||||
*/
|
||||
public boolean matches (Event event)
|
||||
{
|
||||
return !super.matches (event);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
/* ClassMatchFilter.java -- filter on class name (inclusive)
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event.filters;
|
||||
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.exception.InvalidStringException;
|
||||
import gnu.classpath.jdwp.exception.InvalidClassException;
|
||||
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
||||
|
||||
/**
|
||||
* An event filter which includes events matching a
|
||||
* specified class pattern (exact match or start/end with "*").
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class ClassMatchFilter
|
||||
implements IEventFilter
|
||||
{
|
||||
// Pattern to match
|
||||
private String _pattern;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ClassMatchFilter</code>
|
||||
*
|
||||
* @param pattern the pattern to use
|
||||
* @throws InvalidStringException if pattern is invalid
|
||||
*/
|
||||
public ClassMatchFilter (String pattern)
|
||||
throws InvalidStringException
|
||||
{
|
||||
int index = pattern.indexOf ('*');
|
||||
if (index != -1 && index != 0 && index != (pattern.length () - 1))
|
||||
{
|
||||
// '*' must be first char or last char
|
||||
throw new InvalidStringException ("pattern may be an exact match or "
|
||||
+ "start/end with \"*\"");
|
||||
}
|
||||
_pattern = pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pattern to be matched
|
||||
*
|
||||
* @return the pattern
|
||||
*/
|
||||
public String getPattern ()
|
||||
{
|
||||
return _pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given event match the filter?
|
||||
*
|
||||
* @param event the <code>Event</code> to scrutinize
|
||||
*/
|
||||
public boolean matches (Event event)
|
||||
{
|
||||
Object type = event.getParameter (ReferenceTypeId.class);
|
||||
if (type != null)
|
||||
{
|
||||
Class eventClass = (Class) type;
|
||||
String name = eventClass.getName ();
|
||||
|
||||
if (_pattern.startsWith ("*"))
|
||||
return name.endsWith (_pattern.substring (1));
|
||||
else if (_pattern.endsWith ("*"))
|
||||
{
|
||||
int end = _pattern.length () - 1;
|
||||
return name.startsWith (_pattern.substring (0, end));
|
||||
}
|
||||
else
|
||||
return name.matches (_pattern);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/* ClassOnlyFilter.java -- filter on specific class
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event.filters;
|
||||
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.exception.InvalidClassException;
|
||||
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
||||
|
||||
/**
|
||||
* An event filter which filters out events in uninteresting
|
||||
* classes.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class ClassOnlyFilter
|
||||
implements IEventFilter
|
||||
{
|
||||
// Class ID for which to filter
|
||||
private ReferenceTypeId _id;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ClassOnlyFilter</code>
|
||||
*
|
||||
* @param refId the reference type id for a class for which events
|
||||
* will be reported
|
||||
* @throws InvalidClassException if the ID is no longer valid
|
||||
*/
|
||||
public ClassOnlyFilter (ReferenceTypeId refId)
|
||||
throws InvalidClassException
|
||||
{
|
||||
// validity check
|
||||
refId.getType ();
|
||||
_id = refId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class to which to restrict events
|
||||
*
|
||||
* @return the class's ID
|
||||
*/
|
||||
public ReferenceTypeId getType ()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given event match the filter?
|
||||
*
|
||||
* @param event the <code>Event</code> to scrutinize
|
||||
*/
|
||||
public boolean matches (Event event)
|
||||
{
|
||||
Object type = event.getParameter (ReferenceTypeId.class);
|
||||
if (type != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Class clazz = _id.getType ();
|
||||
Class eventClass = (Class) type;
|
||||
if (clazz.isAssignableFrom (eventClass))
|
||||
return true;
|
||||
}
|
||||
catch (InvalidClassException ice)
|
||||
{
|
||||
// class is no longer valid
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
/* ConditionalFilter.java -- conditional expression filter
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event.filters;
|
||||
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.exception.NotImplementedException;
|
||||
|
||||
/**
|
||||
* An event filter which allows expression conditionals.
|
||||
* Note that in JDWP 1.4, this class is marked "for the
|
||||
* future".
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class ConditionalFilter
|
||||
implements IEventFilter
|
||||
{
|
||||
// private ConditionalId _exprId;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ConditionalFilter</code> with the
|
||||
* given conditional.
|
||||
*
|
||||
* <p><b>NOTE:</b> This filter is marked "for the future",
|
||||
* i.e, there is no way to actually use this yet.
|
||||
*
|
||||
* @param cond the conditional expression
|
||||
* @throws NotImplementedException if used
|
||||
*/
|
||||
public ConditionalFilter (Object conditional)
|
||||
throws NotImplementedException
|
||||
{
|
||||
throw new NotImplementedException ("conditional filters");
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given event match the filter?
|
||||
*
|
||||
* @param event the <code>Event</code> to scrutinize
|
||||
*/
|
||||
public boolean matches (Event event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/* CountFilter.java -- a step filter
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event.filters;
|
||||
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.exception.InvalidCountException;
|
||||
|
||||
/**
|
||||
* An ignore count filter.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class CountFilter
|
||||
implements IEventFilter
|
||||
{
|
||||
// the count
|
||||
private int _count;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>CountFilter</code> with the given count.
|
||||
*
|
||||
* @param count the number of times the event will be ignored
|
||||
* @throws InvalidCountException if count is invalid (< 1)
|
||||
*/
|
||||
public CountFilter (int count)
|
||||
throws InvalidCountException
|
||||
{
|
||||
// Check for valid count
|
||||
if (count < 1)
|
||||
throw new InvalidCountException (count);
|
||||
|
||||
_count = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ignore count
|
||||
*
|
||||
* @return the number of times the event should be ignored
|
||||
*/
|
||||
public int getCount ()
|
||||
{
|
||||
return _count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given event match the filter?
|
||||
*
|
||||
* @param event the <code>Event</code> to scrutinize
|
||||
*/
|
||||
public boolean matches (Event event)
|
||||
{
|
||||
// This filter only relies on its count
|
||||
if (--_count == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
/* ExceptionOnlyFilter.java --
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event.filters;
|
||||
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.exception.InvalidClassException;
|
||||
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
||||
|
||||
/**
|
||||
* Restricts reported exceptions by their class and whether they are caught
|
||||
* or uncaught.
|
||||
*
|
||||
* This modifier can be used with exception event kinds only.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class ExceptionOnlyFilter
|
||||
implements IEventFilter
|
||||
{
|
||||
private ReferenceTypeId _refId;
|
||||
private boolean _caught;
|
||||
private boolean _uncaught;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ExceptionOnlyFilter</code>
|
||||
*
|
||||
* @param refid
|
||||
* @param caught
|
||||
* @param uncaught
|
||||
* @throws InvalidClassException if refid is invalid
|
||||
*/
|
||||
public ExceptionOnlyFilter (ReferenceTypeId refId, boolean caught,
|
||||
boolean uncaught)
|
||||
throws InvalidClassException
|
||||
{
|
||||
if (refId == null || refId.getReference().get () == null)
|
||||
throw new InvalidClassException (refId.getId ());
|
||||
|
||||
_refId = refId;
|
||||
_caught = caught;
|
||||
_uncaught = uncaught;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exception class to report (<code>null</code> for all)
|
||||
*
|
||||
* @return the class's ID
|
||||
*/
|
||||
public ReferenceTypeId getType ()
|
||||
{
|
||||
return _refId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report caught exceptions?
|
||||
*
|
||||
* @return whether to report caught exceptions
|
||||
*/
|
||||
public boolean forCaught ()
|
||||
{
|
||||
return _caught;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report uncaught exceptions?
|
||||
*
|
||||
* @return whether to report uncaught exceptions
|
||||
*/
|
||||
public boolean forUncaught ()
|
||||
{
|
||||
return _uncaught;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given event match the filter?
|
||||
*
|
||||
* @param event the <code>Event</code> to scrutinize
|
||||
*/
|
||||
public boolean matches (Event event)
|
||||
{
|
||||
// FIXME
|
||||
throw new RuntimeException ("ExceptionOnlyFilter.matches not implemented");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/* FieldOnlyFilter.java -- filter on field
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event.filters;
|
||||
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.exception.InvalidClassException;
|
||||
import gnu.classpath.jdwp.exception.InvalidFieldException;
|
||||
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
||||
|
||||
/**
|
||||
* Restricts reported events to those that occur for a given field.
|
||||
*
|
||||
* This modifier can be used with field access and field modification event
|
||||
* kinds only.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class FieldOnlyFilter
|
||||
implements IEventFilter
|
||||
{
|
||||
private ReferenceTypeId _refId;
|
||||
private ReferenceTypeId _fieldId;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>FieldOnlyFilter</code>.
|
||||
*
|
||||
* @param refId class for field
|
||||
* @param fid field
|
||||
* @throws InvalidClassException if class is invalid
|
||||
* @throws InvalidFieldExcpetion if field is invalid
|
||||
*/
|
||||
public FieldOnlyFilter (ReferenceTypeId refId, /*Field*/ReferenceTypeId fid)
|
||||
throws InvalidClassException, InvalidFieldException
|
||||
{
|
||||
if (refId == null || refId.getReference().get () == null)
|
||||
throw new InvalidClassException (refId.getId ());
|
||||
|
||||
if (fid == null)
|
||||
throw new InvalidFieldException (fid.getId ());
|
||||
|
||||
_refId = refId;
|
||||
_fieldId = fid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class in which the field is declared
|
||||
*
|
||||
* @return the class's id
|
||||
*/
|
||||
public ReferenceTypeId getType ()
|
||||
{
|
||||
return _refId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field for which to restrict events
|
||||
*
|
||||
* @return the field's id
|
||||
*/
|
||||
public ReferenceTypeId getField ()
|
||||
{
|
||||
return _fieldId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given event match the filter?
|
||||
*
|
||||
* @param event the <code>Event</code> to scrutinize
|
||||
*/
|
||||
public boolean matches (Event event)
|
||||
{
|
||||
// FIXME
|
||||
throw new RuntimeException ("FieldOnlyFilter.matches not implemented");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/* IEventFilter.java -- an interface for event filters
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event.filters;
|
||||
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
|
||||
/**
|
||||
* An interface for event filters. The debugger registers an event
|
||||
* filter for a given event when it is interested in receiving
|
||||
* notifications about that event from the VM.
|
||||
*
|
||||
* <p>Filters are attached to {@link gnu.classpath.jdwp.event.EventRequest}s
|
||||
* in order to allow the debugger to specify that an event should be sent
|
||||
* only when the filters for the event request all match.
|
||||
*
|
||||
* <p>No filters means "send all notifications".
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public interface IEventFilter
|
||||
{
|
||||
/**
|
||||
* Does the given event match the filter?
|
||||
*
|
||||
* @param event the <code>Event</code> to scrutinize
|
||||
*/
|
||||
public boolean matches (Event event);
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
/* InstanceOnlyFilter.java -- filter on instance
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event.filters;
|
||||
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.exception.InvalidObjectException;
|
||||
import gnu.classpath.jdwp.id.ObjectId;
|
||||
|
||||
/**
|
||||
* Restricts reported events to those whose active 'this' object is the
|
||||
* given object. Match value is the null object for static methods.
|
||||
*
|
||||
* This modifier can be used with any event kind except class prepare,
|
||||
* class unload, thread start, and thread end. Introduced in JDWP version 1.4.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class InstanceOnlyFilter
|
||||
implements IEventFilter
|
||||
{
|
||||
private ObjectId _instance;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>InstanceOnlyFilter</code>.
|
||||
*
|
||||
* @param oid the object to which to restrict events (may be null)
|
||||
* @throws InvalidObjectException if Object is invalid
|
||||
*/
|
||||
public InstanceOnlyFilter (ObjectId oid)
|
||||
throws InvalidObjectException
|
||||
{
|
||||
if (oid != null && oid.getReference().get () == null)
|
||||
throw new InvalidObjectException (oid.getId ());
|
||||
|
||||
_instance = oid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the instance to which to restrict events
|
||||
*
|
||||
* @return the object's ID
|
||||
*/
|
||||
public ObjectId getInstance ()
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given event match the filter?
|
||||
*
|
||||
* @param event the <code>Event</code> to scrutinize
|
||||
*/
|
||||
public boolean matches (Event event)
|
||||
{
|
||||
Object eventInstance = event.getParameter (ObjectId.class);
|
||||
if (eventInstance != null)
|
||||
{
|
||||
Object myInstance = _instance.getReference().get ();
|
||||
return ((myInstance != null) && (myInstance == eventInstance));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
/* LocationOnlyFilter.java -- filter on location
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event.filters;
|
||||
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.exception.InvalidLocationException;
|
||||
import gnu.classpath.jdwp.util.Location;
|
||||
|
||||
/**
|
||||
* Restricts reported events to those that occur at the given location.
|
||||
*
|
||||
* May be used with breakpoint, field access, field modification, step,
|
||||
* and exception event kinds.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class LocationOnlyFilter
|
||||
implements IEventFilter
|
||||
{
|
||||
private Location _location;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>LocationOnlyFilter</code>.
|
||||
*
|
||||
* @param loc the location for which to report events
|
||||
* @throws InvalidLocationException if location is invalid
|
||||
*/
|
||||
public LocationOnlyFilter (Location loc)
|
||||
throws InvalidLocationException
|
||||
{
|
||||
_location = loc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the location at which to restrict events
|
||||
*
|
||||
* @return the location
|
||||
*/
|
||||
public Location getLocation ()
|
||||
{
|
||||
return _location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given event match the filter?
|
||||
*
|
||||
* @param event the <code>Event</code> to scrutinize
|
||||
*/
|
||||
public boolean matches (Event event)
|
||||
{
|
||||
// FIXME
|
||||
throw new RuntimeException ("LocationOnlyFilter.matches not implemented");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
/* StepFilter.java -- a step filter
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event.filters;
|
||||
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.exception.InvalidThreadException;
|
||||
import gnu.classpath.jdwp.id.ThreadId;
|
||||
|
||||
/**
|
||||
* An event filter which restricts reported step events to those which
|
||||
* satisfy depth and size constraints. This modifier can only be used with
|
||||
* step event kinds.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class StepFilter
|
||||
implements IEventFilter
|
||||
{
|
||||
private ThreadId _tid;
|
||||
private int _size;
|
||||
private int _depth;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>StepFilter</code> with the given count.
|
||||
*
|
||||
* @param count the number of times the event will be ignored
|
||||
* @throws InvalidThreadException if thread is invalid
|
||||
*/
|
||||
public StepFilter (ThreadId tid, int size, int depth)
|
||||
throws InvalidThreadException
|
||||
{
|
||||
if (tid == null | tid.getReference().get () == null)
|
||||
throw new InvalidThreadException (tid.getId ());
|
||||
|
||||
_tid = tid;
|
||||
_size = size;
|
||||
_depth = depth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the thread in which to step
|
||||
*
|
||||
* @return the thread's ID
|
||||
*/
|
||||
public ThreadId getThread ()
|
||||
{
|
||||
return _tid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of each step (insn, line)
|
||||
*
|
||||
* @return the step size
|
||||
* @see JdwpConstants.StepSize
|
||||
*/
|
||||
public int getSize ()
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the relative call stack limit (into, over, out)
|
||||
*
|
||||
* @return how to step
|
||||
* @see JdwpConstants.StepDepth
|
||||
*/
|
||||
public int getDepth ()
|
||||
{
|
||||
return _depth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given event match the filter?
|
||||
*
|
||||
* @param event the <code>Event</code> to scrutinize
|
||||
*/
|
||||
public boolean matches (Event event)
|
||||
{
|
||||
// FIXME
|
||||
throw new RuntimeException ("StepFilter.matches not implemented");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
/* ThreadOnlyFilter.java -- a thread filter
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.event.filters;
|
||||
|
||||
import gnu.classpath.jdwp.Jdwp;
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.exception.InvalidThreadException;
|
||||
import gnu.classpath.jdwp.id.ThreadId;
|
||||
|
||||
/**
|
||||
* An event filter which allows only events within a specific
|
||||
* thread
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class ThreadOnlyFilter
|
||||
implements IEventFilter
|
||||
{
|
||||
// the thread
|
||||
private ThreadId _tid;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ThreadOnlyFilter</code> for the given
|
||||
* thread id
|
||||
*
|
||||
* @param tid ID of the thread on which to filter
|
||||
* @throws InvalidThreadException if the thread is not valid
|
||||
*/
|
||||
public ThreadOnlyFilter (ThreadId tid)
|
||||
throws InvalidThreadException
|
||||
{
|
||||
if (tid == null | tid.getReference().get () == null)
|
||||
throw new InvalidThreadException (tid.getId ());
|
||||
|
||||
_tid = tid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the thread in which to restrict events
|
||||
*
|
||||
* @return the thread's ID
|
||||
*/
|
||||
public ThreadId getThread ()
|
||||
{
|
||||
return _tid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the given event match the filter?
|
||||
*
|
||||
* @param event the <code>Event</code> to scrutinize
|
||||
*/
|
||||
public boolean matches (Event event)
|
||||
{
|
||||
Object thread = event.getParameter (ThreadId.class);
|
||||
if (thread != null)
|
||||
{
|
||||
Thread eventThread = (Thread) thread;
|
||||
Thread myThread = (Thread) _tid.getReference().get ();
|
||||
return (eventThread == myThread);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/* InvalidClassLoaderException.java -- an invalid class loader exception
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown when the debugger uses an invalid class loader
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class InvalidClassLoaderException
|
||||
extends JdwpException
|
||||
{
|
||||
public InvalidClassLoaderException (long id)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_CLASS_LOADER,
|
||||
"invalid class loader (" + id + ")");
|
||||
}
|
||||
|
||||
public InvalidClassLoaderException (Throwable t)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_CLASS_LOADER, t);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/* InvalidFieldException.java -- an invalid field id exception
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown when an invalid field id is used by the
|
||||
* debugger
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class InvalidFieldException
|
||||
extends JdwpException
|
||||
{
|
||||
public InvalidFieldException (long id)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_FIELDID,
|
||||
"invalid field id (" + id + ")");
|
||||
}
|
||||
|
||||
public InvalidFieldException (Throwable t)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_FIELDID, t);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/* InvalidLocationException.java -- an invalid location exception
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown when the debugger specifies an invalid location
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class InvalidLocationException
|
||||
extends JdwpException
|
||||
{
|
||||
public InvalidLocationException (/*something*/)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_LOCATION,
|
||||
"invalid location (" + "something" + ")");
|
||||
}
|
||||
|
||||
public InvalidLocationException (Throwable t)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_LOCATION, t);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/* InvalidMethodException.java -- an invalid method id exception
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown when an invalid method id is used
|
||||
* by the debugger
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class InvalidMethodException
|
||||
extends JdwpException
|
||||
{
|
||||
public InvalidMethodException (long id)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_METHODID,
|
||||
"invalid method id (" + id + ")");
|
||||
}
|
||||
|
||||
public InvalidMethodException (Throwable t)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_METHODID, t);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/* JdwpIllegalArgumentException.java -- an illegal argument exception
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An illegal argument exception for JDWP.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class JdwpIllegalArgumentException
|
||||
extends JdwpException
|
||||
{
|
||||
/**
|
||||
* Constructs a new <code>JdwpIllegalArgumentException</code> with
|
||||
* the given error code and given cause
|
||||
*
|
||||
* @param msg a message explaining the illegal argument
|
||||
*/
|
||||
public JdwpIllegalArgumentException (String msg)
|
||||
{
|
||||
super (JdwpConstants.Error.ILLEGAL_ARGUMENT, msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,174 @@
|
|||
/* ArrayReferenceCommandSet.java -- class to implement the Array
|
||||
Reference Command Set
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.exception.InvalidObjectException;
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
|
||||
import gnu.classpath.jdwp.exception.NotImplementedException;
|
||||
import gnu.classpath.jdwp.id.ObjectId;
|
||||
import gnu.classpath.jdwp.util.Value;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A class representing the ArrayReference Command Set.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public class ArrayReferenceCommandSet
|
||||
extends CommandSet
|
||||
{
|
||||
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
|
||||
throws JdwpException
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case JdwpConstants.CommandSet.ArrayReference.LENGTH:
|
||||
executeLength(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ArrayReference.GET_VALUES:
|
||||
executeGetValues(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ArrayReference.SET_VALUES:
|
||||
executeSetValues(bb, os);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("Command " + command +
|
||||
" not found in Array Reference Command Set.");
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// The DataOutputStream we're using isn't talking to a socket at all
|
||||
// So if we throw an IOException we're in serious trouble
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void executeLength(ByteBuffer bb, DataOutputStream os)
|
||||
throws InvalidObjectException, IOException
|
||||
{
|
||||
ObjectId oid = idMan.readObjectId(bb);
|
||||
Object array = oid.getObject();
|
||||
os.writeInt(Array.getLength(array));
|
||||
}
|
||||
|
||||
private void executeGetValues(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ObjectId oid = idMan.readObjectId(bb);
|
||||
Object array = oid.getObject();
|
||||
int first = bb.getInt();
|
||||
int length = bb.getInt();
|
||||
|
||||
// We need to write out the byte signifying the type of array first
|
||||
Class clazz = array.getClass().getComponentType();
|
||||
|
||||
// Uugh, this is a little ugly but it's the only time we deal with
|
||||
// arrayregions
|
||||
if (clazz == byte.class)
|
||||
os.writeByte(JdwpConstants.Tag.BYTE);
|
||||
else if (clazz == char.class)
|
||||
os.writeByte(JdwpConstants.Tag.CHAR);
|
||||
else if (clazz == float.class)
|
||||
os.writeByte(JdwpConstants.Tag.FLOAT);
|
||||
else if (clazz == double.class)
|
||||
os.writeByte(JdwpConstants.Tag.DOUBLE);
|
||||
else if (clazz == int.class)
|
||||
os.writeByte(JdwpConstants.Tag.BYTE);
|
||||
else if (clazz == long.class)
|
||||
os.writeByte(JdwpConstants.Tag.LONG);
|
||||
else if (clazz == short.class)
|
||||
os.writeByte(JdwpConstants.Tag.SHORT);
|
||||
else if (clazz == void.class)
|
||||
os.writeByte(JdwpConstants.Tag.VOID);
|
||||
else if (clazz == boolean.class)
|
||||
os.writeByte(JdwpConstants.Tag.BOOLEAN);
|
||||
else if (clazz.isArray())
|
||||
os.writeByte(JdwpConstants.Tag.ARRAY);
|
||||
else if (String.class.isAssignableFrom(clazz))
|
||||
os.writeByte(JdwpConstants.Tag.STRING);
|
||||
else if (Thread.class.isAssignableFrom(clazz))
|
||||
os.writeByte(JdwpConstants.Tag.THREAD);
|
||||
else if (ThreadGroup.class.isAssignableFrom(clazz))
|
||||
os.writeByte(JdwpConstants.Tag.THREAD_GROUP);
|
||||
else if (ClassLoader.class.isAssignableFrom(clazz))
|
||||
os.writeByte(JdwpConstants.Tag.CLASS_LOADER);
|
||||
else if (Class.class.isAssignableFrom(clazz))
|
||||
os.writeByte(JdwpConstants.Tag.CLASS_OBJECT);
|
||||
else
|
||||
os.writeByte(JdwpConstants.Tag.OBJECT);
|
||||
|
||||
// Write all the values, primitives should be untagged and Objects must be
|
||||
// tagged
|
||||
for (int i = first; i < first + length; i++)
|
||||
{
|
||||
Object value = Array.get(array, i);
|
||||
if (clazz.isPrimitive())
|
||||
Value.writeUntaggedValue(os, value);
|
||||
else
|
||||
Value.writeTaggedValue(os, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void executeSetValues(ByteBuffer bb, DataOutputStream os)
|
||||
throws IOException, JdwpException
|
||||
{
|
||||
ObjectId oid = idMan.readObjectId(bb);
|
||||
Object array = oid.getObject();
|
||||
int first = bb.getInt();
|
||||
int length = bb.getInt();
|
||||
Class type = array.getClass().getComponentType();
|
||||
for (int i = first; i < first + length; i++)
|
||||
{
|
||||
Object value = Value.getUntaggedObj(bb, type);
|
||||
Array.set(array, i, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/* ArrayTypeCommandSet.java -- class to implement the ArrayType Command Set
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
|
||||
import gnu.classpath.jdwp.exception.NotImplementedException;
|
||||
import gnu.classpath.jdwp.id.ObjectId;
|
||||
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A class representing the ArrayType Command Set.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public class ArrayTypeCommandSet
|
||||
extends CommandSet
|
||||
{
|
||||
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
|
||||
throws JdwpException
|
||||
{
|
||||
|
||||
// Although there's only a single command to choose from we still use
|
||||
// a switch to maintain consistency with the rest of the CommandSets
|
||||
try
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case JdwpConstants.CommandSet.ArrayType.NEW_INSTANCE:
|
||||
executeNewInstance(bb, os);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("Command " + command +
|
||||
" not found in ArrayType Command Set.");
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// The DataOutputStream we're using isn't talking to a socket at all
|
||||
// So if we throw an IOException we're in serious trouble
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void executeNewInstance(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
Class arrayType = refId.getType();
|
||||
Class componentType = arrayType.getComponentType();
|
||||
|
||||
int length = bb.getInt();
|
||||
Object newArray = Array.newInstance(componentType, length);
|
||||
ObjectId oid = idMan.getObjectId(newArray);
|
||||
|
||||
// Since this array isn't referenced anywhere we'll disable garbage
|
||||
// collection on it so it's still around when the debugger gets back to it.
|
||||
oid.disableCollection();
|
||||
oid.writeTagged(os);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
/* ClassLoaderReferenceCommandSet.java -- class to implement the
|
||||
ClassLoaderReference Command Set
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.VMVirtualMachine;
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
|
||||
import gnu.classpath.jdwp.exception.NotImplementedException;
|
||||
import gnu.classpath.jdwp.id.ObjectId;
|
||||
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* A class representing the ClassLoaderReference Command Set.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public class ClassLoaderReferenceCommandSet
|
||||
extends CommandSet
|
||||
{
|
||||
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
|
||||
throws JdwpException
|
||||
{
|
||||
|
||||
// Although there's only a single command to choose from we still use
|
||||
// a switch to maintain consistency with the rest of the CommandSets
|
||||
try
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case JdwpConstants.CommandSet.ClassLoaderReference.VISIBLE_CLASSES:
|
||||
executeVisibleClasses(bb, os);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("Command " + command +
|
||||
" not found in ClassLoaderReference Command Set.");
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// The DataOutputStream we're using isn't talking to a socket at all
|
||||
// So if we throw an IOException we're in serious trouble
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void executeVisibleClasses(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ObjectId oId = idMan.readObjectId(bb);
|
||||
ClassLoader cl = (ClassLoader) oId.getObject();
|
||||
ArrayList loadRequests = VMVirtualMachine.getLoadRequests(cl);
|
||||
os.writeInt(loadRequests.size());
|
||||
for (Iterator iter = loadRequests.iterator(); iter.hasNext();)
|
||||
{
|
||||
Class clazz = (Class)iter.next();
|
||||
ReferenceTypeId refId = idMan.getReferenceTypeId(clazz);
|
||||
refId.writeTagged(os);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
/* ClassObjectReferenceCommandSet.java -- class to implement the
|
||||
ClassObjectReference Command Set
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
|
||||
import gnu.classpath.jdwp.exception.NotImplementedException;
|
||||
import gnu.classpath.jdwp.id.ObjectId;
|
||||
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A class representing the ClassObjectReference Command Set.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public class ClassObjectReferenceCommandSet
|
||||
extends CommandSet
|
||||
{
|
||||
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
|
||||
throws JdwpException
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case JdwpConstants.CommandSet.ClassObjectReference.REFLECTED_TYPE:
|
||||
executeReflectedType(bb, os);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("Command " + command +
|
||||
" not found in ClassObject Reference Command Set.");
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// The DataOutputStream we're using isn't talking to a socket at all
|
||||
// So if we throw an IOException we're in serious trouble
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void executeReflectedType(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ObjectId oid = idMan.readObjectId(bb);
|
||||
Class clazz = (Class) oid.getObject();
|
||||
|
||||
// The difference between a ClassObjectId and a ReferenceTypeId is one is
|
||||
// stored as an ObjectId and the other as a ReferenceTypeId.
|
||||
ReferenceTypeId refId = idMan.getReferenceTypeId(clazz);
|
||||
refId.writeTagged(os);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,218 @@
|
|||
/* ClassTypeCommandSet.java -- class to implement the ClassType
|
||||
Command Set
|
||||
Copyright (C) 2005 Free Software Foundation
|
||||
|
||||
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
|
||||
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.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.VMVirtualMachine;
|
||||
import gnu.classpath.jdwp.exception.InvalidFieldException;
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
|
||||
import gnu.classpath.jdwp.exception.NotImplementedException;
|
||||
import gnu.classpath.jdwp.id.ObjectId;
|
||||
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
||||
import gnu.classpath.jdwp.util.MethodResult;
|
||||
import gnu.classpath.jdwp.util.Value;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A class representing the ClassType Command Set.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public class ClassTypeCommandSet
|
||||
extends CommandSet
|
||||
{
|
||||
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
|
||||
throws JdwpException
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case JdwpConstants.CommandSet.ClassType.SUPERCLASS:
|
||||
executeSuperclass(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ClassType.SET_VALUES:
|
||||
executeSetValues(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ClassType.INVOKE_METHOD:
|
||||
executeInvokeMethod(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ClassType.NEW_INSTANCE:
|
||||
executeNewInstance(bb, os);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("Command " + command +
|
||||
" not found in ClassType Command Set.");
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// The DataOutputStream we're using isn't talking to a socket at all
|
||||
// So if we throw an IOException we're in serious trouble
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void executeSuperclass(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
Class clazz = refId.getType();
|
||||
Class superClazz = clazz.getSuperclass();
|
||||
|
||||
ReferenceTypeId clazzId = idMan.getReferenceTypeId(superClazz);
|
||||
clazzId.write(os);
|
||||
}
|
||||
|
||||
private void executeSetValues(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
|
||||
// We don't actually seem to need this...
|
||||
Class clazz = refId.getType();
|
||||
|
||||
int numValues = bb.getInt();
|
||||
|
||||
for (int i = 0; i < numValues; i++)
|
||||
{
|
||||
ObjectId fieldId = idMan.readObjectId(bb);
|
||||
Field field = (Field) (fieldId.getObject());
|
||||
Object value = Value.getUntaggedObj(bb, field.getType());
|
||||
try
|
||||
{
|
||||
field.setAccessible(true); // Might be a private field
|
||||
field.set(null, value);
|
||||
}
|
||||
catch (IllegalArgumentException ex)
|
||||
{
|
||||
throw new InvalidFieldException(ex);
|
||||
}
|
||||
catch (IllegalAccessException ex)
|
||||
{ // Since we set it as accessible this really shouldn't happen
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void executeInvokeMethod(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
MethodResult mr = invokeMethod(bb);
|
||||
|
||||
Object value = mr.getReturnedValue();
|
||||
Exception exception = mr.getThrownException();
|
||||
ObjectId eId = idMan.getObjectId(exception);
|
||||
|
||||
Value.writeTaggedValue(os, value);
|
||||
eId.writeTagged(os);
|
||||
}
|
||||
|
||||
private void executeNewInstance(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
MethodResult mr = invokeMethod(bb);
|
||||
|
||||
Object obj = mr.getReturnedValue();
|
||||
ObjectId oId = idMan.getObjectId(obj);
|
||||
Exception exception = mr.getThrownException();
|
||||
ObjectId eId = idMan.getObjectId(exception);
|
||||
|
||||
oId.writeTagged(os);
|
||||
eId.writeTagged(os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the static method and return the resulting MethodResult.
|
||||
*/
|
||||
private MethodResult invokeMethod(ByteBuffer bb) throws JdwpException,
|
||||
IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
Class clazz = refId.getType();
|
||||
|
||||
ObjectId tId = idMan.readObjectId(bb);
|
||||
Thread thread = (Thread) tId.getObject();
|
||||
|
||||
ObjectId mId = idMan.readObjectId(bb);
|
||||
Method method = (Method) mId.getObject();
|
||||
|
||||
int args = bb.getInt();
|
||||
Object[] values = new Object[args];
|
||||
|
||||
for (int i = 0; i < args; i++)
|
||||
{
|
||||
values[i] = Value.getObj(bb);
|
||||
}
|
||||
|
||||
int invokeOpts = bb.getInt();
|
||||
boolean suspend = ((invokeOpts
|
||||
& JdwpConstants.InvokeOptions.INVOKE_SINGLE_THREADED)
|
||||
!= 0);
|
||||
try
|
||||
{
|
||||
if (suspend)
|
||||
VMVirtualMachine.suspendAllThreads ();
|
||||
|
||||
MethodResult mr = VMVirtualMachine.executeMethod(null, thread,
|
||||
clazz, method,
|
||||
values, false);
|
||||
if (suspend)
|
||||
VMVirtualMachine.resumeAllThreads ();
|
||||
|
||||
return mr;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (suspend)
|
||||
VMVirtualMachine.resumeAllThreads ();
|
||||
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue