+ All Categories
Home > Technology > Introduction to JavaBeans Activation Framework v1.1

Introduction to JavaBeans Activation Framework v1.1

Date post: 02-Nov-2014
Category:
Upload: ejlp12
View: 5,872 times
Download: 2 times
Share this document with a friend
Description:
JavaBeans Activation Framework standard extension, developers who use Java technology can take advantage of standard services to -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 said operation(s). The API doc said: It is used by the JavaMail API to manage MIME data. But actually, it is more general purpose.
11
JavaBeans Activation Framework (version 1.1) [email protected] Jan 2012
Transcript
Page 1: Introduction to JavaBeans Activation Framework v1.1

JavaBeans Activation Framework

(version 1.1)[email protected]

Jan 2012

Page 2: Introduction to JavaBeans Activation Framework v1.1

With the JavaBeans Activation Framework standard extension, developers who use Java technology can take advantage of standard services to

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 said

operation(s).

The API doc said: It is used by the JavaMail API to manage MIME data.But actually, it is more general purpose.

The Spec said…

Page 3: Introduction to JavaBeans Activation Framework v1.1

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 standard API in Java SE 6 and Java EE 5 Has only one package javax.activation (4 interfaces, 13

classes)

Spec document can be seen online at http://www.oracle.com/technetwork/java/jaf-1-150219.pdf

API documentation

JAF

Page 4: Introduction to JavaBeans Activation Framework v1.1

Major components on the JAF architecture

JAF architecture

Source: JAF Specification v1.1

provides a consistent interface between JAF-aware clients and other subsystems

Encapsulates an object that contains data, and that can return both • a stream providing data access, and • a string defining the MIME type describing the data.

• Allows consumers of its interfaces to determine the ‘commands’ available on a particular MIME type

• An interface to retrieve an object that can operate on an object of a particular MIME type

Beans extend the CommandObject interface in order to interact with JAF services

Page 5: Introduction to JavaBeans Activation Framework v1.1

Provides access to an arbitrary collection of data Get name of the data, data-type name (content type), and the

data itself as InputStream or OutputStream Two implementation classes provided

URLDataSourcesimplifies the handling of data described by URLs

FileDataSourcesimple DataSource object that encapsulates a fileprovides data typing services -> delegated to a FileTypeMap object.

Other implementation javax.mail.internet.MimePartDataSource

DataSource Interface

Page 6: Introduction to JavaBeans Activation Framework v1.1

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

DataContentHandler interface

Page 7: Introduction to JavaBeans Activation Framework v1.1

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 (RFC 1524)

Command list available from a MIME Type is stored in CommandInfo object

CommandMap class

Page 8: Introduction to JavaBeans Activation Framework v1.1

Interface to be implemented by JavaBeans components that are Activation Framework aware

Simple interface with one method: setCommandContext(String verb, DataHandler  dh)

CommandObject interface

Page 9: Introduction to JavaBeans Activation Framework v1.1

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 toMultipart multipart= new MimeMultipart();

// Create and fill the first text message partMimeBodyPart mbp = new MimeBodyPart(); mbp.setText(Body); multipart.addBodyPart(mbp);

// Create a file attachment and fill as second message partMimeBodyPart 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 messagemessage.setContent(multipart);...

Example: Compose an e-mail with attachment

Page 10: Introduction to JavaBeans Activation Framework v1.1

Another example of JAF in use: REST easy with the JavaBeans Activation Framework

http://www.javaworld.com/javaworld/jw-10-2007/jw-10-resteasy.html Example also available in Java 6™ New Features: A Tutorial book, chapter-

13ISBN 0-9752128-8-5

JAF in use

Other presentation deck:http://www.hilbertinc.com/whitepapers/JAF.pdf

Page 11: Introduction to JavaBeans Activation Framework v1.1

Thank You


Recommended