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