/** * Creates a model wrapper object out of the given model object. Throws IllegalArgumentException in case the given * model object is no model. */ public static ModelWrapper wrap(Object model) { if (!(isModel(model.getClass()))) { throw new IllegalArgumentException("The given object is no model"); } return new ModelWrapper((OpenEngSBModel) model); }
/** * Creates a model of the given type and uses the list of OpenEngSBModelEntries as initialization data. */ public static <T> T createModel(Class<T> model, List<OpenEngSBModelEntry> entries) { if (!ModelWrapper.isModel(model)) { throw new IllegalArgumentException("The given class is no model"); } try { T instance = model.newInstance(); for (OpenEngSBModelEntry entry : entries) { if (tryToSetValueThroughField(entry, instance)) { continue; } if (tryToSetValueThroughSetter(entry, instance)) { continue; } ((OpenEngSBModel) instance).addOpenEngSBModelEntry(entry); } return instance; } catch (InstantiationException e) { LOGGER.error("InstantiationException while creating a new model instance.", e); } catch (IllegalAccessException e) { LOGGER.error("IllegalAccessException while creating a new model instance.", e); } catch (SecurityException e) { LOGGER.error("SecurityException while creating a new model instance.", e); } return null; }