Public:BWmeta service/Java mapping

From YaddaWiki

< Public:BWmeta service
Revision as of 11:51, 13 October 2010 by Kura (Talk | contribs)
Jump to: navigation, search
Service details
NameBWmeta
Code location
(relative to SVN root)
projects/dir/bwmeta-core
Javadoc
Contact personJakub Jurkiewicz

Contents

History

Three different mappings of BWmeta to Java have been written in the project's lifetime. The following table summarizes the mappings.

Model Name Works with
BWmeta versions
Usage areas Comments
Repo model 1.0.0 ÷ 1.0.5 Processes, YaddaWeb Hibernate-oriented
DeskLight model 1.0.0 ÷ 1.0.5 DeskLight
"Y" model 1.2.0 ÷ 2.0.0 Pack Management

Current efforts are focused on replacing the older models (Repo and DeskLight) with the latest one ("Y"). The remainder of this page and all the other pages on BWmeta usage in YADDA assume usage of the "Y" model.

General contracts

Unless explicitly stated in the documentation, every "Y" class has the following properties:

  • has a public default constructor.
  • every property is protected, but has a public getter and setter.
  • getters of String, YLanguage and List properties can never return null. Instead, an empty String, YLanguage.Undetermined or an empty List is returned, respectively.
  • for every List<T> property:
    • its getter returns a modifiable List<T>;
    • its getter returns the same reference all the time;
    • its setter accepts any Collection<T> (and copies the contents);
    • there's an adder (which returns this).
  • every setter and every list adder returns this, which allows chained setting, e.g.:
new YElement()
    .setId("bwmeta1.element.foo")
    .addName(new YName().setText("Foo").setLanguage(YLanguage.English))
    .addDescription(new YDescription().setText("Lorem ipsum").setLanguage(YLanguage.Latin));

The folowing contracts are to be implemented/verified in the future:

  • hashCode() and equals() methods are based on the values of all the properties, i.e., two "Y" objects are equal iff they are of the same type and all their properties are equal.


Rich text support

Support for rich text, introduced in BWmeta 2.0.0 calls for changes in the "Y" model.

Adding YRichText class

YRichText is mutable.

Constructors

  • YRichText(String) – constructor from plain text.
  • YRichText(List<YRichText.Part>) – constructor from list of trees.

Methods

  • String toText() – returns a flattened text view of the rich text. It's a concatenation of text contents of the tree list visited in the infix order.
  • List<YRichText.Part> toParts() – returns a list of trees which represent the rich text.

Changes in classes with a YRichText property

YRichText-related methods (other than the ones below) which have been already added should be @Deprecated and subsequently removed.

YName, YDescription

  • Every constructor from String text has a corresponding constructor from YRichText text.
  • String getText() – returns flattened text.
  • YRichText getRichText() – returns rich text.
  • T setText(String) – sets plain text.
  • T setRichText(YRichText) – sets rich text.

YAttribute

  • Every constructor from String value has a corresponding constructor from YRichText value.
  • String getValue() – returns plain text.
  • YRichText getRichValue() – returns rich text.
  • YAttribute setValue(String) – sets plain text.
  • YAttribute setRichValue(YRichText) – sets rich text.

YTagList

  • List<String> getValues() – returns unmodifiable, flattened text view of the list of tags.
  • List<YRichText> getRichValues() – returns modifiable list of rich text tags.
  • YTagList setValues(Collection<String>) – sets plain text values.
  • YTagList setRichValues(Collection<YRichText>) – sets rich text values.
  • YTagList addValue(String) – adds a plain text value.
  • YTagList addRichValue(YRichText) – adds a rich text value.

Adding RichTextSerialization utility class

  • String toXmlFragment(YRichText) – serializes a rich text to an XML fragment.
  • YRichText fromXmlFragment(String) – deserializes a rich text from an XML fragment.

Contracts

  • For any String text != null the following assert should pass:
yFoo.setText(text);
// ... potential serialization and deserialization ...
// ... conversion to "DL" model and back ...
// ... or all of the above in any order ...
assertEquals(text, yFoo.getText());
  • For any String text != null the following assert should pass:
yFoo.setText(text);
// ... conversion to "DL" model ...
assertEquals(text, dFoo.getText());
  • Example:
yName.setText("<b xmlns="http://www.w3.org/1999/xhtml">1 &lt; 2</b>");
// ... conversion Y -> DL ...
assertEquals("<b xmlns="http://www.w3.org/1999/xhtml">1 &lt; 2</b>", dName.getText());
// ... conversion DL -> Y ...
assertEquals("<b xmlns="http://www.w3.org/1999/xhtml">1 &lt; 2</b>", yName.getText());
  • For any XML fragment foo if BWmeta 2.0.0 contains <name>foo</name> then:
assertEquals("foo", yName.getXml());
  • After all processes without editing we got eqal rich text objects
YrichText text=yFoo.getRichText();
// ... potential serialization and deserialization ...
// ... conversion to "DL" model and back ...
// .. no edition etc...
// ... or all of the above in any order ...
YrichText text1=yFoo.getRichText();
assertEquals(text, text1);
  • Partticularly:
YrichText rtext=yFoo.getRichText();
String text=yFoo.getText();
yFoo.setText(text);
YrichText rtext1=yFoo.getRichText();
assertEquals(rtext.getText(), rtext1.getText());


  • Partticularly:
YrichText rtext=yFoo.getRichText();
String text=yFoo.getText();
yFoo.setText(text);
//yFoo serialize deserilize
YrichText rtext1=yFoo.getRichText();
assertEquals(rtext, rtext1);


  • What if:
yName.setText("1 < 2")
Personal tools