public static void toResource(Resource resource, ResourceFilter filter) throws RepositoryException { if (resource != null) { MappingStrategy strategy = getStrategy(filter.getClass()); strategy.toResource(resource, filter); } }
public static ResourceFilter fromResource(Resource resource) throws Exception { ResourceFilter filter = null; if (resource != null) { ResourceHandle handle = ResourceHandle.use(resource); String typeName = handle.getProperty(PROPERTY_TYPE); Class<? extends ResourceFilter> type = getType(typeName); MappingStrategy strategy = getStrategy(type); filter = strategy.fromResource(resource); } return filter; }
protected T processLine(MappingStrategy<T> mapper, String[] line) throws IllegalAccessException, InvocationTargetException, InstantiationException, IntrospectionException { T bean = mapper.createBean(); for (int col = 0; col < line.length; col++) { String value = line[col]; PropertyDescriptor prop = mapper.findDescriptor(col); if (null != prop) { Object obj = convertValue(value, prop); prop.getWriteMethod().invoke(bean, new Object[] {obj}); } } return bean; }
public AgiScript determineScript(AgiRequest request) { AgiScript script = null; if (strategies == null) { return null; } for (MappingStrategy strategy : strategies) { script = strategy.determineScript(request); if (script != null) { break; } } return script; }
public List<T> parse(MappingStrategy<T> mapper, CSVReader csv) { try { mapper.captureHeader(csv); String[] line; List<T> list = new ArrayList<T>(); while (null != (line = csv.readNext())) { T obj = processLine(mapper, line); list.add(obj); // TODO: (Kyle) null check object } return list; } catch (Exception e) { throw new RuntimeException("Error parsing CSV!", e); } }