KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > config > schema > NewSpringApplicationConfigObject


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.config.schema;
5
6 import org.apache.xmlbeans.XmlObject;
7
8 import com.tc.config.schema.BaseNewConfigObject;
9 import com.tc.config.schema.context.ConfigContext;
10 import com.tc.config.schema.dynamic.ObjectArrayConfigItem;
11 import com.tc.config.schema.dynamic.ObjectArrayXPathBasedConfigItem;
12 import com.terracottatech.config.NonDistributedFields;
13 import com.terracottatech.config.SpringAppContext;
14 import com.terracottatech.config.SpringAppContexts;
15 import com.terracottatech.config.SpringApplication;
16 import com.terracottatech.config.SpringApps;
17 import com.terracottatech.config.SpringBean;
18 import com.terracottatech.config.SpringDistributedEvent;
19
20 public class NewSpringApplicationConfigObject extends BaseNewConfigObject implements NewSpringApplicationConfig {
21
22   private final ObjectArrayConfigItem springApps;
23
24   public NewSpringApplicationConfigObject(ConfigContext context) {
25     super(context);
26
27     this.context.ensureRepositoryProvides(SpringApplication.class);
28
29     this.springApps = new ObjectArrayXPathBasedConfigItem(this.context, ".") {
30       protected Object JavaDoc fetchDataFromXmlObject(XmlObject xmlObject) {
31         return translateSpringApps(xmlObject);
32       }
33     };
34
35   }
36
37   public ObjectArrayConfigItem springApps() {
38     return this.springApps;
39   }
40
41   private static Object JavaDoc translateSpringBeans(XmlObject xmlObject) {
42     if (xmlObject == null) return null;
43
44     NonDistributedFields[] springBeans = ((SpringBean) xmlObject).getBeanArray();
45     SpringContextBean[] beans = new SpringContextBean[springBeans.length];
46
47     for (int i = 0; i < springBeans.length; i++) {
48       String JavaDoc name = springBeans[i].getName();
49       String JavaDoc[] fields = springBeans[i].getNonDistributedFieldArray();
50       beans[i] = new SpringContextBean(name, fields);
51     }
52
53     return beans;
54   }
55
56   private static Object JavaDoc translateAppContexts(XmlObject xmlObject) {
57     if (xmlObject == null) return null;
58
59     SpringAppContext[] springAppContexts = ((SpringAppContexts) xmlObject).getApplicationContextArray();
60     AppContext[] appContexts = new AppContext[springAppContexts.length];
61
62     for (int i = 0; i < springAppContexts.length; i++) {
63       SpringAppContext ctx = springAppContexts[i];
64       String JavaDoc[] paths = ctx.getPaths().getPathArray();
65       SpringDistributedEvent distributedEvent = ctx.getDistributedEvents();
66       String JavaDoc[] distributedEvents = null;
67       if (distributedEvent != null) {
68         distributedEvents = distributedEvent.getDistributedEventArray();
69       }
70       SpringContextBean[] beans = (SpringContextBean[]) NewSpringApplicationConfigObject.translateSpringBeans(ctx
71           .getBeans());
72       
73       String JavaDoc rootName = ctx.getRootName();
74       
75       boolean locationInfoEnabled = ctx.getEnableLocationInfo();
76       
77       appContexts[i] = new AppContext(paths, distributedEvents, beans, rootName, locationInfoEnabled);
78     }
79
80     return appContexts;
81   }
82
83   private static Object JavaDoc translateSpringApps(XmlObject xmlObject) {
84     if (xmlObject == null) return null;
85
86     SpringApps[] springApps = ((SpringApplication) xmlObject).getJeeApplicationArray();
87     SpringApp[] springApp = new SpringApp[springApps.length];
88
89     for (int i = 0; i < springApps.length; i++) {
90       SpringApps app = springApps[i];
91       String JavaDoc name = app.getName();
92       boolean sessionSupport = app.getSessionSupport();
93       Lock[] locks = (Lock[]) ConfigTranslationHelper.translateLocks(app.getLocks());
94       InstrumentedClass[] includes = (InstrumentedClass[]) ConfigTranslationHelper.translateIncludes(app
95           .getInstrumentedClasses());
96
97       String JavaDoc[] transientFields = null;
98       if (app.getTransientFields() != null) {
99         transientFields = app.getTransientFields().getFieldNameArray();
100       }
101       if (transientFields == null) transientFields = new String JavaDoc[0];
102
103       AppContext[] appContexts = (AppContext[]) NewSpringApplicationConfigObject.translateAppContexts(app
104           .getApplicationContexts());
105
106       boolean fastProxy = app.getFastProxy();
107
108       springApp[i] = new SpringApp(sessionSupport, locks, includes, appContexts, name, fastProxy, transientFields);
109     }
110
111     return springApp;
112   }
113
114 }
115
Popular Tags