001package org.nasdanika.html.model.html.gen; 002 003import org.nasdanika.common.Consumer; 004import org.nasdanika.common.ConsumerFactory; 005import org.nasdanika.common.Context; 006import org.nasdanika.common.FunctionFactory; 007import org.nasdanika.common.ProgressMonitor; 008 009public class HtmlElementConsumerFactoryAdapter<M extends org.nasdanika.html.model.html.HtmlElement, T extends org.nasdanika.html.HTMLElement<?>> extends HtmlElementAdapter<M,T> implements ConsumerFactory<T> { 010 011 protected HtmlElementConsumerFactoryAdapter(M htmlElement) { 012 super(htmlElement); 013 } 014 015 @Override 016 public boolean isAdapterForType(Object type) { 017 return type == ConsumerFactory.class; 018 } 019 020 protected Consumer<T> createConsumer(Context context) { 021 return new Consumer<T>() { 022 023 @Override 024 public double size() { 025 return 1; 026 } 027 028 @Override 029 public String name() { 030 return "HTML Element Consumer"; 031 } 032 033 @Override 034 public void execute(T htmlElement, ProgressMonitor progressMonitor) throws Exception { 035 HtmlElementConsumerFactoryAdapter.this.build(htmlElement, context, progressMonitor); 036 } 037 }; 038 }; 039 040 /** 041 * Builds HTML element. This implementation does nothing. 042 * @param htmlElement 043 * @param progressMonitor 044 * @throws Exception 045 */ 046 protected void build(T htmlElement, Context context, ProgressMonitor progressMonitor) throws Exception {} 047 048 @Override 049 public Consumer<T> create(Context context) throws Exception { 050 FunctionFactory<T,T> configureFunctionFactory = this::createConfigureFunction; 051 ConsumerFactory<T> consumerFactory = this::createConsumer; 052 return configureFunctionFactory.then(consumerFactory).create(context); 053 } 054 055}