@PostConstruct
    public void init() {
      FS commandFileSystem =
          createFileSystem(
              this.properties.getCommandPathPatterns(), this.properties.getDisabledCommands());
      FS configurationFileSystem =
          createFileSystem(this.properties.getConfigPathPatterns(), new String[0]);

      PluginDiscovery discovery =
          new BeanFactoryFilteringPluginDiscovery(
              this.resourceLoader.getClassLoader(),
              this.beanFactory,
              this.properties.getDisabledPlugins());

      PluginContext context =
          new PluginContext(
              discovery,
              createPluginContextAttributes(),
              commandFileSystem,
              configurationFileSystem,
              this.resourceLoader.getClassLoader());

      context.refresh();
      start(context);
    }
  private ModifierGenerator(
      final PluginContext pluginContext,
      final DefinedTypeOutline classOutline,
      final String modifierClassName,
      final String modifierInterfaceName,
      final Collection<TypeOutline> interfaces,
      final String modifierMethodName,
      final boolean implement)
      throws JClassAlreadyExistsException {
    this.classOutline = classOutline;
    final JDefinedClass definedClass = classOutline.getImplClass();
    this.implement = implement;
    this.modifierClass =
        definedClass._class(
            JMod.PUBLIC, modifierClassName, classOutline.getImplClass().getClassType());
    if (interfaces != null) {
      for (final TypeOutline interfaceOutline : interfaces) {
        this.modifierClass._implements(
            pluginContext.ref(interfaceOutline.getImplClass(), modifierInterfaceName, true));
      }
    }
    final JFieldRef cachedModifierField;
    if (!"java.lang.Object".equals(definedClass._extends().fullName())) {
      this.modifierClass._extends(
          pluginContext.ref(definedClass._extends(), modifierClassName, false));
      cachedModifierField = JExpr.refthis(ModifierGenerator.MODIFIER_CACHE_FIELD_NAME);
    } else {
      if (implement) {
        cachedModifierField =
            JExpr._this()
                .ref(
                    definedClass.field(
                        JMod.PROTECTED | JMod.TRANSIENT,
                        this.modifierClass,
                        ModifierGenerator.MODIFIER_CACHE_FIELD_NAME));
      } else {
        cachedModifierField = null;
      }
    }

    final JDefinedClass typeDefinition =
        classOutline.isInterface()
                && ((DefinedInterfaceOutline) classOutline).getSupportInterface() != null
            ? ((DefinedInterfaceOutline) classOutline).getSupportInterface()
            : definedClass;
    final JMethod modifierMethod =
        typeDefinition.method(JMod.PUBLIC, this.modifierClass, modifierMethodName);
    if (this.implement) {
      final JConditional ifCacheNull =
          modifierMethod.body()._if(JExpr._null().eq(cachedModifierField));
      ifCacheNull._then().assign(cachedModifierField, JExpr._new(this.modifierClass));
      modifierMethod.body()._return(JExpr.cast(this.modifierClass, cachedModifierField));
    }
  }
Esempio n. 3
0
  public Object postProcessBeforeInitialization(Object bean, String beanName)
      throws BeansException {
    // System.out.println(" init " + beanName);
    if (bean instanceof AutoRegisterPlugin) {
      AutoRegisterPlugin plugin = (AutoRegisterPlugin) bean;
      if (plugin.getBundleList() == null) {
        // System.out.println( plugin.getName() + " bundlelist is null "
        // );
      } else {

        plugin.register();
        List<IPluginBundle> pluginBundelList = plugin.getBundleList();
        for (IPluginBundle bundle : pluginBundelList) {
          bundle.registerPlugin(plugin);
          // System.out.println(plugin.getName() + "注册在" +
          // bundle.getClass().getName()+"桩中" );
        }
        PluginContext.registerPlugin(plugin);
      }
    }

    return bean;
  }
