28.04.2015 Views

Java Specification Request 086 Enterprise Media BeansTM ...

Java Specification Request 086 Enterprise Media BeansTM ...

Java Specification Request 086 Enterprise Media BeansTM ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Java</strong> <strong>Specification</strong> <strong>Request</strong> <strong>086</strong><br />

<strong>Enterprise</strong> <strong>Media</strong> Beans TM <strong>Specification</strong>,<br />

Version 1.0, Final Release<br />

This is the specification of the <strong>Enterprise</strong> <strong>Media</strong> Beans’ architecture. The <strong>Enterprise</strong> <strong>Media</strong> Beans<br />

architecture allows the seamless integration of rich media data like audio, video, image and component<br />

document formats into applications based on the J2EE’ programming model. Applications written<br />

using the <strong>Enterprise</strong> <strong>Media</strong> Beans architecture incorporate rich media data as just another datatype<br />

in a scalable, transactional, and multi-user secure way. They may be written once, and then deployed on<br />

any server platform that implements both the J2EE and the <strong>Enterprise</strong> <strong>Media</strong> Beans specifications.<br />

Expert Group:<br />

Dave Bolt<br />

Dr. Harold A. Anderson, Jr.<br />

Dr. Poornachandra G. Sarang<br />

Jonathan R. Earl<br />

Sascha Baumeister, <strong>Specification</strong> Lead<br />

Document Author:<br />

Sascha Baumeister<br />

Please send technical comments on this specification to:<br />

sbaumei@de.ibm.com (Sascha Baumeister, spec lead)<br />

caser@us.ibm.com (Ralph B. Case, maintenance lead)<br />

Version 1.0, Final Release<br />

April 6, 2004


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Release<br />

Version 1.0, Final<br />

Table of Contents<br />

CHAPTER 1 INTRODUCTION 4<br />

1.1 Target Audience 4<br />

1.2 Acknowledgements 4<br />

1.3 Organization 5<br />

1.4 Document Conventions 5<br />

CHAPTER 2 POSITIONING 6<br />

2.1 <strong>Java</strong> <strong>Media</strong> Framework TM 7<br />

2.2 Content Management Systems 7<br />

2.3 <strong>Java</strong> Content Repository (JSR170) 8<br />

2.4 <strong>Media</strong> Streaming 8<br />

CHAPTER 3 ARCHITECTURE 10<br />

3.1 <strong>Media</strong> Foundation Beans 10<br />

3.2 <strong>Media</strong> Entity Beans 11<br />

CHAPTER 4 MEDIA FOUNDATION BEANS 15<br />

4.1 javax.emb.<strong>Media</strong> 16<br />

4.2 javax.emb.<strong>Media</strong>Bean 18<br />

4.3 javax.emb.<strong>Media</strong>Format 19<br />

4.4 javax.emb.Generic<strong>Media</strong>Format 21<br />

4.5 javax.emb.<strong>Media</strong>FormatRegistry 22<br />

4.6 javax.emb.<strong>Media</strong>Segment 23<br />

4.7 javax.emb.<strong>Media</strong>Header 25<br />

4.8 javax.emb.Generic<strong>Media</strong>Header 25<br />

4.9 javax.emb.<strong>Media</strong>Converter 26<br />

4.10 javax.emb.<strong>Media</strong>ConverterSpec 27<br />

4.11 javax.emb.<strong>Media</strong>Exception 28<br />

4.12 javax.emb.ContentAccessException 28<br />

1


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

4.13 javax.emb.<strong>Media</strong>FormatException 28<br />

4.14 javax.emb.ContentTooLargeException 28<br />

4.15 javax.emb.ConversionException 29<br />

4.16 javax.emb.FormatAlreadyBoundException 29<br />

4.17 javax.emb.FormatFeatureException 29<br />

4.18 javax.emb.FormatNotFoundException 29<br />

4.19 javax.emb.FormatSyntaxException 29<br />

4.20 javax.emb.LinkTranslationException 29<br />

4.21 javax.emb.MalformedLocationException 30<br />

CHAPTER 5 MEDIA ENTITY BEANS 31<br />

5.1 javax.emb.<strong>Media</strong>EntityLocal 33<br />

5.2 javax.emb.<strong>Media</strong>EntityLocalHome 42<br />

5.3 javax.emb.<strong>Media</strong>Listener 49<br />

5.4 javax.emb.ProtocolConstraints 51<br />

5.5 javax.emb.MetaDataEntityLocal 52<br />

5.6 javax.emb.MetaDataEntityLocalHome 56<br />

5.7 javax.emb.<strong>Media</strong>Exception 57<br />

5.7.1 javax.emb.ContentUnmutableException 57<br />

5.7.2 javax.emb.IllegalOptionException 57<br />

5.7.3 javax.emb.ListenerVetoException 57<br />

5.7.4 javax.emb.LocationUnmutableException 57<br />

5.7.5 javax.emb.MalformedQueryException 57<br />

5.7.6 javax.emb.MetaDataValidationException 57<br />

5.7.7 javax.emb.MetaDataSyntaxException 58<br />

5.7.8 javax.emb.NoServerFoundException 58<br />

5.7.9 javax.emb.VersionChainIntegrityException 58<br />

5.7.10 javax.emb.UnsupportedQueryLanguageException 58<br />

5.8 javax.ejb.RemoveException 58<br />

5.8.1 javax.emb.ParentAssociationExistsException 58<br />

5.8.2 javax.emb.PredecessorAssociationExistsException 58<br />

CHAPTER 6 RESPONSIBILITIES OF EMB ROLES 59<br />

6.1 <strong>Media</strong> Foundation Bean Providers 59<br />

6.2 <strong>Media</strong> Entity Bean Providers 59<br />

6.3 EJB Application Developers 59<br />

6.4 EJB Container Providers 60<br />

6.5 Client Programmer 㤱 s Responsibilities 60<br />

2


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

CHAPTER 7 EXAMPLES 61<br />

7.1 Simple Burst Transfer 62<br />

7.2 Publishing & Burst Transfer 63<br />

7.3 Publishing & Streaming 64<br />

7.4 Presentation & Dynamic Conversion 65<br />

7.5 Dynamic Header Extraction 66<br />

CHAPTER 8 APPENDIX 67<br />

8.1 Reference 67<br />

8.1.1 Classes and Interfaces 67<br />

8.1.2 Exceptions 70<br />

8.2 Related Documents 71<br />

3


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

Chapter 1<br />

Introduction<br />

This is the specification of the <strong>Enterprise</strong> <strong>Media</strong> Beans’ (EMB) architecture. The<br />

<strong>Enterprise</strong> <strong>Media</strong> Beans architecture is a component-based architecture that extends the<br />

J2EE and <strong>Enterprise</strong> <strong>Java</strong>Beans’ architectures to allow the seamless integration of rich<br />

media data such as audio, video, image or component documents into J2EE’<br />

technology based business applications. Such applications can be written once, and then<br />

deployed on any server platform that supports the J2EE and <strong>Enterprise</strong> <strong>Media</strong> Beans<br />

specifications.<br />

This specification is accompanied by a container independent reference implementation<br />

(RI) and a technology compatibility kit (TCK) able to test if an implementation is<br />

conforming this specification or not. Both the reference implementation and the<br />

technology compatibility kit are open source, published under Common Public License<br />

(CPL), and available at<br />

http://oss.software.ibm.com/developerworks/projects/embri for<br />

download. Container providers and 3 rd parties are invited to implement this specification<br />

if a quality of service exceeding the one provided in said reference implementation is<br />

desired.<br />

1.1 Target Audience<br />

The target audience of this specification is the subset of the J2EE specification audience<br />

working on incorporating support for rich media data into their product offerings. This<br />

specification is especially targeting, but is not limited to, the <strong>Enterprise</strong> <strong>Java</strong>Beans part of<br />

the J2EE community.<br />

In this community, this document mainly targets vendors of EJB transaction processing<br />

platforms and vendors of enterprise application tools. However, the API sections of this<br />

specification may also be of interest for application programmers who want to use<br />

<strong>Enterprise</strong> <strong>Media</strong> Beans implementations in their projects.<br />

1.2 Acknowledgements<br />

We –d like to thank Jeffrey Frey, Donna N Dillenberger Gerd Breiter and all others in<br />

IBM contributing directly or indirectly to this work for their tremendous support and<br />

invaluable input during the evolvement of <strong>Enterprise</strong> <strong>Media</strong> Beans.<br />

Thanks to Sarah Boaz, Frank Castaneda, Adam J. Goldman and Adrian G. Treuille for<br />

their dedication and creativity during the <strong>Enterprise</strong> <strong>Media</strong> Beans related IBM Extreme<br />

Blue 2000 internship in Boston.<br />

Special thanks also to Ann Black, Lan Vuong and Ralph Case for teaming up to finalize<br />

the reference implementation and the related test kit.<br />

Last but not least, we –d like to acknowledge the <strong>Enterprise</strong> <strong>Java</strong>Beans 2.0 architects as<br />

we took parts of their document layout as a template for this specification. This should<br />

4


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

ease navigation and understanding for the audience already familiar with the <strong>Enterprise</strong><br />

<strong>Java</strong>Beans specification.<br />

1.3 Organization<br />

Chapter 2 positions the <strong>Enterprise</strong> <strong>Media</strong> Beans technology against related <strong>Java</strong> and non-<br />

<strong>Java</strong> technology.<br />

Chapter 3 provides a high level view on the <strong>Enterprise</strong> <strong>Media</strong> Beans architecture and its<br />

components.<br />

Chapter 4 defines the <strong>Media</strong> Foundation Beans component of the <strong>Enterprise</strong> <strong>Media</strong><br />

Beans architecture. This component is targeting the whole J2EE community. Parts of the<br />

J2SE/J2ME community might find parts of this specification useful too.<br />

Chapter 5 defines the <strong>Media</strong> Entity Beans component of the <strong>Enterprise</strong> <strong>Media</strong> Beans<br />

architecture. This component is specifically targeting the <strong>Enterprise</strong> <strong>Java</strong>Beans<br />

community.<br />

Chapter 6 provides some Servlet code snipplets illustrating the use of <strong>Enterprise</strong> <strong>Media</strong><br />

Beans in J2EE based enterprise applications.<br />

Chapter 7 is the appendix including an API reference, an index, and a list of related<br />

documents.<br />

1.4 Document Conventions<br />

The regular Garamond font is used for prescriptive information.<br />

The italic Garamond font is used for descriptive information.<br />

The regular Courier font is used for code samples.<br />

The OMG Unified Modeling Language (UML) is used for diagrams. Concrete classes are<br />

depicted as regular rectangles; interfaces are depicted as rounded rectangles.<br />

5


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

Chapter 2<br />

Positioning<br />

Rich media data extends traditional computer data formats into more natural data formats<br />

for the interaction of humans and computers by incorporating images, documents,<br />

animations, motion pictures, voice, audio, and video. Leading market, business, social,<br />

and technical indicators point to the growing importance of this digitally recorded<br />

content. Storing, managing, rendering and integrating this kind of data seamlessly into<br />

business applications yields significant competitive advantage and the opportunity for<br />

new markets, new customers, and new services.<br />

The World Wide Web demand for rich media data has brought up a wide variety of<br />

products dealing with recording, authoring, rendering, streaming and storing rich media<br />

data in recent years. Usually, these products are developed around a specialized and<br />

proprietary database, make use of specialized and proprietary file systems and offer<br />

proprietary API – s and protocols to handle rich media data.<br />

Content Management Systems for instance are highly complex and heavyweight<br />

middleware with proprietary data stores and proprietary interfaces to store, retrieve and<br />

manage digital content. Streaming media solutions as another example are nonstandardized<br />

software products using proprietary protocols to transfer and render<br />

content such as audio and video on end users – systems. They mainly work with<br />

proprietary formatted content stored in plain files. Products within this fast emerging<br />

market come from companies like Real Networks, Microsoft, Apple, and IBM.<br />

This has a serious impact on enterprise customers who are interested in incorporating<br />

rich media data into their core business applications. For example, the use of proprietary<br />

APIs creates dependencies on the architecture of the products used, making it hard to<br />

migrate from those products later. The integration of standard business applications with<br />

products exposing proprietary data formats, APIs and protocols is very hard to achieve.<br />

The lack of integration with mission critical enterprise data residing in customers –<br />

relational databases violates referential integrity. Backup procedures are not consistent,<br />

because the rich media part of the enterprise data is handled by proprietary data<br />

management systems. Caching or replication of media data throughout customer<br />

intranets is either not handled at all or based on proprietary solutions or stream server<br />

providers. Also, there is no unified mechanism for authorization and transactional<br />

behavior when it comes to integrating structured data with rich media data.<br />

What customers are lacking is a standardized middleware extension that provides a<br />

uniform view on rich media data from the backend throughout their infrastructure, and a<br />

possibility of maintaining it, using their existing data administration tools and<br />

procedures. In other words, rich media data needs to be treated as just another data type<br />

that is handled similarly to structured data within the application layer. <strong>Enterprise</strong> <strong>Media</strong><br />

Beans addresses these rich media related problems within the J2EE community.<br />

6


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

2.1 <strong>Java</strong> <strong>Media</strong> Framework TM<br />

The <strong>Java</strong> <strong>Media</strong> Framework models rich media primarily from the functional perspective<br />

of capturing, processing and playing back streaming media. It is mainly based around<br />

the concept of constructing customized media players in <strong>Java</strong> in a platform independent<br />

way, thereby targeting the distributed programming model (J2SE “ applets and<br />

applications). In contrast, <strong>Enterprise</strong> <strong>Media</strong> Beans come from a data model perspective,<br />

thereby targeting integration of rich media and relational data in the server-centric<br />

programming model (J2EE, Servlets, JSPs, EJBs).<br />

The <strong>Java</strong> <strong>Media</strong> Framework is targeted at streaming media capture and playback and has<br />

as its strength the means to handle rich media that is composed of tracks of content to<br />

be processed (multiplexed/demultiplexed, compressed/decompressed, transcoded,<br />

rendered etc.). From the perspective of <strong>Enterprise</strong> <strong>Media</strong> Beans, the <strong>Java</strong> <strong>Media</strong><br />

Framework is the mechanism that extends J2SE for supporting rich media processing.<br />

From the perspective of the <strong>Java</strong> <strong>Media</strong> Framework, <strong>Enterprise</strong> <strong>Media</strong> Beans is one of<br />

several possible ways to manage persistent rich media data.<br />

There is real synergism possible between JMF and EMB when it comes to transcoding<br />

and conversion of rich media data. The JMF processor model allows <strong>Java</strong>Beans to be<br />

developed that perform transcoding and conversion. JMF-based converters and<br />

transcoders implemented as <strong>Java</strong>Beans can be incorporated into <strong>Enterprise</strong> <strong>Media</strong>. As<br />

this part of the <strong>Java</strong> <strong>Media</strong> Framework doesn –t seem to be specifically tailored to the<br />

distributed programming model, <strong>Enterprise</strong> <strong>Media</strong> Beans transcoders and converters are<br />

implementable based on the <strong>Java</strong> <strong>Media</strong> Framework. However, <strong>Enterprise</strong> <strong>Media</strong> Beans<br />

does not architect the internals of such implementations and therefore also allows the<br />

integration of native means of transcoding or conversion.<br />

2.2 Content Management Systems<br />

Content Management Systems are products that manage and persist rich media data.<br />

They come with product specific APIs and data models surrounding rich media data,<br />

which makes it very hard for customers to exchange data between competing products,<br />

like the FileNet TM content management system and IBM – s Content Manager TM . Content<br />

management systems focus on management and query aspects of rich media, like<br />

distribution of content over the network and federated content search algorithms.<br />

As the requirements for rich media related data depend highly on the use case scenario<br />

and the kind of media involved, the APIs available with these systems tend to be rather<br />

complicated and large. Also, content management systems tend to integrate rather poorly<br />

with J2EE, especially when it comes to backup/restore, security, and transactions. In<br />

particular, EJB security credentials and transaction concepts are not compatible with<br />

those in content management systems, if present at all.<br />

<strong>Enterprise</strong> <strong>Media</strong> Beans is intended to be a lightweight, standardized middleware that<br />

can be used with or without an underlying content management system to seamlessly<br />

integrate rich media data into a J2EE environment. On one hand, it can be implemented<br />

on top of a relational database system in conjunction with file system to provide support<br />

for a variety of platforms. On the other hand, a specific content management system can<br />

be encapsulated as a data store for <strong>Enterprise</strong> <strong>Media</strong> Beans.<br />

7


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

2.3 <strong>Java</strong> Content Repository (JSR170)<br />

The <strong>Java</strong> Content Repository is a work in progress unifying the APIs for content<br />

management systems. The positioning between this API and <strong>Enterprise</strong> <strong>Media</strong> Beans is<br />

highly similarly to the positioning between JDBC and EJBs, i.e. <strong>Java</strong> Content Repository<br />

provides the data access function and data model, whereas <strong>Enterprise</strong> <strong>Media</strong> Beans<br />

provides the integration into the J2EE/EJB component model. Specifically, <strong>Enterprise</strong><br />

<strong>Media</strong> Beans can be implemented on top of <strong>Java</strong> Content Repository compliant content<br />

management systems.<br />

Also similarly to the relation between EJBs and JDBC, we target an evolution of function<br />

being incorporated into <strong>Enterprise</strong> <strong>Media</strong> Beans over time, like search and indexing.<br />

However, we postpone this integration to a future version of <strong>Enterprise</strong> <strong>Media</strong> Beans, as<br />

JSR170 has not evolved to a point yet that allows integrating such function into the API.<br />

2.4 <strong>Media</strong> Streaming<br />

Today, the market for streaming media product offerings is neither standards based nor a<br />

<strong>Java</strong> domain. The leading product offerings can be characterized as proprietary, like<br />

Microsoft Windows <strong>Media</strong> Services TM , RealNetworks RealSystem TM , Apple Quicktime TM ,<br />

IBM VideoCharger TM , or Nullsoft Winamp TM . Most of them feature a unique proprietary<br />

player. This technique is an optimization of the traditional way to handle data, which is<br />

to first transfer the streaming media over a network and to store it locally on the client<br />

completely before presenting it. Streaming technology always requires a pair of<br />

components to work together: On the server side a stream server component is required<br />

to stream the data onto the network. On the client side a player is required that is able<br />

to immediately process and present rich media data stream right when it arrives over the<br />

network.<br />

In order to initiate streaming with a media player, a file is often required containing a<br />

pointer to the media file to be streamed, the IP hostname of the stream server machine,<br />

the port the stream server software listens to,<br />

and optionally additional information. Such a<br />

file is commonly referred to as a metafile, and<br />

its format is specific to the kind of stream<br />

server used. To the right is a typical sample<br />

content of a RealNetworks TM metafile (”.ram<br />

file).<br />

rtsp://9.164.184.12:200/media/video42.rm<br />

rtsp://9.164.184.12:200/media/audio16.rm<br />

Figure 1: Sample streaming metafile<br />

The major advantage of streaming technology is that it makes transfer and rendering of<br />

rich media realistic regardless of the media size. The major disadvantage is that due to<br />

the lack of accepted standards, stream server and media player components are strongly<br />

coupled by proprietary protocols and therefore don –t work with components of other<br />

vendors in the majority of cases. <strong>Enterprise</strong> <strong>Media</strong> Beans addresses the heterogeneity<br />

and proprietary nature of streaming media client/server systems by encapsulation. Thus,<br />

enabling e-business applications to be developed on the J2EE platform without having to<br />

deal with the vendor-specific characteristics of the stored streaming media content and<br />

installed streaming media servers.<br />

Since <strong>Enterprise</strong> <strong>Media</strong> Beans abstract over streaming-media-based products, they in<br />

