1 26 package org.objectweb.openccm.explorer.CosNaming; 27 28 import org.objectweb.util.explorer.api.MenuItem; 29 import org.objectweb.util.explorer.api.MenuItemTreeView; 30 import org.objectweb.util.explorer.api.TreeView; 31 import org.objectweb.util.explorer.swing.gui.api.DialogAction; 32 import org.objectweb.util.explorer.swing.gui.api.DialogBox; 33 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox; 34 import org.objectweb.util.explorer.swing.gui.lib.LabelBox; 35 import org.omg.CosNaming.NamingContextExt ; 36 import org.omg.CosNaming.NamingContext ; 37 import org.omg.CosNaming.NameComponent ; 38 39 46 public class BindNewContextAction 47 implements MenuItem, DialogAction { 48 49 55 56 protected DialogBox dialog_; 57 58 59 protected NamingContextExt namingContext_ = null; 60 61 62 protected LabelBox name_ = null; 63 64 70 76 82 85 public int getStatus(TreeView treeView) { 86 return MenuItem.ENABLED_STATUS; 87 } 88 89 92 public void actionPerformed(MenuItemTreeView e) { 93 namingContext_ = (NamingContextExt ) e.getSelectedObject(); 94 dialog_ = new DefaultDialogBox("Binds a new context into the NameService"); 95 name_ = new LabelBox("Context name"); 96 dialog_.addElementBox(name_); 97 dialog_.setValidateAction(this); 98 dialog_.show(); 99 } 100 101 107 110 public void executeAction() throws Exception { 111 NameComponent [] names = namingContext_.to_name(name_.getLabel()); 112 NamingContext namingContext = namingContext_; 113 for (int i = 0 ; i < names.length ; i++) { 114 NameComponent [] currentNameComponent = new NameComponent []{names[i]}; 115 NamingContext newNamingContext = null; 116 try { 117 newNamingContext = namingContext.bind_new_context(currentNameComponent); 118 } catch(org.omg.CosNaming.NamingContextPackage.AlreadyBound e){ 119 newNamingContext = org.omg.CosNaming.NamingContextExtHelper.narrow(namingContext.resolve(currentNameComponent)); 121 } 122 namingContext = newNamingContext; 123 } 124 } 125 } | Popular Tags |