Source Code Cross Referenced for CommandInfo.java in  » 6.0-JDK-Core » activation » javax » activation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » activation » javax.activation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1997-1999 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package javax.activation;
027
028        import java.io.*;
029        import java.beans.Beans;
030
031        /**
032         * The CommandInfo class is used by CommandMap implementations to
033         * describe the results of command requests. It provides the requestor
034         * with both the verb requested, as well as an instance of the
035         * bean. There is also a method that will return the name of the
036         * class that implements the command but <i>it is not guaranteed to
037         * return a valid value</i>. The reason for this is to allow CommandMap
038         * implmentations that subclass CommandInfo to provide special
039         * behavior. For example a CommandMap could dynamically generate
040         * JavaBeans. In this case, it might not be possible to create an
041         * object with all the correct state information solely from the class
042         * name.
043         * 
044         * @since 1.6
045         */
046
047        public class CommandInfo {
048            private String verb;
049            private String className;
050
051            /**
052             * The Constructor for CommandInfo.
053             * @param verb The command verb this CommandInfo decribes.
054             * @param className The command's fully qualified class name.
055             */
056            public CommandInfo(String verb, String className) {
057                this .verb = verb;
058                this .className = className;
059            }
060
061            /**
062             * Return the command verb.
063             *
064             * @return the command verb.
065             */
066            public String getCommandName() {
067                return verb;
068            }
069
070            /**
071             * Return the command's class name. <i>This method MAY return null in
072             * cases where a CommandMap subclassed CommandInfo for its
073             * own purposes.</i> In other words, it might not be possible to
074             * create the correct state in the command by merely knowing
075             * its class name. <b>DO NOT DEPEND ON THIS METHOD RETURNING
076             * A VALID VALUE!</b>
077             *
078             * @return The class name of the command, or <i>null</i>
079             */
080            public String getCommandClass() {
081                return className;
082            }
083
084            /**
085             * Return the instantiated JavaBean component.
086             * <p>
087             * Begin by instantiating the component with
088             * <code>Beans.instantiate()</code>.
089             * <p>
090             * If the bean implements the <code>javax.activation.CommandObject</code>
091             * interface, call its <code>setCommandContext</code> method.
092             * <p>
093             * If the DataHandler parameter is null, then the bean is
094             * instantiated with no data. NOTE: this may be useful
095             * if for some reason the DataHandler that is passed in
096             * throws IOExceptions when this method attempts to
097             * access its InputStream. It will allow the caller to
098             * retrieve a reference to the bean if it can be
099             * instantiated.
100             * <p>
101             * If the bean does NOT implement the CommandObject interface,
102             * this method will check if it implements the
103             * java.io.Externalizable interface. If it does, the bean's
104             * readExternal method will be called if an InputStream
105             * can be acquired from the DataHandler.<p>
106             *
107             * @param dh	The DataHandler that describes the data to be
108             *			passed to the command.
109             * @param loader	The ClassLoader to be used to instantiate the bean.
110             * @return The bean
111             * @see java.beans.Beans#instantiate
112             * @see javax.activation.CommandObject
113             */
114            public Object getCommandObject(DataHandler dh, ClassLoader loader)
115                    throws IOException, ClassNotFoundException {
116                Object new_bean = null;
117
118                // try to instantiate the bean
119                new_bean = java.beans.Beans.instantiate(loader, className);
120
121                // if we got one and it is a CommandObject
122                if (new_bean != null) {
123                    if (new_bean instanceof  CommandObject) {
124                        ((CommandObject) new_bean).setCommandContext(verb, dh);
125                    } else if (new_bean instanceof  Externalizable) {
126                        if (dh != null) {
127                            InputStream is = dh.getInputStream();
128                            if (is != null) {
129                                ((Externalizable) new_bean)
130                                        .readExternal(new ObjectInputStream(is));
131                            }
132                        }
133                    }
134                }
135
136                return new_bean;
137            }
138        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.