private ObjectType convertSettings(DatabaseSession session, Plugin plugin)
     throws BimserverDatabaseException {
   ObjectType settings = session.create(ObjectType.class);
   ObjectDefinition settingsDefinition = plugin.getSettingsDefinition();
   if (plugin.getSettingsDefinition() != null) {
     for (ParameterDefinition parameterDefinition : settingsDefinition.getParameters()) {
       Parameter parameter = session.create(Parameter.class);
       parameter.setName(parameterDefinition.getName());
       if (parameterDefinition.getDefaultValue() != null) {
         Type value = cloneAndAdd(session, parameterDefinition.getDefaultValue());
         parameter.setValue(value);
       }
       settings.getParameters().add(parameter);
     }
   }
   return settings;
 }
  private void genericPluginConversion(
      DatabaseSession session,
      Plugin plugin,
      PluginConfiguration pluginConfiguration,
      PluginDescriptor pluginDescriptor)
      throws BimserverDatabaseException {
    try {
      pluginConfiguration.setName(plugin.getDefaultName());
      pluginConfiguration.setPluginDescriptor(pluginDescriptor);

      // For the opposite of setPluginDescriptor
      // session.store(pluginDescriptor); Disabled for now, this creates massive lists, that are not
      // really useful...

      pluginConfiguration.setDescription(plugin.getDescription());
      pluginConfiguration.setEnabled(true);
      pluginConfiguration.setSettings(convertSettings(session, plugin));
    } catch (NoClassDefFoundError e) {
      // ignore for now
    }
  }
 private Class<?> getPluginInterfaceClass(Plugin plugin) {
   for (Class<?> pluginInterface : plugin.getClass().getInterfaces()) {
     if (pluginInterface != Plugin.class && Plugin.class.isAssignableFrom(pluginInterface)) {
       return pluginInterface;
     }
   }
   if (plugin.getClass().getSuperclass() != Object.class) {
     for (Class<?> pluginInterface : plugin.getClass().getSuperclass().getInterfaces()) {
       if (pluginInterface != Plugin.class && Plugin.class.isAssignableFrom(pluginInterface)) {
         return pluginInterface;
       }
     }
     if (plugin.getClass().getSuperclass().getSuperclass() != Object.class) {
       for (Class<?> pluginInterface :
           plugin.getClass().getSuperclass().getSuperclass().getInterfaces()) {
         if (pluginInterface != Plugin.class && Plugin.class.isAssignableFrom(pluginInterface)) {
           return pluginInterface;
         }
       }
     }
     return plugin.getClass().getSuperclass();
   }
   return plugin.getClass();
 }
 private void updatePlugins(DatabaseSession session) throws BimserverDatabaseException {
   Collection<Plugin> allPlugins = pluginManager.getAllPlugins(false);
   for (Plugin plugin : allPlugins) {
     Condition pluginCondition =
         new AttributeCondition(
             StorePackage.eINSTANCE.getPluginDescriptor_PluginClassName(),
             new StringLiteral(plugin.getClass().getName()));
     Map<Long, PluginDescriptor> results =
         session.query(pluginCondition, PluginDescriptor.class, Query.getDefault());
     if (results.size() == 0) {
       PluginContext pluginContext = pluginManager.getPluginContext(plugin);
       PluginDescriptor pluginDescriptor = session.create(PluginDescriptor.class);
       pluginDescriptor.setPluginClassName(plugin.getClass().getName());
       pluginDescriptor.setSimpleName(plugin.getClass().getSimpleName());
       pluginDescriptor.setDescription(plugin.getDescription() + " " + plugin.getVersion());
       pluginDescriptor.setLocation(pluginContext.getLocation().toString());
       pluginDescriptor.setPluginInterfaceClassName(getPluginInterfaceClass(plugin).getName());
       pluginDescriptor.setEnabled(true); // New plugins are enabled by default
     } else if (results.size() == 1) {
       PluginContext pluginContext = pluginManager.getPluginContext(plugin);
       PluginDescriptor pluginDescriptor = results.values().iterator().next();
       pluginDescriptor.setPluginClassName(plugin.getClass().getName());
       pluginDescriptor.setSimpleName(plugin.getClass().getSimpleName());
       pluginDescriptor.setDescription(plugin.getDescription() + " " + plugin.getVersion());
       pluginDescriptor.setLocation(pluginContext.getLocation().toString());
       pluginDescriptor.setPluginInterfaceClassName(getPluginInterfaceClass(plugin).getName());
       session.store(pluginDescriptor);
       pluginManager.getPluginContext(plugin).setEnabled(pluginDescriptor.getEnabled(), false);
     } else {
       LOGGER.error(
           "Multiple plugin descriptor objects found with the same name: "
               + plugin.getClass().getName());
     }
   }
 }