|
From: <rga...@us...> - 2002-10-21 22:07:35
|
Update of /cvsroot/csms/csms-core/src/java/org/fanfoot/scoring
In directory usw-pr-cvs1:/tmp/cvs-serv1399
Modified Files:
EventPattern.java
Log Message:
Refactoring
Index: EventPattern.java
===================================================================
RCS file: /cvsroot/csms/csms-core/src/java/org/fanfoot/scoring/EventPattern.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** EventPattern.java 21 Oct 2002 21:42:19 -0000 1.3
--- EventPattern.java 21 Oct 2002 22:07:31 -0000 1.4
***************
*** 79,87 ****
public EventPattern(Node node) {
super();
StringBuffer sb = new StringBuffer();
- String strGroupName;
String strRE;
- NamedNodeMap atts;
int idxGroup = 1;
Node curNode = node.getFirstChild();
--- 79,105 ----
public EventPattern(Node node) {
super();
+ NamedNodeMap atts;
+
+ regexPattern = Pattern.compile(createREPattern(node));
+ Node eventNode = node.getParentNode();
+ atts = eventNode.getAttributes();
+ String strType = atts.getNamedItem("type").getFirstChild().getNodeValue();
+ this.setType(strType);
+ }
+
+
+ /**
+ * Create a Regular Expression pattern from the supplied node.
+ * Returns the RE as a string and records the captuing groups and
+ * part names by calling setCapturingGroup for each one.
+ *
+ *@param node the node containing the XML representation of the
+ * pattern
+ *@return the string representation of the pattern
+ */
+ private String createREPattern(Node node) {
StringBuffer sb = new StringBuffer();
String strRE;
int idxGroup = 1;
Node curNode = node.getFirstChild();
***************
*** 89,93 ****
while(curNode != null) {
-
if(curNode.getNodeName().equals("part")) {
childNode = curNode.getFirstChild();
--- 107,110 ----
***************
*** 101,112 ****
sb.append(strRE);
sb.append(')');
! atts = curNode.getAttributes();
! strGroupName = atts.getNamedItem("name").getNodeValue();
! this.setCapturingGroup(idxGroup, strGroupName);
idxGroup = idxGroup + 1;
} else if(curNode.getNodeName().equals("unwantedPart")) {
strRE = curNode.getFirstChild().getNodeValue();
sb.append(strRE);
- logger.fine("Added non-capturing group with RE " + strRE);
}
--- 118,126 ----
sb.append(strRE);
sb.append(')');
! addCapturingGroup();
idxGroup = idxGroup + 1;
} else if(curNode.getNodeName().equals("unwantedPart")) {
strRE = curNode.getFirstChild().getNodeValue();
sb.append(strRE);
}
***************
*** 114,124 ****
}
! regexPattern = Pattern.compile(sb.toString());
- Node eventNode = node.getParentNode();
- atts = eventNode.getAttributes();
! String strType = atts.getNamedItem("type").getFirstChild().getNodeValue();
! this.setType(strType);
}
--- 128,149 ----
}
! return sb.toString();
! }
! /**
! * Add a capturing group at the given index, represented by the
! * given node.
! *
! *@param idx the index number for this group
! *@param node the node representing this group
! */
! private void addCapturingGroup(int idx, Node node) {
! NamedNodeMap atts;
! String strGroupName;
!
! atts = node.getAttributes();
! strGroupName = atts.getNamedItem("name").getNodeValue();
! this.setCapturingGroup(idx, strGroupName);
}
|