Source Code Cross Referenced for ClassChecks.java in  » Development » OVal » net » sf » oval » internal » 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 » Development » OVal » net.sf.oval.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Portions created by Sebastian Thomschke are copyright (c) 2005-2007 Sebastian
003:         * Thomschke.
004:         * 
005:         * All Rights Reserved. This program and the accompanying materials
006:         * are made available under the terms of the Eclipse Public License v1.0
007:         * which accompanies this distribution, and is available at
008:         * http://www.eclipse.org/legal/epl-v10.html
009:         * 
010:         * Contributors:
011:         *     Sebastian Thomschke - initial implementation.
012:         *******************************************************************************/package net.sf.oval.internal;
013:
014:        import java.lang.reflect.AccessibleObject;
015:        import java.lang.reflect.Constructor;
016:        import java.lang.reflect.Field;
017:        import java.lang.reflect.Method;
018:        import java.util.Collection;
019:        import java.util.Map;
020:        import java.util.Set;
021:
022:        import net.sf.oval.Check;
023:        import net.sf.oval.exception.InvalidConfigurationException;
024:        import net.sf.oval.guard.IsGuarded;
025:        import net.sf.oval.guard.PostCheck;
026:        import net.sf.oval.guard.PreCheck;
027:        import net.sf.oval.internal.util.ArrayUtils;
028:        import net.sf.oval.internal.util.ReflectionUtils;
029:
030:        /**
031:         * This class holds the instantiated checks for a single class.
032:         * 
033:         * <b>Note:</b> For performance reasons the collections are made public (intended for read-access only).
034:         * Modifications to the collections should be done through the appropriate methods addXXX, removeXXX, clearXXX methods.
035:         * 
036:         * @author Sebastian Thomschke
037:         */
038:        public class ClassChecks {
039:            private static final Log LOG = Log.getLog(ClassChecks.class);
040:
041:            /**
042:             * compound constraints / object level invariants
043:             */
044:            public final Set<Check> checksForObject = CollectionFactoryHolder
045:                    .getFactory().createSet(2);
046:
047:            /**
048:             * checks on constructors' parameter values
049:             */
050:            public final Map<Constructor, Map<Integer, Set<Check>>> checksForConstructorParameters = CollectionFactoryHolder
051:                    .getFactory().createMap(2);
052:
053:            /**
054:             * checks on fields' value
055:             */
056:            public final Map<Field, Set<Check>> checksForFields = CollectionFactoryHolder
057:                    .getFactory().createMap();
058:
059:            /**
060:             * checks on methods' return value
061:             */
062:            public final Map<Method, Set<Check>> checksForMethodReturnValues = CollectionFactoryHolder
063:                    .getFactory().createMap();
064:
065:            public final Set<Method> methodsWithCheckInvariantsPre = CollectionFactoryHolder
066:                    .getFactory().createSet();
067:
068:            public final Set<AccessibleObject> methodsWithCheckInvariantsPost = CollectionFactoryHolder
069:                    .getFactory().createSet();
070:
071:            /**
072:             * checks on methods' parameter values
073:             */
074:            public final Map<Method, Map<Integer, Set<Check>>> checksForMethodParameters = CollectionFactoryHolder
075:                    .getFactory().createMap();
076:
077:            public final Map<Method, Set<PostCheck>> checksForMethodsPostExcecution = CollectionFactoryHolder
078:                    .getFactory().createMap();
079:
080:            public final Map<Method, Set<PreCheck>> checksForMethodsPreExecution = CollectionFactoryHolder
081:                    .getFactory().createMap();
082:
083:            public final Class clazz;
084:
085:            /**
086:             * all non-static fields that have value constraints.
087:             * Validator loops over this set during validation.
088:             */
089:            public final Set<Field> constrainedStaticFields = CollectionFactoryHolder
090:                    .getFactory().createSet();
091:
092:            /**
093:             * all static non-void, non-parameterized methods marked as invariant that have return value constraints.
094:             * Validator loops over this set during validation.
095:             */
096:            public final Set<Method> constrainedStaticMethods = CollectionFactoryHolder
097:                    .getFactory().createSet();
098:
099:            /**
100:             * all non-static fields that have value constraints.
101:             * Validator loops over this set during validation.
102:             */
103:            public final Set<Field> constrainedFields = CollectionFactoryHolder
104:                    .getFactory().createSet();
105:
106:            /**
107:             * all non-static non-void, non-parameterized methods marked as invariant that have return value constraints.
108:             * Validator loops over this set during validation.
109:             */
110:            public final Set<Method> constrainedMethods = CollectionFactoryHolder
111:                    .getFactory().createSet();
112:
113:            public final boolean isGuarded;
114:
115:            public boolean isCheckInvariants;
116:
117:            /**
118:             * package constructor used by the Validator class
119:             * 
120:             * @param clazz
121:             */
122:            @SuppressWarnings("unchecked")
123:            public ClassChecks(final Class clazz) {
124:                LOG.debug(
125:                        "Initializing constraints configuration for class {}",
126:                        clazz);
127:
128:                this .clazz = clazz;
129:                isGuarded = IsGuarded.class.isAssignableFrom(clazz);
130:            }
131:
132:            /**
133:             * adds constraint checks to a constructor parameter 
134:             *  
135:             * @param constructor
136:             * @param parameterIndex
137:             * @param checks
138:             * @throws InvalidConfigurationException if the declaring class is not guarded by GuardAspect 
139:             */
140:            public void addConstructorParameterChecks(
141:                    final Constructor constructor, final int parameterIndex,
142:                    final Check... checks) throws InvalidConfigurationException {
143:                addConstructorParameterChecks(constructor, parameterIndex,
144:                        (Object) checks);
145:            }
146:
147:            /**
148:             * adds constraint checks to a constructor parameter 
149:             *  
150:             * @param constructor
151:             * @param parameterIndex
152:             * @param checks
153:             * @throws InvalidConfigurationException if the declaring class is not guarded by GuardAspect 
154:             */
155:            public void addConstructorParameterChecks(
156:                    final Constructor constructor, final int parameterIndex,
157:                    final Collection<Check> checks)
158:                    throws InvalidConfigurationException {
159:                addConstructorParameterChecks(constructor, parameterIndex,
160:                        (Object) checks);
161:            }
162:
163:            @SuppressWarnings("unchecked")
164:            private void addConstructorParameterChecks(
165:                    final Constructor constructor, final int parameterIndex,
166:                    final Object checks) throws InvalidConfigurationException {
167:                if (!isGuarded)
168:                    throw new InvalidConfigurationException(
169:                            "Cannot apply constructor parameter constraints to constructor "
170:                                    + constructor
171:                                    + ". Constraints guarding is not activated for this class.");
172:
173:                final int paramCount = constructor.getParameterTypes().length;
174:
175:                if (parameterIndex < 0 || parameterIndex >= paramCount)
176:                    throw new InvalidConfigurationException("ParameterIndex "
177:                            + parameterIndex + " is out of range (0-"
178:                            + (paramCount - 1) + ")");
179:
180:                synchronized (checksForConstructorParameters) {
181:                    // retrieve the currently registered checks for all parameters of the specified constructor
182:                    Map<Integer, Set<Check>> checksOfConstructorByParameter = checksForConstructorParameters
183:                            .get(constructor);
184:                    if (checksOfConstructorByParameter == null) {
185:                        checksOfConstructorByParameter = CollectionFactoryHolder
186:                                .getFactory().createMap(paramCount);
187:                        checksForConstructorParameters.put(constructor,
188:                                checksOfConstructorByParameter);
189:                    }
190:
191:                    // retrieve the checks for the specified parameter
192:                    Set<Check> checksOfConstructorParameter = checksOfConstructorByParameter
193:                            .get(parameterIndex);
194:                    if (checksOfConstructorParameter == null) {
195:                        checksOfConstructorParameter = CollectionFactoryHolder
196:                                .getFactory().createSet(2);
197:                        checksOfConstructorByParameter.put(parameterIndex,
198:                                checksOfConstructorParameter);
199:                    }
200:
201:                    if (checks instanceof  Collection) {
202:                        checksOfConstructorParameter
203:                                .addAll((Collection<Check>) checks);
204:                    } else {
205:                        ArrayUtils.addAll(checksOfConstructorParameter,
206:                                (Check[]) checks);
207:                    }
208:                }
209:            }
210:
211:            /**
212:             * adds check constraints to a field 
213:             *  
214:             * @param field
215:             * @param checks 
216:             */
217:            public void addFieldChecks(final Field field, final Check... checks)
218:                    throws InvalidConfigurationException {
219:                addFieldChecks(field, (Object) checks);
220:            }
221:
222:            /**
223:             * adds check constraints to a field 
224:             *  
225:             * @param field
226:             * @param checks 
227:             */
228:            public void addFieldChecks(final Field field,
229:                    final Collection<Check> checks)
230:                    throws InvalidConfigurationException {
231:                addFieldChecks(field, (Object) checks);
232:            }
233:
234:            @SuppressWarnings("unchecked")
235:            private void addFieldChecks(final Field field, final Object checks) {
236:                synchronized (checksForFields) {
237:                    Set<Check> checksOfField = checksForFields.get(field);
238:                    if (checksOfField == null) {
239:                        checksOfField = CollectionFactoryHolder.getFactory()
240:                                .createSet(2);
241:                        checksForFields.put(field, checksOfField);
242:                        if (ReflectionUtils.isStatic(field))
243:                            constrainedStaticFields.add(field);
244:                        else
245:                            constrainedFields.add(field);
246:                    }
247:
248:                    if (checks instanceof  Collection) {
249:                        checksOfField.addAll((Collection<Check>) checks);
250:                    } else {
251:                        ArrayUtils.addAll(checksOfField, (Check[]) checks);
252:                    }
253:                }
254:            }
255:
256:            /**
257:             * adds constraint checks to a method parameter 
258:             *  
259:             * @param method
260:             * @param parameterIndex
261:             * @param checks
262:             * @throws InvalidConfigurationException if the declaring class is not guarded by GuardAspect
263:             */
264:            public void addMethodParameterChecks(final Method method,
265:                    final int parameterIndex, final Check... checks)
266:                    throws InvalidConfigurationException {
267:                addMethodParameterChecks(method, parameterIndex,
268:                        (Object) checks);
269:            }
270:
271:            /**
272:             * adds constraint checks to a method parameter 
273:             *  
274:             * @param method
275:             * @param parameterIndex
276:             * @param checks
277:             * @throws InvalidConfigurationException if the declaring class is not guarded by GuardAspect
278:             */
279:            public void addMethodParameterChecks(final Method method,
280:                    final int parameterIndex, final Collection<Check> checks)
281:                    throws InvalidConfigurationException {
282:                addMethodParameterChecks(method, parameterIndex,
283:                        (Object) checks);
284:            }
285:
286:            @SuppressWarnings("unchecked")
287:            private void addMethodParameterChecks(final Method method,
288:                    final int parameterIndex, final Object checks)
289:                    throws InvalidConfigurationException {
290:                if (!isGuarded)
291:                    throw new InvalidConfigurationException(
292:                            "Cannot apply method parameter constraints to class "
293:                                    + clazz.getName()
294:                                    + ". Constraints guarding is not activated for this class.");
295:
296:                final int paramCount = method.getParameterTypes().length;
297:
298:                if (parameterIndex < 0 || parameterIndex >= paramCount)
299:                    throw new InvalidConfigurationException("ParameterIndex "
300:                            + parameterIndex + " is out of range (0-"
301:                            + (paramCount - 1) + ")");
302:
303:                synchronized (checksForMethodParameters) {
304:                    // retrieve the currently registered checks for all parameters of the specified method
305:                    Map<Integer, Set<Check>> checksOfMethodByParameter = checksForMethodParameters
306:                            .get(method);
307:                    if (checksOfMethodByParameter == null) {
308:                        checksOfMethodByParameter = CollectionFactoryHolder
309:                                .getFactory().createMap(paramCount);
310:                        checksForMethodParameters.put(method,
311:                                checksOfMethodByParameter);
312:                    }
313:
314:                    // retrieve the checks for the specified parameter
315:                    Set<Check> checksOfMethodParameter = checksOfMethodByParameter
316:                            .get(parameterIndex);
317:                    if (checksOfMethodParameter == null) {
318:                        checksOfMethodParameter = CollectionFactoryHolder
319:                                .getFactory().createSet(2);
320:                        checksOfMethodByParameter.put(parameterIndex,
321:                                checksOfMethodParameter);
322:                    }
323:
324:                    if (checks instanceof  Collection) {
325:                        checksOfMethodParameter
326:                                .addAll((Collection<Check>) checks);
327:                    } else {
328:                        ArrayUtils.addAll(checksOfMethodParameter,
329:                                (Check[]) checks);
330:                    }
331:                }
332:            }
333:
334:            /**
335:             * adds constraint checks to a method's return value
336:             * @param method
337:             * @param checks
338:             * @throws InvalidConfigurationException if the declaring class is not guarded by GuardAspect
339:             */
340:            public void addMethodPostChecks(final Method method,
341:                    final Collection<PostCheck> checks)
342:                    throws InvalidConfigurationException {
343:                addMethodPostChecks(method, (Object) checks);
344:            }
345:
346:            @SuppressWarnings("unchecked")
347:            private void addMethodPostChecks(final Method method,
348:                    final Object checks) throws InvalidConfigurationException {
349:                if (!isGuarded)
350:                    throw new InvalidConfigurationException(
351:                            "Cannot apply pre condition for method "
352:                                    + method
353:                                    + ". Constraints guarding is not activated for this class.");
354:
355:                synchronized (checksForMethodsPostExcecution) {
356:                    Set<PostCheck> postChecks = checksForMethodsPostExcecution
357:                            .get(method);
358:                    if (postChecks == null) {
359:                        postChecks = CollectionFactoryHolder.getFactory()
360:                                .createSet(2);
361:                        checksForMethodsPostExcecution.put(method, postChecks);
362:                    }
363:
364:                    if (checks instanceof  Collection) {
365:                        postChecks.addAll((Collection<PostCheck>) checks);
366:                    } else {
367:                        ArrayUtils.addAll(postChecks, (PostCheck[]) checks);
368:                    }
369:                }
370:            }
371:
372:            /**
373:             * adds constraint checks to a method's return value
374:             * @param method
375:             * @param checks
376:             * @throws InvalidConfigurationException if the declaring class is not guarded by GuardAspect
377:             */
378:            public void addMethodPostChecks(final Method method,
379:                    final PostCheck... checks)
380:                    throws InvalidConfigurationException {
381:                addMethodPostChecks(method, (Object) checks);
382:            }
383:
384:            /**
385:             * @param method
386:             * @param checks
387:             * @throws InvalidConfigurationException if the declaring class is not guarded by GuardAspect
388:             */
389:            public void addMethodPreChecks(final Method method,
390:                    final Collection<PreCheck> checks)
391:                    throws InvalidConfigurationException {
392:                addMethodPreChecks(method, (Object) checks);
393:            }
394:
395:            @SuppressWarnings("unchecked")
396:            private void addMethodPreChecks(final Method method,
397:                    final Object checks) throws InvalidConfigurationException {
398:                if (!isGuarded)
399:                    throw new InvalidConfigurationException(
400:                            "Cannot apply pre condition for method "
401:                                    + method
402:                                    + ". Constraints guarding is not activated for this class.");
403:
404:                synchronized (checksForMethodsPreExecution) {
405:                    Set<PreCheck> preChecks = checksForMethodsPreExecution
406:                            .get(method);
407:                    if (preChecks == null) {
408:                        preChecks = CollectionFactoryHolder.getFactory()
409:                                .createSet(2);
410:                        checksForMethodsPreExecution.put(method, preChecks);
411:                    }
412:
413:                    if (checks instanceof  Collection) {
414:                        preChecks.addAll((Collection<PreCheck>) checks);
415:                    } else {
416:                        ArrayUtils.addAll(preChecks, (PreCheck[]) checks);
417:                    }
418:                }
419:            }
420:
421:            /**
422:             * @param method
423:             * @param checks
424:             * @throws InvalidConfigurationException if the declaring class is not guarded by GuardAspect
425:             */
426:            public void addMethodPreChecks(final Method method,
427:                    final PreCheck... checks)
428:                    throws InvalidConfigurationException {
429:                addMethodPreChecks(method, (Object) checks);
430:            }
431:
432:            /**
433:             * adds constraint checks to a method's return value
434:             * @param method
435:             * @param isInvariant determines if the return value should be checked when the object is validated, can be null
436:             * @param checks
437:             */
438:            public void addMethodReturnValueChecks(final Method method,
439:                    final Boolean isInvariant, final Check... checks)
440:                    throws InvalidConfigurationException {
441:                addMethodReturnValueChecks(method, isInvariant, (Object) checks);
442:            }
443:
444:            /**
445:             * adds constraint checks to a method's return value
446:             * @param method
447:             * @param isInvariant determines if the return value should be checked when the object is validated, can be null
448:             * @param checks
449:             */
450:            public void addMethodReturnValueChecks(final Method method,
451:                    final Boolean isInvariant, final Collection<Check> checks)
452:                    throws InvalidConfigurationException {
453:                addMethodReturnValueChecks(method, isInvariant, (Object) checks);
454:            }
455:
456:            @SuppressWarnings("unchecked")
457:            private void addMethodReturnValueChecks(final Method method,
458:                    final Boolean isInvariant, final Object checks)
459:                    throws InvalidConfigurationException {
460:                // ensure the method has a return type
461:                if (method.getReturnType() == Void.TYPE)
462:                    throw new InvalidConfigurationException(
463:                            "Adding return value constraints for method "
464:                                    + method
465:                                    + " is not possible. The method is declared as void and does not return any values.");
466:
467:                if (ReflectionUtils.isVoidMethod(method))
468:                    throw new InvalidConfigurationException(
469:                            "Cannot apply method return value constraints for void method "
470:                                    + method);
471:
472:                final boolean hasParameters = method.getParameterTypes().length > 0;
473:
474:                if (!isGuarded && hasParameters)
475:                    throw new InvalidConfigurationException(
476:                            "Cannot apply method return value constraints for parameterized method "
477:                                    + method
478:                                    + ". Constraints guarding is not activated for this class.");
479:
480:                final boolean isInvariant2 = isInvariant == null ? constrainedMethods
481:                        .contains(method)
482:                        : isInvariant;
483:
484:                if (!isGuarded && !isInvariant2)
485:                    throw new InvalidConfigurationException(
486:                            "Cannot apply method return value constraints for method "
487:                                    + method
488:                                    + ". The method needs to be marked as being invariant (@IsInvariant) since constraints guarding is not activated for this class.");
489:
490:                synchronized (checksForMethodReturnValues) {
491:                    if (!hasParameters && isInvariant2) {
492:                        if (ReflectionUtils.isStatic(method))
493:                            constrainedStaticMethods.add(method);
494:                        else
495:                            constrainedMethods.add(method);
496:                    } else {
497:                        if (ReflectionUtils.isStatic(method))
498:                            constrainedStaticMethods.remove(method);
499:                        else
500:                            constrainedMethods.remove(method);
501:                    }
502:
503:                    Set<Check> methodChecks = checksForMethodReturnValues
504:                            .get(method);
505:                    if (methodChecks == null) {
506:                        methodChecks = CollectionFactoryHolder.getFactory()
507:                                .createSet(2);
508:                        checksForMethodReturnValues.put(method, methodChecks);
509:                    }
510:
511:                    if (checks instanceof  Collection) {
512:                        methodChecks.addAll((Collection<Check>) checks);
513:                    } else {
514:                        ArrayUtils.addAll(methodChecks, (Check[]) checks);
515:                    }
516:                }
517:            }
518:
519:            /**
520:             * adds check constraints on object level (invariants) 
521:             *  
522:             * @param checks 
523:             */
524:            public void addObjectChecks(final Check... checks) {
525:                synchronized (checksForObject) {
526:                    ArrayUtils.addAll(checksForObject, checks);
527:                }
528:            }
529:
530:            /**
531:             * adds check constraints on object level (invariants) 
532:             *  
533:             * @param checks 
534:             */
535:            public void addObjectChecks(final Collection<Check> checks) {
536:                synchronized (checksForObject) {
537:                    checksForObject.addAll(checks);
538:                }
539:            }
540:
541:            public synchronized void clear() {
542:                LOG.debug("Clearing all checks for class {}", clazz);
543:
544:                checksForObject.clear();
545:                checksForMethodsPostExcecution.clear();
546:                checksForMethodsPreExecution.clear();
547:                checksForConstructorParameters.clear();
548:                checksForFields.clear();
549:                checksForMethodReturnValues.clear();
550:                checksForMethodParameters.clear();
551:                constrainedFields.clear();
552:                constrainedStaticFields.clear();
553:                constrainedMethods.clear();
554:                constrainedStaticMethods.clear();
555:            }
556:
557:            public void clearConstructorChecks(final Constructor constructor) {
558:                clearConstructorParameterChecks(constructor);
559:            }
560:
561:            public void clearConstructorParameterChecks(
562:                    final Constructor constructor) {
563:                synchronized (checksForConstructorParameters) {
564:                    checksForConstructorParameters.remove(constructor);
565:                }
566:            }
567:
568:            public void clearConstructorParameterChecks(
569:                    final Constructor constructor, final int parameterIndex) {
570:                synchronized (checksForConstructorParameters) {
571:                    // retrieve the currently registered checks for all parameters of the specified method
572:                    final Map<Integer, Set<Check>> checksOfConstructorByParameter = checksForConstructorParameters
573:                            .get(constructor);
574:                    if (checksOfConstructorByParameter == null)
575:                        return;
576:
577:                    // retrieve the checks for the specified parameter
578:                    final Collection<Check> checksOfMethodParameter = checksOfConstructorByParameter
579:                            .get(parameterIndex);
580:                    if (checksOfMethodParameter == null)
581:                        return;
582:
583:                    checksOfConstructorByParameter.remove(parameterIndex);
584:                }
585:            }
586:
587:            public void clearFieldChecks(final Field field) {
588:                synchronized (checksForFields) {
589:                    checksForFields.remove(field);
590:                    constrainedFields.remove(field);
591:                    constrainedStaticFields.remove(field);
592:                }
593:            }
594:
595:            public synchronized void clearMethodChecks(final Method method) {
596:                clearMethodParameterChecks(method);
597:                clearMethodReturnValueChecks(method);
598:                clearMethodPreChecks(method);
599:                clearMethodPostChecks(method);
600:            }
601:
602:            public void clearMethodParameterChecks(final Method method) {
603:                synchronized (checksForMethodParameters) {
604:                    checksForMethodParameters.remove(method);
605:                }
606:            }
607:
608:            public void clearMethodParameterChecks(final Method method,
609:                    final int parameterIndex) {
610:                synchronized (checksForMethodParameters) {
611:                    // retrieve the currently registered checks for all parameters of the specified method
612:                    final Map<Integer, Set<Check>> checksOfMethodByParameter = checksForMethodParameters
613:                            .get(method);
614:                    if (checksOfMethodByParameter == null)
615:                        return;
616:
617:                    // retrieve the checks for the specified parameter
618:                    final Collection<Check> checksOfMethodParameter = checksOfMethodByParameter
619:                            .get(parameterIndex);
620:                    if (checksOfMethodParameter == null)
621:                        return;
622:
623:                    checksOfMethodByParameter.remove(parameterIndex);
624:                }
625:            }
626:
627:            public void clearMethodPostChecks(final Method method) {
628:                synchronized (checksForMethodsPostExcecution) {
629:                    checksForMethodsPostExcecution.remove(method);
630:                }
631:            }
632:
633:            public void clearMethodPreChecks(final Method method) {
634:                synchronized (checksForMethodsPreExecution) {
635:                    checksForMethodsPreExecution.remove(method);
636:                }
637:            }
638:
639:            public void clearMethodReturnValueChecks(final Method method) {
640:                synchronized (checksForMethodReturnValues) {
641:                    checksForMethodReturnValues.remove(method);
642:                    constrainedMethods.remove(method);
643:                    constrainedStaticMethods.remove(method);
644:                }
645:            }
646:
647:            public void clearObjectChecks() {
648:                synchronized (checksForObject) {
649:                    checksForObject.clear();
650:                }
651:            }
652:
653:            public void removeConstructorParameterChecks(
654:                    final Constructor constructor, final int parameterIndex,
655:                    final Check... checks) {
656:                synchronized (checksForConstructorParameters) {
657:                    // retrieve the currently registered checks for all parameters of the specified method
658:                    final Map<Integer, Set<Check>> checksOfConstructorByParameter = checksForConstructorParameters
659:                            .get(constructor);
660:                    if (checksOfConstructorByParameter == null)
661:                        return;
662:
663:                    // retrieve the checks for the specified parameter
664:                    final Collection<Check> checksOfConstructorParameter = checksOfConstructorByParameter
665:                            .get(parameterIndex);
666:                    if (checksOfConstructorParameter == null)
667:                        return;
668:
669:                    for (final Check check : checks) {
670:                        checksOfConstructorParameter.remove(check);
671:                    }
672:
673:                    if (checksOfConstructorParameter.size() == 0) {
674:                        checksOfConstructorByParameter.remove(parameterIndex);
675:                    }
676:                }
677:            }
678:
679:            public void removeFieldChecks(final Field field,
680:                    final Check... checks) {
681:                synchronized (checksForFields) {
682:                    final Set<Check> checksOfField = checksForFields.get(field);
683:
684:                    if (checksOfField == null)
685:                        return;
686:
687:                    for (final Check check : checks) {
688:                        checksOfField.remove(check);
689:                    }
690:
691:                    if (checksOfField.size() == 0) {
692:                        checksForFields.remove(field);
693:                        constrainedFields.remove(field);
694:                        constrainedStaticFields.remove(field);
695:                    }
696:                }
697:            }
698:
699:            public void removeMethodChecks(final Method method,
700:                    final Check... checks) {
701:                synchronized (checksForMethodReturnValues) {
702:                    final Set<Check> checksOfMethod = checksForMethodReturnValues
703:                            .get(method);
704:
705:                    if (checksOfMethod == null)
706:                        return;
707:
708:                    for (final Check check : checks) {
709:                        checksOfMethod.remove(check);
710:                    }
711:
712:                    if (checksOfMethod.size() == 0) {
713:                        checksForMethodReturnValues.remove(method);
714:                        constrainedMethods.remove(method);
715:                        constrainedStaticMethods.remove(method);
716:                    }
717:                }
718:            }
719:
720:            public void removeMethodParameterChecks(final Method method,
721:                    final int parameterIndex, final Check... checks)
722:                    throws InvalidConfigurationException {
723:                if (parameterIndex < 0
724:                        || parameterIndex > method.getParameterTypes().length)
725:                    throw new InvalidConfigurationException(
726:                            "ParameterIndex is out of range");
727:
728:                synchronized (checksForMethodParameters) {
729:                    // retrieve the currently registered checks for all parameters of the specified method
730:                    final Map<Integer, Set<Check>> checksOfMethodByParameter = checksForMethodParameters
731:                            .get(method);
732:                    if (checksOfMethodByParameter == null)
733:                        return;
734:
735:                    // retrieve the checks for the specified parameter
736:                    final Collection<Check> checksOfMethodParameter = checksOfMethodByParameter
737:                            .get(parameterIndex);
738:                    if (checksOfMethodParameter == null)
739:                        return;
740:
741:                    for (final Check check : checks) {
742:                        checksOfMethodParameter.remove(check);
743:                    }
744:
745:                    if (checksOfMethodParameter.size() == 0) {
746:                        checksOfMethodByParameter.remove(parameterIndex);
747:                    }
748:                }
749:            }
750:
751:            public void removeMethodPostChecks(final Method method,
752:                    final PostCheck... checks) {
753:                synchronized (checksForMethodsPostExcecution) {
754:                    final Set<PostCheck> checksforMethod = checksForMethodsPostExcecution
755:                            .get(method);
756:
757:                    if (checksforMethod == null)
758:                        return;
759:
760:                    for (final PostCheck check : checks) {
761:                        checksforMethod.remove(check);
762:                    }
763:
764:                    if (checksforMethod.size() == 0) {
765:                        checksForMethodsPostExcecution.remove(method);
766:                    }
767:                }
768:            }
769:
770:            public void removeMethodPreChecks(final Method method,
771:                    final PreCheck... checks) {
772:                synchronized (checksForMethodsPreExecution) {
773:                    final Set<PreCheck> checksforMethod = checksForMethodsPreExecution
774:                            .get(method);
775:
776:                    if (checksforMethod == null)
777:                        return;
778:
779:                    for (final PreCheck check : checks) {
780:                        checksforMethod.remove(check);
781:                    }
782:
783:                    if (checksforMethod.size() == 0) {
784:                        checksForMethodsPreExecution.remove(method);
785:                    }
786:                }
787:            }
788:
789:            public void removeObjectChecks(final Check... checks) {
790:                synchronized (checksForObject) {
791:                    for (final Check check : checks) {
792:                        checksForObject.remove(check);
793:                    }
794:                }
795:            }
796:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.