Changeset 22714
- Timestamp:
- 03/09/10 17:02:37 (17 months ago)
- Location:
- branches/mnw21/pathquery_refactor/intermine
- Files:
-
- 4 edited
-
api/main/src/org/intermine/api/xml/SavedQueryHandler.java (modified) (1 diff)
-
api/main/src/org/intermine/api/xml/TemplateQueryHandler.java (modified) (4 diffs)
-
pathquery/main/src/org/intermine/pathquery/PathQueryBinding.java (modified) (1 diff)
-
pathquery/main/src/org/intermine/pathquery/PathQueryHandler.java (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/mnw21/pathquery_refactor/intermine/api/main/src/org/intermine/api/xml/SavedQueryHandler.java
r21699 r22714 62 62 */ 63 63 @Override 64 public void endElement(String uri, String localName, String qName) {64 public void endElement(String uri, String localName, String qName) throws SAXException { 65 65 super.endElement(uri, localName, qName); 66 66 if ("saved-query".equals(qName)) { -
branches/mnw21/pathquery_refactor/intermine/api/main/src/org/intermine/api/xml/TemplateQueryHandler.java
r21957 r22714 13 13 import java.util.ArrayList; 14 14 import java.util.HashMap; 15 import java.util.LinkedHashSet; 15 16 import java.util.List; 16 17 import java.util.Map; … … 87 88 + templateName); 88 89 } 89 PathConstraint constraint = processConstraint(query, path, attrs); 90 if ((code == null) || (constraint instanceof PathConstraintLoop)) { 91 query.addConstraint(constraint); 92 } else { 93 query.addConstraint(constraint, code); 90 constraintPath = path; 91 constraintAttributes = new HashMap<String, String>(); 92 for (int i = 0; i < attrs.getLength(); i++) { 93 constraintAttributes.put(attrs.getQName(i), attrs.getValue(i)); 94 94 } 95 String description = attrs.getValue("description"); 96 String editable = attrs.getValue("editable"); 97 if ("true".equals(editable)) { 98 editableConstraints.add(constraint); 99 } 100 constraintDescriptions.put(constraint, description); 101 String switchable = attrs.getValue("switchable"); 102 if ("on".equals(switchable)) { 103 constraintSwitchables.put(constraint, SwitchOffAbility.ON); 104 } else if ("off".equals(switchable)) { 105 constraintSwitchables.put(constraint, SwitchOffAbility.OFF); 106 } 95 constraintValues = new LinkedHashSet<String>(); 96 constraintCode = code; 97 107 98 } 108 99 } else { … … 115 106 */ 116 107 @Override 117 public void endElement(String uri, String localName, String qName) { 118 super.endElement(uri, localName, qName); 108 public void endElement(String uri, String localName, String qName) throws SAXException { 119 109 if ("template".equals(qName)) { 120 110 TemplateQuery t = new TemplateQuery(templateName, templateTitle, templateComment, … … 130 120 templates.put(templateName, t); 131 121 reset(); 122 } else if ("constraint".equals(qName)) { 123 PathConstraint constraint = processConstraint(query, constraintPath, 124 constraintAttributes, constraintValues); 125 if ((constraintCode == null) || (constraint instanceof PathConstraintLoop)) { 126 query.addConstraint(constraint); 127 } else { 128 query.addConstraint(constraint, constraintCode); 129 } 130 String description = constraintAttributes.get("description"); 131 String editable = constraintAttributes.get("editable"); 132 if ("true".equals(editable)) { 133 editableConstraints.add(constraint); 134 } 135 constraintDescriptions.put(constraint, description); 136 String switchable = constraintAttributes.get("switchable"); 137 if ("on".equals(switchable)) { 138 constraintSwitchables.put(constraint, SwitchOffAbility.ON); 139 } else if ("off".equals(switchable)) { 140 constraintSwitchables.put(constraint, SwitchOffAbility.OFF); 141 } 142 constraintPath = null; 143 } else { 144 super.endElement(uri, localName, qName); 132 145 } 133 146 } -
branches/mnw21/pathquery_refactor/intermine/pathquery/main/src/org/intermine/pathquery/PathQueryBinding.java
r22151 r22714 181 181 } else if (constraint.getKey() instanceof PathConstraintMultiValue) { 182 182 writer.writeAttribute("op", "" + constraint.getKey().getOp()); 183 StringBuilder sb = new StringBuilder();184 boolean needComma = false;185 183 for (String value : ((PathConstraintMultiValue) constraint.getKey()).getValues()) { 186 if (value.contains(",")) {187 throw new XMLStreamException("Value in MultiValue contains a comma - this "188 + "query cannot be represented in XML");189 }190 184 if (!value.equals(value.trim())) { 191 185 throw new XMLStreamException("Value in MultiValue starts or ends with " 192 186 + "whitespace - this query cannot be represented in XML"); 193 187 } 194 if (needComma) { 195 sb.append(", "); 196 } 197 needComma = true; 198 sb.append(value); 199 } 200 writer.writeAttribute("values", sb.toString()); 188 writer.writeStartElement("value"); 189 writer.writeCharacters(value); 190 writer.writeEndElement(); 191 } 201 192 } else if (constraint.getKey() instanceof PathConstraintLoop) { 202 193 writer.writeAttribute("op", "" + constraint.getKey().getOp()); -
branches/mnw21/pathquery_refactor/intermine/pathquery/main/src/org/intermine/pathquery/PathQueryHandler.java
r22186 r22714 49 49 "float", "double", "short", "int", "long", "Boolean", "Float", "Double", "Short", 50 50 "Integer", "Long", "BigDecimal", "Date", "String")); 51 private StringBuilder valueBuffer = null; 52 protected String constraintPath = null; 53 protected Map<String, String> constraintAttributes = null; 54 protected Collection<String> constraintValues = null; 55 protected String constraintCode = null; 51 56 52 57 /** … … 66 71 @SuppressWarnings("unused") String localName, String qName, Attributes attrs) 67 72 throws SAXException { 73 if (valueBuffer != null) { 74 throw new SAXException("Cannot have any tags inside a value tag"); 75 } 76 if ((constraintPath != null) && (!"value".equals(qName))) { 77 throw new SAXException("Cannot have anything other than value tag inside a constraint"); 78 } 68 79 if ("query-list".equals(qName)) { 69 80 // Do nothing … … 132 143 } else { 133 144 path = path.replace(':', '.'); 134 PathConstraint constraint = processConstraint(query, path, attrs); 135 if (code == null) { 136 query.addConstraint(constraint); 137 } else { 138 query.addConstraint(constraint, code); 139 } 145 constraintPath = path; 146 constraintAttributes = new HashMap<String, String>(); 147 for (int i = 0; i < attrs.getLength(); i++) { 148 constraintAttributes.put(attrs.getQName(i), attrs.getValue(i)); 149 } 150 constraintValues = new LinkedHashSet<String>(); 151 constraintCode = code; 140 152 } 141 153 } else if ("pathDescription".equals(qName)) { … … 153 165 throw new SAXException("Unknown join style " + type + " for path " + pathString); 154 166 } 167 } else if ("value".equals(qName)) { 168 valueBuffer = new StringBuilder(); 155 169 } 156 170 } … … 162 176 * @param path the path of the constraint to create 163 177 * @param attrs the XML attributes 178 * @param values the enclosed values 164 179 * @return a PathConstraint object 165 180 * @throws SAXException if something is wrong 166 181 */ 167 182 public PathConstraint processConstraint(PathQuery query, String path, 168 Attributes attrs) throws SAXException {169 ConstraintOp constraintOp = ConstraintOp.getConstraintOp(attrs.get Value("op"));183 Map<String, String> attrs, Collection<String> values) throws SAXException { 184 ConstraintOp constraintOp = ConstraintOp.getConstraintOp(attrs.get("op")); 170 185 if (ConstraintOp.CONTAINS.equals(constraintOp)) { 171 186 constraintOp = ConstraintOp.MATCHES; … … 175 190 if (PathConstraintLoop.VALID_OPS.contains(constraintOp)) { 176 191 try { 177 Path constraintPath = query.makePath(path);178 if (!constraintPath .endIsAttribute()) {192 Path constraintPath2 = query.makePath(path); 193 if (!constraintPath2.endIsAttribute()) { 179 194 isLoop = true; 180 195 } … … 185 200 } 186 201 if (isLoop) { 187 String loopPath = attrs.get Value("loopPath");202 String loopPath = attrs.get("loopPath"); 188 203 if (loopPath == null) { 189 loopPath = attrs.get Value("value");204 loopPath = attrs.get("value"); 190 205 } 191 206 loopPath = loopPath.replace(':', '.'); 192 207 return new PathConstraintLoop(path, constraintOp, loopPath); 193 208 } else { 194 String constraintValue = attrs.get Value("value");209 String constraintValue = attrs.get("value"); 195 210 return new PathConstraintAttribute(path, constraintOp, constraintValue); 196 211 } … … 198 213 return new PathConstraintNull(path, constraintOp); 199 214 } else if (PathConstraintBag.VALID_OPS.contains(constraintOp)) { 200 String bag = attrs.get Value("value");201 String ids = attrs.get Value("ids");215 String bag = attrs.get("value"); 216 String ids = attrs.get("ids"); 202 217 if (bag != null) { 203 218 return new PathConstraintBag(path, constraintOp, bag); … … 214 229 return new PathConstraintIds(path, constraintOp, idsCollection); 215 230 } else { 216 String values = attrs.getValue("values");217 String[] valueArray = values.split(",");218 231 Collection<String> valuesCollection = new LinkedHashSet<String>(); 219 for (String value : value Array) {232 for (String value : values) { 220 233 valuesCollection.add(value.trim()); 221 234 } … … 223 236 } 224 237 } else if (ConstraintOp.LOOKUP.equals(constraintOp)) { 225 String lookup = attrs.get Value("value");226 String extraValue = attrs.get Value("extraValue");238 String lookup = attrs.get("value"); 239 String extraValue = attrs.get("extraValue"); 227 240 return new PathConstraintLookup(path, lookup, extraValue); 228 241 } else { 229 242 throw new SAXException("Invalid operation type: " + constraintOp 230 + " (from text \"" + attrs.get Value("op") + "\"");243 + " (from text \"" + attrs.get("op") + "\", attributes: " + attrs + ")"); 231 244 } 232 245 } … … 236 249 */ 237 250 @Override public void endElement(@SuppressWarnings("unused") String uri, 238 @SuppressWarnings("unused") String localName, String qName){251 @SuppressWarnings("unused") String localName, String qName) throws SAXException { 239 252 if ("query".equals(qName)) { 240 253 if (constraintLogic != null) { … … 263 276 } else if ("node".equals(qName)) { 264 277 currentNodePath = null; 278 } else if ("constraint".equals(qName) && (constraintPath != null)) { 279 PathConstraint constraint = processConstraint(query, constraintPath, 280 constraintAttributes, constraintValues); 281 if (constraintCode == null) { 282 query.addConstraint(constraint); 283 } else { 284 query.addConstraint(constraint, constraintCode); 285 } 286 constraintPath = null; 287 } else if ("value".equals(qName)) { 288 if (valueBuffer == null) { 289 throw new NullPointerException("valueBuffer is null while closing value tag"); 290 } 291 constraintValues.add(valueBuffer.toString()); 292 } 293 } 294 295 /** 296 * {@inheritDoc} 297 */ 298 @Override 299 public void characters(char[] ch, int start, int length) { 300 if (valueBuffer != null) { 301 valueBuffer.append(ch, start, length); 265 302 } 266 303 }
Note: See TracChangeset
for help on using the changeset viewer.
