1 26 package org.objectweb.openccm.explorer.CosNaming; 27 28 import java.awt.Dimension ; 29 import java.io.BufferedReader ; 30 import java.io.File ; 31 import java.io.FileReader ; 32 33 import org.objectweb.openccm.explorer.menu.JFileChooserSingleton; 34 import org.objectweb.openccm.explorer.menu.OpenCCMBrowserConstants; 35 import org.objectweb.openccm.explorer.menu.TreeDialogSingleton; 36 import org.objectweb.util.explorer.api.MenuItem; 37 import org.objectweb.util.explorer.api.MenuItemTreeView; 38 import org.objectweb.util.explorer.api.TreeView; 39 import org.objectweb.util.explorer.swing.gui.api.DialogAction; 40 import org.objectweb.util.explorer.swing.gui.api.DialogBox; 41 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox; 42 import org.objectweb.util.explorer.swing.gui.lib.FileChooserBox; 43 import org.objectweb.util.explorer.swing.gui.lib.LabelBox; 44 import org.objectweb.util.explorer.swing.gui.lib.TreeBox; 45 import org.omg.CORBA.ORB ; 46 import org.omg.CosNaming.NamingContextExt ; 47 48 54 public class BindObject 55 implements MenuItem, DialogAction 56 { 57 58 64 65 protected DialogBox dialog_; 66 67 68 protected NamingContextExt namingContext_ = null; 69 70 71 protected LabelBox name_ = null; 72 73 74 protected FileChooserBox iorFile_ = null; 75 76 77 protected TreeBox tree_ = null; 78 79 85 91 94 protected void bind(NamingContextExt naming, String id, org.omg.CORBA.Object o) { 95 try { 96 naming.rebind(naming.to_name(id), o); 97 } catch (org.omg.CosNaming.NamingContextPackage.NotFound e) { 98 System.out.println(getClass().getName() + " : Object Not Found Exception !"); 99 } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) { 100 System.out.println(getClass().getName() + " : CannotProceed Exception"); 101 } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) { 102 System.out.println(getClass().getName() + " : InvalidName Exception"); 103 } 104 } 105 106 109 protected void createBox() { 110 name_ = new LabelBox("Object's name"); 111 dialog_.addElementBox(name_); 112 iorFile_ = new FileChooserBox("IOR file",JFileChooserSingleton.getInstance(OpenCCMBrowserConstants.IOR_FILE_CHOOSER),false); 113 dialog_.addElementBox(iorFile_); 114 tree_ = new TreeBox(TreeDialogSingleton.getInstance(),false); 115 tree_.setPreferredSize(new Dimension (350, 150)); 116 dialog_.addElementBox(tree_); 117 } 118 119 125 128 public int getStatus(TreeView treeView) { 129 return MenuItem.ENABLED_STATUS; 130 } 131 132 135 public void actionPerformed(MenuItemTreeView e) { 136 namingContext_ = (NamingContextExt ) e.getSelectedObject(); 137 dialog_ = new DefaultDialogBox("Binds an object into the NameService"); 138 createBox(); 139 dialog_.setValidateAction(this); 140 dialog_.show(); 141 } 142 143 149 152 public void executeAction() throws Exception { 153 File file = iorFile_.getFile(); 154 Object selectedObject = tree_.getObject(); 155 org.omg.CORBA.Object object = null; 156 if (file != null) { 157 String ior = null; 158 try { 159 BufferedReader in = new BufferedReader (new FileReader (file)); 160 ior = in.readLine(); 161 } catch (java.io.FileNotFoundException err) { 162 System.out.println(file + " : File not found !"); 163 } catch (java.io.IOException err) { 164 System.out.println(file + " : Error while reading !"); 165 } 166 if (ior != null && ior.startsWith("IOR:")) { 167 ORB orb = org.objectweb.openccm.corba.TheORB.getORB(); 168 object = orb.string_to_object(ior); 169 } 170 } else if (selectedObject != null) { 171 try { 172 object = (org.omg.CORBA.Object ) selectedObject; 173 } catch (ClassCastException e1) { 174 throw new Exception ("You must select a org.omg.CORBA.Object \n Found : " + selectedObject.getClass().getName()); 175 } 176 } 177 if (object != null) 178 bind(namingContext_, name_.getLabel(), object); 179 else 180 throw new Exception ("The valid object to bind is expected !"); 181 } 182 } 183 | Popular Tags |