1
2 /*
3 * Copyright (C) 2005 by Arno Schumacher
4 *
5 * This file is part of net.sourceforge.servletspy
6 *
7 * net.sourceforge.servletspy is free software; you can redistribute
8 * it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation; either
10 * version 2, or (at your option) any later version.
11 *
12 * net.sourceforge.servletspy is distributed in the hope that it will
13 * be useful, but WITHOUT ANY WARRANTY; without even the implied
14 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA
20 */
21
22 package net.sourceforge.servletspy.handler.std;
23
24 import java.util.Map;
25
26 import net.sourceforge.servletspy.IContext;
27 import net.sourceforge.servletspy.IContextHandler;
28 import net.sourceforge.servletspy.Node;
29 import net.sourceforge.servletspy.config.Param;
30 import net.sourceforge.servletspy.ctx.Context;
31
32 /***
33 * @author arno schumacher
34 */
35 public final class CycleDetectorHandler implements IContextHandler {
36
37 /*
38 * (non-Javadoc)
39 *
40 * @see net.sourceforge.servletspy.ILifecycle#init(net.sourceforge.servletspy.config.Param[])
41 */
42 public void init(final Param[] params) {
43 }
44
45 /*
46 * (non-Javadoc)
47 *
48 * @see net.sourceforge.servletspy.ILifecycle#destroy()
49 */
50 public void destroy() {
51 }
52
53 /*
54 * (non-Javadoc)
55 *
56 * @see net.sourceforge.servletspy.IContextHandler#handle(net.sourceforge.servletspy.IContext)
57 */
58 public final void handle(final IContext context) throws Exception {
59 doHandle((Context) context);
60 }
61
62 /***
63 * @param context
64 * The context
65 */
66 private void doHandle(final Context context) {
67
68 // TODO Temp workaround for org.ofbiz.core.entity.GenericEntity
69 // com.atlassian.jira-3.2.2 ClassCastException. Check it!
70 try {
71 final Object anObject = new Object();
72 context.getSubject().equals(anObject);
73 } catch (Throwable t) {
74 context.proceed();
75 return;
76 }
77 // END FIX
78
79 final Map introspected = context.getIntrospectedMap();
80 if (introspected.containsKey(context.getSubject())) {
81 context.getNode().setReference(
82 (Node) introspected.get(context.getSubject()));
83 } else {
84 introspected.put(context.getSubject(), context.getNode());
85 context.proceed();
86 }
87 }
88 }