View Javadoc
1 /*** 2 * PerspectiveManager.java 3 * 4 * Project: Dependency Tool 5 * 6 * WHEN WHO WHAT 7 * 06.06.2003 pko initial public release 8 * 10.12.2002 pko creation 9 * 10 * Copyright 2003 ELCA Informatique SA 11 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland 12 * www.elca.ch 13 * 14 * This library is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU Lesser General Public License 16 * as published by the Free Software Foundation; either version 2.1 of 17 * the License, or (at your option) any later version. 18 * 19 * This library is distributed in the hope that it will be useful, but 20 * WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 * Lesser General Public License for more details. 23 * 24 * You should have received a copy of the GNU Lesser General Public 25 * License along with this library; if not, write to the Free Software 26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 27 * USA 28 */ 29 30 package ch.elca.dependency.graph; 31 32 import java.io.File; 33 import java.io.FileInputStream; 34 import java.io.InputStream; 35 import java.net.URL; 36 import java.util.ArrayList; 37 38 import org.apache.commons.digester.xmlrules.DigesterLoader; 39 import org.apache.log4j.Logger; 40 41 /*** 42 * This class is responsible for loading perspectives from a config 43 * file and to make them available. 44 * 45 * @author Pawel Kowalski 46 * @version 1.0-beta 47 */ 48 public class PerspectiveManager { 49 50 /*** 51 * Log4j Logger. 52 */ 53 private static final Logger LOG = Logger.getLogger(PerspectiveManager.class); 54 55 /*** 56 * Path to the Digester rules 57 */ 58 private static final String RULES_PATH = "ch/elca/dependency/graph/"; 59 60 /*** 61 * Digester rules filename 62 */ 63 private static final String PERSPECTIVE_RULES = RULES_PATH + "process-rules.xml"; 64 65 //****************************************************************************************/ 66 // load perspectives 67 //****************************************************************************************/ 68 69 /*** 70 * Load Perspectives described in <code>File</code> 71 * perspectiveConfig. If the file specified doesn't exist or is 72 * not readable or it cann't be parsed by the Digester, just one 73 * default perspective will be available. 74 * 75 * @param perspectiveConfig a <code>String</code> identifying the 76 * perspectives config file. 77 */ 78 public static synchronized Perspective[] loadPerspectives(File perspectiveConfig) { 79 80 ArrayList perspectives = null; 81 82 // try to get a config stream (either user specified or custom) 83 // 84 try { 85 perspectives = internal_loadPerspective(perspectiveConfig); 86 LOG.debug("Perspectives loaded successfully: " + perspectiveConfig); 87 } catch (Exception e) { 88 89 // something went wrong, we need just an ArrayList in this case 90 // 91 perspectives = new ArrayList(); 92 93 String problem = "Perspectives file wrong or unavailable: " + perspectiveConfig; 94 LOG.error(problem); 95 96 problem += "\nWill start with a default perspective only"; 97 ch.elca.dependency.DPToolErrorDialog.showContinueDialog(problem, e); 98 99 } finally { 100 101 // in either case, we want a default perspective at front 102 // 103 perspectives.add(0, Perspective.DEFAULT_PERSPECTIVE); 104 return (Perspective[])perspectives.toArray(new Perspective[] {}); 105 } 106 } 107 108 /*** 109 * Load the first perspective defined in a config file. 110 * 111 * @param perspectiveConfig a <code>File</code> value 112 * @return a <code>Perspective</code> value 113 */ 114 public static synchronized Perspective loadFirstPerspective(File perspectiveConfig) { 115 116 Perspective perspective = null; 117 try { 118 perspective = (Perspective)internal_loadPerspective(perspectiveConfig).get(0); 119 LOG.debug("Perspective loaded successfully: " + perspectiveConfig); 120 } catch (Exception e) { 121 LOG.error("Perspectives file wrong or unavailable: " + perspectiveConfig); 122 perspective = null; 123 } 124 return perspective; 125 126 } 127 128 /*** 129 * Load perspectives. 130 * 131 * @param perspectiveConfig a <code>File</code> value 132 * @return an <code>ArrayList</code> value 133 * @exception Exception if an error occurs 134 */ 135 private static synchronized ArrayList internal_loadPerspective(File perspectiveConfig) throws Exception { 136 137 // prepare loading 138 // 139 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 140 URL rulesUrl = classLoader.getResource(PERSPECTIVE_RULES); 141 InputStream configStream = new FileInputStream(perspectiveConfig); 142 143 // load config file 144 // 145 return (ArrayList)DigesterLoader.load(rulesUrl, classLoader, configStream); 146 } 147 }

This page was automatically generated by Maven