effect represent a J2EE middleware extension for managing and delivering distributed<br />

8


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

streaming media content. EMB enables enterprise <strong>Java</strong> applications to be developed that<br />

have no dependency on the type of specific streaming technology installed.<br />

9


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

Chapter 3<br />

Architecture<br />

The J2EE TM architecture consists of components that help developers to create enterprise<br />

business applications that conform to the Model-View-Controller paradigm within the<br />

server-centric programming model. With the exception of the Servlet TM and <strong>Java</strong><br />

ServerPages TM components (which deal with view and controller aspects), all J2EE<br />

functionality can be applied in two forms: either separately by adding atomic<br />

components like JDBC TM , JMS TM or JTS TM to enrich applications with specific services, or<br />

by using <strong>Enterprise</strong> <strong>Java</strong>Beans TM that integrate all this into a single architecture.<br />

Therefore, J2EE applications significantly differ in either utilizing <strong>Enterprise</strong> <strong>Java</strong>Beans<br />

technology or not.<br />

<strong>Enterprise</strong> <strong>Media</strong> Beans target<br />

the seamless integration of rich<br />

<strong>Enterprise</strong> <strong>Media</strong> Beans<br />

media data into applications<br />

based on the J2EE programming<br />

<strong>Media</strong> Foundation <strong>Media</strong> Entity<br />

model. As such applications<br />

Beans<br />

Beans<br />

come in two basic shapes as<br />

described above, the <strong>Enterprise</strong><br />

<strong>Media</strong> Beans architecture is<br />

require<br />

require<br />

separated into two components<br />

require<br />

too: <strong>Media</strong> Foundation Beans<br />

require only basic <strong>Java</strong> 2 TM<br />

technology and can be used in <strong>Java</strong> 2 base<br />

EJB 2.0<br />

any kind of J2EE application. In<br />

Technology<br />

Entity Beans<br />

contrast, <strong>Media</strong> Entity Beans rely<br />

on EJB entity beans and are Figure 2: <strong>Enterprise</strong> <strong>Media</strong> Beans components and dependencies<br />

therefore of interest only for<br />

applications based on the <strong>Enterprise</strong> <strong>Java</strong>Beans architecture.<br />

3.1 <strong>Media</strong> Foundation Beans<br />

<strong>Media</strong> Foundation Beans provide definitions for basic media related services in a servercentric<br />

programming model. These services specifically target media objects that are<br />

possibly transient, local, and immutable.<br />

Core to this is a model for media formats that offers a service to extract links to external<br />

media resources from non-embedded media, a service to extract header information<br />

without the need of programming against platform specific interfaces, and some other<br />

services required when integrating rich media data into J2EE based applications. <strong>Media</strong><br />

headers can be used to dynamically calculate information about a media object instead<br />

of storing said information redundantly in a database. For example, if a Servlet wants to<br />

display song length and sampling rate information about MP3s, this information can<br />

easily be extracted from MP3 files. Extracting link information from non-embedded<br />

media objects is useful when analyzing dependencies between media files.<br />

Additionally, a model is defined to convert media objects from one format to another,<br />

without the need to program against platform specific interfaces. For example,<br />

10


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

applications transcoding media objects can use this in order to meet format requirements<br />

of specific clients. Another use is Servlets dynamically modifying images served through<br />

them, in order to meet size requirements or add watermarks.<br />

In the future, <strong>Media</strong> Foundation Beans will be extended to offer an architected model for<br />

transcoding, i.e. analyzing a given client – s capabilities and determining which<br />

conversions are necessary to render a given media object on said client. However, as<br />

standards for formally describing and querying client capabilities are still evolving, the<br />

topic has been postponed to future versions of<br />

this specification.<br />

Both media formats and media converters are<br />

designed as a plug-in architecture, which means<br />

3 rd party implementations of these components<br />

can be used throughout all implementations of<br />

<strong>Media</strong> Foundation Beans. The reference<br />

implementation of this specification will come<br />

with specific support for those media formats that<br />

are most common throughout the Internet “<br />

JPEG, BMP, WAV, MPEG audio (MP3), MPEG<br />

video and a generic playlist format. Additionally,<br />

any kind of embedded media format is generically<br />

supported.<br />

<strong>Media</strong> Foundation Beans<br />

<strong>Media</strong> Format<br />

Plug<br />

plug-in<br />

3rd Party<br />

Implementatio<br />

n<br />

<strong>Media</strong><br />

Converter<br />

Plug<br />

plug-in<br />

3rd Party<br />

Implementatio<br />

n<br />

Figure 3: <strong>Media</strong> Foundation Beans<br />

plug-in architecture<br />

<strong>Media</strong> Foundation Beans offer a convenient and lightweight way to include basic rich<br />

media related services in J2EE applications. However, if EJB entity beans are used in<br />

such applications, the use of <strong>Media</strong> Entity Beans as described in the section below<br />

should be preferred. <strong>Media</strong> Entity Beans use the functionality provided by <strong>Media</strong><br />

Foundation Beans.<br />

3.2 <strong>Media</strong> Entity Beans<br />

<strong>Media</strong> Entity Beans integrate the services provided by <strong>Media</strong> Foundation Beans into the<br />

<strong>Enterprise</strong> <strong>Java</strong>Beans architecture, adding additional services that require media<br />

persistence.<br />

Core to <strong>Media</strong> Entity Beans is an EJB entity bean called media entity EJB. Each media<br />

entity EJB models a single medium that is persistent and mutable. One key design point<br />

of media entity EJBs is that they abstract over the persistent store of rich media data,<br />

which means they are opaque to the application model whether persistence of media<br />

content is achieved using binary large objects, user defined data types, IBM Datalinks or<br />

simple URL references. Also, as rich media content can range from a few kilobytes to<br />

many gigabytes in size, the freedom of choice in how to map media of various formats<br />

can have a significant impact on the overall system performance.<br />

<strong>Media</strong> Entity Beans are designed for either container-managed persistence or beanmanaged<br />

persistence which allows EJB deployers to map these EJBs to a custom data<br />

model or a content repository.<br />

This is important when it comes to backup/restore processes in enterprises, as consistent<br />

backups of the complete data model, including rich media, become possible. However,<br />

11


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

this requires the media content to be persisted using a technology supported by<br />

database backup/restore processes - like binary large objects or Datalinks.<br />

The key advantage of media entity EJBs is their tight integration into the EJB<br />

programming model. <strong>Media</strong> entity EJBs share the same transaction and security model<br />

with all other business entity beans of a complex, EJB based, enterprise application.<br />

Also, if packaged with a business application they can participate fully in EJB<br />

relationships, which is<br />

*<br />

1 .. *<br />

key to a seamless<br />

EmmyAward<br />

winner<br />

integration of<br />

Person<br />

information in EJB<br />

*<br />

participa<br />

1<br />

based enterprise<br />

1 .. *<br />

nt 1 .. *<br />

applications.<br />

poster<br />

The static structure<br />

diagram to the right<br />

depicts the model of a<br />

library application that<br />

maintains and presents<br />

information about<br />

Emmy awards. The<br />

media entity EJB<br />

participates in varying<br />

roles in relationships<br />

to multiple application<br />

specific EJBs. This<br />

allows a seamless<br />

integration of rich<br />

media data into this<br />

application –s EJB model.<br />

Series<br />

winner 1<br />

1 1<br />

1<br />

EmmyAsset<br />

1 *<br />

1 *<br />

background<br />

material<br />

Episode<br />

Figure 4: <strong>Media</strong> entity EJB participating in custom EJB relationships<br />

picture<br />

<strong>Media</strong>Entity<br />

Apart from forming relationships with other EJBs, media entity EJBs can relate with other<br />

media entity EJBs. This is especially useful to guarantee referential integrity in case of<br />

non-embedded media formats. Non-embedded media contains links to external media<br />

resources, which require an understanding of the document format in question.<br />

1<br />

1<br />

vide<br />

o<br />

house.smi<br />

house.rt house.rp house.rm<br />

. . .<br />

image1.jpg image2.jpg image10.jp<br />

g<br />

Figure 5: Parent/child relationships among media entity EJBs<br />

<strong>Media</strong> Foundation Beans provide the<br />

necessary support and plug-in<br />

mechanisms for analyzing and<br />

generating the dependencies (links)<br />

between non-embedded media objects<br />

and their children, transform such links<br />

to child media objects into parent/child<br />

relationships between media entity<br />

EJBs, and manage these relations in<br />

case participants are moved or altered.<br />

The sample to the left shows the<br />

relations formed between various<br />

media entity EJBs after analyzing the<br />

non-embedded media files house.smi<br />

(SMIL format) and house.rp (RealPix<br />

format) recursively.<br />

12


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

Other relationships among media entity EJBs that are part of this specification are<br />

predecessor/successor relations between different editions of the ”same media and<br />

content/representant relationships between images and thumbnails. Of course, custom<br />

EJB models may define additional relationships among media entity EJBs.<br />

Also, media entity EJBs can be extended using a built-in persistent observer design. This<br />

allows application programmers to add custom behavior to various events in media<br />

entity EJBs, while remaining independent from a media entity EJBs implementation. For<br />

example, persistent observers allow application-specific relations that involve media<br />

entity EJBs to be maintained correctly as the observers are notified of remove requests.<br />

Also, the observers are notified of every state change in media entity EJBs, which allows<br />

application-specific media entity extensions that are independent of the underlying<br />

media entity EJB implementation.<br />

<strong>Media</strong> entity EJBs also provide an operation that allows publishing media objects to<br />

protocol servers for access, such as HTTP servers or stream servers. While being<br />

maintained as media entity EJBs, media content is neither bound to a specific protocol,<br />

nor a specific protocol server instance. The advantage is that systems built on media<br />

entity EJBs have no hard dependencies on a specific stream server manufacturer or a<br />

proprietary transport protocol, both of which may become legacy in the future.<br />

Publishing a media entity to protocol servers will create managed copies of the media<br />

entity and all its children on said protocol server. In opposition to transferring content to<br />

a client as a Servlet response this has a number of advantages, both for embedded and<br />

non-embedded media types:<br />

• Publishing an embedded media object to stream servers allows streaming access to<br />

the media content, which dramatically reduces latency times in case the content is<br />

large. Also, no streaming metadata has to be maintained for the media entities as it is<br />

generated on the fly if necessary.<br />

• Publishing a non-embedded media object to stream servers allows streaming access<br />

to the media content and the content of all its direct or indirect children. Nonembedded<br />

media objects cannot be transferred to a client by Servlet response, such<br />

media objects always require publishing by nature. Again, no streaming metadata<br />

has to be maintained for the media entities as it is generated on the fly if necessary.<br />

• Publishing an embedded media object to an HTTP server allows burst access to the<br />

media content, similar to transferring the content as a Servlet response. However, the<br />

network infrastructure can efficiently cache the content.<br />

• Publishing a non-embedded media object to an HTTP server allows burst access to<br />

the media content and the content of all its direct or indirect children. Again nonembedded<br />

media objects cannot be transferred to a client by Servlet response, and<br />

this method is preferred over publishing to a stream server in all cases where the<br />

size of the media object and all its children combined is relatively small, as the<br />

network infrastructure can efficiently cache the content.<br />

As a result of a publish request, either a meta-medium or a URL is returned depending<br />

on the kind of request. A meta-medium can be sent directly to a client as a Servlet<br />

response, and most stream servers allow meta-media to be playlists consisting of several<br />

media objects. In contrast, a URL has the advantage that it allows content to be<br />

embedded as part of an HTML page, for example using the HTML IMG element. Both<br />

kinds of results point to the media content published and contain additional information<br />

about a specific protocol server and a specific transport protocol to be used for content<br />

access.<br />

13


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

Of course, subsequent publish requests against the same media object are likely to be<br />

optimized by an EMB implementation. Also, note that the set of protocol servers<br />

supported is up to each implementation of this specification.<br />

Origin<br />

Server<br />

Protocol<br />

Server<br />

A<br />

B<br />

C<br />

Publishing A causes A, B,<br />

and C to be copied to the<br />

protocol server. Inside A – ,<br />

the child links to B and C<br />

are replaced to protocol<br />

and server specific links to<br />

B – and C – .<br />

A<br />

–<br />

B<br />

–<br />

C<br />

–<br />

Figure 6: Publishing a non-embedded media object<br />

14


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

Chapter 4<br />

<strong>Media</strong> Foundation Beans<br />

<strong>Media</strong> Foundation Beans model basic operations on media within the server-centric J2EE<br />

programming model. With the exception of media header extraction they do not target<br />

the semantic understanding of the media content, but rather represent a syntactical<br />

approach in order to unify the way media is managed and handled.<br />

So far, the overall design of <strong>Media</strong> Foundation Beans is mainly driven by the<br />

requirements of <strong>Media</strong> Entity Beans. However, in the long run <strong>Media</strong> Foundation Beans<br />

are intended to offer services independently from <strong>Media</strong> Entity Beans, like transcoding<br />

support for the server-centric programming model. Therefore, the design of <strong>Media</strong><br />

Foundation Beans will evolve exceeding <strong>Media</strong> Entity Beans requirements in the future.<br />

Throughout this chapter, the term ”link describes a reference from within a nonembedded<br />

media content to an external resource, most likely a file. Such links come in<br />

two forms: Absolute links are always URLs and therefore contain all the information<br />

necessary to access external media content: access protocol, machine address, and<br />

access path. On the other hand, relative links only provide partial information, for<br />

example the full or partial access path in case of a file name. This means that the missing<br />

information required for access has either to be derived from the context, or has to be<br />

provided explicitly.<br />

<strong>Media</strong>FormatRegistry<br />

manage<br />

<strong>Media</strong>Segment<br />

<strong>Media</strong>Header<br />

Generic<strong>Media</strong>Format<br />

extract<br />

analyze<br />

<strong>Media</strong>Format<br />

extract<br />

Generic<strong>Media</strong>Header<br />

<strong>Media</strong><br />

convert<br />

<strong>Media</strong>Converter<br />

utilize<br />

<strong>Media</strong>Bean<br />

<strong>Media</strong>ConverterSpec<br />

Figure 7: <strong>Media</strong> Foundation Beans components and interactions<br />

15


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

4.1 javax.emb.<strong>Media</strong><br />

This basic interface is used throughout <strong>Enterprise</strong> <strong>Media</strong> Beans to define the most<br />

common behavior for media objects. It defines the services common to all kinds of<br />

media objects, regardless of them being persistent or transient.<br />

There are basically two major ways to implement this interface. <strong>Media</strong> Entity Beans as<br />

described in chapter 5 deal with media content modeled as EJB entity beans, i.e. media<br />

that is persistent and mutable. The class <strong>Media</strong>Bean models media content that is local,<br />

possibly transient and immutable as described later in this chapter.<br />

In order to allow a common view on all kinds of media objects, the <strong>Media</strong> interface<br />

extends java.io.Serializable, regardless of media being persistent or transient. Having the<br />

<strong>Media</strong> interface extend Serializable ensures that instances can be transferred over remote<br />

boundaries, for example using facade stateless session beans.<br />

public interface <strong>Media</strong> extends Serializable {<br />

static final String MIME_TYPE_UNKNOWN = “www/unknown“;<br />

byte[] getContent() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>Format getFormat() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>Header getHeader() throws <strong>Media</strong>Exception;<br />

String getMimeType() throws <strong>Media</strong>Exception;<br />

String getName() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong> getProxy() throws <strong>Media</strong>Exception;<br />

long getSize() throws <strong>Media</strong>Exception;<br />

int readContent (long, byte[]) throws <strong>Media</strong>Exception;<br />

int readContent (long, byte[], int, int) throws <strong>Media</strong>Exception;<br />

}<br />

getContent ()<br />

Returns the complete media content as a byte array. This method is intended for<br />

convenient access to media content up to a few MB in size. Streaming I/O access as<br />

defined in readContent() should be used instead to access large content.<br />

If the resulting byte array size exceeds the theoretical maximum <strong>Java</strong> array size of 2 GB,<br />

a javax.emb.ContentTooLargeException is thrown. A javax.emb.ContentAccessException<br />

is thrown if the content cannot be accessed.<br />

getFormat ()<br />

Queries a suitable media format instance from the <strong>Media</strong>FormatRegistry singleton and<br />

returns it. The file extension contained in the name property is used as a key for this<br />

query.<br />

A javax.emb.FormatNotFoundException is thrown if the file extension is not registered<br />

with the media format registry.<br />

getHeader ()<br />

Returns the receiver's header information. Queries a suitable media format instance from<br />

the <strong>Media</strong>FormatRegistry singleton and determines the header information based on it.<br />

16


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

A javax.emb.FormatNotFoundException is thrown if the file extension is not registered<br />

with the media format registry. A javax.emb.FormatSyntaxException is thrown if the<br />

receiver –s content does not match the syntax defined for the receiver –s media format. A<br />

javax.emb.FormatFeatureException is thrown if the header cannot be extracted because a<br />

vital feature of the media format involved is not supported by the implementation.<br />

A javax.emb.ContentAccessException is thrown if the actual content access fails.<br />

getMimeType ()<br />

Returns a mime type for the receiver's content as a string. This allows media content to<br />

be written directly to a Servlet output stream, as this technique requires a mime type to<br />

be specified in case the output is different from HTML. If no mime type has been set<br />

explicitly a default mime type is returned, possibly based on the receiver –s format.<br />

A javax.emb.FormatNotFoundException is thrown if the receiver –s media format cannot<br />

be determined.<br />

getName ()<br />

Returns the receiver's non-unique name as a String. The name is used as a file name hint<br />

in case the media content is to be stored in a file system and therefore may only contain<br />

characters that are valid in file names. It contains a file extension that represents the<br />

receiver –s media format.<br />

getProxy ()<br />

Returns a media object that can be used as a proxy for the receiver, e.g. a thumbnail, an<br />

icon, a short video/audio clip. Servlets can use this operation whenever a thumbnail or<br />

sound bite is required to represent a given media and give users an up front impression<br />

of the content. The value returned may have any format and is never null.<br />

getSize ()<br />

This operation returns the receiver's content size in number of bytes as a long value.<br />

A javax.emb.ContentAccessException is thrown if there –s a problem accessing the<br />

receiver –s content.<br />

readContent (long position, byte[] buffer)<br />

Similarly to input streams, this method fills the given buffer with content read from the<br />

media object. The media content is copied from the given position, and the buffer is<br />

filled beginning with offset 0. In case the buffer is larger than the amount of bytes<br />

available, it is only partially filled. The buffer may also be filled partially if the<br />

implementation uses non-blocking I/O. The method returns the number of bytes copied<br />

into the buffer, or “1 in case the given position equals the content size.<br />

A java.lang.IndexOutOfBoundsException is thrown if the given position is negative or<br />

exceeding the content size. A java.lang.NullPointerExcetion is thrown if the given buffer<br />

is null. A javax.emb.ContentAccessException is thrown if the actual content access fails.<br />

readContent (long position, byte[] buffer, int offset, int length)<br />

Similar to input streams, this method fills the given buffer with content read from the<br />

media object. The media content is copied from the given position, and the buffer is<br />

17


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

filled beginning from the given offset with a maximum amount of bytes defined by the<br />

given length. In case the buffer is larger than the amount of bytes available, it is only<br />

partially filled. The buffer may also be filled partially if the implementation uses nonblocking<br />

I/O. The method returns the number of bytes copied into the buffer, or “1 in<br />

case the given position equals the content size.<br />

A java.lang.IndexOutOfBoundsException is thrown if the given position is negative or<br />

exceeding the content size, or in case the given offset is negative or exceeding the buffer<br />

size. A java.lang.NegativeArraySizeException is thrown if the given length is negative. A<br />

java.lang.NullPointerExcetion is thrown if the given buffer is null. A<br />

