Class BinaryExporter
- All Implemented Interfaces:
Comparator<Object>,ContentHandler,ProtoHandler,RouteHandler,ScriptHandler,StringContentHandler
Format:
table describing compression method per fieldType
# of table entries(8)
fieldType(8), compression method(8)
table describing compression method for individual nodes
# of table entries(16)
nodeNumber(16), compression method(8)
scene graph structure
PROTO definitions
Nodes
NodeNumber(8 or 16)
DEF #(16) or 0(8) for no DEF name. 1st bit(0 = no def)
Fields
fieldNumber(8) 0=end of node (Internal Xj3D index + 1)
field encoding by type
Compression method numbers:
Separate set of assigned numbers for fieldType and node
Consortium assigned numbers are 0-127, the rest are locally definable
FieldType Compression methods implemented
All field types 0 Straight IEEE Encoding
MFInt32 1 Squash Range
MFFloat 1 Convert to Int, squash range
Goals:
Enable experimentation with compression methods.
Avoid having experimenters change this file
Enable app writers to choose different compression methods.
Design:
Have a properties file saying what class implements the compression method
fieldType, method, class
nodeNumber, method, class
Each compressor class must implement either the FieldCompressor or NodeCompressor interface
----------------------------------
Proposed New Structure
Header
Binary spec version
Profile
length(8)
data
Component
number of components(8)
length(8)
data
Number of Bits used for Node Number(max 16)
Number of Bits used for DEF lookup(max 32)
Number of Bits used for field name
Node Dictionary Table
num entries(32)
values(UTF8)
DEF Dictionary Table
num entries(32)
values(UTF8)
Field Table
num entries(32) -- Number of field table entries
num fields for this node
values(UTF8)
Table describing compression method per fieldType
# of table entries(8)
fieldType(8),
number of methods(8) Cannot exceed 8 entries
compression method(8) -- Indexed into X3D Binary Spec
Table describing compression method for individual nodes
# of table entries(16)
nodeNumber(16), compression method(8)
Proto Definitions, assign NodeNum to each Prototype. Retain nested structures.
Structure TBD
Import/Export Statements
Structure TBD
Main File
Sequence of OP Codes and Data
OpCode(2 bits, 00 = Node, 01=USE, 10 = Comment, 11 = ROUTE
Node
NodeNum(variable)
Def lookup(variable) --> Byte Alignment(OP+NodeNum+DEF divisible by 8)
Field Name Id(variable) --> Look for end of fields marker
Field Method used(3 bits) --> Byte Alignment(FieldNameID+FieldMethod)
Field Method Params --> Byte Aligned
Field Data --> Byte Aligned
USE
Def lookup(variable) --> Byte Aligned(OP+DEF)
Comment
length(14) --> Byte Aligned(OP+length)
data
ROUTE
fromNode(Def Lookup, variable)
fromField(FieldNameID,variable)
toNode(Def Lookup, variable)
toField(FieldNameID, variable) --> Byte Alignment(OP+fromNode+fromField+toNode+toField)
NodeNum 0 is reserved as end of fields marker.
NodeNum 1 is reserved for Script nodes. They will have their own format.
FieldNum 0 is reserved for end of fields marker
- Version:
- $Revision: 1.18 $
- Author:
- Alan Hudson
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map<String, ExternalPrototypeDecl> The mapping of externproto names (key) to node instances (value)static final intThe number of Bits used for the FieldMethodprotected static VRMLFieldReaderField Parserstatic final intstatic final intstatic final intThe number of Bits used for the OPCodestatic final intstatic final intstatic final intstatic final intprotected Map<String, PrototypeDecl> The mapping of proto names (key) to node instances (value)Fields inherited from class org.web3d.vrml.export.Exporter
errorReporter, lastErrorCode, majorVersion, minorVersion -
Constructor Summary
ConstructorsConstructorDescriptionBinaryExporter(OutputStream os, int major, int minor, StatisticsCollector stats) Create a new exporter for binary file formats. -
Method Summary
Modifier and TypeMethodDescriptionintvoidcomponentDecl(String componentName) A component declaration has been found in the code.voidDeclaration of the end of the document.voidNotification of the end of an EXTERNPROTO declaration.voidendField()Notification of the end of a field declaration.voidendNode()Notification of the end of a node declaration.voidNotification of the end of an ordinary proto body.voidNotification of the end of an ordinary proto declaration statement.voidNotification of the end of a script declaration.booleanvoidexportDecl(String defName, String exported) An EXPORT declaration has been found in the document.voidexternProtoURI(String[] values) Notification of the URI list for an EXTERNPROTO.voidfieldValue(String value) The value of a normal field.voidfieldValue(String[] values) The value of an MFField where the underlying parser knows about how the values are broken up.voidimportDecl(String inline, String exported, String imported) An IMPORT declaration has been found in the document.voidA META declaration has been found in the code.voidvoidprofileDecl(String profileName) A profile declaration has been found in the code.voidprotoFieldDecl(int access, String type, String name, Object value) Notification of a proto's field declaration.voidprotoIsDecl(String fieldName) Notification of a field value uses an IS statement.voidregisterFieldCompressor(int fieldType, int method, FieldCompressor compressor) Register a class for a field/compression method.voidregisterNodeCompressor(int nodeNumber, int method, NodeCompressor compressor) Register a class for a node/compression method.voidNotification of a ROUTE declaration in the file.voidscriptFieldDecl(int access, String type, String name, Object value) Notification of a script's field declaration.voidSet the document locator that can be used by the implementing code to find out information about the current line information.voidDeclaration of the start of the document.voidstartExternProtoDecl(String name) Notification of the start of an EXTERNPROTO declaration of the given name.voidstartField(String name) Notification of a field declaration.voidNotification of the start of a node.voidNotification of the start of an ordinary proto body.voidstartProtoDecl(String name) Notification of the start of an ordinary (inline) proto declaration.voidNotification of the start of a script declaration.voidThe field value is a USE for the given node name.Methods inherited from class org.web3d.vrml.export.Exporter
getLastErrorCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
OP_BITS
public static final int OP_BITSThe number of Bits used for the OPCode- See Also:
-
FIELD_METHOD_BITS
public static final int FIELD_METHOD_BITSThe number of Bits used for the FieldMethod- See Also:
-
OP_NODE
public static final int OP_NODE- See Also:
-
OP_USE
public static final int OP_USE- See Also:
-
OP_COMMENT
public static final int OP_COMMENT- See Also:
-
OP_ROUTE
public static final int OP_ROUTE- See Also:
-
NODEOP_ENDFIELDS
public static final int NODEOP_ENDFIELDS- See Also:
-
NODEOP_DYNAMIC
public static final int NODEOP_DYNAMIC- See Also:
-
fieldParser
Field Parser -
protoMap
The mapping of proto names (key) to node instances (value) -
externProtoMap
The mapping of externproto names (key) to node instances (value)
-
-
Constructor Details
-
BinaryExporter
Create a new exporter for binary file formats.- Parameters:
os-major- The major version number of this sceneminor- The minor version number of this scenestats- The first pass stats.
-
-
Method Details
-
registerFieldCompressor
Register a class for a field/compression method.- Parameters:
fieldType- For what field type, defined in FieldConstants.method- For what compression method.compressor- What class implements the FieldCompressor interface.
-
registerNodeCompressor
Register a class for a node/compression method.- Parameters:
nodeNumber- For what field type, defined in FieldConstants.method- For what compression method.compressor- What class implements the FieldCompressor interface.
-
setDocumentLocator
Set the document locator that can be used by the implementing code to find out information about the current line information. This method is called by the parser to your code to give you a locator to work with. If this has not been set by the timestartDocument()has been called, you can assume that you will not have one available.- Specified by:
setDocumentLocatorin interfaceContentHandler- Parameters:
loc- The locator instance to use
-
startDocument
public void startDocument(String uri, String url, String encoding, String type, String version, String comment) throws SAVException, VRMLException Declaration of the start of the document. The parameters are all of the values that are declared on the header line of the file after the#start. The type string contains the representation of the first few characters of the file after the #. This allows us to work out if it is VRML97 or the later X3D spec.Version numbers change from VRML97 to X3D and aren't logical. In the first, it is
#VRML V2.0and the second is#X3D V1.0even though this second header represents a later spec.- Specified by:
startDocumentin interfaceContentHandler- Parameters:
uri- The URI of the file.url- The base URL of the file for resolving relative URIs contained in the fileencoding- The encoding of this document - utf8 or binarytype- The bytes of the first part of the file headerversion- The VRML version of this documentcomment- Any trailing text on this line. If there is none, this is null.- Throws:
SAVException- This call is taken at the wrong time in the structure of the documentVRMLException- The content provided is invalid for this part of the document or can't be parsed
-
profileDecl
A profile declaration has been found in the code. IAW the X3D specification, this method will only ever be called once in the lifetime of the parser for this document. The name is the name of the profile for the document to use.- Specified by:
profileDeclin interfaceContentHandler- Parameters:
profileName- The name of the profile to use- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
componentDecl
A component declaration has been found in the code. There may be zero or more component declarations in the file, appearing just after the profile declaration. The textual information after the COMPONENT keyword is left unparsed and presented through this call. It is up to the user application to parse the component information.- Specified by:
componentDeclin interfaceContentHandler- Parameters:
componentName- The name of the component to use- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
metaDecl
A META declaration has been found in the code. There may be zero or more meta declarations in the file, appearing just after the component declaration. Each meta declaration has a key and value strings. No information is to be implied from this. It is for extra data only.- Specified by:
metaDeclin interfaceContentHandler- Parameters:
key- The value of the key stringvalue- The value of the value string- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
importDecl
public void importDecl(String inline, String exported, String imported) throws SAVException, VRMLException An IMPORT declaration has been found in the document. All three parameters will always be provided, regardless of whether the AS keyword has been used or not. The parser implementation will automatically set the local import name as needed.- Specified by:
importDeclin interfaceContentHandler- Parameters:
inline- The name of the inline DEF nodesexported- The exported name from the inlined fileimported- The local name to use for the exported name- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
exportDecl
An EXPORT declaration has been found in the document. Both paramters will always be provided regardless of whether the AS keyword has been used. The parser implementation will automatically set the exported name as needed.- Specified by:
exportDeclin interfaceContentHandler- Parameters:
defName- The DEF name of the nodes to be exportedexported- The name to be exported as- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
endDocument
Declaration of the end of the document. There will be no further parsing and hence events after this.- Specified by:
endDocumentin interfaceContentHandler- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
startNode
Notification of the start of a node. This is the opening statement of a node and it's DEF name. USE declarations are handled in a separate method.- Specified by:
startNodein interfaceContentHandler- Parameters:
name- The name of the node that we are about to parsedefName- The string associated with the DEF name. Null if not given for this node.- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
endNode
Notification of the end of a node declaration.- Specified by:
endNodein interfaceContentHandler- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
startField
Notification of a field declaration. This notification is only called if it is a standard node. If the node is a script or PROTO declaration then theScriptHandlerorProtoHandlermethods are used.- Specified by:
startFieldin interfaceContentHandler- Parameters:
name- The name of the field declared- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
fieldValue
The value of a normal field. This is a string that represents the entire value of the field. MFStrings will have to be parsed. This is a terminating call for startField as well. The next call will either be anotherstartField()orendNode().If this field is an SFNode with a USE declaration you will have the
useDecl(String)method called rather than this method. If the SFNode is empty the value returned here will be "NULL".There are times where we have an MFField that is declared in the file to be empty. To signify this case, this method will be called with a parameter value of null. A lot of the time this is because we can't really determine if the incoming node is an MFNode or not.
- Specified by:
fieldValuein interfaceStringContentHandler- Parameters:
value- The value of this field- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
fieldValue
The value of an MFField where the underlying parser knows about how the values are broken up. The parser is not required to support this callback, but implementors of this interface should understand it. The most likely time we will have this method called is for MFString or URL lists. If called, it is guaranteed to split the strings along the SF node type boundaries.- Specified by:
fieldValuein interfaceStringContentHandler- Parameters:
values- The list of string representing the values- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
useDecl
The field value is a USE for the given node name. This is a terminating call for startField as well. The next call will either be anotherstartField()orendNode().- Specified by:
useDeclin interfaceContentHandler- Parameters:
defName- The name of the DEF string to use- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
endField
Notification of the end of a field declaration. This is called only at the end of an MFNode declaration. All other fields are terminated by eitheruseDecl(String)orfieldValue(String). This will only ever be called if there have been nodes declared. If no nodes have been declared (ie "[]") then you will get afieldValue(). call with the parameter value of null.- Specified by:
endFieldin interfaceContentHandler- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
routeDecl
public void routeDecl(String srcNode, String srcField, String destNode, String destField) throws SAVException, VRMLException Notification of a ROUTE declaration in the file. The context of this route should be assumed from the surrounding calls to start and end of proto and node bodies.- Specified by:
routeDeclin interfaceRouteHandler- Parameters:
srcNode- The name of the DEF of the source nodesrcField- The name of the field to route values fromdestNode- The name of the DEF of the destination nodedestField- The name of the field to route values to- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException
-
startScriptDecl
Notification of the start of a script declaration. All calls between now and the correspondingendScriptDecl()call belong to this script node. This method will be called after the ContentHandlerstartNode()method call. All DEF information is contained in that method call and this just signifies the start of script processing so that we know to treat the field parsing callbacks a little differently.- Specified by:
startScriptDeclin interfaceScriptHandler- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
endScriptDecl
Notification of the end of a script declaration. This is guaranteed to be called before the ContentHandlerendNode()callback.- Specified by:
endScriptDeclin interfaceScriptHandler- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
scriptFieldDecl
public void scriptFieldDecl(int access, String type, String name, Object value) throws SAVException, VRMLException Notification of a script's field declaration. This is used for all fields excepturl,mustEvaluateanddirectOutputfields. These fields use the normal field callbacks ofContentHandler.If the current parsing is in a proto and the field "value" is defined with an IS statement then the value returned here is null. There will be a subsequent call to the ProtoHandlers
protoIsDecl()method with the name of the field included.- Specified by:
scriptFieldDeclin interfaceScriptHandler- Parameters:
access- The access type (eg exposedField, field etc)type- The field type (eg SFInt32, MFVec3d etc)name- The name of the fieldvalue- The default value of the field as either String or String[]. Null if not allowed.- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
startProtoDecl
Notification of the start of an ordinary (inline) proto declaration. The proto has the given node name.- Specified by:
startProtoDeclin interfaceProtoHandler- Parameters:
name- The name of the proto- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
endProtoDecl
Notification of the end of an ordinary proto declaration statement. This is called just after the closing bracket of the declaration and before the opening of the body statement. If the next thing called is not astartProtoBody()Then that method should toss an exception.- Specified by:
endProtoDeclin interfaceProtoHandler- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
protoFieldDecl
public void protoFieldDecl(int access, String type, String name, Object value) throws SAVException, VRMLException Notification of a proto's field declaration. This is used for both external and ordinary protos. Externprotos don't allow the declaration of a value for the field. In this case, the parameter value will be null.- Specified by:
protoFieldDeclin interfaceProtoHandler- Parameters:
access- The access type (eg exposedField, field etc)type- The field type (eg SFInt32, MFVec3d etc)name- The name of the fieldvalue- The default value of the field as either String or String[]. Null if not allowed.- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
protoIsDecl
Notification of a field value uses an IS statement.- Specified by:
protoIsDeclin interfaceProtoHandler- Parameters:
fieldName- The name of the field that is being IS'd- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
startProtoBody
Notification of the start of an ordinary proto body. All nodes contained between here and the correspondingendProtoBody()statement form the body and not the normal scene graph information.- Specified by:
startProtoBodyin interfaceProtoHandler- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
endProtoBody
Notification of the end of an ordinary proto body. Parsing now returns to ordinary node declarations.- Specified by:
endProtoBodyin interfaceProtoHandler- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
startExternProtoDecl
Notification of the start of an EXTERNPROTO declaration of the given name. Between here and the matchingendExternProtoDecl()call you should only receiveprotoFieldDecl(int, java.lang.String, java.lang.String, java.lang.Object)calls.- Specified by:
startExternProtoDeclin interfaceProtoHandler- Parameters:
name- The node name of the extern proto- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
endExternProtoDecl
Notification of the end of an EXTERNPROTO declaration. This is called just after the closing bracket of the declaration and before the opening of the body statement. If the next thing called is not aexternProtoURI(java.lang.String[])Then that method should toss an exception.- Specified by:
endExternProtoDeclin interfaceProtoHandler- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
externProtoURI
Notification of the URI list for an EXTERNPROTO. This is a complete list as an array of URI strings. The calling application is required to interpret the incoming string. Even if the externproto has no URIs registered, this method shall be called. If there are none available, this will be called with a zero length list of values.- Specified by:
externProtoURIin interfaceProtoHandler- Parameters:
values- A list of strings representing all of the URI values- Throws:
SAVException- This call is taken at the wrong time in the structure of the document.VRMLException- This call is taken at the wrong time in the structure of the document.
-
compare
- Specified by:
comparein interfaceComparator<Object>
-
equals
-
printStats
public void printStats()
-