SOA.WRK.

Tuesday Feb 27, 2007

Aspect Oriented Programming w/Domain Specific Languages (AOP/DSL)

Several friends asked me to explain the link between the message-based and the traditional approach of aspect composition discussed briefly in my last post. I will try to illustrate this concept with an example.

The "hello world" service is probably the simplest example of a service. However, when implemented as a http/soap based service in, e.g., Java, the code can be very complicated. Using the traditional AOP, the soap messaging aspect can be separated out from the core logic as follows:

  • First, write the code for the core logic in a short program
    String msg = receiveMessage(...params...);
    sendMessage(msg, ...params...);
  • Then, define aspects linking point-cuts to advices
    execute soapMessageRecive(...) before receiveMessage(...)
    execute soapMessageSend(...) after sendMessage(...)
  • Finally, implement the massive advice code to handle soap messaging
    MessageFactory mf = MessageFactory.newInstance(); 
    SOAPMessage msg = mf.createMessage(); 
    SOAPPart part = msg.getSOAPPart(); 
    SOAPEnvelope env = (SOAPEnvelope) part.getEnvelope(); 
    SOAPBody body = env.getBody(); 
    ...

This is nice... but feel like busy work because we restructured the service code without reducing its complexity. This often makes me wonder something important is missing in AOP. There must be a hidden door somewhere waiting to be discovered.

OK, let's try to implement the same service using the composite application platform introduced in Netbeans Enterprise Pack. We will need a SOAP binding component, and a BPEL or EJB service engine for the core logic. Once these containers are installed, we can implement the service component as follows:

  • First, write the code for the core logic in a short program
    String msg = receiveMessage(...params...);
    sendMessage(msg, ...params...);
  • Then, define aspects linking point-cuts to advices
    connect myEchoPort to SOAP BC's echoPort
  • Finally, implement the advice code to handle soap messaging in a WSDL
    ...
    <wsdl:service name="echoService">
      <wsdl:port name="echoPort" binding="myns:echoBinding">
        <soap:address location="http://localhost:12345/echo"/>
      </wsdl:port>
    </wsdl:service>

Yes, WSDL can be run in BCs! The important difference between this version and the one implemented using the traditional AOP approach is in the last step. Instead of using the same implementation language as the core logic, the aspect logic is implemented in its own domain specific language, in this case, WSDL. This is the hidden door I was earching for in AOP before. After separating aspects out from the core logic, why not run each aspect in its domain specific container and implement it in its own language, e.g., WSDL, XSL, SQL, XQUERY, etc.

AOP/DSL

There are many ways to broaden the conventional application architecture. One can extend primary programming languages, e.g., Java and C#, with facilities to handle domain specific logics. Annotation is a good example. Microsoft's LINQ is also a great example of such an approach. Another approach is to allow applications to be composed from components implemented in different languages. We refer the later approach as Composite Application Development (CAD) or Composite Application Programming (CAP).

Comments:

Post a Comment:
Comments are closed for this entry.

Calendar

Feeds

Search

Links

Navigation

Referrers