javax.emb.ContentAccessException is thrown if the actual content access fails.<br />

4.2 javax.emb.<strong>Media</strong>Bean<br />

This class implements the <strong>Media</strong> interface and models media objects that are transient,<br />

immutable, and local. In order to avoid excessive memory use, a temporary file may be<br />

used to store and access the media content while an instance is alive.<br />

Please note that only methods added to the basic <strong>Media</strong> interface are described in detail<br />

below.<br />

public class <strong>Media</strong>Bean implements <strong>Media</strong> {<br />

public <strong>Media</strong>Bean(InputStream, String, String) throws <strong>Media</strong>Exception;<br />

public <strong>Media</strong>Bean(File, String) throws <strong>Media</strong>Exception;<br />

public byte[] getContent() throws <strong>Media</strong>Exception;<br />

public <strong>Media</strong>Format getFormat() throws <strong>Media</strong>Exception;<br />

public <strong>Media</strong>Header getHeader() throws <strong>Media</strong>Exception;<br />

public String getMimeType() throws <strong>Media</strong>Exception;<br />

public String getName() throws <strong>Media</strong>Exception;<br />

public <strong>Media</strong> getProxy() throws <strong>Media</strong>Exception;<br />

public long getSize() throws <strong>Media</strong>Exception;<br />

int readContent (long, byte[]) throws <strong>Media</strong>Exception;<br />

int readContent (long, byte[], int, int) throws <strong>Media</strong>Exception;<br />

}<br />

<strong>Media</strong>Bean (InputStream contentStream, String mimeType, String name)<br />

This constructor initializes a new instance with content copied from the given content<br />

stream, and the given mime type and name. The given name is a file name that should<br />

be associated with the object. If the given mimeType is null, one is chosen<br />

automatically by analyzing the given file extension, or <strong>Media</strong>.MIME_TYPE_UNKNOWN is<br />

assigned in case none can be derived.<br />

This constructor is suitable for media content regardless of its size. Please note that the<br />

given input stream is closed once the content is read completely. Also note that a<br />

temporary file is used internally to maintain the content. The implementation tries to<br />

delete this file once the instance is garbage collected, and again once the process dies in<br />

case the former attempt fails.<br />

18


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

A javax.emb.ContentAccessException is thrown if something goes wrong during content<br />

transfer. A java.lang.NullPointerException is thrown if the given content stream or name<br />

is null.<br />

<strong>Media</strong>Bean (File mediaFile, String mimeType)<br />

This constructor wraps a new instance around the given media file. The name property<br />

of the receiver is initialized to the name of the given file (without path information). If<br />

the given mimeType is null, one is chosen automatically by analyzing the file<br />

extension, or <strong>Media</strong>.MIME_TYPE_UNKNOWN is assigned in case none can be derived.<br />

This constructor is useful to invoke a media related service on an existing media file<br />

without copying the content of the latter. Please note that the file is not deleted once an<br />

instance referencing it is garbage collected.<br />

A javax.emb.ContentAccessException is thrown if something goes wrong during content<br />

transfer, or if the given file is not present or cannot be accessed. A<br />

java.lang.NullPointerException is thrown if the given media file is null.<br />

4.3 javax.emb.<strong>Media</strong>Format<br />

This interface is used throughout <strong>Enterprise</strong> <strong>Media</strong> Beans for operations that require<br />

knowledge of the media format. Each specific supported media format requires an<br />

implementation of this interface to handle format specifics correctly. Applications should<br />

not create instances directly using a constructor, but instead query them using the<br />

<strong>Media</strong>FormatRegistry class. As implementations of this interface may have to be<br />

transferred over remote boundaries at times, the <strong>Media</strong>Format interface extends<br />

java.io.Serializable.<br />

public interface <strong>Media</strong>Format extends Serializable {<br />

byte[] assembleContent(URL, <strong>Media</strong>Segment[]) throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>Segment[] disassembleContent(URL, byte[]) throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>Header extractHeader(InputStream) throws <strong>Media</strong>Exception;<br />

<strong>Media</strong> extractProxy(InputStream) throws <strong>Media</strong>Exception;<br />

String getDefaultMimeType();<br />

boolean isEmbedded();<br />

boolean isStreamingDesirable();<br />

}<br />

assembleContent (URL mediaLocation, <strong>Media</strong>Segment[] mediaSegments)<br />

Assembles the given media segments and returns the resulting media content as a byte<br />

array. The optional media location describes where the content itself is stored, and<br />

passing it allows links to child media to be written as relative file paths. In case the<br />

given media location is null, all links in the resulting media content will be URLs. In<br />

case it is not null, those links that can be expressed relative to the given URL will be<br />

relative file paths, and all others will be URLs.<br />

This means a media object that has been disassembled into media segments beforehand<br />

can be reassembled using this operation. The given media location is used to handle<br />

relative links to external media correctly. <strong>Media</strong> Entity Beans use this operation when<br />

19


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

maintaining referential integrity between complex graphs of persistent, non-embedded,<br />

media objects. The implicit limitation of media size to a theoretical limit of 2GB should<br />

not impose a restriction in practice as this operation is only of value for non-embedded<br />

media, which tends to be relatively small in size.<br />

If the resulting byte array size exceeds the theoretical maximum <strong>Java</strong> array size of 2 GB,<br />

a javax.emb.ContentTooLargeException is thrown. A LinkTranslationException is thrown<br />

if there –s a problem transforming one of the media segment child locations into a<br />

format specific link. In case of embedded media formats, a<br />

javax.emb.FormatSyntaxException is thrown if the given media segment array contains<br />

more than one element, or if an element is passed that contains a child link that is not<br />

null. A java.lang.NullPointerException is thrown if the given segment array is null.<br />

disassembleContent (URL mediaLocation, byte[] mediaContent)<br />

Disassembles the given media content into an array of media segments preserving the<br />

order of the original content, and returns said array of media segments. The optional<br />

media location describes where the content itself is stored, and passing it allows relative<br />

links to child media to be interpreted.<br />

In case of simple media formats, the resulting media segment array contains exactly one<br />

element, which consists of null as child location and the complete media content as<br />

content. <strong>Media</strong> Entity Beans use this operation when maintaining referential integrity<br />

between complex graphs of persistent, non embedded, media objects. Note that this<br />

operation is only of value for non-embedded media formats. As the reassembly is limited<br />

to media up to 2GB in size, the <strong>Media</strong>Format.isEmbedded() operation should be<br />

used to determine if disassembling a given media content is of value beforehand.<br />

A javax.emb.FormatSyntaxException is thrown if the content does not match the<br />

expected media format. A javax.emb.LinkTranslationException is thrown if the given<br />

media location is null and the given content contains child links that are not URLs. A<br />

java.lang.NullPointerException is thrown if the content passed is null.<br />

extractHeader (InputStream content)<br />

Extracts a media header instance from the given media content and returns it. The<br />

information presented by the header is up to the implementation of the media format<br />

bean, and the information returned can therefore be the complete header information as<br />

defined in the relevant media format standard, no information at all, or something in<br />

between. However, implementers are encouraged to return header information as<br />

complete as possible, as such information can be highly useful for format specific<br />

algorithms and optimizations.<br />

Please note that the given input stream is not closed once the operation is successfully<br />

completed.<br />

A javax.emb.FormatSyntaxException is thrown if the given media content does not match<br />

the syntax defined for the receiver. A javax.emb.FormatFeatureException is thrown if the<br />

header cannot be extracted because a vital feature of the media format involved is not<br />

supported. A java.lang.NullPointerException is thrown if the value passed is null.<br />

extractProxy (InputStream content)<br />

Extracts a proxy from the given media content and returns it. The proxy may be of any<br />

media format. For example, a key frame image may be returned in case of video<br />

20


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

content, a waveform image in case of audio content, or a thumbnail in case of image<br />

content. In case there –s a problem creating the surrogate, a default format specific proxy<br />

must be returned “ for example Generic<strong>Media</strong>Format.GENERIC_PROXY. Please<br />

note that the given input stream is closed once the operation is completed.<br />

A java.lang.NullPointerException is thrown if the argument passed is null.<br />

getDefaultMimeType ()<br />

Returns the default mime type for the given media format as a String. If there is no<br />

suitable MIME type, <strong>Media</strong>.MIME_TYPE_UNKNOWN should be returned.<br />

isEmbedded ()<br />

Returns false if the media format allows links to external media, or true otherwise. It can<br />

be used to determine if the media content has to be examined and possibly altered<br />

when a persistent media object is moved from one location to another while having<br />

child and/or parent dependencies to other media objects.<br />

isStreamingDesirable ()<br />

Returns true if it is always desirable to stream media of this format, or false otherwise.<br />

For example, it is not always desirable to stream JPEG or GIF images, even given the<br />

possibility to stream them with a Real player. Servlets can use this information to decide<br />

whether they should try to stream content or transfer it using burst transfer instead.<br />

4.4 javax.emb.Generic<strong>Media</strong>Format<br />

This class offers a generic implementation of the <strong>Media</strong>Format interface for use with all<br />

kinds of embedded media formats. Note that this class should not be used to represent<br />

non-embedded media formats, as it does not handle parent/child relationships. By<br />

registering instances of this class with the <strong>Media</strong>FormatRegistry described in the followup<br />

section, various media formats can be supported in case no format specific support is<br />

available.<br />

The public constant DEFAULT_PROXY contains an image that can be used as a default<br />

proxy for all kinds of media formats or in case the generation of a proxy fails for<br />

whatever reason.<br />

public class Generic<strong>Media</strong>Format implements <strong>Media</strong>Format {<br />

public static final <strong>Media</strong> DEFAULT_PROXY;<br />

byte[] assembleContent(URL, <strong>Media</strong>Segment[]) throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>Segment[] disassembleContent(URL, byte[]) throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>Header extractHeader(InputStream) throws <strong>Media</strong>Exception;<br />

<strong>Media</strong> extractProxy(InputStream) throws <strong>Media</strong>Exception;<br />

String getDefaultMimeType();<br />

boolean isEmbedded();<br />

boolean isStreamingDesirable();<br />

}<br />

21


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

assembleContent (URL mediaLocation, <strong>Media</strong>Segment[] mediaSegments)<br />

Returns the content of the given media segment array – s first element, or an empty byte<br />

array if no element is passed.<br />

A javax.emb.FormatSyntaxException is thrown if the given media segment array contains<br />

more than one element, or if an element is passed that contains a child link that is not<br />

null. A java.lang.NullPointerException is thrown if the given segment array is null. A<br />

javax.emb.ContentTooLargeException is thrown if the assembled content is larger than<br />

the maximum <strong>Java</strong> array size of 2 GB.<br />

disassembleContent (URL mediaLocation, byte[] mediaContent)<br />

Disassembles the given media content. As embedded media doesn –t contain any links<br />

and therefore consists of a single media segment, this generic implementation returns a<br />

one-element array of media segments, with a segment element composed of null as<br />

child location and the given media content as content.<br />

A java.lang.NullPointerException is thrown if the content passed is null.<br />

extractHeader (InputStream mediaContent)<br />

Returns an instance of class Generic<strong>Media</strong>Header, as this class cannot make any<br />

assumptions about header fields.<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

extractProxy (InputStream mediaContent)<br />

Returns a default image that is suitable to represent all kinds of content.<br />

getDefaultMimeType ()<br />

Returns <strong>Media</strong>.MIME_TYPE_UNKNOWN, as this class cannot make any assumptions<br />

about mime types.<br />

isEmbedded ()<br />

Returns true, as this class assumes media to be embedded.<br />

isStreamingDesirable ()<br />

Returns false, as this class cannot make any assumptions about media to be streamable<br />

or not.<br />

4.5 javax.emb.<strong>Media</strong>FormatRegistry<br />

This singleton class manages the different header types and allows the generic selection<br />

of a format bean suitable for a given media. The selection criterion is the file extension<br />

associated with the media, and a media format can be registered multiple times if many<br />

file extensions are typically associated with it.<br />

The class has a private default constructor to prevent direct construction of instances in<br />

applications. Instead, the SINGLETON constant provides the one and only instance of<br />

22


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

this class. Implementations are free to initialize the registry with mappings of their<br />

choice. However, the design allows applications to plug in additional mappings.<br />

public final class <strong>Media</strong>FormatRegistry {<br />

public static final <strong>Media</strong>FormatRegistry SINGLETON;<br />

private <strong>Media</strong>FormatRegistry();<br />

public void bind(String, <strong>Media</strong>Format) throws FormatAlreadyBoundException;<br />

public Iterator getFileExtensions();<br />

public <strong>Media</strong>Format lookup(String) throws FormatNotFoundException;<br />

public void rebind(String, <strong>Media</strong>Format);<br />

public void unbind(String) throws FormatNotFoundException;<br />

}<br />

bind (String fileExtension, <strong>Media</strong>Format mediaFormat)<br />

This operation associates the given file extension with the given media format instance.<br />

A javax.emb.FormatAlreadyBoundException is thrown if a mapping already exists for the<br />

given file extension. A java.lang.NullPointerException is thrown if one of the values<br />

passed is null.<br />

getFileExtensions()<br />

This operation returns the file extensions for which bindings exist in the registry.<br />

rebind (String fileExtension, <strong>Media</strong>Format mediaFormat)<br />

This operation associates the given file extension with the given media format instance.<br />

If a mapping already exists for the given file extension, it is replaced by the new one.<br />

A java.lang.NullPointerException is thrown if one of the values passed is null.<br />

unbind (String fileExtension)<br />

This method removes the mapping defined by the given file extension.<br />

A javax.emb.FormatNotFoundException is thrown if there is no mapping for the given<br />

file extension. A java.lang.NullPointerException is thrown if the value passed is null.<br />

lookup (String fileExtension)<br />

Returns the media format instance registered under the given file extension.<br />

A javax.emb.FormatNotFoundException is thrown if there is no mapping for the given<br />

file extension. A java.lang.NullPointerException is thrown if the value passed is null.<br />

4.6 javax.emb.<strong>Media</strong>Segment<br />

This class models a portion of a (usually non-embedded) medium that is optionally<br />

followed by a reference to an external<br />

Medium := { <strong>Media</strong>Segment }<br />

media file represented by a media location <strong>Media</strong>Segment := content [ childLocation ]<br />

URL. The EBNF grammar to the right<br />

Figure 8: <strong>Media</strong> segment definition<br />

23


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

illustrates the relation between media objects and media segments.<br />

Splitting up media content into media segments is useful if references contained have to<br />

be updated, for example because one of the children has moved. In order to handle<br />

such a situation it is necessary to disassemble the media, update the reference, and<br />

reassemble it afterwards. <strong>Media</strong>Format instances provide the operations necessary, and<br />

the <strong>Media</strong>Segment class describes the data container for a single segment.<br />

The value null is a valid value for the childLocation property and indicates that the<br />

segment content is not followed by any reference, for example because the end of<br />

media is reached. The content of media segments is restricted to a theoretical maximum<br />

size of 2GB due to the <strong>Java</strong> restriction of byte array size. However this should not<br />

impose a restriction in practice as non-embedded media tends to be fairly small in size,<br />

and embedded media doesn– t require segmentation at all.<br />

<strong>Media</strong> segments also implement java.io.Serializable in order to allow instances to be<br />

exchanged over remote boundaries.<br />

public class <strong>Media</strong>Segment extends java.io.Serializable {<br />

public <strong>Media</strong>Segment();<br />

public byte[] getContent();<br />

public URL getChildLocation();<br />

public void setContent(byte[]);<br />

public void setChildLocation(URL);<br />

}<br />

<strong>Media</strong>Segment()<br />

Default constructor for media segments. The content field is initialized to an empty byte<br />

array, and the child location field is initialized to null.<br />

getContent ()<br />

Returns the content of the media segment as a byte array.<br />

getChildLocation ()<br />

Returns the media location of a media resource referenced by the receiver.<br />

setContent (byte[] content)<br />

Sets the content of the media segment.<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

setChildLocation (URL childLocation)<br />

Sets the media location of a media resource referenced by the receiver. Passing the value<br />

null is allowed.<br />

24


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

4.7 javax.emb.<strong>Media</strong>Header<br />

The interface <strong>Media</strong>Header defines the common behavior between media header<br />

implementations. All media header instances must allow access to the format specific<br />

header fields by name, in order to allow easy generic access in case some information is<br />

required for browsing purposes. Additionally, all header fields accessible by the<br />

<strong>Media</strong>Header.getField(String) method must be accessible by standard getter methods, too. As<br />

media header instances have to be transferred over machine boundaries at times, this<br />

interface extends java.io.Serializable.<br />

public interface <strong>Media</strong>Header extends Serializable {<br />

}<br />

String[] getFieldNames();<br />

Object getField(String);<br />

getFieldNames ()<br />

Returns an array of Strings containing all the field names defined for the header.<br />

getField (String fieldName)<br />

Returns the field with the given name downcast to java.lang.Object. If the field is<br />

modeled as a <strong>Java</strong> base type, an instance of the corresponding wrapper class has to be<br />

returned. The value null is returned if a field name is passed that is not defined for the<br />

receiver.<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

4.8 javax.emb.Generic<strong>Media</strong>Header<br />

This class offers a generic implementation of the <strong>Media</strong>Header interface. It is suitable for<br />

all kinds of media that don– t expose any header information.<br />

public class Generic<strong>Media</strong>Header implements <strong>Media</strong>Header {<br />

}<br />

public String[] getFieldNames();<br />

public Object getField(String);<br />

getFieldNames ()<br />

Returns an empty array of Strings, as no header information is exposed.<br />

getField (String fieldName)<br />

Returns null regardless of the field name passed.<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

25


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

4.9 javax.emb.<strong>Media</strong>Converter<br />

A media converter performs actual conversions of media content. Implementations of<br />

this interface can work in one of two ways: Synchronous converters perform conversions<br />

completely before returning the input stream on the converted content. Asynchronous<br />

converters return a piped input stream immediately after checking the input and<br />

spawning a new thread to perform the conversion. The latter has the advantage of being<br />

very memory efficient in case the result is consumed immediately, while the first tends to<br />

be more robust because it doesn –t require the maintenance of additional threads of<br />

execution.<br />

The design assumes a converter is instantiated for a specific kind of conversion.<br />

Therefore, classes implementing this interface should take a media converter spec as a<br />

constructor argument. Said media converter spec should contain the necessary<br />

conversion parameters, for example the desired bandwidth for a WAV to MP3 converter.<br />

public interface <strong>Media</strong>Converter {<br />

InputStream process (InputStream) throws <strong>Media</strong>Exception;<br />

void process (InputStream, OutputStream) throws <strong>Media</strong>Exception;<br />

}<br />

process (InputStream inputStream)<br />

Converts the media content offered on the given input stream and returns the converted<br />

media content as an input stream. Implementations of this method may, but are not<br />

required to, spawn a new thread to perform the actual conversion, and return a<br />

PipedInputStream immediately.<br />

A java.lang.NullPointerException is thrown if the value passed is null. A<br />

javax.emb.FormatSyntaxException is thrown if the content provided with the input<br />

stream does not meet the expected format syntax. A javax.emb.FormatFeatureException<br />

is thrown if the content provided in the input stream uses a format feature not supported<br />

by the receiver. A javax.emb.LinkTranslationException is thrown if the content provided<br />

contains relative links to child media objects. A javax.emb.ContentAccessException is<br />

thrown if an I/O problem occurs or if said child links cannot be resolved to child media<br />

content. A javax.emb.ConversionException is thrown if the conversion fails because a<br />

conversion specific problem occurred.<br />

process (InputStream inputStream, OutputStream outputStream)<br />

Converts the media content offered on the given input stream and writes the converted<br />

media content on the given output stream. In any case, this method will block until the<br />

conversion is completed.<br />

