protected Pattern initialPattern() { return new Pattern(); }
@Override public boolean equals(Object o) { if ((o == null) || !(o instanceof Pattern)) { return false; } Pattern r = (Pattern) o; if (r.size() != size()) { return false; } int len = size(); for (int i = 0; i < len; i++) { if (!equalityCheck(get(i), r.get(i))) { return false; } } // if everything matches, then the two patterns are equal return true; }
private void endElement(String namespaceURI, String localName, String qName) { // given that an action list is always pushed for every startElement, we need // to always pop for every endElement List applicableActionList = (List) actionListStack.pop(); if (skip != null) { if (skip.equals(pattern)) { skip = null; } } else if (applicableActionList != EMPTY_LIST) { callEndAction(applicableActionList, getTagName(localName, qName)); } // given that we always push, we must also pop the pattern pattern.pop(); }
List tailMatch(Pattern currentPattern) { int max = 0; Pattern longestMatchingPattern = null; for (Pattern p : rules.keySet()) { if ((p.size() > 1) && p.get(0).equals(ANY)) { int r = currentPattern.getTailMatchLength(p); if (r > max) { max = r; longestMatchingPattern = p; } } } if (longestMatchingPattern != null) { return rules.get(longestMatchingPattern); } else { return null; } }
String last = p.peekLast(); String first = null; if(p.size() > 1) { first = p.get(0); List<String> partList = p.getCopyOfPartList(); if(partList.size() > 2) { partList.remove(0); Pattern clone = new Pattern(partList); if(currentPattern.isContained(clone)) { r = clone.size();
List prefixMatch(Pattern currentPattern) { int max = 0; Pattern longestMatchingPattern = null; for (Pattern p : rules.keySet()) { String last = p.peekLast(); if (ANY.equals(last)) { int r = currentPattern.getPrefixMatchLength(p); // to qualify the match length must equal p's size omitting the '*' if ((r == p.size() - 1) && (r > max)) { // System.out.println("New longest prefixMatch "+p); max = r; longestMatchingPattern = p; } } } if (longestMatchingPattern != null) { return rules.get(longestMatchingPattern); } else { return null; } }
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { String tagName = getTagName(localName, qName); globalPattern.push(tagName); Pattern current = (Pattern) globalPattern.clone(); saxEventList.add(new StartEvent(current, namespaceURI, localName, qName, atts, getLocator())); }
String nestedElementTagName = pattern.peekLast();
/** * Returns the number of "prefix" components that this pattern has in common * with the pattern p passed as parameter. By "prefix" components we mean the * components at the beginning of the pattern. */ public int getPrefixMatchLength(Pattern p) { if (p == null) { return 0; } int lSize = this.partList.size(); int rSize = p.partList.size(); // no match possible for empty sets if ((lSize == 0) || (rSize == 0)) { return 0; } int minLen = (lSize <= rSize) ? lSize : rSize; int match = 0; for (int i = 0; i < minLen; i++) { String l = (String) this.partList.get(i); String r = (String) p.partList.get(i); if (equalityCheck(l, r)) { match++; } else { break; } } return match; }
public void endElement(String namespaceURI, String localName, String qName) { saxEventList .add(new EndEvent(namespaceURI, localName, qName, getLocator())); globalPattern.pop(); }
private void startElement(String namespaceURI, String localName, String qName, Attributes atts) { String tagName = getTagName(localName, qName); pattern.push(tagName); if (skip != null) { // every startElement pushes an action list pushEmptyActionList(); return; } List applicableActionList = getApplicableActionList(pattern, atts); if (applicableActionList != null) { actionListStack.add(applicableActionList); callBeginAction(applicableActionList, tagName, atts); } else { // every startElement pushes an action list pushEmptyActionList(); String errMsg = "no applicable action for [" + tagName + "], current pattern is [" + pattern + "]"; cai.addError(errMsg); } }
void callBeginAction(List applicableActionList, String tagName, Attributes atts) { if (applicableActionList == null) { return; } Iterator i = applicableActionList.iterator(); while (i.hasNext()) { Action action = (Action) i.next(); // now let us invoke the action. We catch and report any eventual // exceptions try { action.begin(interpretationContext, tagName, atts); } catch (ActionException e) { skip = (Pattern) pattern.clone(); cai.addError("ActionException in Action for tag [" + tagName + "]", e); } catch (RuntimeException e) { skip = (Pattern) pattern.clone(); cai.addError("RuntimeException in Action for tag [" + tagName + "]", e); } } }
String last = p.peekLast(); String first = null; if(p.size() > 1) { first = p.get(0); List<String> partList = p.getCopyOfPartList(); if(partList.size() > 2) { partList.remove(0); Pattern clone = new Pattern(partList); if(currentPattern.isContained(clone)) { r = clone.size();
List tailMatch(Pattern currentPattern) { int max = 0; Pattern longestMatchingPattern = null; for (Pattern p : rules.keySet()) { if ((p.size() > 1) && p.get(0).equals(ANY)) { int r = currentPattern.getTailMatchLength(p); if (r > max) { max = r; longestMatchingPattern = p; } } } if (longestMatchingPattern != null) { return rules.get(longestMatchingPattern); } else { return null; } }
List prefixMatch(Pattern currentPattern) { int max = 0; Pattern longestMatchingPattern = null; for (Pattern p : rules.keySet()) { String last = p.peekLast(); if (ANY.equals(last)) { int r = currentPattern.getPrefixMatchLength(p); // to qualify the match length must equal p's size omitting the '*' if ((r == p.size() - 1) && (r > max)) { // System.out.println("New longest prefixMatch "+p); max = r; longestMatchingPattern = p; } } } if (longestMatchingPattern != null) { return rules.get(longestMatchingPattern); } else { return null; } }
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { String tagName = getTagName(localName, qName); globalPattern.push(tagName); Pattern current = (Pattern) globalPattern.clone(); saxEventList.add(new StartEvent(current, namespaceURI, localName, qName, atts, getLocator())); }
public boolean isApplicable(Pattern pattern, Attributes attributes, InterpretationContext ic) { String nestedElementTagName = pattern.peekLast(); // calling ic.peekObject with an empty stack will throw an exception if (ic.isEmpty()) { return false; } Object o = ic.peekObject(); PropertySetter parentBean = new PropertySetter(o); parentBean.setContext(context); AggregationType aggregationType = parentBean .computeAggregationType(nestedElementTagName); switch (aggregationType) { case NOT_FOUND: case AS_BASIC_PROPERTY: case AS_BASIC_PROPERTY_COLLECTION: return false; // we only push action data if NestComponentIA is applicable case AS_COMPLEX_PROPERTY_COLLECTION: case AS_COMPLEX_PROPERTY: IADataForComplexProperty ad = new IADataForComplexProperty(parentBean, aggregationType, nestedElementTagName); actionDataStack.push(ad); return true; default: addError("PropertySetter.computeAggregationType returned " + aggregationType); return false; } }
/** * Returns the number of "prefix" components that this pattern has in common * with the pattern p passed as parameter. By "prefix" components we mean the * components at the beginning of the pattern. */ public int getPrefixMatchLength(Pattern p) { if (p == null) { return 0; } int lSize = this.partList.size(); int rSize = p.partList.size(); // no match possible for empty sets if ((lSize == 0) || (rSize == 0)) { return 0; } int minLen = (lSize <= rSize) ? lSize : rSize; int match = 0; for (int i = 0; i < minLen; i++) { String l = (String) this.partList.get(i); String r = (String) p.partList.get(i); if (equalityCheck(l, r)) { match++; } else { break; } } return match; }