| 25 | import pcgen.util.Logging; |
| 26 | |
| 27 | public class CDOMSubLineLoader<T extends Loadable> |
| 28 | { |
| 29 | |
| 30 | private final Class<T> targetClass; |
| 31 | private final String targetPrefix; |
| 32 | private final String targetPrefixColon; |
| 33 | |
| 34 | // private final int prefixLength; |
| 35 | |
| 36 | public CDOMSubLineLoader(String prefix, Class<T> cl) |
| 37 | { |
| 38 | targetPrefix = prefix; |
| 39 | targetClass = cl; |
| 40 | targetPrefixColon = prefix + ":"; |
| 41 | // prefixLength = targetPrefixColon.length(); |
| 42 | } |
| 43 | |
| 44 | public boolean parseLine(LoadContext context, T obj, String val) |
| 45 | { |
| 46 | if (val == null) |
| 47 | { |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | boolean returnValue = true; |
| 52 | StringTokenizer st = new StringTokenizer(val, "\t"); |
| 53 | while (st.hasMoreTokens()) |
| 54 | { |
| 55 | String token = st.nextToken().trim(); |
| 56 | int colonLoc = token.indexOf(':'); |
| 57 | if (colonLoc == -1) |
| 58 | { |
| 59 | Logging.errorPrint("Invalid Token - does not contain a colon: " + token); |
| 60 | returnValue = false; |
| 61 | continue; |
| 62 | } |
| 63 | else if (colonLoc == 0) |
| 64 | { |
| 65 | Logging.errorPrint("Invalid Token - starts with a colon: " + token); |
| 66 | returnValue = false; |
| 67 | continue; |
| 68 | } |
| 69 | String key = token.substring(0, colonLoc); |
| 70 | String value = (colonLoc == token.length() - 1) ? null : token.substring(colonLoc + 1); |
| 71 | if (value == null) |
| 72 | { |
| 73 | Logging.errorPrint("Invalid token - key or value missing: " + token + " in line " + val, context); |
| 74 | returnValue = false; |
| 75 | continue; |
| 76 | } |
| 77 | boolean passed = context.processToken(obj, key.intern(), value.intern()); |
| 78 | if (passed) |
| 79 | { |
| 80 | context.commit(); |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | context.rollback(); |
nothing calls this directly
no outgoing calls
no test coverage detected