diff --git a/src/main/java/org/ical4j/template/TemplateFactory.java b/src/main/java/org/ical4j/template/TemplateFactory.java new file mode 100644 index 0000000..28608b6 --- /dev/null +++ b/src/main/java/org/ical4j/template/TemplateFactory.java @@ -0,0 +1,38 @@ +package org.ical4j.template; + +import net.fortuna.ical4j.extensions.concept.ActionType; +import net.fortuna.ical4j.extensions.concept.EventType; +import net.fortuna.ical4j.model.component.VEvent; +import net.fortuna.ical4j.model.component.VToDo; +import net.fortuna.ical4j.model.property.Concept; +import org.ical4j.template.groupware.Action; +import org.ical4j.template.groupware.Meeting; + +import java.util.function.UnaryOperator; + +public class TemplateFactory { + + @SuppressWarnings("unchecked") + public UnaryOperator newInstance(Concept concept) { + if (EventType.MEETING.equals(concept)) { + return (UnaryOperator) new Meeting(); + } else if (ActionType.ACTION.equals(concept)) { + return (UnaryOperator) new Action(); +// } else if (ActionType.AGENDA.equals(concept)) { +// return (UnaryOperator) new Agenda(); + } + throw new IllegalArgumentException("Unknown concept"); + } + + @SuppressWarnings("unchecked") + public UnaryOperator newInstance(Concept concept, T prototype) { + if (EventType.MEETING.equals(concept)) { + return (UnaryOperator) new Meeting((VEvent) prototype); + } else if (ActionType.ACTION.equals(concept)) { + return (UnaryOperator) new Action((VToDo) prototype); +// } else if (ActionType.AGENDA.equals(concept)) { +// return (UnaryOperator) new Agenda(); + } + throw new IllegalArgumentException("Unknown concept"); + } +}