/** * Make a BaseComponentType component from an ical4j object. This may produce a VEvent, VTodo or * VJournal. * * @param val * @param pattern - if non-null limit returned components and values to those supplied in the * pattern. * @return JAXBElement<? extends BaseComponentType> * @throws Throwable */ public static JAXBElement toComponent( final Component val, final BaseComponentType pattern, final boolean wrapXprops) throws Throwable { if (val == null) { return null; } final PropertyList icprops = val.getProperties(); ComponentList icComps = null; if (icprops == null) { // Empty component return null; } final JAXBElement el; if (val instanceof VEvent) { el = of.createVevent(new VeventType()); icComps = ((VEvent) val).getAlarms(); } else if (val instanceof VToDo) { el = of.createVtodo(new VtodoType()); icComps = ((VToDo) val).getAlarms(); } else if (val instanceof VJournal) { el = of.createVjournal(new VjournalType()); } else if (val instanceof VFreeBusy) { el = of.createVfreebusy(new VfreebusyType()); } else if (val instanceof VAlarm) { el = of.createValarm(new ValarmType()); } else if (val instanceof VTimeZone) { el = of.createVtimezone(new VtimezoneType()); icComps = ((VTimeZone) val).getObservances(); } else if (val instanceof Daylight) { el = of.createDaylight(new DaylightType()); } else if (val instanceof Standard) { el = of.createStandard(new StandardType()); } else { throw new Exception("org.bedework.invalid.entity.type" + val.getClass().getName()); } final BaseComponentType comp = (BaseComponentType) el.getValue(); processProperties(val.getProperties(), comp, pattern, wrapXprops); if (Util.isEmpty(icComps)) { return el; } /* Process any sub-components */ final ArrayOfComponents aoc = new ArrayOfComponents(); comp.setComponents(aoc); for (final Object o : icComps) { @SuppressWarnings("unchecked") final JAXBElement<? extends BaseComponentType> subel = toComponent((Component) o, pattern, wrapXprops); aoc.getBaseComponent().add(subel); } return el; }