KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > gui > AJValueWrapper


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22
23 package org.aspectj.debugger.gui;
24
25 import org.aspectj.debugger.base.*;
26
27 import java.awt.datatransfer.DataFlavor JavaDoc;
28 import java.awt.datatransfer.Transferable JavaDoc;
29 import java.io.Serializable JavaDoc;
30 import com.sun.jdi.InvalidTypeException;
31 import com.sun.jdi.Value;
32
33 import com.sun.jdi.*;
34
35 public class AJValueWrapper implements Transferable JavaDoc,
36                                        Serializable JavaDoc {
37
38     Object JavaDoc value = null;
39     
40     public AJValueWrapper(Value value) {
41         this.value = wrap(value);
42     }
43     
44     public Value unwrap() {
45         Value result = null;
46         try {
47             VirtualMachine vm = ComponentRepository.vm();
48             if (value instanceof Byte JavaDoc) {
49                 result = vm.mirrorOf( ((Byte JavaDoc)value).byteValue() );
50             } else if (value instanceof Character JavaDoc) {
51                 result = vm.mirrorOf(((Character JavaDoc)value).charValue());
52             } else if (value instanceof Double JavaDoc) {
53                 result = vm.mirrorOf( ((Double JavaDoc)value).doubleValue() );
54             } else if (value instanceof Float JavaDoc) {
55                 result = vm.mirrorOf( ((Float JavaDoc)value).floatValue() );
56             } else if (value instanceof Integer JavaDoc) {
57                 result = vm.mirrorOf( ((Integer JavaDoc)value).intValue() );
58             } else if (value instanceof Long JavaDoc) {
59                 result = vm.mirrorOf( ((Long JavaDoc)value).longValue() );
60             } else if (value instanceof Short JavaDoc) {
61                 result = vm.mirrorOf( ((Short JavaDoc)value).shortValue() );
62             } else if (value instanceof String JavaDoc) {
63                 result = vm.mirrorOf( ((String JavaDoc)value).toString() );
64             }
65         } catch (DebuggerException e) {
66         }
67         return result;
68     }
69
70     private Object JavaDoc wrap(Value value) {
71         Object JavaDoc result = null;
72         if (value instanceof ByteValue) {
73             result = new Byte JavaDoc( ((ByteValue)value).byteValue() );
74         } else if (value instanceof CharValue) {
75             result = new Character JavaDoc( ((CharValue)value).charValue() );
76         } else if (value instanceof DoubleValue) {
77             result = new Double JavaDoc( ((DoubleValue)value).doubleValue() );
78         } else if (value instanceof FloatValue) {
79             result = new Float JavaDoc( ((FloatValue)value).floatValue() );
80         } else if (value instanceof IntegerValue) {
81             result = new Integer JavaDoc( ((IntegerValue)value).intValue() );
82         } else if (value instanceof LongValue) {
83             result = new Long JavaDoc( ((LongValue)value).longValue() );
84         } else if (value instanceof ShortValue) {
85             result = new Short JavaDoc( ((ShortValue)value).shortValue() );
86         } else if (value instanceof StringReference) {
87             result = new String JavaDoc( ((StringReference)value).toString() );
88         }
89         return result;
90     }
91
92     /*
93      * Transferable stuff
94      */

95      //TODO: Check the DataFlavor
96
public Object JavaDoc getTransferData(DataFlavor JavaDoc flavor) {
97         return this;
98      }
99
100     public DataFlavor JavaDoc[] getTransferDataFlavors() {
101         return AJDataFlavor.FLAVORS;
102     }
103
104     public boolean isDataFlavorSupported(DataFlavor JavaDoc flavor) {
105         boolean ok = false;
106         if (flavor.getHumanPresentableName().equals("AJValueWrapper")) {
107             ok = true;
108         }
109         return ok;
110     }
111 }
112
Popular Tags