DECLARE_EXPORT void Location::endElement(XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement) { if (pAttr.isA(Tags::tag_available)) { CalendarDouble *cal = dynamic_cast<CalendarDouble*>(pIn.getPreviousObject()); if (cal) setAvailable(cal); else { Calendar *c = dynamic_cast<Calendar*>(pIn.getPreviousObject()); if (!c) throw LogicException("Incorrect object type during read operation"); throw DataException("Calendar '" + c->getName() + "' has invalid type for use as location calendar"); } } else { HasDescription::endElement(pIn, pAttr, pElement); HasHierarchy<Location>::endElement(pIn, pAttr, pElement); } }
DECLARE_EXPORT Object* CalendarBucket::createBucket( const MetaClass* cat, const DataValueDict& atts ) { // Pick up the calendar and id fields const DataValue* cal_val = atts.get(Tags::calendar); Calendar *cal = cal_val ? static_cast<Calendar*>(cal_val->getObject()) : NULL; const DataValue* id_val = atts.get(Tags::id); int id = id_val ? id_val->getInt() : INT_MIN; // Check for existence of a bucket with the same identifier CalendarBucket* result = NULL; if (cal) result = cal->findBucket(id); // Pick up the action attribute and update the bucket accordingly switch (MetaClass::decodeAction(atts)) { case ADD: // Only additions are allowed if (result) { ostringstream o; o << "Bucket " << id << " already exists in calendar '" << cal << "'"; throw DataException(o.str()); } result = new CalendarBucket(); result->setId(id); if (cal) result->setCalendar(cal); return result; case CHANGE: // Only changes are allowed if (!result) { ostringstream o; o << "Bucket " << id << " doesn't exist in calendar '" << (cal ? cal->getName() : "NULL") << "'"; throw DataException(o.str()); } return result; case REMOVE: // Delete the entity if (!result) { ostringstream o; o << "Bucket " << id << " doesn't exist in calendar '" << (cal ? cal->getName() : "NULL") << "'"; throw DataException(o.str()); } else { // Delete it cal->removeBucket(result); return NULL; } case ADD_CHANGE: if (!result) { // Adding a new bucket result = new CalendarBucket(); result->setId(id); if (cal) result->setCalendar(cal); } return result; } // This part of the code isn't expected not be reached throw LogicException("Unreachable code reached"); }