This project has retired. For details please refer to its
Attic page.
SessionFactoryImpl xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.client.runtime;
2021import java.util.ArrayList;
22import java.util.List;
23import java.util.Map;
2425import org.apache.chemistry.opencmis.client.api.ObjectFactory;
26import org.apache.chemistry.opencmis.client.api.Repository;
27import org.apache.chemistry.opencmis.client.api.Session;
28import org.apache.chemistry.opencmis.client.api.SessionFactory;
29import org.apache.chemistry.opencmis.client.runtime.cache.Cache;
30import org.apache.chemistry.opencmis.client.runtime.repository.RepositoryImpl;
31import org.apache.chemistry.opencmis.commons.SessionParameter;
32import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
33import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
34import org.apache.chemistry.opencmis.commons.spi.AuthenticationProvider;
35import org.apache.chemistry.opencmis.commons.spi.CmisBinding;
3637/**38 * Default implementation of a session factory. Used by unit tests or39 * applications that depend directly on runtime implementation.40 * <p>41 * <code>42 * SessionFactory sf = new SessionFactoryImpl();<br>43 * Session s = sf.createSession(...);44 * </code>45 * <p>46 * Alternative factory lookup methods:47 * <p>48 * <p>49 * <code>50 * Context ctx = new DefaultContext();<br>51 * SessionFactory = ctx.lookup(jndi_key);52 * </code>53 */54publicclassSessionFactoryImpl implements SessionFactory {
5556protectedSessionFactoryImpl() {
57 }
5859publicstaticSessionFactoryImpl newInstance() {
60returnnewSessionFactoryImpl();
61 }
6263public Session createSession(Map<String, String> parameters) {
64return createSession(parameters, null, null, null);
65 }
6667/**68 * Creates a new session. The provided object factory, authentication69 * provider and cache instance override the values in the session parameters70 * if they are not <code>null</code>.71 * 72 * @param parameters73 * a {@code Map} of name/value pairs with parameters for the74 * session75 * @param objectFactory76 * an object factory instance77 * @param authenticationProvider78 * an authentication provider instance79 * @param cache80 * a cache instance81 * @return a {@link Session} connected to the CMIS repository82 * @throws CmisBaseException83 * if the connection could not be established84 * 85 * @see SessionParameter86 */87public Session createSession(Map<String, String> parameters, ObjectFactory objectFactory,
88 AuthenticationProvider authenticationProvider, Cache cache) {
89SessionImpl session = newSessionImpl(parameters, objectFactory, authenticationProvider, cache);
90 session.connect();
9192return session;
93 }
9495public List<Repository> getRepositories(Map<String, String> parameters) {
96return getRepositories(parameters, null, null, null);
97 }
9899/**100 * Returns all repositories that are available at the endpoint. See101 * {@link #createSession(Map, ObjectFactory, AuthenticationProvider, Cache)}102 * for parameter details. The parameter103 * {@code SessionParameter.REPOSITORY_ID} should not be set.104 */105public List<Repository> getRepositories(Map<String, String> parameters, ObjectFactory objectFactory,
106 AuthenticationProvider authenticationProvider, Cache cache) {
107 CmisBinding binding = CmisBindingHelper.createBinding(parameters, authenticationProvider);
108109 List<RepositoryInfo> repositoryInfos = binding.getRepositoryService().getRepositoryInfos(null);
110111 List<Repository> result = new ArrayList<Repository>();
112for (RepositoryInfo data : repositoryInfos) {
113 result.add(newRepositoryImpl(data, parameters, this, objectFactory, authenticationProvider, cache));
114 }
115116return result;
117 }
118 }