protected static ComponentBuilder<?> createScriptBuilder( ComponentDescriptor component, BeneratorContext context) { TypeDescriptor type = component.getTypeDescriptor(); if (type == null) return null; String scriptText = type.getScript(); if (scriptText == null) return null; Script script = ScriptUtil.parseScriptText(scriptText); Generator<?> generator = new ScriptGenerator(script); generator = DescriptorUtil.createConvertingGenerator(component.getTypeDescriptor(), generator, context); return builderFromGenerator(generator, component, context); }
@Override protected Generator<Object[]> createSourceGenerator( ArrayTypeDescriptor descriptor, Uniqueness uniqueness, BeneratorContext context) { // if no sourceObject is specified, there's nothing to do String sourceName = descriptor.getSource(); if (sourceName == null) return null; // create sourceObject generator Generator<Object[]> generator = null; Object contextSourceObject = context.get(sourceName); if (contextSourceObject != null) generator = createSourceGeneratorFromObject(descriptor, context, generator, contextSourceObject); else { String lcSourceName = sourceName.toLowerCase(); if (lcSourceName.endsWith(".csv")) generator = createCSVSourceGenerator(descriptor, context, sourceName); else if (lcSourceName.endsWith(".xls")) generator = createXLSSourceGenerator(descriptor, context, sourceName); else { try { BeanSpec sourceBeanSpec = DatabeneScriptParser.resolveBeanSpec(sourceName, context); Object sourceObject = sourceBeanSpec.getBean(); if (!sourceBeanSpec.isReference() && sourceObject instanceof ContextAware) ((ContextAware) sourceObject).setContext(context); generator = createSourceGeneratorFromObject(descriptor, context, generator, sourceObject); if (sourceBeanSpec.isReference()) generator = WrapperFactory.preventClosing(generator); return generator; } catch (Exception e) { throw new UnsupportedOperationException("Unknown source type: " + sourceName); } } } if (descriptor.getFilter() != null) { Expression<Boolean> filter = new ScriptExpression<Boolean>(ScriptUtil.parseScriptText(descriptor.getFilter())); generator = new FilteringGenerator<Object[]>(generator, filter); } Distribution distribution = FactoryUtil.getDistribution(descriptor.getDistribution(), uniqueness, false, context); if (distribution != null) generator = new DistributingGenerator<Object[]>(generator, distribution, uniqueness.isUnique()); return generator; }