Search in sources :

Example 1 with DataStoreFactory

use of org.apache.jackrabbit.core.data.DataStoreFactory in project jackrabbit by apache.

the class RepositoryConfigurationParser method parseRepositoryConfig.

/**
     * Parses repository configuration. Repository configuration uses the
     * following format:
     * <pre>
     *   &lt;Repository&gt;
     *     &lt;FileSystem ...&gt;
     *     &lt;Security appName="..."&gt;
     *       &lt;SecurityManager ...&gt;
     *       &lt;AccessManager ...&gt;
     *       &lt;LoginModule ... (optional)&gt;
     *     &lt;/Security&gt;
     *     &lt;Workspaces rootPath="..." defaultWorkspace="..."/&gt;
     *     &lt;Workspace ...&gt;
     *     &lt;Versioning ...&gt;
     *   &lt;/Repository&gt;
     * </pre>
     * <p>
     * The <code>FileSystem</code> element is a
     * {@link #parseBeanConfig(Element,String) bean configuration} element,
     * that specifies the file system implementation for storing global
     * repository information. The <code>Security</code> element contains
     * an <code>AccessManager</code> bean configuration element and the
     * JAAS name of the repository application. The <code>Workspaces</code>
     * element contains general workspace parameters, and the
     * <code>Workspace</code> element is a template for the individual
     * workspace configuration files. The <code>Versioning</code> element
     * contains
     * {@link #parseVersioningConfig(Element) versioning configuration} for
     * the repository.
     * <p>
     * In addition to the configured information, the returned repository
     * configuration object also contains the repository home directory path
     * that is given as the ${rep.home} parser variable. Note that the
     * variable <em>must</em> be available for the configuration document to
     * be correctly parsed.
     * <p>
     * {@link #replaceVariables(String) Variable replacement} is performed
     * on the security application name attribute, the general workspace
     * configuration attributes, and on the file system, access manager,
     * and versioning configuration information.
     * <p>
     * Note that the returned repository configuration object has not been
     * initialized.
     *
     * @param xml repository configuration document
     * @return repository configuration
     * @throws ConfigurationException if the configuration is broken
     * @see #parseBeanConfig(Element, String)
     * @see #parseVersioningConfig(Element)
     */
public RepositoryConfig parseRepositoryConfig(InputSource xml) throws ConfigurationException {
    Element root = parseXML(xml, true);
    // Repository home directory
    String home = getVariables().getProperty(REPOSITORY_HOME_VARIABLE);
    // File system implementation
    FileSystemFactory fsf = getFileSystemFactory(root, FILE_SYSTEM_ELEMENT);
    // Security configuration and access manager implementation
    Element security = getElement(root, SECURITY_ELEMENT);
    SecurityConfig securityConfig = parseSecurityConfig(security);
    // General workspace configuration
    Element workspaces = getElement(root, WORKSPACES_ELEMENT);
    String workspaceDirectory = replaceVariables(getAttribute(workspaces, ROOT_PATH_ATTRIBUTE));
    String workspaceConfigDirectory = getAttribute(workspaces, CONFIG_ROOT_PATH_ATTRIBUTE, null);
    String defaultWorkspace = replaceVariables(getAttribute(workspaces, DEFAULT_WORKSPACE_ATTRIBUTE));
    int maxIdleTime = Integer.parseInt(getAttribute(workspaces, MAX_IDLE_TIME_ATTRIBUTE, "0"));
    // Workspace configuration template
    Element template = getElement(root, WORKSPACE_ELEMENT);
    // Versioning configuration
    VersioningConfig vc = parseVersioningConfig(root);
    // Query handler implementation
    QueryHandlerFactory qhf = getQueryHandlerFactory(root);
    // Optional journal configuration
    ClusterConfig cc = parseClusterConfig(root, new File(home));
    // Optional data store factory
    DataStoreFactory dsf = getDataStoreFactory(root, home);
    RepositoryLockMechanismFactory rlf = getRepositoryLockMechanismFactory(root);
    // Optional data source configuration
    DataSourceConfig dsc = parseDataSourceConfig(root);
    return new RepositoryConfig(home, securityConfig, fsf, workspaceDirectory, workspaceConfigDirectory, defaultWorkspace, maxIdleTime, template, vc, qhf, cc, dsf, rlf, dsc, connectionFactory, this);
}
Also used : Element(org.w3c.dom.Element) FileSystemFactory(org.apache.jackrabbit.core.fs.FileSystemFactory) RepositoryLockMechanismFactory(org.apache.jackrabbit.core.util.RepositoryLockMechanismFactory) QueryHandlerFactory(org.apache.jackrabbit.core.query.QueryHandlerFactory) File(java.io.File) DataStoreFactory(org.apache.jackrabbit.core.data.DataStoreFactory)

Example 2 with DataStoreFactory

use of org.apache.jackrabbit.core.data.DataStoreFactory in project jackrabbit by apache.

the class RepositoryConfigurationParser method getDataStoreFactory.

