package com.dbxml.db.embedded;
/*
* dbXML - Native XML Database
* Copyright (c) 1999-2006 The dbXML Group, L.L.C.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* $Id: EmbeddedConfiguration.java,v 1.4 2006/02/02 18:55:06 bradford Exp $
*/
import com.dbxml.db.common.fulltext.FullTextQueryResolver;
import com.dbxml.db.common.security.NoSecurityManager;
import com.dbxml.db.common.xpath.XPathQueryResolver;
import com.dbxml.db.common.xslt.XSLTQueryResolver;
import com.dbxml.db.common.xupdate.XUpdateQueryResolver;
import com.dbxml.util.Configuration;
import com.dbxml.xml.dom.DOMHelper;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.w3c.dom.Document;
/**
* EmbeddedConfiguration
*/
public final class EmbeddedConfiguration {
private static final String CONFIG = "config";
private static final String DBROOT = "dbroot";
private static final String QUERYENGINE = "queryengine";
private static final String RESOLVER = "resolver";
private static final String SECURITY = "security";
private static final String NAME = "name";
private static final String CLASS = "class";
private static final Class DEFAULT_SECURITYMANAGER = NoSecurityManager.class;
private static final List DEFAULT_RESOLVERS = new ArrayList();
static {
DEFAULT_RESOLVERS.add(XPathQueryResolver.class);
DEFAULT_RESOLVERS.add(XSLTQueryResolver.class);
DEFAULT_RESOLVERS.add(XUpdateQueryResolver.class);
DEFAULT_RESOLVERS.add(FullTextQueryResolver.class);
}
private String dbName = null;
private File dbRoot = null;
private Class security = null;
private List queryResolvers = null;
public EmbeddedConfiguration() {
}
public EmbeddedConfiguration(String dbName) {
this.dbName = dbName;
}
public EmbeddedConfiguration(String dbName, File dbRoot) {
this.dbName = dbName;
this.dbRoot = dbRoot;
}
public void setDatabaseName(String dbName) {
this.dbName = dbName;
}
public String getDatabaseName() {
return dbName;
}
public void setDatabaseRoot(File dbRoot) {
this.dbRoot = dbRoot;
}
public File getDatabaseRoot() {
return dbRoot;
}
public void setSecurityManager(Class security) {
this.security = security;
}
public Class getSecurityManager() {
return security;
}
public void addQueryResolver(Class resolver) {
if ( queryResolvers == null )
queryResolvers = new ArrayList();
queryResolvers.add(resolver);
}
public Configuration getConfig() {
Document doc = DOMHelper.newDocument();
doc.appendChild(doc.createElement(CONFIG));
Configuration config = new Configuration(doc);
if ( dbName != null )
config.setAttribute(NAME, dbName);
else
config.setAttribute(NAME, "db");
if ( dbRoot != null )
config.setAttribute(DBROOT, dbRoot.getPath());
else
config.setAttribute(DBROOT, "./db");
Configuration securityCfg = config.add(SECURITY);
if ( security != null )
securityCfg.setAttribute(CLASS, security.getName());
else
securityCfg.setAttribute(CLASS, DEFAULT_SECURITYMANAGER.getName());
Configuration queryEngineCfg = config.add(QUERYENGINE);
Iterator iter;
if ( queryResolvers != null )
iter = queryResolvers.iterator();
else
iter = DEFAULT_RESOLVERS.iterator();
while ( iter.hasNext() ) {
Class c = (Class)iter.next();
Configuration resolverCfg = queryEngineCfg.add(RESOLVER);
resolverCfg.setAttribute(CLASS, c.getName());
}
return config;
}
}