001/* ActivationDataFlavor.java -- Activation-specific DataFlavor instance. 002 Copyright (C) 2004 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038package javax.activation; 039 040import gnu.java.lang.CPStringBuilder; 041 042import java.awt.datatransfer.DataFlavor; 043import java.io.InputStream; 044 045/** 046 * Activation-specific DataFlavor with improved MIME parsing. 047 * 048 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> 049 * @version 1.0.2 050 */ 051public class ActivationDataFlavor extends DataFlavor 052{ 053 054 private final String mimeType; 055 private final Class<?> representationClass; 056 private String humanPresentableName; 057 058 /** 059 * Constructor. 060 * @param representationClass the representation class 061 * @param mimeType the MIME type of the data 062 * @param humanPresentableName the human-presentable name of the data 063 * flavor 064 */ 065 // Raw types enforced as part of spec. 066 @SuppressWarnings("unchecked") 067 public ActivationDataFlavor(Class representationClass, String mimeType, 068 String humanPresentableName) 069 { 070 super(mimeType, humanPresentableName); 071 this.mimeType = mimeType; 072 this.humanPresentableName = humanPresentableName; 073 this.representationClass = representationClass; 074 } 075 076 /** 077 * Constructor. 078 * @param representationClass the representation class 079 * @param humanPresentableName the human-presentable name of the data 080 * flavor 081 */ 082 // Raw types enforced as part of spec. 083 @SuppressWarnings("unchecked") 084 public ActivationDataFlavor(Class representationClass, 085 String humanPresentableName) 086 { 087 super(representationClass, humanPresentableName); 088 mimeType = super.getMimeType(); 089 this.representationClass = representationClass; 090 this.humanPresentableName = humanPresentableName; 091 } 092 093 /** 094 * Constructor. The representation class is an InputStream. 095 * @param mimeType the MIME type of the data 096 * @param humanPresentableName the human-presentable name of the data 097 * flavor 098 */ 099 public ActivationDataFlavor(String mimeType, String humanPresentableName) 100 { 101 super(mimeType, humanPresentableName); 102 this.mimeType = mimeType; 103 this.humanPresentableName = humanPresentableName; 104 representationClass = InputStream.class; 105 } 106 107 public String getMimeType() 108 { 109 return mimeType; 110 } 111 112 // Raw types enforced as part of spec. 113 @SuppressWarnings("unchecked") 114 public Class getRepresentationClass() 115 { 116 return representationClass; 117 } 118 119 public String getHumanPresentableName() 120 { 121 return humanPresentableName; 122 } 123 124 public void setHumanPresentableName(String humanPresentableName) 125 { 126 this.humanPresentableName = humanPresentableName; 127 } 128 129 public boolean equals(DataFlavor dataFlavor) 130 { 131 return (isMimeTypeEqual(dataFlavor) && 132 dataFlavor.getRepresentationClass() == representationClass); 133 } 134 135 public boolean isMimeTypeEqual(String mimeType) 136 { 137 try 138 { 139 return new MimeType(this.mimeType).match(new MimeType(mimeType)); 140 } 141 catch (MimeTypeParseException e) 142 { 143 return false; 144 } 145 } 146 147 protected String normalizeMimeTypeParameter(String parameterName, 148 String parameterValue) 149 { 150 return new CPStringBuilder(parameterName) 151 .append('=') 152 .append(parameterValue) 153 .toString(); 154 } 155 156 protected String normalizeMimeType(String mimeType) 157 { 158 return mimeType; 159 } 160 161}