1 16 package org.apache.commons.chain.config; 17 18 19 import org.apache.commons.chain.Catalog; 20 import org.apache.commons.chain.CatalogFactory; 21 import org.apache.commons.digester.Rule; 22 import org.xml.sax.Attributes ; 23 24 25 36 class ConfigCatalogRule extends Rule { 37 38 39 41 42 51 public ConfigCatalogRule(String nameAttribute, String catalogClass) { 52 super(); 53 this.nameAttribute = nameAttribute; 54 this.catalogClass = catalogClass; 55 } 56 57 58 60 61 65 private String catalogClass = null; 66 67 68 72 private String nameAttribute = null; 73 74 75 77 78 91 public void begin(String namespace, String name, Attributes attributes) 92 throws Exception { 93 94 Catalog catalog = null; 96 CatalogFactory factory = CatalogFactory.getInstance(); 97 String nameValue = attributes.getValue(nameAttribute); 98 if (nameValue == null) { 99 catalog = factory.getCatalog(); 100 } else { 101 catalog = factory.getCatalog(nameValue); 102 } 103 104 if (catalog == null) { 106 Class clazz = digester.getClassLoader().loadClass(catalogClass); 107 catalog = (Catalog) clazz.newInstance(); 108 if (nameValue == null) { 109 factory.setCatalog(catalog); 110 } else { 111 factory.addCatalog(nameValue, catalog); 112 } 113 } 114 115 digester.push(catalog); 117 118 } 119 120 121 } 122 | Popular Tags |