View Javadoc
1   /**
2    * Copyright By Grandsoft Company Limited.  
3    * 2013-8-10 上午06:11:08
4    */
5   package gboat2.base.core.web.md;
6   
7   import gboat2.base.core.Activator;
8   import gboat2.base.core.cache.ICacheService;
9   
10  import java.net.URL;
11  
12  import net.sf.json.JSONObject;
13  
14  import org.osgi.framework.Bundle;
15  import org.osgi.framework.BundleContext;
16  
17  /**
18   * 
19   * 缓存metadata url处理器.缓存url,防止重新与bundle的资源交互
20   * @author lysming
21   * @since jdk1.6
22   * @date 2013-8-10
23   *  
24   */
25  
26  public class CacheHandler extends MetadataHandler {
27  
28  	/** 
29  	  * {@inheritDoc}   
30  	  * @see gboat2.base.core.web.md.MetadataHandler#parseMetadata(org.osgi.framework.Bundle, java.net.URL) 
31  	  */
32  	@Override
33  	public JSONObject parseMetadata(JSONObject object, URL url, Bundle bundle, MetadataHandlerChain chain) {
34  		BundleContext context =  Activator.LOCAL_BUNDLE.getBundleContext();
35  		ICacheService cache =(ICacheService)context.getService(context.getServiceReference(ICacheService.class.getName()));
36  		if(cache!=null){
37  			if (cache.get(chain.getBundle().getSymbolicName(), chain.getFilePath()) == null) {
38  				cache.put(chain.getBundle().getSymbolicName(), chain.getFilePath(), url);
39  			}
40  		}
41  		return chain.doHandler(object, url, bundle);
42  	}
43  
44  }