01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.config.schema;
06:
07: import org.apache.xmlbeans.XmlObject;
08:
09: import com.tc.config.schema.context.ConfigContext;
10: import com.tc.config.schema.dynamic.ConfigItem;
11: import com.tc.config.schema.dynamic.XPathBasedConfigItem;
12: import com.tc.config.schema.setup.ConfigurationSetupException;
13: import com.tc.util.Assert;
14: import com.terracottatech.config.ConfigurationModel;
15: import com.terracottatech.config.System;
16:
17: /**
18: * The standard implementation of {@link NewSystemConfig}.
19: */
20: public class NewSystemConfigObject extends BaseNewConfigObject
21: implements NewSystemConfig {
22:
23: private final ConfigItem configurationModel;
24:
25: public NewSystemConfigObject(ConfigContext context)
26: throws ConfigurationSetupException {
27: super (context);
28:
29: this .context.ensureRepositoryProvides(System.class);
30:
31: this .configurationModel = new XPathBasedConfigItem(
32: this .context, "configuration-model") {
33: protected Object fetchDataFromXmlObject(XmlObject xmlObject) {
34: if (xmlObject == null)
35: return null;
36: if (((ConfigurationModel) xmlObject).enumValue()
37: .equals(ConfigurationModel.DEVELOPMENT))
38: return com.tc.config.schema.ConfigurationModel.DEVELOPMENT;
39: if (((ConfigurationModel) xmlObject).enumValue()
40: .equals(ConfigurationModel.PRODUCTION))
41: return com.tc.config.schema.ConfigurationModel.PRODUCTION;
42: throw Assert.failure("Unexpected configuration model: "
43: + xmlObject);
44: }
45: };
46: }
47:
48: public ConfigItem configurationModel() {
49: return this.configurationModel;
50: }
51:
52: }
|