A java.lang.NullPointerException is thrown if one the values passed is null. A<br />

javax.emb.FormatSyntaxException is thrown if the content provided with the input<br />

stream does not meet the expected format syntax. A javax.emb.FormatFeatureException<br />

is thrown if the content provided in the input stream utilizes a format feature not<br />

supported by the receiver. A javax.emb.LinkTranslationException is thrown if the content<br />

provided contains relative links to child media objects. A<br />

javax.emb.ContentAccessException is thrown if an I/O problem occurs or if said child<br />

links cannot be resolved to child media content. A javax.emb.ConversionException is<br />

thrown if the conversion fails because a conversion specific problem occurred.<br />

26


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

4.10 javax.emb.<strong>Media</strong>ConverterSpec<br />

An instance of a class implementing this interface collects all properties necessary to<br />

perform a conversion from a specific source format to a specific target format. One or<br />

more converter spec classes correspond to one converter class, and the contract for<br />

accessing the conversion parameters is up to the implementers of the converter spec<br />

classes.<br />

A conversion spec instance can be reused for multiple conversions. Also,<br />

implementations of this interface must provide a default constructor that initializes all<br />

properties with suitable values, in order to allow default conversions. As converter specs<br />

sometimes have to be transferred over machine boundaries, this interface extends<br />

java.io.Serializable. The design allows various parties to come up with implementations<br />

for various combinations of media formats.<br />

public interface <strong>Media</strong>ConverterSpec extends Serializable {<br />

<strong>Media</strong>Converter getConverter() throws <strong>Media</strong>Exception;<br />

String getTargetFileExtension();<br />

String getTargetMimeType();<br />

}<br />

getConverter ()<br />

Returns an object implementing the <strong>Media</strong>Converter interface that can be used to<br />

process conversions using the receiver. The instance returned is initialized with the<br />

receiver to define the conversion specific parameters.<br />

A javax.emb.ConversionException is thrown if the instantiation of the converter fails.<br />

getTargetMimeType ()<br />

Returns a MIME type as a String that can be used as a default for media objects created<br />

using the receiver. A result of null indicates that the receiver does not alter the media<br />

format of the content offered on the given input stream.<br />

getTargetFileExtension ()<br />

Returns a file extension as a String that can be used as a default for media objects<br />

created using the receiver. The String must not include any separator characters. A result<br />

of null indicates that the receiver does not alter the media format of the content offered<br />

on the given input stream.<br />

27


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

4.11 javax.emb.<strong>Media</strong>Exception<br />

This exception is root to most application specific exceptions thrown by <strong>Enterprise</strong><br />

<strong>Media</strong> Beans components. The idea is to abstract over the specific causes of exceptional<br />

behavior as the causes of such behavior can differ a lot between different <strong>Enterprise</strong><br />

<strong>Media</strong> Beans implementations. As this would prevent applications to be written in an<br />

implementation independent way, these causes have to be mapped to a unified<br />

exception model.<br />

public class <strong>Media</strong>Exception extends Exception {<br />

}<br />

<strong>Media</strong>Exception();<br />

<strong>Media</strong>Exception(String);<br />

<strong>Media</strong>Exception(String, Throwable);<br />

<strong>Media</strong>Exception(Throwable);<br />

There are various subclasses of this exception class to distinguish specific exception<br />

causes. <strong>Media</strong> Format Beans use the exception classes below, while some more are<br />

defined with <strong>Media</strong> Entity Beans in the next chapter. Note that the additional exception<br />

constructors defined in JDK 1.4 are provided in order to enable consistent exception<br />

chaining.<br />

4.12 javax.emb.ContentAccessException<br />

This exception extends javax.emb.<strong>Media</strong>Exception and is thrown whenever access to<br />

media content fails, be it because a file is not found, there's missing access rights to a file<br />

or subsystem, a subsystem or file is temporarily blocked for access, or content<br />

transmission fails.<br />

4.13 javax.emb.<strong>Media</strong>FormatException<br />

This exception extends javax.emb.<strong>Media</strong>Exception and is thrown whenever a problem<br />

occurs in dealing with a media format. Usually, this exception is not thrown directly.<br />

Instead, instances of its subclasses are thrown to indicate a more specific reason for the<br />

problem. Standardized subclasses of this exception class are<br />

javax.emb.FormatSyntaxException,<br />

javax.emb.FormatFeatureException,<br />

javax.emb.FormatNotFoundException and javax.emb.FormatAlreadyBoundException.<br />

4.14 javax.emb.ContentTooLargeException<br />

This exception extends javax.emb.<strong>Media</strong>Exception and is thrown whenever the creation<br />

of a byte array is attempted that exceeds 2GB in size (the current hard limit of byte array<br />

size in <strong>Java</strong>).<br />

28


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

4.15 javax.emb.ConversionException<br />

This exception extends javax.emb.<strong>Media</strong>Exception and is thrown if the actual conversion<br />

of media content from one format to another fails and the reason for this is not related to<br />

the media formats involved, but rather because of a limitation of the converter. For<br />

example, a BMP to JPEG converter can fail because it does not support a specific format<br />

feature in the source, while the format bean handling the input format itself may well<br />

support this feature.<br />

4.16 javax.emb.FormatAlreadyBoundException<br />

This exception extends javax.emb.<strong>Media</strong>FormatException and is thrown whenever a<br />

media format cannot be bound to the media format registry because another media<br />

format instance is already bound for the file extension specified.<br />

4.17 javax.emb.FormatFeatureException<br />

This exception extends javax.emb.<strong>Media</strong>FormatException and is thrown whenever media<br />

content matches the overall syntax defined for a media format, but uses a feature that is<br />

not supported by the media format implementation, for example a specific sub-format.<br />

For example, a format bean for the BMP format that supports Windows BMP format only<br />

will throw such an exception when analyzing a BMP object featuring OS/2 BMP<br />

definitions.<br />

4.18 javax.emb.FormatNotFoundException<br />

This exception extends javax.emb.<strong>Media</strong>FormatException and is thrown whenever a<br />

media format cannot be determined. Usually the media format registry throws this<br />

exception.<br />

4.19 javax.emb.FormatSyntaxException<br />

This exception extends javax.emb.<strong>Media</strong>FormatException and is thrown whenever media<br />

content does not match the syntax defined for its media format.<br />

4.20 javax.emb.LinkTranslationException<br />

This exception extends javax.emb.<strong>Media</strong>Exception and is thrown whenever a problem<br />

occurs translating a child link contained in non-embedded media content into a location<br />

URL or vice versa, for example because a relative filename is present when only absolute<br />

links are allowed.<br />

29


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

4.21 javax.emb.MalformedLocationException<br />

This exception extends javax.emb.<strong>Media</strong>Exception and is thrown if a location URL is not<br />

a valid URL, or if it does not have a supported protocol type (like example "file").<br />

30


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

Chapter 5<br />

<strong>Media</strong> Entity Beans<br />

<strong>Media</strong> Entity Beans are based on EJB entity beans and are designed to be implemented<br />

with either container-managed persistence (CMP), bean managed persistence (BMP), or a<br />

combination of both. At the core they are media entity EJBs, which model media that is<br />

persistent and mutable. They extend the services offered in the basic javax.emb.<strong>Media</strong><br />

interfaces with parent/child relationship management for non-embedded media,<br />

metadata management, version management, and a media listener for extendibility.<br />

<strong>Media</strong> Entity Beans allow a tight integration of rich media data into the EJB programming<br />

model as they extend the standard EJB transaction and security models to media data<br />

and can be included directly in EJB entity bean relationships. Also, they offer a powerful<br />

abstraction over server side protocol handlers like stream servers, which removes<br />

dependencies from applications.<br />

<strong>Media</strong>Entity<br />

Constraints<br />

utilize<br />

<strong>Media</strong>EntityLocal<br />

*<br />

*<br />

MetaDataEntityLocal<br />

original /<br />

proxy<br />

*<br />

*<br />

0 .. 1<br />

*<br />

<strong>Media</strong>EntityLocalHome<br />

<strong>Media</strong> Entity EJB<br />

content /<br />

metadata<br />

0 .. 1 0 .. 1<br />

predecessor<br />

/ successor<br />

0 .. 1 0 .. 1<br />

0 .. 1<br />

*<br />

MetaDataEntityLocalHom<br />

e<br />

Meta Data Entity EJB<br />

parent /<br />

child<br />

parent /<br />

child<br />

<strong>Media</strong>Listener<br />

observ<br />

e<br />

1<br />

*<br />

Figure 9: <strong>Media</strong> Entity Beans components and interactions<br />

<strong>Media</strong> Entity EJBs can be extended by using media listeners, custom persistent observers<br />

that are notified of changes in the persistent state of <strong>Media</strong> Entity EJBs. For example,<br />

media listeners can be used to trigger recalculations in depending business objects, clean<br />

up related resources if a media entity EJB is removed, or count access to the entity if<br />

fulfillment or monitoring is required.<br />

Additionally, <strong>Media</strong> Entity EJBs relate to MetaData Entity EJBs that model XML metadata.<br />

Such metadata can be used for XPATH or full text based queries. The design is both<br />

31


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

open and pluggable; it allows implementations to support multiple query languages,<br />

which makes sure existing and upcoming standards for said can be supported.<br />

<strong>Media</strong> entity EJBs also maintain some relationships among each other:<br />

• Parent/child relations model the relationship between non-embedded content and<br />

the files referenced from within it. Every parent can have many children, and every<br />

child can have many parents. The Parent / child relationship is maintained<br />

automatically by parsing (assembling / dissembling) content once it is inserted, using<br />

some of the format related function introduced in the <strong>Media</strong> Foundation Beans.<br />

• Original / proxy relationships allow content to be associated with a representative,<br />

like a thumbnail, sound bite, key frame, etc. Furthermore, implementations of this<br />

specification may choose to generate and cache representatives automatically.<br />

• Predecessor / successor relationships offer simple versioning support.<br />

Although it would have been nice to have both local and remote interface definitions for<br />

the API, it is limited to local interfaces only. The reason for this is that many method<br />

names would have had to be duplicated in case local and remote methods only<br />

distinguish themselves with their return types (local and home interface types). As this<br />

became too complicated to use and with the industry moving away from using remote<br />

entity bean interfaces, we decided to restrict the API to local interfaces only. If an<br />

application needs to invoke the methods remotely, a stateless session bean facade can<br />

be used to do so.<br />

32


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

5.1 javax.emb.<strong>Media</strong>EntityLocal<br />

This basic interface extends the javax.emb.<strong>Media</strong> interface with behavior common to all<br />

kinds of media objects that are persistent and can be altered. It also extends<br />

EJBLocalObject and therefore represents the local interface of a media entity EJB.<br />

<strong>Media</strong> Entity EJB<br />

content<br />

location<br />

description<br />

name<br />

mimeType<br />

Figure 10: <strong>Media</strong> Entity EJB alterable properties<br />

<strong>Media</strong> Entity EJBs consist of the five basic alterable properties:<br />

• The content property models the byte content of a media entity EJB. As such content<br />

can become rather large, additional streaming I/O accessors are provided in addition<br />

to the standard set of get/set methods. The content length of a single media entity<br />

EJB is not limited to 2GB; it can theoretically be up to about 9 hexabytes (2^63) in<br />

size. Note that the presence of the content property does not mean an<br />

implementation has to load the media content into memory; as most<br />

implementations will avoid this to keep memory consumption at bay. Also note that<br />

the content property is correlated to the location property, i.e. the content property<br />

cannot be set if the location property is set and vice versa. The default value for this<br />

property is null.<br />

• The location property allows a media entity to gain read access to externally<br />

managed content, as opposed to the content property which models internally<br />

managed content. For example, a location URL can point to an HTTP site that hosts<br />

an image. If the location property is set, read access to the content is possible, but<br />

all operations requiring write access to the content will fail. The location property is<br />

correlated to the content property, i.e. the location property cannot be set if the<br />

content property is set and vice versa. The default value for this property is null.<br />

• The description property allows a textual description to be associated with a media<br />

entity EJB, for example to be displayed in conjunction with some thumbnail in an<br />

image list for orientation. The default value for this property is null.<br />

• The name property models a file name that is used as a default in case the content<br />

has to be exported to a file. The media format of a media entity EJB is derived from<br />

the file name extension. The default value for this property is null.<br />

• The mimeType property is used to hint web application programmers of which<br />

mime type to use when transferring content directly over HTTP. The default value<br />

33


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

for this property is null, but unless both the mimeType and name properties are<br />

null the mimeType accessor will provide a format specific default mime type.<br />

Note that the following method descriptions repeat the javax.emb.<strong>Media</strong> method<br />

descriptions in italics for convenience.<br />

public interface <strong>Media</strong>EntityLocal extends EJBLocalObject, <strong>Media</strong> {<br />

void addListener(<strong>Media</strong>Listener) throws <strong>Media</strong>Exception;<br />

void addMetaData(MetaDataEntityLocal) throws <strong>Media</strong>Exception;<br />

void convert(<strong>Media</strong>ConverterSpec[]) throws <strong>Media</strong>Exception;<br />

URL export<strong>Media</strong>(URL) throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>EntityLocal[] getChildren() throws <strong>Media</strong>Exception;<br />

byte[] getContent() throws <strong>Media</strong>Exception;<br />

String getDescription() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>Format getFormat() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>Header getHeader() throws <strong>Media</strong>Exception;<br />

long getLastModified() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>Listener[] getListeners() throws <strong>Media</strong>Exception;<br />

URL getLocation() throws <strong>Media</strong>Exception;<br />

MetaDataEntityLocal[] getMetaData() throws <strong>Media</strong>Exception;<br />

String getMimeType() throws <strong>Media</strong>Exception;<br />

String getName() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>EntityLocal getNextVersion() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>EntityLocal[] getParents() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>EntityLocal getPreviousVersion() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong> getProxy() throws <strong>Media</strong>Exception;<br />

long getSize() throws <strong>Media</strong>Exception;<br />

void import<strong>Media</strong>(URL, String) throws <strong>Media</strong>Exception;<br />

int readContent (long, byte[]) throws <strong>Media</strong>Exception;<br />

int readContent (long, byte[], int, int) throws <strong>Media</strong>Exception;<br />

void removeListener(<strong>Media</strong>Listener) throws <strong>Media</strong>Exception;<br />

void removeMetaData(MetaDataEntityLocal) throws <strong>Media</strong>Exception;<br />

void setChildren(<strong>Media</strong>EntityLocal[]) throws <strong>Media</strong>Exception;<br />

void setContent(byte[]) throws <strong>Media</strong>Exception;<br />

void setContent(InputStream) throws <strong>Media</strong>Exception;<br />

void setDescription(String) throws <strong>Media</strong>Exception;<br />

void setLocation(URL) throws <strong>Media</strong>Exception;<br />

void setMimeType(String) throws <strong>Media</strong>Exception;<br />

void setName(String) throws <strong>Media</strong>Exception;<br />

void setPreviousVersion(<strong>Media</strong>EntityLocal) throws <strong>Media</strong>Exception;<br />

void setProxy(<strong>Media</strong>EntityLocal) throws <strong>Media</strong>Exception;<br />

}<br />

addListener (<strong>Media</strong>Listener listener)<br />

Adds the given listener to the list of persistent observers that are notified of important<br />

state changes or activities inside the receiver. If the given listener is already part of the<br />

receiver –s list of persistent observers, no action is performed. Note that listeners are<br />

distinguished using checks for content equality, not content identity.<br />

34


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

addMetaData (MetaDataEntityLocal metaData)<br />

Adds the given metadata to the receiver –s list of associated metadata. Metadata consists<br />

of XML content that has been stored in separate MetaDataEntity EJBs. Several<br />

applications can associate XML metadata with a single media entity. If the given<br />

metadata EJB is already part of the receiver –s list of metadata entities, no action is<br />

performed.<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

convert (<strong>Media</strong>ConverterSpec[] specifications)<br />

This operation updates the receiver's content after performing a series of transformations<br />

on the original content, as defined in the given specifications array. The order of the<br />

specifications array defines the order of the transformations being performed. This allows<br />

modification of the receiver without transferring the content over machine boundaries.<br />

Note that the receiver's format can change due to this operation, and that it implicitly<br />

updates the receiver –s lastModified property. Also note that this operation will fail if the<br />

location property is set.<br />

A java.lang.NullPointerException is thrown if the value passed is null. A<br />

javax.emb.ContentAccessException is thrown in case the content cannot be accessed. A<br />

javax.emb.ContentUnmutableException is thrown if the location property is not null. A<br />

javax.emb.<strong>Media</strong>FormatException is thrown in case a problem occurs handling the<br />

different media formats involved. A javax.emb.ConversionException is thrown if one of<br />

the conversions fails. A javax.emb.ListenerVetoException is thrown if a media listener<br />

vetoes the change. A javax.emb.ContentTooLargeException is thrown if the content<br />

generated is larger than supported by the implementation.<br />

export<strong>Media</strong> (URL targetDirectoryLocation)<br />

Copies the receiver –s content to the given target directory location, a URL pointing to a<br />

directory. If null is passed, the content is exported to a default directory. The URL must<br />

be of protocol type ”file or any additional protocol supported by the implementation. In<br />

case of non-embedded media formats, the content of related children is also recursively<br />

copied into the same directory or one of its subdirectories. Implementations must<br />

guarantee that no existing files are overwritten during execution, i.e. they must resolve<br />

naming conflicts by generating file names and adjusting parent content if necessary.<br />

The location returned points to the file exported for the receiver, which is necessary to<br />

know in case a directory location was given, or the location given pointed to an existing<br />

file.<br />

A javax.emb.ContentAccessException is thrown if the content cannot be stored at the<br />

given target location, or if the content transfer fails. A<br />

javax.emb.MalformedLocationException is thrown if the given target location is<br />

malformed or the given protocol is not supported. An instance of a subclass of<br />

javax.emb.<strong>Media</strong>FormatException is thrown if there is a problem dealing with one of the<br />

media formats involved.<br />

35


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

getChildren ()<br />

Returns the receiver's children as an array of media entities. Children are media entities<br />

being referenced from within the receiver's content, and the array is therefore<br />

guaranteed to be empty in case of embedded media formats.<br />

Note that in case of non-embedded media formats a change of the media content can<br />

implicitly alter the set of children. Also note that altering the resulting array content will<br />

not alter the persisted set of children, i.e. no persistent relationship collection is exposed.<br />

The reason for this is that the number of children depends on the content.<br />

getContent ()<br />

Returns the complete media content as a byte array. This method is intended for<br />

convenient access to media content up to a few MB in size. Streaming I/O access as<br />

defined in readContent() should be used to access large content instead.<br />

Note that the value returned may be based either on the content property or the location<br />

property in case the implementation is able to access the content referenced by the<br />

latter.<br />

If the resulting byte array size exceeds the theoretical maximum <strong>Java</strong> array size of 2 GB,<br />

a javax.emb.ContentTooLargeException is thrown. A javax.emb.ContentAccessException<br />

is thrown if the content is null or cannot be accessed.<br />

getDescription ()<br />

Returns the receiver's description as a String or null. The string is not guaranteed to<br />

have any structure, and is primarily designed to allow storing a descriptive label without<br />

the need to model an EJB relation to another entity bean describing the receiver.<br />

getFormat ()<br />

Queries a suitable media format instance from the <strong>Media</strong>FormatRegistry singleton and<br />

returns it. The file extension contained in the name property is used as a key for this<br />

query.<br />

A javax.emb.FormatNotFoundException is thrown if the file extension is not registered<br />

with the media format registry or if the name property is null.<br />

getHeader ()<br />

Returns the receiver's header information. Queries a suitable media format instance from<br />

the <strong>Media</strong>FormatRegistry singleton and determines the header information based on it.<br />

