1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | package org.ananas.xi; import java.util.*; public class Ruleset extends QName { private List matches = new ArrayList(); private String error = null; public Ruleset(String namespaceURI, String localName, String qualifiedName) { super(namespaceURI,localName,qualifiedName); } public void setError(String error) { this.error = error; } public String getError() { return error; } public synchronized void addMatch(Match match) { matches.add(match); } public synchronized Match getMatchAt(int index) { return (Match)matches.get(index); } public synchronized int getMatchCount() { return matches.size(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | package org.ananas.xi; import java.util.*; import java.util.regex.*; public class Match extends QName { private Pattern pattern; private Matcher matcher = null; private String input = null; private List groups = new ArrayList(); public Match(String namespaceURI, String localName, String qualifiedName, String pattern) { super(namespaceURI,localName,qualifiedName); this.pattern = Pattern.compile(pattern); } public synchronized void addGroup(Group group) { groups.add(group); } public synchronized Group getGroupNameAt(int index) { if(index < 1 || index > groups.size()) throw new IndexOutOfBoundsException("index out of bounds"); return (Group)groups.get(index - 1); } public synchronized String getGroupValueAt(int index) throws IllegalStateException, IllegalArgumentException { if(matcher == null) throw new IllegalStateException("Call matches() first"); return getGroupNameAt(index).isText() ? matcher.group(0) : matcher.group(index); } public synchronized int getGroupCount() { return groups.size(); } public boolean matches(String st) { input = st; if(matcher == null) matcher = pattern.matcher(st); else matcher.reset(st); return matcher.lookingAt(); } public String rest() { if(matcher == null) throw new IllegalStateException("Call matches() first"); int end = matcher.end(), length = input.length(); if(end < length) return input.substring(end,length); else return null; } } |
1 2 3 4 5 6 7 8 9 10 11 | package org.ananas.xi; public class Group extends QName { public Group(String namespaceURI, String localName, String qualifiedName) { super(namespaceURI,localName,qualifiedName); } } |
1 2 3 4 5 6 7 8 9 10 11 | package org.ananas.xi; public class Group extends QName { public Group(String namespaceURI, String localName, String qualifiedName) { super(namespaceURI,localName,qualifiedName); } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |