src/share/classes/java/awt/datatransfer/DataFlavor.java

Print this page


   1 /*
   2  * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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


1167         return isMimeTypeEqual(dataFlavor.mimeType);
1168     }
1169 
1170     /**
1171      * Compares the <code>mimeType</code> of two <code>DataFlavor</code>
1172      * objects.  No parameters are considered.
1173      *
1174      * @return true if the <code>MimeType</code>s are equal,
1175      *  otherwise false
1176      */
1177 
1178     private boolean isMimeTypeEqual(MimeType mtype) {
1179         if (this.mimeType == null) {
1180             return (mtype == null);
1181         }
1182         return mimeType.match(mtype);
1183     }
1184 
1185    /**
1186     * Does the <code>DataFlavor</code> represent a serialized object?

1187     */
1188 
1189     public boolean isMimeTypeSerializedObject() {
1190         return isMimeTypeEqual(javaSerializedObjectMimeType);
1191     }
1192 




1193     public final Class<?> getDefaultRepresentationClass() {
1194         return ioInputStreamClass;
1195     }
1196 




1197     public final String getDefaultRepresentationClassAsString() {
1198         return getDefaultRepresentationClass().getName();
1199     }
1200 
1201    /**
1202     * Does the <code>DataFlavor</code> represent a
1203     * <code>java.io.InputStream</code>?


1204     */
1205 
1206     public boolean isRepresentationClassInputStream() {
1207         return ioInputStreamClass.isAssignableFrom(representationClass);
1208     }
1209 
1210     /**
1211      * Returns whether the representation class for this
1212      * <code>DataFlavor</code> is <code>java.io.Reader</code> or a subclass
1213      * thereof.



1214      *
1215      * @since 1.4
1216      */
1217     public boolean isRepresentationClassReader() {
1218         return java.io.Reader.class.isAssignableFrom(representationClass);
1219     }
1220 
1221     /**
1222      * Returns whether the representation class for this
1223      * <code>DataFlavor</code> is <code>java.nio.CharBuffer</code> or a
1224      * subclass thereof.



1225      *
1226      * @since 1.4
1227      */
1228     public boolean isRepresentationClassCharBuffer() {
1229         return java.nio.CharBuffer.class.isAssignableFrom(representationClass);
1230     }
1231 
1232     /**
1233      * Returns whether the representation class for this
1234      * <code>DataFlavor</code> is <code>java.nio.ByteBuffer</code> or a
1235      * subclass thereof.



1236      *
1237      * @since 1.4
1238      */
1239     public boolean isRepresentationClassByteBuffer() {
1240         return java.nio.ByteBuffer.class.isAssignableFrom(representationClass);
1241     }
1242 
1243    /**
1244     * Returns true if the representation class can be serialized.
1245     * @return true if the representation class can be serialized
1246     */
1247 
1248     public boolean isRepresentationClassSerializable() {
1249         return java.io.Serializable.class.isAssignableFrom(representationClass);
1250     }
1251 
1252    /**
1253     * Returns true if the representation class is <code>Remote</code>.
1254     * @return true if the representation class is <code>Remote</code>
1255     */


1391     public Object clone() throws CloneNotSupportedException {
1392         Object newObj = super.clone();
1393         if (mimeType != null) {
1394             ((DataFlavor)newObj).mimeType = (MimeType)mimeType.clone();
1395         }
1396         return newObj;
1397     } // clone()
1398 
1399    /**
1400     * Called on <code>DataFlavor</code> for every MIME Type parameter
1401     * to allow <code>DataFlavor</code> subclasses to handle special
1402     * parameters like the text/plain <code>charset</code>
1403     * parameters, whose values are case insensitive.  (MIME type parameter
1404     * values are supposed to be case sensitive.
1405     * <p>
1406     * This method is called for each parameter name/value pair and should
1407     * return the normalized representation of the <code>parameterValue</code>.
1408     *
1409     * This method is never invoked by this implementation from 1.1 onwards.
1410     *



1411     * @deprecated
1412     */
1413     @Deprecated
1414     protected String normalizeMimeTypeParameter(String parameterName, String parameterValue) {
1415         return parameterValue;
1416     }
1417 
1418    /**
1419     * Called for each MIME type string to give <code>DataFlavor</code> subtypes
1420     * the opportunity to change how the normalization of MIME types is
1421     * accomplished.  One possible use would be to add default
1422     * parameter/value pairs in cases where none are present in the MIME
1423     * type string passed in.
1424     *
1425     * This method is never invoked by this implementation from 1.1 onwards.
1426     *


1427     * @deprecated
1428     */
1429     @Deprecated
1430     protected String normalizeMimeType(String mimeType) {
1431         return mimeType;
1432     }
1433 
1434     /*
1435      * fields
1436      */
1437 
1438     /* placeholder for caching any platform-specific data for flavor */
1439 
1440     transient int       atom;
1441 
1442     /* Mime Type of DataFlavor */
1443 
1444     MimeType            mimeType;
1445 
1446     private String      humanPresentableName;
   1 /*
   2  * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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


1167         return isMimeTypeEqual(dataFlavor.mimeType);
1168     }
1169 
1170     /**
1171      * Compares the <code>mimeType</code> of two <code>DataFlavor</code>
1172      * objects.  No parameters are considered.
1173      *
1174      * @return true if the <code>MimeType</code>s are equal,
1175      *  otherwise false
1176      */
1177 
1178     private boolean isMimeTypeEqual(MimeType mtype) {
1179         if (this.mimeType == null) {
1180             return (mtype == null);
1181         }
1182         return mimeType.match(mtype);
1183     }
1184 
1185    /**
1186     * Does the <code>DataFlavor</code> represent a serialized object?
1187     * @return whether or not a serialized object is represented
1188     */