A javax.emb.FormatNotFoundException is thrown if the file extension is not registered<br />

with the media format registry. A javax.emb.FormatSyntaxException is thrown if the<br />

receiver –s content does not match the syntax defined for the receiver –s media format. A<br />

javax.emb.FormatFeatureException is thrown if the header cannot be extracted because a<br />

vital feature of the media format involved is not supported.<br />

getLastModified ()<br />

Returns a timestamp stating when the receiver's persistent state was last modified. Note<br />

that relationships are not considered part of the persistent state and therefore don –t<br />

affect the value of this property.<br />

36


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

getListeners ()<br />

Returns an array containing the media listeners associated with the receiver. If no<br />

listeners are associated with the receiver, an empty array is returned. Note that listeners<br />

are distinguished using checks for content equality, not content identity.<br />

getLocation ()<br />

Returns the location of the media content as an instance of java.net.URL or null if no<br />

location has been set.<br />

getMetaData ()<br />

Returns the receiver –s associated metadata as an array of MetaDataEntity EJBs. Metadata<br />

consists of XML content that has been stored in separate MetaDataEntity EJBs. Several<br />

applications can associate their metadata with a single MetaDataEntity EJB. An empty<br />

array is returned if no metadata has been set.<br />

getMimeType ()<br />

Returns a mime type for the receiver's content as a string. This allows media content to<br />

be written directly to a Servlet output stream, as this technique requires a mime type to<br />

be specified in case the output is different from HTML. . If no mime type has been set<br />

explicitly a default mime type is returned, possibly based on the receiver –s format.<br />

A javax.emb.FormatNotFoundException is thrown if the mimeType property is null and<br />

no format can be determined.<br />

getName ()<br />

Returns the receiver's non-unique name as a String or null. The name is used as a file<br />

name hint in case the media content is to be stored in a file system and therefore may<br />

only contain characters that are valid in file names. Also, it must contain a file extension<br />

that represents the receiver– s media format.<br />

getNextVersion ()<br />

Returns the succeeding version of the receiver, which allows querying and a history<br />

chain of media objects that represent the same thing. The value null is returned if no<br />

next version exists.<br />

getParents ()<br />

Returns the receiver's parents as an array of media entities. Parents are media entities<br />

that reference the receiver as their child, and the collection is therefore guaranteed to<br />

consist entirely of non-embedded media entities. Note that changing parents – content<br />

can alter a child media entitie –s set of parents implicitly. An empty array is returned if<br />

no parents are available.<br />

getPreviousVersion ()<br />

Returns the previous version of the receiver, which allows querying a history of media<br />

objects that represent the same logical thing. The value null is returned if no previous<br />

version exists.<br />

37


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

getProxy ()<br />

Returns a media object that can be used as a proxy for the receiver, e.g. a thumbnail, an<br />

icon, a short video/audio clip. Servlets can use this operation whenever a thumbnail or<br />

sound bite is required to represent a given media and give users an up front impression<br />

of the content. The value returned may have any format and may never be null.<br />

If a proxy relationship was explicitly set using setProxy() with a non-null value, the<br />

persistent proxy set is to be returned. Otherwise, a transient proxy is generated on the<br />

fly using the <strong>Media</strong>Format.extractProxy() operation and returned. Note that no<br />

proxy relationship can be defined with such a transient proxy. However,<br />

implementations are free to use an additional cache mechanism for the transient proxies<br />

in order to improve performance.<br />

A javax.emb.<strong>Media</strong>FormatException is thrown if there – s a problem handling aspects of<br />

the receiver –s content. A javax.emb.ContentAccessException is thrown if there – s a<br />

problem reading the receiver –s content.<br />

getSize ()<br />

This operation returns the receiver's content size in number of bytes as a long value.<br />

A javax.emb.ContentAccessException is thrown if there –s a problem accessing the<br />

receiver –s content.<br />

import<strong>Media</strong> (URL sourceLocation, String name)<br />

Alters the content of the receiver with the one read from the given source location, a<br />

URL of type ”file or any other protocol type supported by the implementation pointing<br />

to a piece of content. If the given name is not null, the name property is also set to<br />

match the given name. It may only contain characters that are valid in file names. If both<br />

the name property and the name given are null the name property is updated with a<br />

generated name, possibly based on the given source location.<br />

In case the media content is non-embedded, the operation recursively creates media<br />

entity EJBs for the children, with their respective names being derived from the child<br />

links within the content. Note that the operation identifies children that are referenced<br />

from multiple parents in the operation – s context and avoids creating multiple media<br />

entity EJBs in this case.<br />

Please note that passing a sourceLocation that is equal to the receiver –s current location<br />

is allowed and can trigger the recursive recreation of all children. Additionally the<br />

receiver's format can change due to this operation if the file extension passed with the<br />

given name differs from the one set for the receiver. Also note that this operation<br />

implicitly updates the receiver –s lastModified property, and it will fail if the location<br />

property is set.<br />

A java.lang.NullPointerException is thrown if the value passed is null. A<br />

java.lang.IllegalArgumentException is thrown if the name argument passed contains<br />

invalid characters. A javax.emb.ContentAccessException is thrown if the content cannot<br />

be accessed at the given source location, or if the content transfer fails. A<br />

javax.emb.ContentUnmutableException is thrown if the location property is not null. A<br />

javax.ejb.CreateException is thrown if the creation of a child EJB fails. An instance of a<br />

subclass of javax.emb.<strong>Media</strong>FormatException is thrown if a format related problem<br />

occurs. A javax.emb.MalformedLocationException is thrown if the given source location<br />

38


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

is malformed. A javax.emb.ListenerVetoException is thrown if a media listener vetoes the<br />

change. A javax.emb.ContentTooLargeException is thrown if the content given is larger<br />

than supported by the implementation.<br />

readContent (long position, byte[] buffer)<br />

Similarly to input streams, this method fills the given buffer with content read from the<br />

media object. The media content is copied from the given position, and the buffer is<br />

filled beginning with offset 0. If the buffer is larger than the number of bytes available, it<br />

is only partially filled. The buffer may also be filled partially if the implementation uses<br />

non-blocking I/O. The method returns the number of bytes copied into the buffer, or “1<br />

if the given position equals the content size.<br />

Note that the value returned may be based either on the content property or the location<br />

property if the implementation is able to access the content referenced by the latter.<br />

A java.lang.IndexOutOfBoundsException is thrown if the given position is negative or<br />

exceeds the content size. A java.lang.NullPointerException is thrown if the given buffer is<br />

null. A javax.emb.ContentAccessException is thrown if the actual content access fails.<br />

readContent (long position, byte[] buffer, int offset, int length)<br />

Similar to input streams, this method fills the given buffer with content read from the<br />

media object. The media content is copied from the given position, and the buffer is<br />

filled beginning from the given offset with a maximum number of bytes defined by the<br />

given length. If the buffer is larger than the number of bytes available, it is only partially<br />

filled. The buffer may also be filled partially if the implementation uses non-blocking<br />

I/O. The method returns the number of bytes copied into the buffer, or “1 if the given<br />

position equals the content size.<br />

Note that the value returned may be based either on the content property or the location<br />

property if the implementation is able to access the content referenced by the latter.<br />

A java.lang.IndexOutOfBoundsException is thrown if the given position is negative or<br />

exceeds the content size, or if the given offset is negative or exceeds the buffer size. A<br />

java.lang.NegativeArraySizeException is thrown if the given length is negative. A<br />

java.lang.NullPointerExcetion is thrown if the given buffer is null. A<br />

javax.emb.ContentAccessException is thrown if the actual content access fails.<br />

removeListener (<strong>Media</strong>Listener listener)<br />

Removes the given listener from the list of persistent observers that are notified of<br />

important state changes or activities inside the receiver. If the listener is not part of the<br />

receiver –s list of persistent observers, no action is performed. Note that listeners are<br />

distinguished using checks for content equality, not content identity.<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

removeMetaData (MetaDataEntityLocal metaData)<br />

Removes the given metadata from the receiver –s list of associated metadata. Metadata<br />

consists of XML content that has been stored in MetaDataEntity EJBs. Several applications<br />

can associate XML metadata with a single media entity. If the given metadata EJB is not<br />

part of the receiver –s list of metadata entities, no action is performed.<br />

39


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

Note that this operation will not remove the MetaDataEntity EJB from the persistent<br />

store, but rather disassociate the metadata from the <strong>Media</strong> Entity on which the method<br />

was invoked.<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

setChildren (<strong>Media</strong>EntityLocal[] children)<br />

This operation sets the children of the receiver to an array of media entity EJBs. Note<br />

that the number of children passed must match the number of existing children. Also<br />

note that this operation is only allowed if the content property is set because it might<br />

require updating said content.<br />

A java.lang.NullPointerException is thrown if the value passed or one of its elements is<br />

null. A java.lang.IllegalArgumentException is thrown if the value passed has more or<br />

fewer elements than the receiver –s existing number of children. A<br />

javax.emb.ContentUnmutableException is thrown if the location property is set. A<br />

javax.emb.ContentAccessException is thrown if the content has not been set.<br />

setContent (byte[] content)<br />

This operation offers a convenient way to alter the content of the receiver for small and<br />

embedded media content. In case the content is non-embedded, the<br />

import<strong>Media</strong>(URL, String) operation should be used instead, as this method only<br />

modifies the receiver –s content and no child content is affected. The same is true if the<br />

content is rather large.<br />

If both the value passed and the receiver –s existing content property are not null, no<br />

format change may occur during this operation. If the location property is not null then<br />

this operation is not permitted. Note that the location property may not be set while the<br />

content property contains a value different from null. Note that this operation implicitly<br />

updates the receiver –s lastModified property. Also note that this operation will fail if the<br />

location property is set.<br />

A javax.emb.ContentAccessException is thrown if content transfer fails. A<br />

javax.emb.FormatNotFoundException is thrown if the name property is null. A<br />

javax.emb.FormatSyntaxException is thrown if the system notices a format change. A<br />

javax.emb.ContentUnmutableException is thrown if the location property is not null. A<br />

javax.emb.ContentTooLargeException is thrown if the content given is larger than<br />

supported by the implementation.<br />

setContent (InputStream content)<br />

This operation offers a convenient way to alter the content of the receiver for all kinds of<br />

embedded media formats. If the content is non-embedded, the import<strong>Media</strong>(URL,<br />

String) operation should be used instead, as this method only modifies the receiver – s<br />

content and no child content is affected. The same is true if the content is rather large.<br />

If both the value passed and the receiver –s existing content property are not null, no<br />

format change may occur during this operation. If the location property is not null, this<br />

operation is not permitted. The location property may not be set while the content<br />

property contains a value different from null. Note that this operation implicitly<br />

updates the receiver –s lastModified property. Also note that this operation will fail if the<br />

location property is set.<br />

40


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

A java.lang.NullPointerException is thrown if the value passed is null. A<br />

javax.emb.ContentAccessException is thrown if content transfer fails. A<br />

javax.emb.FormatNotFoundException is thrown if the name property is null. A<br />

javax.emb.FormatSyntaxException is thrown if the system notices a format change. A<br />

javax.emb.ContentUnmutableException is thrown if the location property is not null. A<br />

javax.emb.ListenerVetoException is thrown if a media listener vetoes the change. A<br />

javax.emb.ContentTooLargeException is thrown if the content given is larger than<br />

supported by the implementation.<br />

setDescription (String description)<br />

Alters the receiver –s description. The description string is primarily designed to allow<br />

storing a descriptive label without the need to model an EJB relation to another entity<br />

bean describing the receiver. Passing null causes the description field to be reset to<br />

null. Note that this operation implicitly updates the receiver –s lastModified property.<br />

A javax.emb.ListenerVetoException is thrown if a media listener vetoes the change.<br />

setLocation (URL location)<br />

Sets the location of the receiver to the given location URL or null. The purpose of this<br />

method is to provide a mechanism for read access to externally managed content. For<br />

example, content that is hosted by an external content provider.<br />

Note that if the content property is not null, this operation is not permitted. Note that<br />

the content property may not be set while the location property contains a value<br />

different from null. Also note that this operation implicitly updates the receiver –s<br />

lastModified property.<br />

A javax.emb.ContentAccessException is thrown if the media content cannot be accessed<br />

under the new location, or if the given location URL points to a directory. A<br />

javax.emb.LocationUnmutableException is thrown if the content property is not null. A<br />

javax.emb.ListenerVetoException is thrown if a media listener vetoes the change.<br />

setMimeType (String mimeType)<br />

Alters the receiver – s MIME type that allows media content to be written directly to a<br />

Servlet output stream. Note that this operation implicitly updates the receiver –s<br />

lastModified property. Note that passing null will cause the getMimeType() method<br />

to return a format specific default. Also note that this operation implicitly updates the<br />

receiver –s lastModified property. A javax.emb.ListenerVetoException is thrown if a<br />

media listener vetoes the change.<br />

setName (String name)<br />

Sets the receiver –s non-unique name as a String. The name is used as a file name hint in<br />

case the media content is to be stored or published in a file system and therefore may<br />

only contain characters that are valid in file names. Also, it must contain a file extension<br />

that represents the receiver– s media format. Note that this operation implicitly updates<br />

the receiver –s lastModified property.<br />

A java.lang.NullPointerException is thrown if the value passed is null. A<br />

java.lang.IllegalArgumentException is thrown if the name argument passed contains<br />

invalid characters. A javax.emb.FormatNotFoundException is thrown if the format cannot<br />

41


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

be determined from the file extension. A javax.emb.ListenerVetoException is thrown if a<br />

media listener vetoes the change.<br />

setPreviousVersion (<strong>Media</strong>EntityLocal mediaEntity)<br />

Defines the given media entity to be the preceding version of the receiver, which allows<br />

querying a history chain of media objects that represent the same logical thing. In return,<br />

the operation causes the receiver to be the given media entity –s next version. Passing<br />

the value null causes the receiver not to have a previous version anymore. The<br />

operation is only allowed if version chain integrity is preserved:<br />

• If the given media entity is the receiver itself: A<br />

javax.emb.VersionChainIntegrityException is thrown.<br />

• If the given media entity is already the previous version of the receiver: No action is<br />

performed.<br />

• If the given media entity is null: A javax.emb.VersionChainIntegrityException is<br />

thrown if the receiver has a successor.<br />

• Otherwise: A javax.emb.VersionChainIntegrityException is thrown if the given media<br />

entity has a successor, or if the receiver has a predecessor, a successor, or both.<br />

setProxy (<strong>Media</strong>EntityLocal mediaEntity)<br />

Sets the given media entity as the receiver –s persistent proxy, e.g. a thumbnail, an icon,<br />

a short video or audio clip of any format. Proxies represent media objects to give people<br />

interested an up front impression of the latter. If there is already a proxy relation for the<br />

receiver, the old relation is discarded and the old persistent proxy is not deleted. In case<br />

null is passed, the relation to any existing persistent proxy is broken up and<br />

getProxy() will return a generated transient proxy.<br />

5.2 javax.emb.<strong>Media</strong>EntityLocalHome<br />

This interface defines the local home interface of media entity EJBs and offers services to<br />

create and to query persistent and mutable media objects. It extends<br />

javax.ejb.EJBLocalHome.<br />

The create method provided allows the creation of empty media entity EJBs. These<br />

instances need to be filled with content in a subsequent step, by using the setName()<br />

and setContent() methods.<br />

Sometimes networks of associated non-embedded media content can become quite<br />

complex. In order to allow the consistent handling of such complex content structures<br />

the import<strong>Media</strong>() and export<strong>Media</strong>() operations allows for consistent import,<br />

creation and export or content if for example many non-embedded parents share<br />

identical children. Using the related methods in the media entity EJB component<br />

interfaces would lead to multiple versions of the shared children being<br />

imported/exported.<br />

Finally, the publishContent() and publish<strong>Media</strong>() operations publish a<br />

transient or persistent media object to a protocol server, and returns a URL or content<br />

that allows clients to access the protocol and server specific copies of said medium and<br />

its children. This abstraction allows applications to access proprietary content delivery<br />

services, without exposing the application to the details of the implementation of those<br />

42


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

services. For example, multiple and distributed streaming server technologies can be<br />

used underneath a publish implementation. Implementations of this specification are not<br />

bound to a specific algorithm to determine a suitable protocol server. Theoretical<br />

possibilities range from dynamic selection from a pre-configured server pool to relating<br />

suitable protocol servers statically with each media entity. The resulting URL/content is<br />

either pointing directly to the cached copy of the media object with a protocol type of<br />

http, rtsp or similar, or it is an http URL pointing to a managed meta-medium that points<br />

to said cached copy.<br />

public interface <strong>Media</strong>EntityLocalHome extends EJBLocalHome {<br />

final static byte TRANSFER_TYPE_STREAM = 0;<br />

final static byte TRANSFER_TYPE_BURST = 1;<br />

<strong>Media</strong>EntityLocal create() throws CreateException, <strong>Media</strong>Exception;<br />

URL[] export<strong>Media</strong> (<strong>Media</strong>EntityLocal[], URL) throws <strong>Media</strong>Exception;<br />

Collection findByPartialDescription(String partialDescription) throws FinderException;<br />

Collection findByPartialLocation(String partialLocation) throws FinderException;<br />

<strong>Media</strong>EntityLocal findByPrimaryKey(String) throws FinderException;<br />

<strong>Media</strong>EntityLocal[] import<strong>Media</strong> (URL[], URL) throws CreateException, <strong>Media</strong>Exception;<br />

URL publishContent(<strong>Media</strong>, String, ProtocolConstraints)<br />

throws <strong>Media</strong>Exception;<br />

<strong>Media</strong> publish<strong>Media</strong>(<strong>Media</strong>EntityLocal[], String, ProtocolConstraints)<br />

throws <strong>Media</strong>Exception;<br />

}<br />

create ()<br />

Creates a new media entity EJB with a generated identity key, the value of<br />

System.currentTimeMillis() as value of the lastModified property, and null as<br />

value for all other properties. Please note most of the methods of the <strong>Media</strong> Entity<br />

returned will throw exceptions until the name and either the location or the content<br />

properties are set.<br />

A javax.ejb.CreateException is thrown if a problem related to EJB creation occurs.<br />

export<strong>Media</strong>(<strong>Media</strong>EntityLocal[] source<strong>Media</strong>, URL targetDirectoryLocation)<br />

Copies the content of the given media entity EJBs and all their direct and indirect<br />

children to the given targetDirectoryLocation, i.e. a URL of protocol type ”file or any<br />

other type supported by the implementation. The operation returns an array of URLs of<br />

the same size as the source media array. The elements of the resulting array point to file<br />

copies of the source media array elements – content. If the media objects affected are<br />

non-embedded, the content of the copies is modified to correctly point to the copies of<br />

the children –s content instead of the original locations.<br />

If the given targetDirectoryLocation is null, a default export directory location is used.<br />

The operation makes sure that each media entity EJB affected corresponds to exactly<br />

one media object created. Note that the names of the copied media objects may differ<br />

from the original ones, that the operation makes sure no existing files are overwritten by<br />

this operation, and that implementations are permitted to copy children to subdirectories<br />

of the given targetDirectoryLocation. Also note that the resulting targetLocation URLs are<br />

returned in the order of their respective media entity EJBs. Duplicate media entity EJBs<br />

43


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

result in targetLocation URLs returned in multiple array slots, null media entity EJBs<br />

result in respective null values in the result. Finally, note that not all media objects<br />

exported are necessarily returned, just the ones for which corresponding media entity<br />

EJBs were passed.<br />

A java.lang.NullPointerException is thrown if the given source media array is null. A<br />

javax.emb.ContentAccessException is thrown in case content transfer fails. An instance of<br />

a subclass of javax.emb.<strong>Media</strong>FormatException is thrown if there is a problem dealing<br />

