1 5 package SOFA.SOFAnode.InOut.Impl; 6 7 import javax.swing.JTextArea ; 8 import javax.swing.tree.DefaultMutableTreeNode ; 9 10 import SOFA.Connector.ConnectorException; 11 import SOFA.Connector.ConnectorTransportException; 12 import SOFA.Connector.Reference; 13 import SOFA.SOFAnode.InOut.Bundle; 14 import SOFA.SOFAnode.InOut.InOut2Client; 15 import SOFA.SOFAnode.InOut.Connector.InOut2ClientConnector; 16 import SOFA.SOFAnode.TR.ComponentInfo; 17 18 23 class SOFANode { 24 27 private String name = null; 28 29 32 private Reference reference = null; 33 34 38 private InOut2Client inOut = null; 39 40 43 private ComponentInfo[] components = null; 44 45 48 private JTextArea messages = null; 49 50 56 SOFANode (String name, String ref, JTextArea messages) { 57 this.name = name; 58 reference = Reference.fromString(ref); 59 this.messages = messages; 60 } 61 62 67 private void _connect () { 68 try { 69 inOut = (InOut2Client) InOut2ClientConnector.createClt(reference); 70 messages.append("A connection to '" + name + "' has been made successfully.\n"); 71 } catch (ConnectorException e) { 72 messages.append("When connecting to '" + name + "', the following exception was thrown:\n" + e + "\n"); 73 inOut = null; 74 components = null; 75 } 76 } 77 78 84 DefaultMutableTreeNode connect (DefaultMutableTreeNode root) { 85 _connect(); 86 DefaultMutableTreeNode tNode = new DefaultMutableTreeNode (this, inOut != null); root.add(tNode); 88 return tNode; 89 } 90 91 97 DefaultMutableTreeNode reconnect (DefaultMutableTreeNode tNode) { 98 _connect(); 99 tNode = new DefaultMutableTreeNode (this, inOut != null); return tNode; 102 } 103 104 111 void list (DefaultMutableTreeNode tNode) { 112 tNode.removeAllChildren(); 113 if (isConnected()) { 114 Bundle bundle; 115 try { 116 bundle = inOut.list(); 117 } catch (ConnectorTransportException e) { 118 messages.append("When listing components on the SOFA node '" + name + "', the following exception was thrown:\n" + e + "\n"); 119 inOut = null; 120 return; 121 } 122 components = bundle.getComponents(); 123 if (components.length > 0) { 124 tNode.setAllowsChildren(true); 125 for (int i = 0; i < components.length; i++) { 126 ComponentInfo info = components[i]; 127 tNode.add(new DefaultMutableTreeNode (info)); 128 } 129 } 130 } 131 } 132 133 137 boolean isConnected () { 138 return inOut != null; 139 } 140 141 146 public String toString () { 147 return name + ((isConnected()) ? "" : " - not accessible"); 148 } 149 150 154 String getName () { 155 return name; 156 } 157 158 162 Reference getReference () { 163 return reference; 164 } 165 166 170 InOut2Client getInOut () { 171 return inOut; 172 } 173 174 178 ComponentInfo[] getComponents () { 179 return components; 180 } 181 182 } 183 | Popular Tags |