Package org.apache.xindice.util

Examples of org.apache.xindice.util.Configuration


            colEle.appendChild(filEle);
        }

        CollectionManager colman = getCollection((String) message.get(COLLECTION));

        Configuration config = new Configuration(doc.getDocumentElement(), false);
        colman.createCollection((String) message.get(NAME), config);

        Hashtable result = new Hashtable();
        result.put(RESULT, message.get(NAME));
        return result;
View Full Code Here


        if (config.getBooleanAttribute(CACHE, true)) {
            documentCache = getDatabase().getDocumentCache();
        }

        // If no Filer is defined, skip Symbols and Indexes
        Configuration filerConfig = config.getChild(FILER);
        if (filerConfig != null) {
            if (log.isTraceEnabled()) {
                log.trace(localDebugHeader + "Have filer config...");
            }

            // Symbol Table Setup
            Configuration symConfig = config.getChild(SYMBOLS);
            internalSymbols = (symConfig != null);
            if (internalSymbols) {
                if (log.isTraceEnabled()) {
                    log.trace(localDebugHeader
                              + "Internal symbols=<" + TextWriter.toString(symConfig.getElement()) + ">");
                }

                try {
                    symbols = new SymbolTable(symConfig.getElement());
                } catch (Exception e) {
                    if (log.isWarnEnabled()) {
                        log.warn(localDebugHeader + "Error building symbol table from internal symbols", e);
                    }
                }
            } else {
                if (log.isTraceEnabled()) {
                    log.trace(localDebugHeader + "No internal symbols...");
                }

                try {
                    symbols = getSystemCollection().loadSymbols(this);
                    if (log.isDebugEnabled()) {
                        log.debug(localDebugHeader + "Loaded symbols=<" +
                                  TextWriter.toString(symbols.streamToXML(new DocumentImpl())) + ">");
                    }
                } catch (Exception e) {
                    if (log.isWarnEnabled()) {
                        log.warn(localDebugHeader + "Error building symbol table from system collection", e);
                    }
                }
            }

            String className = filerConfig.getAttribute(CLASS);
            if (log.isDebugEnabled()) {
                log.debug(localDebugHeader + "Filer class=<" + className + ">");
            }
            try {
                filer = (Filer) Class.forName(className).newInstance();
                filer.setLocation(getCollectionRoot(), getName());
                filer.setConfig(filerConfig);
                if (!filer.exists()) {
                    filer.create();
                }
                filer.open();
            } catch (Exception e) {
                if (log.isWarnEnabled()) {
                    log.warn("Filer '" + className + "' is not available", e);
                }
            }

            // Index Manager
            try {
                indexManager = new IndexManager(this, getDatabase().getTimer());
                Configuration idxConfig = config.getChild(INDEXES, true);
                indexManager.setConfig(idxConfig);
            } catch (Exception e) {
                if (log.isWarnEnabled()) {
                    log.warn("Failed to initialize indexer", e);
                }
View Full Code Here

    /**
     * Initializes database
     */
    public void init(ServletConfig servletConfig) throws ServletException {

        Configuration configuration = loadConfiguration(servletConfig);

        //
        // The configuration is wrapped in a <xindice> element so we need to get the "root-collection" configuration.
        //
        try {
            Configuration[] rootConfigurations = configuration.getChildren("root-collection");
            if (rootConfigurations.length == 0) {
                throw new ConfigurationException("The database configuration is missing the <root-collection> element");
            }

            for (int i = 0; i < rootConfigurations.length; i++) {
                Configuration rootConfiguration = rootConfigurations[i];
                String name = rootConfiguration.getAttribute(Database.NAME);

                //
                // We need to ensure that the database points to a place where it makes
                // sense. If the path in the system.xml file is an absolute path, then
                // honor it. If it's not, we first check for the system property "xindice.db.home"
                // and if the lookup is successful we use it as the database root parent. If
                // the property is not set, we use /WEB-INF relative to the servlet context, unless
                // the war has not been unpacked. In this case, we throw an exception and
                // ask the user to specify the location of database root
                //
                String dbRoot = rootConfiguration.getAttribute(Database.DBROOT, Database.DBROOT_DEFAULT);

                //
                // If there is no absolute path, we have to perform some checks.
                //
                if (!new File(dbRoot).isAbsolute()) {

                    // Stupid hack but spec compliant:
                    // If getRealPath() returns null the war archive has not been unpacked.
                    String realPath = servletConfig.getServletContext().getRealPath("/WEB-INF");

                    // Let's see if the property was specified.
                    String home = System.getProperty(Xindice.PROP_XINDICE_DB_HOME);
                    if (log.isDebugEnabled()) {
                        log.debug(Xindice.PROP_XINDICE_DB_HOME + " is set to " + home);
                    }

                    if (home != null) {
                        dbRoot = new File(home + File.separator + dbRoot).getCanonicalPath();
                    } else if (realPath != null) {
                        dbRoot = new File(realPath + File.separator + dbRoot).getCanonicalPath();
                        log.warn("The database '" + name + "' root directory has been set to " + dbRoot +
                                 ". Keep in mind that if a war upgrade will take place the database will be lost.");
                    } else {
                        throw new ConfigurationException(
                                "The database '" + name + "' configuration points to a relative path, "
                                + "but there was no " + Xindice.PROP_XINDICE_DB_HOME + " property set. "
                                + "Furthermore, the war was not unpacked by the application server "
                                + "so Xindice was unable to find a database location "
                                + "Please check /WEB-INF/system.xml and set an absolute path "
                                + "as the \"dbroot\" attribute of \"root-collection\" "
                                + "or specify a suitable " + Xindice.PROP_XINDICE_DB_HOME + " system property.");
                    }

                    rootConfiguration.setAttribute(Database.DBROOT, dbRoot);
                }

                //
                // We need to use this method to be consistent between deployments (embed, standalone, etc)
                // and let the Database object maintain the set of Databases.
                //
                Database.getDatabase(rootConfiguration);
                log.info("Database '" + name + "' successfully opened");
            }

            // Setup the XML-RPC impl to support UTF-8 input via Xerces.
            XmlRpc.setEncoding("UTF8");

            /*
             * Setup the SAX parser XML-RPC impl will use.
             * The XmlRpc.setDriver() method takes either the classname or a shorthand
             * name for the SAX parser it will use.  The default (for backwards compatibility
             * if nothing else) is xerces.
             */
            String xmlrpcDriver = DEFAULT_XMLRPC_DRIVER;

            Configuration xmlRpcConfiguration = configuration.getChild("xml-rpc");
            if (xmlRpcConfiguration != null) {
                Configuration xmlRpcDriverConfiguration = xmlRpcConfiguration.getChild("driver");
                if (xmlRpcDriverConfiguration != null) {
                    // xmlrpcDriver will have non-empty value, guaranteed by providing default value
                    xmlrpcDriver = xmlRpcDriverConfiguration.getAttribute("name", DEFAULT_XMLRPC_DRIVER);
                }
            }

            try {
                XmlRpc.setDriver(xmlrpcDriver);
View Full Code Here

            } else {
                log.warn("Loading the standard configuration");
                doc = DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION);
            }

            return new Configuration(doc, false);
        } catch (Exception e) {
            throw new ConfigurationException("Failed to load configuration.", e);
        }
    }
View Full Code Here

                if (getCollection(n) != null) {
                    throw new DBException(FaultCodes.COL_DUPLICATE_COLLECTION,
                                          "Duplicate Collection '" + n + "'");
                }

                Configuration colConfig = this.config.getChild(COLLECTIONS, true);
                colConfig.add(cfg);

                collection.setConfig(cfg);
                collection.create();
                collections.put(n, collection);
                if (log.isInfoEnabled()) {
View Full Code Here

        synchronized (collections) {
            boolean dropped = collection.drop();
            if (dropped) {
                collections.remove(name);
                Configuration colConfig = config.getChild(COLLECTIONS);
                colConfig.processChildren(COLLECTION, new ConfigurationCallback() {
                    public void process(Configuration cfg) {
                        try {
                            if (cfg.getAttribute(NAME).equals(name)) {
                                cfg.delete();
                            }
View Full Code Here

            log.info("Database name: '" + db.getName() + "'");
        }
    }

    protected Configuration loadConfiguration() throws IOException, XindiceException {
        Configuration config;
        String configDir = null;
        String configFile = System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION);
        if (configFile != null && !configFile.equals("")) {
            if (log.isInfoEnabled()) {
                log.info("Specified configuration file: '" + configFile + "'");
            }
            FileInputStream configXMLFile = new FileInputStream(new File(configFile));

            config = new Configuration(DOMParser.toDocument(configXMLFile), false);
            configDir = new File(configFile).getAbsoluteFile().getParent();
        } else {
            if (log.isInfoEnabled()) {
                log.info("No configuration file specified, going with the default configuration");
            }

            config = new Configuration(DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION), false);
        }

        config = config.getChild("root-collection", false);

        String dbRoot = config.getAttribute(Database.DBROOT, Database.DBROOT_DEFAULT);
        if (!new File(dbRoot).isAbsolute()) {
            // Let's see if the property was specified.
            String home = System.getProperty(Xindice.PROP_XINDICE_DB_HOME);
            if (home != null) {
                dbRoot = new File(home + File.separator + dbRoot).getCanonicalPath();
            } else if (configDir != null) {
                dbRoot = configDir + File.separator + dbRoot;
            } else {
                dbRoot = new File("." + File.separator + dbRoot).getCanonicalPath();
                log.warn("The database configuration file is not specified and there was no "
                         + Xindice.PROP_XINDICE_DB_HOME + " property set, "
                         + "so Xindice was unable to determine a database location. "
                         + "Database will be created relative to the current directory.");
            }
            config.setAttribute(Database.DBROOT, dbRoot);
        }

        return config;
    }
View Full Code Here

     * @see org.apache.xindice.util.Configurable#setConfig(org.apache.xindice.util.Configuration)
     */
    public void setConfig(Configuration config) throws XindiceException {
        this.config = config;

        Configuration colConfig = config.getChild(COLLECTIONS);
        if (colConfig != null) {
            colConfig.processChildren(COLLECTION, new ConfigurationCallback() {
                public void process(Configuration cfg) throws XindiceException {
                    // check for an existing Collection by name and, if found, skip creating a new Collection
                    // else, create a new child Collection, configure it an add it
                    // if the Collection already exists in our collections list,
                    // creating a new one will cause the old one to be discarded
View Full Code Here

     *                        or could not be read.
     */
    private Database getDatabase(String dbName, String uri) throws XMLDBException {
        Database database = Database.getDatabase(dbName);
        if (database == null && !isManaged()) {
            Configuration dbConfig = getConfiguration(dbName);
            if (log.isDebugEnabled()) {
                log.debug("Mounting database: '" + dbName + "'");
            }

            if (dbConfig == null) {
View Full Code Here

     * @param dbName Database name
     * @return Database configuration
     * @throws XMLDBException if unable to load database configuration
     */
    protected Configuration getConfiguration(String dbName) throws XMLDBException {
        Configuration config = loadConfiguration();

        // Find database config with the given database name
        Configuration[] roots = config.getChildren("root-collection");
        config = null;
        for (int i = 0; i < roots.length; i++) {
            if (dbName.equals(roots[i].getAttribute(Database.NAME))) {
                config = roots[i];
                break;
            }
        }

        if (config == null) {
            return null;
        }

        // Figure out database root
        String dbRoot = config.getAttribute(Database.DBROOT, Database.DBROOT_DEFAULT);
        if (!new File(dbRoot).isAbsolute()) {
            // Let's see if the XINDICE_DB_HOME property was specified.
            String home = null;
            try {
                // Try configuration first
                home = getProperty(PROP_XINDICE_DB_HOME);
            } catch (XMLDBException e) {
                /* ignored */
            }
            if (home == null) {
                // Fallback to system property
                home = System.getProperty(SYSPROP_XINDICE_DB_HOME);
            }

            if (home != null) {
                try {
                    dbRoot = new File(home + File.separator + dbRoot).getCanonicalPath();
                } catch (IOException e) {
                    log.warn("getCanonicalPath failed", e);
                    dbRoot = new File(home + File.separator + dbRoot).getAbsolutePath();
                }
            } else if (configFile != null) {
                dbRoot = new File(configFile).getAbsoluteFile().getParent() + File.separator + dbRoot;
            } else {
                log.warn("The database configuration file is not specified and there was no "
                         + SYSPROP_XINDICE_DB_HOME + " property set, "
                         + "so Xindice was unable to determine a database location. "
                         + "Database will be created relative to the current directory.");
                try {
                    dbRoot = new File("." + File.separator + dbRoot).getCanonicalPath();
                } catch (IOException e) {
                    log.warn("getCanonicalPath failed", e);
                    dbRoot = new File("." + File.separator + dbRoot).getAbsolutePath();
                }
            }
            try {
                config.setAttribute(Database.DBROOT, dbRoot);
            } catch (ReadOnlyException e) {
                /* ignored */
            }
        }

View Full Code Here

TOP

Related Classes of org.apache.xindice.util.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.