private Object convertCalendarToPartial(Class type, Calendar calendar) throws Exception { if (type.equals(Partial.class)) { Partial partial = new Partial(); if (isHour()) { partial = partial.with(DateTimeFieldType.hourOfDay(), calendar.get(Calendar.HOUR_OF_DAY)); } if (isMinute()) { partial = partial.with(DateTimeFieldType.minuteOfHour(), calendar.get(Calendar.MINUTE)); } return partial; } else { // ASSUMPTION // assume that we want a subtype of BasePartial and that the // subtype implements the factory // method fromCalendarField(Calendar calendar) Method method = type.getMethod("fromCalendarFields", new Class[] {Calendar.class}); return method.invoke(null, new Object[] {calendar}); } }