nodal-cvs Mailing List for NODAL (Page 10)
Status: Pre-Alpha
Brought to you by:
leei
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(69) |
Jun
(153) |
Jul
(129) |
Aug
(70) |
Sep
(94) |
Oct
(105) |
Nov
(31) |
Dec
(34) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(7) |
Feb
(40) |
Mar
(68) |
Apr
(27) |
May
(107) |
Jun
(202) |
Jul
(74) |
Aug
(5) |
Sep
(25) |
Oct
(40) |
Nov
(43) |
Dec
(73) |
2004 |
Jan
(63) |
Feb
(40) |
Mar
(104) |
Apr
(34) |
May
(33) |
Jun
(18) |
Jul
(12) |
Aug
(2) |
Sep
(24) |
Oct
(52) |
Nov
(44) |
Dec
(4) |
2005 |
Jan
(42) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2008 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(5) |
Jun
|
Jul
|
Aug
(6) |
Sep
(3) |
Oct
|
Nov
|
Dec
(1) |
2014 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
(1) |
May
|
Jun
(1) |
Jul
|
Aug
(1) |
Sep
(6) |
Oct
(5) |
Nov
(8) |
Dec
(3) |
2015 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
(2) |
Dec
|
2017 |
Jan
|
Feb
|
Mar
(1) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Lee I. <le...@us...> - 2004-05-05 03:24:46
|
Update of /cvsroot/nodal/nodal/j-src/test/storage/jar In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31300/test/storage/jar Modified Files: TestJarRepository.java Log Message: Make Struct a kind of RecordContent Inherit nodeType() from Node Inherit type() from Content. Index: TestJarRepository.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/test/storage/jar/TestJarRepository.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TestJarRepository.java 30 Mar 2004 00:56:06 -0000 1.2 --- TestJarRepository.java 5 May 2004 03:24:37 -0000 1.3 *************** *** 61,65 **** Node root = manifest.root(); assertTrue(root != null); ! NodeType rootType = root.type(); assertTrue(rootType != null); System.out.println(manifest); --- 61,65 ---- Node root = manifest.root(); assertTrue(root != null); ! NodeType rootType = root.nodeType(); assertTrue(rootType != null); System.out.println(manifest); |
From: Lee I. <le...@us...> - 2004-05-05 03:24:46
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/format/text/xml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31300/org/nodal/format/text/xml Modified Files: Format.java Log Message: Make Struct a kind of RecordContent Inherit nodeType() from Node Inherit type() from Content. Index: Format.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/format/text/xml/Format.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Format.java 19 Apr 2004 23:59:19 -0000 1.16 --- Format.java 5 May 2004 03:24:36 -0000 1.17 *************** *** 188,192 **** private void encodeNode(PrintWriter out, Node node, int indent, NSChain nsChain) { ! NodeType nodeType = node.type(); if (XMLFactory.chardataType.acceptsType(nodeType)) { RecordNode text = node.asRecordNode(); --- 188,192 ---- private void encodeNode(PrintWriter out, Node node, int indent, NSChain nsChain) { ! NodeType nodeType = node.nodeType(); if (XMLFactory.chardataType.acceptsType(nodeType)) { RecordNode text = node.asRecordNode(); *************** *** 552,556 **** List ch = elem.getContent(); if (!ch.isEmpty()) { ! NodeType t = (NodeType) elementNode.type().valueType("children"); SequenceNode.Editor childrenList = factory.createNodeList(t); elementNode.setField("children").setNode(childrenList); --- 552,556 ---- List ch = elem.getContent(); if (!ch.isEmpty()) { ! NodeType t = (NodeType) elementNode.nodeType().valueType("children"); SequenceNode.Editor childrenList = factory.createNodeList(t); elementNode.setField("children").setNode(childrenList); |
From: Lee I. <le...@us...> - 2004-05-05 03:24:46
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/format/application/octet_stream In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31300/org/nodal/format/application/octet_stream Modified Files: Format.java Log Message: Make Struct a kind of RecordContent Inherit nodeType() from Node Inherit type() from Content. Index: Format.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/format/application/octet_stream/Format.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Format.java 19 Mar 2004 00:24:43 -0000 1.2 --- Format.java 5 May 2004 03:24:37 -0000 1.3 *************** *** 74,78 **** public OutputStream encode(OutputStream stream, Node root) throws IOException { ! if (!Types.OCTET_SEQUENCE.accepts(root.type())) { return null; } --- 74,78 ---- public OutputStream encode(OutputStream stream, Node root) throws IOException { ! if (!Types.OCTET_SEQUENCE.accepts(root.nodeType())) { return null; } |
From: Lee I. <le...@us...> - 2004-05-05 03:24:46
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/nav In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31300/org/nodal/nav Modified Files: Paths.java NodeGetter.java Log Message: Make Struct a kind of RecordContent Inherit nodeType() from Node Inherit type() from Content. Index: Paths.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/nav/Paths.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** Paths.java 30 Mar 2004 00:56:06 -0000 1.37 --- Paths.java 5 May 2004 03:24:36 -0000 1.38 *************** *** 127,131 **** private NodeGetter(Node node) { ! super(node.type()); this.node = node; } --- 127,131 ---- private NodeGetter(Node node) { ! super(node.nodeType()); this.node = node; } Index: NodeGetter.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/nav/NodeGetter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NodeGetter.java 25 Mar 2004 21:52:34 -0000 1.3 --- NodeGetter.java 5 May 2004 03:24:36 -0000 1.4 *************** *** 22,26 **** NodeGetter(Path path, Node node) { ! super(node.type()); this.node = node; this.path = path; --- 22,26 ---- NodeGetter(Path path, Node node) { ! super(node.nodeType()); this.node = node; this.path = path; |
From: Lee I. <le...@us...> - 2004-05-05 03:24:44
|
Update of /cvsroot/nodal/nodal/j-src/extras In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31300/extras Modified Files: baseTypes.nls xml.nls Log Message: Make Struct a kind of RecordContent Inherit nodeType() from Node Inherit type() from Content. Index: baseTypes.nls =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/extras/baseTypes.nls,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** baseTypes.nls 28 Apr 2004 14:04:12 -0000 1.19 --- baseTypes.nls 5 May 2004 03:24:36 -0000 1.20 *************** *** 226,233 **** </struct> ! <struct name="RegularExpressionStruct" extends="RestrictionStruct"> <field name="re" type="Name"/> </struct> <!-- The type descriptor that allows any variation of a Node type to be --- 226,259 ---- </struct> ! <struct name="NonNull" extends="RestrictionStruct"/> ! ! <struct name="RegularExpression" extends="RestrictionStruct"> <field name="re" type="Name"/> </struct> + <struct name="Fixed" extends="RestrictionStruct"> + <field name="value" type="Type"/> + </struct> + + <struct name="Enumeration" extends="RestrictionStruct"> + <field name="value" type="String"/> + </struct> + + <struct name="MinInclusive" extends="RestrictionStruct"> + <field name="value" type="Type"/> + </struct> + + <struct name="MaxInclusive" extends="RestrictionStruct"> + <field name="value" type="Type"/> + </struct> + + <struct name="MinExclusive" extends="RestrictionStruct"> + <field name="value" type="Type"/> + </struct> + + <struct name="MaxExclusive" extends="RestrictionStruct"> + <field name="value" type="Type"/> + </struct> + <!-- The type descriptor that allows any variation of a Node type to be Index: xml.nls =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/extras/xml.nls,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** xml.nls 19 Apr 2004 23:59:17 -0000 1.13 --- xml.nls 5 May 2004 03:24:36 -0000 1.14 *************** *** 7,10 **** --- 7,14 ---- <schema xmlns:ndl="baseTypes.nls"> + <record name="XMLDocument" extends="ndl:Document"> + <field name="root" type="Document"/> + </record> + <sequence name="NodeList" itemType="Node"/> |
From: Lee I. <le...@us...> - 2004-05-05 03:24:44
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31300/org/nodal/implementation/types Modified Files: TypeDoc.java NodeTypeImpl.java StructTypeImpl.java Log Message: Make Struct a kind of RecordContent Inherit nodeType() from Node Inherit type() from Content. Index: TypeDoc.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/TypeDoc.java,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** TypeDoc.java 28 Apr 2004 16:24:30 -0000 1.63 --- TypeDoc.java 5 May 2004 03:24:35 -0000 1.64 *************** *** 324,328 **** // First attach the Document node... attachNode(docNode.bareNode()); ! System.out.println("Associate " + this +" with " + docNode); // And then all of its children. --- 324,328 ---- // First attach the Document node... attachNode(docNode.bareNode()); ! //System.out.println("Associate " + this +" with " + docNode); // And then all of its children. *************** *** 375,379 **** // " " + (name == null ? "<unnamed>" : name.string()) + ": "); ! NodeType typeOf = record.type(); // Using the typeOf value, select a class of Type to create --- 375,379 ---- // " " + (name == null ? "<unnamed>" : name.string()) + ": "); ! NodeType typeOf = record.nodeType(); // Using the typeOf value, select a class of Type to create Index: NodeTypeImpl.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/NodeTypeImpl.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** NodeTypeImpl.java 19 Apr 2004 23:59:19 -0000 1.16 --- NodeTypeImpl.java 5 May 2004 03:24:36 -0000 1.17 *************** *** 59,63 **** public boolean acceptsNode (Node n) { /* FIXME: We need to test both the type and value! */ ! return acceptsType (n.type ()); } --- 59,63 ---- public boolean acceptsNode (Node n) { /* FIXME: We need to test both the type and value! */ ! return acceptsType (n.nodeType ()); } Index: StructTypeImpl.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/StructTypeImpl.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** StructTypeImpl.java 28 Apr 2004 16:24:33 -0000 1.4 --- StructTypeImpl.java 5 May 2004 03:24:36 -0000 1.5 *************** *** 15,20 **** --- 15,22 ---- import java.util.Vector; import org.nodal.model.Getter; + import org.nodal.model.InvalidOperator; import org.nodal.model.MapNode; import org.nodal.model.Node; + import org.nodal.model.Operator; import org.nodal.model.RecordNode; import org.nodal.model.Struct; *************** *** 350,353 **** --- 352,359 ---- } + public boolean hasField (Name name) { + return fieldType(name) != null; + } + public int size() { if (extension() != null) { *************** *** 441,445 **** return structVals; } ! public StructType type() { return type; } --- 447,451 ---- return structVals; } ! public StructType structType() { return type; } *************** *** 473,476 **** --- 479,525 ---- return getField(Names.getName(name)); } + public boolean hasField(Name fieldName) { + return type.hasField(fieldName); + } + public boolean hasField(String fieldName) { + return hasField(Names.getName(fieldName)); + } + public Type type() { + return type; + } + public int size() { + return type.size(); + } + public Iterator properties() { + return type.fields(); + } + public boolean isValidProperty(Object property) { + if (property instanceof Name) { + return type.hasField ((Name) property); + } else if (property instanceof String) { + return type.hasField (Names.getName((String)property)); + } + return false; + } + public Getter value(Object obj) { + if (obj instanceof Name) { + return field((Name) obj); + } else if (obj instanceof String) { + return field((String)obj); + } + return null; + } + + public Object getValue(Object obj) { + if (obj instanceof Name) { + return getField((Name) obj); + } else if (obj instanceof String) { + return getField((String)obj); + } + return null; + } + public Operator invert(Operator op) throws InvalidOperator, ConstraintFailure { + return null; + } } |
From: Lee I. <le...@us...> - 2004-05-05 03:24:44
|
Update of /cvsroot/nodal/nodal/j-src/storage/framework In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31300/storage/framework Modified Files: DirFromNode.java StreamBasedNode.java AbstractNode.java ProxyNode.java DocFromNode.java Log Message: Make Struct a kind of RecordContent Inherit nodeType() from Node Inherit type() from Content. Index: DocFromNode.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/storage/framework/DocFromNode.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** DocFromNode.java 19 Mar 2004 00:24:42 -0000 1.14 --- DocFromNode.java 5 May 2004 03:24:35 -0000 1.15 *************** *** 103,107 **** public static DocFromNode createDoc(Path path, NodeContent node) { DocFromNode doc = null; ! Type type = node.type(); if (!DOC_T.acceptsType(type)) { throw new RuntimeException("Incompatible Document node."); --- 103,107 ---- public static DocFromNode createDoc(Path path, NodeContent node) { DocFromNode doc = null; ! Type type = node.nodeType(); if (!DOC_T.acceptsType(type)) { throw new RuntimeException("Incompatible Document node."); *************** *** 130,134 **** NodeContent node, DocumentFormat format) { ! if (DIR_T.acceptsType(node.type())) { return DirFromNode.createDir(path, node); } else { --- 130,134 ---- NodeContent node, DocumentFormat format) { ! if (DIR_T.acceptsType(node.nodeType())) { return DirFromNode.createDir(path, node); } else { Index: StreamBasedNode.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/storage/framework/StreamBasedNode.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** StreamBasedNode.java 26 Feb 2004 08:54:02 -0000 1.8 --- StreamBasedNode.java 5 May 2004 03:24:35 -0000 1.9 *************** *** 177,184 **** * @see org.nodal.model.Node#type() */ ! public NodeType type() { // Don't read just to get type. if (node != null) { ! return node.type(); } else { return format().rootType(); --- 177,184 ---- * @see org.nodal.model.Node#type() */ ! public NodeType nodeType() { // Don't read just to get type. if (node != null) { ! return node.nodeType(); } else { return format().rootType(); Index: ProxyNode.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/storage/framework/ProxyNode.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ProxyNode.java 20 Apr 2004 18:01:25 -0000 1.12 --- ProxyNode.java 5 May 2004 03:24:35 -0000 1.13 *************** *** 32,35 **** --- 32,36 ---- import org.nodal.security.Capability; import org.nodal.type.NodeType; + import org.nodal.type.Type; import org.nodal.util.ConstraintFailure; import org.nodal.util.IndexBoundsException; *************** *** 70,75 **** } ! public NodeType type() { ! return target().type(); } --- 71,76 ---- } ! public NodeType nodeType() { ! return target().nodeType(); } *************** *** 175,178 **** --- 176,183 ---- } + public Type type () { + return proxy.nodeType(); + } + public boolean isValidProperty(Object property) { return nodeContent.isValidProperty(property); Index: DirFromNode.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/storage/framework/DirFromNode.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** DirFromNode.java 19 Mar 2004 00:24:42 -0000 1.12 --- DirFromNode.java 5 May 2004 03:24:35 -0000 1.13 *************** *** 56,60 **** if (mapNode == null) { ! RecordType dirType = node.type().asRecordType(); RecordNode.Editor editDoc = content.editRecord(); mapNode = editDoc.createNode((NodeType) dirType.fieldType(ROOT_N)); --- 56,60 ---- if (mapNode == null) { ! RecordType dirType = node.nodeType().asRecordType(); RecordNode.Editor editDoc = content.editRecord(); mapNode = editDoc.createNode((NodeType) dirType.fieldType(ROOT_N)); Index: AbstractNode.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/storage/framework/AbstractNode.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** AbstractNode.java 19 Apr 2004 23:59:20 -0000 1.8 --- AbstractNode.java 5 May 2004 03:24:35 -0000 1.9 *************** *** 46,50 **** } ! public final NodeType type() { return type; } --- 46,50 ---- } ! public final NodeType nodeType() { return type; } |
From: Lee I. <le...@us...> - 2004-05-05 03:24:43
|
Update of /cvsroot/nodal/nodal/j-src/storage/trans In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31300/storage/trans Modified Files: BareNode.java Log Message: Make Struct a kind of RecordContent Inherit nodeType() from Node Inherit type() from Content. Index: BareNode.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/storage/trans/BareNode.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** BareNode.java 19 Apr 2004 23:59:19 -0000 1.28 --- BareNode.java 5 May 2004 03:24:35 -0000 1.29 *************** *** 88,92 **** return nid; } ! public NodeType type() { return type; } --- 88,92 ---- return nid; } ! public NodeType nodeType() { return type; } |
From: Lee I. <le...@us...> - 2004-05-05 03:24:43
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/format/text/x_nodal_schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31300/org/nodal/format/text/x_nodal_schema Modified Files: Writer.java Log Message: Make Struct a kind of RecordContent Inherit nodeType() from Node Inherit type() from Content. Index: Writer.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/format/text/x_nodal_schema/Writer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Writer.java 19 Apr 2004 23:59:19 -0000 1.3 --- Writer.java 5 May 2004 03:24:35 -0000 1.4 *************** *** 61,64 **** --- 61,66 ---- private static final RecordType recordRType = (RecordType) Types.BASESCHEMA.typeNamed("RecordType"); + private static final RecordType structRType = + (RecordType) Types.BASESCHEMA.typeNamed("StructType"); private static final MapType recordFieldsType = (MapType) recordRType.fieldType("fields"); *************** *** 158,162 **** declareSequenceType(type); } else if (recordRType.accepts(type)) { ! declareRecordType(type); } else if (unionRType.accepts(type)) { declareUnionType(type); --- 160,166 ---- declareSequenceType(type); } else if (recordRType.accepts(type)) { ! declareRecordType(type, "record"); ! } else if (structRType.accepts(type)) { ! declareRecordType(type, "struct"); } else if (unionRType.accepts(type)) { declareUnionType(type); *************** *** 261,267 **** * @param type the Record Node representing this declaration */ ! private void declareRecordType(RecordNode type) throws PropertyConstraintFailure { ! beginDeclaration(type, "record"); Node extend = type.field("extends").getNode(); if (extend != null) { --- 265,271 ---- * @param type the Record Node representing this declaration */ ! private void declareRecordType(RecordNode type, String typeName) throws PropertyConstraintFailure { ! beginDeclaration(type, typeName); Node extend = type.field("extends").getNode(); if (extend != null) { *************** *** 290,294 **** } indent -= 2; ! println("</record>"); } } --- 294,298 ---- } indent -= 2; ! println("</"+typeName+">"); } } |
From: Lee I. <le...@us...> - 2004-04-28 16:24:46
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18573/org/nodal/implementation/types Modified Files: RecordTypeImpl.java TypeDoc.java StructTypeImpl.java Log Message: Remove TypeDoc logging. Index: RecordTypeImpl.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/RecordTypeImpl.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** RecordTypeImpl.java 23 Apr 2004 21:39:49 -0000 1.21 --- RecordTypeImpl.java 28 Apr 2004 16:24:27 -0000 1.22 *************** *** 288,296 **** RecordImpl newImpl = new NodeImpl(record); // compareImpls (this.impl, newImpl); ! System.out.print("From <= "); ! System.out.println(toString(true)); this.impl = newImpl; ! System.out.print("To => "); ! System.out.println(toString(true)); } --- 288,296 ---- RecordImpl newImpl = new NodeImpl(record); // compareImpls (this.impl, newImpl); ! //System.out.print("From <= "); ! //System.out.println(toString(true)); this.impl = newImpl; ! //System.out.print("To => "); ! //System.out.println(toString(true)); } Index: TypeDoc.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/TypeDoc.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** TypeDoc.java 28 Apr 2004 14:04:12 -0000 1.62 --- TypeDoc.java 28 Apr 2004 16:24:30 -0000 1.63 *************** *** 264,268 **** if (!bootstrapped) { try { ! System.out.println(DOCTYPE); Document base = Nodal.openDocument(BASEURI); BASESCHEMA.associateBase(base.docNode()); --- 264,268 ---- if (!bootstrapped) { try { ! //System.out.println(DOCTYPE); Document base = Nodal.openDocument(BASEURI); BASESCHEMA.associateBase(base.docNode()); *************** *** 301,305 **** this.uri = uri; ns = Names.getNamespace(uri); ! System.out.println("Create " + this +" given Node " + docNode); types = new Vector(); names = new HashMap(); --- 301,305 ---- this.uri = uri; ns = Names.getNamespace(uri); ! //System.out.println("Create " + this +" given Node " + docNode); types = new Vector(); names = new HashMap(); *************** *** 365,370 **** type = (TypeImpl) typeNamed(name); if (type != null) { ! System.out.println( ! " Associate " + name.string() + ": " + record + " with " + type); type.associateRecord(record); return type; --- 365,370 ---- type = (TypeImpl) typeNamed(name); if (type != null) { ! //System.out.println( ! // " Associate " + name.string() + ": " + record + " with " + type); type.associateRecord(record); return type; *************** *** 372,377 **** // Finally, use the Node to create it if necessary ! System.out.print( ! " " + (name == null ? "<unnamed>" : name.string()) + ": "); NodeType typeOf = record.type(); --- 372,377 ---- // Finally, use the Node to create it if necessary ! //System.out.print( ! // " " + (name == null ? "<unnamed>" : name.string()) + ": "); NodeType typeOf = record.type(); *************** *** 379,406 **** // Using the typeOf value, select a class of Type to create if (typeOf == MAPREC_TYPE) { ! System.out.println("Create Map from " + typeOf); type = MapTypeImpl.createFromNode(this, record); } else if (typeOf == SEQREC_TYPE) { ! System.out.println("Create Sequence from " + typeOf); type = SequenceTypeImpl.createFromNode(this, record); } else if (typeOf == SETREC_TYPE) { ! System.out.println("Create Set from " + typeOf); type = SetTypeImpl.createFromNode(this, record); } else if (typeOf == RECREC_TYPE) { ! System.out.println("Create Record from " + typeOf); type = RecordTypeImpl.createFromNode(this, record); } else if (typeOf == STRUCTREC_TYPE) { ! System.out.println("Create Struct from " + typeOf); type = StructTypeImpl.createFromNode(this, record); } else if (typeOf == UNIONREC_TYPE) { // Create Union type from RecordNode ! System.out.println("Create Union from " + typeOf); type = UnionTypeImpl.createFromNode(this, record); } else if (typeOf == RESTRREC_TYPE) { // Create Restriction type from RecordNode ! System.out.println("Create Restriction from " + typeOf); type = RestrictionTypeImpl.create(this, record); } else if (typeOf == NODEREC_TYPE) { ! System.out.println("Create Node from " + typeOf); TypeImpl nodeType = TypeImpl.NODETYPE; nodeType.associateRecord(record); --- 379,406 ---- // Using the typeOf value, select a class of Type to create if (typeOf == MAPREC_TYPE) { ! //System.out.println("Create Map from " + typeOf); type = MapTypeImpl.createFromNode(this, record); } else if (typeOf == SEQREC_TYPE) { ! //System.out.println("Create Sequence from " + typeOf); type = SequenceTypeImpl.createFromNode(this, record); } else if (typeOf == SETREC_TYPE) { ! //System.out.println("Create Set from " + typeOf); type = SetTypeImpl.createFromNode(this, record); } else if (typeOf == RECREC_TYPE) { ! //System.out.println("Create Record from " + typeOf); type = RecordTypeImpl.createFromNode(this, record); } else if (typeOf == STRUCTREC_TYPE) { ! //System.out.println("Create Struct from " + typeOf); type = StructTypeImpl.createFromNode(this, record); } else if (typeOf == UNIONREC_TYPE) { // Create Union type from RecordNode ! //System.out.println("Create Union from " + typeOf); type = UnionTypeImpl.createFromNode(this, record); } else if (typeOf == RESTRREC_TYPE) { // Create Restriction type from RecordNode ! //System.out.println("Create Restriction from " + typeOf); type = RestrictionTypeImpl.create(this, record); } else if (typeOf == NODEREC_TYPE) { ! //System.out.println("Create Node from " + typeOf); TypeImpl nodeType = TypeImpl.NODETYPE; nodeType.associateRecord(record); *************** *** 535,538 **** --- 535,542 ---- } + public String toString() { + return "TypeDoc["+uri()+"]"; + } + public Repository repository() { // FIXME: stub Index: StructTypeImpl.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/StructTypeImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** StructTypeImpl.java 28 Apr 2004 14:04:12 -0000 1.3 --- StructTypeImpl.java 28 Apr 2004 16:24:33 -0000 1.4 *************** *** 288,296 **** Impl newImpl = new NodeImpl(record); // compareImpls (this.impl, newImpl); ! System.out.print("From <= "); ! System.out.println(toString(true)); this.impl = newImpl; ! System.out.print("To => "); ! System.out.println(toString(true)); } --- 288,296 ---- Impl newImpl = new NodeImpl(record); // compareImpls (this.impl, newImpl); ! //System.out.print("From <= "); ! //System.out.println(toString(true)); this.impl = newImpl; ! //System.out.print("To => "); ! //System.out.println(toString(true)); } |
From: Lee I. <le...@us...> - 2004-04-28 14:04:23
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18194/org/nodal/implementation/types Modified Files: TypeDoc.java StructTypeImpl.java Log Message: Integrate reading of Struct types into baseTypes and schema parser. Index: TypeDoc.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/TypeDoc.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** TypeDoc.java 22 Apr 2004 22:19:40 -0000 1.61 --- TypeDoc.java 28 Apr 2004 14:04:12 -0000 1.62 *************** *** 38,41 **** --- 38,42 ---- import org.nodal.type.SequenceType; import org.nodal.type.SetType; + import org.nodal.type.StructType; import org.nodal.type.Type; import org.nodal.type.UnionType; *************** *** 343,346 **** --- 344,348 ---- static Type SETREC_TYPE = BASESCHEMA.typeNamed("SetType"); static Type RECREC_TYPE = BASESCHEMA.typeNamed("RecordType"); + static Type STRUCTREC_TYPE = BASESCHEMA.typeNamed("StructType"); static Type UNIONREC_TYPE = BASESCHEMA.typeNamed("UnionType"); static Type RESTRREC_TYPE = BASESCHEMA.typeNamed("RestrictionType"); *************** *** 388,391 **** --- 390,396 ---- System.out.println("Create Record from " + typeOf); type = RecordTypeImpl.createFromNode(this, record); + } else if (typeOf == STRUCTREC_TYPE) { + System.out.println("Create Struct from " + typeOf); + type = StructTypeImpl.createFromNode(this, record); } else if (typeOf == UNIONREC_TYPE) { // Create Union type from RecordNode *************** *** 490,493 **** --- 495,514 ---- /** + * Create a new StructType. + */ + StructType.Editor createStructType() { + StructType rt = StructTypeImpl.create(this); + return (StructType.Editor) rt.edit(); + } + + /** + * Create a new RecordType as extension of ext. + */ + StructType.Editor createStructType(StructType ext) { + StructType rt = StructTypeImpl.createExtended(this, ext); + return (StructType.Editor) rt.edit(); + } + + /** * Create a new RestrictionType dreived from an existing Type. */ *************** *** 620,623 **** --- 641,658 ---- /** + * Create a new StructType. + */ + public StructType.Editor createStructType() { + return TypeDoc.this.createStructType(); + } + + /** + * Create a new StructType as extension of ext. + */ + public StructType.Editor createStructType(StructType ext) { + return TypeDoc.this.createStructType(ext); + } + + /** * Create a new UnionType. */ *************** *** 713,716 **** --- 748,769 ---- /** + * Create, name and append new StructType. + */ + public StructType.Editor appendNewStructType(String nm) { + StructType.Editor t = createStructType(); + appendType(nm, t); + return t; + } + + /** + * Create, name and append new StructType. + */ + public StructType.Editor appendNewStructType(String nm, StructType ext) { + StructType.Editor t = createStructType(ext); + appendType(nm, t); + return t; + } + + /** * Create, name and append new MapType. */ Index: StructTypeImpl.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/StructTypeImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StructTypeImpl.java 23 Apr 2004 21:39:49 -0000 1.2 --- StructTypeImpl.java 28 Apr 2004 14:04:12 -0000 1.3 *************** *** 387,412 **** } public Struct createStruct(Object[] vals) throws ConstraintFailure { ! Type[] types = fieldTypes(); ! if (vals.length < types.length) { ! throw new ConstraintFailure ("Too few values"); ! } ! Object[] structVals = new Object[types.length]; ! for (int i = 0; i < types.length; ++i) { ! if (types[i].accepts(vals[i])) { ! structVals[i] = types[i].from (vals[i]); ! } else { ! throw new TypeConstraintFailure (vals[i], types[i], "Creating Struct"); ! } ! } ! return new StructImpl (this, structVals); } ! static final class StructImpl implements Struct { ! private StructTypeImpl type; ! private Object[] vals; ! StructImpl (StructTypeImpl type, Object[] vals) { this.type = type; ! this.vals = vals; } public StructType type() { --- 387,443 ---- } + /** + * Create a Struct instance from the argument sequence vals. + * @param vals an array of values to be used for initialization + * @return a Struct instance with those values. + */ public Struct createStruct(Object[] vals) throws ConstraintFailure { ! return new StructImpl (this, vals); } ! private static final class StructImpl implements Struct { ! private final StructTypeImpl type; ! private final Object[] vals; ! ! StructImpl (StructTypeImpl type, Object[] vals) throws ConstraintFailure { this.type = type; ! if (vals.length == type.size()) { ! this.vals = valsDirect (vals); ! } else if (vals.length == 2*type.size()) { ! this.vals = valsNamed (vals); ! } else { ! throw new ConstraintFailure ("Wrong length of parameter array"); ! } ! } ! private Object[] valsDirect (Object[] vals) throws TypeConstraintFailure { ! Type[] types = type.fieldTypes(); ! Object[] structVals = new Object[types.length]; ! for (int i = 0; i < types.length; ++i) { ! if (types[i].accepts(vals[i])) { ! structVals[i] = types[i].from (vals[i]); ! } else { ! throw new TypeConstraintFailure (vals[i], types[i], "Creating Struct"); ! } ! } ! return structVals; ! } ! private Object[] valsNamed (Object[] vals) throws ConstraintFailure { ! FieldMap map = type.fieldMap(); ! Type[] types = type.fieldTypes(); ! Object[] structVals = new Object[type.size()]; ! for (int i = 0; i < vals.length; i += 2) { ! Name nm = Names.getName((String) vals[i]); ! int fieldIdx = map.fieldIndex(nm); ! if (fieldIdx < 0) { ! throw new ConstraintFailure ("Unrecognized field name: "+nm.string()); ! } ! Type fieldType = types[fieldIdx]; ! if (fieldType.accepts(vals[i+1])) { ! structVals[i] = fieldType.from (vals[i+1]); ! } else { ! throw new TypeConstraintFailure (vals[i+1], fieldType, "Creating Struct"); ! } ! } ! return structVals; } public StructType type() { |
From: Lee I. <le...@us...> - 2004-04-28 14:04:22
|
Update of /cvsroot/nodal/nodal/j-src/extras In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18194/extras Modified Files: types.dtd baseTypes.nls Log Message: Integrate reading of Struct types into baseTypes and schema parser. Index: types.dtd =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/extras/types.dtd,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** types.dtd 19 Apr 2004 23:59:17 -0000 1.10 --- types.dtd 28 Apr 2004 14:04:12 -0000 1.11 *************** *** 8,12 **** <!-- A type declaration, but any possible one. --> <!ENTITY % nodeType ! "type|map|sequence|set|record|union|restriction" > <!ENTITY % anyType --- 8,12 ---- <!-- A type declaration, but any possible one. --> <!ENTITY % nodeType ! "type|map|sequence|set|record|struct|union|restriction" > <!ENTITY % anyType *************** *** 91,94 **** --- 91,104 ---- extends NMTOKEN #IMPLIED > + <!-- struct --> + <!-- A struct type --> + <!ELEMENT struct (field)* > + <!-- name the name of this type (declaration) + extends a struct reference that this struct derives + from --> + <!ATTLIST struct + name ID #IMPLIED + extends NMTOKEN #IMPLIED > + <!-- field --> <!-- A field description for a record --> Index: baseTypes.nls =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/extras/baseTypes.nls,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** baseTypes.nls 22 Apr 2004 22:19:40 -0000 1.18 --- baseTypes.nls 28 Apr 2004 14:04:12 -0000 1.19 *************** *** 221,224 **** --- 221,233 ---- </record> + <struct name="RestrictionStruct"> + <field name="name" type="Name"/> + <field name="comments" type="Comments"/> + </struct> + + <struct name="RegularExpressionStruct" extends="RestrictionStruct"> + <field name="re" type="Name"/> + </struct> + <!-- The type descriptor that allows any variation of a Node type to be |
From: Lee I. <le...@us...> - 2004-04-28 14:04:21
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/format/text/x_nodal_schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18194/org/nodal/format/text/x_nodal_schema Modified Files: Parser.java Log Message: Integrate reading of Struct types into baseTypes and schema parser. Index: Parser.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/format/text/x_nodal_schema/Parser.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Parser.java 20 Apr 2004 18:01:08 -0000 1.5 --- Parser.java 28 Apr 2004 14:04:11 -0000 1.6 *************** *** 153,157 **** .typeNamed("SetType"); private static final RecordType recordRType = (RecordType) Types.BASESCHEMA ! .typeNamed("RecordType"); private static final MapType recordFieldsType = (MapType) recordRType .fieldType("fields"); --- 153,159 ---- .typeNamed("SetType"); private static final RecordType recordRType = (RecordType) Types.BASESCHEMA ! .typeNamed("RecordType"); ! private static final RecordType structRType = (RecordType) Types.BASESCHEMA ! .typeNamed("StructType"); private static final MapType recordFieldsType = (MapType) recordRType .fieldType("fields"); *************** *** 178,181 **** --- 180,184 ---- private static final Name SET_N = Names.getName("set"); private static final Name RECORD_N = Names.getName("record"); + private static final Name STRUCT_N = Names.getName("struct"); private static final Name FIELD_N = Names.getName("field"); private static final Name UNION_N = Names.getName("union"); *************** *** 390,393 **** --- 393,398 ---- } else if (elem == RECORD_N) { return new RecordContext(this, attr, th); + } else if (elem == STRUCT_N) { + return new StructContext(this, attr, th); } else if (elem == UNION_N) { return new UnionContext(this, attr, th); *************** *** 630,633 **** --- 635,647 ---- } + abstract class FieldMapContext extends TypeContext { + protected FieldMapContext(ElementContext parent, TypeHandler th) { + super(parent, th); + } + + abstract void addField(String name, Node t, SequenceNode comments) + throws SAXException; + } + /** * A parsing context for <record> declarations. Initializes and passes *************** *** 638,642 **** * @author leei */ ! class RecordContext extends TypeContext { RecordNode.Editor recordRec; MapNode.Editor fieldsMap; --- 652,656 ---- * @author leei */ ! class RecordContext extends FieldMapContext { RecordNode.Editor recordRec; MapNode.Editor fieldsMap; *************** *** 707,712 **** } class FieldContext extends BaseContext implements TypeHandler { ! RecordContext record; String fieldName; Name typeName; --- 721,803 ---- } + /** + * A parsing context for <struct> declarations. Initializes and passes + * up a new "StructType" record and collects field declarations. + * + * Created on Jun 25, 2003 + * + * @author leei + */ + class StructContext extends FieldMapContext { + RecordNode.Editor recordRec; + MapNode.Editor fieldsMap; + MapNode.Editor commentsMap; + Name extName; + RecordNode extType; + + StructContext(ElementContext prev, Attributes attr, TypeHandler th) + throws SAXException { + super(prev, th); + //nl (); emit ("NDL: <struct> "+this); + recordRec = createTypeNode(structRType); + try { + fieldsMap = root.createNode(recordFieldsType).editMap(); + commentsMap = root.createNode(recordFieldCommentsType).editMap(); + recordRec.setField("fields").setNode(fieldsMap); + extName = nameFromQName(attr.getValue("extends")); + updateExtends(); + } catch (ConstraintFailure c) { + error(new SAXParseException( + "Violated baseTypes.nls#RecordType.fields", loc, c)); + } + sendType(recordRec); + } + + public void element(Name prefix, Name elem, Attributes attr) + throws SAXException { + if (elem == FIELD_N) { + new FieldContext(this, attr); + } else { + warning(new SAXParseException("Expecting <field>", loc)); + new UnknownContext(this, prefix, elem); + } + } + + private boolean updateExtends() throws SAXException { + try { + if (extType == null && extName != null) { + //nl(); emit("NDL: "+recordRec+" => extName \""+extName+"\""); + extType = nodeFromName(extName); + } + if (extType != null) { + //nl(); emit("NDL: "+recordRec+" => extends \""+extType+"\""); + recordRec.setField("extends").setNode(extType); + } + } catch (ConstraintFailure c) { + error(new SAXParseException( + "Violated baseTypes.nls#RecordType.extends", loc, c)); + } + return extName == null || extType != null; + } + + void addField(String name, Node t, SequenceNode comments) + throws SAXException { + try { + //nl (); emit ("NDL: addField "+name+" = "+t); + fieldsMap.setValue(name).setNode(t); + commentsMap.setValue(name).setNode(comments); + } catch (ConstraintFailure c) { + error(new SAXParseException( + "Violated baseTypes.nls#RecordType.fields", loc, c)); + } + } + + public boolean complete() throws SAXException { + return updateExtends(); + } + } + class FieldContext extends BaseContext implements TypeHandler { ! FieldMapContext record; String fieldName; Name typeName; *************** *** 714,718 **** SequenceNode comments; ! FieldContext(RecordContext record, Attributes attr) throws SAXException { super(record); this.record = record; --- 805,809 ---- SequenceNode comments; ! FieldContext(FieldMapContext record, Attributes attr) throws SAXException { super(record); this.record = record; |
From: Lee I. <le...@us...> - 2004-04-28 14:04:20
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/type In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18194/org/nodal/type Modified Files: StructType.java Log Message: Integrate reading of Struct types into baseTypes and schema parser. Index: StructType.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/type/StructType.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StructType.java 23 Apr 2004 21:39:49 -0000 1.2 --- StructType.java 28 Apr 2004 14:04:11 -0000 1.3 *************** *** 73,78 **** /** ! * Create a Struct of this type by interpreting the vals array, using the ! * fields in the order returned by fields(). * @param vals an array of Objects to be used for creating the Struct * @return a Struct value with the given field assignments --- 73,83 ---- /** ! * Create a Struct of this type by interpreting the vals array. ! * There are two ways of initializing the fields in the Struct: ! * 1) by using the fields in the order returned by fields(); ! * 2) by interleaving a String/Name to select a field and a value ! * that should be used to initialize that field. ! * The array provided can be either an Object[] or String[], and will ! * be interpreted appropriately. * @param vals an array of Objects to be used for creating the Struct * @return a Struct value with the given field assignments *************** *** 84,87 **** --- 89,98 ---- /** + * Create and return an Editor that allows one to modify this StructType. + * @return a StructType.Editor object or null if permission not available + */ + Editor edit(); + + /** * The interface for modifying a StructType. */ |
From: Lee I. <le...@us...> - 2004-04-23 21:39:58
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14680/org/nodal/implementation/types Modified Files: RecordTypeImpl.java StructTypeImpl.java Log Message: Add Struct type to model. Add methods to StructType for creation of Structs. Index: RecordTypeImpl.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/RecordTypeImpl.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** RecordTypeImpl.java 22 Apr 2004 22:19:40 -0000 1.20 --- RecordTypeImpl.java 23 Apr 2004 21:39:49 -0000 1.21 *************** *** 34,37 **** --- 34,38 ---- abstract Iterator localFields(); + abstract int localSize(); abstract RecordType extension(); *************** *** 64,67 **** --- 65,72 ---- } + int localSize() { + return fields.size(); + } + RecordType extension() { return extend; *************** *** 151,154 **** --- 156,163 ---- } + int localSize () { + return fields.size(); + } + RecordType setExtension(RecordType ext) { RecordTypeImpl extImpl = (RecordTypeImpl) ext; *************** *** 341,344 **** --- 350,365 ---- } + public int size() { + if (extension() != null) { + return localSize() + ((RecordTypeImpl)extension()).size(); + } else { + return localSize(); + } + } + + public int localSize() { + return impl.localSize(); + } + private class FieldIterator implements Iterator { boolean isExIter; *************** *** 363,369 **** public void remove() { ! // NEXT Throw unmodifiable? for Iterator } } protected synchronized RecordType setExtension(RecordType ext) { return impl.setExtension(ext); --- 384,391 ---- public void remove() { ! throw new UnsupportedOperationException ("Unmodifiable Iterator"); } } + protected synchronized RecordType setExtension(RecordType ext) { return impl.setExtension(ext); Index: StructTypeImpl.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/StructTypeImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StructTypeImpl.java 22 Apr 2004 22:19:40 -0000 1.1 --- StructTypeImpl.java 23 Apr 2004 21:39:49 -0000 1.2 *************** *** 9,14 **** --- 9,16 ---- package org.nodal.implementation.types; + import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; + import java.util.Map; import java.util.Vector; import org.nodal.model.Getter; *************** *** 16,25 **** --- 18,31 ---- import org.nodal.model.Node; import org.nodal.model.RecordNode; + import org.nodal.model.Struct; + import org.nodal.nav.Path; import org.nodal.type.RestrictionType; import org.nodal.type.StructType; import org.nodal.type.Type; import org.nodal.util.ConstraintFailure; + import org.nodal.util.GetterUtil; import org.nodal.util.Name; import org.nodal.util.Names; + import org.nodal.util.TypeConstraintFailure; /** *************** *** 31,36 **** abstract Type localFieldType(Name name); ! abstract Iterator fields(); ! abstract StructType extension(); --- 37,43 ---- abstract Type localFieldType(Name name); ! abstract Iterator localFields(); ! abstract int localSize(); ! abstract StructType extension(); *************** *** 58,65 **** } ! Iterator fields() { return fields.iterator(); } StructType extension() { return extend; --- 65,76 ---- } ! Iterator localFields() { return fields.iterator(); } + int localSize() { + return fields.size(); + } + StructType extension() { return extend; *************** *** 145,152 **** } ! Iterator fields() { return fields.properties(); } StructType setExtension(StructType ext) { StructTypeImpl extImpl = (StructTypeImpl) ext; --- 156,167 ---- } ! Iterator localFields() { return fields.properties(); } + int localSize() { + return fields.size(); + } + StructType setExtension(StructType ext) { StructTypeImpl extImpl = (StructTypeImpl) ext; *************** *** 231,238 **** private Impl impl; - //private RecordNode record; - //protected StructType extend; - //protected Vector fields; - //protected Hashtable types; private Editor editor; --- 246,249 ---- *************** *** 327,332 **** } public Iterator fields() { ! return impl.fields(); } --- 338,504 ---- } + public Iterator localFields() { + return impl.localFields(); + } + public Iterator fields() { ! if (extension() == null) { ! return localFields(); ! } else { ! return new FieldIterator(); ! } ! } ! ! public int size() { ! if (extension() != null) { ! return localSize() + extension().size(); ! } else { ! return localSize(); ! } ! } ! ! public int localSize() { ! return impl.localSize(); ! } ! private class FieldIterator implements Iterator { ! boolean isExIter; ! Iterator i; ! FieldIterator () { ! i = extension().fields(); ! isExIter = true; ! } ! public boolean hasNext() { ! boolean hasNext = i.hasNext(); ! if (! hasNext && isExIter) { ! i = localFields(); ! isExIter = false; ! hasNext = i.hasNext(); ! } ! return hasNext; ! } ! ! public Object next() { ! return i.next(); ! } ! ! public void remove() { ! throw new UnsupportedOperationException ("Unmodifiable Iterator"); ! } ! } ! ! public Struct createStruct(Object[] vals) throws ConstraintFailure { ! Type[] types = fieldTypes(); ! if (vals.length < types.length) { ! throw new ConstraintFailure ("Too few values"); ! } ! Object[] structVals = new Object[types.length]; ! for (int i = 0; i < types.length; ++i) { ! if (types[i].accepts(vals[i])) { ! structVals[i] = types[i].from (vals[i]); ! } else { ! throw new TypeConstraintFailure (vals[i], types[i], "Creating Struct"); ! } ! } ! return new StructImpl (this, structVals); ! } ! ! static final class StructImpl implements Struct { ! private StructTypeImpl type; ! private Object[] vals; ! StructImpl (StructTypeImpl type, Object[] vals) { ! this.type = type; ! this.vals = vals; ! } ! public StructType type() { ! return type; ! } ! public Getter field(Name name) { ! int idx = type.fieldMap().fieldIndex(name); ! if (idx < 0) {return null;} ! return new FieldGetter(idx); ! } ! class FieldGetter extends GetterUtil { ! int idx; ! FieldGetter (int idx) { ! super(type.fieldMap().types()[idx]); ! this.idx = idx; ! } ! public Object get() { ! return vals[idx]; ! } ! public Path createPath() { ! return null; ! } ! } ! public Getter field(String name) { ! return field(Names.getName(name)); ! } ! public Object getField(Name name) { ! int idx = type.fieldMap().fieldIndex(name); ! if (idx < 0) {return null;} ! return vals[idx]; ! } ! public Object getField(String name) { ! return getField(Names.getName(name)); ! } ! } ! ! private FieldMap fieldMap; ! ! final class FieldMap { ! final Type[] typeArray; ! final Name[] fieldArray; ! final Map map; ! ! FieldMap () { ! int size = size(); ! this.map = new HashMap(); ! this.typeArray = new Type[size]; ! this.fieldArray = new Name[size]; ! Iterator fields = fields(); ! for (int i = 0; fields.hasNext(); ++i) { ! Name name = (Name) fields.next(); ! fieldArray[i] = name; ! typeArray[i] = fieldType(name); ! map.put (name, new Integer(i)); ! } ! } ! ! Type[] types () { ! return typeArray; ! } ! Name[] names () { ! return fieldArray; ! } ! int fieldIndex(Name name) { ! Object idx = map.get(name); ! if (idx == null) { ! return -1; ! } ! return ((Integer) idx).intValue(); ! } ! } ! ! private FieldMap fieldMap () { ! if (fieldMap == null) { ! fieldMap = new FieldMap(); ! } ! return fieldMap; ! } ! ! /** ! * Return an array of the field types in a Struct of this type. ! * @return ! */ ! private Type[] fieldTypes() { ! return fieldMap().types(); ! } ! ! /** ! * Return an array of the field types in a Struct of this type. ! * @return ! */ ! private Name[] fieldNames() { ! return fieldMap().names(); } *************** *** 390,397 **** --- 562,581 ---- } + public Iterator localFields() { + return StructTypeImpl.this.localFields(); + } + public Iterator fields() { return StructTypeImpl.this.fields(); } + public int localSize () { + return StructTypeImpl.this.localSize(); + } + + public int size () { + return StructTypeImpl.this.size(); + } + // Implementations of StructTypeEditor methods public StructType setExtension(StructType ext) { *************** *** 406,409 **** --- 590,597 ---- return StructTypeImpl.this.removeField(nm); } + + public Struct createStruct(Object[] vals) throws ConstraintFailure { + return StructTypeImpl.this.createStruct(vals); + } } *************** *** 474,478 **** */ public boolean acceptsString(String s) { - // TODO Auto-generated method stub return false; } --- 662,665 ---- *************** *** 482,486 **** */ protected boolean acceptsObject(Object o) { ! // TODO Auto-generated method stub return false; } --- 669,677 ---- */ protected boolean acceptsObject(Object o) { ! if (o instanceof Struct) { ! Struct other = (Struct) o; ! return acceptsType(other.type()); ! } ! // TODO Check types for an array return false; } *************** *** 490,494 **** */ public Object fromString(String s) { - // TODO Auto-generated method stub return null; } --- 681,684 ---- *************** *** 498,502 **** */ protected Object fromObject(Object o) { ! // TODO Auto-generated method stub return null; } --- 688,698 ---- */ protected Object fromObject(Object o) { ! if (o instanceof Struct) { ! Struct other = (Struct) o; ! if (acceptsType(other.type())) { ! return other; ! } ! } ! // TODO Check types for an array return null; } |
From: Lee I. <le...@us...> - 2004-04-23 21:39:58
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/type In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14680/org/nodal/type Modified Files: StructType.java Log Message: Add Struct type to model. Add methods to StructType for creation of Structs. Index: StructType.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/type/StructType.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StructType.java 22 Apr 2004 22:19:39 -0000 1.1 --- StructType.java 23 Apr 2004 21:39:49 -0000 1.2 *************** *** 12,15 **** --- 12,17 ---- import java.util.Iterator; + import org.nodal.model.Struct; + import org.nodal.util.ConstraintFailure; import org.nodal.util.Name; *************** *** 47,55 **** /** * An Enumeration of all of the field names for this StructType ! * (not including those of the extension.) */ Iterator fields (); /** * The interface for modifying a StructType. */ --- 49,87 ---- /** * An Enumeration of all of the field names for this StructType ! * (including those of any extension.) */ Iterator fields (); /** + * An Enumeration of all of the field names for this StructType + * (not including those of any extension.) + */ + Iterator localFields (); + + + /** + * The number of fields in this StructType (including any extension). + * @return the number of fields in this StructType + */ + int size(); + + /** + * The number of fields in this StructType (not including any extension). + * @return the number of fields in this StructType + */ + int localSize(); + + /** + * Create a Struct of this type by interpreting the vals array, using the + * fields in the order returned by fields(). + * @param vals an array of Objects to be used for creating the Struct + * @return a Struct value with the given field assignments + * @throws ConstraintFailure when any of the values doesn't match the type + * of the associated field. + * + */ + Struct createStruct (Object[] vals) throws ConstraintFailure; + + /** * The interface for modifying a StructType. */ |
From: Lee I. <le...@us...> - 2004-04-22 22:19:49
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12627/org/nodal/implementation/types Modified Files: RecordTypeImpl.java TypeDoc.java RestrictionTypeImpl.java Added Files: StructTypeImpl.java Log Message: Add StructType and Struct implementations. Index: RestrictionTypeImpl.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/RestrictionTypeImpl.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** RestrictionTypeImpl.java 22 Apr 2004 16:50:48 -0000 1.18 --- RestrictionTypeImpl.java 22 Apr 2004 22:19:40 -0000 1.19 *************** *** 72,75 **** --- 72,76 ---- private void initRestrictions () { + doc.createTypeFromRecord(record.field("base").getNode().asRecordNode()); for (int i = 0; i < seq.size(); ++i) { RecordNode rec = seq.item(i).getNode().asRecordNode(); Index: TypeDoc.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/TypeDoc.java,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** TypeDoc.java 19 Apr 2004 23:59:19 -0000 1.60 --- TypeDoc.java 22 Apr 2004 22:19:40 -0000 1.61 *************** *** 176,182 **** mt.addField("valueType", tt); RecordType.Editor rt = ED.appendNewRecordType("RecordType", nt); rt.addField("extends", rt); ! rt.addField("fields", ED.createMapType(TypeImpl.NAME, tt)); rt.addField("fieldComments", ED.createMapType(TypeImpl.NAME, ct)); --- 176,184 ---- mt.addField("valueType", tt); + MapType.Editor fields = ED.createMapType(TypeImpl.NAME, tt); + RecordType.Editor rt = ED.appendNewRecordType("RecordType", nt); rt.addField("extends", rt); ! rt.addField("fields", fields); rt.addField("fieldComments", ED.createMapType(TypeImpl.NAME, ct)); *************** *** 184,187 **** --- 186,194 ---- ut.addField("types", ED.createSetType(nt)); + RecordType.Editor struct = ED.appendNewRecordType("StructType", nt); + struct.addField("extends", struct); + struct.addField("fields", fields); + struct.addField("fieldComments", ED.createMapType(TypeImpl.NAME, ct)); + RecordType.Editor rest = ED.appendNewRecordType("RestrictionType", tt); rest.addField("base", tt); Index: RecordTypeImpl.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/RecordTypeImpl.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** RecordTypeImpl.java 16 Apr 2004 22:03:45 -0000 1.19 --- RecordTypeImpl.java 22 Apr 2004 22:19:40 -0000 1.20 *************** *** 33,37 **** abstract Type localFieldType(Name name); ! abstract Iterator fields(); abstract RecordType extension(); --- 33,37 ---- abstract Type localFieldType(Name name); ! abstract Iterator localFields(); abstract RecordType extension(); *************** *** 60,64 **** } ! Iterator fields() { return fields.iterator(); } --- 60,64 ---- } ! Iterator localFields() { return fields.iterator(); } *************** *** 128,133 **** this.fields = record.field("fields").getNode().asMapNode(); this.editor = record.editRecord(); ! ! initTypes (); } --- 128,132 ---- this.fields = record.field("fields").getNode().asMapNode(); this.editor = record.editRecord(); ! initTypes(); } *************** *** 147,152 **** return (RecordType) typeForNode(extend.getNode()); } ! ! Iterator fields() { return fields.properties(); } --- 146,151 ---- return (RecordType) typeForNode(extend.getNode()); } ! ! Iterator localFields() { return fields.properties(); } *************** *** 208,221 **** return prev; } ! ! private void initTypes () { Node extendsNode = record.field("extends").getNode(); if (extendsNode != null) { doc.createTypeFromRecord(extendsNode.asRecordNode()); //System.out.println(this + ": (check association)"); ! //System.out.println(" > extend: " + extend + " = " + extendsNode + "/"+ nodeExtends); //this.extend = (RecordType) nodeExtends; } - // Map all of the fields... Node fieldsNode = record.field("fields").getNode(); --- 207,220 ---- return prev; } ! ! private void initTypes() { Node extendsNode = record.field("extends").getNode(); if (extendsNode != null) { doc.createTypeFromRecord(extendsNode.asRecordNode()); //System.out.println(this + ": (check association)"); ! //System.out.println(" > extend: " + extend + " = " + extendsNode + ! // "/"+ nodeExtends); //this.extend = (RecordType) nodeExtends; } // Map all of the fields... Node fieldsNode = record.field("fields").getNode(); *************** *** 224,234 **** while (e.hasNext()) { Name fieldName = (Name) e.next(); ! RecordNode fieldTypeNode = ! fields.value(fieldName).getNode().asRecordNode(); doc.createTypeFromRecord(fieldTypeNode); ! //System.out.println (RecordTypeImpl.this+"."+fieldName.string()+" = "+fieldType); } } - } --- 223,233 ---- while (e.hasNext()) { Name fieldName = (Name) e.next(); ! RecordNode fieldTypeNode = fields.value(fieldName).getNode() ! .asRecordNode(); doc.createTypeFromRecord(fieldTypeNode); ! //System.out.println (RecordTypeImpl.this+"."+fieldName.string()+" = ! // "+fieldType); } } } *************** *** 278,288 **** void associateRecord(RecordNode record) { attachNode(record.bareNode()); ! RecordImpl newImpl = new NodeImpl (record); // compareImpls (this.impl, newImpl); ! System.out.print("From <= "); System.out.println (toString (true)); this.impl = newImpl; ! System.out.print("To => "); System.out.println (toString (true)); } ! // Implementation of NodeType methods public final Type propertyType() { --- 277,289 ---- void associateRecord(RecordNode record) { attachNode(record.bareNode()); ! RecordImpl newImpl = new NodeImpl(record); // compareImpls (this.impl, newImpl); ! System.out.print("From <= "); ! System.out.println(toString(true)); this.impl = newImpl; ! System.out.print("To => "); ! System.out.println(toString(true)); } ! // Implementation of NodeType methods public final Type propertyType() { *************** *** 328,335 **** } public Iterator fields() { ! return impl.fields(); } protected synchronized RecordType setExtension(RecordType ext) { return impl.setExtension(ext); --- 329,369 ---- } + public Iterator localFields() { + return impl.localFields(); + } + public Iterator fields() { ! if (extension() == null) { ! return localFields(); ! } else { ! return new FieldIterator(); ! } } + private class FieldIterator implements Iterator { + boolean isExIter; + Iterator i; + FieldIterator () { + i = extension().fields(); + isExIter = true; + } + public boolean hasNext() { + boolean hasNext = i.hasNext(); + if (! hasNext && isExIter) { + i = localFields(); + isExIter = false; + hasNext = i.hasNext(); + } + return hasNext; + } + + public Object next() { + return i.next(); + } + + public void remove() { + // NEXT Throw unmodifiable? for Iterator + } + } protected synchronized RecordType setExtension(RecordType ext) { return impl.setExtension(ext); *************** *** 400,403 **** --- 434,441 ---- } + public Iterator localFields() { + return rec.localFields(); + } + // Implementations of RecordTypeEditor methods public RecordType setExtension(RecordType ext) { *************** *** 432,436 **** while (flds.hasNext()) { Name f = (Name) flds.next(); ! Type t = localFieldType(f); b.append(" <field name=\"" + f.string() + "\""); if (t.name() == null) { --- 470,474 ---- while (flds.hasNext()) { Name f = (Name) flds.next(); ! Type t = fieldType(f); b.append(" <field name=\"" + f.string() + "\""); if (t.name() == null) { --- NEW FILE: StructTypeImpl.java --- /* * * Distributed under the Apache Software License, Version 1.1 * (see below, or the file LICENSE for terms and conditions) * * Copyright (c) 2002 University of BC. All rights reserved. * */ package org.nodal.implementation.types; import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; import org.nodal.model.Getter; import org.nodal.model.MapNode; import org.nodal.model.Node; import org.nodal.model.RecordNode; import org.nodal.type.RestrictionType; import org.nodal.type.StructType; import org.nodal.type.Type; import org.nodal.util.ConstraintFailure; import org.nodal.util.Name; import org.nodal.util.Names; /** * Implementation of a 'record' or 'struct' type. * */ public class StructTypeImpl extends AtomicType implements StructType { private abstract class Impl { abstract Type localFieldType(Name name); abstract Iterator fields(); abstract StructType extension(); // Editing methods abstract StructType setExtension(StructType ext); abstract boolean addField(Name name, Type type); abstract Type removeField(Name name); } private final class BareImpl extends Impl { protected StructType extend; protected Vector fields; protected Hashtable types; BareImpl(StructType extend) { this.fields = new Vector(); this.types = new Hashtable(); this.extend = (StructType) (extend == null ? extend : extend.type()); } Type localFieldType(Name name) { return (Type) types.get(name); } Iterator fields() { return fields.iterator(); } StructType extension() { return extend; } synchronized StructType setExtension(StructType ext) { ext = (StructType) ext.type(); // Resolve to base type StructType prev = extend; // Use asStructType to get back to base StructTypeImpl instance. this.extend = (StructType) (ext == null ? ext : ext.type()); return prev; } synchronized boolean addField(Name name, Type type) { type = type.type(); // Resolve to base type // Override field already locally defined. Type currentType = localFieldType(name); if (currentType != null) { if (!type.equals(currentType)) { types.put(name, type); } return true; } // Check for shadowing if (extend != null) { Type shadowedType = extend.fieldType(name); if (shadowedType != null) { // This is a shadowing declaration. if (shadowedType.equals(type)) { return false; } // Check for type compatibility. This means that the new type // is a restriction of the type being shadowed. if (!shadowedType.acceptsType(type)) { return false; } } } // Finally, add it. fields.addElement(name); types.put(name, type); return true; } synchronized Type removeField(Name name) { int i = fields.indexOf(name); if (i < 0) { return null; } fields.removeElementAt(i); return (Type) types.remove(name); } } private final class NodeImpl extends Impl { private final RecordNode record; private final Getter extend; private final MapNode fields; private final RecordNode.Editor editor; NodeImpl(RecordNode record) { this.record = record; this.extend = record.field("extends"); this.fields = record.field("fields").getNode().asMapNode(); this.editor = record.editRecord(); initTypes(); } // NEXT Create RecordNode for StructTypeImpl... /* * NodeImpl (NodeFactory factory) { this.editor = factory.createNode (...); } */ Type localFieldType(Name name) { Node n = fields.value(name).getNode(); if (n == null) { return null; } return typeForNode(n); } StructType extension() { return (StructType) typeForNode(extend.getNode()); } Iterator fields() { return fields.properties(); } StructType setExtension(StructType ext) { StructTypeImpl extImpl = (StructTypeImpl) ext; Node extNode = extImpl.node; StructType prev = (StructType) extension(); try { editor.setField("extends").setNode(extNode); } catch (ConstraintFailure e) { throw new RuntimeException("StructType with incompatible Node: " + ext); } return prev; } synchronized boolean addField(Name name, Type type) { TypeImpl impl = (TypeImpl) type.type(); MapNode.Editor fieldEditor = fields.editMap(); try { // Override field already locally defined. Type currentType = localFieldType(name); if (currentType != null) { if (!type.equals(currentType)) { fieldEditor.setValue(name).setNode(impl.node()); } return true; } // Check for shadowing StructType extend = extension(); if (extend != null) { Type shadowedType = extend.fieldType(name); if (shadowedType != null) { // This is a shadowing declaration. if (shadowedType.equals(type)) { return false; } // Check for type compatibility. This means that the new type // is a restriction of the type being shadowed. if (!shadowedType.acceptsType(type)) { return false; } } } // Finally, add it. fieldEditor.setValue(name).setNode(impl.node()); } catch (ConstraintFailure e) { throw new RuntimeException("Type with incompatible Node: " + impl); } return true; } Type removeField(Name name) { MapNode.Editor fieldEditor = fields.editMap(); Type prev = (Type) fields.value(name); if (prev != null) { fieldEditor.removeKey(name); } return prev; } private void initTypes() { Node extendsNode = record.field("extends").getNode(); if (extendsNode != null) { doc.createTypeFromRecord(extendsNode.asRecordNode()); //System.out.println(this + ": (check association)"); //System.out.println(" > extend: " + extend + " = " + extendsNode + // "/"+ nodeExtends); //this.extend = (StructType) nodeExtends; } // Map all of the fields... Node fieldsNode = record.field("fields").getNode(); MapNode fields = fieldsNode.asMapNode(); Iterator e = fields.properties(); while (e.hasNext()) { Name fieldName = (Name) e.next(); RecordNode fieldTypeNode = fields.value(fieldName).getNode() .asRecordNode(); doc.createTypeFromRecord(fieldTypeNode); //System.out.println (StructTypeImpl.this+"."+fieldName.string()+" = // "+fieldType); } } } private Impl impl; //private RecordNode record; //protected StructType extend; //protected Vector fields; //protected Hashtable types; private Editor editor; static StructTypeImpl create(TypeDoc doc) { return new StructTypeImpl(doc); } static StructTypeImpl createExtended(TypeDoc doc, StructType ext) { return new StructTypeImpl(doc, ext); } /** * Create a StructType from the given RecordNode (appropriately typed). * * @param doc * the TypeDoc containing this Type * @param typeNode * a RecordNode describing the Type * @return a new StructTypeImpl built from the Node contents */ static TypeImpl createFromNode(TypeDoc doc, RecordNode typeNode) { return new StructTypeImpl(doc, typeNode); } private StructTypeImpl(TypeDoc d) { super(d); this.impl = new BareImpl(null); } private StructTypeImpl(TypeDoc d, StructType ext) { super(d); this.impl = new BareImpl(ext); } private StructTypeImpl(TypeDoc doc, RecordNode record) { super(doc); this.impl = new NodeImpl(record); } void associateRecord(RecordNode record) { attachNode(record.bareNode()); Impl newImpl = new NodeImpl(record); // compareImpls (this.impl, newImpl); System.out.print("From <= "); System.out.println(toString(true)); this.impl = newImpl; System.out.print("To => "); System.out.println(toString(true)); } // Implementation of NodeType methods public final Type propertyType() { return TypeImpl.NAME; } public final Type valueType(Object property) { if (property instanceof Names) { Name nm = (Name) property; return fieldType(nm); } else if (property instanceof String) { return fieldType((String) property); } return null; } public StructType asStructType() { return this; } // Implementation of StructType methods public StructType extension() { return impl.extension(); } public Type fieldType(String nm) { return fieldType(Names.getName(nm)); } public Type fieldType(Name name) { Type t = localFieldType(name); if (t == null) { StructType extend = extension(); if (extend != null) { t = extend.fieldType(name); } } return t; } private final Type localFieldType(Name name) { return impl.localFieldType(name); } public Iterator fields() { return impl.fields(); } protected synchronized StructType setExtension(StructType ext) { return impl.setExtension(ext); } protected boolean addField(String nm, Type type) { Name name = Names.getName(nm); return addField(name, type); } protected synchronized boolean addField(Name name, Type type) { return impl.addField(name, type); } protected synchronized Type removeField(String nm) { return impl.removeField(Names.getName(nm)); } public StructType.Editor edit() { // FIXME: check permission if (editor == null) { editor = new Editor(); } return editor; } private class Editor extends TypeEditorUtil implements StructType.Editor { Editor() { super (StructTypeImpl.this); } public StructType asStructType() { return StructTypeImpl.this; } // Implementations of SequenceType methods public StructType.Editor edit() { return this; } public final Type propertyType() { return StructTypeImpl.this.propertyType(); } public final Type valueType(Object property) { return StructTypeImpl.this.valueType(property); } public StructType extension() { return StructTypeImpl.this.extension(); } public Type fieldType(String nm) { return StructTypeImpl.this.fieldType(nm); } public Type fieldType(Name name) { return StructTypeImpl.this.fieldType(name); } public Iterator fields() { return StructTypeImpl.this.fields(); } // Implementations of StructTypeEditor methods public StructType setExtension(StructType ext) { return StructTypeImpl.this.setExtension(ext); } public boolean addField(String nm, Type type) { return StructTypeImpl.this.addField(nm, type); } public Type removeField(String nm) { return StructTypeImpl.this.removeField(nm); } } private String toString(boolean decl) { StringBuffer b = new StringBuffer("<ndl:record"); //b.append(" hash=\"" + Integer.toHexString(hashCode()) + "\""); if (!decl && name != null) { b.append(" name=\"" + name.string() + "\"/>"); } else { if (name != null) { b.append(" " + "name=\"" + name.string() + "\""); } StructType extend = extension(); if (extend != null && extend.name() != null) { b.append(" extend=\"" + extend.name().string() + "\""); } Iterator flds = fields(); if (flds.hasNext()) { b.append(">\n"); while (flds.hasNext()) { Name f = (Name) flds.next(); Type t = localFieldType(f); b.append(" <field name=\"" + f.string() + "\""); if (t.name() == null) { b.append(">\n " + t.toString() + "\n </field>\n"); } else { b.append(" type=\"" + t.name().string() + "\"/>\n"); } } b.append("</ndl:record>"); } else { b.append("/>"); } } return b.toString(); } public String toString() { return toString(false); } public String declString() { return toString(true); } public boolean acceptsType(Type t) { // Find the base of the RestrictionType chain if (t instanceof RestrictionType) { t = ((RestrictionType) t).baseType(); } // Check the equivalence of StructType objects if (t instanceof StructType) { StructType rt = (StructType) t; // Basically we will accept any StructType that is extended from // this one. while (rt != null) { if (this.equals(rt)) { return true; } rt = rt.extension(); } } return false; } /* (non-Javadoc) * @see org.nodal.implementation.types.TypeImpl#acceptsString(java.lang.String) */ public boolean acceptsString(String s) { // TODO Auto-generated method stub return false; } /* (non-Javadoc) * @see org.nodal.implementation.types.TypeImpl#acceptsObject(java.lang.Object) */ protected boolean acceptsObject(Object o) { // TODO Auto-generated method stub return false; } /* (non-Javadoc) * @see org.nodal.implementation.types.TypeImpl#fromString(java.lang.String) */ public Object fromString(String s) { // TODO Auto-generated method stub return null; } /* (non-Javadoc) * @see org.nodal.implementation.types.TypeImpl#fromObject(java.lang.Object) */ protected Object fromObject(Object o) { // TODO Auto-generated method stub return null; } } |
From: Lee I. <le...@us...> - 2004-04-22 22:19:49
|
Update of /cvsroot/nodal/nodal/j-src/extras In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12627/extras Modified Files: baseTypes.nls Log Message: Add StructType and Struct implementations. Index: baseTypes.nls =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/extras/baseTypes.nls,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** baseTypes.nls 19 Apr 2004 23:59:17 -0000 1.17 --- baseTypes.nls 22 Apr 2004 22:19:40 -0000 1.18 *************** *** 112,115 **** --- 112,130 ---- <!-- + The Struct type, a mapping from names to values similar to a struct + in C or a relational table. The extends attribute allows one + StructType to derive from another in a kind of + inheritance. Maintains a list of name->type mappings that describes + the full set of fields in the given record. + Unlike the RecordType, this does not describe a NodeType, and thus + represents structured, but unmodifiable values. + This record maps onto the org.nodal.type.StructType interface. + --> + <record name="StructType" extends="Type"> + <field name="extends" type="StructType"/> + <field name="fields" type="Fields"/> + </record> + + <!-- The base type of all Nodes. This record maps onto the org.nodal.type.NodeType interface. *************** *** 151,163 **** inheritance. Maintains a list of name->type mappings that describes the full set of fields in the given record. This record maps onto the org.nodal.type.RecordType interface. --> <record name="RecordType" extends="NodeType"> <field name="extends" type="RecordType"/> ! <field name="fields"> ! <map keyType="Name" valueType="Type"/> ! </field> </record> <!-- The Union type represents a union of a number of different NodeType --- 166,180 ---- inheritance. Maintains a list of name->type mappings that describes the full set of fields in the given record. + Unlike the StructType, the objects stored as Records are Nodes, and thus + modifiable and imbued with all of the Node metadata. This record maps onto the org.nodal.type.RecordType interface. --> <record name="RecordType" extends="NodeType"> <field name="extends" type="RecordType"/> ! <field name="fields" type="Fields"/> </record> + <map name="Fields" keyType="Name" valueType="Type"/> + <!-- The Union type represents a union of a number of different NodeType |
From: Lee I. <le...@us...> - 2004-04-22 22:19:49
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12627/org/nodal/model Added Files: Struct.java Log Message: Add StructType and Struct implementations. --- NEW FILE: Struct.java --- /* * Distributed under the Apache Software License, Version 1.1 * (see below, or the file LICENSE for terms and conditions) * * Copyright (c) 2004 University of British Columbia. All rights reserved. * * Created on Apr 22, 2004 by leei */ package org.nodal.model; import org.nodal.type.StructType; import org.nodal.util.Name; /** * A compound, but atomic data element. Objects of this type have a set of * named fields, defined by the StructType, but are not modifiable. Once * constructed they remain constant. * * @author leei */ public interface Struct { /** * The StructType that defines this Object's fields. * @return the StructType that defined this Object's fields. */ StructType type(); /** * Return a Getter for the field named. */ Getter field(Name name); /** * Return a Getter for the field named. */ Getter field(String name); /** * Return the Object stored in the name field. */ Object getField(Name name); /** * Return the Object stored in the name field. */ Object getField(String name); } |
From: Lee I. <le...@us...> - 2004-04-22 22:19:48
|
Update of /cvsroot/nodal/nodal/j-src/.externalToolBuilders In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12627/.externalToolBuilders Modified Files: Prepare.launch Log Message: Add StructType and Struct implementations. Index: Prepare.launch =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/.externalToolBuilders/Prepare.launch,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Prepare.launch 19 Apr 2004 23:59:20 -0000 1.6 --- Prepare.launch 22 Apr 2004 22:19:39 -0000 1.7 *************** *** 4,9 **** <booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/> <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/> ! <stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <launchConfigurationWorkingSet factoryID="org.eclipse.ui.internal.WorkingSetFactory" name="workingSet"> <item factoryID="org.eclipse.ui.internal.model.ResourceFactory" path="/j-src/extras" type="2"/> </launchConfigurationWorkingSet> }"/> ! <stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/j-src}"/> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/j-src/build.xml}"/> --- 4,9 ---- <booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/> <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/> ! <stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <launchConfigurationWorkingSet factoryID="org.eclipse.ui.internal.WorkingSetFactory" name="workingSet" editPageId="org.eclipse.ui.resourceWorkingSetPage"> <item factoryID="org.eclipse.ui.internal.model.ResourceFactory" path="/j-src/extras" type="2"/> </launchConfigurationWorkingSet> }"/> ! <stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/j-src}"/> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/j-src/build.xml}"/> |
From: Lee I. <le...@us...> - 2004-04-22 22:19:47
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/type In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12627/org/nodal/type Modified Files: RecordType.java Added Files: StructType.java Log Message: Add StructType and Struct implementations. --- NEW FILE: StructType.java --- /* * * Distributed under the Apache Software License, Version 1.1 * (see below, or the file LICENSE for terms and conditions) * * Copyright (c) 2001 SRI International. All rights reserved. * */ package org.nodal.type; import java.util.Iterator; import org.nodal.util.Name; /** * A Type representing a structured atomic type. * * <p>Instances of this type are structures with named * fields. Each field has an associated Type.<p> * * <p>A StructType can be an extension of another StructType, which * represents data inheritance. In other words, any field in the * extension StructType is also a field of this StructType.</p> * * @author Lee Iverson <le...@ec...> * @see org.nodal.model.Struct */ public interface StructType extends Type { /** * The StructType for which this StructType is an extension. */ StructType extension (); /** * The Type associated with this field name. */ Type fieldType (String field); /** * The Type associated with this field name. */ Type fieldType (Name field); /** * An Enumeration of all of the field names for this StructType * (not including those of the extension.) */ Iterator fields (); /** * The interface for modifying a StructType. */ interface Editor extends StructType { /** * Change the extension of the associated StructType. */ StructType setExtension (StructType ext); /** * Add a field to the associated StructType. */ boolean addField (String name, Type type /*, Object def*/); /** * Remove a field from the associated StructType. * * <p>Returns the Type of the field removed, or null if it does * not exist.</p> */ Type removeField (String name); } } Index: RecordType.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/type/RecordType.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RecordType.java 19 Mar 2004 00:24:43 -0000 1.7 --- RecordType.java 22 Apr 2004 22:19:39 -0000 1.8 *************** *** 46,54 **** /** * An Enumeration of all of the field names for this RecordType ! * (not including those of the extension.) */ Iterator fields (); /** * The interface for modifying a RecordType. */ --- 46,60 ---- /** * An Enumeration of all of the field names for this RecordType ! * (including those of the extension.) */ Iterator fields (); /** + * An Enumeration of all of the field names for this RecordType + * (not including those of the extension.) + */ + Iterator localFields (); + + /** * The interface for modifying a RecordType. */ |
From: Lee I. <le...@us...> - 2004-04-22 16:50:58
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv508/org/nodal/implementation/types Modified Files: RestrictionTypeImpl.java Log Message: Modify RestrictionTypeImpl to indirect bare/node implementation. Index: RestrictionTypeImpl.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/implementation/types/RestrictionTypeImpl.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** RestrictionTypeImpl.java 16 Apr 2004 22:03:45 -0000 1.17 --- RestrictionTypeImpl.java 22 Apr 2004 16:50:48 -0000 1.18 *************** *** 16,19 **** --- 16,20 ---- import java.util.Set; + import org.nodal.model.Getter; import org.nodal.model.MapNode; import org.nodal.model.Node; *************** *** 30,37 **** */ class RestrictionTypeImpl extends TypeImpl implements RestrictionType { ! // NEXT Convert RestrictionTypeImpl to indirect style. private RecordNode record; - private final Type type; - private final Set restrictions; private Editor editor; --- 31,105 ---- */ class RestrictionTypeImpl extends TypeImpl implements RestrictionType { ! private abstract class Impl { ! abstract Type base(); ! abstract Set restrictions(); ! abstract Iterator iterator(); ! abstract boolean addRestriction (Restriction r); ! abstract boolean removeRestriction (Restriction r); ! } ! ! private final class BareImpl extends Impl { ! private final Type base; ! private final Set restrictions; ! BareImpl (Type base) { ! this.base = base; ! this.restrictions = new java.util.HashSet(); ! } ! Type base () { return base; } ! Set restrictions () { return restrictions; } ! Iterator iterator() { return restrictions.iterator(); } ! boolean addRestriction (Restriction r) { ! return restrictions.add(r); ! } ! boolean removeRestriction (Restriction r) { ! return restrictions.remove(r); ! } ! } ! ! private final class NodeImpl extends Impl { ! private final RecordNode record; ! private final Getter baseGetter; ! private final SequenceNode seq; ! private final Set restrictions; ! ! NodeImpl (RecordNode record) { ! this.record = record; ! this.restrictions = new java.util.HashSet(); ! this.baseGetter = record.field("base"); ! this.seq = record.field("restrictions").getNode().asSequenceNode(); ! initRestrictions(); ! } ! ! private void initRestrictions () { ! for (int i = 0; i < seq.size(); ++i) { ! RecordNode rec = seq.item(i).getNode().asRecordNode(); ! Name name = (Name) rec.getField("name"); ! MapNode args = rec.field("args").getNode().asMapNode(); ! try { ! restrictions.add (RestrictionImpl.create(base(), name, args)); ! } catch (CreationFailure e) { ! // TODO Handle a problematic Restriction record ! System.err.println("Couldn't handle restriction: " + name.string()); ! } ! } ! } ! ! Type base() { return typeForNode (baseGetter.getNode()); } ! Set restrictions() { return restrictions; } ! Iterator iterator() { return restrictions.iterator(); } ! boolean addRestriction (Restriction r) { ! // SequenceNode.Editor ed = seq.editSequence(); ! // NEXT r.node(): ed.insertAfter(-1).set(r.node()); ! return restrictions.add(r); ! } ! boolean removeRestriction (Restriction r) { ! return restrictions.remove(r); ! } ! ! } ! ! private Impl impl; ! private RecordNode record; private Editor editor; *************** *** 49,54 **** super(d, null); ! this.type = base; ! this.restrictions = new java.util.HashSet(); } --- 117,121 ---- super(d, null); ! this.impl = new BareImpl (base); } *************** *** 71,98 **** super(doc, record); this.record = record; ! this.restrictions = new java.util.HashSet(); ! RecordNode baseRecord = record.field("base").getNode().asRecordNode(); ! this.type = doc.createTypeFromRecord(baseRecord); ! initFromRecord(); ! } ! ! /** ! * Constrict Restriction list from .restrictions field in Record. ! */ ! private void initFromRecord() { ! SequenceNode seq = record.field("restrictions").getNode().asSequenceNode(); ! for (int i = 0; i < seq.size(); ++i) { ! RecordNode rec = seq.item(i).getNode().asRecordNode(); ! Name name = (Name) rec.getField("name"); ! MapNode args = rec.field("args").getNode().asMapNode(); ! try { ! Restriction r = RestrictionImpl.create(restrictionOf(), name, args); ! addRestriction(r); ! } catch (CreationFailure e) { ! // TODO Handle a problematic Restriction record ! System.err.println("Couldn't handle restriction: " + name.string()); ! } ! ! } } --- 138,142 ---- super(doc, record); this.record = record; ! this.impl = new NodeImpl (record); } *************** *** 100,104 **** attachNode(record.bareNode()); this.record = record; ! initFromRecord(); } --- 144,148 ---- attachNode(record.bareNode()); this.record = record; ! this.impl = new NodeImpl (record); } *************** *** 108,112 **** } public final boolean isNodeType() { ! return type.isNodeType(); } --- 152,156 ---- } public final boolean isNodeType() { ! return impl.base().isNodeType(); } *************** *** 152,195 **** // like a TypeFilter. public Object from(boolean b) { ! return type.from(b); } public Object from(char c) { ! return type.from(c); } public Object from(byte b) { ! return type.from(b); } public Object from(short s) { ! return type.from(s); } public Object from(int i) { ! return type.from(i); } public Object from(long l) { ! return type.from(l); } public Object from(float f) { ! return type.from(f); } public Object from(double d) { ! return type.from(d); } public Object fromString(String s) { ! return type.fromString(s); } public Object fromNode(Node nd) { ! return type.fromNode(nd); } protected Object fromObject(Object v) { ! return type.from(v); } // Methods from RestrictionType public Type restrictionOf() { ! return type; } public Enumeration restrictions() { ! return new Restrictions(restrictions.iterator()); } --- 196,239 ---- // like a TypeFilter. public Object from(boolean b) { ! return impl.base().from(b); } public Object from(char c) { ! return impl.base().from(c); } public Object from(byte b) { ! return impl.base().from(b); } public Object from(short s) { ! return impl.base().from(s); } public Object from(int i) { ! return impl.base().from(i); } public Object from(long l) { ! return impl.base().from(l); } public Object from(float f) { ! return impl.base().from(f); } public Object from(double d) { ! return impl.base().from(d); } public Object fromString(String s) { ! return impl.base().fromString(s); } public Object fromNode(Node nd) { ! return impl.base().fromNode(nd); } protected Object fromObject(Object v) { ! return impl.base().from(v); } // Methods from RestrictionType public Type restrictionOf() { ! return impl.base(); } public Enumeration restrictions() { ! return new Restrictions(impl.iterator()); } *************** *** 217,226 **** public boolean accepts(boolean v) { // Check against base ! if (!type.accepts(v)) { return false; } // Check all restrictions ! Iterator i = restrictions.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); --- 261,270 ---- public boolean accepts(boolean v) { // Check against base ! if (!impl.base().accepts(v)) { return false; } // Check all restrictions ! Iterator i = impl.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); *************** *** 235,244 **** public boolean accepts(char v) { // Check against base ! if (!type.accepts(v)) { return false; } // Check all restrictions ! Iterator i = restrictions.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); --- 279,288 ---- public boolean accepts(char v) { // Check against base ! if (!impl.base().accepts(v)) { return false; } // Check all restrictions ! Iterator i = impl.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); *************** *** 253,262 **** public boolean accepts(byte v) { // Check against base ! if (!type.accepts(v)) { return false; } // Check all restrictions ! Iterator i = restrictions.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); --- 297,306 ---- public boolean accepts(byte v) { // Check against base ! if (!impl.base().accepts(v)) { return false; } // Check all restrictions ! Iterator i = impl.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); *************** *** 271,280 **** public boolean accepts(short v) { // Check against base ! if (!type.accepts(v)) { return false; } // Check all restrictions ! Iterator i = restrictions.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); --- 315,324 ---- public boolean accepts(short v) { // Check against base ! if (!impl.base().accepts(v)) { return false; } // Check all restrictions ! Iterator i = impl.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); *************** *** 289,298 **** public boolean accepts(int v) { // Check against base ! if (!type.accepts(v)) { return false; } // Check all restrictions ! Iterator i = restrictions.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); --- 333,342 ---- public boolean accepts(int v) { // Check against base ! if (!impl.base().accepts(v)) { return false; } // Check all restrictions ! Iterator i = impl.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); *************** *** 307,316 **** public boolean accepts(long v) { // Check against base ! if (!type.accepts(v)) { return false; } // Check all restrictions ! Iterator i = restrictions.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); --- 351,360 ---- public boolean accepts(long v) { // Check against base ! if (!impl.base().accepts(v)) { return false; } // Check all restrictions ! Iterator i = impl.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); *************** *** 325,334 **** public boolean accepts(float v) { // Check against base ! if (!type.accepts(v)) { return false; } // Check all restrictions ! Iterator i = restrictions.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); --- 369,378 ---- public boolean accepts(float v) { // Check against base ! if (!impl.base().accepts(v)) { return false; } // Check all restrictions ! Iterator i = impl.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); *************** *** 343,352 **** public boolean accepts(double v) { // Check against base ! if (!type.accepts(v)) { return false; } // Check all restrictions ! Iterator i = restrictions.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); --- 387,396 ---- public boolean accepts(double v) { // Check against base ! if (!impl.base().accepts(v)) { return false; } // Check all restrictions ! Iterator i = impl.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); *************** *** 361,370 **** public boolean acceptsString(String v) { // Check against base ! if (!type.acceptsString(v)) { return false; } // Check all restrictions ! Iterator i = restrictions.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); --- 405,414 ---- public boolean acceptsString(String v) { // Check against base ! if (!impl.base().acceptsString(v)) { return false; } // Check all restrictions ! Iterator i = impl.restrictions().iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); *************** *** 379,388 **** public boolean acceptsNode(Node v) { // Check against base ! if (!type.acceptsNode(v)) { return false; } // Check all restrictions ! Iterator i = restrictions.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); --- 423,432 ---- public boolean acceptsNode(Node v) { // Check against base ! if (!impl.base().acceptsNode(v)) { return false; } // Check all restrictions ! Iterator i = impl.restrictions().iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); *************** *** 397,406 **** public boolean acceptsObject(Object v) { // Check against base ! if (!type.accepts(v)) { return false; } // Check all restrictions ! Iterator i = restrictions.iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); --- 441,450 ---- public boolean acceptsObject(Object v) { // Check against base ! if (!impl.base().accepts(v)) { return false; } // Check all restrictions ! Iterator i = impl.restrictions().iterator(); while (i.hasNext()) { Restriction r = (Restriction) i.next(); *************** *** 457,461 **** public boolean removeRestriction(Restriction r) { ! return type.restrictions.remove(r); } --- 501,505 ---- public boolean removeRestriction(Restriction r) { ! return type.impl.removeRestriction(r); } *************** *** 471,481 **** private boolean addRestriction(Restriction r) { ! if (r == null || !r.canRestrict(type) || restrictions.contains(r)) { return false; } ! if (!restrictions.contains(r)) { ! restrictions.add(r); ! } ! return true; } } --- 515,522 ---- private boolean addRestriction(Restriction r) { ! if (r == null || !r.canRestrict(impl.base())) { return false; } ! return impl.addRestriction(r); } } |
From: Lee I. <le...@us...> - 2004-04-20 18:02:39
|
Update of /cvsroot/nodal/nodal/j-src/storage/memory In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17970/storage/memory Modified Files: memOperator.java memSetContent.java memContent.java RecordLayout.java Added Files: memOpAdd.java Log Message: Extend SetContent.Editor with add() method. Add AddOp support. Implement and use add() method. Index: RecordLayout.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/storage/memory/RecordLayout.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** RecordLayout.java 19 Mar 2004 00:24:44 -0000 1.10 --- RecordLayout.java 20 Apr 2004 18:01:02 -0000 1.11 *************** *** 11,14 **** --- 11,15 ---- import java.util.HashMap; import java.util.Iterator; + import java.util.Set; import org.nodal.type.RecordType; *************** *** 77,86 **** } public String toString() { ! return "RecordLayout@" ! + Integer.toHexString(hashCode()) ! + "[" ! + size() ! + "]"; } } --- 78,97 ---- } + private String descr; + public String toString() { ! if (descr == null) { ! StringBuffer b = new StringBuffer("["); ! Set names = idxMap.keySet(); ! for (Iterator i = names.iterator(); i.hasNext(); ) { ! Name nm = (Name) i.next(); ! int idx = lookup(nm); ! b.append(idx); b.append(":"); b.append(nm.string()); ! if (i.hasNext()) { b.append(", "); } ! } ! b.append("]"); ! descr = b.toString(); ! } ! return descr; } } Index: memContent.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/storage/memory/memContent.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** memContent.java 19 Apr 2004 23:59:18 -0000 1.29 --- memContent.java 20 Apr 2004 18:00:59 -0000 1.30 *************** *** 35,41 **** /** ! * The base class for all of the Content classes in this package. The create ! * and ingest methods act as static abstract constructors for these classes, ! * using the NodeType to determine which class to construct. */ public abstract class memContent implements MemContentI { --- 35,41 ---- /** ! * The base class for all of the Content classes in this package. The create and ! * ingest methods act as static abstract constructors for these classes, using ! * the NodeType to determine which class to construct. */ public abstract class memContent implements MemContentI { *************** *** 54,58 **** * Create a new instance of the given type. * ! * @param t the NodeType of the object that will be created * @return a new memContent object with the given type */ --- 54,59 ---- * Create a new instance of the given type. * ! * @param t ! * the NodeType of the object that will be created * @return a new memContent object with the given type */ *************** *** 96,100 **** * applyTo method of the memOperator. * ! * @param op the memOperator to apply this content to */ public void modify(memOperator op, NodeContent c) throws InvalidOperator, --- 97,102 ---- * applyTo method of the memOperator. * ! * @param op ! * the memOperator to apply this content to */ public void modify(memOperator op, NodeContent c) throws InvalidOperator, *************** *** 110,114 **** // Methods valid only for MapContent ! void opRemoveKey(Object k, NodeContent c) throws InvalidOperator, ConstraintFailure { throw new InvalidOperator("invalid OpRemoveKey on " + this); --- 112,116 ---- // Methods valid only for MapContent ! boolean opRemoveKey(Object k, NodeContent c) throws InvalidOperator, ConstraintFailure { throw new InvalidOperator("invalid OpRemoveKey on " + this); *************** *** 147,150 **** --- 149,157 ---- } + boolean opAdd(Object v, NodeContent c) throws InvalidOperator, + ConstraintFailure { + throw new InvalidOperator("invalid OpAdd on " + this); + } + public Operator invert(Operator op, NodeContent c) throws InvalidOperator, ConstraintFailure { *************** *** 196,203 **** } /** * If a NodeContent record already exists (in canonical cache), return it. * ! * @param n a Node reference * @return a NodeContent record if one has already been created */ --- 203,216 ---- } + memOperator invertAdd(Object v, NodeContent c) throws InvalidOperator, + ConstraintFailure { + throw new InvalidOperator("invalid OpAdd on " + this); + } + /** * If a NodeContent record already exists (in canonical cache), return it. * ! * @param n ! * a Node reference * @return a NodeContent record if one has already been created */ *************** *** 211,217 **** * recoverable from {@link #findNodeContent(Node)}. * ! * @param c a NodeContent reference ! * @param canonical if this is the canonical reference, then store in the ! * special index as well. */ protected void rememberNodeContent(NodeContent c, boolean canonical) { --- 224,232 ---- * recoverable from {@link #findNodeContent(Node)}. * ! * @param c ! * a NodeContent reference ! * @param canonical ! * if this is the canonical reference, then store in the special ! * index as well. */ protected void rememberNodeContent(NodeContent c, boolean canonical) { *************** *** 227,233 **** * Capability, and RepoServices. * ! * @param n a Node associated with this memContent ! * @param cap a Capability restricting access to operations ! * @param s the RepoServices needed to manage Txns and create Nodes * @return a new NodeContent object */ --- 242,251 ---- * Capability, and RepoServices. * ! * @param n ! * a Node associated with this memContent ! * @param cap ! * a Capability restricting access to operations ! * @param s ! * the RepoServices needed to manage Txns and create Nodes * @return a new NodeContent object */ *************** *** 245,252 **** * Capability. * ! * @param n the Node that this content is associated with ! * @param services a set of RepoServices for handling Node creation and Txn ! * management ! * @param cap a Capability restricting access (or null for default). * @return a NodeContent object or null if not allowed */ --- 263,273 ---- * Capability. * ! * @param n ! * the Node that this content is associated with ! * @param services ! * a set of RepoServices for handling Node creation and Txn ! * management ! * @param cap ! * a Capability restricting access (or null for default). * @return a NodeContent object or null if not allowed */ *************** *** 274,279 **** * Ensure that any Node references are within the current Repository. * ! * @param node the Node being referenced ! * @param c the NodeContent context for this reference * @return a "seated" reference to the given Node */ --- 295,302 ---- * Ensure that any Node references are within the current Repository. * ! * @param node ! * the Node being referenced ! * @param c ! * the NodeContent context for this reference * @return a "seated" reference to the given Node */ *************** *** 283,291 **** // Only use direct Node references. node = node.bareNode(); - // If we are not in the same Repository, then create an AnchorNode // reference to the other Repository. if (node.repository() != c.repository()) { ! node = c.createAnchor(node.path()); System.out.println("Storing " + node + " in " + c.repository()); } --- 306,313 ---- // Only use direct Node references. node = node.bareNode(); // If we are not in the same Repository, then create an AnchorNode // reference to the other Repository. if (node.repository() != c.repository()) { ! node = c.createAnchor(node.path()); System.out.println("Storing " + node + " in " + c.repository()); } *************** *** 295,306 **** /** ! * Called whenever a Node value is assigned anywhere in memContent. This ! * takes care of accessing the {@link org.nodal.model.Node#bareNode()}, ! * ensuring that the reference stored is in the same repository, and then ! * that all indices are properly updated. * ! * @param c the NodeContent context for this assignment ! * @param property the property being assigned ! * @param node the Node being assigned as the value for property * @return the Node pointer ultimately assigned */ --- 317,331 ---- /** ! * Called whenever a Node value is assigned anywhere in memContent. This takes ! * care of accessing the {@link org.nodal.model.Node#bareNode()}, ensuring ! * that the reference stored is in the same repository, and then that all ! * indices are properly updated. * ! * @param c ! * the NodeContent context for this assignment ! * @param property ! * the property being assigned ! * @param node ! * the Node being assigned as the value for property * @return the Node pointer ultimately assigned */ Index: memSetContent.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/storage/memory/memSetContent.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** memSetContent.java 19 Apr 2004 23:59:18 -0000 1.1 --- memSetContent.java 20 Apr 2004 18:00:49 -0000 1.2 *************** *** 7,11 **** * */ - package storage.memory; --- 7,10 ---- *************** *** 34,46 **** import org.nodal.util.PropertyTypeMismatch; import org.nodal.util.SetterUtil; import storage.framework.RepoServices; /** ! * The canonical implementation of a SetContent object in memory. ! * This implementation also contains subclasses for implementing Set ! * and SetEditor given a Node that is using this class as its ! * memContent. */ - public final class memSetContent extends memContent { protected final SetType setType; --- 33,44 ---- import org.nodal.util.PropertyTypeMismatch; import org.nodal.util.SetterUtil; + import org.nodal.util.TypeConstraintFailure; import storage.framework.RepoServices; /** ! * The canonical implementation of a SetContent object in memory. This ! * implementation also contains subclasses for implementing Set and SetEditor ! * given a Node that is using this class as its memContent. */ public final class memSetContent extends memContent { protected final SetType setType; *************** *** 80,87 **** } ! protected NodeContent createNodeContent( ! Node n, ! Capability cap, ! RepoServices s) { return new MyNodeContent(n, cap, s); } --- 78,82 ---- } ! protected NodeContent createNodeContent(Node n, Capability cap, RepoServices s) { return new MyNodeContent(n, cap, s); } *************** *** 104,111 **** // Implementation of Content methods ! public Set asSet () { return Collections.unmodifiableSet(content); } ! public NodeType type() { return setType; --- 99,106 ---- // Implementation of Content methods ! public Set asSet() { return Collections.unmodifiableSet(content); } ! public NodeType type() { return setType; *************** *** 122,126 **** /** * Return true if this Set contains the object obj. ! * @param obj an Object * @return true if this Set contains obj */ --- 117,123 ---- /** * Return true if this Set contains the object obj. ! * ! * @param obj ! * an Object * @return true if this Set contains obj */ *************** *** 128,135 **** return content.contains(obj); } ! /** * Notify all interested parties when we remove a key. ! * @param key the key being removed from this Map */ private void notifyRemoveKey(Object key) { --- 125,134 ---- return content.contains(obj); } ! /** * Notify all interested parties when we remove a key. ! * ! * @param key ! * the key being removed from this Map */ private void notifyRemoveKey(Object key) { *************** *** 140,144 **** c.notifyRemoveKey(key); } - // Notify any interested Getters KeyGetter keyGetter = (KeyGetter) getters.get(key); --- 139,142 ---- *************** *** 150,155 **** /** * Notify all interested parties when we assign a value to a key. ! * @param key the key being set ! * @param val the value assigned to this key */ private void notifySetValue(Object key, Object val) { --- 148,156 ---- /** * Notify all interested parties when we assign a value to a key. ! * ! * @param key ! * the key being set ! * @param val ! * the value assigned to this key */ private void notifySetValue(Object key, Object val) { *************** *** 160,164 **** c.notifySetValue(key, val); } - // Notify any interested values KeyGetter keyGetter = (KeyGetter) getters.get(key); --- 161,164 ---- *************** *** 172,176 **** */ protected GetterUtil valueGetter(Object key, NodeContent c) ! throws PropertyTypeMismatch { KeyGetter util = (KeyGetter) getters.get(key); if (util == null) { --- 172,176 ---- */ protected GetterUtil valueGetter(Object key, NodeContent c) ! throws PropertyTypeMismatch { KeyGetter util = (KeyGetter) getters.get(key); if (util == null) { *************** *** 190,193 **** --- 190,194 ---- protected Object key; protected NodeContent node; + KeyGetter(Object key, NodeContent node) { super(setType.itemType()); *************** *** 195,208 **** --- 196,213 ---- this.node = node; } + public Object get() { // Every single value access goes through here. return (content.contains(key) ? key : null); } + void notifySetValue(Object key, Object value) { notifySetValue(node, key, value); } + void notifyRemoveKey(Object key) { notifyRemoveKey(node, key); } + public boolean valueEquals(Object v) throws PropertyConstraintFailure { if (isNodeValue && v != null) { *************** *** 218,223 **** }; ! public Getter value(Object key, NodeContent node) ! throws PropertyTypeMismatch { return valueGetter(key, node); } --- 223,227 ---- }; ! public Getter value(Object key, NodeContent node) throws PropertyTypeMismatch { return valueGetter(key, node); } *************** *** 236,282 **** } ! void opRemoveKey(Object key, NodeContent.Editor c) ! throws PropertyConstraintFailure { ! key = checkItemType(key); // Notify interested parties notifyRemoveKey(key); - // Actually remove the key ! content.remove(key); } void opSetValue(Object key, Object val, NodeContent.Editor c) ! throws ConstraintFailure { // Check types and convert if necessary key = checkItemType(key); ! if (val == null) { opRemoveKey(key, c); } else { ! if (isNodeValue) { ! key = assignNode(c, key, (Node) key); ! } ! // Notify any interested values ! notifySetValue(key, key); ! // Every single set goes through here. ! content.add(key); } } ! memOperator invertRemoveKey(Object key, NodeContent c) ! throws PropertyConstraintFailure { Object value = getValue(key, c); if (value == null) { return null; } ! return memOperator.createOpSetValue(key, value); } ! private final class MyNodeEditor ! extends BareContent.Editor ! implements SetNode.Editor { protected MyNodeContent content; --- 240,304 ---- } ! Object checkValue(Object val) throws TypeConstraintFailure { ! Type keyType = setType.itemType(); ! if (!keyType.accepts(val)) { ! throw new TypeConstraintFailure(val, keyType, "invalid item"); ! } ! return keyType.from(val); ! } + boolean opRemoveKey(Object key, NodeContent.Editor c) { + key = checkItemType(key); // Notify interested parties notifyRemoveKey(key); // Actually remove the key ! return content.remove(key); } void opSetValue(Object key, Object val, NodeContent.Editor c) ! throws ConstraintFailure { // Check types and convert if necessary key = checkItemType(key); ! val = checkValue(val); if (val == null) { opRemoveKey(key, c); + } else if (key == val) { + opAdd(key, c); } else { ! throw new ConstraintFailure("key/value different in Set: " + key + ", " ! + val); ! } ! } ! boolean opAdd(Object val, NodeContent.Editor c) throws ConstraintFailure { ! val = checkValue(val); ! if (isNodeValue) { ! val = assignNode(c, val, (Node) val); ! } ! // Notify any interested values ! notifySetValue(val, val); ! // Every single set goes through here. ! return content.add(val); ! } ! memOperator invertAdd(Object key, NodeContent c) { ! Object value = getValue(key, c); ! if (value != null) { ! return null; } + return memOperator.createOpRemoveKey(value); } ! memOperator invertRemoveKey(Object key, NodeContent c) { Object value = getValue(key, c); if (value == null) { return null; } ! return memOperator.createOpAdd(value); } ! private final class MyNodeEditor extends BareContent.Editor ! implements ! SetNode.Editor { protected MyNodeContent content; *************** *** 291,301 **** } ! public Set asSet () { return content.asSet(); } ! public boolean contains (Object obj) { return content.contains(obj); } ! // Methods from BareNodeEditor public Setter setValue(Object key) throws PropertyConstraintFailure { --- 313,324 ---- } ! public Set asSet() { return content.asSet(); } ! ! public boolean contains(Object obj) { return content.contains(obj); } ! // Methods from BareNodeEditor public Setter setValue(Object key) throws PropertyConstraintFailure { *************** *** 308,334 **** private Object key; private NodeManager nodeMgr; ! KeySetter(Object k, NodeManager nodeMgr) { ! key = k; this.nodeMgr = nodeMgr; } public Object set(Object val) throws ConstraintFailure { val = memSetContent.this.checkItemType(val); ! TxnOp op = null; ! try { ! // Create a transaction record of this operation ! if (nodeMgr != null) { ! op = ! nodeMgr.currentTxn().addOp( ! nodeMgr.node(), ! memOperator.createOpSetValue(key, val)); ! } ! // Perform the operation ! memSetContent.this.opSetValue(key, val, MyNodeEditor.this); ! } catch (ConstraintFailure f) { ! // Retract op from record if unsuccessful ! if (nodeMgr != null) { ! nodeMgr.currentTxn().retractOp(op); ! } ! throw f; } return val; --- 331,349 ---- private Object key; private NodeManager nodeMgr; ! ! KeySetter(Object key, NodeManager nodeMgr) { ! this.key = memSetContent.this.checkItemType(key); this.nodeMgr = nodeMgr; } + public Object set(Object val) throws ConstraintFailure { val = memSetContent.this.checkItemType(val); ! if (val == null) { ! remove(val); ! } else if (key == val) { ! add(val); ! } else { ! throw new ConstraintFailure("key/value different in Set: " + key ! + ", " + val); } return val; *************** *** 336,348 **** } ! public Object remove (Object key) throws PropertyConstraintFailure { ! Setter set = setValue(key); ! Object v = set.get(); try { ! set.set(null); } catch (ConstraintFailure f) { ! throw new Error("removeKey cannot throw ConstraintFailure " + f); } ! return v; } --- 351,382 ---- } ! public boolean add(Object val) throws ConstraintFailure { ! val = memSetContent.this.checkItemType(val); ! TxnOp op = null; try { ! // Create a transaction record of this operation ! if (nodeMgr != null) { ! op = nodeMgr.currentTxn().addOp(nodeMgr.node(), ! memOperator.createOpAdd(val)); ! } ! // Perform the operation ! return memSetContent.this.opAdd(val, MyNodeEditor.this); } catch (ConstraintFailure f) { ! // Retract op from record if unsuccessful ! if (nodeMgr != null) { ! nodeMgr.currentTxn().retractOp(op); ! } ! throw f; } ! } ! ! public boolean remove(Object val) { ! val = memSetContent.this.checkItemType(val); ! if (nodeMgr != null) { ! nodeMgr.currentTxn().addOp(nodeMgr.node(), ! memOperator.createOpRemoveKey(val)); ! } ! // Perform the operation ! return memSetContent.this.opRemoveKey(val, MyNodeEditor.this); } *************** *** 355,358 **** } } ! ! } --- 389,391 ---- } } ! } \ No newline at end of file --- NEW FILE: memOpAdd.java --- /* * * Distributed under the Apache Software License, Version 1.1 * (see below, or the file LICENSE for terms and conditions) * * Copyright (c) 2002 University of British Columbia. All rights reserved. * */ package storage.memory; import org.nodal.model.InvalidOperator; import org.nodal.model.NodeContent; import org.nodal.model.OpAdd; import org.nodal.util.ConstraintFailure; final class memOpAdd extends memOperator implements OpAdd { private Object val; protected memOpAdd (Object k) { val = k; } public Object value () { return val; } void applyTo (memContent content, NodeContent c) throws InvalidOperator, ConstraintFailure { content.opAdd (val, c); } memOperator invertOn (memContent content, NodeContent c) throws InvalidOperator, ConstraintFailure { return content.invertAdd (val, c); } }; Index: memOperator.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/storage/memory/memOperator.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** memOperator.java 26 Mar 2004 18:23:30 -0000 1.15 --- memOperator.java 20 Apr 2004 18:00:46 -0000 1.16 *************** *** 119,122 **** --- 119,130 ---- } + /** + * Create an OpAdd instance. + */ + public static + memOperator createOpAdd (Object v) { + return new memOpAdd (v); + } + abstract void applyTo (memContent content, NodeContent c) throws InvalidOperator, ConstraintFailure; |
From: Lee I. <le...@us...> - 2004-04-20 18:02:11
|
Update of /cvsroot/nodal/nodal/j-src/storage/framework In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17970/storage/framework Modified Files: ProxyNode.java Log Message: Extend SetContent.Editor with add() method. Add AddOp support. Implement and use add() method. Index: ProxyNode.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/storage/framework/ProxyNode.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ProxyNode.java 19 Apr 2004 23:59:20 -0000 1.11 --- ProxyNode.java 20 Apr 2004 18:01:25 -0000 1.12 *************** *** 398,404 **** return this; } ! public Object remove(Object key) throws PropertyConstraintFailure { return editor.remove(key); } public String toString() { return "SetEditor[" + path() + "]"; --- 398,407 ---- return this; } ! public boolean remove(Object key) { return editor.remove(key); } + public boolean add (Object val) throws ConstraintFailure { + return editor.add(val); + } public String toString() { return "SetEditor[" + path() + "]"; |
From: Lee I. <le...@us...> - 2004-04-20 18:02:11
|
Update of /cvsroot/nodal/nodal/j-src/org/nodal/format/text/x_nodal_schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17970/org/nodal/format/text/x_nodal_schema Modified Files: Parser.java Log Message: Extend SetContent.Editor with add() method. Add AddOp support. Implement and use add() method. Index: Parser.java =================================================================== RCS file: /cvsroot/nodal/nodal/j-src/org/nodal/format/text/x_nodal_schema/Parser.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Parser.java 19 Apr 2004 23:59:19 -0000 1.4 --- Parser.java 20 Apr 2004 18:01:08 -0000 1.5 *************** *** 91,95 **** reader.setEntityResolver(handler); handler.setInputSource(src); ! System.out.println("text/x-nodal-schema parse " + src.getSystemId()); reader.parse(src); Node root = handler.root(); --- 91,95 ---- reader.setEntityResolver(handler); handler.setInputSource(src); ! //System.out.println("text/x-nodal-schema parse " + src.getSystemId()); reader.parse(src); Node root = handler.root(); *************** *** 918,922 **** try { // Add this type to the Union ! types.setValue(t).set(t); } catch (ConstraintFailure c) { error(new SAXParseException("Violated baseTypes.nls#UnionType.types", --- 918,922 ---- try { // Add this type to the Union ! types.add(t); } catch (ConstraintFailure c) { error(new SAXParseException("Violated baseTypes.nls#UnionType.types", *************** *** 940,944 **** try { // Add this type to list and clear string ! types.setValue(n).set(n); typeNames[i] = null; } catch (ConstraintFailure c) { --- 940,944 ---- try { // Add this type to list and clear string ! types.add(n); typeNames[i] = null; } catch (ConstraintFailure c) { |