Ignore:
Timestamp:
06/30/13 12:48:20 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

  • loading f0 schema with XmlLoader?
  • use XmlLoader? to load configuration
  • introduce unified fork-join model of various entities

(Instances, Connections, GUI Frames, etc.),
all those entities clean up gracefully on
shutdown, which may be initialized by user
or by some entity

  • basing on above, simplify several organizing classes

(Observer, main class)

(to host native frams server process from Java level)

CHANGELOG:
Remove redundant Observer class.

Clean up in AbstractJoinable?.

Update ExternalProcess? class to changes in joining model.

Another sweep through code with FindBugs?.

Find bug with not joining RemoteInstance?.

Joining almost works.

Much improved joining model.

More improvement to joining model.

Add logging messages around joinable operations.

Rename methods in AbstractJoinable?.

Improve Joinable.

Rewrite of entity structure.

More simplifications with entities.

Further improve joinables.

Let Frame compose from JFrame instead of inheriting.

Add join classes.

Improvements of closing.

Add Builder interface.

Add FramsServerTest?.xml

FramsServer? may be configured through xml.

Make Framsticks main class an Observer of Entities.

Make Observer a generic type.

Remove variables regarding to removed endpoint.

Simplify observer (remove endpoints).

More changes to Observer and Endpoint.

Minor improvements.

Add OutputListener? to ExternalProcess?.

Improve testing of ExternalProcess?.

Add ExternalProcess? runner.

Rename the Program class to Framsticks.

Migrate Program to use XmlLoader? configuration.

First steps with configuration using XmlLoader?.

Fix several bugs.

Move all f0 classes to apriopriate package.

XmlLoader? is able to load Schema.

XmlLoader? is loading classes and props.

Add GroupBuilder?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/parsers/XmlLoader.java

    r87 r88  
    11package com.framsticks.parsers;
    22
     3import java.io.InputStream;
     4
     5import javax.xml.parsers.DocumentBuilder;
     6import javax.xml.parsers.DocumentBuilderFactory;
     7
     8import org.apache.log4j.Logger;
     9import org.w3c.dom.Document;
     10import org.w3c.dom.Element;
     11import org.w3c.dom.NamedNodeMap;
     12import org.w3c.dom.Node;
     13import org.w3c.dom.NodeList;
     14
     15import com.framsticks.params.AccessInterface;
     16import com.framsticks.params.Registry;
     17import com.framsticks.util.FramsticksException;
     18
    319public class XmlLoader {
     20        private static final Logger log = Logger.getLogger(XmlLoader.class);
    421
     22        protected Registry registry = new Registry();
     23
     24        /**
     25         *
     26         */
     27        public XmlLoader() {
     28        }
     29
     30        /**
     31         * @return the registry
     32         */
     33        public Registry getRegistry() {
     34                return registry;
     35        }
     36
     37        boolean useLowerCase = false;
     38
     39        /**
     40         * @param useLowerCase the useLowerCase to set
     41         */
     42        public void setUseLowerCase(boolean useLowerCase) {
     43                this.useLowerCase = useLowerCase;
     44        }
     45
     46        public Object processElement(Element element) {
     47                String name = element.getNodeName();
     48                if (useLowerCase) {
     49                        name = name.toLowerCase();
     50                }
     51                if (name.equals("import")) {
     52                        String className = element.getAttribute("class");
     53                        try {
     54                                registry.registerAndBuild(Class.forName(className));
     55                                return null;
     56                        } catch (ClassNotFoundException e) {
     57                                throw new FramsticksException().msg("failed to import class").arg("name", name).cause(e);
     58                        }
     59                }
     60
     61                AccessInterface access = registry.createAccess(name);
     62
     63                if (access == null) {
     64                        throw new FramsticksException().msg("failed to find access interface").arg("name", name);
     65                }
     66                Object object = access.createAccessee();
     67                assert object != null;
     68                access.select(object);
     69
     70                NamedNodeMap attributes = element.getAttributes();
     71                for (int i = 0; i < attributes.getLength(); ++i) {
     72                        Node attributeNode = attributes.item(i);
     73                        access.set(attributeNode.getNodeName().toLowerCase(), attributeNode.getNodeValue());
     74                }
     75
     76                NodeList children = element.getChildNodes();
     77                log.debug("found " + children.getLength() + " children in " + object);
     78                for (int i = 0; i < children.getLength(); ++i) {
     79                        Node childNode = children.item(i);
     80                        if (!(childNode instanceof Element)) {
     81                                continue;
     82                        }
     83                        Object childObject = processElement((Element) childNode);
     84                        if (childObject == null) {
     85                                continue;
     86                        }
     87
     88                        if (!access.tryAutoAppend(childObject)) {
     89                                throw new FramsticksException().msg("failed to auto append").arg("child", childObject).arg("parent", object);
     90                        }
     91                }
     92                log.debug("loaded " + object);
     93
     94                return object;
     95        }
     96
     97        public Object load(InputStream stream) {
     98                try {
     99                        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     100                        DocumentBuilder db = factory.newDocumentBuilder();
     101
     102                        Document document = db.parse(stream);
     103                        document.getDocumentElement().normalize();
     104                        Element element = document.getDocumentElement();
     105                        assert element != null;
     106
     107                        return processElement(element);
     108
     109                } catch (Exception e) {
     110                        throw new FramsticksException().msg("failed to load").cause(e);
     111                }
     112        }
     113
     114        public <T> T load(InputStream stream, Class<T> type) {
     115                registry.registerAndBuild(type);
     116
     117                Object object = load(stream);
     118                if (type.isAssignableFrom(object.getClass())) {
     119                        return type.cast(object);
     120                }
     121                throw new FramsticksException().msg("invalid type has been loaded");
     122        }
    5123}
     124
Note: See TracChangeset for help on using the changeset viewer.