01: /* Copyright 2002-2005 The Apache Software Foundation
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel;
17:
18: import java.awt.datatransfer.DataFlavor;
19: import java.awt.datatransfer.UnsupportedFlavorException;
20:
21: import org.apache.ojb.broker.metadata.AttributeDescriptorBase;
22:
23: /**
24: *
25: * @author Florian Bruckner
26: */
27: public class OjbMetadataTransferable implements
28: java.awt.datatransfer.Transferable {
29:
30: public static final DataFlavor OJBMETADATA_FLAVOR
31: // = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + "; class=org.apache.ojb.broker.metadata.AttributeDescriptorBase[]", "OJB Repository metadata objects");
32: = new DataFlavor(
33: org.apache.ojb.broker.metadata.AttributeDescriptorBase[].class,
34: "OJB");
35:
36: private static final DataFlavor[] _flavors = { OJBMETADATA_FLAVOR };
37:
38: private AttributeDescriptorBase[] selectedDescriptors;
39:
40: /** Creates a new instance of OjbMetadataTransferable */
41: public OjbMetadataTransferable(
42: AttributeDescriptorBase[] pSelectedDescriptors) {
43: selectedDescriptors = pSelectedDescriptors;
44: }
45:
46: /** Returns an object which represents the data to be transferred. The class
47: * of the object returned is defined by the representation class of the flavor.
48: *
49: * @param flavor the requested flavor for the data
50: * @see DataFlavor#getRepresentationClass
51: * @exception IOException if the data is no longer available
52: * in the requested flavor.
53: * @exception UnsupportedFlavorException if the requested data flavor is
54: * not supported.
55: *
56: */
57: public Object getTransferData(DataFlavor flavor)
58: throws UnsupportedFlavorException, java.io.IOException {
59: if (flavor.isMimeTypeEqual(OJBMETADATA_FLAVOR))
60: return selectedDescriptors;
61: else
62: throw new UnsupportedFlavorException(flavor);
63: }
64:
65: /** Returns an array of DataFlavor objects indicating the flavors the data
66: * can be provided in. The array should be ordered according to preference
67: * for providing the data (from most richly descriptive to least descriptive).
68: * @return an array of data flavors in which this data can be transferred
69: *
70: */
71: public DataFlavor[] getTransferDataFlavors() {
72: return _flavors;
73: }
74:
75: /** Returns whether or not the specified data flavor is supported for
76: * this object.
77: * @param flavor the requested flavor for the data
78: * @return boolean indicating whether or not the data flavor is supported
79: *
80: */
81: public boolean isDataFlavorSupported(DataFlavor flavor) {
82: return java.util.Arrays.asList(_flavors).contains(flavor);
83: }
84:
85: }
|