/**
     * Parses data store configuration. Data store configuration uses the following format:
     * <pre>
     *   &lt;DataStore class="..."&gt;
     *     &lt;param name="..." value="..."&gt;
     *     ...
     *   &lt;/DataStore&gt;
     * </pre>
     * Its also possible to configure a multi data store. The configuration uses following format:
     * <pre>
     *   &lt;DataStore class="org.apache.jackrabbit.core.data.MultiDataStore"&gt;
     *     &lt;param name="primary" value="org.apache.jackrabbit.core.data.db.XXDataStore"&gt;
     *         &lt;param name="..." value="..."&gt;
     *         ...
     *     &lt;/param&gt;
     *     &lt;param name="archive" value="org.apache.jackrabbit.core.data.db.XXDataStore"&gt;
     *         &lt;param name="..." value="..."&gt;
     *         ...
     *     &lt;/param&gt;
     *   &lt;/DataStore&gt;
     * </pre>
     * <p>
     * <code>DataStore</code> is a {@link #parseBeanConfig(Element,String) bean configuration}
     * element.
     *
     * @param parent configuration element
     * @param directory the repository directory
     * @return data store factory
     * @throws ConfigurationException if the configuration is broken
     */
protected DataStoreFactory getDataStoreFactory(final Element parent, final String directory) throws ConfigurationException {
    return new DataStoreFactory() {

        public DataStore getDataStore() throws RepositoryException {
            NodeList children = parent.getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                Node child = children.item(i);
                if (child.getNodeType() == Node.ELEMENT_NODE && DATA_STORE_ELEMENT.equals(child.getNodeName())) {
                    BeanConfig bc = parseBeanConfig(parent, DATA_STORE_ELEMENT);
                    bc.setValidate(false);
                    DataStore store = bc.newInstance(DataStore.class);
                    if (store instanceof MultiDataStore) {
                        DataStore primary = null;
                        DataStore archive = null;
                        NodeList subParamNodes = child.getChildNodes();
                        for (int x = 0; x < subParamNodes.getLength(); x++) {
                            Node paramNode = subParamNodes.item(x);
                            if (paramNode.getNodeType() == Node.ELEMENT_NODE && (PRIMARY_DATASTORE_ATTRIBUTE.equals(paramNode.getAttributes().getNamedItem("name").getNodeValue()) || ARCHIVE_DATASTORE_ATTRIBUTE.equals(paramNode.getAttributes().getNamedItem("name").getNodeValue()))) {
                                try {
                                    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
                                    Element newParent = document.createElement("parent");
                                    document.appendChild(newParent);
                                    Element datastoreElement = document.createElement(DATA_STORE_ELEMENT);
                                    newParent.appendChild(datastoreElement);
                                    NodeList childNodes = paramNode.getChildNodes();
                                    for (int y = 0; childNodes.getLength() > y; y++) {
                                        datastoreElement.appendChild(document.importNode(childNodes.item(y), true));
                                    }
                                    NamedNodeMap attributes = paramNode.getAttributes();
                                    for (int z = 0; attributes.getLength() > z; z++) {
                                        Node item = attributes.item(z);
                                        datastoreElement.setAttribute(CLASS_ATTRIBUTE, item.getNodeValue());
                                    }
                                    DataStore subDataStore = getDataStoreFactory(newParent, directory).getDataStore();
                                    if (!MultiDataStoreAware.class.isAssignableFrom(subDataStore.getClass())) {
                                        throw new ConfigurationException("Only MultiDataStoreAware datastore's can be used within a MultiDataStore.");
                                    }
                                    String type = getAttribute((Element) paramNode, NAME_ATTRIBUTE);
                                    if (PRIMARY_DATASTORE_ATTRIBUTE.equals(type)) {
                                        primary = subDataStore;
                                    } else if (ARCHIVE_DATASTORE_ATTRIBUTE.equals(type)) {
                                        archive = subDataStore;
                                    }
                                } catch (Exception e) {
                                    throw new ConfigurationException("Failed to parse the MultiDataStore element.", e);
                                }
                            }
                        }
                        if (primary == null || archive == null) {
                            throw new ConfigurationException("A MultiDataStore must have configured a primary and archive datastore");
                        }
                        ((MultiDataStore) store).setPrimaryDataStore(primary);
                        ((MultiDataStore) store).setArchiveDataStore(archive);
                    }
                    store.init(directory);
                    return store;
                }
            }
            return null;
        }
    };
}
Also used : MultiDataStoreAware(org.apache.jackrabbit.core.data.MultiDataStoreAware) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) JournalException(org.apache.jackrabbit.core.journal.JournalException) MultiDataStore(org.apache.jackrabbit.core.data.MultiDataStore) DataStore(org.apache.jackrabbit.core.data.DataStore) MultiDataStore(org.apache.jackrabbit.core.data.MultiDataStore) DataStoreFactory(org.apache.jackrabbit.core.data.DataStoreFactory)

Aggregations

DataStoreFactory (org.apache.jackrabbit.core.data.DataStoreFactory)2 Element (org.w3c.dom.Element)2 File (java.io.File)1 IOException (java.io.IOException)1 RepositoryException (javax.jcr.RepositoryException)1 ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)1 DataStore (org.apache.jackrabbit.core.data.DataStore)1 MultiDataStore (org.apache.jackrabbit.core.data.MultiDataStore)1 MultiDataStoreAware (org.apache.jackrabbit.core.data.MultiDataStoreAware)1 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)1 FileSystemFactory (org.apache.jackrabbit.core.fs.FileSystemFactory)1 JournalException (org.apache.jackrabbit.core.journal.JournalException)1 QueryHandlerFactory (org.apache.jackrabbit.core.query.QueryHandlerFactory)1 RepositoryLockMechanismFactory (org.apache.jackrabbit.core.util.RepositoryLockMechanismFactory)1 Document (org.w3c.dom.Document)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1