1 /** 2 * 3 * Copyright 2003-2004 The Apache Software Foundation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package javax.activation; 19 20 import java.awt.datatransfer.DataFlavor; 21 import java.io.InputStream; 22 23 /** 24 * @version $Rev: 158704 $ $Date: 2005-03-22 17:53:37 -0800 (Tue, 22 Mar 2005) $ 25 */ 26 public class ActivationDataFlavor extends DataFlavor { 27 private final Class representationClass; 28 private final String mimeType; 29 private String humanPresentableName; 30 31 public ActivationDataFlavor(Class representationClass, String mimeType, String humanPresentableName) { 32 this.representationClass = representationClass; 33 this.mimeType = mimeType; 34 this.humanPresentableName = humanPresentableName; 35 } 36 37 public ActivationDataFlavor(Class representationClass, String humanPresentableName) { 38 this.representationClass = representationClass; 39 this.mimeType = "application/x-java-serialized-object"; 40 this.humanPresentableName = humanPresentableName; 41 } 42 43 public ActivationDataFlavor(String mimeType, String humanPresentableName) { 44 this.mimeType = mimeType; 45 this.representationClass = InputStream.class; 46 this.humanPresentableName = humanPresentableName; 47 } 48 49 public String getMimeType() { 50 return mimeType; 51 } 52 53 public Class getRepresentationClass() { 54 return representationClass; 55 } 56 57 public String getHumanPresentableName() { 58 return humanPresentableName; 59 } 60 61 public void setHumanPresentableName(String humanPresentableName) { 62 this.humanPresentableName = humanPresentableName; 63 } 64 65 public boolean equals(DataFlavor dataFlavor) { 66 return this.isMimeTypeEqual(dataFlavor.getMimeType()) && representationClass == dataFlavor.getRepresentationClass(); 67 } 68 69 public boolean isMimeTypeEqual(String mimeType) { 70 try { 71 MimeType thisType = new MimeType(this.mimeType); 72 MimeType thatType = new MimeType(mimeType); 73 return thisType.match(thatType); 74 } catch (MimeTypeParseException e) { 75 return false; 76 } 77 } 78 79 protected String normalizeMimeTypeParameter(String parameterName, String parameterValue) { 80 return parameterName + "=" + parameterValue; 81 } 82 83 protected String normalizeMimeType(String mimeType) { 84 return mimeType; 85 } 86 }