Example usage for javax.activation DataHandler getBean

List of usage examples for javax.activation DataHandler getBean

Introduction

In this page you can find the example usage for javax.activation DataHandler getBean.

Prototype

public Object getBean(CommandInfo cmdinfo) 

Source Link

Document

A convenience method that takes a CommandInfo object and instantiates the corresponding command, usually a JavaBean component.

Usage

From source file:MultipartViewer.java

protected Component getComponent(BodyPart bp) {

    try {//from   w ww  .  j ava  2s.  c o  m
        DataHandler dh = bp.getDataHandler();
        CommandInfo ci = dh.getCommand("view");
        if (ci == null) {
            throw new MessagingException("view command failed on: " + bp.getContentType());
        }

        Object bean = dh.getBean(ci);

        if (bean instanceof Component) {
            return (Component) bean;
        } else {
            if (bean == null)
                throw new MessagingException(
                        "bean is null, class " + ci.getCommandClass() + " , command " + ci.getCommandName());
            else
                throw new MessagingException("bean is not a awt.Component" + bean.getClass().toString());
        }
    } catch (MessagingException me) {
        return new Label(me.toString());
    }
}

From source file:MessageViewer.java

protected Component getBodyComponent() {
    //------------
    // now get a content viewer for the main type...
    //------------
    try {/*w w w  .ja  v  a2 s.c  o m*/
        DataHandler dh = displayed.getDataHandler();
        CommandInfo ci = dh.getCommand("view");
        if (ci == null) {
            throw new MessagingException("view command failed on: " + displayed.getContentType());
        }

        Object bean = dh.getBean(ci);
        if (bean instanceof Component) {
            return (Component) bean;
        } else {
            throw new MessagingException("bean is not a component " + bean.getClass().toString());
        }
    } catch (MessagingException me) {
        return new Label(me.toString());
    }
}