001 /**
002 *
003 * Copyright 2003-2004 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package javax.activation;
019
020 import java.awt.datatransfer.DataFlavor;
021 import java.io.InputStream;
022
023 /**
024 * @version $Rev: 158704 $ $Date: 2005-03-22 17:53:37 -0800 (Tue, 22 Mar 2005) $
025 */
026 public class ActivationDataFlavor extends DataFlavor {
027 private final Class representationClass;
028 private final String mimeType;
029 private String humanPresentableName;
030
031 public ActivationDataFlavor(Class representationClass, String mimeType, String humanPresentableName) {
032 this.representationClass = representationClass;
033 this.mimeType = mimeType;
034 this.humanPresentableName = humanPresentableName;
035 }
036
037 public ActivationDataFlavor(Class representationClass, String humanPresentableName) {
038 this.representationClass = representationClass;
039 this.mimeType = "application/x-java-serialized-object";
040 this.humanPresentableName = humanPresentableName;
041 }
042
043 public ActivationDataFlavor(String mimeType, String humanPresentableName) {
044 this.mimeType = mimeType;
045 this.representationClass = InputStream.class;
046 this.humanPresentableName = humanPresentableName;
047 }
048
049 public String getMimeType() {
050 return mimeType;
051 }
052
053 public Class getRepresentationClass() {
054 return representationClass;
055 }
056
057 public String getHumanPresentableName() {
058 return humanPresentableName;
059 }
060
061 public void setHumanPresentableName(String humanPresentableName) {
062 this.humanPresentableName = humanPresentableName;
063 }
064
065 public boolean equals(DataFlavor dataFlavor) {
066 return this.isMimeTypeEqual(dataFlavor.getMimeType()) && representationClass == dataFlavor.getRepresentationClass();
067 }
068
069 public boolean isMimeTypeEqual(String mimeType) {
070 try {
071 MimeType thisType = new MimeType(this.mimeType);
072 MimeType thatType = new MimeType(mimeType);
073 return thisType.match(thatType);
074 } catch (MimeTypeParseException e) {
075 return false;
076 }
077 }
078
079 protected String normalizeMimeTypeParameter(String parameterName, String parameterValue) {
080 return parameterName + "=" + parameterValue;
081 }
082
083 protected String normalizeMimeType(String mimeType) {
084 return mimeType;
085 }
086 }