Guest User

Untitled

a guest
Oct 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. package com.activecq.core;
  2.  
  3. import org.apache.sling.api.adapter.AdapterFactory;
  4. import org.apache.sling.api.resource.Resource;
  5. import org.osgi.service.component.ComponentContext;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8.  
  9. import com.activecq.core.ActiveComponent;
  10.  
  11. /**
  12. * AdapterFactory that adapts Resources to the ActiveComponent class.
  13. *
  14. * @scr.component metatype="no" immediate="true"
  15. * @scr.property name="service.vendor" value="Active CQ"
  16. * @scr.property name="service.description" value="Active Component Adapter"
  17. * @scr.property name="adaptables"
  18. * values.0="org.apache.sling.api.resource.Resource"
  19. * @scr.property name="adapters"
  20. * values.0="com.activecq.core.ActiveComponent"
  21. * @scr.service interface="org.apache.sling.api.adapter.AdapterFactory"
  22. */
  23. public class ActiveComponentAdapterFactory implements AdapterFactory {
  24.  
  25. private static final Logger log = LoggerFactory.getLogger(ActiveComponentAdapterFactory.class);
  26.  
  27. // ---------- AdapterFactory -----------------------------------------------
  28.  
  29. @SuppressWarnings("unchecked")
  30. public <AdapterType> AdapterType getAdapter(Object adaptable,
  31. Class<AdapterType> type) {
  32. log.info("### Adapting Resource to ActiveComponent");
  33. if(!(adaptable instanceof Resource)) { return null; }
  34.  
  35. Resource resource = (Resource) adaptable;
  36.  
  37. return (AdapterType) new ActiveComponent(resource);
  38. }
  39.  
  40.  
  41. protected void activate(ComponentContext context) {
  42.  
  43. }
  44.  
  45. protected void deactivate(ComponentContext context) {
  46.  
  47. }
  48.  
  49. }
Add Comment
Please, Sign In to add comment