[Swift-commit] r7589 - branches/release-0.95/src/org/griphyn/vdl/mapping/file
davidk at ci.uchicago.edu
davidk at ci.uchicago.edu
Fri Feb 14 14:30:08 CST 2014
Author: davidk
Date: 2014-02-14 14:30:07 -0600 (Fri, 14 Feb 2014)
New Revision: 7589
Modified:
branches/release-0.95/src/org/griphyn/vdl/mapping/file/StructuredRegularExpressionMapper.java
Log:
Bug 1171 fix from trunk
Modified: branches/release-0.95/src/org/griphyn/vdl/mapping/file/StructuredRegularExpressionMapper.java
===================================================================
--- branches/release-0.95/src/org/griphyn/vdl/mapping/file/StructuredRegularExpressionMapper.java 2014-02-11 22:16:06 UTC (rev 7588)
+++ branches/release-0.95/src/org/griphyn/vdl/mapping/file/StructuredRegularExpressionMapper.java 2014-02-14 20:30:07 UTC (rev 7589)
@@ -15,8 +15,8 @@
*/
-package org.griphyn.vdl.mapping.file;
-
+package org.griphyn.vdl.mapping.file;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -27,27 +27,28 @@
import org.apache.log4j.Logger;
import org.griphyn.vdl.mapping.AbsFile;
+import org.griphyn.vdl.mapping.AbstractMapper;
import org.griphyn.vdl.mapping.DSHandle;
import org.griphyn.vdl.mapping.HandleOpenException;
import org.griphyn.vdl.mapping.InvalidPathException;
import org.griphyn.vdl.mapping.MappingParamSet;
import org.griphyn.vdl.mapping.Path;
import org.griphyn.vdl.mapping.PhysicalFormat;
-
-public class StructuredRegularExpressionMapper extends AbstractFileMapper {
-
- public static final Logger logger =
- Logger.getLogger(StructuredRegularExpressionMapper.class);
+
+public class StructuredRegularExpressionMapper extends AbstractMapper {
+
+ public static final Logger logger =
+ Logger.getLogger(StructuredRegularExpressionMapper.class);
@Override
protected void getValidMappingParams(Set<String> s) {
s.addAll(StructuredRegularExpressionMapperParams.NAMES);
super.getValidMappingParams(s);
}
-
- public StructuredRegularExpressionMapper() {
- }
+ public StructuredRegularExpressionMapper() {
+ }
+
@Override
public String getName() {
return "StructuredRegexpMapper";
@@ -58,80 +59,80 @@
return new StructuredRegularExpressionMapperParams();
}
- @Override
+ @Override
public Collection<Path> existing() {
- StructuredRegularExpressionMapperParams cp = getParams();
-
- DSHandle sourceHandle = cp.getSource();
-
- Collection<Path> output = new ArrayList<Path>();
- Collection<DSHandle> sourceFields;
- try {
- sourceFields = sourceHandle.getFields(Path.CHILDREN);
- }
- catch (InvalidPathException ipe) {
- return Collections.emptyList();
- }
- catch (HandleOpenException hoe) {
- throw new RuntimeException(
- "Handle open. Throwing this exception may not be the right thing to do. TODO");
- }
- Iterator<DSHandle> i = sourceFields.iterator();
- while (i.hasNext()) {
- DSHandle f = i.next();
- output.add(f.getPathFromRoot());
- }
-
- return output;
- }
+ StructuredRegularExpressionMapperParams cp = getParams();
- @Override
+ DSHandle sourceHandle = cp.getSource();
+
+ Collection<Path> output = new ArrayList<Path>();
+ Collection<DSHandle> sourceFields;
+ try {
+ sourceFields = sourceHandle.getFields(Path.CHILDREN);
+ }
+ catch (InvalidPathException ipe) {
+ return Collections.emptyList();
+ }
+ catch (HandleOpenException hoe) {
+ throw new RuntimeException(
+ "Handle open. Throwing this exception may not be the right thing to do. TODO");
+ }
+ Iterator<DSHandle> i = sourceFields.iterator();
+ while (i.hasNext()) {
+ DSHandle f = i.next();
+ output.add(f.getPathFromRoot());
+ }
+
+ return output;
+ }
+
+ @Override
public PhysicalFormat map(Path path) {
- if (logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("map(): path: " + path);
}
- StructuredRegularExpressionMapperParams cp = getParams();
-
- DSHandle sourceHandle = cp.getSource();
- DSHandle hereHandle;
- try {
- hereHandle = sourceHandle.getField(path);
- }
- catch (InvalidPathException ipe) {
- throw new RuntimeException("Cannot get requested path " + path
- + " from source data structure");
+ StructuredRegularExpressionMapperParams cp = getParams();
+
+ DSHandle sourceHandle = cp.getSource();
+ DSHandle hereHandle;
+ try {
+ hereHandle = sourceHandle.getField(path);
}
+ catch (InvalidPathException ipe) {
+ throw new RuntimeException("Cannot get requested path " + path
+ + " from source data structure");
+ }
- PhysicalFormat source = hereHandle.getMapper().map(hereHandle.getPathFromRoot());
- if (!source.getType().equals("file")) {
- throw new RuntimeException(
- "Cannot use the regular expression mapper with a source that has a mapper that is not file-based");
- }
- Pattern p = Pattern.compile(cp.getMatch());
- Matcher m = p.matcher(((AbsFile) source).getPath());
- if (!m.find()) {
- throw new RuntimeException("No match found! source='" + source + "' match = '" + cp.getMatch()
- + "'");
- }
- // find group number to replace
- Pattern p2 = Pattern.compile("(\\\\\\d)");
- Matcher m2 = p2.matcher(cp.getTransform());
- StringBuffer sb = new StringBuffer();
- while (m2.find()) {
- String group = m2.group(1);
- int g = Integer.parseInt(group.substring(1));
- m2.appendReplacement(sb, m.group(g));
- }
- m2.appendTail(sb);
- return new AbsFile(sb.toString());
- }
-
- public Path rmap(String name) {
- return Path.EMPTY_PATH;
- }
-
- public boolean isStatic() {
- return true;
- }
-
-}
+ PhysicalFormat source = hereHandle.getMapper().map(hereHandle.getPathFromRoot());
+ if (!source.getType().equals("file")) {
+ throw new RuntimeException(
+ "Cannot use the regular expression mapper with a source that has a mapper that is not file-based");
+ }
+ Pattern p = Pattern.compile(cp.getMatch());
+ Matcher m = p.matcher(((AbsFile) source).getPath());
+ if (!m.find()) {
+ throw new RuntimeException("No match found! source='" + source + "' match = '" + cp.getMatch()
+ + "'");
+ }
+ // find group number to replace
+ Pattern p2 = Pattern.compile("(\\\\\\d)");
+ Matcher m2 = p2.matcher(cp.getTransform());
+ StringBuffer sb = new StringBuffer();
+ while (m2.find()) {
+ String group = m2.group(1);
+ int g = Integer.parseInt(group.substring(1));
+ m2.appendReplacement(sb, m.group(g));
+ }
+ m2.appendTail(sb);
+ return new AbsFile(sb.toString());
+ }
+
+ public Path rmap(String name) {
+ return Path.EMPTY_PATH;
+ }
+
+ public boolean isStatic() {
+ return true;
+ }
+
+}
More information about the Swift-commit
mailing list