1 23 24 package com.sun.enterprise.config.serverbeans.validation; 25 26 import java.util.ArrayList ; 28 import java.util.Hashtable ; 29 import java.util.Iterator ; 30 import java.net.URL ; 31 import java.io.File ; 32 import java.io.IOException ; 33 34 import javax.xml.parsers.*; 36 import org.w3c.dom.*; 37 import org.xml.sax.SAXException ; 38 import org.xml.sax.InputSource ; 39 40 import java.util.logging.Logger ; 42 import java.util.logging.Level ; 43 import com.sun.logging.LogDomains; 44 45 import com.sun.enterprise.util.LocalStringManagerImpl; 46 47 import com.sun.enterprise.config.ConfigContext; 48 49 import com.sun.enterprise.config.ConfigException; 51 import com.sun.enterprise.config.ConfigBean; 52 53 import javax.management.Attribute ; 55 import javax.management.AttributeList ; 56 57 99 100 public class NameList { 101 102 static Logger _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER); 104 LocalStringManagerImpl _localStrings = StringManagerHelper.getLocalStringsManager(); 105 106 ConfigContext _ctx; 107 108 ArrayList _srcXPathes; 109 ArrayList _refXPathes; 110 111 Hashtable _srcLists = null; 112 Hashtable _refLists = null; 113 114 boolean _bKeepList = false; 115 String _name; 116 String _fullName; 117 String _scope; 118 int _scope_depth; 119 120 121 public NameList(String name, String fullName, String scope, ArrayList srcXPathes, ArrayList refXPathes, ConfigContext ctx, boolean bPreCreateAndKeepList) { 122 _name = name; 123 _fullName = fullName; 124 _srcXPathes = srcXPathes; 125 _refXPathes = refXPathes; 126 if(scope!=null && !scope.equals("/")) 127 { 128 _scope = scope.trim(); 129 _scope_depth = XPathHelper.getNumberOfElemTokens(_scope); 130 } 132 _ctx = ctx; 133 _bKeepList = bPreCreateAndKeepList; 134 _srcLists = new Hashtable (); 135 _refLists = new Hashtable (); 136 if(bPreCreateAndKeepList) 137 buildLists(null); 138 } 139 140 public String toString() 141 { 142 String str = "domain name: " + _name; 143 144 if(_srcLists!=null) 145 { 146 Iterator lists = _srcLists.keySet().iterator(); 147 while(lists.hasNext()) 148 { 149 String key = (String )lists.next(); 150 str = str + "\n " + "list name: " + key; 151 Hashtable list = (Hashtable )_srcLists.get(key); 152 if(list!=null) 153 { 154 Object [] keys = (Object [])list.keySet().toArray(); 155 for(int i=0; i<keys.length; i++) 156 str = str + "\n " + keys[i]; } 158 } 159 } 160 if(_refLists!=null) 161 { 162 Iterator lists = _refLists.keySet().iterator(); 163 while(lists.hasNext()) 164 { 165 String key = (String )lists.next(); 166 str = str + "\n " + "Referencees list name: " + key; 167 Hashtable list = (Hashtable )_refLists.get(key); 168 if(list!=null) 169 { 170 Object [] keys = (Object [])list.keySet().toArray(); 171 for(int i=0; i<keys.length; i++) 172 str = str + "\n " + keys[i]; } 174 } 175 } 176 return str; 177 } 178 179 public String getDomainValueSourceXPath(Object value, String xpath, boolean bRef) 180 { 181 String listName; 182 if(xpath==null || value==null || (listName = getListNameForXpath(xpath))==null) 183 return null; 184 Hashtable list = getNamedList(listName, bRef, false); 185 if(list!=null) 186 return (String )list.get(value); 187 return null; 188 } 189 190 public boolean isValueInNameDomain(Object value, String xpath, boolean bRef) 191 { 192 return (getDomainValueSourceXPath(value, xpath, bRef)!=null); 193 } 194 195 protected void buildLists(String onlyPrefix) 196 { 197 _srcLists.clear(); 199 _refLists.clear(); 200 201 buildList(_srcXPathes, onlyPrefix, false); 203 buildList(_refXPathes, onlyPrefix, true); 205 } 206 207 private void buildList(ArrayList xpathes, String onlyPrefix, boolean bRef) 208 { 209 AttributeList arr = XPathHelper.resolve(_ctx, xpathes, onlyPrefix); 211 for(int i=0; i<arr.size(); i++) 212 { 213 Attribute attr = (Attribute )arr.get(i); 214 String [] values = ((String )attr.getValue()).split(","); 215 for(int j=0; j<values.length; j++) 216 { 217 addValueToProperList(attr.getName(), values[j], bRef); 218 } 219 } 220 } 221 222 private String addValueToProperList(String xpath, Object value, boolean bRef) 223 { 224 String listName; 225 if(xpath==null || value==null || (listName = getListNameForXpath(xpath))==null) 226 return null; 227 addValueToNamedList(listName, xpath, value, bRef); 229 return listName; 230 } 231 232 private void addValueToNamedList(String listName, String sourceXPath, Object value, boolean bRef) 233 { 234 if(listName!=null && value!=null) 235 { 236 Hashtable list = getNamedList(listName, bRef, true); 237 if(list.get(value)==null) 238 list.put(value, sourceXPath); 239 } 240 } 241 242 private Hashtable getNamedList(String listName, boolean bRef, boolean bCreateIfNotFound) 243 { 244 Hashtable lists = bRef?_refLists:_srcLists; 245 Hashtable list = (Hashtable )lists.get(listName); 246 if(list==null && bCreateIfNotFound) 247 { 248 list = new Hashtable (); 249 lists.put(listName, list); 250 } 251 return list; 252 } 253 254 private String getListNameForXpath(String xpath) 255 { 256 return XPathHelper.getXPathPrefix(xpath, _scope_depth); 257 } 258 259 } 260 | Popular Tags |