KickJava   Java API By Example, From Geeks To Geeks.

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


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

5 package com.tc.object.config.schema;
6
7 import org.apache.xmlbeans.XmlObject;
8
9 import com.tc.capabilities.AbstractCapabilitiesFactory;
10 import com.tc.capabilities.Capabilities;
11 import com.tc.config.schema.BaseNewConfigObject;
12 import com.tc.config.schema.context.ConfigContext;
13 import com.tc.config.schema.dynamic.BooleanConfigItem;
14 import com.tc.config.schema.dynamic.ConfigItem;
15 import com.tc.config.schema.dynamic.StringArrayConfigItem;
16 import com.tc.config.schema.dynamic.XPathBasedConfigItem;
17 import com.tc.logging.CustomerLogging;
18 import com.tc.logging.TCLogger;
19 import com.tc.logging.TCLogging;
20 import com.terracottatech.config.DsoApplication;
21 import com.terracottatech.config.Root;
22 import com.terracottatech.config.Roots;
23
24 public class NewDSOApplicationConfigObject extends BaseNewConfigObject implements NewDSOApplicationConfig {
25   private static final TCLogger logger = TCLogging.getLogger(NewDSOApplicationConfigObject.class);
26
27   private final ConfigItem instrumentedClasses;
28   private final StringArrayConfigItem transientFields;
29   private final ConfigItem locks;
30   private final ConfigItem roots;
31   private final StringArrayConfigItem additionalBootJarClasses;
32   private final BooleanConfigItem supportSharingThroughReflection;
33   private final StringArrayConfigItem webApplications;
34
35   public NewDSOApplicationConfigObject(ConfigContext context) {
36     super(context);
37
38     this.context.ensureRepositoryProvides(DsoApplication.class);
39
40     this.instrumentedClasses = new XPathBasedConfigItem(this.context, "instrumented-classes") {
41       protected Object JavaDoc fetchDataFromXmlObject(XmlObject xmlObject) {
42         return ConfigTranslationHelper.translateIncludes(xmlObject);
43       }
44     };
45
46     this.locks = new XPathBasedConfigItem(this.context, "locks") {
47       protected Object JavaDoc fetchDataFromXmlObject(XmlObject xmlObject) {
48         return ConfigTranslationHelper.translateLocks(xmlObject);
49       }
50     };
51
52     this.roots = new XPathBasedConfigItem(this.context, "roots") {
53       protected Object JavaDoc fetchDataFromXmlObject(XmlObject xmlObject) {
54         return translateRoots(xmlObject);
55       }
56     };
57
58     this.transientFields = this.context.stringArrayItem("transient-fields");
59     this.additionalBootJarClasses = this.context.stringArrayItem("additional-boot-jar-classes");
60     this.webApplications = this.context.stringArrayItem("web-applications");
61     this.supportSharingThroughReflection = this.context.booleanItem("dso-reflection-enabled");
62   }
63
64   public StringArrayConfigItem webApplications() {
65     return this.webApplications;
66   }
67
68   public ConfigItem instrumentedClasses() {
69     return this.instrumentedClasses;
70   }
71
72   public StringArrayConfigItem transientFields() {
73     return this.transientFields;
74   }
75
76   public ConfigItem locks() {
77     return this.locks;
78   }
79
80   public ConfigItem roots() {
81     return this.roots;
82   }
83
84   public StringArrayConfigItem additionalBootJarClasses() {
85     return this.additionalBootJarClasses;
86   }
87
88   public BooleanConfigItem supportSharingThroughReflection() {
89     return supportSharingThroughReflection;
90   }
91
92   private static Object JavaDoc translateRoots(XmlObject xmlObject) {
93     if (xmlObject == null) return null;
94
95     Capabilities capabilitiesManager = AbstractCapabilitiesFactory.getCapabilitiesManager();
96     if (capabilitiesManager.canClusterPOJOs()) {
97       com.tc.object.config.schema.Root[] out;
98       Root[] theRoots = ((Roots) xmlObject).getRootArray();
99       out = new com.tc.object.config.schema.Root[theRoots == null ? 0 : theRoots.length];
100       for (int i = 0; i < out.length; ++i) {
101         out[i] = new com.tc.object.config.schema.Root(theRoots[i].getRootName(), theRoots[i].getFieldName());
102       }
103       return out;
104     } else {
105       String JavaDoc msg = "Declared roots not a supported capability: " + capabilitiesManager.describe();
106       logger.error(msg);
107       CustomerLogging.getConsoleLogger().error(msg);
108       throw new RuntimeException JavaDoc("msg");
109     }
110   }
111 }
112
Popular Tags