KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > NewSystemConfigObject


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.config.schema;
6
7 import org.apache.xmlbeans.XmlObject;
8
9 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 implements NewSystemConfig {
21
22   private final ConfigItem configurationModel;
23
24   public NewSystemConfigObject(ConfigContext context) throws ConfigurationSetupException {
25     super(context);
26
27     this.context.ensureRepositoryProvides(System JavaDoc.class);
28
29     this.configurationModel = new XPathBasedConfigItem(this.context, "configuration-model") {
30       protected Object JavaDoc fetchDataFromXmlObject(XmlObject xmlObject) {
31         if (xmlObject == null) return null;
32         if (((ConfigurationModel) xmlObject).enumValue().equals(ConfigurationModel.DEVELOPMENT)) return com.tc.config.schema.ConfigurationModel.DEVELOPMENT;
33         if (((ConfigurationModel) xmlObject).enumValue().equals(ConfigurationModel.PRODUCTION)) return com.tc.config.schema.ConfigurationModel.PRODUCTION;
34         throw Assert.failure("Unexpected configuration model: " + xmlObject);
35       }
36     };
37   }
38
39   public ConfigItem configurationModel() {
40     return this.configurationModel;
41   }
42
43 }
44
Popular Tags