s.im.pl serialization:
annotation language (DBAL)

Introduction

S.IM.PL serialization's Data Binding Annotation Language (DBAL) enables embedding specification of which fields to serialize and how directly into Java or C# source code. DBAL is designed to be concise and expressive at the same time. Developers use DBAL to connect their class definitions with XML, JSON, and binary representations of complex data structures. The annotations also serve as integrated documentation about data structure de/serialization. S.IM.PL automatically stores all type and data-binding information, at run time, into S.IM.PL type scopes.

Specification



Annotation Production Rule Description
@simpl_scalar

SIMPLIndividualAnnotation:

@simpl_composite

| @simpl_scalar

| @simpl_hints({HintName {, HintName }})

| @simpl_filter(regex = "Expression")

defines a scalar class attribute to be translated as XML attribute.



Example:

@simpl_scalar String item;
@simpl_hints

SIMPLIndividualAnnotation:

@simpl_composite

| @simpl_scalar

| @simpl_hints({HintName {, HintName }})

| @simpl_filter(regex = "Expression")

precisely define the syntactic structure of serialization by using XML_ATTRIBUTE, XML_LEAF, XML_LEAF_CDATA, XML_TEXT, XML_TEXT_CDATA, or UNDEFINED



Example:

@simpl_hints(Hint.XML_ATTRIBUTE)

String item;
@simpl_filter

SIMPLIndividualAnnotation:

@simpl_composite

| @simpl_scalar

| @simpl_hints({HintName {, HintName }})

| @simpl_filter(regex = "Expression")

takes a valid regular expression to filter out the data when translating from serialized representation.



Example:

@simpl_filter(regex = "") String item;
@simpl_composite

SIMPLIndividualAnnotation:

@simpl_composite

| @simpl_scalar

| @simpl_hints({HintName {, HintName }})

| @simpl_filter(regex = "Expression")

field annotated with @simpl_composite must be declared with a Type that is a subclass of ElementState, meaning that it, in turn, has further annotated fields which bind to XML



Example:

@simpl_composite

NestedObject item;
@simpl_map

SIMPLCollectionAnnotation:
@simpl_wrap | @simpl_nowrap

@simpl_collection(["TagName"]) [SIMPLClasses]

        Identifier TypeArguments

| @simpl_map(["TagName"]) [SIMPLClasses]

        Identifier TypeArguments

Defines a collections attribute of class to be translated as a set of XML leaf nodes.

Used in conjuction with @simpl_nowrap and @simpl_wrap. By default the collections are wrapped. @simpl_collection also accepts a parameter to define which defines the tags on leaf nodes.



Example:

@simpl_map

HashMap<String, Object> itemMap;
@simpl_collection

SIMPLCollectionAnnotation:
@simpl_wrap | @simpl_nowrap

@simpl_collection(["TagName"]) [SIMPLClasses]

        Identifier TypeArguments

| @simpl_map(["TagName"]) [SIMPLClasses]

        Identifier TypeArguments

Defines a collections attribute of class to be translated as a set of XML leaf nodes.

Used in conjuction with @simpl_nowrap and @simpl_wrap. By default the collections are wrapped. @simpl_collection also accepts a parameter to define which defines the tags on leaf nodes.



Example:

@simpl_collection("item")

ArrayList<String> items;
@simpl_wrap

SIMPLCollectionAnnotation:
@simpl_wrap | @simpl_nowrap

@simpl_collection(["TagName"]) [SIMPLClasses]

        Identifier TypeArguments

| @simpl_map(["TagName"]) [SIMPLClasses]

        Identifier TypeArguments

Used with collections and maps. This directive defines if the resultant leaf nodes in XML files be wrapped with class or attribute name.



Example:

@simpl_wrap
@simpl_collection("item")
ArrayList<String> items;
@simpl_nowrap

SIMPLCollectionAnnotation:
@simpl_wrap | @simpl_nowrap

@simpl_collection(["TagName"]) [SIMPLClasses]

        Identifier TypeArguments

| @simpl_map(["TagName"]) [SIMPLClasses]

        Identifier TypeArguments

Used with collections and maps. This directive defines if the resultant leaf nodes in XML files be wrapped with class or attribute name.



Example:

@simpl_nowrap
@simpl_collection("item")
ArrayList<String> items;
@simpl_classes

SIMPLClasses:

