Ignore:
Timestamp:
06/28/13 11:56:03 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

  • FramsClass? and contained Param are now immutable classes (like String),

which allows to refer to them concurrently without synchronization
(which for example in turn simplifies GUI management)

  • also make Path immutable (which was earlier only assumed)
  • add global cache for FramsClasses? created solely and automatically

on base of Java classes.

representations basing on given FramsClass?

  • above changes greatly improved GUI responsivness during browsing
  • furtherly improve Param class hierarchy
  • allow to inject actions on state changes into MultiParamLoader?
  • add more tests

CHANGELOG:

Add StatusListener? to MultiParamLoader?.

Minor refactorization in MultiParamLoader?.

First step with auto append.

Add SchemaTest?.

Improve Registry.

Clean up in Registry.

Work out Registry.

Use annotations for Param.

Fix ListChange?.

Improve fluent interface of the FramsClassBuilder?.

Done caching of ReflectionAccess?.Backend

Fix hashCode of Pair.

A step on a way to cache ReflectionAccess?.Backend

Make SimpleAbstractAccess?.framsClass a final field.

Add static cache for FramsClasses? based on java.

Only classes created strictly and automatically
based on java classes are using this cache.

Make all Params immutable.

Many improvement to make Param immutable.

Make PrimitiveParam? generic type.

Several changes to make Param immutable.

Make FramsClass? immutable.

Another improvement to Path immutability.

Several improvements to Path.

Improve PathTest?.

Configurarable MutabilityDetector?.

File:
1 edited

Legend:

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

    r85 r87  
    88
    99import com.framsticks.params.*;
     10import com.framsticks.params.annotations.AutoAppendAnnotation;
     11import com.framsticks.params.annotations.FramsClassAnnotation;
     12import com.framsticks.util.FramsticksException;
    1013import com.framsticks.util.lang.Numbers;
    1114import org.apache.log4j.Logger;
     
    3033 * (please replace name and surname with my personal data)
    3134 */
     35@FramsClassAnnotation
    3236public class Schema {
    3337
     
    4246                //return new FileInputStream(new File(Schema.class.getResource("/parsers/f0def.xml").getPath()));
    4347                return Schema.class.getResourceAsStream("/parsers/f0def.xml");
     48        }
     49
     50        public Schema() {
     51        }
     52
     53        @AutoAppendAnnotation
     54        public void addNeuroClass(NeuroClass neuroClass) {
    4455        }
    4556
     
    5263         *             the exception if one occurred while reading the stream
    5364         */
    54         public Schema(InputStream inputStream) throws Exception {
     65        public Schema(InputStream inputStream) {
    5566
    5667                DocumentBuilderFactory factory;
     
    105116
    106117                } catch (IOException | ParserConfigurationException | SAXException e) {
    107                         logger.fatal("unexpected exception occurred: ", e);
    108                         throw e;
    109                 }
    110 
     118                        throw new FramsticksException().msg("unexpected exception occurred").cause(e);
     119                }
    111120        }
    112121
     
    170179         *             the exception in case of any error
    171180         */
    172         private static FramsClass processClass(Node classNode) throws Exception {
     181        private static FramsClass processClass(Node classNode) {
    173182                String classId = null;
    174183                String className = "";
    175184                String classDescription = "";
    176185                try {
    177                         classId = classNode.getAttributes().getNamedItem("ID")
    178                                         .getNodeValue();
     186                        classId = classNode.getAttributes().getNamedItem("ID").getNodeValue();
    179187                } catch (NullPointerException e) {
    180                         throw new Exception("Class getId is not defined!");
     188                        throw new FramsticksException().msg("class id is not defined");
    181189                }
    182190
     
    184192                classDescription = getAttributeFromNode("DESCRIPTION", classNode);
    185193
    186                 FramsClass framsClass = new FramsClass(classId, className, classDescription);
     194                FramsClassBuilder builder = FramsClass.build().id(classId).name(className).description(classDescription);
    187195
    188196                NodeList classProperties = classNode.getChildNodes();
     
    195203                                String name = getAttribute(attributes, "NAME");
    196204                                if (name == null) {
    197                                         logger.warn("Group name in class \"" + classId + "\" ("
    198                                                         + className + ") is undefined");
     205                                        logger.warn("Group name in class \"" + classId + "\" (" + className + ") is undefined");
    199206                                } else {
    200                                         framsClass.appendGroup(new Group(name));
     207                                        builder.group(new Group(name));
    201208                                }
    202209                        } else if ("PROP".equals(node.getNodeName())
     
    204211
    205212                                NamedNodeMap attributes = node.getAttributes();
    206                                 Param param = processParameter(attributes, classId);
    207                                 framsClass.append(param);
     213                                processParameter(attributes, classId, builder);
    208214                        }
    209215
    210216                }
    211217
    212                 return framsClass;
     218                return builder.finish();
    213219        }
    214220
     
    231237         *             the exception in case of any error
    232238         */
    233         private static Param processParameter(NamedNodeMap attributes, String classId)
    234                         throws Exception {
     239        private static void processParameter(NamedNodeMap attributes, String classId, FramsClassBuilder classBuilder) {
    235240
    236241                String id = getAttribute(attributes, "ID");
    237                 if (id == null)
    238                         throw new Exception("Property ID in class \"" + classId
    239                                         + "\" is undefined");
     242                if (id == null) {
     243                        throw new FramsticksException().msg("Property ID in class \"" + classId + "\" is undefined");
     244                }
    240245                String type = getAttribute(attributes, "TYPE");
    241                 if (type == null)
    242                         throw new Exception("TYPE of property \"" + id + "\" is undefined");
     246                if (type == null) {
     247                        throw new FramsticksException().msg("TYPE of property \"" + id + "\" is undefined");
     248                }
    243249
    244250                String name = getAttribute(attributes, "NAME");
     
    261267                }
    262268
    263                 ParamBuilder builder = Param.build();
    264                 builder.id(id).name(name).help(description).group(group).flags(flags);
     269                ParamBuilder builder = classBuilder.param(id).name(name).help(description).group(group).flags(flags);
    265270
    266271                builder.type(type);
     
    282287                        builder.type(type);
    283288                }
    284                 return builder.finish();
     289
     290                classBuilder.param(builder);
    285291        }
    286292
Note: See TracChangeset for help on using the changeset viewer.