001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/framework/trigger/TriggerCapabilities.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.util.ArrayList;
046 import java.util.Iterator;
047 import java.util.List;
048 import java.util.Map;
049
050 import org.deegree.framework.log.ILogger;
051 import org.deegree.framework.log.LoggerFactory;
052
053 /**
054 *
055 *
056 *
057 * @version $Revision: 9339 $
058 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
059 * @author last edited by: $Author: apoth $
060 *
061 * @version 1.0. $Revision: 9339 $, $Date: 2007-12-27 13:31:52 +0100 (Do, 27 Dez 2007) $
062 *
063 * @since 2.0
064 */
065 public class TriggerCapabilities {
066
067 private static final ILogger LOG = LoggerFactory.getLogger( TriggerCapabilities.class );
068
069 private Map<String, TargetClass> targetClasses;
070
071 public static enum TRIGGER_TYPE {
072 /** identifies pre-trigger */
073 PRE,
074 /** identifies post-trigger */
075 POST,
076 /** identifies all trigger */
077 ALL
078 }
079
080 /**
081 *
082 */
083 public TriggerCapabilities( Map<String, TargetClass> targetClasses ) {
084 this.targetClasses = targetClasses;
085 }
086
087 /**
088 * returns a List of capabilities of all available
089 *
090 * @see Trigger
091 * @return a List of capabilities of all available
092 * @see Trigger
093 */
094 public List<TargetClass> getTargetClasses() {
095 List<TargetClass> list = new ArrayList<TargetClass>( targetClasses.size() );
096 Iterator iter = targetClasses.values().iterator();
097 while ( iter.hasNext() ) {
098 list.add( (TargetClass) iter.next() );
099 }
100 return list;
101 }
102
103 /**
104 * returns all the capabilties of all
105 *
106 * @see Trigger assigned to class and method. The thrid parameter determines if just
107 * pre-trigger, post-trigger or all triggers shall be returned.
108 * @param clss
109 * @param method
110 * @param type
111 * @return all the capabilties of all
112 * @see Trigger assigned to class and method.
113 */
114 public TriggerCapability getTriggerCapability( String clss, String method, TRIGGER_TYPE type ) {
115
116 LOG.logDebug( "get trigger capability for: ", clss + '.' + method );
117
118 TriggerCapability tc = null;
119 TargetClass tgc = targetClasses.get( clss );
120 if ( tgc != null ) {
121 TargetMethod tm = tgc.getMethod( method );
122 if ( tm != null ) {
123 if ( type.equals( TRIGGER_TYPE.PRE ) ) {
124 tc = tm.getPreTrigger();
125 } else {
126 tc = tm.getPostTrigger();
127 }
128 }
129 }
130 return tc;
131 }
132
133 /**
134 * returns the mapping of java class names to
135 *
136 * @see TargetClass instances
137 * @return the mapping of java class names to
138 * @see TargetClass instances
139 */
140 Map<String, TargetClass> getClassMappings() {
141 return targetClasses;
142 }
143
144 /**
145 * adds all mappings from the passed TriggerCapabilities to the current. The passed mappings
146 * will override the current mapping if necessary
147 *
148 * @param other
149 */
150 void merge( TriggerCapabilities other ) {
151 Iterator iter = other.getClassMappings().keySet().iterator();
152 while ( iter.hasNext() ) {
153 String key = (String) iter.next();
154 targetClasses.put( key, other.getClassMappings().get( key ) );
155 }
156 }
157
158 }