Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 211   Methods: 10
NCLOC: 104   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WebAdminManager.java 33.3% 60% 20% 49.3%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: WebAdminManager.java 551435 2007-06-28 03:26:43Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.webadmin;
 21   
 22    import org.apache.commons.logging.Log;
 23    import org.apache.commons.logging.LogFactory;
 24    import org.apache.xindice.webadmin.viewer.HtmlCollectionViewer;
 25    import org.apache.xindice.webadmin.viewer.HtmlDatabaseViewer;
 26    import org.apache.xindice.webadmin.viewer.HtmlResourceViewer;
 27    import org.apache.xindice.webadmin.webdav.components.DAVComponent;
 28   
 29    import org.w3c.dom.Element;
 30    import org.w3c.dom.NamedNodeMap;
 31    import org.w3c.dom.Node;
 32    import org.w3c.dom.NodeList;
 33   
 34    import java.util.ArrayList;
 35    import java.util.HashMap;
 36    import java.util.Map;
 37   
 38    /**
 39    * Manager class that is responsible for reading configuration, initializing
 40    * all components, and dispatching calls.
 41    *
 42    * WebAdminManager configuration has several sections descibing different
 43    * components:
 44    * <ul>
 45    * <li>methods - list of supported WebDAV methods
 46    * <li>colviewers - list of collection-level operations for WebAdmin
 47    * <li>resviewers - list of resource-level operations for WebAdmin
 48    * <li>dbviewers - list of database-level operations for WebAdmin
 49    * </ul>
 50    *
 51    * @version $Revision: 551435 $, $Date: 2007-06-27 20:26:43 -0700 (Wed, 27 Jun 2007) $
 52    */
 53    public class WebAdminManager {
 54   
 55    private final Map methods = new HashMap();
 56    private final Map colViewers = new HashMap();
 57    private final Map resViewers = new HashMap();
 58    private final Map dbViewers = new HashMap();
 59   
 60    private static String[] methodsList;
 61    private static String[] colViewersList;
 62    private static String[] resViewersList;
 63    private static String[] dbViewersList;
 64   
 65    private static final Log log = LogFactory.getLog(WebAdminManager.class);
 66   
 67   
 68  1 public WebAdminManager(Element config) {
 69  1 Node node = config.getElementsByTagName("methods").item(0);
 70  1 try {
 71  1 methodsList = processSection(node, "method", methods);
 72    } catch (Exception e) {
 73  0 log.error("Failed to load WebDAV methods", e);
 74    }
 75   
 76  1 node = config.getElementsByTagName("colviewers").item(0);
 77  1 try {
 78  1 colViewersList = processSection(node, "viewer", colViewers);
 79    } catch (Exception e) {
 80  0 log.error("Failed to load WebAdmin collection viewers", e);
 81    }
 82   
 83  1 node = config.getElementsByTagName("resviewers").item(0);
 84  1 try {
 85  1 resViewersList = processSection(node, "viewer", resViewers);
 86    } catch (Exception e) {
 87  0 log.error("Failed to load WebAdmin resource viewers", e);
 88    }
 89   
 90  1 node = config.getElementsByTagName("dbviewers").item(0);
 91  1 try {
 92  1 dbViewersList = processSection(node, "viewer", dbViewers);
 93    } catch (Exception e) {
 94  0 log.error("Failed to load WebAdmin DB viewers", e);
 95    }
 96    }
 97   
 98  4 private String[] processSection(Node node, String name, Map storage) throws Exception {
 99  4 ArrayList list = new ArrayList();
 100   
 101  4 NodeList nodes = ((Element) node).getElementsByTagName(name);
 102  4 for (int i = 0; i < nodes.getLength(); i++) {
 103  25 Node child = nodes.item(i);
 104  25 NamedNodeMap attrs = child.getAttributes();
 105   
 106  25 String className = attrs.getNamedItem("class").getNodeValue();
 107  25 Object object = Class.forName(className).newInstance();
 108   
 109  25 String id = attrs.getNamedItem("id").getNodeValue();
 110  25 if (id != null && id.length() > 0) {
 111  25 storage.put(id, object);
 112  25 list.add(id);
 113    }
 114    }
 115   
 116  4 Node attr = node.getAttributes().getNamedItem("default");
 117  4 if (attr != null) {
 118  4 storage.put("default", storage.get(attr.getNodeValue()));
 119    }
 120   
 121  4 return (String[]) list.toArray(new String[0]);
 122    }
 123   
 124    /**
 125    * Gets class that handles specific DAV request.
 126    *
 127    * @param id Method name (e.g. PROPFIND, MKCOL)
 128    * @return applicable class, if it has been configured, null otherwise
 129    */
 130  0 public DAVComponent getMethod(String id) {
 131  0 return (DAVComponent) methods.get(id);
 132    }
 133   
 134    /**
 135    * Gets class that handles specific collection-level operation for WebAdmin.
 136    *
 137    * @param id Opration id
 138    * @return applicable class, if it has been configured, null otherwise
 139    */
 140  0 public HtmlCollectionViewer getCollectionViewer(String id) {
 141  0 if (id == null || id.length() == 0) {
 142  0 id = "default";
 143    }
 144   
 145  0 return (HtmlCollectionViewer) colViewers.get(id);
 146    }
 147   
 148    /**
 149    * Gets class that handles specific resource-level operation for WebAdmin.
 150    *
 151    * @param id Opration id
 152    * @return applicable class, if it has been configured, null otherwise
 153    */
 154  0 public HtmlResourceViewer getResourceViewer(String id) {
 155  0 if (id == null || id.length() == 0) {
 156  0 id = "default";
 157    }
 158   
 159  0 return (HtmlResourceViewer) resViewers.get(id);
 160    }
 161   
 162    /**
 163    * Gets class that handles specific database-level operation for WebAdmin.
 164    *
 165    * @param id Opration id
 166    * @return applicable class, if it has been configured, null otherwise
 167    */
 168  0 public HtmlDatabaseViewer getDatabaseViewer(String id) {
 169  0 if (id == null || id.length() == 0) {
 170  0 id = "default";
 171    }
 172   
 173  0 return (HtmlDatabaseViewer) dbViewers.get(id);
 174    }
 175   
 176    /**
 177    * Gets all supported methods.
 178    *
 179    * @return Array of all supported WebDAV methods.
 180    */
 181  0 public static String[] getMethods() {
 182  0 return methodsList;
 183    }
 184   
 185    /**
 186    * Gets all supported database-level operations.
 187    *
 188    * @return Array of all supported database-level operations.
 189    */
 190  0 public static String[] getDatabaseViewers() {
 191  0 return dbViewersList;
 192    }
 193   
 194    /**
 195    * Gets all supported collection-level operations.
 196    *
 197    * @return Array of all supported collection-level operations.
 198    */
 199  0 public static String[] getCollectionViewers() {
 200  0 return colViewersList;
 201    }
 202   
 203    /**
 204    * Gets all supported resource-level operations.
 205    *
 206    * @return Array of all supported resource-level operations.
 207    */
 208  0 public static String[] getResourceViewers() {
 209  0 return resViewersList;
 210    }
 211    }