KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > config > ServiceTag


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 JavaDoc;
14 import java.util.List JavaDoc;
15
16
17 /**
18  * This class implements the <code>soto:service</code> tag.
19  *
20  * @author Yanick Duchesne
21  * <dl>
22  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
23  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
24  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
25  * </dl>
26  */

27 public class ServiceTag implements ObjectHandlerIF, ObjectCreationCallback {
28   private Service _service;
29   private ServiceMetaData _meta;
30   private String JavaDoc _id;
31   private SotoContainer _cont;
32   private List JavaDoc _services;
33   private List JavaDoc _layers = new ArrayList JavaDoc();
34
35   /**
36    * Constructor for ServiceTag.
37    */

38   public ServiceTag(SotoContainer cont, List JavaDoc services) {
39     _cont = cont;
40     _services = services;
41   }
42
43   public Service getService() {
44     return _service;
45   }
46
47   public void setId(String JavaDoc id) {
48     _id = id;
49   }
50
51   public String JavaDoc getId() {
52     return _id;
53   }
54
55   /**
56    * @see org.sapia.util.xml.confix.ObjectCreationCallback#onCreate()
57    */

58   public Object JavaDoc 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 JavaDoc e) {
74       throw new ConfigurationException("Could not initialize service", e);
75     }
76   }
77
78   public ServiceMetaData getServiceMetaData() {
79     return _meta;
80   }
81
82   /**
83    * @see org.sapia.util.xml.confix.ObjectHandlerIF#handleObject(String, Object)
84    */

85   public void handleObject(String JavaDoc name, Object JavaDoc 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 JavaDoc[] interfaces = obj.getClass().getInterfaces();
102       String JavaDoc 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