1 22 23 package org.xquark.extractor.runtime; 24 25 import java.util.Collection ; 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 29 import org.apache.xerces.impl.xpath.regex.RegularExpression; 30 import org.xquark.extractor.common.Constants; 31 32 36 public class Selection implements Constants { 38 private static final String RCSRevision = "$Revision: 1.1 $"; 39 private static final String RCSName = "$Name: $"; 40 41 private static RegularExpression regexNCName = 42 new RegularExpression("[\\i-[:]][\\c-[:]]*", "X"); 43 private static RegularExpression regexEntry = 44 new RegularExpression("", "X"); 45 46 private byte type = NONE; 47 private String name = null; 48 private boolean nameIsRegex = false; 49 private String targetNamespace = null; 51 private HashMap map = null; 52 private String alias = null; 53 private int elementFormDefault = UNQUALIFIED; 54 55 58 private boolean pkColumn = false; 59 60 61 public Selection( 62 String name, 63 String targetNamespace, 64 byte type, 65 HashMap map) { 66 this.name = name; 67 this.nameIsRegex = false; 68 this.targetNamespace = targetNamespace; 69 this.type = type; 70 this.map = map; 71 } 72 73 public Selection( 74 String name, 75 boolean nameIsRegex, 76 String targetNamespace, 77 byte type, 78 HashMap map) { 79 this.name = name; 80 this.nameIsRegex = nameIsRegex; 81 this.targetNamespace = targetNamespace; 82 this.type = type; 83 this.map = map; 84 } 85 86 public String getName() { 87 return name; 88 } 89 90 public void setNameForDefault(String name) { 91 if (this.name == null) 92 this.name = name; 93 } 94 95 public String getTargetNamespace() { 96 return targetNamespace; 97 } 98 public byte getType() { 99 return type; 100 } 101 public HashMap getMap() { 102 return map; 103 } 104 105 public void setElementFormDefault(int elementFormDefault) { 106 this.elementFormDefault = elementFormDefault; 107 } 108 109 public int getElementFormDefault() { 110 return elementFormDefault; 111 } 112 113 public void addToMap(String name, Selection selection) { 114 if (map == null) 115 map = new HashMap (); 116 map.put(name, selection); 117 } 118 119 public void setAlias(String alias) { 120 this.alias = alias; 121 } 122 123 public String getAlias() { 124 return this.alias; 125 } 126 127 131 142 public boolean noSubElementDef() { 143 return (null == map || map.isEmpty()); 144 } 145 146 public Selection includesSubElement(String str) { 147 if (map == null || map.isEmpty()) 148 return null; 149 if (null == str) { 150 return (Selection) this.map.get(null); 151 } 152 Collection values = map.values(); 154 Iterator it = values.iterator(); 155 Selection retSelection = null; 156 while (it.hasNext()) { 157 Selection value = (Selection) it.next(); 158 if (value == null || value.getName() == null) 160 continue; 161 regexEntry.setPattern(value.getName()); 163 if (regexEntry.matches(str)) { 164 if (value.getType() == Selection.EXCLUDES) 165 return null; 166 else if (value.getType() == Selection.INCLUDES) 167 if (retSelection == null) 168 retSelection = value; 169 } 170 } 171 return retSelection; 172 } 173 174 public void setPKColumn(boolean pkColumn) { 175 this.pkColumn = pkColumn; 176 } 177 178 public boolean getPKColumn() { 179 return this.pkColumn; 180 } 181 182 static public boolean verifyName(String name) { 183 return regexNCName.matches(name); 184 } 185 186 193 194 public String print() { 195 return print(0); 196 } 197 198 public String print(int tab) { 199 StringBuffer bufTab = new StringBuffer (); 200 for (int i=0;i<tab;i++) 201 bufTab.append("\t"); 202 StringBuffer buf = new StringBuffer (); 203 buf.append("\n"); 204 buf.append(bufTab.toString()); 205 buf.append("Name : "); 206 buf.append(name); 207 buf.append("\n"); 208 buf.append(bufTab.toString()); 209 buf.append("TargetNamespace : "); 210 buf.append(targetNamespace); 211 buf.append("\n"); 212 buf.append(bufTab.toString()); 213 buf.append("Type : "); 214 buf.append(type); 215 if (map != null) { 216 Collection col = map.values(); 217 Iterator it = col.iterator(); 218 while (it.hasNext()) { 219 buf.append("\n"); 220 buf.append(bufTab.toString()); 221 buf.append("Map entry -->"); 222 buf.append(((Selection) it.next()).print(tab+1)); 223 } 224 } 225 return buf.toString(); 226 } 227 228 public String toString() { 229 return print(); 230 } 231 } 232 | Popular Tags |