All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.cayenne.configuration.DataNodeDescriptor Maven / Gradle / Ivy

There is a newer version: 4.2.1
Show newest version
/*****************************************************************
 *   Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 ****************************************************************/
package org.apache.cayenne.configuration;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.apache.cayenne.access.DataNode;
import org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory;
import org.apache.cayenne.conn.DataSourceInfo;
import org.apache.cayenne.resource.Resource;
import org.apache.cayenne.util.XMLEncoder;
import org.apache.cayenne.util.XMLSerializable;
import java.io.Serializable;

/**
 * A descriptor of {@link DataNode} configuration.
 * 
 * @since 3.1
 */
public class DataNodeDescriptor implements ConfigurationNode, XMLSerializable,
        Serializable, Comparable {

    protected String name;
    protected Collection dataMapNames;

    protected String parameters;
    protected String adapterType;
    protected String dataSourceFactoryType;
    protected String schemaUpdateStrategyType;

    // TODO: andrus, 12.13.2009: replace funky DataSourceInfo with a cleaner new class
    // (DataSourceDescriptor?)
    protected DataSourceInfo dataSourceDescriptor;

    protected Resource configurationSource;

    /**
     * @since 3.1
     */
    protected DataChannelDescriptor dataChannelDescriptor;

    public DataNodeDescriptor() {
        this(null);
    }

    public DataNodeDescriptor(String name) {
        this.dataMapNames = new ArrayList();
        this.name = name;
    }

    /**
     * @since 3.1
     */
    public DataChannelDescriptor getDataChannelDescriptor() {
        return dataChannelDescriptor;
    }

    /**
     * @since 3.1
     */
    public void setDataChannelDescriptor(DataChannelDescriptor dataChannelDescriptor) {
        this.dataChannelDescriptor = dataChannelDescriptor;
    }

    public int compareTo(DataNodeDescriptor o) {
        String o1 = getName();
        String o2 = o.getName();

        if (o1 == null) {
            return (o2 != null) ? -1 : 0;
        }
        else if (o2 == null) {
            return 1;
        }
        else {
            return o1.compareTo(o2);
        }
    }

    public  T acceptVisitor(ConfigurationNodeVisitor visitor) {
        return visitor.visitDataNodeDescriptor(this);
    }

    public void encodeAsXML(XMLEncoder encoder) {
        encoder.print("");

        if (!dataMapNames.isEmpty()) {

            List names = new ArrayList(dataMapNames);
            Collections.sort(names);

            for (String mapName : names) {
                encoder.print("");
            }
        }

        if (dataSourceDescriptor != null && XMLPoolingDataSourceFactory.class.getName().equals(dataSourceFactoryType)) {
            dataSourceDescriptor.encodeAsXML(encoder);
        }

        encoder.indent(-1);
        encoder.println("");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Collection getDataMapNames() {
        return dataMapNames;
    }

    /**
     * Returns extra DataNodeDescriptor parameters. This property is often used by custom
     * {@link DataSourceFactory} to configure a DataSource. E.g. JNDIDataSoirceFactory may
     * treat parameters String as a JNDI location of the DataSource, etc.
     */
    public String getParameters() {
        return parameters;
    }

    /**
     * Sets extra DataNodeDescriptor parameters. This property is often used by custom
     * {@link DataSourceFactory} to configure a DataSource. E.g. JNDIDataSoirceFactory may
     * treat parameters String as a JNDI location of the DataSource, etc.
     */
    public void setParameters(String parameters) {
        this.parameters = parameters;
    }

    public String getAdapterType() {
        return adapterType;
    }

    public void setAdapterType(String adapter) {
        this.adapterType = adapter;
    }

    public String getDataSourceFactoryType() {
        return dataSourceFactoryType;
    }

    public void setDataSourceFactoryType(String dataSourceFactory) {
        this.dataSourceFactoryType = dataSourceFactory;
    }

    public String getSchemaUpdateStrategyType() {
        return schemaUpdateStrategyType;
    }

    public void setSchemaUpdateStrategyType(String schemaUpdateStrategyClass) {
        this.schemaUpdateStrategyType = schemaUpdateStrategyClass;
    }

    public DataSourceInfo getDataSourceDescriptor() {
        return dataSourceDescriptor;
    }

    public void setDataSourceDescriptor(DataSourceInfo dataSourceDescriptor) {
        this.dataSourceDescriptor = dataSourceDescriptor;
    }

    /**
     * Returns configuration resource for this descriptor. Configuration is usually shared
     * with the parent {@link DataChannelDescriptor}.
     */
    public Resource getConfigurationSource() {
        return configurationSource;
    }

    /**
     * Sets configuration resource for this descriptor. Configuration is usually shared
     * with the parent {@link DataChannelDescriptor} and has to be synchronized when it
     * changes in the parent.
     */
    public void setConfigurationSource(Resource configurationResource) {
        this.configurationSource = configurationResource;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy