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.results.cpu.cct.nodes;
042:
043: import org.netbeans.lib.profiler.results.cpu.cct.*;
044:
045: /**
046: *
047: * @author Jaroslav Bachorik
048: */
049: public class ServletRequestCPUCCTNode extends TimedCPUCCTNode {
050: //~ Inner Classes ------------------------------------------------------------------------------------------------------------
051:
052: public static class Locator extends RuntimeCPUCCTNodeVisitorAdaptor {
053: //~ Instance fields ------------------------------------------------------------------------------------------------------
054:
055: private ServletRequestCPUCCTNode cctNodeCandidate = null;
056: private String servletPath;
057: private int requestType;
058:
059: //~ Constructors ---------------------------------------------------------------------------------------------------------
060:
061: private Locator() {
062: }
063:
064: //~ Methods --------------------------------------------------------------------------------------------------------------
065:
066: public static ServletRequestCPUCCTNode locate(int requestType,
067: String servletPath, RuntimeCPUCCTNode.Children nodes) {
068: Locator instance = new Locator();
069:
070: return instance.doLocate(requestType, servletPath, nodes);
071: }
072:
073: public void visit(ServletRequestCPUCCTNode node) {
074: if (node.getServletPath().equals(servletPath)
075: && (node.getRequestType() == requestType)) {
076: cctNodeCandidate = node;
077: }
078: }
079:
080: private ServletRequestCPUCCTNode doLocate(int requestType,
081: String servletPath, RuntimeCPUCCTNode.Children nodes) {
082: cctNodeCandidate = null;
083: this .requestType = requestType;
084: this .servletPath = servletPath;
085: nodes.accept(this );
086:
087: return cctNodeCandidate;
088: }
089: }
090:
091: //~ Instance fields ----------------------------------------------------------------------------------------------------------
092:
093: int hashCode = 0;
094: private final String servletPath;
095: private final int requestType;
096:
097: //~ Constructors -------------------------------------------------------------------------------------------------------------
098:
099: /**
100: * Creates a new instance of ServletRequestCPUCCTNode
101: */
102: public ServletRequestCPUCCTNode(CPUCCTNodeFactory factory,
103: int requestType, String path,
104: boolean collectingTwoTimestamps) {
105: super (factory, collectingTwoTimestamps);
106: this .servletPath = path;
107: this .requestType = requestType;
108: setFilteredStatus(FILTERED_YES); // boundary node is going to be filtered by default
109: setNCalls(0);
110: }
111:
112: //~ Methods ------------------------------------------------------------------------------------------------------------------
113:
114: public int getRequestType() {
115: return requestType;
116: }
117:
118: public boolean isRoot() {
119: return false;
120: }
121:
122: public String getServletPath() {
123: return servletPath;
124: }
125:
126: public void accept(RuntimeCPUCCTNodeVisitor visitor) {
127: visitor.visit(this );
128: }
129:
130: public boolean equals(Object otherNode) {
131: if (otherNode == null) {
132: return false;
133: }
134:
135: if (!(otherNode instanceof ServletRequestCPUCCTNode)) {
136: return false;
137: }
138:
139: return servletPath
140: .equals(((ServletRequestCPUCCTNode) otherNode).servletPath)
141: && (requestType == ((ServletRequestCPUCCTNode) otherNode).requestType);
142: }
143:
144: public int hashCode() {
145: if (hashCode == 0) {
146: hashCode = servletPath.hashCode() + (requestType * 18321);
147: }
148:
149: return hashCode;
150: }
151:
152: protected TimedCPUCCTNode createSelfInstance() {
153: CPUCCTNodeFactory factory = getFactory();
154:
155: return (factory != null) ? factory.createServletRequestNode(
156: requestType, servletPath) : null;
157: }
158: }
|