01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.geoserver.wfs;
06:
07: import org.aopalliance.intercept.MethodInterceptor;
08: import org.aopalliance.intercept.MethodInvocation;
09: import org.eclipse.emf.ecore.EObject;
10: import org.eclipse.emf.ecore.EStructuralFeature;
11: import java.util.Iterator;
12: import java.util.List;
13: import java.util.logging.Logger;
14:
15: public class WFSLogger implements MethodInterceptor {
16: /**
17: * Logging instance
18: */
19: Logger logger = org.geotools.util.logging.Logging
20: .getLogger("org.geoserver.wfs");
21:
22: public Object invoke(MethodInvocation invocation) throws Throwable {
23: StringBuffer log = new StringBuffer();
24: log.append("\n" + "Request: "
25: + invocation.getMethod().getName());
26:
27: if (invocation.getArguments().length > 0) {
28: EObject requestBean = null;
29:
30: for (int i = 0; i < invocation.getArguments().length; i++) {
31: Object argument = (Object) invocation.getArguments()[i];
32:
33: if (argument instanceof EObject) {
34: requestBean = (EObject) argument;
35:
36: break;
37: }
38: }
39:
40: if (requestBean != null) {
41: log(requestBean, 1, log);
42: }
43: }
44:
45: Object result = invocation.proceed();
46: log.append("\n\nResult:");
47:
48: // if (result instanceof EObject) {
49: // log((EObject) result, 1, log);
50: // } else {
51: // log.append("\t" + result);
52: // }
53: logger.info(log.toString());
54:
55: return result;
56: }
57:
58: void log(EObject object, int level, StringBuffer log) {
59: List properties = object.eClass().getEAllStructuralFeatures();
60:
61: for (Iterator p = properties.iterator(); p.hasNext();) {
62: EStructuralFeature property = (EStructuralFeature) p.next();
63: Object value = object.eGet(property);
64:
65: log.append("\n");
66:
67: for (int i = 0; i < level; i++)
68: log.append("\t");
69:
70: log.append(property.getName());
71:
72: if (value instanceof EObject && (level < 2)) {
73: log.append(":");
74: log((EObject) value, level + 1, log);
75: } else {
76: log.append(" = " + value);
77: }
78: }
79: }
80: }
|