Browse Source

解耦合

pull/3/head
richie 5 years ago
parent
commit
ab162f1ad2
  1. 47
      src/main/java/com/fr/solution/plugin/design/formula/compat/FunctionConstants.java

47
src/main/java/com/fr/solution/plugin/design/formula/compat/FunctionConstants.java

@ -1,6 +1,7 @@
package com.fr.solution.plugin.design.formula.compat; package com.fr.solution.plugin.design.formula.compat;
import com.fanruan.api.function.FunctionKit; import com.fanruan.api.function.FunctionKit;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.macro.EncodeConstants; import com.fanruan.api.macro.EncodeConstants;
import com.fanruan.api.util.GeneralKit; import com.fanruan.api.util.GeneralKit;
import com.fanruan.api.util.OperatingKit; import com.fanruan.api.util.OperatingKit;
@ -17,7 +18,6 @@ import com.fr.function.MIN;
import com.fr.function.RANGE; import com.fr.function.RANGE;
import com.fr.function.SUM; import com.fr.function.SUM;
import com.fr.function.TIME; import com.fr.function.TIME;
import com.fr.general.FRLogger;
import com.fr.plugin.ExtraClassManager; import com.fr.plugin.ExtraClassManager;
import com.fr.stable.fun.FunctionDefContainer; import com.fr.stable.fun.FunctionDefContainer;
import com.fr.stable.fun.mark.Mutable; import com.fr.stable.fun.mark.Mutable;
@ -63,7 +63,8 @@ public final class FunctionConstants {
/** /**
* Don't let anyone instantiate this class. * Don't let anyone instantiate this class.
*/ */
private FunctionConstants() {} private FunctionConstants() {
}
private static void loadEmbededFunctions() { private static void loadEmbededFunctions() {
String pkgName = "com.fr.function"; String pkgName = "com.fr.function";
@ -73,7 +74,7 @@ public final class FunctionConstants {
try { try {
urlEnumeration = classloader.getResources(pkgName.replace('.', '/')); urlEnumeration = classloader.getResources(pkgName.replace('.', '/'));
} catch (IOException e) { } catch (IOException e) {
FRLogger.getLogger().error(e.getMessage()); LogKit.error(e.getMessage());
return; return;
} }
while (urlEnumeration.hasMoreElements()) { while (urlEnumeration.hasMoreElements()) {
@ -86,9 +87,9 @@ public final class FunctionConstants {
try { try {
classFilePath = URLDecoder.decode(classFilePath, EncodeConstants.ENCODING_UTF_8); classFilePath = URLDecoder.decode(classFilePath, EncodeConstants.ENCODING_UTF_8);
} catch (UnsupportedEncodingException e1) { } catch (UnsupportedEncodingException e1) {
FRLogger.getLogger().error(e1.getMessage(), e1); LogKit.error(e1.getMessage(), e1);
} }
FRLogger.getLogger().info("ClassFilePath:" + classFilePath); LogKit.info("ClassFilePath:" + classFilePath);
if (isCustomFormulaPath(classFilePath)) { if (isCustomFormulaPath(classFilePath)) {
continue; continue;
} }
@ -97,7 +98,7 @@ public final class FunctionConstants {
Class<?> cls = Class.forName(pkgName + "." + fileName.substring(0, fileName.length() - 6)); Class<?> cls = Class.forName(pkgName + "." + fileName.substring(0, fileName.length() - 6));
if (TypeKit.classInstanceOf(cls, iface)) { if (TypeKit.classInstanceOf(cls, iface)) {
Function inst; Function inst;
inst = (Function)cls.newInstance(); inst = (Function) cls.newInstance();
for (NameAndTypeAndFunctionList EMBFUNCTION : EMBFUNCTIONS) { for (NameAndTypeAndFunctionList EMBFUNCTION : EMBFUNCTIONS) {
if (EMBFUNCTION.test(inst)) { if (EMBFUNCTION.test(inst)) {
break; break;
@ -107,7 +108,7 @@ public final class FunctionConstants {
} catch (Exception ignore) { } catch (Exception ignore) {
} catch (Throwable e) { } catch (Throwable e) {
// 不要因为个别公式加载失败,而导致整个函数面板无法启动 // 不要因为个别公式加载失败,而导致整个函数面板无法启动
FRLogger.getLogger().error(e.getMessage()); LogKit.error(e.getMessage());
} }
} }
} }
@ -127,24 +128,26 @@ public final class FunctionConstants {
/** /**
* 将函数分组插件中的函数添加到对应的列表中 * 将函数分组插件中的函数添加到对应的列表中
*
* @param listModel * @param listModel
*/ */
public static void addFunctionGroupFromPlugins(DefaultListModel listModel){ public static void addFunctionGroupFromPlugins(DefaultListModel listModel) {
//hugh:自定义函数分组 //hugh:自定义函数分组
Set<Mutable> containers = ExtraClassManager.getInstance().getArray(FunctionDefContainer.MARK_STRING); Set<Mutable> containers = ExtraClassManager.getInstance().getArray(FunctionDefContainer.MARK_STRING);
if(!containers.isEmpty()){ if (!containers.isEmpty()) {
for(Mutable container : containers){ for (Mutable container : containers) {
listModel.addElement(createFunctionGroup((FunctionDefContainer)container)); listModel.addElement(createFunctionGroup((FunctionDefContainer) container));
} }
} }
} }
/** /**
* 创建一个新的分组 * 创建一个新的分组
*
* @param container * @param container
* @return * @return
*/ */
private static FunctionGroup createFunctionGroup(final FunctionDefContainer container){ private static FunctionGroup createFunctionGroup(final FunctionDefContainer container) {
return new FunctionGroup() { return new FunctionGroup() {
@Override @Override
public String getGroupName() { public String getGroupName() {
@ -156,7 +159,7 @@ public final class FunctionConstants {
FunctionDef[] fs = container.getFunctionDefs(); FunctionDef[] fs = container.getFunctionDefs();
int count = fs.length; int count = fs.length;
FunctionDefNAD[] nads = new FunctionDefNAD[count]; FunctionDefNAD[] nads = new FunctionDefNAD[count];
for (int i = 0; i < count; i ++) { for (int i = 0; i < count; i++) {
nads[i] = new FunctionDefNAD(fs[i]); nads[i] = new FunctionDefNAD(fs[i]);
} }
return nads; return nads;
@ -172,10 +175,10 @@ public final class FunctionConstants {
String[] arr = filePath.split("!/"); String[] arr = filePath.split("!/");
String jarPath = arr[0].substring(6); String jarPath = arr[0].substring(6);
String classPath = arr[1]; String classPath = arr[1];
if(classPath.endsWith("/")){ if (classPath.endsWith("/")) {
classPath = classPath.substring(0, classPath.length() - 1); classPath = classPath.substring(0, classPath.length() - 1);
} }
if (!OperatingKit.isWindows()){ if (!OperatingKit.isWindows()) {
//windows里substring后是d:\123\456, mac下substring后是Application/123/456 //windows里substring后是d:\123\456, mac下substring后是Application/123/456
jarPath = StringKit.perfectStart(jarPath, "/"); jarPath = StringKit.perfectStart(jarPath, "/");
} }
@ -198,7 +201,7 @@ public final class FunctionConstants {
classNameList.add(entryName.substring(classPath.length() + 1)); classNameList.add(entryName.substring(classPath.length() + 1));
} }
} catch (IOException e) { } catch (IOException e) {
FRLogger.getLogger().error(e.getMessage(), e); LogKit.error(e.getMessage(), e);
} }
} else { } else {
File dir = new File(filePath); File dir = new File(filePath);
@ -228,7 +231,7 @@ public final class FunctionConstants {
FunctionDef[] fs = ExtraClassManager.getInstance().getFunctionDef(); FunctionDef[] fs = ExtraClassManager.getInstance().getFunctionDef();
int count = fs.length; int count = fs.length;
FunctionDefNAD[] nads = new FunctionDefNAD[count]; FunctionDefNAD[] nads = new FunctionDefNAD[count];
for (int i = 0; i < count; i ++) { for (int i = 0; i < count; i++) {
nads[i] = new FunctionDefNAD(fs[i]); nads[i] = new FunctionDefNAD(fs[i]);
} }
return nads; return nads;
@ -251,13 +254,13 @@ public final class FunctionConstants {
} }
private static NameAndFunctionList getCommonFunctionList() { private static NameAndFunctionList getCommonFunctionList() {
return new NameAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Most_Recently_Used"), new Function[] { return new NameAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Most_Recently_Used"), new Function[]{
new SUM(), new COUNT(), new AVERAGE(), new CHAR(), new DATE(), new MAX(), new MIN(), new TIME(), new RANGE() new SUM(), new COUNT(), new AVERAGE(), new CHAR(), new DATE(), new MAX(), new MIN(), new TIME(), new RANGE()
}); });
} }
private static NameAndTypeAndFunctionList[] getEmbededFunctionListArray() { private static NameAndTypeAndFunctionList[] getEmbededFunctionListArray() {
return new NameAndTypeAndFunctionList[] { return new NameAndTypeAndFunctionList[]{
new NameAndTypeAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Math_&_Trig"), Function.MATH), new NameAndTypeAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Math_&_Trig"), Function.MATH),
new NameAndTypeAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Text"), Function.TEXT), new NameAndTypeAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Text"), Function.TEXT),
new NameAndTypeAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Date_&_Time"), Function.DATETIME), new NameAndTypeAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Date_&_Time"), Function.DATETIME),
@ -286,9 +289,9 @@ public final class FunctionConstants {
Collections.addAll(all, CUSTOM.getDescriptions()); Collections.addAll(all, CUSTOM.getDescriptions());
//hugh:自定义函数分组 //hugh:自定义函数分组
Set<Mutable> containers = ExtraClassManager.getInstance().getArray(FunctionDefContainer.MARK_STRING); Set<Mutable> containers = ExtraClassManager.getInstance().getArray(FunctionDefContainer.MARK_STRING);
if(!containers.isEmpty()){ if (!containers.isEmpty()) {
for(Mutable container : containers){ for (Mutable container : containers) {
Collections.addAll(all,createFunctionGroup(((FunctionDefContainer)container)).getDescriptions()); Collections.addAll(all, createFunctionGroup(((FunctionDefContainer) container)).getDescriptions());
} }
} }

Loading…
Cancel
Save