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.config.schema;
006:
007: import com.tc.config.schema.context.ConfigContext;
008: import com.tc.config.schema.dynamic.FileConfigItem;
009: import com.tc.config.schema.dynamic.IntConfigItem;
010: import com.tc.config.schema.dynamic.ParameterSubstituter;
011: import com.tc.config.schema.dynamic.StringConfigItem;
012: import com.terracottatech.config.Authentication;
013: import com.terracottatech.config.Server;
014:
015: import java.io.File;
016:
017: import javax.xml.namespace.QName;
018:
019: /**
020: * The standard implementation of {@link NewCommonL2Config}.
021: */
022: public class NewCommonL2ConfigObject extends BaseNewConfigObject
023: implements NewCommonL2Config {
024:
025: private final FileConfigItem dataPath;
026: private final FileConfigItem logsPath;
027: private final IntConfigItem jmxPort;
028: private final StringConfigItem host;
029: private final boolean authentication;
030: private final String passwordFile;
031: private final String accessFile;
032:
033: public NewCommonL2ConfigObject(ConfigContext context) {
034: super (context);
035:
036: this .context.ensureRepositoryProvides(Server.class);
037:
038: this .dataPath = context
039: .configRelativeSubstitutedFileItem("data");
040: this .logsPath = context
041: .configRelativeSubstitutedFileItem("logs");
042: this .jmxPort = context.intItem("jmx-port");
043: this .host = context.stringItem("@host");
044:
045: String pwd = null;
046: String access = null;
047: Server server = (Server) context.bean();
048: if (server != null) {
049: this .authentication = server.isSetAuthentication();
050: } else {
051: this .authentication = false;
052: }
053:
054: if (authentication) {
055: pwd = server.getAuthentication().getPasswordFile();
056: if (pwd == null)
057: pwd = Authentication.type.getElementProperty(
058: QName.valueOf("password-file"))
059: .getDefaultText();
060: pwd = new File(ParameterSubstituter.substitute(pwd))
061: .getAbsolutePath();
062:
063: access = server.getAuthentication().getAccessFile();
064: if (access == null)
065: access = Authentication.type.getElementProperty(
066: QName.valueOf("access-file")).getDefaultText();
067: access = new File(ParameterSubstituter.substitute(access))
068: .getAbsolutePath();
069: }
070: this .passwordFile = pwd;
071: this .accessFile = access;
072: }
073:
074: public FileConfigItem dataPath() {
075: return this .dataPath;
076: }
077:
078: public FileConfigItem logsPath() {
079: return this .logsPath;
080: }
081:
082: public IntConfigItem jmxPort() {
083: return this .jmxPort;
084: }
085:
086: public StringConfigItem host() {
087: return this .host;
088: }
089:
090: public boolean authentication() {
091: return authentication;
092: }
093:
094: public String authenticationAccessFile() {
095: return accessFile;
096: }
097:
098: public String authenticationPasswordFile() {
099: return passwordFile;
100: }
101: }
|