Esempio n. 4
0
  /**
   * Sets the plugin context - return <code>false</code> if the connection is not an instance of
   * <code>SeekJinConnection</code>.
   */
  public boolean setContext(PluginContext context) {
    if (!(context.getConnection() instanceof SeekConnection)) return false;

    return super.setContext(context);
  }
  @Override
  public View getContentView(HttpServletRequest request, PluginContext pluginContext) {
    if (pluginContext.getLocalPath().equals("/edit")) {
      Bundle bundle = getBundleById(request.getParameter("id"));

      BundleConfiguration bundleConfiguration = null;
      try {
        bundleConfiguration = new BundleConfiguration(bundle, configAdmin, metaTypeService);
      } catch (Exception e) {
        message = "Error: " + e.getMessage();
        return new RedirectView(pluginContext.getApplicationPath());
      }

      return new ConfigurationView(bundle, bundleConfiguration, metaTypeService, loader);

    } else if (pluginContext.getLocalPath().equals("/changebundle")) {
      String id = request.getParameter("id");
      Bundle bundle = getBundleById(id);
      try {
        BundleConfiguration bundleConfiguration =
            new BundleConfiguration(bundle, configAdmin, metaTypeService);
        Dictionary<String, String> bundleProperties = new Hashtable<String, String>();

        String[] keys = request.getParameterValues("keyList");
        if (keys != null) {
          for (String key : keys) {
            String value = request.getParameter(key + "Property");
            if (value != null && !value.isEmpty()) {
              bundleProperties.put(key, request.getParameter(key + "Property"));
            }
          }
        }
        String newkey = request.getParameter("newkey");
        if (!newkey.equals("")) {
          bundleProperties.put(newkey, request.getParameter("newkeyProperty"));
        }
        bundleConfiguration.setBundleProperties(bundleProperties);

        return new RedirectView(pluginContext.getApplicationPath() + "/edit?id=" + id);
      } catch (Exception e) {
        message = "Error: " + e.getMessage();
        return new RedirectView(pluginContext.getApplicationPath());
      }
    } else if (pluginContext.getLocalPath().equals("/install")) {
      installBundle(request, pluginContext);
      return new RedirectView(pluginContext.getApplicationPath());
    } else if (pluginContext.getLocalPath().equals("/uninstall")) {
      Bundle bundle = getBundleById(request.getParameter("id"));
      if (bundle != null) {
        try {
          message = "Info: " + bundle.getSymbolicName() + " uninstalled";
          bundle.uninstall();
        } catch (BundleException e) {
          message = "Error: " + e.getMessage();
        }
      }
      return new RedirectView(pluginContext.getApplicationPath());
    } else if (pluginContext.getLocalPath().equals("/update")) {
      Bundle bundle = getBundleById(request.getParameter("id"));
      if (bundle != null) {
        try {
          message = "Info: " + bundle.getSymbolicName() + " updated";
          bundle.update();
        } catch (BundleException e) {
          message = "Error: " + e.getMessage();
        }
      }
      return new RedirectView(pluginContext.getApplicationPath());
    } else if (pluginContext.getLocalPath().equals("/stop")) {
      Bundle bundle = getBundleById(request.getParameter("id"));
      if (bundle != null) {
        try {
          message = "Info: " + bundle.getSymbolicName() + " stoped";
          bundle.stop();
        } catch (BundleException e) {
          message = "Error: " + e.getMessage();
        }
      }
      return new RedirectView(pluginContext.getApplicationPath());
    } else if (pluginContext.getLocalPath().equals("/start")) {
      Bundle bundle = getBundleById(request.getParameter("id"));
      if (bundle != null) {
        try {
          message = "Info: " + bundle.getSymbolicName() + " started";
          bundle.start();
        } catch (BundleException e) {
          message = "Error: " + e.getMessage();
        }
      }
      return new RedirectView(pluginContext.getApplicationPath());
    } else {
      String temp = message;
      message = null;
      return new BundleListView(context, loader, temp);
    }
  }