with one of the media formats involved. A javax.emb.MalformedLocationException is<br />

thrown if the URL given is malformed or has a protocol type not supported by the<br />

implementation.<br />

findByPartialDescription (String partialDescription)<br />

Returns all media entities in the persistent store whose description contains the given<br />

String. The query is case-sensitive. Note that passing an empty string will return all<br />

media entity beans in the persistent store that have a description different from null.<br />

Passing in null or a partial description not present in the data store will result in an<br />

empty collection.<br />

A javax.ejb.FinderException is thrown if a finder problem occurs.<br />

findByPartialLocation (String partialLocation)<br />

Returns all media entities in the persistent store whose location URL contains the given<br />

String. The query is case-sensitive. Note that passing an empty string will return all<br />

media entity beans in the persistent store that have a location different from null.<br />

Passing in null or a partial location not present in the data store will result in an empty<br />

collection.<br />

A javax.ejb.FinderException is thrown if a finder problem occurs.<br />

findByPrimaryKey (String identity)<br />

Returns the media entity with the given identity.<br />

A java.lang.NullPointerException is thrown if the value passed is null. A<br />

javax.ejb.FinderException is thrown if a finder problem occurs or no media entity is<br />

found.<br />

import<strong>Media</strong>(URL[] sourceLocations, String[] names)<br />

Imports the given media objects and all their direct and indirect children from the given<br />

source locations and creates new EJBs for said media objects and children. For the media<br />

entity EJBs directly created from the source locations given, the names are derived from<br />

the given name array at equivalent indices. If a name value is null a generated name is<br />

used, possibly based on the related source location. For all other media entity EJBs<br />

created, the name properties are derived from the links present in their respective parent<br />

content.<br />

The operation returns an array of media entity EJBs of the same size as the source<br />

location array. The elements of the resulting array are based on the content of the<br />

corresponding elements of the source location array.<br />

44


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

The operation makes sure that each media object affected corresponds to exactly one<br />

media entity EJB created in the operations context. Note that the resulting <strong>Media</strong> entity<br />

EJBs are returned in the order of their respective sourceLocations. Duplicate<br />

sourceLocations result in media entity EJBs returned in multiple array slots, null<br />

sourceLocations result in respective null values in the result. If a source location is<br />

given multiple times with differing names, one of the names is picked for the resulting<br />

media entity EJB. Finally, note that not all media entity EJBs created are necessarily<br />

returned, just the ones for which corresponding location URLs were passed.<br />

A java.lang.NullPointerException is thrown if one of the arrays passed is null. A<br />

java.lang.IllegalArgumentException is thrown the two arrays passed mismatch in length<br />

or if one or more of the name arguments passed contain invalid characters. A<br />

javax.ejb.CreateException is thrown if the creation of a media entity EJB fails. A<br />

javax.emb.ContentAccessException is thrown if content transfer fails. An instance of a<br />

subclass of javax.emb.<strong>Media</strong>FormatException is thrown if there –s a problem dealing<br />

with one of the media formats involved. A javax.emb.MalformedLocationException is<br />

thrown if one of the URLs given is malformed or has a protocol type not supported by<br />

the implementation. A javax.emb.ContentTooLargeException is thrown if one the media<br />

entity EJB contents would become larger than supported by the implementation.<br />

publishContent (<strong>Media</strong> content, byte transferType, ProtocolConstraints constraints)<br />

This operation publishes persistent or transient media content to a protocol server and<br />

returns a URL. The URL allows web clients to access the protocol and server specific<br />

copies of said medium. Note that it also exports its children if a non-embedded media<br />

entity EJB is passed. If the medium is persistent (i.e. is a media entity EJB), said copies<br />

will likely be managed and updated once the original content changes. Optionally, the<br />

selection of a suitable protocol server can be influenced using the given constraints<br />

object. Implementations of this specification are not bound to a specific algorithm to<br />

determine a suitable protocol server. Theoretical possibilities range from dynamic<br />

selection from a pre-configured server pool to relating suitable protocol servers statically<br />

with each media entity. The resulting URL is either pointing directly to the cached copy<br />

of the media object with a protocol type of http, rtsp or similar, or it is an http URL<br />

pointing to a managed meta-medium that points to said cached copy.<br />

The kind of protocol server chosen may be determined by the given transferType.<br />

Specified values are:<br />

• TRANSFER_TYPE_STREAM for streaming of media content, using a stream server as<br />

protocol server.<br />

• TRANSFER_TYPE_BURST for burst transfer of media content, usually using a web<br />

server as protocol server.<br />

Specified protocol constraint types are:<br />

• ”SERVER_TYPE for restriction of stream servers to chose from. The constraint value<br />

is an array of Strings. Specified constraint values are ”VideoCharger for IBM<br />

VideoCharger servers, ”RealSystem for RealNetworks RealSystem servers, and<br />

”Windows <strong>Media</strong> for Microsoft Windows <strong>Media</strong> services, and ”QuickTime for Apple<br />

QuickTime servers. The protocol server selected will be of one of these types. Note<br />

that some server types can feed a number of different clients.<br />

• ”CLIENT_TYPE for restriction of stream servers to chose from. The constraint value<br />

is an array of Strings. Specified constraint values are ”VideoCharger for IBM<br />

VideoCharger players, ”RealPlayer for RealNetworks players, and ”Windows <strong>Media</strong><br />

for Microsoft Windows <strong>Media</strong> players, and ”QuickTime for Apple QuickTime<br />

45


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

players. The protocol server selected will support one of these client types. Note<br />

that some players can work with a number of protocol servers.<br />

In case the selected protocol server supports more than one client type, the client type is<br />

not constrained and a meta-medium has to be generated, said meta-medium is generated<br />

for the default client type of the selected protocol server. If in a similar case there is<br />

more than one constraint value for the client type, the constraint value is interpreted as a<br />

priority list and therefore the meta-medium is generated for the first client type in that<br />

list that is supported by the selected protocol server.<br />

A java.lang.NullPointerException is thrown if the media object passed is null. A<br />

java.lang.IllegalArgumentException is thrown if a transfer type is passed that is not<br />

supported by the implementation, or if a protocol type SERVER_TYPE or CLIENT_TYPE<br />

is passed with a value that is not an array of Strings. A<br />

javax.emb.NoServerFoundException is thrown if no suitable protocol server can be<br />

determined. A javax.emb.ContentAccessException is thrown if content transfer fails or if<br />

non-embedded content is passed in anything other than a media entity EJB. An instance<br />

of a subclass of javax.emb.<strong>Media</strong>FormatException is thrown if there –s a problem dealing<br />

with one of the media formats involved. A javax.emb.LinkTranslationException is thrown<br />

if ingesting protocol specific links into copies of non-embedded media objects fails. A<br />

javax.emb.ConversionException is thrown if the middleware fails converting the media<br />

content to another format in order to make it suitable for a specific protocol server.<br />

publish<strong>Media</strong> (<strong>Media</strong>EntityLocal[] playlist, byte transferType, ProtocolConstraints<br />

constraints)<br />

This operation publishes the given playlist of persistent media entities to a protocol<br />

server and returns a meta medium that allows clients to access the protocol and server<br />

specific copies of said playlist and its children. If the implementation chooses to cache<br />

the media objects on the protocol server chosen, it must be guaranteed that eventual<br />

child copies are also managed and will be updated if the original content changes.<br />

Optionally, the selection of a suitable protocol server can be influenced using the given<br />

constraints object. Implementations of this specification are not bound to a specific<br />

algorithm to determine a suitable protocol server. Theoretical possibilities range from<br />

dynamic selection from a pre-configured server pool to relating suitable protocol servers<br />

statically with each media entity. The content of the resulting meta medium is pointing<br />

directly to the cached copies of the given media entities with a protocol type of http,<br />

rtsp or similar.<br />

The kind of protocol server chosen may be determined by the given transferType.<br />

Specified values are:<br />

• TRANSFER_TYPE_STREAM for streaming of media content, using a stream server as<br />

protocol server.<br />

• TRANSFER_TYPE_BURST for burst transfer of media content, usually using a web<br />

server as protocol server.<br />

Specified protocol constraint types are:<br />

• ”SERVER_TYPE for restriction of stream servers to chose from. The constraint value<br />

is an array of Strings. Specified constraint values are ”VideoCharger for IBM<br />

VideoCharger servers, ”RealSystem for RealNetworks servers, and ”Windows <strong>Media</strong><br />

for Microsoft <strong>Media</strong> services, and ”QuickTime for Apple QuickTime servers. The<br />

46


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

protocol server selected will be of one of these types. Note that some server types<br />

can feed a number of different clients.<br />

• ”CLIENT_TYPE for restriction of stream servers to chose from. The constraint value<br />

is an array of Strings. Specified constraint values are ”VideoCharger for IBM<br />

VideoCharger players, ”RealPlayer for RealNetworks players, and ”Windows <strong>Media</strong><br />

for Microsoft Windows <strong>Media</strong> players, and ”QuickTime for Apple QuickTime<br />

players. The protocol server selected will support one of these client types. Note<br />

that some players can work with a number of protocol servers.<br />

If the selected protocol server supports more than one client type and the client type is<br />

not constrained, a meta-medium is generated for the default client type of the selected<br />

protocol server. If in a similar case there is more than one constraint value for the client<br />

type, the constraint value is interpreted as a priority list and therefore the meta-medium<br />

is generated for the first client type in that list that is supported by the selected protocol<br />

server.<br />

Both the format and the content of the resulting meta-medium are considered<br />

proprietary to an implementation of this specification. Suitable are streaming metafile<br />

formats like Real .ram or IBM .ivs for streaming, or HTML files - containing auto load<br />

links for playlists consisting of exactly one entry, or clickable links for playlists consisting<br />

of two or more entries - for burst transfer. However, a Servlet must be able to return the<br />

resulting meta-medium directly to its requesting client to cause a media player to render<br />

the playlist on said client. For example, publishing an MPEG movie and a SMIL<br />

presentation for streaming<br />

delivery can result in the<br />

.ram file content depicted<br />

below. Please note that<br />

the implementation chose<br />

to cache the SMIL<br />

presentation and the<br />

MPEG movie on server<br />

17.12.88.92, as the<br />

originals and their children<br />

are distributed over 4<br />

different servers. This<br />

implies that said cache<br />

copy of the SMIL<br />

presentation contains rtsp<br />

references to its child<br />

media.<br />

In contrast, publishing the<br />

same playlist for the HTML<br />

protocol would have<br />

resulted in an html meta<br />

playlist<br />

file://16.37.12.67/movie.mp<br />

eg<br />

file://32.2.12.65/text.rt<br />

file://16.32.48.64/presentation.s<br />

mi<br />

file://32.2.96.66/music.rm<br />

publish<br />

(playlist, …RTSP…, null)<br />

rtsp://17.12.88.92/movie.mpeg<br />

rtsp://17.12.88.92/presentation.smi<br />

resulting .ram<br />

meta-medium<br />

media containing HREF links to the SMIL presentation and the MPEG movie. Also, the<br />

cache copy of the SMIL presentation would contain HTML references to its child media<br />

in this case.<br />

A java.lang.NullPointerException is thrown if the playlist passed is null. A<br />

java.lang.IllegalArgumentExce<br />

ption is thrown if a transfer Figure 11: Publishing a sample playlist<br />

type is passed that is not<br />

supported by the implementation, or if a protocol type SERVER_TYPE or CLIENT_TYPE<br />

47


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

is passed with a value that is not an array of Strings. A<br />

javax.emb.NoServerFoundException is thrown if no suitable protocol server can be<br />

determined. A javax.emb.ContentAccessException is thrown if content transfer fails. An<br />

instance of a subclass of javax.emb.<strong>Media</strong>FormatException is thrown if there – s a<br />

problem dealing with one of the media formats involved. A<br />

javax.emb.LinkTranslationException is thrown if ingesting protocol specific links into<br />

copies of non-embedded media objects fails. A javax.emb.ConversionException is<br />

thrown if the middleware fails converting the media content to another format in order<br />

to make it suitable for a specific protocol server.<br />

48


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

5.3 javax.emb.<strong>Media</strong>Listener<br />

This interface defines the common behavior of media listener. Such observers are<br />

implemented by application programmers to be persisted with and extend the semantics<br />

of media entity EJBs in a way that does not depend on the implementation of the latter.<br />

Listeners are notified of specific events in media entity EJBs once they are registered<br />

with said. As they have to be persisted with media entity EJBs, all listeners must be<br />

serializable.<br />

The persistent observer design differs from the standard <strong>Java</strong> listener practice by passing<br />

the name of properties affected instead of passing the property value to distinct callback<br />

methods. The reason for this is that the large size of media content makes it practically<br />

impossible to pass it to observers. Therefore, observers are forced to retrieve property<br />

values from entity beans when there is a need. Please note that Entity Beans must be<br />

deployed as reentrant in order for the latter to work.<br />

public interface <strong>Media</strong>EntityListener extends Serializable {<br />

void handleAboutToChange<strong>Media</strong>Entity(<strong>Media</strong>EntityLocal, String) throws <strong>Media</strong>Exception;<br />

void handleAboutToRemove<strong>Media</strong>Entity(<strong>Media</strong>EntityLocal) throws <strong>Media</strong>Exception;<br />

void handle<strong>Media</strong>EntityChanged(<strong>Media</strong>EntityLocal, String) throws <strong>Media</strong>Exception;<br />

}<br />

handleAboutToChange<strong>Media</strong>Entity (<strong>Media</strong>EntityLocal mediaEntity, String<br />

propertyName)<br />

This method handles the fact that the given media entity is about to change the value of<br />

its property named propertyName. Valid property names are …content“,<br />

…location“, …mimeType“, …name“ and …description“.<br />

A javax.emb.ListenerVetoException is thrown if the listener does not agree to the<br />

intended change. An instance of a subclass of javax.emb.<strong>Media</strong>Exception is thrown if<br />

there – s an application specific problem. A java.lang.NullPointerException is thrown if<br />

one of the values passed is null.<br />

handleAboutToRemove<strong>Media</strong>Entity (<strong>Media</strong>EntityLocal mediaEntity)<br />

This method handles the fact that the given media entity is about to be removed.<br />

A javax.emb.ListenerVetoException is thrown if the listener does not agree to the<br />

intended removal. An instance of a subclass of javax.emb.<strong>Media</strong>Exception is thrown if<br />

there – s an application specific problem. A java.lang.NullPointerException is thrown if<br />

the value passed is null.<br />

handle<strong>Media</strong>EntityChanged (<strong>Media</strong>EntityLocal mediaEntity, String<br />

propertyName)<br />

This method handles the fact that the given media entity has changed the value of its<br />

property named propertyName. Valid property names are …content“, …location“,<br />

…mimeType“, …name“ and …description“.<br />

49


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

A javax.emb.ListenerVetoException is thrown if the listener does not agree to the change<br />

performed. An instance of a subclass of javax.emb.<strong>Media</strong>Exception is thrown if there –s<br />

an application specific problem. A java.lang.NullPointerException is thrown if one of the<br />

values passed is null.<br />

In addition to the methods described, all listeners should overwrite the two methods<br />

described below. <strong>Media</strong> listeners are persisted as part of <strong>Media</strong> Entity EJBs and therefore<br />

may change their object identity without notice. Therefore, the media entity EJB<br />

addListener() and removeListener() methods may not work correctly if the<br />

methods described below are not overwritten.<br />

equals (Object object)<br />

This method overwrites the matching method in java.lang.Object. The result is true if the<br />

given object is a <strong>Media</strong>Listener and it is content equal to the receiver, otherwise false.<br />

Note that this behavior is required as listeners are stored and loaded as part of EJB<br />

operations and therefore frequently change their object identity.<br />

hashCode ()<br />

This method overwrites the matching method in java.lang.Object. The resulting hash<br />

code is calculated based on the receiver –s content. Note that this behavior is required as<br />

listeners are stored and loaded as part of EJB operations and therefore frequently change<br />

their object identity.<br />

50


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

5.4 javax.emb.ProtocolConstraints<br />

This class models constraints that restrict the selection of protocol servers, like stream<br />

servers. Instances can contain multiple kinds of constraints. Constraints come as<br />

type/value pairs, with the type defining the type of constraint and the value giving the<br />

actual constraint data “ similar to a dictionary. Protocol constraints are used when<br />

publishing media for a given protocol, see <strong>Media</strong>EntityLocalHome.publish(’)<br />

for reference. As streaming constraints have to be transferred over machine boundaries,<br />

the class implements java.io.Serializable.<br />

This specification covers two types of constraint as binding for all implementations:<br />

• ”CLIENT_TYPE constrains the protocol server selection indirectly by defining an<br />

array of protocol client types (Strings) that are running on a client machine.<br />

Protocol servers are only eligible for selection during publish operations if they at<br />

least support one of the given client types. Also, the metadata generated during<br />

publish requests must be suitable for one of these clients. Standardized values for<br />

this constraint type are: ”Quicktime for Apple Quicktime players, ”VideoCharger<br />

for IBM VideoCharger players, ”Windows <strong>Media</strong> for Microsoft Windows <strong>Media</strong><br />

players, ”RealPlayer for RealNetworks players. Additional client types may be added<br />

to this list in future releases of this specification.<br />

• ”SERVER_TYPE constrains the protocol server selection directly by defining an array<br />

of protocol server types (Strings) eligible for selection during publish requests.<br />

Standardized values for this constraint type are: ”Quicktime for Apple Quicktime<br />

servers, ”VideoCharger for IBM VideoCharger servers, ”Windows <strong>Media</strong> for<br />

Microsoft Windows <strong>Media</strong> services, ”RealSystem for RealNetworks servers.<br />

Additional protocol server types may be added to this list in future releases of this<br />

specification.<br />

public final class ProtocolConstraints implements Serializable {<br />

public final static String CLIENT_TYPE = …CLIENT_TYPE“;<br />

public final static String SERVER_TYPE = …SERVER_TYPE“;<br />

public ProtocolConstraints();<br />

public Object getConstraint(String type);<br />

public void setConstraint(String type, Object value);<br />

public String[] getConstraintTypes();<br />

}<br />

ProtocolConstraints ()<br />

This is the default constructor.<br />

getConstraint (String type)<br />

Returns the value of the constraint defined by the given type, or null if said constraint<br />

is not present.<br />

A javax.emb.NullPointerException is thrown if the given type is null.<br />

51


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

setConstraint (String type, Object value)<br />

Alters the value of the constraint defined by the given type to the given value. Passing<br />

the constraint value null removes a constraint type from the receiver if present.<br />

A javax.emb.NullPointerException is thrown if the given type is null. A<br />

java.lang.IllegalArgumentException is thrown in case the constraint type given is either<br />

”CLIENT_TYPE or ”SERVER_TYPE , and the value given is not an array of Strings.<br />

getConstraintTypes ()<br />

Returns the receiver –s constraint types as an array of Strings.<br />

5.5 javax.emb.MetaDataEntityLocal<br />

This basic interface defines behavior common to all kinds of metadata objects that are<br />

persistent and can be altered. It also extends EJBLocalObject and therefore represents<br />

the local interface of a Metadata Entity EJB.<br />

Meta Data Entity EJB<br />

xml<br />

name<br />

Figure 12: <strong>Media</strong> Entity Beans components and<br />

interactions<br />

MetaDataEntity EJBs consist of the two basic alterable properties:<br />

• The xml property models the XML content of a Meta Data Entity EJB. XML content<br />

may be implicitly processed for the creation of persistent indexing information to<br />

allow efficient content search. The default for this property is null.<br />

• The name property models a file name that is used as a default in case the xml<br />

content has to be exported to a file. The default value for this property is null.<br />

52


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

