KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > attachments > AttachmentUtils


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.jboss.axis.attachments;
17
18 import org.jboss.axis.AxisFault;
19 import org.jboss.axis.Part;
20 import org.jboss.axis.utils.Messages;
21
22 import javax.activation.DataHandler JavaDoc;
23
24 /**
25  * This class allow access to the Jaf data handler in AttachmentPart.
26  *
27  * @author Rick Rineholt
28  */

29 public class AttachmentUtils
30 {
31
32    private AttachmentUtils()
33    {
34    }
35    // no one should create.
36

37    /**
38     * Obtain the DataHandler from the part.
39     *
40     * @param part the part containing the Java Activiation Framework data source.
41     * @return The Java activation data handler.
42     * @throws AxisFault
43     */

44    public static DataHandler JavaDoc getActivationDataHandler(Part part)
45            throws AxisFault
46    {
47
48       if (null == part)
49       {
50          throw new AxisFault(Messages.getMessage("gotNullPart"));
51       }
52
53       if (!(part instanceof AttachmentPartImpl))
54       {
55          throw new AxisFault(Messages.getMessage("unsupportedAttach", part.getClass().getName(),
56                  AttachmentPartImpl.class.getName()));
57       }
58
59       return ((AttachmentPartImpl)part).getActivationDataHandler();
60    }
61
62    /**
63     * Determine if an object is to be treated as an attchment.
64     *
65     * @param value the value that is to be determined if
66     * its an attachment.
67     * @return True if value should be treated as an attchment.
68     */

69    public static boolean isAttachment(Object JavaDoc value)
70    {
71
72       if (null == value)
73       {
74          return false;
75       }
76
77       return value instanceof javax.activation.DataHandler JavaDoc;
78    }
79 }
Popular Tags