001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.lib.profiler.wireprotocol;
042:
043: import java.io.IOException;
044: import java.io.ObjectInputStream;
045: import java.io.ObjectOutputStream;
046:
047: /**
048: * Notification about a class load event that the server sends to the client.
049: *
050: * @author Misha Dmitriev
051: * @author Ian Formanek
052: */
053: public class ClassLoadedCommand extends Command {
054: //~ Instance fields ----------------------------------------------------------------------------------------------------------
055:
056: private String className;
057: private byte[] classFileBytes;
058: private int[] this AndParentLoaderData;
059: private boolean threadInCallGraph;
060:
061: //~ Constructors -------------------------------------------------------------------------------------------------------------
062:
063: public ClassLoadedCommand(String className,
064: int[] this AndParentLoaderData, byte[] classFileBytes,
065: boolean threadInCallGraph) {
066: super (CLASS_LOADED);
067: this .className = className;
068: this .this AndParentLoaderData = this AndParentLoaderData;
069: this .classFileBytes = classFileBytes;
070: this .threadInCallGraph = threadInCallGraph;
071: }
072:
073: // Custom serialization support
074: ClassLoadedCommand() {
075: super (CLASS_LOADED);
076: }
077:
078: //~ Methods ------------------------------------------------------------------------------------------------------------------
079:
080: public byte[] getClassFileBytes() {
081: return classFileBytes;
082: }
083:
084: public String getClassName() {
085: return className;
086: }
087:
088: public int[] getThisAndParentLoaderData() {
089: return this AndParentLoaderData;
090: }
091:
092: public boolean getThreadInCallGraph() {
093: return threadInCallGraph;
094: }
095:
096: // for debugging
097: public String toString() {
098: return super .toString()
099: + ", className: "
100: + className // NOI18N
101: + ", threadInCallGraph: "
102: + threadInCallGraph // NOI18N
103: + ", thisAndParentLoaderData: " // NOI18N
104: + this AndParentLoaderData[0]
105: + ", " // NOI18N
106: + this AndParentLoaderData[1]
107: + ", " // NOI18N
108: + this AndParentLoaderData[2]
109: + ", classFileBytes: "
110: + ((classFileBytes == null) ? "null"
111: : ("" + classFileBytes.length)); // NOI18N
112: }
113:
114: void readObject(ObjectInputStream in) throws IOException {
115: className = in.readUTF();
116: this AndParentLoaderData = new int[3];
117:
118: for (int i = 0; i < 3; i++) {
119: this AndParentLoaderData[i] = in.readInt();
120: }
121:
122: int len = in.readInt();
123:
124: if (len == 0) {
125: classFileBytes = null;
126: } else {
127: classFileBytes = new byte[len];
128: in.readFully(classFileBytes);
129: }
130:
131: threadInCallGraph = in.readBoolean();
132: }
133:
134: void writeObject(ObjectOutputStream out) throws IOException {
135: out.writeUTF(className);
136:
137: for (int i = 0; i < 3; i++) {
138: out.writeInt(this AndParentLoaderData[i]);
139: }
140:
141: if (classFileBytes != null) {
142: out.writeInt(classFileBytes.length);
143: out.write(classFileBytes);
144: classFileBytes = null;
145: } else {
146: out.writeInt(0);
147: }
148:
149: out.writeBoolean(threadInCallGraph);
150: }
151: }
|