Browse Source

保证获取不到已经禁用了的图表插件实例

master
juhaoyu 8 years ago
parent
commit
d9b634132b
  1. 19
      designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java
  2. 32
      designer_chart/src/com/fr/design/extra/ChartTypeInterfaceCloseableHandler.java

19
designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java

@ -25,6 +25,9 @@ import com.fr.general.*;
import com.fr.plugin.PluginCollector; import com.fr.plugin.PluginCollector;
import com.fr.plugin.PluginLicenseManager; import com.fr.plugin.PluginLicenseManager;
import com.fr.plugin.PluginMessage; import com.fr.plugin.PluginMessage;
import com.fr.design.extra.ChartTypeInterfaceCloseableHandler;
import com.fr.plugin.proxy.PluginInstanceProxyFactory;
import com.fr.plugin.proxy.PluginInvocationHandler;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.EnvChangedListener; import com.fr.stable.EnvChangedListener;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -33,6 +36,7 @@ import com.fr.stable.fun.Authorize;
import com.fr.stable.plugin.ExtraChartDesignClassManagerProvider; import com.fr.stable.plugin.ExtraChartDesignClassManagerProvider;
import com.fr.stable.plugin.PluginReadListener; import com.fr.stable.plugin.PluginReadListener;
import com.fr.stable.plugin.PluginSimplify; import com.fr.stable.plugin.PluginSimplify;
import com.fr.stable.plugin.closeable.Closeable;
import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
@ -213,24 +217,27 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
if (authorize != null) { if (authorize != null) {
PluginLicenseManager.getInstance().registerPaid(authorize, simplify); PluginLicenseManager.getInstance().registerPaid(authorize, simplify);
} }
IndependentChartUIProvider provider = (IndependentChartUIProvider) clazz.newInstance(); IndependentChartUIProvider provider = getProxyObj(plotID, simplify, clazz);
if (PluginCollector.getCollector().isError(provider, IndependentChartUIProvider.CURRENT_API_LEVEL, simplify.getPluginName()) || !containsChart(plotID)) { if (PluginCollector.getCollector().isError(provider, IndependentChartUIProvider.CURRENT_API_LEVEL, simplify.getPluginName())) {
PluginMessage.remindUpdate(className); PluginMessage.remindUpdate(className);
} else { } else {
ChartTypeInterfaceManager.getInstance().addChartTypeInterface(provider, priority, plotID); addChartTypeInterface(provider, priority, plotID);
} }
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
FRLogger.getLogger().error("class not found:" + e.getMessage()); FRLogger.getLogger().error("class not found:" + e.getMessage());
} catch (IllegalAccessException | InstantiationException e) { } catch (IllegalAccessException | InstantiationException e) {
FRLogger.getLogger().error("object create error:" + e.getMessage()); FRLogger.getLogger().error("object create error:" + e.getMessage());
} catch (NoSuchMethodException e) {
FRLogger.getLogger().error(e.getMessage());
} }
} }
} }
//UI对应的chart如果没有加载,UI也不必加进去了 private IndependentChartUIProvider getProxyObj(String plotID, PluginSimplify simplify, Class<?> clazz) throws IllegalAccessException, InstantiationException, NoSuchMethodException {
private boolean containsChart(String plotID) {
return ChartTypeManager.getInstance().containsPlot(plotID); PluginInstanceProxyFactory factory = new PluginInstanceProxyFactory(clazz, simplify);
PluginInvocationHandler handler = new ChartTypeInterfaceCloseableHandler(plotID);
return (IndependentChartUIProvider) factory.addProxy(Closeable.class, handler).getProxyObj();
} }

32
designer_chart/src/com/fr/design/extra/ChartTypeInterfaceCloseableHandler.java

@ -0,0 +1,32 @@
package com.fr.design.extra;
import com.fr.chart.charttypes.ChartTypeManager;
import com.fr.plugin.proxy.CloseableInvocationHandler;
/**
* Created by juhaoyu on 2016/12/27.
*/
public class ChartTypeInterfaceCloseableHandler extends CloseableInvocationHandler {
private final String plotID;
public ChartTypeInterfaceCloseableHandler(String plotID) throws NoSuchMethodException {
super();
this.plotID = plotID;
}
@Override
protected boolean invokeIsClosed() {
//找不到Plugin对象时,默认是关闭的
return super.invokeIsClosed() && containsChart();
}
//UI对应的chart如果没有关闭或者不存在,则UI关闭
private boolean containsChart() {
return ChartTypeManager.getInstance().containsPlot(plotID);
}
}
Loading…
Cancel
Save