Source Code Cross Referenced for TriggerProvider.java in  » GIS » deegree » org » deegree » framework » trigger » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » deegree » org.deegree.framework.trigger 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/framework/trigger/TriggerProvider.java $
002:        /*----------------    FILE HEADER  ------------------------------------------
003:
004:         This file is part of deegree.
005:         Copyright (C) 2001-2008 by:
006:         EXSE, Department of Geography, University of Bonn
007:         http://www.giub.uni-bonn.de/deegree/
008:         lat/lon GmbH
009:         http://www.lat-lon.de
010:
011:         This library is free software; you can redistribute it and/or
012:         modify it under the terms of the GNU Lesser General Public
013:         License as published by the Free Software Foundation; either
014:         version 2.1 of the License, or (at your option) any later version.
015:
016:         This library is distributed in the hope that it will be useful,
017:         but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019:         Lesser General Public License for more details.
020:
021:         You should have received a copy of the GNU Lesser General Public
022:         License along with this library; if not, write to the Free Software
023:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
024:
025:         Contact:
026:
027:         Andreas Poth
028:         lat/lon GmbH
029:         Aennchenstr. 19
030:         53115 Bonn
031:         Germany
032:         E-Mail: poth@lat-lon.de
033:
034:         Prof. Dr. Klaus Greve
035:         Department of Geography
036:         University of Bonn
037:         Meckenheimer Allee 166
038:         53115 Bonn
039:         Germany
040:         E-Mail: greve@giub.uni-bonn.de
041:
042:         ---------------------------------------------------------------------------*/
043:        package org.deegree.framework.trigger;
044:
045:        import java.lang.reflect.Constructor;
046:        import java.net.URL;
047:        import java.util.ArrayList;
048:        import java.util.HashMap;
049:        import java.util.List;
050:        import java.util.Map;
051:
052:        import org.deegree.framework.log.ILogger;
053:        import org.deegree.framework.log.LoggerFactory;
054:        import org.deegree.framework.trigger.TriggerCapabilities.TRIGGER_TYPE;
055:        import org.deegree.framework.util.BootLogger;
056:        import org.deegree.i18n.Messages;
057:
058:        /**
059:         * 
060:         * 
061:         * 
062:         * @version $Revision: 9339 $
063:         * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
064:         * @author last edited by: $Author: apoth $
065:         * 
066:         * @version 1.0. $Revision: 9339 $, $Date: 2007-12-27 04:31:52 -0800 (Thu, 27 Dec 2007) $
067:         * 
068:         * @since 2.0
069:         */
070:        public class TriggerProvider {
071:
072:            private static Map<String, TriggerProvider> providerMap = new HashMap<String, TriggerProvider>();
073:
074:            private static TriggerCapabilities triggerCapabilities;
075:
076:            private static final ILogger LOG = LoggerFactory
077:                    .getLogger(TriggerProvider.class);
078:
079:            static {
080:                try {
081:                    URL url = TriggerProvider.class
082:                            .getResource("triggerConfiguration.xml");
083:                    TriggerConfigurationDocument doc = new TriggerConfigurationDocument();
084:                    doc.load(url);
085:                    triggerCapabilities = doc.parseTriggerCapabilities();
086:                    // try reading trigger definitions from root that may overrides
087:                    // default trigger
088:                    url = TriggerProvider.class
089:                            .getResource("/triggerConfiguration.xml");
090:                    try {
091:
092:                        if (url != null) {
093:                            LOG
094:                                    .logDebug("Trying to create trigger from local configuration: "
095:                                            + url);
096:                            doc = new TriggerConfigurationDocument();
097:                            doc.load(url);
098:                            TriggerCapabilities temp = doc
099:                                    .parseTriggerCapabilities();
100:                            triggerCapabilities.merge(temp);
101:                        } else {
102:                            LOG.logDebug("No local configuration found.");
103:                        }
104:
105:                    } catch (Exception e) {
106:                        e.printStackTrace();
107:                        BootLogger
108:                                .log("!!! BOOTLOG: No valid trigger configuration available from root.");
109:                    }
110:                } catch (Exception e) {
111:                    e.printStackTrace();
112:                }
113:            }
114:
115:            private String className = null;
116:
117:            private TriggerProvider(String className) {
118:                this .className = className;
119:            }
120:
121:            /**
122:             * 
123:             * @param clss
124:             */
125:            public static TriggerProvider create(Class clss) {
126:                String s = clss.getName();
127:                if (providerMap.get(s) == null) {
128:                    providerMap.put(s, new TriggerProvider(s));
129:                }
130:                return providerMap.get(s);
131:            }
132:
133:            /**
134:             * @return all pre triggers assigend to the calling method
135:             */
136:            public List<Trigger> getPreTrigger() throws TriggerException {
137:
138:                List<Trigger> trigger = new ArrayList<Trigger>();
139:
140:                StackTraceElement[] st = Thread.currentThread().getStackTrace();
141:
142:                String mn = null;
143:                for (int i = 0; i < st.length; i++) {
144:                    if (st[i].getClassName().equals(className)) {
145:                        mn = st[i].getMethodName();
146:                        break;
147:                    }
148:                }
149:                if (mn != null) {
150:                    TriggerCapability tc = triggerCapabilities
151:                            .getTriggerCapability(className, mn,
152:                                    TRIGGER_TYPE.PRE);
153:                    if (tc != null) {
154:                        appendTrigger(trigger, tc);
155:
156:                        List<TriggerCapability> tCaps = tc.getTrigger();
157:                        for (int i = 0; i < tCaps.size(); i++) {
158:                            appendTrigger(trigger, tCaps.get(i));
159:                        }
160:                    }
161:                }
162:
163:                return trigger;
164:            }
165:
166:            /**
167:             * returns all post triggers assigend to the calling method
168:             * 
169:             * @return all post triggers assigend to the calling method
170:             */
171:            public List<Trigger> getPostTrigger() throws TriggerException {
172:                List<Trigger> trigger = new ArrayList<Trigger>();
173:
174:                StackTraceElement[] st = Thread.currentThread().getStackTrace();
175:                String mn = null;
176:                for (int i = 0; i < st.length; i++) {
177:                    if (st[i].getClassName().equals(className)) {
178:                        mn = st[i].getMethodName();
179:                        break;
180:                    }
181:                }
182:
183:                if (mn != null) {
184:                    TriggerCapability tc = triggerCapabilities
185:                            .getTriggerCapability(className, mn,
186:                                    TRIGGER_TYPE.POST);
187:
188:                    if (tc != null) {
189:                        appendTrigger(trigger, tc);
190:
191:                        List<TriggerCapability> tCaps = tc.getTrigger();
192:                        for (int i = 0; i < tCaps.size(); i++) {
193:                            appendTrigger(trigger, tCaps.get(i));
194:                        }
195:                    }
196:                }
197:                return trigger;
198:            }
199:
200:            /**
201:             * creates a Trigger instance from the passed TriggerCapability and add it to the passed list. If the
202:             * TriggerCapability contains futher TriggerCapability entries they will also be added within a recursion
203:             * 
204:             * @param trigger
205:             * @param tc
206:             * @return extended list
207:             * @throws TriggerException
208:             */
209:            private List<Trigger> appendTrigger(List<Trigger> trigger,
210:                    TriggerCapability tc) throws TriggerException {
211:                Class clss = tc.getPerformingClass();
212:                List<String> paramNames = tc.getInitParameterNames();
213:                Class[] initClasses = new Class[paramNames.size()];
214:                Object[] paramVals = new Object[paramNames.size()];
215:                for (int i = 0; i < initClasses.length; i++) {
216:                    paramVals[i] = tc.getInitParameterValue(paramNames.get(i));
217:                    initClasses[i] = paramVals[i].getClass();
218:                }
219:                try {
220:                    Constructor cstrtr = clss.getConstructor(initClasses);
221:                    LOG.logDebug("Trying to instantiate new class");
222:                    trigger.add((Trigger) cstrtr.newInstance(paramVals));
223:                    LOG
224:                            .logDebug("Succesfully instantiated configured trigger class.");
225:                } catch (Exception e) {
226:                    e.printStackTrace();
227:                    throw new TriggerException(Messages.getMessage(
228:                            "FRAMEWORK_ERROR_INITIALIZING_TRIGGER", clss));
229:                }
230:                return trigger;
231:            }
232:
233:            /**
234:             * performs pre triggers assigend to the calling method
235:             * 
236:             * @param caller
237:             * @param obj
238:             * @return changed object passed to the trigger(s)
239:             * @throws TriggerException
240:             */
241:            public Object[] doPreTrigger(Object caller, Object... obj)
242:                    throws TriggerException {
243:                List<Trigger> list = getPreTrigger();
244:                if (LOG.getLevel() == ILogger.LOG_DEBUG) {
245:                    LOG.logDebug("list of appliable pretriggers: " + list);
246:                }
247:                for (int i = 0; i < list.size(); i++) {
248:                    obj = list.get(i).doTrigger(caller, obj);
249:                }
250:                return obj;
251:            }
252:
253:            /**
254:             * performs post triggers assigend to the calling method
255:             * 
256:             * @param caller
257:             * @param obj
258:             * @return changed object passed to the trigger(s)
259:             */
260:            public Object[] doPostTrigger(Object caller, Object... obj) {
261:                List<Trigger> list = getPostTrigger();
262:                if (LOG.getLevel() == ILogger.LOG_DEBUG) {
263:                    LOG.logDebug("list of appliable posttriggers: " + list);
264:                }
265:                for (int i = 0; i < list.size(); i++) {
266:                    obj = list.get(i).doTrigger(caller, obj);
267:                }
268:                return obj;
269:            }
270:
271:            /**
272:             * returns the root capabilities
273:             * 
274:             * @return the root capabilities
275:             */
276:            public TriggerCapabilities getCapabilities() {
277:                return triggerCapabilities;
278:            }
279:
280:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.