/** * @see org.openmrs.module.webservices.rest.web.resource.api.Converter#newInstance(java.lang.String) */ @Override public T newInstance(String type) { if (hasTypesDefined()) { if (type == null) throw new IllegalArgumentException(getClass().getSimpleName() + " requires a '" + RestConstants.PROPERTY_FOR_TYPE + "' property to create a new object"); DelegatingResourceHandler<? extends T> handler = getResourceHandler(type); return handler.newDelegate(); } else { return newDelegate(); } }
public T convert(SimpleObject propertiesToCreate) { DelegatingResourceHandler<? extends T> handler; if (hasTypesDefined()) { String type = (String) propertiesToCreate.remove(RestConstants.PROPERTY_FOR_TYPE); if (type == null) throw new IllegalArgumentException( "When creating a resource that supports subclasses, you must indicate the particular subclass with a " + RestConstants.PROPERTY_FOR_TYPE + " property"); handler = getResourceHandler(type); } else { handler = this; } T delegate = handler.newDelegate(propertiesToCreate); DelegatingResourceDescription description = handler.getCreatableProperties(); if (propertiesToCreate.containsKey("uuid")) { description.addProperty("uuid"); } setConvertedProperties(delegate, propertiesToCreate, description, true); return delegate; }