Clover coverage report - JFox Service-Oriented Application Framework - 1.0-M2 Coverage timestamp: 星期四 十一月 25 2004 17:14:11 PST FRAMES NO FRAMES |
file stats: | LOC: | 158 |  | Methods: | 6
| NCLOC: | 90 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
ServiceLoadProxy.java | 78.6% | 91.7% | 100% | 89.3% |

1 |  |
     /**
2 |  |
      * JFoxSOAF, Service-Oriented Application Framework
3 |  |
      *
4 |  |
      * Copyright (C) www.huihoo.org
5 |  |
      *
6 |  |
      * Distributable under GNU LGPL For more information, please visit:
7 |  |
      * http://www.huihoo.org/jfox/jfoxsoaf
8 |  |
      */
9 |  |
10 |  |
     package org.huihoo.jfox.soaf.container;
11 |  |
12 |  |
     import java.io.IOException;
13 |  |
     import java.io.InputStream;
14 |  |
     import java.io.InputStreamReader;
15 |  |
     import java.util.ArrayList;
16 |  |
     import java.util.Collection;
17 |  |
     import java.util.Iterator;
18 |  |
     import java.util.LinkedList;
19 |  |
20 |  |
     import org.apache.commons.logging.Log;
21 |  |
     import org.apache.commons.logging.LogFactory;
22 |  |
     import org.huihoo.jfox.soaf.exception.ServiceConfigurationException;
23 |  |
     import org.huihoo.jfox.soaf.schema.config.Configuration;
24 |  |
     import org.huihoo.jfox.soaf.schema.config.ConfigurationEntry;
25 |  |
     import org.huihoo.jfox.soaf.schema.config.Interceptor;
26 |  |
     import org.huihoo.jfox.soaf.schema.service.Service;
27 |  |
     import org.huihoo.jfox.soaf.schema.service.ServiceEntry;
28 |  |
     import org.huihoo.jfox.soaf.util.resource.ResourceHelper;
29 |  |
30 |  |
     /**
31 |  |
      * <p>
32 |  |
      * Service Configration load proxy.
33 |  |
      * </p>
34 |  |
      *
35 |  |
      * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
36 |  |
      * @version $Revision: 1.7 $ $Date: 2004/10/28 05:11:43 $
37 |  |
      * @version Revision: 1.0
38 |  |
      */
39 |  |
40 |  |
     public class ServiceLoadProxy {
41 |  |
42 |  |
         private boolean serviceLoaded = false;
43 |  |
44 |  |
         private Collection serviceSchemaColl = new LinkedList();
45 |  |
46 |  |
         private Collection interceptorColl = new ArrayList();
47 |  |
48 |  |
         private Collection serviceEntryColl = new ArrayList();
49 |  |
50 |  |
         private InterceptorManager interceptorManager = new InterceptorManagerImpl();
51 |  |
52 |  |
         private final Log logger = LogFactory.getLog(getClass());
53 |  |
54 |  |
         /**
55 |  |
          * Default Constructor.
56 |  |
          */
57 | 2 |
         public ServiceLoadProxy() {
58 | 2 |
             super();
59 |  |
         }
60 |  |
61 |  |
         /**
62 |  |
          * Load all configuration service.
63 |  |
          * @param service
64 |  |
          */
65 | 2 |
         public void loadConfig(Configuration config)
66 |  |
                 throws Throwable {
67 | 2 |
             if (!serviceLoaded) {
68 | 2 |
                 processConfig(config);
69 | 2 |
                 loadService(serviceSchemaColl);
70 | 2 |
                 interceptorManager.processInterceptor(interceptorColl,
71 |  |
                         serviceEntryColl);
72 | 2 |
                 this.serviceLoaded = true;
73 |  |
             }
74 |  |
         }
75 |  |
76 |  |
         /**
77 |  |
          * Load service schema.
78 |  |
          * @param serviceSchemaColl
79 |  |
          *
80 |  |
          * @throws ServiceConfigurationException
81 |  |
          */
82 | 2 |
         private void loadService(Collection serviceSchemaColl) throws ServiceConfigurationException {
83 | 2 |
             InputStream is = null;
84 | 2 |
             InputStreamReader isr = null;
85 | 2 |
             Iterator iter = serviceSchemaColl.iterator();
86 | 2 |
             Service service;
87 | 2 |
             try {
88 | 2 |
                 while (iter.hasNext()) {
89 | 8 |
                     is = ResourceHelper.getResourceAsStream((String) iter.next());
90 | 8 |
                     isr = new InputStreamReader(is);
91 | 8 |
                     service = Service.unmarshal(isr);
92 | 8 |
                     processService(service);
93 |  |
                 }
94 |  |
             } catch (Exception e) {
95 | 0 |
                 throw new ServiceConfigurationException(e);
96 |  |
             } finally {
97 | 2 |
                 if (is != null) {
98 | 2 |
                     try {
99 | 2 |
                         is.close();
100 |  |
                     } catch (IOException e1) {
101 | 0 |
                         e1.printStackTrace();
102 |  |
                     }
103 |  |
104 |  |
                 }
105 |  |
106 | 2 |
                 if (isr != null) {
107 | 2 |
                     try {
108 | 2 |
                         isr.close();
109 |  |
                     } catch (IOException e1) {
110 | 0 |
                         e1.printStackTrace();
111 |  |
                     }
112 |  |
                 }
113 |  |
114 |  |
             }
115 |  |
116 |  |
         }
117 |  |
118 |  |
         /**
119 |  |
          * Add service to service entry collection.
120 |  |
          *
121 |  |
          * @param service
122 |  |
          */
123 | 8 |
         private void processService(Service service) {
124 | 8 |
             ServiceEntry[] serviceEntry = service.getServiceEntry();
125 | 8 |
             for (int i = 0; i < serviceEntry.length; i++) {
126 | 14 |
                 serviceEntryColl.add(serviceEntry[i]);
127 |  |
             }
128 |  |
         }
129 |  |
130 |  |
         /**
131 |  |
          * Is service loaded?
132 |  |
          *
133 |  |
          * @return boolean
134 |  |
          */
135 | 3 |
         public boolean isServiceLoaded() {
136 | 3 |
             return this.serviceLoaded;
137 |  |
         }
138 |  |
139 |  |
         /**
140 |  |
          * Add service schema and interceptor to collection.
141 |  |
          *
142 |  |
          * @param config
143 |  |
          */
144 | 2 |
         private void processConfig(Configuration config) {
145 | 2 |
             ConfigurationEntry[] configEntry = config.getServiceConfiguration()
146 |  |
                     .getConfigurationEntry();
147 | 2 |
             Interceptor[] interceptor = config.getSystemInterceptor()
148 |  |
                     .getInterceptor();
149 | 2 |
             for (int i = 0; i < configEntry.length; i++) {
150 | 8 |
                 logger.info("Load service schema : " + configEntry[i].getValue());
151 | 8 |
                 serviceSchemaColl.add(configEntry[i].getValue());
152 |  |
             }
153 |  |
154 | 2 |
             for (int i = 0; i < interceptor.length; i++) {
155 | 4 |
                 interceptorColl.add(interceptor[i].getValue());
156 |  |
             }
157 |  |
         }
158 |  |
     }