]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
34e2bf7e1bf07840b35f2f269882d660e4700b38
[tmp/jakarta-migration.git] /
1 /**
2  * An AOP (AspectJ) aspect to resolve the timezone related issue https://issues.collectionspace.org/browse/DRYD-182.
3  * 
4  * See related config in files: src/main/resources/META-INF/aop.xml, src/main/webapp/WEB-INF/applicationContext-security.xml
5  * 
6  */
7 package org.collectionspace.services.aspect;
8
9 import java.util.Date;
10 import javax.xml.datatype.XMLGregorianCalendar;
11
12 import org.aspectj.lang.ProceedingJoinPoint;
13 import org.aspectj.lang.annotation.Aspect;
14 import org.aspectj.lang.annotation.Around;
15 import org.aspectj.lang.annotation.Pointcut;
16
17 @Aspect
18 public class HyperJaxb3TimezoneAspect {
19
20         @Around("methodsToBeProfiled()")
21     public Object profile(ProceedingJoinPoint pjp) throws Throwable {
22         try {
23                 Date fromDate = (Date)pjp.getArgs()[0];
24                 XMLGregorianCalendar toDate = (XMLGregorianCalendar)pjp.getArgs()[1];
25                         
26             Object result = pjp.proceed();
27             //
28             // Marshal the timezone info from the 'fromDate' Date instance into the XMLGregorianCalendar 'toDate' instance
29             //
30             toDate.setTimezone(fromDate.getTimezoneOffset());
31
32             return result;
33         } finally {
34             // No cleanup needed.
35         }
36     }
37
38     /**
39      * Intercept all calls to the createCalendar() method of the XMLGregorianCalendarAsDateTime class.  This is how HyperJaxb3 marshals datetime info from Hibernate/JPA into
40      * out AuthN/AuthZ class instances.
41      */
42     @Pointcut("execution(* org.jvnet.hyperjaxb3.xml.bind.annotation.adapters.XMLGregorianCalendarAsDateTime.createCalendar(java.util.Date, javax.xml.datatype.XMLGregorianCalendar))")
43     public void methodsToBeProfiled() {}
44 }