Study of an API Migration for two XML APIs Thiago Bartholomei - - PowerPoint PPT Presentation

study of an api migration for two xml apis
SMART_READER_LITE
LIVE PREVIEW

Study of an API Migration for two XML APIs Thiago Bartholomei - - PowerPoint PPT Presentation

Study of an API Migration for two XML APIs Thiago Bartholomei Krzysztof Czarnecki Ralf Lmmel Tijs van der Storm API migration Source API uses Application API X Transformation Target API uses Application API Y API migration --


slide-1
SLIDE 1

Study of an API Migration for two XML APIs

Thiago Bartholomei Krzysztof Czarnecki Ralf Lämmel Tijs van der Storm

slide-2
SLIDE 2

API migration

Application API X API Y

uses

Application

Transformation

uses

Source API Target API

slide-3
SLIDE 3

API migration -- why?

... because the target API is more modern, reliable, efficient, etc., or ... because the source API is no longer supported, or causing worrisome license costs, or ... because the app should use less APIs per domain.

slide-4
SLIDE 4

API migration

by wrapper-based reimplementation

Application API X

API X interface

API Y

Wrapping

uses

Application

uses

slide-5
SLIDE 5

Plan

Illustrate difficulty of API migration in the XML domain. Describe a wrapper-based migration study between two Java XML APIs: JDOM vs. XOM. Observations

slide-6
SLIDE 6

API Differences

API Y API X

slide-7
SLIDE 7

Construct a phone

  • rder with JDOM

// JDOM Element order = new Element("order"). addContent(new Element("product"). addContent("iPhone")). addContent(new Element("customer"). addContent("1234"));

This-returning and method chaining

slide-8
SLIDE 8

Construct a phone

  • rder with XOM

// XOM Element order = new Element("order"); Element product = new Element("product"); product.appendChild("iPhone");

  • rder.appendChild(product);

Element customer = new Element("customer"); customer.appendChild("1234");

  • rder.appendChild(customer);

Void result type

slide-9
SLIDE 9

Position- vs. identity- based replacement

// JDOM int index = order.indexOf(oldProduct);

  • rder.setContent(index, newProduct);

// XOM

  • rder.replaceChild(oldProduct, newProduct);
slide-10
SLIDE 10

Less vs. more strict pre-conditions

// JDOM

  • rder.removeContent(product);
  • rder.removeContent(product);

// quietly completes. // XOM

  • rder.removeChild(product);
  • rder.removeChild(product); // throws!
slide-11
SLIDE 11

Eager vs. lazy queries

// XOM Elements es = order.getChildElements(); for (int i = 0; i < es.size(); i++) es.get(i).detach(); // JDOM (illegal, throws exception) for (Object k : order.getChildren()) ((Element)k).detach();

slide-12
SLIDE 12

Wrapper-based migration

slide-13
SLIDE 13

Wrapping process

Start with empty wrapper Iteratively implement methods Test and diagnose Judgment call Fix and @annotate Adapter pattern

slide-14
SLIDE 14

“JDOM as XOM”

package nu.xom; @MapsTo("org.jdom.Element") public class Element { private org.jdom.Element wrappee; @MapsTo("org.jdom.getContentSize()") @Solution(Strategy.DELEGATE) public int getChildCount() { return wrappee.getContentSize(); } }

slide-15
SLIDE 15

Annotations

Progress of implementation e.g., done, todo, wontdo Adaptation levels delegate, reimplement Generic issues pre, post, invariant Domain-specific issues Serialization, Base URI

slide-16
SLIDE 16

Observations

slide-17
SLIDE 17

Test suite-based compliance

Estimate compliance using tests API’s test suite Comprehensive XOM test suite An application’s test suite: Chemistry Development Kit (CDK)

slide-18
SLIDE 18

Compliance results

Test suite Compliant test cases Non-Comp. test cases API Method coverage #Number

  • f test

cases API App

417 280 156 697 752 35 752

slide-19
SLIDE 19

Notice

Full compliance for application was reached without manual modifications.

except for 3 test-cases that depended on the

  • rder of attributes
slide-20
SLIDE 20

Method-compliance levels (relative to a test suite)

Always exercised in successful test cases only Sometimes also involved in failing test cases Never

  • nly involved in failing testcases

Unused not exercised at all

slide-21
SLIDE 21

Method-compliance levels

Test suite always some times never unused API App

75 77 4 79 35 200

slide-22
SLIDE 22

Notice

There are methods with issues w.r.t. the API’s test suite that have no issues w.r.t. the application’s test suite.

See the paper for detailed numbers on these matters.

slide-23
SLIDE 23

Method-adaptation levels

1 Pure delegation 2 + Pre/postprocessing 3 Composite 4 Reimplementation

# methods per level # methods per level # methods per level # methods per level # methods per level 1 2 3 4 rest

107 66 31 27 4

slide-24
SLIDE 24

Judgment call

Aiming for more compliance means higher adaptation levels.

slide-25
SLIDE 25

Summary

Wrapper is good enough for application. Full compliance for API’s test suite Not reached, and Not necessary, and Not practical. Wrapper is instructive for transformation. Study feeds into method for API migration.