JavaBeans Activation Framework

From Wikipedia, the free encyclopedia
Jump to: navigation, search

Introduction[edit]

In computer programming, JavaBeans Activation Framework, or JAF, enables developers to:[1]

  • determine the type of an arbitrary piece of data,
  • encapsulate access to it,
  • discover the operations available on it and
  • to instantiate the appropriate bean to perform the operation(s).

It also enables you to dynamically register types of arbitrary data and actions associated with particular kinds of data. Additionally, it enables a program to dynamically provide or retrieve JavaBeans that implement actions associated with some kind of data.

  • JSR-925
  • Latest spec version is 1.1
  • It's an old spec released on April 2006
  • It's originally an extension API
    • Now available as a standard API in Java SE and Java EE
    • Has only one package javax.activation (4 interfaces, 13 classes)

Datasource Interface[edit]

  • Provides access to an arbitrary collection of data
  • Get name of the data, data-type name (content type), and the data itself asInputStream or OutputStream
  • Two implementation classes provided
    • URLDataSource simplifies the handling of data described by URLs
    • FileDataSource simple DataSource object that encapsulates a file provides data typing services -> delegated to a FileTypeMap object.
  • Other implementation
    • javax.mail.internet.MimePartDataSource

DataContentHandler interface[edit]

  • Convert the object to a byte stream and write it to the output stream
  • Convert streams in to objects
  • Used to get object/data which can be transferred
  • Uses java.awt.datatransfer.DataFlavor to indicate the data that can be accessed. DataFlavor is a data format as would appear on a clipboard, during drag and drop, or in a file system.

CommandMap class[edit]

  • An abstract class provides an interface to a registry of command objects available in the system
  • Developer develop their own implementation or use
    • MailcapCommandMap class that implements a CommandMap whose configuration is based on mailcap files (1524)
  • Command list available from a MIME Type is stored in CommandInfo object.

CommandObject interface[edit]

  • Interface to be implemented by JavaBeans components that are ActivationFramework aware
  • Simple interface with one method:
    • setCommandContext(String verb, DataHandler dh)

Example: Compose an e-mail with attachment[edit]

import javax.activation.DataHandler;

import javax.activation.FileDataSource;

import javax.mail.internet.*;

import javax.mail.*;

...

// Create a message.

MimeMessage message = new MimeMessage(session);

...

// Create the Multipart to be added the parts to

Multipart multipart= new MimeMultipart();

// Create and fill the first text message part

MimeBodyPart mbp = new MimeBodyPart();

mbp.setText(Body);

multipart.addBodyPart(mbp);

// Create a file attachment and fill as second message part

MimeBodyPart mbp = new MimeBodyPart();

FileDataSource fds = new FileDataSource(“C:attachment.zip”);

mbp.setDataHandler(new DataHandler(fds));

mbp.setFileName(fds.getName());

multipart.addBodyPart(mbp);

// Add the multipart to the message

message.setContent(multipart);

...

JAF in use[edit]

External links[edit]

References[edit]

  1. ^ JavaBeans Activation Framework. Retrieved 2013-08-11.