/** * 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); }
/** * Calculates the complete model oid from the model. */ public String getCompleteModelOID() { return appendContextId(model.retrieveInternalModelId()); }
/** * Creates the model description object for the underlying model object. */ public ModelDescription getModelDescription() { String modelName = retrieveModelName(); String modelVersion = retrieveModelVersion(); if (modelName == null || modelVersion == null) { throw new IllegalArgumentException("Unsufficient information to create model description."); } return new ModelDescription(modelName, modelVersion); }
/** * 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; }
String oid = ModelWrapper.wrap(model).getCompleteModelOID(); EDBObject object = new EDBObject(oid); try {
/** * Creates a version object from the model version string in the wrapper model. */ public Version retrieveModelVersionObject() { return new Version(retrieveModelVersion()); }