001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.object.config.schema;
006:
007: import org.apache.xmlbeans.XmlObject;
008:
009: import com.tc.capabilities.AbstractCapabilitiesFactory;
010: import com.tc.capabilities.Capabilities;
011: import com.tc.config.schema.BaseNewConfigObject;
012: import com.tc.config.schema.context.ConfigContext;
013: import com.tc.config.schema.dynamic.BooleanConfigItem;
014: import com.tc.config.schema.dynamic.ConfigItem;
015: import com.tc.config.schema.dynamic.StringArrayConfigItem;
016: import com.tc.config.schema.dynamic.XPathBasedConfigItem;
017: import com.tc.logging.CustomerLogging;
018: import com.tc.logging.TCLogger;
019: import com.tc.logging.TCLogging;
020: import com.terracottatech.config.DsoApplication;
021: import com.terracottatech.config.Root;
022: import com.terracottatech.config.Roots;
023:
024: public class NewDSOApplicationConfigObject extends BaseNewConfigObject
025: implements NewDSOApplicationConfig {
026: private static final TCLogger logger = TCLogging
027: .getLogger(NewDSOApplicationConfigObject.class);
028:
029: private final ConfigItem instrumentedClasses;
030: private final StringArrayConfigItem transientFields;
031: private final ConfigItem locks;
032: private final ConfigItem roots;
033: private final StringArrayConfigItem additionalBootJarClasses;
034: private final BooleanConfigItem supportSharingThroughReflection;
035: private final StringArrayConfigItem webApplications;
036:
037: public NewDSOApplicationConfigObject(ConfigContext context) {
038: super (context);
039:
040: this .context.ensureRepositoryProvides(DsoApplication.class);
041:
042: this .instrumentedClasses = new XPathBasedConfigItem(
043: this .context, "instrumented-classes") {
044: protected Object fetchDataFromXmlObject(XmlObject xmlObject) {
045: return ConfigTranslationHelper
046: .translateIncludes(xmlObject);
047: }
048: };
049:
050: this .locks = new XPathBasedConfigItem(this .context, "locks") {
051: protected Object fetchDataFromXmlObject(XmlObject xmlObject) {
052: return ConfigTranslationHelper
053: .translateLocks(xmlObject);
054: }
055: };
056:
057: this .roots = new XPathBasedConfigItem(this .context, "roots") {
058: protected Object fetchDataFromXmlObject(XmlObject xmlObject) {
059: return translateRoots(xmlObject);
060: }
061: };
062:
063: this .transientFields = this .context
064: .stringArrayItem("transient-fields");
065: this .additionalBootJarClasses = this .context
066: .stringArrayItem("additional-boot-jar-classes");
067: this .webApplications = this .context
068: .stringArrayItem("web-applications");
069: this .supportSharingThroughReflection = this .context
070: .booleanItem("dso-reflection-enabled");
071: }
072:
073: public StringArrayConfigItem webApplications() {
074: return this .webApplications;
075: }
076:
077: public ConfigItem instrumentedClasses() {
078: return this .instrumentedClasses;
079: }
080:
081: public StringArrayConfigItem transientFields() {
082: return this .transientFields;
083: }
084:
085: public ConfigItem locks() {
086: return this .locks;
087: }
088:
089: public ConfigItem roots() {
090: return this .roots;
091: }
092:
093: public StringArrayConfigItem additionalBootJarClasses() {
094: return this .additionalBootJarClasses;
095: }
096:
097: public BooleanConfigItem supportSharingThroughReflection() {
098: return supportSharingThroughReflection;
099: }
100:
101: private static Object translateRoots(XmlObject xmlObject) {
102: if (xmlObject == null)
103: return null;
104:
105: Capabilities capabilitiesManager = AbstractCapabilitiesFactory
106: .getCapabilitiesManager();
107: if (capabilitiesManager.canClusterPOJOs()) {
108: com.tc.object.config.schema.Root[] out;
109: Root[] theRoots = ((Roots) xmlObject).getRootArray();
110: out = new com.tc.object.config.schema.Root[theRoots == null ? 0
111: : theRoots.length];
112: for (int i = 0; i < out.length; ++i) {
113: out[i] = new com.tc.object.config.schema.Root(
114: theRoots[i].getRootName(), theRoots[i]
115: .getFieldName());
116: }
117: return out;
118: } else {
119: String msg = "Declared roots not a supported capability: "
120: + capabilitiesManager.describe();
121: logger.error(msg);
122: CustomerLogging.getConsoleLogger().error(msg);
123: throw new RuntimeException("msg");
124: }
125: }
126: }
|