使用yWorks和Java Reflection API反序列化JavaFX属性

时间:2018-03-22 10:49:25

标签: javafx reflection yfiles

我正在实施流程管理工具,我正在使用(用于研究目的)yWorks库“yFiles for JavaFX”。

到目前为止,我做得很好,但有一件事只是为我设置了一个让我停留2天的时间:

由于我使用JavaFX bean及其属性来编辑和显示我的数据,我不得不实现某种自定义序列化器:

graphMLIOHandler.addHandleSerializationListener(
            (source, hsArgs) -> {
                // Only serialize items that are of the specific type.
                if (hsArgs.getItem() instanceof StringProperty) {
                    //serialize
                } else if (hsArgs.getItem() instanceof IntegerProperty) {
                    //serialize
                } else if (hsArgs.getItem() instanceof DoubleProperty) {
                    //serialize
                } else if (hsArgs.getItem() instanceof SimpleListProperty) {
                    //serialize
                }
            });

但是在加载我写的文件时,我得到了IllegalArgumentException。 yFiles想要调用setValue方法并抛出DeserializationNotSupportedException。所以我尝试实现addHandleDeserializationListener。没工作。然后我为MarkupExtensions课程实施了Project。没有改变。给你们后者实现的代码,并希望有人找到我错过的东西。我有点在我的最后一个地方..

CustomGraphController:

public class CustomGraphController extends GraphControl{

   private IGraph graph ;
   private GraphMLIOHandler graphMLIOHandler;

    public CustomGraphController(){
        super();
        graph = this.getGraph();
        graph.setTag(new Project());
    }
}

Project.class:

@GraphML(markupExtensionConverter = ProjectMEC.class)
public class Project {
    SimpleListProperty<ParameterOccurrence> generalParameters;

    public Project(){
        generalParameters = new SimpleListProperty<>(FXCollections.observableArrayList());
    }

    public ObservableList<ParameterOccurrence> getGeneralParameters() {
        return generalParameters;
    }

    public SimpleListProperty<ParameterOccurrence> generalParametersProperty() {
        return generalParameters;
    }

    public void setGeneralParameters(ObservableList<ParameterOccurrence> generalParameters) {
        this.generalParameters.set(generalParameters);
    }
}

ProjectME.class

public class ProjectME extends MarkupExtension {

    ArrayList<ParameterOccurrence> generalParameters;

    public ProjectME() {
        super();
    }

    public ArrayList<ParameterOccurrence> getGeneralParameters() {
        return generalParameters;
    }

    public void setGeneralParameters(ArrayList<ParameterOccurrence> generalParameters) {
        this.generalParameters = generalParameters;
    }


    @Override
    public Object provideValue(ILookup iLookup) {
        Project ret = new Project();
        ret.getGeneralParameters().addAll(generalParameters);
        return ret;
    }
}

ProjectMEC.class:

public class ProjectMEC implements IMarkupExtensionConverter {

    @Override
    public boolean canConvert(IWriteContext iWriteContext, Object o) {
        return o instanceof Project;
    }

    @Override
    public MarkupExtension convert(IWriteContext iWriteContext, Object o) {
        ProjectME extension = new ProjectME();
        ObservableList<ParameterOccurrence> temp = FXCollections.observableArrayList(((Project)o).getGeneralParameters());
        extension.getGeneralParameters().addAll(temp);
        return extension;
    }
}

堆栈跟踪:

Caused by: com.yworks.yfiles.graphml.DeserializationNotSupportedException: Error parsing property GeneralParameters: argument type mismatch
    at com.yworks.yfiles.graphml.XamlReader.b(Unknown Source)
    at com.yworks.yfiles.graphml.XamlReader.c(Unknown Source)
    ... 83 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.yworks.yfiles.graphml.PropertyInfo.setValue(Unknown Source)
    at com.yworks.yfiles.graphml.Property.setValue(Unknown Source)
    ... 85 more
  

我的猜测是GeneralParameters属性(即使我   试图实现addHandleDeserializationListener   SimpleListProperty)以某种方式需要这个MarkupExtension。但是   stacktrace保持完全相同,因为反射API和   我无法找到的封闭源代码,Exception的确切位置   抛出...

有什么想法,有什么事吗?

0 个答案:

没有答案