public interface MetaDataEntityLocal extends EJBLocalObject {<br />

void addChild(MetaDataEntityLocal) throws <strong>Media</strong>Exception;<br />

void add<strong>Media</strong>Entity(<strong>Media</strong>EntityLocal) throws <strong>Media</strong>Exception;<br />

URL export<strong>Media</strong>(URL) throws <strong>Media</strong>Exception;<br />

MetaDataEntityLocal[] getChildren() throws <strong>Media</strong>Exception;<br />

long getLastModified() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>EntityLocal[] get<strong>Media</strong>Entities() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>EntityLocal[] get<strong>Media</strong>Entities(<strong>Media</strong>Format, boolean) throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>EntityLocal[] get<strong>Media</strong>Entities(String, boolean) throws <strong>Media</strong>Exception;<br />

String getName() throws <strong>Media</strong>Exception;<br />

MetaDataEntityLocal getNextVersion() throws <strong>Media</strong>Exception;<br />

MetaDataEntityLocal[] getParents() throws <strong>Media</strong>Exception;<br />

MetaDataEntityLocal getPreviousVersion() throws <strong>Media</strong>Exception;<br />

String getXML() throws <strong>Media</strong>Exception;<br />

void removeChild(MetaDataEntityLocal) throws <strong>Media</strong>Exception;<br />

void remove<strong>Media</strong>Entity(<strong>Media</strong>EntityLocal) throws <strong>Media</strong>Exception;<br />

void setName(String) throws <strong>Media</strong>Exception;<br />

void setPreviousVersion(MetaDataEntityLocal) throws <strong>Media</strong>Exception;<br />

void setXML(String, boolean) throws <strong>Media</strong>Exception;<br />

}<br />

addChild (MetaDataEntityLocal child)<br />

Adds the given Metadata Entity EJB to the receiver– s set of children. If the given<br />

MetaDataEntity EJB is already part of the receiver – s list of children no action is<br />

performed.<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

add<strong>Media</strong>Entity (<strong>Media</strong>EntityLocal mediaEntity)<br />

Adds the given <strong>Media</strong> Entity EJB to the receiver –s set of associated <strong>Media</strong> Entity EJBs<br />

that are described by the receiver. If the given <strong>Media</strong> Entity EJB is already part of the<br />

receiver –s list no action is performed.<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

getChildren ()<br />

Returns the receiver –s children as an array of <strong>Media</strong> Entity EJBs. The array is empty if<br />

no children are related.<br />

getLastModified ()<br />

Returns a timestamp stating when the receiver's persistent state was last modified.<br />

get<strong>Media</strong>Entities ()<br />

Returns the <strong>Media</strong> Entity EJBs associated with the receiver. The array is empty if no<br />

media entity EJBs are related.<br />

53


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

get<strong>Media</strong>Entities (<strong>Media</strong>Format mediaFormat, boolean searchCildren)<br />

This method locates all <strong>Media</strong> Entity EJBs associated with the receiver that have the<br />

specified media format. If the given recursion flag is true, the search is extended to all<br />

<strong>Media</strong> Entity EJBs that relate to the receiver or one of its recursive children.<br />

A java.lang.NullPointerException is thrown if the media format passed is null.<br />

get<strong>Media</strong>Entities (String mimeType, boolean searchCildren)<br />

This method locates all <strong>Media</strong> Entity EJBs associated with the receiver that have the<br />

given mime type. If the given recursion flag is true, the search is extended to all <strong>Media</strong><br />

Entity EJBs that relate to the receiver or one of its recursive children.<br />

A java.lang.NullPointerException is thrown if the mime type passed is null.<br />

getName ()<br />

Returns the receiver's non-unique name as a String. The name is used as a file name hint<br />

in case the metadata XML content is to be stored in a file system and therefore may only<br />

contain characters that are valid in file names. Also, it should contain a file extension that<br />

represents the receiver –s format. Note that as opposed to media entity EJBs, the name<br />

property is not required to contain a file extension registered with the<br />

<strong>Media</strong>FormatRegistry.<br />

getNextVersion ()<br />

Returns the succeeding version edition of the receiver, which allows querying and a<br />

history chain of metadata objects that represent the same thing. The value null is<br />

returned if no next version exists.<br />

getParents ()<br />

Returns the receiver's parents as an array of Metadata Entity EJBs. The array is empty if<br />

no parents are related.<br />

getPreviousVersion ()<br />

Returns the previous version of the receiver, which allows querying a history of<br />

metadata objects that represent the same logical thing. The value null is returned if no<br />

previous version exists.<br />

getXML ()<br />

This method returns the receiver –s content as an XML string.<br />

A javax.emb.ContentAccessException is thrown if the value passed is null.<br />

removeChild (MetaDataEntityLocal child)<br />

Removes the given Metadata Entity EJB from the receiver –s set of children. If the given<br />

MetaDataEntity EJB is not part of the receiver –s list of children, no action is performed.<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

54


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

remove<strong>Media</strong>Entity (<strong>Media</strong>EntityLocal mediaEntity)<br />

Removes the given <strong>Media</strong> Entity EJB from the receiver– s set of associated <strong>Media</strong> Entity<br />

EJBs that are described by the receiver. If the given <strong>Media</strong> Entity EJB is not part of the<br />

receiver –s list no action is performed.<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

setName (String name)<br />

Sets the receiver –s non-unique name as a String. The name is used as a file name hint in<br />

case the media content is to be stored or published in a file system and therefore may<br />

only contain characters that are valid in file names. Also, it should contain a file<br />

extension that represents the receiver –s media format. Note that as opposed media<br />

entity EJBs the name property is not required to contain a file extension registered with<br />

the <strong>Media</strong>FormatRegistry.<br />

A java.lang.NullPointerException is thrown if the value passed is null.<br />

setPreviousVersion (MetaDataEntityLocal metadata)<br />

Defines the given metadata entity to be the previous version of the receiver, which<br />

allows querying a history chain of metadata objects that represent the same logical thing.<br />

In return, the operation causes the receiver to be the given metadata entity –s successor.<br />

Passing the value null causes the receiver not to have a predecessor anymore. The<br />

operation is only allowed if version chain integrity is preserved:<br />

• If the given metadata entity EJB is the receiver itself: A<br />

javax.emb.VersionChainIntegrityException is thrown.<br />

• If the given metadata entity EJB is already the previous version of the receiver: No<br />

action is performed.<br />

• If the given metadata entity EJB is null: A<br />

javax.emb.VersionChainIntegrityException is thrown if the receiver has a successor.<br />

• Otherwise: A javax.emb.VersionChainIntegrityException is thrown if the given<br />

metadata entity EJB has a successor, or if the receiver has a predecessor, a successor,<br />

or both.<br />

setXML (String xmlContent, boolean validate)<br />

If the given XML content is well formed, it replaces the receiver –s current metadata<br />

content. If the given validation flag is true, the content is additionally strictly validated<br />

before the operation is performed.<br />

A java.lang.NullPointerException is thrown if the content passed is null. A<br />

javax.emb.MetaDataValidationException is thrown if the validate flag is true and the<br />

content validation fails. A javax.emb.MetaDataSyntaxException is thrown if the XML<br />

content is not well formed, regardless of the validate flag.<br />

55


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

5.6 javax.emb.MetaDataEntityLocalHome<br />

This interface defines the local home interface of metadata entity EJBs and therefore<br />

services relevant for local, persistent and mutable metadata objects. It extends<br />

javax.ejb.EJBLocalHome and defines additional methods with a semantic requiring the<br />

persistence of such metadata<br />

public interface MetaDataEntityLocalHome extends EJBLocalHome {<br />

MetaDataEntityLocal create() throws CreateException, <strong>Media</strong>Exception;<br />

MetaDataEntityLocal findByPrimaryKey(String) throws FinderException;<br />

Collection query(String, String, Map) throws FinderException, <strong>Media</strong>Exception;<br />

String[] retrieveSupportedOptions(String) throws <strong>Media</strong>Exception;<br />

String[] retrieveSupportedQueryLanguages() throws <strong>Media</strong>Exception;<br />

}<br />

create ()<br />

Creates a new metadata entity EJB with a generated identity key, null XML content and<br />

default values for the other properties. Please note many of the Metadata Entity EJB<br />

methods will throw exceptions until the XML content is set.<br />

A javax.ejb.CreateException is thrown if a problem related to EJB creation occurs.<br />

findByPrimaryKey (String identity)<br />

Returns the metadata entity with the given identity.<br />

A java.lang.NullPointerException is thrown if the value passed is null. A<br />

javax.ejb.FinderException is thrown if no matching metadata entity is found.<br />

query (String query, String queryLanguage, Map options)<br />

Returns the metadata entities that match the given query. The query semantics are<br />

defined by the given query language in association with the optionally given query<br />

options. Note that the set of query languages and options supported is up to the<br />

implementation. Valid keys for the options map can be derived by calling<br />

retreiveSupportedOptions(). In case unsupported options are passed,<br />

implementations should ignore them.<br />

A java.lang.NullPointerException is thrown if the query or query language passed is<br />

null. A javax.emb.MalformedQueryException is thrown if the query statement does not<br />

match the syntax defined by the given query language. A<br />

javax.emb.UnsupportedQueryLanguageException is thrown if the specified query<br />

language is not supported by the implementation. A javax.emb.IllegalOptionException is<br />

thrown if the given options are not formatted properly and cannot be read or if one of<br />

the options is unsupported and cannot be processed.<br />

retrieveSupportedOptions (String queryLanguage)<br />

Returns an array containing the names of supported options for the given query<br />

language. If no query options are supported then an empty array is returned.<br />

56


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

A java.lang.NullPointerException is thrown if the value passed is null. A<br />

javax.emb.UnsupportedQueryLanguageException is thrown if the name of the query<br />

language passed is not supported by the implementation.<br />

retrieveSupportedQueryLanguages ()<br />

Returns an array containing the names of supported query languages. If no query<br />

languages are supported then an empty array is returned.<br />

5.7 javax.emb.<strong>Media</strong>Exception<br />

<strong>Enterprise</strong> <strong>Media</strong> Beans extend the exception classes introduced with <strong>Media</strong> Foundation<br />

Beans with some more subclasses of javax.emb.<strong>Media</strong>Exception.<br />

5.7.1 javax.emb.ContentUnmutableException<br />

This exception is thrown during <strong>Media</strong>EntityLocal.setContent() whenever the<br />

content cannot be manually changed on the entity.<br />

5.7.2 javax.emb.IllegalOptionException<br />

This exception is thrown during MetaDataEntityLocalHome.query() whenever a<br />

specified option is not valid for the specified query language.<br />

5.7.3 javax.emb.ListenerVetoException<br />

This exception extends javax.emb.<strong>Media</strong>Exception and is thrown by <strong>Media</strong> entity listener<br />

EJBs in order to issue a veto against a media entity EJB modification.<br />

5.7.4 javax.emb.LocationUnmutableException<br />

This exception is thrown during <strong>Media</strong>EntityLocal.setLocation(’) whenever<br />

the location can not be manually changed on the entity.<br />

5.7.5 javax.emb.MalformedQueryException<br />

This exception is thrown during MetaDataEntityLocalHome.query(’) whenever<br />

a specified query statement is not valid for the specified query language.<br />

5.7.6 javax.emb.MetaDataValidationException<br />

This exception is thrown during MetaDataEntityLocal.setXML() whenever the<br />

XML metadata validation fails.<br />

57


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

5.7.7 javax.emb.MetaDataSyntaxException<br />

This exception is thrown during MetaDataEntityLocal.getXML() whenever the<br />

XML metadata given is not well formed.<br />

5.7.8 javax.emb.NoServerFoundException<br />

This exception is thrown if no suitable protocol server is found during publish<br />

operations.<br />

5.7.9 javax.emb.VersionChainIntegrityException<br />

This exception extends javax.emb.<strong>Media</strong>Exception and is thrown if there is a problem<br />

altering a media entity previous version association.<br />

5.7.10 javax.emb.UnsupportedQueryLanguageException<br />

This exception is thrown during MetaDataEntityLocalHome.query() whenever a<br />

specified query language is not supported<br />

5.8 javax.ejb.RemoveException<br />

<strong>Enterprise</strong> <strong>Media</strong> Beans extend the exception model introduced with <strong>Enterprise</strong> <strong>Java</strong><br />

Beans.<br />

5.8.1 javax.emb.ParentAssociationExistsException<br />

This exception extends javax.ejb.RemoveException and is thrown if a media entity EJB<br />

cannot be removed because it has parents that contain links pointing to the receiver.<br />

Removing a media entity EJB while it has parents would violate referential integrity and<br />

is therefore forbidden.<br />

5.8.2 javax.emb.PredecessorAssociationExistsException<br />

This exception extends javax.ejb.RemoveException and is thrown if a media entity EJB<br />

cannot be removed because it has associations to a previous version in the version<br />

chain. Removing a media entity EJB while it has a previous version would violate<br />

referential integrity and is therefore forbidden.<br />

58


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

Chapter 6<br />

Responsibilities Of EMB Roles<br />

In addition to the general responsibilities of EJB roles described in the EJB specification,<br />

the additional responsibilities applying for <strong>Enterprise</strong> <strong>Media</strong> Beans are described below.<br />

6.1 <strong>Media</strong> Foundation Bean Providers<br />

<strong>Media</strong> Foundation Bean Providers are responsible for providing enhanced support for<br />

media formats and/or converters as described in the <strong>Media</strong> Foundation Bean section of<br />

this specification. The set of converters and/or formats supported is up to the <strong>Media</strong><br />

Foundation Bean Provider.<br />

<strong>Media</strong> Foundation Bean Providers are encouraged to deliver implementations that are<br />

both container and <strong>Media</strong> Entity Bean Provider (see below) invariant.<br />

6.2 <strong>Media</strong> Entity Bean Providers<br />

<strong>Media</strong> Entity Bean Providers are responsible for providing implementations of the EJBs<br />

described in the <strong>Media</strong> Entity Bean section of this specification. The <strong>Media</strong> Entity Bean<br />

Provider chooses the kind of persistent store supported (relational database, file system,<br />

content management system) and if bean-managed persistence/relationships (BMP/BMR)<br />

or container-managed persistence/relationships (CMP/CMR) are used.<br />

<strong>Media</strong> Entity Bean Providers may additionally support extensions to the EJB deployment<br />

descriptor for resource configuration, such as format registry content, default directories,<br />

etc.<br />

<strong>Media</strong> Entity Bean Providers are encouraged to provide base support for media formats<br />

and converters exceeding the content of the javax.emb package. <strong>Media</strong> Entity Bean<br />

Providers are also encouraged to deliver implementations that are container invariant.<br />

6.3 EJB Application Developers<br />

When creating applications or reusable components, EJB Application Developers can<br />

directly use the <strong>Media</strong> Entity Beans and <strong>Media</strong> Foundation Beans APIs. They may define<br />

relationships between custom EJBs, media entity EJBs, and metadata entity EJBs.<br />

Additionally, they can provide custom media listener implementations to extend media<br />

entity EJBs.<br />

59


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

6.4 EJB Container Providers<br />

EJB Container Providers are additionally encouraged, but not required, to provide tooling<br />

to manage EMB resources such as the content of the format bean registry. EJB Container<br />

Providers may provide a default EMB implementation.<br />

Note that future versions of this specification may agree on common ways to handle<br />

resource configuration, such as common EMB specific extensions to the EJB deployment<br />

descriptor, or common container extensions for EMB resource configuration. However, at<br />

the current point in time we feel there is not enough industry consensus to impose such<br />

requirements on container providers.<br />

6.5 Client Programmerⱃs Responsibilities<br />

The EJB client programmer accesses EJBs, <strong>Media</strong> Entity EJBs and Metadata Entity EJBs<br />

via their home and component interfaces. <strong>Media</strong> Foundation Bean function is accessed<br />

directly via the <strong>Media</strong> Foundation Bean API defined in javax.emb.<br />

60


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

Chapter 7<br />

Examples<br />

This chapter provides some sample Servlet code to illustrate working with <strong>Enterprise</strong><br />

<strong>Media</strong> Beans. The code assumes that the respective Servlet classes import the java.io,<br />

javax.servlet and javax.emb packages.<br />

Please note that the following Servlet code snipplets are designed to receive the identity<br />

of a media entity EJB as a parameter. Therefore, a parameter called ”identity , along with<br />

the String representation of a long value, has to be passed with each HTTP request to<br />

such a Servlet. This is achieved by adding a parameter to the URLs pointing to such<br />

Servlets - for example, a URL like<br />

http://myServer/myapp/myservlet?identity=42<br />

would cause the corresponding Servlet to receive a parameter named ”identity and an<br />

associated value of ”42 upon invocation.<br />

Also, all snipplets assume that the Servlet classes declare a static variable called<br />

mediaEntityHome that caches the local home of the media entity EJB. The method<br />

below demonstrates a way to initialize this variable. Note that the exact code depends<br />

on the container used for deployment.<br />

public void init() throws ServletException {<br />

try {<br />

// Lookup the media entity EJB home.<br />

javax.naming.InitialContext context = new javax.naming.InitialContext();<br />

mediaEntityHome = (<strong>Media</strong>EntityLocalHome) context.lookup("<strong>Media</strong>Entity");<br />

} catch (Exception exception) {<br />

throw new ServletException(exception);<br />

}<br />

}<br />

61


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

7.1 Simple Burst Transfer<br />

This sample service method of a Servlet illustrates the basic way to present the content<br />

of a media entity EJB on a client within the J2EE programming model. In this case, said<br />

Servlet transfers the content of the media directly through the Servlet engine to a<br />

requesting web client. Once the content is received, the web client will start an<br />

appropriate media player by analyzing the mime type set in the response. Note that this<br />

simple scenario is only suitable for embedded media objects.<br />

public void service(HttpServlet<strong>Request</strong> request, HttpServletResponse response) throws ServletException<br />

{<br />

try {<br />

// Query the media entity EJB instance.<br />

String identity = request.getParameter("identity");<br />

<strong>Media</strong>EntityLocal mediaEntity = mediaEntityLocalHome.findByPrimaryKey(identity);<br />

// Determine if the media entity doesn–t exceed 2GB in size.<br />

long contentSize = mediaEntity.getSize();<br />

if (contentSize > Integer.MAX_VALUE) {<br />

throw new ServletException(…cannot transfer content larger than 2GB as servlet response“);<br />

}<br />

// Fill the servlet response. The content is transferred using streaming I/O<br />

// to avoid memory clogging due to large content.<br />

response.setContentLength((int) contentSize);<br />

response.setContentType(mediaEntity.getMimeType());<br />

}<br />

byte[] buffer = new byte[0x10000];<br />

long position = 0;<br />

int bytesRead = 0;<br />

while((bytesRead = media.readContent(position, buffer)) != - 1) {<br />

response.getOutputStream().write(buffer, 0, bytesRead);<br />

position += bytesRead;<br />

}<br />

} catch (Throwable exception) {<br />

throw new ServletException(exception);<br />

}<br />

62


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

7.2 Publishing & Burst Transfer<br />

This sample service method of a Servlet illustrates how the publish operation can be<br />

used to present the content of a media entity EJB on a client within the J2EE<br />

programming model. In this case, said Servlet transfers the content of the media using<br />

the publish operation with transfer type burst. The resulting URL is used to render the<br />

medium as integral part of a HTML page. For simplicity, we –ll assume that only images<br />

are available in the data store.<br />

public void service(HttpServlet<strong>Request</strong> request, HttpServletResponse response) throws ServletException<br />

