Example usage for javax.activation DataHandler getCommand

List of usage examples for javax.activation DataHandler getCommand

Introduction

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

Prototype

public CommandInfo getCommand(String cmdName) 

Source Link

Document

Get the command cmdName.

Usage

From source file:MultipartViewer.java

protected Component getComponent(BodyPart bp) {

    try {/*from  ww  w .j  a v  a  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  . j  a  va  2  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());
    }
}