@simpl_classes({ClassName.class{, ClassName.class}})

for polymorphism, @simpl_classes can be used to bind one of various polymorphic instances of a super type to a single field.



Example:

@simpl_classes (

{Base.class , Sub.
class })

@simpl_collection

ArrayyList<Base> items;
@simpl_scope

SIMPLScope:

@simpl_scope(["TranslationScope"])

for polymorphism, @simpl_scope can be used to bind one of various polymorphic instances of a super type to a single field.



Example:

@simpl_scope ( TranslationScope.get() )

@simpl_collection

ArrayyList<Base> items;
@simpl_inherit

ClassDeclaration:

class [@simpl_inherit] [@xml_tag("TagName")] [XMLOtherTags] Identifier [extends Type] [implements TypeList] ClassBody

The @simpl_inherit construct , by its presence in a class's declaration, indicates that the fields of the class's superclass should be translated.



Example:

@simpl_inherit
public class 

SomeClass extends AnotherClass
@xml_tag

FieldDecl:

[@xml_tag("TagName")] [XMLOtherTags] [SIMPLClasses] SIMPLIndividualAnnotation Type Identifier MethodOrFieldRest

| SIMPLCollectionAnnotation Identifier MethodOrFieldRest

allows the programmer to explicitly declare the tag name for a given field or class. @xml_tag overrides s.im.pl serialization's automatic camel case conversion of names.



Example:

@xml_tag("old_tag")

String item;
@xml_other_tags

XMLOtherTags:

@xml_other_tags({"TagName"{, "TagName"}})

Support for compatibility with old versions of an XML dialect is provided by this directive. It takes one or more strings as its argument. It can be applied to either a class or field declaration



Example:

@xml_other_tags("old_tag")

String item;


Grammar

Below is the specifications of DBAL as defined in s.im.pl serialization. We define all the DBAL language constructs. You can also download an offline version of the grammer from here

[x] denotes zero or one occurrences of x.

{x} denotes zero or more occurrences of x.

x | y means one of either x or y.

ClassBody:

{ {ClassBodyDeclaration} }

ClassBodyDeclaration:

;

| [static] Block

| {OtherModifier} MemberDecl

OtherModifier:

OtherAnnotation | public | protected | private | static | abstract | final | native | synchronized | transient | volatile | strictfp

MemberDecl:

| GenericMethodOrConstructorDecl

| MethodDecl

| FieldDecl

| void Identifier MethodDeclaratorRest

| Identifier ConstructorDeclaratorRest

| ClassOrInterfaceDeclaration

ClassOrInterfaceDeclaration:

ModifiersOpt (ClassDeclaration | InterfaceDeclaration)

ClassDeclaration:

class [@simpl_inherit] [@xml_tag("TagName")] [XMLOtherTags] Identifier [extends Type] [implements TypeList] ClassBody

Type:

Identifier [TypeArguments]{ . Identifier [TypeArguments]} {[ ]}

| BasicType

TypeArguments:

< TypeArgument {, TypeArgument} >

TypeArgument:

Type

| ? [( extends | super ) Type]

FieldDecl:

[@xml_tag("TagName")] [XMLOtherTags] [SIMPLClasses] SIMPLIndividualAnnotation Type Identifier MethodOrFieldRest

| SIMPLCollectionAnnotation Identifier MethodOrFieldRest

SIMPLIndividualAnnotation:

@simpl_composite

| @simpl_scalar

| @simpl_hints({HintName {, HintName }})

| @simpl_filter(regex = "Expression")

SIMPLCollectionAnnotation:
@simpl_wrap | @simpl_nowrap

@simpl_collection(["TagName"]) [SIMPLClasses] Identifier TypeArguments

| @simpl_map(["TagName"]) [SIMPLClasses] Identifier TypeArguments

SIMPLClasses:

@simpl_classes({ClassName.class{, ClassName.class}})

SIMPLScope:

@simpl_scope(["TranslationScope"])

XMLOtherTags:

@xml_other_tags({"TagName"{, "TagName"}})

TagName:

any allowed XML tag name

ClassName:

name of any existing class

TranslationScope:

the name identifier of the translation scope

HintName:

XML_ATTRIBUTE, XML_LEAF, XML_LEAF_CDATA, XML_TEXT, XML_TEXT_CDATA, or UNDEFINED






an interface ecology lab production