View Javadoc

1   /*
2    * Copyright 2007 Hippo
3    *
4    * Licensed under the Apache License, Version 2.0 (the  "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" 
12   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  package nl.hippo.portal.binding;
17  
18  import nl.hippo.client.api.event.EventValidity;
19  import nl.hippo.portal.cms.CMSSite;
20  import nl.hippo.portal.cms.cache.EventCacheable;
21  import nl.hippo.portal.cms.cache.ObjectCache;
22  import nl.hippo.portal.cms.cache.PortalCacheKey;
23  import nl.hippo.portal.cms.source.Source;
24  import nl.hippo.portal.cms.source.SourceException;
25  
26  /***
27   * @author <a href="mailto:d.dam@hippo.nl">Dennis Dam</a>
28   *
29   * @version $Id: MarshalledObjectManagerImpl.java 8567 2007-10-18 15:32:18Z ddam $
30   */
31  public class MarshalledObjectManagerImpl implements MarshalledObjectManager {
32  
33      private CMSSite site;
34      
35      public Object createObject(BindingService bindingService, String url, Class clazz) throws BindingException, SourceException {
36          ObjectCache cache = site.getObjectCache();
37          PortalCacheKey cacheKey = cache.getCacheKeyFactory().createKey(new Object[]{"JAXBObject","site="+site.getName(),"url="+url,"class="+clazz.getName()});
38          Object object = cache.get(cacheKey);
39          if (object == null){
40              Source source = site.getSourceResolver().resolve(url);            
41              object = bindingService.unmarshal(clazz, source.getInputStream());
42              if (source instanceof EventCacheable){
43                  EventValidity[] validities = ((EventCacheable)source).getEventValidities();
44                  cache.store(cacheKey, object, validities);
45              }
46          }
47          return object;        
48      }
49  
50      public void setSite(CMSSite site) {
51          this.site = site;
52      }
53  
54  }