KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb2 > ojbmetatreemodel > OjbMetadataTransferable


1 /* Copyright 2002-2005 The Apache Software Foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * 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 JavaDoc;
19 import java.awt.datatransfer.UnsupportedFlavorException JavaDoc;
20
21 import org.apache.ojb.broker.metadata.AttributeDescriptorBase;
22 /**
23  *
24  * @author Florian Bruckner
25  */

26 public class OjbMetadataTransferable implements java.awt.datatransfer.Transferable JavaDoc
27 {
28     
29     public static final DataFlavor JavaDoc OJBMETADATA_FLAVOR
30     // = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + "; class=org.apache.ojb.broker.metadata.AttributeDescriptorBase[]", "OJB Repository metadata objects");
31
= new DataFlavor JavaDoc(org.apache.ojb.broker.metadata.AttributeDescriptorBase[].class, "OJB");
32     
33     private static final DataFlavor JavaDoc[] _flavors = {OJBMETADATA_FLAVOR};
34     
35     private AttributeDescriptorBase[] selectedDescriptors;
36     
37     /** Creates a new instance of OjbMetadataTransferable */
38     public OjbMetadataTransferable(AttributeDescriptorBase[] pSelectedDescriptors)
39     {
40         selectedDescriptors = pSelectedDescriptors;
41     }
42         
43     /** Returns an object which represents the data to be transferred. The class
44      * of the object returned is defined by the representation class of the flavor.
45      *
46      * @param flavor the requested flavor for the data
47      * @see DataFlavor#getRepresentationClass
48      * @exception IOException if the data is no longer available
49      * in the requested flavor.
50      * @exception UnsupportedFlavorException if the requested data flavor is
51      * not supported.
52      *
53      */

54     public Object JavaDoc getTransferData(DataFlavor JavaDoc flavor) throws UnsupportedFlavorException JavaDoc, java.io.IOException JavaDoc
55     {
56         if (flavor.isMimeTypeEqual(OJBMETADATA_FLAVOR))
57             return selectedDescriptors;
58         else
59             throw new UnsupportedFlavorException JavaDoc(flavor);
60     }
61     
62     /** Returns an array of DataFlavor objects indicating the flavors the data
63      * can be provided in. The array should be ordered according to preference
64      * for providing the data (from most richly descriptive to least descriptive).
65      * @return an array of data flavors in which this data can be transferred
66      *
67      */

68     public DataFlavor JavaDoc[] getTransferDataFlavors()
69     {
70         return _flavors;
71     }
72     
73     /** Returns whether or not the specified data flavor is supported for
74      * this object.
75      * @param flavor the requested flavor for the data
76      * @return boolean indicating whether or not the data flavor is supported
77      *
78      */

79     public boolean isDataFlavorSupported(DataFlavor JavaDoc flavor)
80     {
81          return java.util.Arrays.asList(_flavors).contains(flavor);
82     }
83     
84 }
85
Popular Tags