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.InputStream;
13 import java.io.InputStreamReader;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Iterator;
17 import java.util.LinkedList;
18
19 import org.huihoo.jfox.soaf.schema.config.Configuration;
20 import org.huihoo.jfox.soaf.schema.config.ConfigurationEntry;
21 import org.huihoo.jfox.soaf.schema.config.Interceptor;
22 import org.huihoo.jfox.soaf.schema.service.Service;
23 import org.huihoo.jfox.soaf.schema.service.ServiceEntry;
24
25 /***
26 * <p>
27 * Service Configration load proxy.
28 * </p>
29 *
30 * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
31 * @version $Revision: 1.3 $ $Date: 2004/10/15 08:36:00 $
32 * @version Revision: 1.0
33 */
34
35 public class ServiceLoadProxy {
36
37 private boolean serviceLoaded = false;
38
39 private Collection serviceSchemaColl = new LinkedList();
40
41 private Collection interceptorColl = new ArrayList();
42
43 private Collection serviceEntryColl = new ArrayList();
44
45 private InterceptorManager interceptorManager = new InterceptorManagerImpl();
46
47 /***
48 * Default Constructor.
49 */
50 public ServiceLoadProxy() {
51 super();
52 }
53
54 /***
55 * Load all configuration service.
56 *
57 * @param service
58 */
59 public void loadConfig(Configuration config, ClassLoader classLoader)
60 throws Throwable {
61 Iterator iter = null;
62 if (!serviceLoaded) {
63 processConfig(config);
64 loadService(serviceSchemaColl, classLoader);
65 interceptorManager.processInterceptor(interceptorColl,
66 serviceEntryColl, classLoader);
67 this.serviceLoaded = true;
68 }
69 }
70
71 private void loadService(Collection serviceSchemaColl,
72 ClassLoader classLoader) throws Throwable {
73 InputStream is = null;
74 InputStreamReader isr = null;
75 Iterator iter = serviceSchemaColl.iterator();
76 Service service;
77 while (iter.hasNext()) {
78 is = classLoader.getResourceAsStream((String) iter.next());
79 isr = new InputStreamReader(is);
80 service = Service.unmarshal(isr);
81 processService(service);
82 }
83 is.close();
84 isr.close();
85 }
86
87 private void processService(Service service) {
88 ServiceEntry[] serviceEntry = service.getServiceEntry();
89 for (int i = 0; i < serviceEntry.length; i++) {
90 serviceEntryColl.add(serviceEntry[i]);
91 }
92 }
93
94 /***
95 * Is service loaded?
96 *
97 * @return boolean
98 */
99 public boolean isServiceLoaded() {
100 return this.serviceLoaded;
101 }
102
103 private void processConfig(Configuration config) {
104 ConfigurationEntry[] configEntry = config.getServiceConfiguration()
105 .getConfigurationEntry();
106 Interceptor[] interceptor = config.getSystemInterceptor()
107 .getInterceptor();
108 for (int i = 0; i < configEntry.length; i++) {
109 serviceSchemaColl.add(configEntry[i].getValue());
110 }
111
112 for (int i = 0; i < interceptor.length; i++) {
113 interceptorColl.add(interceptor[i].getValue());
114 }
115 }
116 }