[Swift-commit] r7873 - trunk/src/org/griphyn/vdl/mapping/file
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Sat May 17 21:09:43 CDT 2014
Author: hategan
Date: 2014-05-17 21:09:43 -0500 (Sat, 17 May 2014)
New Revision: 7873
Modified:
trunk/src/org/griphyn/vdl/mapping/file/StructuredRegularExpressionMapper.java
Log:
make structured regexp mapper work with string array as source (bug 1271)
Modified: trunk/src/org/griphyn/vdl/mapping/file/StructuredRegularExpressionMapper.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/file/StructuredRegularExpressionMapper.java 2014-05-18 02:08:47 UTC (rev 7872)
+++ trunk/src/org/griphyn/vdl/mapping/file/StructuredRegularExpressionMapper.java 2014-05-18 02:09:43 UTC (rev 7873)
@@ -35,6 +35,8 @@
import org.griphyn.vdl.mapping.MappingParamSet;
import org.griphyn.vdl.mapping.Path;
import org.griphyn.vdl.mapping.PhysicalFormat;
+import org.griphyn.vdl.type.Type;
+import org.griphyn.vdl.type.Types;
public class StructuredRegularExpressionMapper extends AbstractMapper {
@@ -74,9 +76,10 @@
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");
+ catch (HandleOpenException hoe) {
+ // should not be happening since the mapper is only initialized after
+ // all parameters have been closed
+ throw new RuntimeException("Handle open in mapper: " + sourceHandle);
}
Iterator<DSHandle> i = sourceFields.iterator();
while (i.hasNext()) {
@@ -109,15 +112,26 @@
+ " 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");
+ String sourceStr;
+ Type sourceType = hereHandle.getType();
+ if (sourceType.equals(Types.STRING)) {
+ sourceStr = (String) hereHandle.getValue();
+ }
+ else if (!sourceType.isComposite() && !sourceType.isPrimitive()) {
+ 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");
+ }
+ sourceStr = ((AbsFile) source).getPath();
+ }
+ else {
+ throw new RuntimeException("Source must be an array of mapped objects or strings. Found " + sourceType);
}
Pattern p = Pattern.compile(cp.getMatch());
- Matcher m = p.matcher(((AbsFile) source).getPath());
+ Matcher m = p.matcher(sourceStr);
if (!m.find()) {
- throw new RuntimeException("No match found! source='" + source + "' match = '" + cp.getMatch()
+ throw new RuntimeException("No match found! source='" + sourceStr + "' match = '" + cp.getMatch()
+ "'");
}
// find group number to replace
More information about the Swift-commit
mailing list