class GeneratorImpl implements Generator {
    
	private final DependencyManager mgr;
	private final TransformFactory factory;
	private final DefaultRenderStack renderStack;
    private final LinkedList<RenderTree.Builder> renderTreeBuilder;
	
    /**
	 * Creates a new generator.
     * 
	 * @param mgr      the dependency manager to use
	 * @param factory  the factory to use 
	 */
	public GeneratorImpl(DependencyManager mgr, TransformFactory factory) {
		this.factory           = requireNonNull(factory);
		this.mgr               = requireNonNull(mgr);
		this.renderStack       = new DefaultRenderStack();
        this.renderTreeBuilder = new LinkedList<>();
        
        // Add initial builder.
        this.renderTreeBuilder.add(RenderTree.builder());
	}

	@Override
	public DependencyManager getDependencyMgr() {
		return mgr;
	}

	@Override
	public RenderStack getRenderStack() {
		return renderStack;
	}

    @Override
    @SuppressWarnings("unchecked")
    public <A, B> Stream<Meta<A, B>> metaOn(A from, Class<B> to) {
        requireNonNulls(from, to);
        
        if (from instanceof Optional) {
            throw new UnsupportedOperationException(
                "Model must not be an Optional!"
            );
        }

        return BridgeTransform.create(factory, from.getClass(), to)
            .map(t -> (Transform<A, B>) t)
            .map(t -> transform(t, from, factory))
            .filter(Optional::isPresent)
            .map(Optional::get)
        ;
    }

    @Override
    public <A, B> Optional<Meta<A, B>> transform(Transform<A, B> transform, A model, TransformFactory factory) {<FILL_FUNCTION_BODY>}
}

        requireNonNulls(transform, model, factory);

        final RenderTree.Builder parent = renderTreeBuilder.peek();
        final RenderTree.Builder branch = RenderTree.builder();
        
        renderTreeBuilder.push(branch);
        renderStack.push(model);
        
        final Optional<Meta<A, B>> meta = transform
            .transform(this, model)
            .map(s -> Meta.builder(model, s)
                .withTransform(transform)
                .withFactory(factory)
                .withRenderTree(branch.build())
                .withRenderStack(new DefaultRenderStack(renderStack))
                .build()
        );
        
        meta.ifPresent(parent::withBranch);
        
        renderStack.pop();
        renderTreeBuilder.pop();
        
        return meta;
    
<no_super_class>