Java and other APIs can be encapsulated into models. This document describes the basic methods of encapsulating various APIs as models.
When we encapsulate an API as a model, the main consideration is how to better use these APIs through the model, so encapsulating an API is usually encapsulating its use interface as a model.
You can encapsulate models in Java projects.
Generally, xworker.lang.MetaDescriptor3 is used to define the model.
The implementation of the model's behavior generally uses JavaAction, which calls Java code.
Models can generally call Java's static methods with an ActionContext parameter and an unlimited return value.
public static void println(ActionContext actionContext) throws IOException { Thing self = actionContext.getObject("self"); PrintWriter writer = getPrintWriter(self, actionContext); String varName = self.doAction("getWriterWar", actionContext); if(varName != null && !"".equals(varName)) { actionContext.peek().put(varName, writer); } for(Thing child : self.getChilds()) { if(!"actions".equals(child.getThingName())) { Object result = child.getAction().run(actionContext); if(result == null && UtilData.isTrue(self.doAction("isIgnoreNull", actionContext))) { continue; } writer.println(result); } } if(UtilData.isTrue(self.doAction("isClose", actionContext))) { writer.close(); } }
The purpose of packaging APIs into models is to use them better, so we should consider how to package APIs into models from the perspective of how to use them better and more conveniently.
If an API is object-oriented, it can be defined as an object model, that is, the attributes and sub-nodes of the model are designed to create corresponding Java objects. For example, the interface model of SWT.
If an API is a method or function, it can be defined as an action model. For example, compress, copy files and so on.
Copyright © 2007-2019 XWorker.org 版权所有 沪ICP备08000575号