1 package org.sapia.soto.config; 2 3 import org.sapia.soto.Debug; 4 import org.sapia.soto.Layer; 5 import org.sapia.soto.Service; 6 import org.sapia.soto.ServiceMetaData; 7 import org.sapia.soto.SotoContainer; 8 9 import org.sapia.util.xml.confix.ConfigurationException; 10 import org.sapia.util.xml.confix.ObjectCreationCallback; 11 import org.sapia.util.xml.confix.ObjectHandlerIF; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 17 27 public class ServiceTag implements ObjectHandlerIF, ObjectCreationCallback { 28 private Service _service; 29 private ServiceMetaData _meta; 30 private String _id; 31 private SotoContainer _cont; 32 private List _services; 33 private List _layers = new ArrayList (); 34 35 38 public ServiceTag(SotoContainer cont, List services) { 39 _cont = cont; 40 _services = services; 41 } 42 43 public Service getService() { 44 return _service; 45 } 46 47 public void setId(String id) { 48 _id = id; 49 } 50 51 public String getId() { 52 return _id; 53 } 54 55 58 public Object onCreate() throws ConfigurationException { 59 if (_service == null) { 60 throw new ConfigurationException("Service instance not specified"); 61 } 62 63 try { 64 _meta = new ServiceMetaData(_id, _service, _layers); 65 _meta.init(); 66 _services.add(this); 67 68 if (_id != null) { 69 _cont.bind(_meta); 70 } 71 72 return _service; 73 } catch (Exception e) { 74 throw new ConfigurationException("Could not initialize service", e); 75 } 76 } 77 78 public ServiceMetaData getServiceMetaData() { 79 return _meta; 80 } 81 82 85 public void handleObject(String name, Object obj) 86 throws ConfigurationException { 87 if (obj instanceof Service) { 88 if (_service != null) { 89 throw new ConfigurationException("Service already defined"); 90 } 91 92 _service = (Service) obj; 93 } else if (obj instanceof Layer) { 94 if (_service == null) { 95 throw new ConfigurationException( 96 "Service instance must be declared before layer"); 97 } 98 99 _layers.add(obj); 100 } else { 101 Class [] interfaces = obj.getClass().getInterfaces(); 102 String ifs = ""; 103 104 for (int i = 0; i < interfaces.length; i++) { 105 ifs = ifs + interfaces.getClass().getName() + ", "; 106 } 107 108 if(Debug.DEBUG){ 109 Debug.debug("===========> " + ifs); 110 Debug.debug("===========> " + 111 Thread.currentThread().getContextClassLoader()); 112 } 113 throw new ConfigurationException( 114 "Service or layer instance expected; received " + 115 obj.getClass().getName() + " for element: " + name + " - " + ifs); 116 } 117 } 118 } 119 | Popular Tags |