1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  */
18 
19 /**
20  * @author Aleksey V. Yantsen
21  */
22 
23 /**
24  * Created on 10.25.2004
25  */
26 package org.apache.harmony.jpda.tests.framework.jdwp;
27 
28 import org.apache.harmony.jpda.tests.framework.DebuggeeWrapper;
29 import org.apache.harmony.jpda.tests.framework.LogWriter;
30 import org.apache.harmony.jpda.tests.framework.TestErrorException;
31 import org.apache.harmony.jpda.tests.framework.TestOptions;
32 import org.apache.harmony.jpda.tests.framework.jdwp.TransportWrapper;
33 import org.apache.harmony.jpda.tests.framework.jdwp.VmMirror;
34 
35 /**
36  * This class represents specific kind of <code>DebuggeeWrapper</code> for JDWP tests.
37  * It encapsulates JDWP connection and communicates with debuggee using
38  * command, reply, and event packets.
39  */
40 public abstract class JDWPDebuggeeWrapper extends DebuggeeWrapper {
41 
42     public VmMirror vmMirror;
43 
44     /**
45      * Creates an instance of JDWPDebuggeeWrapper.
46      *
47      * @param settings test run options
48      * @param logWriter logWriter for messages
49      */
JDWPDebuggeeWrapper(TestOptions settings, LogWriter logWriter)50     public JDWPDebuggeeWrapper(TestOptions settings, LogWriter logWriter) {
51         super(settings, logWriter);
52         vmMirror = createVmMirror(settings, logWriter);
53     }
54 
55     /**
56      * Creates new instance of appropriate TransportWrapper.
57      *
58      * @return new instance of TransportWrapper
59      */
createTransportWrapper()60     public TransportWrapper createTransportWrapper() {
61         String name = settings.getTransportWrapperClassName();
62         try {
63             Class cls = Class.forName(name);
64             return (TransportWrapper) cls.newInstance();
65         } catch (Exception e) {
66             throw new TestErrorException(e);
67         }
68     }
69 
70     /**
71      * Creates new instance of VmMirror.
72      *
73      * @return new instance of VmMirror
74      */
createVmMirror(TestOptions settings, LogWriter logWriter)75     protected VmMirror createVmMirror(TestOptions settings, LogWriter logWriter) {
76         return new VmMirror(settings, logWriter);
77     }
78 
79     /**
80      * Returns opened JDWP connection or null.
81      *
82      * @return JDWP connection or null
83      */
getConnection()84     public TransportWrapper getConnection() {
85         return vmMirror.getConnection();
86     }
87 
88     /**
89      * Sets opened JDWP connection.
90      *
91      * @param connection to set
92      */
setConnection(TransportWrapper connection)93     public void setConnection(TransportWrapper connection) {
94         vmMirror.setConnection(connection);
95     }
96    /**
97      * Resumes debuggee VM.
98      */
resume()99     public void resume() {
100         vmMirror.resume();
101     }
102 
103     /**
104      * Disposes debuggee VM.
105      */
dispose()106     public void dispose() {
107         vmMirror.dispose();
108     }
109 
110     /**
111      * Exit target Virtual Machine
112      */
exit(int exitStatus)113     public void exit(int exitStatus) {
114         vmMirror.exit(exitStatus);
115     }
116 
117 
118 }
119