1189     public boolean isMimeTypeSerializedObject() {
1190         return isMimeTypeEqual(javaSerializedObjectMimeType);
1191     }
1192 
1193     /**
1194      * Returns the default representation class.
1195      * @return the default representation class
1196      */
1197     public final Class<?> getDefaultRepresentationClass() {
1198         return ioInputStreamClass;
1199     }
1200 
1201     /**
1202      * Returns the name of the default representation class.
1203      * @return the name of the default representation class
1204      */
1205     public final String getDefaultRepresentationClassAsString() {
1206         return getDefaultRepresentationClass().getName();
1207     }
1208 
1209    /**
1210     * Does the <code>DataFlavor</code> represent a
1211     * <code>java.io.InputStream</code>?
1212     * @return whether or not this {@code DataFlavor} represent a
1213     * {@code java.io.InputStream}
1214     */

1215     public boolean isRepresentationClassInputStream() {
1216         return ioInputStreamClass.isAssignableFrom(representationClass);
1217     }
1218 
1219     /**
1220      * Returns whether the representation class for this
1221      * <code>DataFlavor</code> is <code>java.io.Reader</code> or a subclass
1222      * thereof.
1223      * @return whether or not the representation class for this
1224      * {@code DataFlavor} is {@code java.io.Reader} or a subclass
1225      * thereof
1226      *
1227      * @since 1.4
1228      */
1229     public boolean isRepresentationClassReader() {
1230         return java.io.Reader.class.isAssignableFrom(representationClass);
1231     }
1232 
1233     /**
1234      * Returns whether the representation class for this
1235      * <code>DataFlavor</code> is <code>java.nio.CharBuffer</code> or a
1236      * subclass thereof.
1237      * @return whether or not the representation class for this
1238      * {@code DataFlavor} is {@code java.nio.CharBuffer} or a subclass
1239      * thereof
1240      *
1241      * @since 1.4
1242      */
1243     public boolean isRepresentationClassCharBuffer() {
1244         return java.nio.CharBuffer.class.isAssignableFrom(representationClass);
1245     }
1246 
1247     /**
1248      * Returns whether the representation class for this
1249      * <code>DataFlavor</code> is <code>java.nio.ByteBuffer</code> or a
1250      * subclass thereof.
1251      * @return whether or not the representation class for this
1252      * {@code DataFlavor} is {@code java.nio.ByteBuffer} or a subclass
1253      * thereof
1254      *
1255      * @since 1.4
1256      */
1257     public boolean isRepresentationClassByteBuffer() {
1258         return java.nio.ByteBuffer.class.isAssignableFrom(representationClass);
1259     }
1260 
1261    /**
1262     * Returns true if the representation class can be serialized.
1263     * @return true if the representation class can be serialized
1264     */
1265 
1266     public boolean isRepresentationClassSerializable() {
1267         return java.io.Serializable.class.isAssignableFrom(representationClass);
1268     }
1269 
1270    /**
1271     * Returns true if the representation class is <code>Remote</code>.
1272     * @return true if the representation class is <code>Remote</code>
1273     */


1409     public Object clone() throws CloneNotSupportedException {
1410         Object newObj = super.clone();
1411         if (mimeType != null) {
1412             ((DataFlavor)newObj).mimeType = (MimeType)mimeType.clone();
1413         }
1414         return newObj;
1415     } // clone()
1416 
1417    /**
1418     * Called on <code>DataFlavor</code> for every MIME Type parameter
1419     * to allow <code>DataFlavor</code> subclasses to handle special
1420     * parameters like the text/plain <code>charset</code>
1421     * parameters, whose values are case insensitive.  (MIME type parameter
1422     * values are supposed to be case sensitive.
1423     * <p>
1424     * This method is called for each parameter name/value pair and should
1425     * return the normalized representation of the <code>parameterValue</code>.
1426     *
1427     * This method is never invoked by this implementation from 1.1 onwards.
1428     *
1429     * @param parameterName the parameter name
1430     * @param parameterValue the parameter value
1431     * @return the parameter value
1432     * @deprecated
1433     */
1434     @Deprecated
1435     protected String normalizeMimeTypeParameter(String parameterName, String parameterValue) {
1436         return parameterValue;
1437     }
1438 
1439    /**
1440     * Called for each MIME type string to give <code>DataFlavor</code> subtypes
1441     * the opportunity to change how the normalization of MIME types is
1442     * accomplished.  One possible use would be to add default
1443     * parameter/value pairs in cases where none are present in the MIME
1444     * type string passed in.
1445     *
1446     * This method is never invoked by this implementation from 1.1 onwards.
1447     *
1448     * @param mimeType the mime type
1449     * @return the mime type
1450     * @deprecated
1451     */
1452     @Deprecated
1453     protected String normalizeMimeType(String mimeType) {
1454         return mimeType;
1455     }
1456 
1457     /*
1458      * fields
1459      */
1460 
1461     /* placeholder for caching any platform-specific data for flavor */
1462 
1463     transient int       atom;
1464 
1465     /* Mime Type of DataFlavor */
1466 
1467     MimeType            mimeType;
1468 
1469     private String      humanPresentableName;