{<br />

try {<br />

// Query the media entity EJB instance.<br />

String identity = request.getParameter("identity");<br />

<strong>Media</strong>EntityLocal mediaEntity = mediaEntityHome.findByPrimaryKey(identity);<br />

// Publish the media entity to an HTTP server<br />

URL link = mediaEntityHome.publishContent(<br />

mediaEntity, <strong>Media</strong>EntityLocalHome.TRANSFER_TYPE_BURST,<br />

null<br />

);<br />

}<br />

// Fill the servlet response. A link to the published content is sent<br />

// that is assembled into the page by the browser.<br />

response.getOutputStream().write(…“);<br />

} catch (Throwable exception) {<br />

throw new ServletException(exception);<br />

}<br />

63


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

7.3 Publishing & Streaming<br />

This sample service method of a Servlet also illustrates how the publish operation can be<br />

used to present the content of a media entity EJB on a client within the J2EE<br />

programming model. In this case, the Servlet engine transfers a streaming metafile to the<br />

requesting web client. Once the metafile is received, the web client will start an<br />

appropriate media player by analyzing the mime type set in the response. After that, said<br />

media player will initiate streaming the media content from the stream server selected by<br />

the <strong>Enterprise</strong> <strong>Media</strong> Beans implementation.<br />

Note that due to the abstraction performed by the publish operation, the Servlet logic<br />

depends on neither any proprietary stream server technology, nor any predefined stream<br />

server location. Also, note that the decision to use a stream server as protocol server is<br />

the decision of the Servlet logic, not a decision of the media creator. Therefore, this is<br />

the preferred way to dynamically compose and present the content of media entity EJBs,<br />

both for burst transfer (http) and streaming (rtsp) protocols.<br />

public void service(HttpServlet<strong>Request</strong> request, HttpServletResponse response) throws ServletException<br />

{<br />

try {<br />

// Query the media entity EJB instance.<br />

String identity = request.getParameter("identity");<br />

<strong>Media</strong>EntityLocal mediaEntity = mediaEntityHome.findByPrimaryKey(identity);<br />

// Publish the media entity.<br />

<strong>Media</strong>EntityLocal[] playlist = new <strong>Media</strong>EntityLocal[] { mediaEntity };<br />

<strong>Media</strong> metaMedium =<br />

mediaEntityHome.publishContent(playlist, <strong>Media</strong>EntityLocalHome.TRANSFER_TYPE_STREAM, null);<br />

}<br />

// Fill the servlet response. Note that meta media content is usually small in size.<br />

response.setContentLength((int) metaMedium.getSize());<br />

response.setContentType(metaMedium.getMimeType());<br />

response.getOutputStream().write(metaMedium.getContent());<br />

} catch (Throwable exception) {<br />

throw new ServletException(exception);<br />

}<br />

64


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

7.4 Presentation & Dynamic Conversion<br />

This example is similar to the one in section 6.1, with the difference that the media is<br />

dynamically converted to watermark the content before sending it to the requesting web<br />

client. If the media entity– s format does not conform to the one supported by the<br />

converter (for example in case of specific image formats), an exception is thrown. This<br />

technique is highly useful in applications incorporating digital rights management, as rich<br />

media content can be associated with the person requesting it. This allows enterprises to<br />

trace back illegal copies of copyrighted content to the originator.<br />

Note that the handling of the watermarked media object (local and transient) is<br />

analogous to the handling of the original media object persistent in section 6.1. Also note<br />

that the class WatermarkConverterSpec is not part of this specification, but rather custom<br />

or bought from a 3 rd party.<br />

public void service(HttpServlet<strong>Request</strong> request, HttpServletResponse response) throws ServletException<br />

{<br />

try {<br />

// Query the media entity EJB instance.<br />

String identity = request.getParameter("identity");<br />

<strong>Media</strong>EntityLocal mediaEntity = mediaEntityHome.findByPrimaryKey(identity);<br />

// Watermark the media entity.<br />

<strong>Media</strong>ConverterSpec[] specs = new <strong>Media</strong>ConverterSpec[] { new WatermarkConverterSpec() };<br />

<strong>Media</strong> media = mediaEntity.getConverted<strong>Media</strong>(specs);<br />

// Determine if the converted media is embedded and doesn–t exceed 2GB in size.<br />

long contentSize = media.getSize();<br />

if (contentSize > Integer.MAX_VALUE) {<br />

throw new ServletException(…cannot transfer content larger than 2GB as servlet response“);<br />

} else if (!media.getFormat().isEmbedded()) {<br />

throw new ServletException(…cannot transfer non-embedded content as servlet response“);<br />

}<br />

// Fill the servlet response. The content is divided up into 64KB<br />

// chunks to avoid memory clogging due to large content.<br />

response.setContentLength((int) contentSize);<br />

response.setContentType(media.getMimeType());<br />

}<br />

byte[] buffer = new byte[0x10000];<br />

long position = 0;<br />

int bytesRead = 0;<br />

while((bytesRead = media.readContent(position, buffer)) != - 1) {<br />

response.getOutputStream().write(buffer, 0, bytesRead);<br />

position += bytesRead;<br />

}<br />

} catch (Throwable exception) {<br />

throw new ServletException(exception);<br />

}<br />

65


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

7.5 Dynamic Header Extraction<br />

This sample service method of a Servlet illustrates how descriptive header information<br />

can be extracted dynamically from media objects. This technique is useful if descriptive<br />

header information should be processed or displayed in an application without storing it<br />

redundantly in the EJB entity bean model.<br />

Note that this technique is independent from any specific media format. Therefore, it can<br />

be used to add generic header detail information to any kind of <strong>Enterprise</strong> <strong>Media</strong> Beans<br />

based enterprise application.<br />

public void service(HttpServlet<strong>Request</strong> request, HttpServletResponse response) throws ServletException<br />

{<br />

try {<br />

Writer writer = new OutputStreamWriter(response.getOutputStream());<br />

// Query the media entity EJB instance.<br />

String identity = request.getParameter("identity");<br />

<strong>Media</strong>EntityLocal mediaEntity = mediaEntityHome.findByPrimaryKey(identity);<br />

// Respond the HTML header.<br />

writer.write(…<strong>Media</strong> Entity #“);<br />

writer.write(identity);<br />

writer.write(… 焠 Header Details“);<br />

}<br />

// respond the HTML body.<br />

<strong>Media</strong>Header header = mediaEntity.getHeader();<br />

String[] fieldNames = header.getFieldNames();<br />

writer.write(…“);<br />

for (int index = 0; index < fieldNames.length; index++) {<br />

writer.write(fieldNames[index]);<br />

writer.write(…: …);<br />

writer.write(header.getField(fieldNames[index]).toString());<br />

writer.write(…“);<br />

}<br />

writer.write(…“);<br />

writer.flush();<br />

} catch (Throwable exception) {<br />

throw new ServletException(exception);<br />

}<br />

66


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

Chapter 8<br />

Appendix<br />

This chapter provides a reference for package javax.emb, an index, and links to related<br />

information.<br />

8.1 Reference<br />

This reference lists all classes and interfaces of package javax.emb. It also lists all<br />

exceptions introduced with the package.<br />

8.1.1 Classes and Interfaces<br />

This section lists all classes and interfaces introduced with the javax.emb package. It also<br />

lists all method signatures.<br />

public final class Generic<strong>Media</strong>Format implements <strong>Media</strong>Format<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

public byte[] assembleContent(URL, <strong>Media</strong>Segment[]) throws <strong>Media</strong>Exception;<br />

public <strong>Media</strong>Segment[] disassembleContent(URL, byte[]) throws <strong>Media</strong>Exception;<br />

public <strong>Media</strong>Header extractHeader(InputStream) throws <strong>Media</strong>Exception;<br />

public <strong>Media</strong> extractProxy (InputStream) throws <strong>Media</strong>Exception;<br />

public String getDefaultMimeType();<br />

public boolean isEmbedded();<br />

public boolean isStreamingDesirable();<br />

public final class Generic<strong>Media</strong>Header implements <strong>Media</strong>Header<br />

o<br />

o<br />

public String[] getFieldNames();<br />

public Object getField(String);<br />

public interface <strong>Media</strong><br />

o static final String MIME_TYPE_UNKNOWN = www/unknown ;<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

byte[] getContent() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>Format getFormat() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>Header getHeader() throws <strong>Media</strong>Exception;<br />

String getMimeType() throws <strong>Media</strong>Exception;<br />

String getName() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong> getProxy() throws <strong>Media</strong>Exception;<br />

long getSize() throws <strong>Media</strong>Exception;<br />

int readContent (long, byte[]) throws <strong>Media</strong>Exception;<br />

int readContent (long, byte[], int, int) throws <strong>Media</strong>Exception;<br />

67


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

public class <strong>Media</strong>Bean implements <strong>Media</strong><br />

o public <strong>Media</strong>Bean(InputStream, String, String) throws <strong>Media</strong>Exception;<br />

o public <strong>Media</strong>Bean(File, String) throws <strong>Media</strong>Exception;<br />

public interface <strong>Media</strong>Converter<br />

o InputStream process (InputStream) throws <strong>Media</strong>Exception;<br />

o void process (InputStream, OutputStream) throws <strong>Media</strong>Exception;<br />

public interface <strong>Media</strong>ConverterSpec extends java.io.Serializable<br />

o <strong>Media</strong>Converter getConverter();<br />

o String getTargetMimeType();<br />

o String getTargetFileExtension();<br />

public interface <strong>Media</strong>EntityLocal extends <strong>Media</strong>, javax.ejb.EJBLocalObject<br />

o void addListener(<strong>Media</strong>Listener) throws <strong>Media</strong>Exception;<br />

o void addMetaData(MetaDataEntityLocal) throws <strong>Media</strong>Exception;<br />

o void convert(<strong>Media</strong>ConverterSpec[]) throws <strong>Media</strong>Exception;<br />

o java.net.URL export<strong>Media</strong>(java.net.URL) throws <strong>Media</strong>Exception;<br />

o <strong>Media</strong>EntityLocal[] getChildren() throws <strong>Media</strong>Exception;<br />

o String getDescription() throws <strong>Media</strong>Exception;<br />

o <strong>Media</strong>Listener[] getListeners();<br />

o URL getLocation() throws <strong>Media</strong>Exception;<br />

o MetaDataEntityLocal[] getMetaData() throws <strong>Media</strong>Exception;<br />

o <strong>Media</strong>EntityLocal getNextVersion() throws <strong>Media</strong>Exception;<br />

o <strong>Media</strong>EntityLocal[] getParents() throws <strong>Media</strong>Exception;<br />

o <strong>Media</strong>EntityLocal getPreviousVersion() throws <strong>Media</strong>Exception;<br />

o void import<strong>Media</strong>(java.net.URL, String) throws <strong>Media</strong>Exception;<br />

o void removeListener(<strong>Media</strong>Listener) throws <strong>Media</strong>Exception;<br />

o void removeMetaDataListener(MetaDataEntityLocal) throws <strong>Media</strong>Exception;<br />

o void setChildren(<strong>Media</strong>EntityLocal[]) throws <strong>Media</strong>Exception;<br />

o void setContent(byte[]) throws <strong>Media</strong>Exception;<br />

o void setContent(InputStream) throws <strong>Media</strong>Exception;<br />

o void setDescription(String) throws <strong>Media</strong>Exception;<br />

o void setLocation(java.net.URL) throws <strong>Media</strong>Exception;<br />

o void setMimeType(String) throws <strong>Media</strong>Exception;<br />

o void setName(String) <strong>Media</strong>Exception<br />

o void setPreviousVersion(<strong>Media</strong>EntityLocal) throws <strong>Media</strong>Exception;<br />

o void setProxy(<strong>Media</strong>EntityLocal) throws <strong>Media</strong>Exception;<br />

public interface <strong>Media</strong>EntityLocalHome extends javax.ejb.EJBLocalHome<br />

o final static byte TRANSFER_TYPE_STREAM = 0;<br />

68


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

o final static byte TRANSFER_TYPE_BURST = 1;<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

<strong>Media</strong>EntityLocal create() throws CreateException, <strong>Media</strong>Exception;<br />

java.net.URL[] export<strong>Media</strong> (<strong>Media</strong>EntityLocal[], java.net.URL) throws <strong>Media</strong>Exception;<br />

java.util.Collection findByPartialDescription(String) throws FinderException;<br />

java.util.Collection findByPartialLocation(String) throws FinderException;<br />

<strong>Media</strong>EntityLocal findByPrimaryKey(String) throws FinderException;<br />

<strong>Media</strong>EntityLocal[] import<strong>Media</strong> (java.net.URL[], String[]) throws CreateException, <strong>Media</strong>Exception;<br />

java.net.URL publishContent(<strong>Media</strong>, String, ProtocolConstraints) throws <strong>Media</strong>Exception;<br />

<strong>Media</strong> publish<strong>Media</strong>(<strong>Media</strong>EntityLocal[], String, ProtocolConstraints) throws <strong>Media</strong>Exception;<br />

public interface <strong>Media</strong>Listener extends java.io.Serializable<br />

o void handleAboutToChange<strong>Media</strong>Entity(<strong>Media</strong>EntityLocal, String) throws <strong>Media</strong>Exception;<br />

o void handleAboutToRemove<strong>Media</strong>Entity(<strong>Media</strong>EntityLocal) throws <strong>Media</strong>Exception;<br />

o void handle<strong>Media</strong>EntityChanged(<strong>Media</strong>EntityLocal, String) throws <strong>Media</strong>Exception;<br />

public interface <strong>Media</strong>Format extends java.io.Serializable<br />

o byte[] assembleContent(URL, <strong>Media</strong>Segment[]);<br />

o <strong>Media</strong>Segment[] disassembleContent(URL, byte[]) throws <strong>Media</strong>Exception;<br />

o <strong>Media</strong>Header extractHeader(InputStream) throws <strong>Media</strong>Exception;<br />

o <strong>Media</strong> extractProxy(InputStream) throws <strong>Media</strong>Exception;<br />

o String getDefaultMimeType();<br />

o boolean isEmbedded();<br />

o boolean isStreamingDesirable();<br />

public final class <strong>Media</strong>FormatRegistry<br />

o public static final <strong>Media</strong>FormatRegistry SINGLETON;<br />

o private <strong>Media</strong>FormatRegistry();<br />

o public void bind(String, <strong>Media</strong>Format) throws FormatAlreadyBoundException;<br />

o public Iterator getFileExtensions();<br />

o public <strong>Media</strong>Format lookup(String) throws FormatNotFoundException;<br />

o public void rebind(String, <strong>Media</strong>Format);<br />

o public void unbind(String) throws FormatNotFoundException;<br />

public interface <strong>Media</strong>Header extends java.io.Serializable<br />

o public String[] getFieldNames();<br />

o public Object getField(String);<br />

public final class <strong>Media</strong>Segment extends java.io.Serializable<br />

o public <strong>Media</strong>Segment();<br />

o public byte[] getContent();<br />

o public URL getChildLocation();<br />

o public void setContent(byte[]);<br />

69


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

o<br />

public void setChildLocation(URL);<br />

public interface MetaDataEntityLocal extends javax.ejb.EJBLocalObject<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

void addChild(MetaDataEntityLocal) throws <strong>Media</strong>Exception;<br />

void add<strong>Media</strong>Entity(<strong>Media</strong>EntityLocal) throws <strong>Media</strong>Exception;<br />

MetaDataEntityLocal getChildren() throws <strong>Media</strong>Exception;<br />

long getLastModified() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>EntityLocal[] get<strong>Media</strong>Entities() throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>EntityLocal[] get<strong>Media</strong>Entities (<strong>Media</strong>Format, boolean) throws <strong>Media</strong>Exception;<br />

<strong>Media</strong>EntityLocal[] get<strong>Media</strong>Entities (String, boolean) throws <strong>Media</strong>Exception;<br />

String getName() throws <strong>Media</strong>Exception;<br />

MetaDataEntityLocal getNextVersion() throws <strong>Media</strong>Exception;<br />

MetaDataEntityLocal[] getParents() throws <strong>Media</strong>Exception;<br />

MetaDataEntityLocal getPreviousVersion() throws <strong>Media</strong>Exception;<br />

String getXML() throws <strong>Media</strong>Exception;<br />

void removeChild(MetaDataEntityLocal) throws <strong>Media</strong>Exception;<br />

void removeMdiaEntity(<strong>Media</strong>EntityLocal) throws <strong>Media</strong>Exception;<br />

void setPreviousVersion(MetaDataEntityLocal) throws <strong>Media</strong>Exception;<br />

void setXML(String, boolean) throws <strong>Media</strong>Exception;<br />

public interface MetaDataEntityLocalHome extends javax.ejb.EJBLocalHome<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

MetaDataEntityLocal create() throws CreateException, <strong>Media</strong>Exception;<br />

java.util.Collection findByPartialContent(String) throws FinderException;<br />

MetaDataEntityLocal findByPrimaryKey(String) throws FinderException;<br />

java.util.Collection query(String, Strin g, java.util.Map) throws FinderException, <strong>Media</strong>Exception;<br />

String[] retrieveSupportedOptions(String) throws <strong>Media</strong>Exception;<br />

String[] retrieveSupportedQueryLanguages() throws <strong>Media</strong>Exception;<br />

public final class ProtocolConstraints implements java.io.Serializable<br />

o<br />

o<br />

o<br />

o<br />

o<br />

o<br />

public static final String CLIENT_TYPE;<br />

public static final String SERVER_TYPE;<br />

public ProtocolConstraints();<br />

8.1.2 Exceptions<br />

public Object getConstraint(String);<br />

public void setConstraint(String, Object);<br />

public String[] getConstraintTypes();<br />

This section provides an overview over the exception classes introduced with this<br />

specification. It also depicts the hierarchy relationships between said exceptions.<br />

Exceptions that are part of the J2EE core are marked with italics.<br />

java.lang.Throwable<br />

java.lang.Exception<br />

70


<strong>Enterprise</strong> <strong>Media</strong> Beans <strong>Specification</strong><br />

Version 1.0, Final Release<br />

javax.emb.<strong>Media</strong>Exception<br />

javax.emb.ContentAccessException<br />

javax.emb.<strong>Media</strong>FormatException<br />

javax.emb.FormatAlreadyBoundException<br />

javax.emb.FormatFeatureException<br />

javax.emb.FormatNotFoundException<br />

javax.emb.FormatSyntaxException<br />

javax.emb.ContentTooLargeException<br />

javax.emb.ContentUnmutableException<br />

javax.emb.ConversionException<br />

javax.emb.IllegalLocationException<br />

javax.emb.LinkTranslationException<br />

javax.emb.LocationUnmutableException<br />

javax.emb.MalformedLocationException<br />

javax.emb.MalformedOptionException<br />

javax.emb.MalformedQueryException<br />

javax.emb.MetaDataSyntaxException<br />

javax.emb.MetaDataValidationException<br />

javax.emb.ListenerVetoException<br />

javax.emb.MalformedSecurityMaskException<br />

javax.emb.NoServerFoundException<br />

javax.emb.UnsupportedQueryLanguageException<br />

javax.emb.VersionChainIntegrityException<br />

javax.ejb.RemoveException<br />

javax.emb.ParentAssociationExistsException<br />

javax.emb.PredecessorAssociationExistsException<br />

8.2 Related Documents<br />

• Sun Microsystems, ”Designing <strong>Enterprise</strong> Applications with the J2EE Platform,<br />

Second Edition , 2002.<br />

• Sun Microsystems, ”<strong>Enterprise</strong> <strong>Java</strong>Beans TM <strong>Specification</strong> , Version 2.x<br />

• Sun Microsystems, ”<strong>Java</strong> <strong>Media</strong> Framework TM <strong>Specification</strong> , Version 2.0, Final<br />

Release, March 2001.<br />

• IBM Corporation, ”Datalinks: Managing External Data With DB2 Universal Database ,<br />

February 1999.<br />

• Object Management Group, ”Unified Modeling Language <strong>Specification</strong> , Version 1.3,<br />

March 2000<br />

71

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!