001/*
002 * Copyright (c) 2006-2014 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Bogdan Stefanescu
011 *     Florent Guillaume
012 */
013package org.nuxeo.ecm.core.api.repository;
014
015import java.io.Serializable;
016import java.util.Map;
017import java.util.concurrent.Callable;
018
019import org.nuxeo.common.xmap.annotation.XNode;
020import org.nuxeo.common.xmap.annotation.XObject;
021import org.nuxeo.ecm.core.api.CoreInstance;
022import org.nuxeo.ecm.core.api.CoreSession;
023
024/**
025 * A high-level repository descriptor, from which you get a {@link CoreSession} when calling {@link #open}.
026 * <p>
027 * This is obsolete as an extension point, use org.nuxeo.ecm.core.storage.sql.RepositoryService instead. Descriptor kept
028 * for backward-compatibility.
029 * <p>
030 * Note that this is still use as an object returned by the core api RepositoryManager.
031 */
032@XObject("repository")
033public class Repository {
034
035    @XNode("@name")
036    private String name;
037
038    @XNode("@label")
039    private String label;
040
041    @XNode("@isDefault")
042    private Boolean isDefault;
043
044    /**
045     * Factory to used to create the low-level repository.
046     */
047    private Callable<Object> repositoryFactory;
048
049    public Repository() {
050    }
051
052    public Repository(String name, String label, Boolean isDefault, Callable<Object> repositoryFactory) {
053        this.name = name;
054        this.label = label;
055        this.isDefault = isDefault;
056        this.repositoryFactory = repositoryFactory;
057    }
058
059    public void setLabel(String label) {
060        this.label = label;
061    }
062
063    public void setDefault(Boolean isDefault) {
064        this.isDefault = isDefault;
065    }
066
067    public String getName() {
068        return name;
069    }
070
071    public String getLabel() {
072        return label;
073    }
074
075    public Boolean getDefault() {
076        return isDefault;
077    }
078
079    public boolean isDefault() {
080        return Boolean.TRUE.equals(isDefault);
081    }
082
083    public Callable<Object> getRepositoryFactory() {
084        return repositoryFactory;
085    }
086
087    /**
088     * @deprecated since 5.9.3, use {@link CoreInstance#openCoreSession} instead.
089     */
090    @Deprecated
091    public CoreSession open() {
092        return CoreInstance.openCoreSession(name);
093    }
094
095    /**
096     * @deprecated since 5.9.3, use {@link CoreInstance#openCoreSession} instead.
097     */
098    @Deprecated
099    public CoreSession open(Map<String, Serializable> context) {
100        return CoreInstance.openCoreSession(name, context);
101    }
102
103    /**
104     * @deprecated since 5.9.3, use {@link CoreSession#close} instead.
105     */
106    @Deprecated
107    public static void close(CoreSession session) {
108        session.close();
109    }
110
111    @Override
112    public String toString() {
113        return getClass().getSimpleName() + " {name=" + name + ", label=" + label + '}';
114    }
115
116}