Java Code Examples for net.sf.cglib.beans.BeanMap#put()

The following examples show how to use net.sf.cglib.beans.BeanMap#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ELCellPostParser.java    From bdf3 with Apache License 2.0 6 votes vote down vote up
@Override
public void parse(Context context) {
	MappingRule mappingRule = context.getCurrentMappingRule();
	Object value = context.getValue();
	String cellPostParserParam = mappingRule.getCellPostParserParam();
	JexlContext jexlContext = expressionHandler.getJexlContext();
	jexlContext.set("context", context);
	jexlContext.set("value", value);
	Expression expression = expressionHandler.compile(cellPostParserParam);
	if (expression == null) {
		value = cellPostParserParam;
	} else {
		value = expression.evaluate();
	}
	context.setValue(value);
	BeanMap beanMap = BeanMap.create(context.getCurrentEntity());
	if (value != Constants.IGNORE_ERROR_FORMAT_DATA) {
		beanMap.put(mappingRule.getPropertyName(), value);
	}
}
 
Example 2
Source File: AbstractCellPostParser.java    From bdf3 with Apache License 2.0 6 votes vote down vote up
@Override
public void parse(Context context) {
	if (context.getValue() != null) {
		MappingRule mappingRule =context.getCurrentMappingRule();
		BeanMap beanMap = BeanMap.create(context.getCurrentEntity());
		if (context.getValue() != Constants.IGNORE_ERROR_FORMAT_DATA) {
			Field field = ReflectionUtils.findField(context.getEntityClass(), mappingRule.getPropertyName());
			Column column = field.getAnnotation(Column.class);
			if (column.nullable()) {
				if (context.getValue() == null) {
					throw new DataNullableException(context.getCurrentCell().getRow(), context.getCurrentCell().getCol());
				}
			}
			
			if (field.getType() == String.class && !field.isAnnotationPresent(Lob.class)) {
				String value = (String) context.getValue();
				if (value.getBytes().length > column.length()) {
					throw new DataLengthException(context.getCurrentCell().getRow(), context.getCurrentCell().getCol(), value, column.length());
				}
			}
			beanMap.put(mappingRule.getPropertyName(), context.getValue());
		}
	}
}
 
Example 3
Source File: JdPricesFieldRender.java    From gecco with MIT License 6 votes vote down vote up
@Override
public void render(HttpRequest request, HttpResponse response, BeanMap beanMap, SpiderBean bean, Field field) {
	ProductList jd = (ProductList)bean;
	StringBuffer sb = new StringBuffer();
	/*for(String code : jd.getCodes()) {
		sb.append("J_").append(code).append(",");
	}*/
	String skuIds = sb.toString();
	try {
		skuIds = URLEncoder.encode(skuIds, "UTF-8");
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	String url = "http://p.3.cn/prices/mgets?skuIds="+skuIds;
	HttpRequest subRequest = request.subRequest(url);
	try {
		HttpResponse subReponse = DownloaderContext.download(subRequest);
		String json = subReponse.getContent();
		List<JDPrice> prices = JSON.parseArray(json, JDPrice.class);
		beanMap.put(field.getName(), prices);
	} catch(Exception ex) {
		ex.printStackTrace();
	}
}
 
Example 4
Source File: DefaultCellPostParser.java    From bdf3 with Apache License 2.0 5 votes vote down vote up
@Override
public void parse(Context context) {
	if (context.getValue() != null) {
		MappingRule mappingRule =context.getCurrentMappingRule();
		BeanMap beanMap = BeanMap.create(context.getCurrentEntity());
		if (context.getValue() != Constants.IGNORE_ERROR_FORMAT_DATA) {
			beanMap.put(mappingRule.getPropertyName(), context.getValue());
		}
	}
}
 
Example 5
Source File: ParseRecordPolicyImpl.java    From bdf3 with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Context context) throws ClassNotFoundException {
	List<Record> records = context.getRecords();
	
	for (int i = context.getStartRow(); i < records.size(); i++) {
		Record record = records.get(i);
		Object entity = BeanUtils.newInstance(context.getEntityClass());
		context.setCurrentEntity(entity);
		context.setCurrentRecord(record);
		String idProperty = JpaUtil.getIdName(context.getEntityClass());
		BeanMap beanMap = BeanMap.create(context.getCurrentEntity());
		if (beanMap.getPropertyType(idProperty) == String.class) {
			beanMap.put(idProperty, UUID.randomUUID().toString());
		}
		for (MappingRule mappingRule : context.getMappingRules()) {
			Cell cell = record.getCell(mappingRule.getExcelColumn());

			context.setCurrentMappingRule(mappingRule);
			context.setCurrentCell(cell);
			cellPreprocess(context);
			cellProcess(context);
			cellPostprocess(context);
			
		}
		JpaUtil.persist(entity);
		if (i % 100 == 0) {
			JpaUtil.persistAndFlush(entity);
			JpaUtil.getEntityManager(entity).clear();
		} else {
			JpaUtil.persist(entity);
		}
	}

}
 
Example 6
Source File: RequestFieldRender.java    From gecco with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked" })
public void render(HttpRequest request, HttpResponse response, BeanMap beanMap, SpiderBean bean) {
	Set<Field> requestFields = ReflectionUtils.getAllFields(bean.getClass(), ReflectionUtils.withAnnotation(Request.class));
	for(Field field : requestFields) {
		beanMap.put(field.getName(), request);
	}
}