1 23 24 package org.objectweb.fractal.gui.admin.control; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 import org.objectweb.fractal.gui.model.Component; 28 import org.objectweb.fractal.gui.model.Configuration; 29 import org.objectweb.fractal.swing.AbstractAction; 30 import org.objectweb.fractal.gui.admin.model.AdminModel; 31 import org.objectweb.fractal.gui.selection.model.Selection; 32 import org.objectweb.fractal.gui.selection.model.SelectionListener; 33 import org.objectweb.fractal.rmi.registry.*; 34 35 import org.objectweb.fractal.util.Fractal; 36 37 import java.awt.event.ActionEvent ; 38 import java.net.URL ; 39 40 import javax.swing.ImageIcon ; 41 import javax.swing.KeyStroke ; 42 import javax.swing.JOptionPane ; 43 44 47 48 public class CreateInstanceAction extends AbstractAction 49 implements BindingController, SelectionListener 50 { 51 55 56 public final static String CONFIGURATION_BINDING = "configuration"; 57 58 62 63 public final static String ADMIN_MODEL_BINDING = "admin-model"; 64 65 68 69 public final static String SELECTION_BINDING = "selection"; 70 71 74 75 private Configuration configuration; 76 77 80 81 private AdminModel adminmodel; 82 83 86 87 private Selection selection; 88 89 90 93 94 public CreateInstanceAction () { 95 putValue(NAME, "Create Instance"); 96 putValue(SHORT_DESCRIPTION, "CreateInstance"); 97 URL url = getClass().getResource( 98 "/org/objectweb/fractal/gui/resources/empty.gif"); 99 putValue(SMALL_ICON, new ImageIcon (url)); 100 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control shift C")); 101 } 102 103 107 public String [] listFc () { 108 return new String [] { 109 CONFIGURATION_BINDING, 110 ADMIN_MODEL_BINDING, 111 SELECTION_BINDING 112 }; 113 } 114 115 public Object lookupFc (final String clientItfName) { 116 if (CONFIGURATION_BINDING.equals(clientItfName)) { 117 return configuration; 118 } else if (ADMIN_MODEL_BINDING.equals(clientItfName)) { 119 return adminmodel; 120 } else if (SELECTION_BINDING.equals(clientItfName)) { 121 return selection; 122 } 123 return null; 124 } 125 126 public void bindFc (final String clientItfName, final Object serverItf) { 127 if (CONFIGURATION_BINDING.equals(clientItfName)) { 128 configuration = (Configuration)serverItf; 129 } else if (ADMIN_MODEL_BINDING.equals(clientItfName)) { 130 adminmodel = (AdminModel)serverItf; 131 } else if (SELECTION_BINDING.equals(clientItfName)) { 132 selection = (Selection)serverItf; 133 } 134 } 135 136 public void unbindFc (final String clientItfName) { 137 if (CONFIGURATION_BINDING.equals(clientItfName)) { 138 configuration = null; 139 } else if (ADMIN_MODEL_BINDING.equals(clientItfName)) { 140 adminmodel = null; 141 } else if (SELECTION_BINDING.equals(clientItfName)) { 142 selection = null; 143 } 144 } 145 146 150 public void selectionChanged () { 151 Object o = selection.getSelection(); 152 if (o instanceof Component) { 153 setEnabled (true); 154 } else { 155 setEnabled(false); 156 } 157 } 158 159 163 public void actionPerformed (final ActionEvent e) { 164 165 Object o = selection.getSelection(); 166 167 String classpath = System.getProperty("java.class.path"); 168 170 try { 171 if (o instanceof Component) { 172 Component c = (Component)o; 173 174 org.objectweb.fractal.api.Component boot = null; 175 176 String rmi_url = "localhost"; 177 String port = null; 178 String name = "localhost"; 179 Integer in = new Integer (1234); 180 String oneMoreTime = ""; 181 String debut = "P"; 182 while (true) { 183 String input = (String )JOptionPane.showInputDialog ( 184 null, 185 "TODO", 186 debut+"lease input "+oneMoreTime+"the URL for wished registry"+"\n machine (host:port/name)", 187 JOptionPane.QUESTION_MESSAGE, 188 null, 189 null, 190 rmi_url+":1234/"+name); 191 if (input != null) { 192 int ina = input.indexOf(':'); 193 int inb = input.indexOf('/'); 194 if ((ina < 1) || (inb < ina)) { 195 oneMoreTime = "AGAIN "; 196 debut = "ERROR : p"; 197 continue; 198 } 199 rmi_url = input.substring(0, ina); 200 name = input.substring(inb+1); 201 port = input.substring(ina+1, inb); 202 in = new Integer (port); 203 if (in.intValue() < 80) { 204 oneMoreTime = "AGAIN "; 205 debut = "ERROR port number : p"; 206 continue; 207 } 208 209 if ((rmi_url.equals("localhost")) && 210 (port.equals("1234")) && 211 (name.equals("localhost"))) { 212 boot = Fractal.getBootstrapComponent(); 213 } 214 else { 215 NamingService ns = Registry.getRegistry (rmi_url, in.intValue()); 216 boot = ns.lookup (name); 217 } 218 } 219 else { return; } 220 break; 221 } 222 223 try { 224 adminmodel.createInstance (c, boot); 225 } catch (Exception ex) { 226 JOptionPane.showMessageDialog ( 227 null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 228 return; 229 } 230 } 231 } catch (Exception ex) { 232 JOptionPane.showMessageDialog ( 233 null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 234 } 235 } 236 } 237 238 | Popular Tags |