public <T> boolean canBeViewedAsWritable(ModelType<T> targetType) { if (targetType.getRawClass().equals(CollectionBuilder.class)) { ModelType<?> targetItemType = targetType.getTypeVariables().get(0); return targetItemType.getRawClass().isAssignableFrom(itemType) || itemType.isAssignableFrom(targetItemType.getRawClass()); } else { return false; } }
/** 释放事业部工序工分表 */ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = ServiceException.class) @Override public <ModelType> void audit(List<ModelType> auditModelList, SystemUser systemUser) { if (auditModelList != null && auditModelList.size() > 0) { try { Date date = new Date(); for (ModelType mod : auditModelList) { CommonUtil.setFieldValue(mod, "auditor", mod.getClass(), systemUser.getUserName()); CommonUtil.setFieldValue(mod, "auditTime", mod.getClass(), date); pdWrkactFaciDao.audit(mod); } } catch (Exception e) { // TODO: handle exception throw new ServiceException("释放事业部工序工分表出错了,原因:" + e.getMessage()); } } }
public <T> ModelView<? extends T> asWritable( ModelBinding<T> binding, ModelRuleDescriptor sourceDescriptor, Inputs inputs, ModelRuleRegistrar modelRuleRegistrar, C instance) { ModelType<T> targetType = binding.getReference().getType(); if (canBeViewedAsWritable(targetType)) { ModelType<?> targetItemType = targetType.getTypeVariables().get(0); if (targetItemType.getRawClass().isAssignableFrom(itemType)) { // item type is super of base return toView(binding, sourceDescriptor, inputs, modelRuleRegistrar, itemType); } else { // item type is sub type Class<? extends M> subType = targetItemType.getRawClass().asSubclass(itemType); return toView(binding, sourceDescriptor, inputs, modelRuleRegistrar, subType); } } else { return null; } }
private <T, S extends M> ModelView<? extends T> toView( ModelBinding<T> binding, ModelRuleDescriptor sourceDescriptor, Inputs inputs, ModelRuleRegistrar modelRuleRegistrar, Class<S> itemType) { CollectionBuilder<S> builder = new DefaultCollectionBuilder<S>( binding.getPath(), new Instantiator<S>(itemType, container), sourceDescriptor, inputs, modelRuleRegistrar); ModelType<CollectionBuilder<S>> viewType = new ModelType.Builder<CollectionBuilder<S>>() {}.where( new ModelType.Parameter<S>() {}, ModelType.of(itemType)) .build(); CollectionBuilderModelView<S> view = new CollectionBuilderModelView<S>(viewType, builder, binding.getPath(), sourceDescriptor); @SuppressWarnings("unchecked") ModelView<T> cast = (ModelView<T>) view; return cast; }
Instantiator(Class<I> defaultType, PolymorphicDomainObjectContainer<? super I> container) { this.defaultType = defaultType; this.itemType = ModelType.of(defaultType); this.container = container; }
/** * Returns a new ModelCodec. * * @param <ModelType> a model type * @param model a model instance to serialize * @return a new ModelCodec */ public static <ModelType> ModelCodec<ModelType> from(ModelType model) { ModelCodec<ModelType> result = new ModelCodec(); result.entity = model; result.entityClass = (Class<ModelType>) model.getClass(); return result; }
@Override ModelType asType() { return ModelType.valueOf(value); }