KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > 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.apache.axis.attachments;
17
18 import org.apache.axis.AxisFault;
19 import org.apache.axis.Part;
20 import org.apache.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     private AttachmentUtils() {
32     }
33     // no one should create.
34

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

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

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