Listing 1.
//
// File : ObjectBrowser.java
// This file contains implementation of following classes
// 1. ObjectBrowser
// copyright 1999: ABCOM Information Systems
Pvt. Ltd., All
rights reserved.
//
import java.awt.;
import java.awt.event.;
import com.sun.java.swing.;
import com.sun.java.swing.event.;
import org.omg.CosNaming.;
import org.omg.CORBA.;
import org.omg.CORBA.InterfaceDefPackage.;
//
// Class implemented : ObjectBrowser
// Derived from : JFrame
// Implements : ActionListener,MouseListener
// Description :
// This class implements the base class of
the Object Browser. It forms
the front
// end of the Object Browser, all other classes are called from here.
//
public class ObjectBrowser extends JFrame
{
// the input panel contains the object name (text field),
// the "Introspect" button and the "EXIT" button.
private InputPanel inputPanel = new
InputPanel(this);
// the ouput panel is enabled once an object has been found.
// displays the attributes and the operations of the object.
public OutputPanel outputPanel = new
OutputPanel(this);
//this bar dsplays the status of the browser.
private StatusBar statusBar = new StatusBar("not
connected ");
// reference to backend.
public BackEnd backEnd = new BackEnd(this);
//constructor for the frame.
// 1. display the user interface.
// 2. Initialize the back end.
public ObjectBrowser()
{
super("CORBA Object Browser");
//initialise the front end.
init();
// set the size of the application frame
java.awt.Dimension d = getToolkit().getScreenSize();
setSize((d.width),(d.height2/3));
if (backEnd.init())
setStatus ("Intialization successful");
else
setStatus ("Initialization failed");
}
//
// main entry point for the application
//
public static void main(String args[])
{
// display the Obejct browser user interface
ObjectBrowser maindisplay = new ObjectBrowser();
maindisplay.setVisible(true);
}
//
// provide user interface of the application
//
public void init()
{
// get a reference to the frames content pane
JComponent displayPane = (JComponent)
this.getContentPane();
// set layout manager
displayPane.setLayout(new BorderLayout());
//add input panel to frame.
displayPane.add(inputPanel,BorderLayout.NORTH);
//add the outputpanel
displayPane.add(outputPanel,BorderLayout.CENTER);
//add the status bar
displayPane.add(statusBar,BorderLayout.SOUTH);
// Initialization complete.
setStatus("Ready");
} // end of init method.
//
// resolveAndIntrospect method performs two operations
// 1. resolve
// 2. introspect
(provided
resolve succeeds)
//
public void resolveAndIntrospect(String name)
{
setStatus ("Trying to resolve Object: "+name);
if (backEnd.resolve(name))
{
// object located.
setStatus ("Object "+ name
+ " found - RESOLVE
SUCCESSFUL");
//clear the output panel.
//clear the text area.
outputPanel.clearListing();
// introspect the object.
backEnd.introspect();
//refresh the display.
repaint();
}
else // object not found.
setStatus ("Object not found");
} // end ofResolve and Introspect.
//
// method to set setStatus in the status bar.
//
public void setStatus(String s)
{
// display a message in the status bar.
statusBar.SetText(s);
}
}// end of the main class ObjectBrowser
Listing 2.
//
// File : InputPanel.java
// This file contains implementation of following classes
// 1. InputPanel
// copyright 1999: ABCOM Information Systems
Pvt. Ltd., All
rights reserved.
//
import java.awt.;
import java.awt.event.;
import com.sun.java.swing.;
//
// Class implemented : InputPanel
// Derived from : JPanel
// Implements : ActionListener
// Description :
// This class implements the user input area in the main user interface
//
public class InputPanel extends JPanel implements ActionListener
{
// define the components
// 1. text field : ObjectName
// 2. exit button
// 3. introspect button
private JTextField ObjectName = new JTextField(40);
private JButton Introspect = new JButton("Introspect");
private JButton Exit = new JButton("Exit");
private ObjectBrowser objectBrowser;
//
// constructor
//
public InputPanel(ObjectBrowser objectBrowser)
{
this.objectBrowser = objectBrowser;
// put both the button into a panel so that
// they get displayed vertically
JPanel choicePanel = new JPanel();
choicePanel.setLayout(new GridLayout(2,1));
choicePanel.add(Introspect);
choicePanel.add(Exit);
// add to Panel
add(ObjectName);
add(choicePanel);
Introspect.addActionListener(this);
Exit.addActionListener(this);
}
//
// Process button clicks
// if INTROSPECT clicked 1. Locate the object
//
2.
display its IDL listing.
// if Exit clicked : quit the application
//
public void actionPerformed (ActionEvent e)
{
if (e.getSource() == Introspect)
{
// check if the text field is blank.
if (!(ObjectName.getText()).equals(""))
{
//perform the introspect
operation.
objectBrowser.resolveAndIntrospect(ObjectName.getText());
}
// else show error message
else
//
name is not entered.
{
objectBrowser.setStatus
("Please ENTER NAME
OF OBJECT");
}
}
// if exit chosen :
shut down.
if (e.getSource() == Exit )
{
objectBrowser.setStatus("Shutting Down ......");
objectBrowser.dispose();
System.exit(0);
}
}
}
Listing 3.
//
// File : OutputPanel.java
// This file contains implementation of following classes
// 1. OutputPanel
// copyright 1998: ABCOM Information Systems
Pvt. Ltd., All
rights reserved.
//
import com.sun.java.swing.event.;
import com.sun.java.swing.event.ListSelectionListener;
import com.sun.java.swing.;
import java.awt.;
import java.awt.event.;
import OperationDescriptionTable;
import AttributeDescription;
//
// Class implemented : OutputPanel
// Derived from : JTabbedPane
// Implements : ListSelectionListener
// Description :
// This class creates the area where the ObjectBrowser dumps the results
// of introspection. i.e. the Interface Listing
and the
Attribute/Operation Lists.
//
public class OutputPanel extends JTabbedPane
implements ListSelectionListener
{
private JList attributeList = new JList();
// list to display
attributes
private JList operationList = new JList();
// list to display
operations
private JTextArea listing;
// for IDL listing
private Box attributes;
private Box operations;
private ObjectBrowser objectBrowser;
private JPanel jpanel;
//
// constructor
//
public OutputPanel(ObjectBrowser objectBrowser)
{
setTabPlacement(SwingConstants.TOP);
this.objectBrowser = objectBrowser;
init();
}
//
// intialize the panel
//
private void init()
{
// create and add the text area to
the tabbed pane.
listing = new JTextArea();
listing.setEditable (false);
// scroll pane for scrolling up down IDL listing.
JScrollPane scrollPane = new JScrollPane(listing);
addTab("Interface Definition", scrollPane);
// The next tabbed pane will contain the operation and
// attribute list in two boxes arranged in a panel.
jpanel = new JPanel(new BorderLayout());
jpanel.setBackground( Color.white );
// create the attributes box
attributes = Box.createVerticalBox();
// add label to the box.
attributes.add(new JLabel("Attributes"));
attributes.add(attributeList);
// add the box to the panel.
jpanel.add(attributes, "East");
// create operations box.
operations = Box.createVerticalBox();
// add label to the box
operations.add(new JLabel("Operations"));
operations.add(operationList);
// add box to the panel.
jpanel.add(operations, "West");
// Add ListSelection listeners to the two lists.
attributeList.addListSelectionListener( this );
operationList.addListSelectionListener(
this );
//display the second pane using the panel.
addTab("Operation and Attribute Listing",
jpanel);
}
//
// add data to the text area control
//
public void setListing(String text)
{
//add the data
listing.append(text);
}
//
// clear the text area control
//
public void clearListing()
{
listing.setText("");
}
//
// updateList method receives two parameters. The first parameter
// supplies data in form of Vector which is added to the JList
// control. The second parameter specifies which JList control to
// be used.
//
public void updateList(java.util.Vector listData, String whichOne )
{
//check if operations list.
if (whichOne == "operations")
{
// clear the list
operationList.removeAll();
// add the data to list.
operationList.setListData (listData);
}
else
//update
the attribute list.
{
// clear the list
attributeList.removeAll();
// add the data to list.
attributeList.setListData(listData);
}
}
//
// show the properties of the attributes using
// a AttributeDescription object
//
private void showAttributeDescription(String name)
{
AttributeDescription ad;
ad = new AttributeDescription(name,objectBrowser);
ad.setVisible(true);
}
//
// show the properties of the method in a new frame
// using the OperationDescriptionTable object.
//
public void showMethodDescription(String name)
{
OperationDescriptionTable pTable;
pTable = new OperationDescriptionTable(name, objectBrowser);
pTable.setVisible(true);
}
//
// process list selection
//
public void valueChanged (ListSelectionEvent evt)
{
if (evt.getLastIndex() != -1) {
if (evt.getSource() == operationList &&
!evt.getValueIsAdjusting())
{
//get the name of the process
//using the index of selected item as index.
int j = evt.getLastIndex();
String operationName =
objectBrowser.backEnd.fullObjectInterface.operations[j].name ;
objectBrowser.setStatus(
"Showing the description
of "
+operationName);
showMethodDescription(operationName);
}
// if attribute list selected
// 1. display the attribute
description in a
frame.
if (evt.getSource() == attributeList &&
!evt.getValueIsAdjusting())
{
// display the contents of the attribute list -
// i.e. the properties of attributes
// into a new frame.
String attributeName =
(attributeList.getSelectedValue()).toString();
objectBrowser.setStatus(
"Showing description
of " +
attributeName);
showAttributeDescription(attributeName);
}
}
}
}
Listing 4.
//
// File : AttributeDescription.java
// This file contains implementation of following classes
// 1. AttributeDescription
// copyright 1999: ABCOM Information Systems
Pvt. Ltd., All
rights reserved.
//
import java.awt.;
import com.sun.java.swing.;
import java.awt.event.;
import org.omg.CORBA.;
//
// Class implemented : AttributeDescription
// Derived from : JFrame
// Implements : None
// Description :
// this class represents the frame in which the complete
// description of the attribute is displayed on being selected.
//
public class AttributeDescription extends JFrame
{
private ObjectBrowser objectBrowser;
private String attributeName;
private String type = "";
private String mode;
//
// constructor
//
public AttributeDescription(String attributeName,
ObjectBrowser objectBrowser)
{
super(attributeName);
this.attributeName = attributeName;
this.objectBrowser = objectBrowser;
init();
}
private void init()
{
getDescription();
displayFrame();
}
//
// initializes and shows the attributes frame
//
private void displayFrame()
{
// get screen dimensions and set the size for frame
Dimension d = getToolkit().getScreenSize();
setBounds(d.width/3,d.height/3,d.width/3,d.height/3);
setResizable(false);
// set the layout manager
JComponent sp = (JComponent) getContentPane();
sp.setLayout(new BorderLayout());
// add various labels and desired text
JLabel tittle = new JLabel(" Attribute Description ");
sp.add(tittle,BorderLayout.NORTH);
JPanel middle = new JPanel(new BorderLayout());
JLabel nLabel = new JLabel("Name : " + attributeName);
JLabel tLabel = new JLabel("Type : " + type);
JLabel mLabel = new JLabel("Mode : " + mode);
middle.add(nLabel,BorderLayout.NORTH);
middle.add(mLabel,BorderLayout.CENTER);
middle.add(tLabel,BorderLayout.SOUTH);
sp.add(middle,BorderLayout.CENTER);
setVisible(true);
}
//
// get the description of attributes from the full
// interface description.
//
private void getDescription()
{
int i = 0;
objectBrowser.setStatus("searching
for "+ attributeName );
// get the number of attributes
int noAttributes =
objectBrowser.backEnd.fullObjectInterface.attributes.length;
// search for attribute from the full_attribute_description .
for (; i < noAttributes ; i++)
{
if (attributeName ==
objectBrowser.backEnd.fullObjectInterface.attributes[i].name)
break;
}
mode = "";
// once found.
// display its properties .
switch
(objectBrowser.backEnd.fullObjectInterface.attributes[i].mode.value())
{
case ParameterMode._PARAM_IN
: mode = "in";
break;
case ParameterMode._PARAM_OUT
: mode = "out";
break;
case ParameterMode._PARAM_INOUT : mode
= "in-out";
break;
}
java.lang.Object obj =
(java.lang.Object)
objectBrowser.backEnd.fullObjectInterface.attributes[i].type;
type = obj.toString();
}
}
Listing 5.
//
// File : OperationDescriptionTable.java
// This file contains implementation of following classes
// 1. OperationDescriptionTable
// copyright 1999: ABCOM Information Systems
Pvt. Ltd., All
rights reserved.
//
import org.omg.CORBA.;
import org.omg.CORBA.InterfaceDefPackage.;
import java.awt.;
import java.awt.event.;
import com.sun.java.swing.;
import com.sun.java.swing.table.;
import java.util.Vector;
import com.sun.java.swing.border.;
//
// Class implemented : OperationDescriptionTable
// Derived from : JFrame
// Implements : ActionListener
// Description :
// this class does following after
// an operation has been selected from the operations list.
// 1. Displaying all the arguments
and their
properties
// 2. Accepting the input values of the parameters
//
public class OperationDescriptionTable extends JFrame
implements ActionListener
{
private JComponent cPane;
//
component pane of the display frame
private JButton Invoke,Close;
// buttons to
invoke and close
private String operationName; // name of selected operation
private Box parameterList ;
// Box for
Textfields accepting parameter values
private boolean accept[] ;
// array of
flags used to check if input is required
private JTextField[] textFieldList;
//
array used to input the text fields
private FullInterfaceDescription OBInterface1;
//reference to the
backend- the object's interface
private Vector Parameter,labels;
// vectors used for
creating list
private JTable otable = new JTable(); // table
private ObjectBrowser objectBrowser;
// reference to ObjectBrowser
class
private int noParameters;
//
no of parameters
//
// constructor.
//
public OperationDescriptionTable(String
operationName,
ObjectBrowser objectBrowser)
{
// initialization of user interface.
super ("Operation Description Table : " + operationName);
this.operationName = operationName;
this.objectBrowser = objectBrowser;
// initialize the display.
init();
}
//
// initialize the display
//
private void init()
{
Dimension d = getToolkit().getScreenSize();
setBounds(d.width/3,d.height/3,d.width/2,d.height/2);
// show the elements on this frame.
cPane = (JComponent) getContentPane();
cPane.setLayout(new BorderLayout());
//create the title bar
JLabel titlePanel = new JLabel("Please
enter the
paramerters ");
cPane.add(titlePanel,BorderLayout.NORTH);
// create a button panel for displaying
Invoke and Close
buttons
JPanel buttonPanel = new JPanel();
buttonPanel.add( Invoke = new JButton("Invoke"));
buttonPanel.add( Close = new JButton("Close"));
cPane.add(buttonPanel,BorderLayout.SOUTH);
//add actionlisteners to both the buttons.
Invoke.addActionListener(this);
Close.addActionListener(this);
//set the initial values of the variables
OBInterface1 = objectBrowser.backEnd.fullObjectInterface;
Parameter = new Vector();
int i = 0;
// compare the name of the operation with the input name
// to get the correct operation from the array.
for ( ; i < OBInterface1.operations.length;i++)
{
if (operationName.equals
(OBInterface1.operations[i].name))
break;
}
//get the no. of parameters and repeat
until j = no of
parameters.
//i.e. initialize the values of the table.
noParameters = OBInterface1.operations[i].parameters.length;
// check for no input parameters
if (noParameters == 0)
{
//display message
JLabel message = new JLabel ("No Input Parameters");
cPane.add(message, BorderLayout.CENTER);
// directly perform dii.
performDii(operationName);
}
else // there
are input
parameters
{
//Initialization the table with operation parameters
initTable(i);
// add the table object to our layout
cPane.add(otable,BorderLayout.WEST);
// add the text fields along
with table rows to
input parameters
parameterList = Box.createVerticalBox();
cPane.add(parameterList,BorderLayout.CENTER);
// create textfield objects for each parameter
textFieldList = new JTextField[otable.getRowCount()];
// SET THE label : values.
textFieldList[0] = new JTextField("Values");
textFieldList[0].setEditable(false);
// create a temp, rectangle
Rectangle rect = otable.getCellRect(1,3,false);
//match the height of the cell and the text field
textFieldList[0].setSize(rect.width,
rect.height);
parameterList.createHorizontalStrut(0);
// add to the parameter list.
parameterList.add(textFieldList[0]);
for ( int j = 1; j < otable.getRowCount(); j++)
{
//create new text field
textFieldList[j] = new JTextField(20);
//match the hieght of the
cell and the text
field
textFieldList[j].setSize(rect.width,rect.height);
parameterList.createHorizontalStrut(0);
// add the text field to the box.
parameterList.add(textFieldList[j]);
// set editable if IN or
INOUT type of
parameter
textFieldList[j].setEditable(accept[j-1]);
}
}
// add the textfield panel to our layout
cPane.add(parameterList,BorderLayout.CENTER);
} // end of init.
//
// initTable method is responsible for all the
// table initialization operations.
//
private void initTable (int i)
{
Parameter.addElement((java.lang.Object) new String("Name"));
Parameter.addElement((java.lang.Object) new String("Mode"));
Parameter.addElement((java.lang.Object)
new String("Type"));
try
{
// initialize accept to array of row length..
accept = new boolean[noParameters];
// start filling the vector with parameter properties
for (int j = 0; j < noParameters;j++)
{
// add paramter name
Parameter.addElement((java.lang.Object)
OBInterface1.operations[i].parameters[j].name);
//temp variable used to set mode in table
String mode = new String();
// set mode to appropriate
value
switch (
OBInterface1.operations[i].parameters[j].mode.value())
{
// input parameter
case ParameterMode._PARAM_IN
: mode =
"in";
accept[j] = true;
break;
// output parameter
case ParameterMode._PARAM_OUT
: mode =
"out";
accept[j] = false;
break;
// inout parameter
case ParameterMode._PARAM_INOUT
: mode =
"in-out";
accept[j] = true;
break;
}
// add mode to vector
Parameter.addElement((java.lang.Object) mode);
// add the type of element.
Parameter.addElement((java.lang.Object)new
String(""+ OBInterface1.operations[i].parameters[j].type));
} //end of adding elements into
the vector.
// create a table with these elements.
labels = new Vector();
labels.addElement((java.lang.Object)
new
String("Name"));
labels.addElement((java.lang.Object)
new
String("Mode"));
labels.addElement((java.lang.Object)
new
String("Type"));
final int rowCount = noParameters+1;
// initialise the tablemodel
TableModel model = new AbstractTableModel()
{
public int getRowCount() { return rowCount;}
public int getColumnCount() { return 3;}
public String getColumnName(int column)
{
return new String
((labels.elementAt(column)).toString());
}
public java.lang.Object
getValueAt(int
row,int column)
{
return
((java.lang.Object)Parameter.elementAt((row3)+column));
}
};
//set model
otable.setModel(model);
// create the new table using the "vector constructor"
otable = new JTable (Parameter,labels);
}
catch(Exception e) // exception BAD_KIND may arise while
{
//
operating on fullObjectInterface.
}
}
//
//invoke method from server object using DII.
//
private void performDii (String operationName)
{
// send the DII request to backend .
if (objectBrowser.backEnd.processRequest(operationName))
objectBrowser.setStatus("DII Succesful");
else
objectBrowser.setStatus("DII Failed");
}
public void actionPerformed(ActionEvent e)
{
// if Invoke is selected then ask back end to begin DII.
if (e.getSource() == Invoke)
{
//string array to store input parameters
String[] parametersValue = new
String[this.noParameters ];
// initialize the string array
with the values in
textfields
for (int j = 1; j < textFieldList.length; j++)
{
parametersValue[j-1] =
textFieldList[j].getText();
}
// call setParameters method to send the parameters
// to backEnd object for processing
objectBrowser.backEnd.setParameters(parametersValue);
//set status bar
objectBrowser.setStatus("DII invoked");
System.out.println(operationName);
performDii(operationName);
}
// close the frame.
if (e.getSource() == Close)
{
dispose();
}
}// end of actionperformed.
}
Listing 6.
//
// File : StatusBar.java
// This file contains implementation of following classes
// 1. StatusBar
// copyright 1999: ABCOM Information Systems
Pvt. Ltd., All
rights reserved.
//
import com.sun.java.swing.JLabel;
//
// Class implemented : StatusBar
// Derived from : JLabel
// Implements : None
// Description :
// This class implements the status bar for displaying the status
// information to the user.
//
public class StatusBar extends JLabel
{
private String cob;
// class constructor
public StatusBar()
{
cob = "CORBA OBJECT BROWSER :";
setText(cob);
}
// construtor that takes String argument
public StatusBar(String s)
{
cob = "CORBA OBJECT BROWSER :";
setText(cob + " " + s);
}
// modifier method for cob member
public void SetText(String s)
{
setText(cob + " " + s);
}
}
Listing 7.
//
// File : BackEnd.java
// This file contains implementation of following classes
// 1. Backend
// copyright 1999: ABCOM Information Systems
Pvt. Ltd., All
rights reserved.
//
import org.omg.CosNaming.;
import org.omg.CORBA.;
import org.omg.CORBA.InterfaceDefPackage.;
import java.awt.;
import java.awt.event.;
import com.sun.java.swing.;
import com.sun.java.swing.event.;
import java.util.;
//
// Class implemented : BackEnd
// Derived from : None
// Implements : None
// Description :
// This is the class that handles all the back end activities.
// All corba work is done in this class.
// It contains following important public Methods :
// 1. resolve()
// 2. introspect()
// 3. processRequest()
//
public class BackEnd
{
//declare variables
private org.omg.CORBA.ORB orb;
// orb object
private org.omg.CosNaming.NamingContext nameService;
private org.omg.CORBA.Object obj; // corba object for naming service
private ObjectBrowser objectBrowser;
// reference to main display
private JFrame opFrame;
// frame to display the
result of dii
private JComponent opFramePane ;
// content
pane of frame
private int noAttributes ; // no of attributes
private int noOperations ;
// no of methods in
object
// string containg the values of parameters for DII
private String[] parametersValue;
// object to describe the interface defintion
public FullInterfaceDescription fullObjectInterface
;
//
// constructor
//
public BackEnd(ObjectBrowser objectBrowser)
{
// get reference to front end.
this.objectBrowser = objectBrowser;
}
//
//method init : used for initialization.
//
public boolean init()
{
try
{
String[] param = {""};
orb = org.omg.CORBA.ORB.init (param, null);
objectBrowser.setStatus("ORB
object created
succesfully ");
// Get a reference to the Naming service
org.omg.CORBA.Object nameServiceObj
=
orb.resolve_initial_references ("NameService");
if (nameServiceObj == null)
{
objectBrowser.setStatus("ERROR
:
nameServiceObj = null");
return(false);
}
nameService =
org.omg.CosNaming.NamingContextHelper.narrow (nameServiceObj);
if (nameService == null)
{
objectBrowser.setStatus("ERROR
:
nameService = null");
return (false);
}
objectBrowser.setStatus("Naming service resolved ");
System.out.println("Initialize - Success");
return (true);
}
catch (Exception e)
{
System.out.println("unable to initialize");
objectBrowser.setStatus("Error in initialization");
return (false);
}
}
//
// sets the parameterList.
//
public void setParameters(String[] parametersValue)
{
// copy the paramters into parametersValue.
this.parametersValue = parametersValue;
}
//
// method resolve used to resolve object reference
// input parameter: String - name of object
//
public boolean resolve(String object)
{
boolean resolved = false;
// initialize using COS Naming or URL Naming Service
if (!(resolved = resolveUsingName(object)))
resolved = resolveUsingURL(object);
// if the object reference was resolved
if (resolved)
{
// object resolved.
System.out.println("Resolved
- Success");
// get the object interface defintion
InterfaceDef objIntfce = obj._get_interface();
fullObjectInterface = objIntfce.describe_interface();
objectBrowser.setStatus("interface
" +
fullObjectInterface.name + "\n");
return ( true );
}
return (false);
}
//
// resolveUsingName() method resolves any object with name service
// input parameter: String - name of object
//
private boolean resolveUsingName(String object)
{
try
{
// resolve the Count object reference
objectBrowser.setStatus("Locating
" + object + "
object");
NameComponent[] name = {new NameComponent(object,
"")};
// resolve name using namin service
obj = nameService.resolve (name);
System.out.println("Init succesful");
return (true);
}
catch (Exception e)
{
objectBrowser.setStatus
("Local Resolve failed" +
"trying to resolve using urlnaming service ");
return (false);
}
}
//
// resolveUsingURL method resolves any object with URL name service
// input parameter: String - URL + name of IOR
//
private boolean resolveUsingURL (String object)
{
try
{
//create the resolver object
org.omg.CORBA.Object resolverObj
=
orb.resolve_initial_references("URLNamingResolver");
// narrow the Object to get URL Resolver
com.visigenic.vbroker.URLNaming.Resolver
URLresolver =
com.visigenic.vbroker.URLNaming.ResolverHelper.narrow(resolverObj);
// locate object using resolver
obj = URLresolver.locate(object);
return (true);
}
catch (Exception e)
{
System.out.println("Resolve - failed" );
objectBrowser.setStatus("Unable to locate object ");
return (false);
}
}
//
// method Introspect :
// used to get the
object interface
description
// and print it
//
public boolean introspect()
{
Vector attr = new Vector();
// vector used to create
attribute list
Vector oper = new Vector(); //
used for
operations list.
try
{
final int noAttributes =
fullObjectInterface.attributes.length;
final int noOperations =
fullObjectInterface.operations.length;
// get the complete listing for
the interface and
print it in text area
objectBrowser.outputPanel.setListing("interface
" +
fullObjectInterface.name
+
"\n{\n");
//print out all the attributes
for (int i = 0; i < noAttributes ; i++)
{
// check the mode of the parameter.
String mode = new String();
switch
(fullObjectInterface.attributes[i].mode.value())
{
case ParameterMode._PARAM_IN
: mode = "in";
break;
case ParameterMode._PARAM_OUT
: mode = "out";
break;
case ParameterMode._PARAM_INOUT
: mode =
"inout";
break;
}
// this string stores the attribute definition
String strAttribute =
"\t" +
mode +
" " +
fullObjectInterface.attributes[i].type +
" " +
fullObjectInterface.attributes[i].name +
";\n\t" ;
objectBrowser.outputPanel.setListing(strAttribute);
// add element name to
the vector (for
creating list.)
attr.addElement(fullObjectInterface.attributes[i].name) ;
}
// add the elements to the attribute
list.
objectBrowser.outputPanel.updateList(attr,"attributes");
// print out the operation signature and the interface listing.
for (int i = 0; i < noOperations ; i++)
{
// string to hold the operation signature.
String signature =
fullObjectInterface.operations[i].result
+
" " +
fullObjectInterface.operations[i].name ;
signature = signature.trim();
//display result type of
method
objectBrowser.outputPanel.setListing("\n\t"+signature+"\n\t(\n");
signature = signature+"
(";
// add the parameters
String mode = new String();
for (int j=0 ;
j <
fullObjectInterface.operations[i].parameters.length;
j++)
{
// set the mode of parameter.
switch
(fullObjectInterface.operations[i].parameters[j].mode.value())
{
case ParameterMode._PARAM_IN
:
mode = "in";
break;
case ParameterMode._PARAM_OUT
:
mode = "out";
break;
case ParameterMode._PARAM_INOUT
:
mode = "in";
break;
}
// check for next line.
if (j != 0 )
{
objectBrowser.outputPanel.setListing(",\n");
signature = signature.trim();
// method (parameter1 ,<--
signature =
signature.concat(", ");
}
//string describing
the parameters
of the method.
signature = signature.trim();
String strParameter
=
"\t\t" +
mode +
" " +
fullObjectInterface.operations[i].parameters[j].type
+
" " +
fullObjectInterface.operations[i].parameters[j].name;
// add to display
objectBrowser.outputPanel.setListing("\t"+strParameter);
strParameter = strParameter.trim();
// add to signature.
signature =
signature.concat(strParameter);
signature = signature.trim();
}
// end the listing for
current method
objectBrowser.outputPanel.setListing("\n\t);\n");
// end the signature
signature = signature.concat(");");
oper.addElement(signature);
}
// add the operations to the
list.
objectBrowser.outputPanel.updateList(oper,"operations");
// print the final braces.
objectBrowser.outputPanel.setListing("}\n");
System.out.println("Introspect - Success");
objectBrowser.setStatus("Introspect - Successful");
return(true);
}//end of try
catch (Exception e)
{
System.out.println("Introspect - Failed"+e);
objectBrowser.setStatus("Introspect - failed");
return (false);
}//end of catch
} // end of introspect
//
// processRequest receives operation name as the input parameter
// and performs DII on the selected operation
//
public boolean processRequest(String
operationName)
{
try
{
System.out.println(operationName);
int i = 0;
noOperations = fullObjectInterface.operations.length;
// compare the name of the operation
with the input
name
// to obtain the index of the operation in the array.
for (i = 0 ; i < noOperations;i++)
{ String name =
fullObjectInterface.operations[i].name;
if (operationName.equals
(name)) break;
}
System.out.println(fullObjectInterface.operations[i].name);
int noParameters =
fullObjectInterface.operations[i].parameters.length;
//create the List and start adding the parameters.
NVList parameterList = orb.create_list(0);
for (int j = 0; j < noParameters;j++)
{
// create an ANY object
to replicate the
parameter.
// set the correct type
and mode and add to
the list.
Any currentParameter =
orb.create_any();
//set the type of any object
to match the
parmater type
currentParameter.type (
fullObjectInterface.operations[i].parameters[j].type);
int mode = 0;
// this flag accept is
used to indicate
values for which
// input must be accepted at runtime.
boolean accept = false;
switch (
fullObjectInterface.operations[i].parameters[j].mode.value()
)
{
case ParameterMode._PARAM_IN :
mode = org.omg.CORBA.ARG_IN.value;
accept = true;
break;
case ParameterMode._PARAM_OUT :
mode = org.omg.CORBA.ARG_OUT.value;
accept = false;
break;
case ParameterMode._PARAM_INOUT :
mode = org.omg.CORBA.ARG_INOUT.value;
accept = true;
break;
}
// input the value of the parameter.
String inputParameter =
new
String(parametersValue[j]);
// insert the correct value
of input
parameter into the ANY
// object.
if ( accept )
{
switch (
currentParameter.type().kind().value())
{
case 0 :{
//tk_null
// in this
program we consider null to be a null object
// as in
orb.init <-- init.
// Another
modification may be the null string
// for
structure references. what to do then ???
currentParameter.insert_Object( null);
break;
}
case 1 :
//tk_void
// this
type is not
implemented as we can't have void as
// the
object type
for an input partameter in Java
case 2 :{
//tk_short
currentParameter.insert_short((short)Integer.parseInt(inputParameter));
break;
}
case 4 :{
//tk_ushort
currentParameter.insert_ushort((short)Integer.parseInt(inputParameter));
break;
}
case 3 :{
//tk_long
currentParameter.insert_long(Integer.parseInt(inputParameter));
break;
}
case 5 :{
//tk_ulong
currentParameter.insert_ulong(Integer.parseInt(inputParameter));
break;
}
case 6 :{
//tk_float
currentParameter.insert_float((float)
(Float.valueOf(inputParameter)).floatValue());
break;
}
case 7 :{
//tk_double
currentParameter.insert_double((double)
(Double.valueOf(inputParameter)).doubleValue());
break;
}
case 8 :{
//tk_boolean
currentParameter.insert_boolean ((boolean)
Boolean.getBoolean(inputParameter));
break;
}
case 26:{
//tk_wchar
currentParameter.insert_wchar((char) (inputParameter).charAt(0));
break;
}
case 9 :{
//tk_char
currentParameter.insert_char((char) (inputParameter).charAt(0));
break;
}
case 10:{
//tk_octet
currentParameter.insert_octet((byte)
((inputParameter).getBytes())[0]);
break;
}
case 11:{
//tk_any
currentParameter.insert_any( currentParameter );
break;
}
case 12:{
//tk_TypeCode
// get the
type code of this parameter from its name.
currentParameter.insert_TypeCode( currentParameter.type() );
break;
}
case 13:
//tk_Principalcase
// not
implemented.
case 14:{
//tk_objref
//
Considering only CORBA Objects
//
currentParameter.insert_Object(
orb.resolve_initial_references(inputParameter));
//
break;
}
case 18:{
//tk_string
currentParameter.insert_string((java.lang.String) inputParameter);
break;
}
case 19:
//tk_sequence
case 20:
//tk_array
case 21:
//tk_alias
case 15:
//tk_struct
case 16:
//tk_union
case 17:
//tk_enum
case 22:
//tk_except
case 23:{
//tk_longlong
currentParameter.insert_longlong((long)
Long.parseLong(inputParameter));
break;
}
case 24: {
//tk_ulonglong
currentParameter.insert_longlong((long) Long.parseLong(inputParameter));
break;
}
case 27:{
//tk_wstring
currentParameter.insert_wstring((java.lang.String) inputParameter);
break;
}
case 25:
//tk_longdouble
// no
java support
for this type
case 28:
//tk_fixed
// no
java support
for this type.
}
}
//add the value to the
list.
parameterList.add_value(fullObjectInterface.operations[i].parameters[j].name,cu
rrentParameter,mode);
} // end of populating the NVLIST.
//
// status == NVLISt created and
populated
succesfully. NOW GO and INVOKE
//
// create the any object for the result field and
Any resultParameter = orb.create_any();
// set the type of object.
resultParameter.type
(fullObjectInterface.operations[i].result);
// create the NamedValue object.
org.omg.CORBA.NamedValue resultField
=
orb.create_named_value("resultField",
resultParameter,
ParameterMode._PARAM_OUT);
// create request object
Request request =
obj._create_request(
null,
fullObjectInterface.operations[i].name,
parameterList,
resultField);
// invoke it and display it on a frame.
request.invoke();
// to print out the results of DII into a frame.
opFrame = new JFrame("Dynamic
Invocation : "
+operationName );
Dimension d = opFrame.getToolkit().getScreenSize();
opFrame.setBounds(d.width/6,d.height/3,d.width2/3,d.height/3);
//get the content pane to this pane.
opFramePane = (JComponent) opFrame.getContentPane();
opFramePane.setLayout(new BorderLayout());
System.out.println("RESULT OF
DII " +
request.result().value());
opFramePane.add(
new JLabel("Result
of " +
fullObjectInterface.operations[i].name +
" : " +
request.result().value()),
BorderLayout.NORTH
);
Box middleBox = Box.createVerticalBox();
middleBox.add(new JLabel("\n"));
middleBox.add(new JLabel("Values
of Output
Arguments"));
// print out - What happened to the inputted NVList.
NVList resultList = request.arguments();
boolean empty = true;
for ( int j=0 ; j < noParameters ; j++)
{
if
((fullObjectInterface.operations[i].parameters[j].mode.value()
== ParameterMode._PARAM_OUT
) ||
(fullObjectInterface.operations[i].parameters[j].mode.value()
== ParameterMode._PARAM_INOUT ))
{
middleBox.add(new
JLabel(
resultList.item(j).name() + " : "
+ resultList.item(j).value() + "\n"));
empty = false;
}
}
System.out.println("DII Succesful");
if (empty)
middleBox.add( new JLabel("No
output
arguments"));
opFramePane.add(middleBox,BorderLayout.CENTER);
//show the opFrame..
opFrame.setVisible(true);
// end of the program.
objectBrowser.setStatus("DII Succesful");
return(true);
} // end of try loop
catch (Exception e)
{
System.out.println("DII failed"
+ e.getMessage());
objectBrowser.setStatus("DII
failed");
// notify user of error through dialog.
opFrame = new JFrame("Error");
java.awt.Dimension d =
opFrame.getToolkit().getScreenSize();
opFrame.setBounds(d.width/3,d.height/2,d.width/2,d.height/6);
opFramePane = (JComponent) opFrame.getContentPane();
opFramePane.add(
new JLabel("Unable to Complete
DII ...
please check input values"));
opFrame.setVisible(true);
return(false);
}
//end of catch
loop
}//end of method process request
}// end of backEnd
Listing 8.
javac -classpath %SWINGPATH% %1
Listing 9.
echo off
REM
REM File Implements : StartUp.bat
REM Comments :
REM Performs initialisation of IR,Visigenic Naming Service and
REM Visigenic osagent.
REM
REM start the Visigenic osagent service.
start OSAgent -c
REM initialize the Interface Repository
REM name of IR : InterfaceRepository
REM stored in file : ABCOM.ir
start irep InterfaceRepository ABCOM.ir
echo Please register IDL definition with the
IR if not yet done so.
REM Start COS Naming Service
REM name of log file : namingLog
start vbj -DORBservices=CosNaming -DSVCnameroot=ABCOM
-DJDKrenameBug
com.visigenic.vbroker.services.CosNaming.ExtFactory
ABCOM namingLog
echo start ObjectBrowser using >Show ObjectBrowser
echo
Listing 10.
vbj -DORBservices=CosNaming -DSVCnameroot=ABCOM
-VBJclasspath "%SWINGPATH%"
ObjectBrowser
Listing 11.
//
// File : Sample.idl
// copyright 1999: ABCOM Information Systems
Pvt. Ltd., All
rights reserved.
//
module Sample
{
interface Test
{
attribute float SampleValue;
float DoubleValue(in float parameter1);
void CountCharacters(in string parameter2,out
short
parameter3);
void ReverseString(inout
string parameter4);
};
};