tikhomirov@295: /* tikhomirov@571: * Copyright (c) 2011-2013 TMate Software Ltd tikhomirov@295: * tikhomirov@295: * This program is free software; you can redistribute it and/or modify tikhomirov@295: * it under the terms of the GNU General Public License as published by tikhomirov@295: * the Free Software Foundation; version 2 of the License. tikhomirov@295: * tikhomirov@295: * This program is distributed in the hope that it will be useful, tikhomirov@295: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@295: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@295: * GNU General Public License for more details. tikhomirov@295: * tikhomirov@295: * For information on how to redistribute this software under tikhomirov@295: * the terms of a license other than GNU General Public License tikhomirov@295: * contact TMate Software at support@hg4j.com tikhomirov@295: */ tikhomirov@295: package org.tmatesoft.hg.core; tikhomirov@295: tikhomirov@295: import org.tmatesoft.hg.util.LogFacility; tikhomirov@571: import org.tmatesoft.hg.util.Path; tikhomirov@295: tikhomirov@295: /** tikhomirov@456: * Access to objects that might need to be shared between various distinct operations ran during the same working session tikhomirov@456: * (i.e. caches, log, etc.). It's unspecified whether session context is per repository or can span multiple repositories tikhomirov@295: * tikhomirov@456: *
Note, API is likely to be extended in future versions, adding more object to share.
tikhomirov@295: *
tikhomirov@295: * @author Artem Tikhomirov
tikhomirov@295: * @author TMate Software Ltd.
tikhomirov@295: */
tikhomirov@456: public abstract class SessionContext {
tikhomirov@456: // abstract class to facilitate adding more functionality without API break
tikhomirov@338:
tikhomirov@338: /**
tikhomirov@456: * Access wrapper for a system log facility.
tikhomirov@456: * @return facility to direct dumps to, never null
tikhomirov@338: */
tikhomirov@456: public abstract LogFacility getLog();
tikhomirov@456:
tikhomirov@456: /**
tikhomirov@456: * Access configuration parameters of the session.
tikhomirov@456: * @param name name of the session configuration parameter
tikhomirov@456: * @param defaultValue value to return if parameter is not configured
tikhomirov@456: * @return value of the session parameter, defaultValue if none found
tikhomirov@456: */
tikhomirov@456: public abstract Object getConfigurationProperty(String name, Object defaultValue);
tikhomirov@456: // perhaps, later may add Configuration object, with PropertyMarshal's helpers
tikhomirov@456: // e.g. when there's standalone Caches and WritableSessionProperties objects
tikhomirov@490:
tikhomirov@490: /**
tikhomirov@571: * Provide a factory to create {@link Path} objects.
tikhomirov@571: *
tikhomirov@571: * Occasionally, there's a need to construct a {@link Path} object from a string/byte data
tikhomirov@571: * kept in mercurial control files. Generally, default implementation (with {@link Path#create(CharSequence)}
tikhomirov@571: * is enough, however, if there's a need to control number of string objects in memory (i.e. prevent duplicates),
tikhomirov@571: * default implementation might need to be replaced with more sophisticated (e.g. using weak references or
tikhomirov@571: * just a huge hash set).
tikhomirov@571: *
tikhomirov@571: * @return factory to construct Path objects, never null
tikhomirov@571: */
tikhomirov@571: public Path.Source getPathFactory() {
tikhomirov@571: return new Path.Source() {
tikhomirov@571: public Path path(CharSequence p) {
tikhomirov@571: return Path.create(p);
tikhomirov@571: }
tikhomirov@571: };
tikhomirov@571: }
tikhomirov@571:
tikhomirov@571: /**
tikhomirov@490: * Providers of the context may implement
tikhomirov@490: */
tikhomirov@490: public interface Source {
tikhomirov@490: SessionContext getSessionContext();
tikhomirov@490: }
tikhomirov@667:
tikhomirov@667: public static final class SourcePrim implements Source {
tikhomirov@667: private final SessionContext ctx;
tikhomirov@667:
tikhomirov@667: public SourcePrim(SessionContext sessionContext) {
tikhomirov@667: assert sessionContext != null;
tikhomirov@667: ctx = sessionContext;
tikhomirov@667: }
tikhomirov@667: public SessionContext getSessionContext() {
tikhomirov@667: return ctx;
tikhomirov@667: }
tikhomirov@667: }
tikhomirov@295: }