Streams
The stream API allows the OPN author to access the stream directly, as a way to implement parsers. Function names are self explanatory.
module Standard;
bool get CurrentBit(this stream s);
int get BitPosition(this stream s);
int get BitLength(this stream s);
binary PeekBits(this stream s, int bitOffset, int bitCount);
byte get CurrentByte(this stream s);
int get BytePosition(this stream s);
int get ByteLength(this stream s);
binary PeekBytes(this stream s, int bitOffset, int byteCount);
char get CurrentChar(this stream s);
int get CharPosition(this stream s);
int get CharLength(this stream s);
string PeekChars(this stream s, int bitOffset, int charCount);
Messages Annotations
All the provided annotations are defined for all messages. As explained before, a user can add new annotations at will.
module Standard;
// Timestamp of the message, assigned by runtime when the message reaches
// the message source.
annotation DateTime Timestamp;
// EndTimestamp refers to the completed timestamp of the operation. Usually
// this is the timestamp of the last origin of the operation (or a
// reassembled message).For a message, the EndTimestamp value is the same as
// its Timestamp value.
annotation DateTime EndTimestamp;
// TimeElapsed is the difference of EndTimestamp and Timestamp annotation
// values for a particular message.
annotation double TimeElapsed;
// This is a GUID to identify a message session. This value is assigned
// by runtime.
annotation guid SessionId;
// A unique number assigned to the message by runtime, guaranteed unique
// per session.
annotation uint MessageNumber;
// Generic comment attached to a message, available for the user.
annotation string Comment;
// Embedded protocols use this annotation to attach embeddedspecific data.
// The key of the map is the embedded protocol name.
annotation map Embedded;
// General diagnosis errors/warnings. Sequence and data validation problems
// are identified here.
annotation DiagnosisType DiagnosisTypes;
annotation DiagnosisLevel DiagnosisLevels;
The DiagnosisLevel annotation represents the severity of the error, and the possible values are the following.
pattern DiagnosisLevel = enum { Error = 1, Warning = 2, Information = 4 };
The DiagnosisType represents the category of the error.
pattern DiagnosisType = enum DiagnosisType {
Application = 0x01,
Validation = 0x02,
InsufficientData = 0x04,
Parsing = 0x08
}
Origins
These functions expose the origins of a message. The array of messages represents the associated direct child messages of a given message.
module Standard;
array get Origins(this any message m);
void set Origins(this any message m, array origins);
Endpoint Transport
These functions allow accessing the underlying endpoint of a given endpoint.
any endpoint GetTransport(this any endpoint x);
T GetTransport(this any endpoint x);
XML
The following DeclarationInfo aspect is for internal purposes only, and it is not supposed to be used by the end user.
///////////////////////////////////////////////
// Part 1. XML Data Types
// Represents a name of an XML element or attribute.
type XmlName : TreedataName {
// Gets the namespace part of the fully qualified name.
// Returns nothing if there is no namespace;
// Returns empty string "" if there is a prefix but the namespace ca not
// be resolved.
optional string NamespaceUri;
}
///////////////////////////////////////////////
// Part 2. XML Properties
// Gets the name of an XML element or attribute.
// Returns nothing if x.Kind is not Element or Attribute.
optional XmlName get Name(this xml x) with DeclarationInfo {
Handcoded = true };
// Gets the kind of an XML element or attribute.
XmlKind get Kind(this xml x) with DeclarationInfo {
Handcoded = true };
// Gets the concatenated text contents of an XML structure,
// as described in this list:
// [XmlKind] [Value property]
// Attribute value of the Attribute
// Namespace namespace URI
// CData {EscapedText}
// Comment {Comment}
// Declaration nothing
// Document nothing
// Element nothing (according to dot net APIs)
// Text textual content
optional string get Value(this xml x) with DeclarationInfo {
Handcoded = true };
// Gets the string representation of the inner content within an
// XML Element.
optional string get InnerXml(this xml x) with DeclarationInfo {
Handcoded = true };
// Gets the string representation of the entire XML structure.
optional string get OuterXml(this xml x) with DeclarationInfo {
Handcoded = true };
// Gets the string representation of the text content within the
// XML structure.
// Element: the concatinated text within the Element.
// Others: the Value.
optional string get Text(this xml x) with DeclarationInfo {
Handcoded = true };
// Gets the resolved namespace URI for an XML Namespace.
// Returns nothing if x has no namespace or its kind is not Element.
optional string get NamespaceUri(this xml x) with DeclarationInfo {
Handcoded = true };
// Gets the count of children.
// Returns 0 if x.Kind is not Element or Document.
int get ChildCount(this xml x) with DeclarationInfo {
Handcoded = true };
// Gets the children elements as array of XML elements.
// Returns array contains only one XML elment of kind XmlKind.
// Text for Attribute. Returns empty array
// if x.Kind is not Element, Attribute or Document.
array get Children(this xml x) with DeclarationInfo {
Handcoded = true };
// Gets the count of attributes.
// Returns 0 if x.Kind is not Element or Declaration.
int get AttributeCount(this xml x) with DeclarationInfo {
Handcoded = true };
// Gets attributes.
// Returns empty map if x.Kind is not Element or Declaration.
array get Attributes(this xml x) with DeclarationInfo {
Handcoded = true };
// Sets the name of the XML element.
// Throws exception if x.Kind is not Element.
void set Name(this xml x, XmlName name) with DeclarationInfo {
Handcoded = true };
// Sets the value of the XML Attribute.
// Throws exception if x.Kind is Declaration or Document.
void set Value(this xml x, string s) with DeclarationInfo {
Handcoded = true };
// Sets the Namespace URI of the XML Namespace.
// Throws exception if x.Kind is not Element or Attribute.
void set NamespaceUri(this xml x, string uri) with DeclarationInfo {
Handcoded = true };
///////////////////////////////////////////////
// Part 3. XML Query/Update methods
// Returns a single XML element matched to the given name from all child
// elements of this XML element, or returns an arbitrary one if more than
// one child matched. Returns nothing if x.Kind is Attribute, CData,
// Comment, Declaration or Text.
optional xml GetChild(this xml x, XmlName name) with DeclarationInfo {
Handcoded = true };
// Returns a single XML element matched to the given name from all
// descendant elements of XML element, returns an arbitrary one if more
// than one descendant matched. Returns nothing if
// x.Kind is CData, Comment, Declaration or Text.
optional xml GetDescendant(this xml x, XmlName name) with DeclarationInfo {
Handcoded = true };
// Returns a filtered array of XML elements matched the given name from
// all children elements of the XML element, in document order.
// Returns empty array if x.Kind is CData, Comment, Declaration or Text.
array GetChildren(this xml x, XmlName name) with DeclarationInfo {
Handcoded = true };
// Returns a filtered array of XML elements matched to the given name from
// all descendant elements of the XML element, in document order.
// Returns empty array if x.Kind is CData, Comment, Declaration or Text.
array GetDescendants(this xml x, XmlName name) with DeclarationInfo {
Handcoded = true };
// Returns an attribute matched the given name of the XML element.
// Returns nothing if x.Kind is CData, Comment, Document or Text.
optional xml GetAttribute(this xml x, XmlName name) with DeclarationInfo {
Handcoded = true };
// !FIXME: XPath query is not supported so far.
// Returns an XML element using the specified XPath-like expression with the
// specified mapping to resolve namespace prefixes.
// Returns an arbitrary one if more than one XML element matches the path.
// Returns nothing if x.Kind is not Document or Element.
optional xml Get(this xml x, string @xpath, map resolver) with
DeclarationInfo { Handcoded = true };
// !FIXME: XPath query is not supported so far.
// Returns an array of XML elementsusing the specified XPath-like expression
// with the specified mapping to resolve namespace prefixes.
// Returns empty array if x.Kind is not Document or Element.
array GetMany(this xml x, string @xpath, map resolver)
with DeclarationInfo { Handcoded = true };
// Adds a child XML element or attribute under the given XML element.
// Throws exception if x.Kind is not Document or Element.
// Throws exception if x is Kind of Document and
// already has one child with kind of Element.
void Add(this xml x, xml y) with DeclarationInfo { Handcoded = true };
// Adds a namespace declaration under the given XML element as attribute.
// Throws exception if x.Kind is not Element.
void AddNamespace(this xml x, string prefix, string uri) with
DeclarationInfo { Handcoded = true };
// Parses string containing the XML element and builds an XML object from it
// Returns null if the data is not in valid XML format.
xml BuildXml(string data) with DeclarationInfo { Handcoded = true };
Share with your friends: |