001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.object.config.schema;
005:
006: import org.apache.xmlbeans.XmlObject;
007:
008: import com.tc.config.schema.BaseNewConfigObject;
009: import com.tc.config.schema.context.ConfigContext;
010: import com.tc.config.schema.dynamic.ObjectArrayConfigItem;
011: import com.tc.config.schema.dynamic.ObjectArrayXPathBasedConfigItem;
012: import com.terracottatech.config.NonDistributedFields;
013: import com.terracottatech.config.SpringAppContext;
014: import com.terracottatech.config.SpringAppContexts;
015: import com.terracottatech.config.SpringApplication;
016: import com.terracottatech.config.SpringApps;
017: import com.terracottatech.config.SpringBean;
018: import com.terracottatech.config.SpringDistributedEvent;
019:
020: public class NewSpringApplicationConfigObject extends
021: BaseNewConfigObject implements NewSpringApplicationConfig {
022:
023: private final ObjectArrayConfigItem springApps;
024:
025: public NewSpringApplicationConfigObject(ConfigContext context) {
026: super (context);
027:
028: this .context.ensureRepositoryProvides(SpringApplication.class);
029:
030: this .springApps = new ObjectArrayXPathBasedConfigItem(
031: this .context, ".") {
032: protected Object fetchDataFromXmlObject(XmlObject xmlObject) {
033: return translateSpringApps(xmlObject);
034: }
035: };
036:
037: }
038:
039: public ObjectArrayConfigItem springApps() {
040: return this .springApps;
041: }
042:
043: private static Object translateSpringBeans(XmlObject xmlObject) {
044: if (xmlObject == null)
045: return null;
046:
047: NonDistributedFields[] springBeans = ((SpringBean) xmlObject)
048: .getBeanArray();
049: SpringContextBean[] beans = new SpringContextBean[springBeans.length];
050:
051: for (int i = 0; i < springBeans.length; i++) {
052: String name = springBeans[i].getName();
053: String[] fields = springBeans[i]
054: .getNonDistributedFieldArray();
055: beans[i] = new SpringContextBean(name, fields);
056: }
057:
058: return beans;
059: }
060:
061: private static Object translateAppContexts(XmlObject xmlObject) {
062: if (xmlObject == null)
063: return null;
064:
065: SpringAppContext[] springAppContexts = ((SpringAppContexts) xmlObject)
066: .getApplicationContextArray();
067: AppContext[] appContexts = new AppContext[springAppContexts.length];
068:
069: for (int i = 0; i < springAppContexts.length; i++) {
070: SpringAppContext ctx = springAppContexts[i];
071: String[] paths = ctx.getPaths().getPathArray();
072: SpringDistributedEvent distributedEvent = ctx
073: .getDistributedEvents();
074: String[] distributedEvents = null;
075: if (distributedEvent != null) {
076: distributedEvents = distributedEvent
077: .getDistributedEventArray();
078: }
079: SpringContextBean[] beans = (SpringContextBean[]) NewSpringApplicationConfigObject
080: .translateSpringBeans(ctx.getBeans());
081:
082: String rootName = ctx.getRootName();
083:
084: boolean locationInfoEnabled = ctx.getEnableLocationInfo();
085:
086: appContexts[i] = new AppContext(paths, distributedEvents,
087: beans, rootName, locationInfoEnabled);
088: }
089:
090: return appContexts;
091: }
092:
093: private static Object translateSpringApps(XmlObject xmlObject) {
094: if (xmlObject == null)
095: return null;
096:
097: SpringApps[] springApps = ((SpringApplication) xmlObject)
098: .getJeeApplicationArray();
099: SpringApp[] springApp = new SpringApp[springApps.length];
100:
101: for (int i = 0; i < springApps.length; i++) {
102: SpringApps app = springApps[i];
103: String name = app.getName();
104: boolean sessionSupport = app.getSessionSupport();
105: Lock[] locks = (Lock[]) ConfigTranslationHelper
106: .translateLocks(app.getLocks());
107: InstrumentedClass[] includes = (InstrumentedClass[]) ConfigTranslationHelper
108: .translateIncludes(app.getInstrumentedClasses());
109:
110: String[] transientFields = null;
111: if (app.getTransientFields() != null) {
112: transientFields = app.getTransientFields()
113: .getFieldNameArray();
114: }
115: if (transientFields == null)
116: transientFields = new String[0];
117:
118: AppContext[] appContexts = (AppContext[]) NewSpringApplicationConfigObject
119: .translateAppContexts(app.getApplicationContexts());
120:
121: boolean fastProxy = app.getFastProxy();
122:
123: springApp[i] = new SpringApp(sessionSupport, locks,
124: includes, appContexts, name, fastProxy,
125: transientFields);
126: }
127:
128: return springApp;
129: }
130:
131: }
|