001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021package org.biojava.nbio.structure.cath; 022 023import org.biojava.nbio.structure.scop.ScopFactory; 024 025import java.util.HashMap; 026import java.util.Map; 027 028/** 029 * Controls global {@link CathDatabase CathDatabases} being used. 030 * Implements a multiton pattern through {@link #getCathDatabase(String)}, 031 * and a singleton pattern through {@link #getCathDatabase()}. 032 * @author dmyersturnbull 033 * @see ScopFactory 034 * @see CathInstallation 035 */ 036public class CathFactory { 037 038 public static final String VERSION_3_5_0 = "3_5_0"; 039 public static final String VERSION_4_0_0 = "4_0_0"; 040 public static final String VERSION_4_1_0 = "4_1_0"; 041 public static final String VERSION_4_2_0 = "4_2_0"; 042 public static final String LATEST_VERSION = VERSION_4_2_0; 043 044 public static final String DEFAULT_VERSION = LATEST_VERSION; 045 046 private static CathDatabase cath; 047 048 private static Map<String, CathDatabase> versions = new HashMap<String, CathDatabase>(); 049 050 /** 051 * Sets the default (singleton) CathDatabase. 052 */ 053 public static void setCath(CathDatabase cath) { 054 CathFactory.cath = cath; 055 } 056 057 /** 058 * Returns the default (singleton) CathDatabase. 059 * If the database is null, this will recreate it (lazy initialization). 060 */ 061 public static CathDatabase getCathDatabase() { 062 if (cath == null) { 063 cath = new CathInstallation(); 064 } 065 return cath; 066 } 067 068 private CathFactory() { 069 070 } 071 072 /** 073 * Returns a CATH database of the specified version. 074 * @param version For example, "3.5.0" 075 */ 076 public static CathDatabase getCathDatabase(String version) { 077 if (version == null) version = DEFAULT_VERSION; 078 CathDatabase cath = versions.get(version); 079 if (cath == null) { 080 CathInstallation newCath = new CathInstallation(); 081 newCath.setCathVersion(version); 082 cath = newCath; 083 } 084 return cath; 085 } 086 087}