1 28 29 package ist.coach.coachEmfServicesComponents.SnmpAdapterProviderComposition ; 30 31 import ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError ; 33 import ist.coach.coachEmfCommon.Utils; 34 import ist.coach.coachEmfCommon.ExceptionMessages; 35 36 import org.omg.CosNaming.NameComponent ; 37 38 import java.util.LinkedList ; 39 import java.util.ListIterator ; 40 41 42 48 public class configSegImpl 49 extends ist.coach.coachEmfServicesComponents.SnmpAdapterProviderComposition.configSeg 50 { 51 57 63 public configSegImpl() 64 { 65 } 66 private boolean nameExists(NameComponent [] name) { 72 73 ListIterator li = SnmpAdapterProviderImpl.linkedList.listIterator(); 74 75 while (li.hasNext()) { 76 SnmpObjectData objData = (SnmpObjectData) li.next(); 77 if (objData.getName().equals(name)) { 78 return true; 79 } 80 } 81 return false; 82 } 83 84 private boolean rootObjectExists(String ipAddress, 85 NameComponent [] name) { 86 87 ListIterator li = SnmpAdapterProviderImpl.linkedList.listIterator(); 88 89 while (li.hasNext()) { 90 91 SnmpObjectData objData = (SnmpObjectData)li.next(); 92 95 if (objData.getIPAddress().equals(ipAddress) && 96 SnmpAdapterProviderImpl.isRootObject( 97 SnmpAdapterProviderImpl.getObjectClass(objData.getName())) && 98 Utils.isChild(name, objData.getName())) 99 return true; 100 } 101 102 return false; 103 } 104 105 private SnmpObjectData findObjectWithName(NameComponent [] name) { 106 107 String name_str = Utils.name2string(name); 108 109 ListIterator li = SnmpAdapterProviderImpl.linkedList.listIterator(); 110 111 SnmpObjectData objData = null; 112 113 while (li.hasNext()) { 114 objData = (SnmpObjectData) li.next(); 115 if (Utils.name2string(objData.getName()).equals(name_str)) { 116 return objData; 117 } 118 } 119 return null; 120 } 121 127 130 public void 131 registerIP(org.omg.CosNaming.NameComponent [] name, String ipAddress) 132 throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError 133 { 134 if (nameExists (name)) { 138 System.err.println("Could not register object with Name " + 139 Utils.name2string(name) + " because it already exists!"); 140 throw new SnmpApplicationError(ExceptionMessages.snmp_register_error); 141 142 } 143 else { 144 SnmpObjectData objData = new SnmpObjectData (name, ipAddress); 145 synchronized(SnmpAdapterProviderImpl.linkedList) { 146 SnmpAdapterProviderImpl.linkedList.add(objData); 147 } 148 } 151 } 152 153 156 public void 157 registerValue(org.omg.CosNaming.NameComponent [] name, String ipAddress, org.omg.CORBA.Any value) 158 throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError 159 { 160 if (nameExists (name)) { 166 System.err.println("SNMPAdapter:registerValue> Could not register object with Name " 167 + Utils.name2string(name) + " because it already exists!"); 168 throw new SnmpApplicationError(ExceptionMessages.snmp_register_error); 169 } 170 else 171 if (rootObjectExists(ipAddress, name) == false) { 172 System.err.println("SNMPAdapter:registerValue> Could not find parent for this object."); 173 throw new SnmpApplicationError(ExceptionMessages.snmp_superior_error); 174 } 175 else { 176 SnmpObjectData objData = new SnmpObjectData (name, ipAddress, value); 177 synchronized(SnmpAdapterProviderImpl.linkedList) { 178 SnmpAdapterProviderImpl.linkedList.add(objData); 179 } 180 } 182 } 183 184 187 public void 188 unregister(org.omg.CosNaming.NameComponent [] name) 189 throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError 190 { 191 195 SnmpObjectData objData = null; 196 197 if ((objData = findObjectWithName(name)) != null) { 198 synchronized(SnmpAdapterProviderImpl.linkedList) { 199 SnmpAdapterProviderImpl.linkedList.remove(objData); 200 } 201 System.err.println("SnmpAdapter:unregister>Unregistered object with name " + Utils.name2string(name)); 202 } 203 else { 204 System.err.println("SnmpAdapter:unregister>Could not unregister object with name " + Utils.name2string(name)); 205 throw new SnmpApplicationError(ExceptionMessages.snmp_unregister_error); 206 } 207 } 208 209 } 210 | Popular Tags |