< prev index next >

src/java.activation/share/classes/javax/activation/ActivationDataFlavor.java

Print this page




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.activation;
  27 
  28 import java.awt.datatransfer.DataFlavor;
  29 import java.io.IOException;
  30 import javax.activation.MimeType;
  31 
  32 /**
  33  * The ActivationDataFlavor class is a special subclass of
  34  * <code>java.awt.datatransfer.DataFlavor</code>. It allows the JAF to
  35  * set all three values stored by the DataFlavor class via a new
  36  * constructor. It also contains improved MIME parsing in the <code>equals
  37  * </code> method. Except for the improved parsing, its semantics are
  38  * identical to that of the JDK's DataFlavor class.
  39  *
  40  * @since 1.6
  41  */
  42 
  43 public class ActivationDataFlavor extends DataFlavor {
  44 
  45     /*
  46      * Raison d'etre:
  47      *
  48      * The DataFlavor class included in JDK 1.1 has several limitations
  49      * including piss poor MIME type parsing, and the limitation of
  50      * only supporting serialized objects and InputStreams as
  51      * representation objects. This class 'fixes' that.
  52      */
  53 
  54     // I think for now I'll keep copies of all the variables and
  55     // then later I may choose try to better coexist with the base
  56     // class *sigh*
  57     private String mimeType = null;
  58     private MimeType mimeObject = null;
  59     private String humanPresentableName = null;
  60     private Class representationClass = null;
  61 
  62     /**
  63      * Construct a DataFlavor that represents an arbitrary
  64      * Java object. This constructor is an extension of the
  65      * JDK's DataFlavor in that it allows the explicit setting
  66      * of all three DataFlavor attributes.
  67      * <p>
  68      * The returned DataFlavor will have the following characteristics:
  69      * <p>
  70      * representationClass = representationClass<br>
  71      * mimeType            = mimeType<br>
  72      * humanName           = humanName
  73      * <p>
  74      *
  75      * @param representationClass the class used in this DataFlavor
  76      * @param mimeType the MIME type of the data represented by this class
  77      * @param humanPresentableName the human presentable name of the flavor
  78      */
  79     public ActivationDataFlavor(Class representationClass,
  80                       String mimeType, String humanPresentableName) {
  81         super(mimeType, humanPresentableName); // need to call super
  82 
  83         // init private variables:
  84         this.mimeType = mimeType;
  85         this.humanPresentableName = humanPresentableName;
  86         this.representationClass = representationClass;
  87     }
  88 
  89     /**
  90      * Construct a DataFlavor that represents a MimeType.
  91      * <p>
  92      * The returned DataFlavor will have the following characteristics:
  93      * <p>
  94      * If the mimeType is "application/x-java-serialized-object;
  95      * class=", the result is the same as calling new
  96      * DataFlavor(Class.forName()) as above.
  97      * <p>
  98      * otherwise:
  99      * <p>
 100      * representationClass = InputStream<p>
 101      * mimeType = mimeType<p>
 102      *
 103      * @param representationClass the class used in this DataFlavor
 104      * @param humanPresentableName the human presentable name of the flavor
 105      */
 106     public ActivationDataFlavor(Class representationClass,
 107                                 String humanPresentableName) {
 108         super(representationClass, humanPresentableName);
 109         this.mimeType = super.getMimeType();
 110         this.representationClass = representationClass;
 111         this.humanPresentableName = humanPresentableName;
 112     }
 113 
 114     /**
 115      * Construct a DataFlavor that represents a MimeType.
 116      * <p>
 117      * The returned DataFlavor will have the following characteristics:
 118      * <p>
 119      * If the mimeType is "application/x-java-serialized-object; class=",
 120      * the result is the same as calling new DataFlavor(Class.forName()) as
 121      * above, otherwise:


 158     /**
 159      * Return the Human Presentable name.
 160      *
 161      * @return  the human presentable name
 162      */
 163     public String getHumanPresentableName() {
 164         return humanPresentableName;
 165     }
 166 
 167     /**
 168      * Set the human presentable name.
 169      *
 170      * @param humanPresentableName      the name to set
 171      */
 172     public void setHumanPresentableName(String humanPresentableName) {
 173         this.humanPresentableName = humanPresentableName;
 174     }
 175 
 176     /**
 177      * Compares the DataFlavor passed in with this DataFlavor; calls
 178      * the <code>isMimeTypeEqual</code> method.
 179      *
 180      * @param dataFlavor        the DataFlavor to compare with
 181      * @return                  true if the MIME type and representation class
 182      *                          are the same
 183      */
 184     public boolean equals(DataFlavor dataFlavor) {
 185         return (isMimeTypeEqual(dataFlavor) &&
 186                 dataFlavor.getRepresentationClass() == representationClass);
 187     }
 188 
 189     /**
 190      * Is the string representation of the MIME type passed in equivalent
 191      * to the MIME type of this DataFlavor. <p>
 192      *
 193      * ActivationDataFlavor delegates the comparison of MIME types to
 194      * the MimeType class included as part of the JavaBeans Activation
 195      * Framework. This provides a more robust comparison than is normally
 196      * available in the DataFlavor class.
 197      *
 198      * @param mimeType  the MIME type




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.activation;
  27 
  28 import java.awt.datatransfer.DataFlavor;
  29 import java.io.IOException;
  30 import javax.activation.MimeType;
  31 
  32 /**
  33  * The ActivationDataFlavor class is a special subclass of
  34  * {@code java.awt.datatransfer.DataFlavor}. It allows the JAF to
  35  * set all three values stored by the DataFlavor class via a new
  36  * constructor. It also contains improved MIME parsing in the {@code equals}
  37  * method. Except for the improved parsing, its semantics are
  38  * identical to that of the JDK's DataFlavor class.
  39  *
  40  * @since 1.6
  41  */
  42 
  43 public class ActivationDataFlavor extends DataFlavor {
  44 
  45     /*
  46      * Raison d'etre:
  47      *
  48      * The DataFlavor class included in JDK 1.1 has several limitations
  49      * including piss poor MIME type parsing, and the limitation of
  50      * only supporting serialized objects and InputStreams as
  51      * representation objects. This class 'fixes' that.
  52      */
  53 
  54     // I think for now I'll keep copies of all the variables and
  55     // then later I may choose try to better coexist with the base
  56     // class *sigh*
  57     private String mimeType = null;
  58     private MimeType mimeObject = null;
  59     private String humanPresentableName = null;
  60     private Class representationClass = null;
  61 
  62     /**
  63      * Construct a DataFlavor that represents an arbitrary
  64      * Java object. This constructor is an extension of the
  65      * JDK's DataFlavor in that it allows the explicit setting
  66      * of all three DataFlavor attributes.
  67      * <p>
  68      * The returned DataFlavor will have the following characteristics:
  69      * <p>
  70      * representationClass = representationClass<br>
  71      * mimeType            = mimeType<br>
  72      * humanName           = humanName

  73      *
  74      * @param representationClass the class used in this DataFlavor
  75      * @param mimeType the MIME type of the data represented by this class
  76      * @param humanPresentableName the human presentable name of the flavor
  77      */
  78     public ActivationDataFlavor(Class representationClass,
  79                       String mimeType, String humanPresentableName) {
  80         super(mimeType, humanPresentableName); // need to call super
  81 
  82         // init private variables:
  83         this.mimeType = mimeType;
  84         this.humanPresentableName = humanPresentableName;
  85         this.representationClass = representationClass;
  86     }
  87 
  88     /**
  89      * Construct a DataFlavor that represents a MimeType.
  90      * <p>
  91      * The returned DataFlavor will have the following characteristics:
  92      * <p>
  93      * If the mimeType is "application/x-java-serialized-object;
  94      * class=", the result is the same as calling new
  95      * DataFlavor(Class.forName()) as above.
  96      * <p>
  97      * otherwise:
  98      * <p>
  99      * representationClass = InputStream<p>
 100      * mimeType = mimeType
 101      *
 102      * @param representationClass the class used in this DataFlavor
 103      * @param humanPresentableName the human presentable name of the flavor
 104      */
 105     public ActivationDataFlavor(Class representationClass,
 106                                 String humanPresentableName) {
 107         super(representationClass, humanPresentableName);
 108         this.mimeType = super.getMimeType();
 109         this.representationClass = representationClass;
 110         this.humanPresentableName = humanPresentableName;
 111     }
 112 
 113     /**
 114      * Construct a DataFlavor that represents a MimeType.
 115      * <p>
 116      * The returned DataFlavor will have the following characteristics:
 117      * <p>
 118      * If the mimeType is "application/x-java-serialized-object; class=",
 119      * the result is the same as calling new DataFlavor(Class.forName()) as
 120      * above, otherwise:


 157     /**
 158      * Return the Human Presentable name.
 159      *
 160      * @return  the human presentable name
 161      */
 162     public String getHumanPresentableName() {
 163         return humanPresentableName;
 164     }
 165 
 166     /**
 167      * Set the human presentable name.
 168      *
 169      * @param humanPresentableName      the name to set
 170      */
 171     public void setHumanPresentableName(String humanPresentableName) {
 172         this.humanPresentableName = humanPresentableName;
 173     }
 174 
 175     /**
 176      * Compares the DataFlavor passed in with this DataFlavor; calls
 177      * the {@code isMimeTypeEqual} method.
 178      *
 179      * @param dataFlavor        the DataFlavor to compare with
 180      * @return                  true if the MIME type and representation class
 181      *                          are the same
 182      */
 183     public boolean equals(DataFlavor dataFlavor) {
 184         return (isMimeTypeEqual(dataFlavor) &&
 185                 dataFlavor.getRepresentationClass() == representationClass);
 186     }
 187 
 188     /**
 189      * Is the string representation of the MIME type passed in equivalent
 190      * to the MIME type of this DataFlavor. <p>
 191      *
 192      * ActivationDataFlavor delegates the comparison of MIME types to
 193      * the MimeType class included as part of the JavaBeans Activation
 194      * Framework. This provides a more robust comparison than is normally
 195      * available in the DataFlavor class.
 196      *
 197      * @param mimeType  the MIME type


< prev index next >