SlideShare uma empresa Scribd logo
1 de 35
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Justin Edelson | Technical Architect
Sling Models
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Agenda
 Background & Goals
 Usage
 Extensions
2
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
What is Sling Models?
 Let’s say you want to adapt a Resource into some domain object…
3
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
What is Sling Models?
public class OldModel {
private String title;
private String description;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
4
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
What is Sling Models?
@Component
@Service
@Properties({
@Property(name=AdapterFactory.ADAPTABLE_CLASSES, value="org.apache.sling.api.Resource"),
@Property(name=AdapterFactory.ADAPTER_CLASSES,
value="com.adobe.people.jedelson.slingmodels.demo.OldModel")
})
public class OldModelAdapterFactory implements AdapterFactory {
@SuppressWarnings("unchecked")
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (adaptable instanceof Resource && type.equals(OldModel.class)) {
OldModel model = new OldModel();
ValueMap map = ResourceUtil.getValueMap((Resource) adaptable);
model.setTitle(map.get(”title", String.class));
model.setDescription(map.get(”description", String.class));
return (AdapterType) model;
} else {
return null;
}
}
}
5
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
What is Sling Models?
OldModel myModel = resource.adaptTo(OldModel.class)
<sling:adaptTo adaptable="${resource}" adaptTo=”…
OldModel" var=”myModel" />
<div data-sly-use.myModel =“…OldModel”></div>
6
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
What is Sling Models?
@Model(adaptables = Resource.class)
public class NewModel {
@Inject
private String title;
@Inject
private String description;
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
}
7
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
What is Sling Models?
NewModel myModel = resource.adaptTo(NewModel.class)
<sling:adaptTo adaptable="${resource}" adaptTo=”…
NewModel" var=”myModel" />
<div data-sly-use.myModel=“…NewModel”></div>
8
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
What is Sling Models?
 The “old” way: 30+ LOC
 The “new” way: 13 LOC
 Plus one extra bundle header:
<Sling-Model-Packages>com.adobe.people.jedelson.slingmodels.demo</Sling-Model-Packages>
9
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
What is Sling Models?
@Model(adaptables = Resource.class)
public interface NewModel2 {
@Inject
public String getTitle();
@Inject
public String getDescription();
}
10
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Design Goals
 Entirely annotation driven. "Pure" POJOs.
 Use standard annotations where possible.
 Pluggable
 OOTB, support resource properties (via ValueMap), SlingBindings, OSGi
services, request attributes
 Adapt multiple objects - minimal required Resource and
SlingHttpServletRequest
 Client doesn't know/care that these objects are different than any other
adapter factory
 Support both classes and interfaces.
 Work with existing Sling infrastructure (i.e. not require changes to other
bundles).
11
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Timeline
 December 2013 – YAMF prototype announced on sling-dev
 January 2014 – API formalized and renamed to Sling Models
 Feburary 2014 – 1.0.0 release; Included in AEM 6.0 Beta
 March 2014 – 1.0.2 release; Included in AEM 6.0 Release
 May 2014 – 1.0.4 release; Memory leak bug fix.
12
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage – What can be injected?
 In order…
 SlingBindings objects
 ValueMap properties (with Resource -> ValueMap adaptation)
 Child Resources
 Request Attributes
 OSGi Services
 This is just the default set.
13
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage - Annotations
 @org.apache.sling.models.annotations.Model
 @javax.inject.Inject
 @javax.inject.Named
 @org.apache.sling.models.annotations.Optional
 @org.apache.sling.models.annotations.Source
 @org.apache.sling.models.annotations.Filter
 @javax.inject.PostConstruct
 @org.apache.sling.models.annotations.Via
 @org.apache.sling.models.annotations.Default
14
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage - @Model
 @Model(adaptables = Resource.class)
 @Model(adaptables = SlingHttpServletRequest.class)
 @Model(adaptables = { Resource.class, ValueMap.class })
15
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage - @Inject
 @Inject private String title;
 valueMap.get(“title”, String.class);
 @Inject public String getTitle();
 valueMap.get(“title”, String.class);
 @Inject private String[] columnNames;
 valueMap.get(“columnNames”, String[].class);
 @Inject private List<Filter> filters;
 bundleContext.getServiceReferences(“javax.servlet.Filter”)
16
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage - @Named
 By default, the name of the field or method is used to perform the
injection.
 @Inject @Named(“jcr:title”) private String title;
 valueMap.get(“jcr:title”, String.class);
17
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage - @Optional
 By default, all @Inject points are required.
 resource.adaptTo(Model.class) <- returns null
 @Inject @Optional private String title;
18
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage - @Source
 request.getAttribute(“text”) <- returns “goodbye”
 slingBindings.get(“text”) <- returns “hello”
 @Inject private String text; <- “hello” (SlingBindings is checked first)
 @Inject @Source(“request-attributes”) private String text; <- “goodbye”
19
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage - @Source
20
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage - @Filter
 Specifically for OSGi services:
 @Inject @Filter("(sling.servlet.extensions=json)") private List<Servlet>
servlets;
 Implicitly applies @Source(“osgi-services”)
21
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage - @PostConstruct
 @Inject private String text;
 @PostConstruct protected void doSomething() { log.info("text = {}", text);
};
 Superclass @PostConstruct methods called first.
22
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage - @Via
@Model(adaptables = SlingHttpServletRequest.class)
public class ViaModel {
@Inject
@Via("resource")
private String firstProperty;
public String getFirstProperty() {
return firstProperty;
}
}
23
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage - @Default
 @Inject @Default(values=“default text”) private String text;
 Also
 booleanValues
 doubleValues
 floatValues
 intValues
 longValues
 shortValues
24
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage – Constructor Injection
 If you need the adaptable itself
@Model(adaptables = SlingHttpServletRequest.class)
public class WithOneConstructorModel {
private final SlingHttpServletRequest request;
@Inject
private int attribute;
public WithOneConstructorModel(SlingHttpServletRequest request) {
this.request = request;
}
public int getAttribute() {
return attribute;
}
public SlingHttpServletRequest getRequest() {
return request;
}
}
25
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage – Child Adaptation
@Model(adaptables = Resource.class)
public interface ChildValueMapModel {
@Inject
public ValueMap getFirstChild();
}
 resource.getChild(“firstChild”).adaptTo(ValueMap.class)
26
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Usage – Fancy Child Adaptation
@Model(adaptables = Resource.class)
public interface ParentModel {
@Inject
public ChildModel getFirstChild();
}
 Works even if resource.adaptTo(ChildModel.class) isn’t done by Sling
Models
27
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Extensions – Custom Injectors
 Injectors are OSGi services implementing the
org.apache.sling.models.spi.Injector interface
 Object getValue(Object adaptable, String name, Type type,
AnnotatedElement element, DisposalCallbackRegistry callbackRegistry)
 adaptable – the object being adapted
 name – the name (either using @Named or the default name)
 element – the method or field
 callbackRegistry – Injector gets notified when the adapted model is
garbage collected
28
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Extensions – Custom Injector
public Object getValue(Object adaptable, String name,
Type type, AnnotatedElement element,
DisposalCallbackRegistry callbackRegistry) {
Resource resource = getResource(adaptable);
if (resource == null) {
return null;
} else if (type instanceof Class<?>) {
InheritanceValueMap map = new
HierarchyNodeInheritanceValueMap(resource);
return map.getInherited(name, (Class<?>) type);
} else {
return null;
}
}
29
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Extensions – Custom Annotation
 Some injectors need extra data
 Example: OSGi service filters
@Target({ ElementType.FIELD, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
@Source("resource-path")
public @interface ResourcePath {
String value();
}
30
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Extensions – Custom Annotations
public Object getValue(Object adaptable, String name,
Type declaredType, AnnotatedElement element,
DisposalCallbackRegistry callbackRegistry) {
ResourcePath path =
element.getAnnotation(ResourcePath.class);
if (path == null) {
return null;
}
ResourceResolver resolver = getResourceResolver(adaptable);
if (resolver == null) {
return null;
}
return resolver.getResource(path.value());
}
31
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Extensions – Custom Annotations
@Model(adaptables = Resource.class)
public interface ResourcePathModel {
@Inject @ResourcePath("/content/dam")
Resource getResource();
}
32
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Availability
 Bundles can be downloaded from http://sling.apache.org/downloads.cgi
 Content Package can be downloaded from https://github.com/Adobe-
Consulting-Services/com.adobe.acs.bundles.sling-models/releases
 Bleeding edge code can be built from
http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/models
33
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Future Roadmap
 Custom Annotations
 More Standard Injectors
 Grandchild Resource Lists
 AEM-specific injectors in ACS AEM Commons
 Pluggable @Via support
34
© 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Mais conteúdo relacionado

Mais procurados

Rest and Sling Resolution
Rest and Sling ResolutionRest and Sling Resolution
Rest and Sling ResolutionDEEPAK KHETAWAT
 
AEM Rich Text Editor (RTE) Deep Dive
AEM Rich Text Editor (RTE) Deep DiveAEM Rich Text Editor (RTE) Deep Dive
AEM Rich Text Editor (RTE) Deep DiveHanish Bansal
 
Introduction to Sightly and Sling Models
Introduction to Sightly and Sling ModelsIntroduction to Sightly and Sling Models
Introduction to Sightly and Sling ModelsStefano Celentano
 
Basics of Solr and Solr Integration with AEM6
Basics of Solr and Solr Integration with AEM6Basics of Solr and Solr Integration with AEM6
Basics of Solr and Solr Integration with AEM6DEEPAK KHETAWAT
 
Dynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMDynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMBojana Popovska
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep DiveGabriel Walt
 
AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101Adobe
 
Aem dispatcher – tips & tricks
Aem dispatcher – tips & tricksAem dispatcher – tips & tricks
Aem dispatcher – tips & tricksAshokkumar T A
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6Yuval Ararat
 
AEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentAEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentGabriel Walt
 
SPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager SitesSPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager SitesGabriel Walt
 
Experience and Content Fragment
Experience and Content FragmentExperience and Content Fragment
Experience and Content FragmentHeena Madan
 
Sling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatSling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatAEM HUB
 
Introduction to JSX
Introduction to JSXIntroduction to JSX
Introduction to JSXMicah Wood
 
Spring framework IOC and Dependency Injection
Spring framework  IOC and Dependency InjectionSpring framework  IOC and Dependency Injection
Spring framework IOC and Dependency InjectionAnuj Singh Rajput
 

Mais procurados (20)

Sightly - Part 2
Sightly - Part 2Sightly - Part 2
Sightly - Part 2
 
AEM - Client Libraries
AEM - Client LibrariesAEM - Client Libraries
AEM - Client Libraries
 
Rest and Sling Resolution
Rest and Sling ResolutionRest and Sling Resolution
Rest and Sling Resolution
 
AEM Rich Text Editor (RTE) Deep Dive
AEM Rich Text Editor (RTE) Deep DiveAEM Rich Text Editor (RTE) Deep Dive
AEM Rich Text Editor (RTE) Deep Dive
 
Introduction to Sightly and Sling Models
Introduction to Sightly and Sling ModelsIntroduction to Sightly and Sling Models
Introduction to Sightly and Sling Models
 
Basics of Solr and Solr Integration with AEM6
Basics of Solr and Solr Integration with AEM6Basics of Solr and Solr Integration with AEM6
Basics of Solr and Solr Integration with AEM6
 
Dynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMDynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEM
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101
 
Aem dispatcher – tips & tricks
Aem dispatcher – tips & tricksAem dispatcher – tips & tricks
Aem dispatcher – tips & tricks
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
AEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentAEM Best Practices for Component Development
AEM Best Practices for Component Development
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
 
SPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager SitesSPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager Sites
 
Experience and Content Fragment
Experience and Content FragmentExperience and Content Fragment
Experience and Content Fragment
 
Sling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatSling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak Khetawat
 
Introduction to JSX
Introduction to JSXIntroduction to JSX
Introduction to JSX
 
Spring framework IOC and Dependency Injection
Spring framework  IOC and Dependency InjectionSpring framework  IOC and Dependency Injection
Spring framework IOC and Dependency Injection
 

Destaque

The six key steps to AEM architecture
The six key steps to AEM architectureThe six key steps to AEM architecture
The six key steps to AEM architectureAshokkumar T A
 
Extra AEM Development Tools
Extra AEM Development ToolsExtra AEM Development Tools
Extra AEM Development ToolsJustin Edelson
 
Omnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the ThingsOmnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the ThingsJustin Edelson
 
Apache Sling Generic Validation Framework
Apache Sling Generic Validation FrameworkApache Sling Generic Validation Framework
Apache Sling Generic Validation FrameworkRadu Cotescu
 
Declarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleDeclarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleFelix Meschberger
 
SCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitSCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitMike Pfaff
 
Server-side OSGi with Apache Sling (OSGiDevCon 2011)
Server-side OSGi with Apache Sling (OSGiDevCon 2011)Server-side OSGi with Apache Sling (OSGiDevCon 2011)
Server-side OSGi with Apache Sling (OSGiDevCon 2011)Felix Meschberger
 
Modern operations with Apache Sling (2014 adaptTo version)
Modern operations with Apache Sling (2014 adaptTo version)Modern operations with Apache Sling (2014 adaptTo version)
Modern operations with Apache Sling (2014 adaptTo version)Bertrand Delacretaz
 
OSGi, Scripting and REST, Building Webapps With Apache Sling
OSGi, Scripting and REST, Building Webapps With Apache SlingOSGi, Scripting and REST, Building Webapps With Apache Sling
OSGi, Scripting and REST, Building Webapps With Apache SlingCarsten Ziegeler
 
RESTful Web Applications with Apache Sling
RESTful Web Applications with Apache SlingRESTful Web Applications with Apache Sling
RESTful Web Applications with Apache SlingBertrand Delacretaz
 
Shooting rabbits with sling
Shooting rabbits with slingShooting rabbits with sling
Shooting rabbits with slingTomasz Rękawek
 
Apache Sling : JCR, OSGi, Scripting and REST
Apache Sling : JCR, OSGi, Scripting and RESTApache Sling : JCR, OSGi, Scripting and REST
Apache Sling : JCR, OSGi, Scripting and RESTCarsten Ziegeler
 
AEM WITH MONGODB
AEM WITH MONGODBAEM WITH MONGODB
AEM WITH MONGODBNate Nelson
 
AEM (CQ) Dispatcher Caching Webinar 2013
AEM (CQ) Dispatcher Caching Webinar 2013AEM (CQ) Dispatcher Caching Webinar 2013
AEM (CQ) Dispatcher Caching Webinar 2013Andrew Khoury
 
IBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and DockerIBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and DockerDavid Currie
 

Destaque (18)

The six key steps to AEM architecture
The six key steps to AEM architectureThe six key steps to AEM architecture
The six key steps to AEM architecture
 
Extra AEM Development Tools
Extra AEM Development ToolsExtra AEM Development Tools
Extra AEM Development Tools
 
Omnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the ThingsOmnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the Things
 
Apache Sling Generic Validation Framework
Apache Sling Generic Validation FrameworkApache Sling Generic Validation Framework
Apache Sling Generic Validation Framework
 
Declarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleDeclarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi Style
 
SCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitSCR Annotations for Fun and Profit
SCR Annotations for Fun and Profit
 
Reactive applications
Reactive applicationsReactive applications
Reactive applications
 
Server-side OSGi with Apache Sling (OSGiDevCon 2011)
Server-side OSGi with Apache Sling (OSGiDevCon 2011)Server-side OSGi with Apache Sling (OSGiDevCon 2011)
Server-side OSGi with Apache Sling (OSGiDevCon 2011)
 
Modern operations with Apache Sling (2014 adaptTo version)
Modern operations with Apache Sling (2014 adaptTo version)Modern operations with Apache Sling (2014 adaptTo version)
Modern operations with Apache Sling (2014 adaptTo version)
 
OSGi, Scripting and REST, Building Webapps With Apache Sling
OSGi, Scripting and REST, Building Webapps With Apache SlingOSGi, Scripting and REST, Building Webapps With Apache Sling
OSGi, Scripting and REST, Building Webapps With Apache Sling
 
RESTful Web Applications with Apache Sling
RESTful Web Applications with Apache SlingRESTful Web Applications with Apache Sling
RESTful Web Applications with Apache Sling
 
Shooting rabbits with sling
Shooting rabbits with slingShooting rabbits with sling
Shooting rabbits with sling
 
Aem maintenance
Aem maintenanceAem maintenance
Aem maintenance
 
Apache Sling : JCR, OSGi, Scripting and REST
Apache Sling : JCR, OSGi, Scripting and RESTApache Sling : JCR, OSGi, Scripting and REST
Apache Sling : JCR, OSGi, Scripting and REST
 
AEM WITH MONGODB
AEM WITH MONGODBAEM WITH MONGODB
AEM WITH MONGODB
 
Intro to OSGi
Intro to OSGiIntro to OSGi
Intro to OSGi
 
AEM (CQ) Dispatcher Caching Webinar 2013
AEM (CQ) Dispatcher Caching Webinar 2013AEM (CQ) Dispatcher Caching Webinar 2013
AEM (CQ) Dispatcher Caching Webinar 2013
 
IBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and DockerIBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and Docker
 

Semelhante a Sling Models Overview

Design Patterns - Part 2 of 2
Design Patterns - Part 2 of 2Design Patterns - Part 2 of 2
Design Patterns - Part 2 of 2Savio Sebastian
 
AEM and Sling
AEM and SlingAEM and Sling
AEM and SlingLokesh BS
 
Deepak khetawat sling_models_sightly_jsp
Deepak khetawat sling_models_sightly_jspDeepak khetawat sling_models_sightly_jsp
Deepak khetawat sling_models_sightly_jspDEEPAK KHETAWAT
 
Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2Savio Sebastian
 
Efficient content structures and queries in CRX/CQ
Efficient content structures and queries in CRX/CQEfficient content structures and queries in CRX/CQ
Efficient content structures and queries in CRX/CQconnectwebex
 
CloudStack Meetup Santa Clara
CloudStack Meetup Santa Clara CloudStack Meetup Santa Clara
CloudStack Meetup Santa Clara NetApp
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Manykenatmxm
 
Mastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin EdelsonMastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin EdelsonAEM HUB
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling RewriterJustin Edelson
 
Storage Plug-ins
Storage Plug-ins Storage Plug-ins
Storage Plug-ins buildacloud
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPTAjay Chimmani
 
Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaert
Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D BosschaertLeveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaert
Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaertmfrancis
 
Android architecture
Android architecture Android architecture
Android architecture Trong-An Bui
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdfShaiAlmog1
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 

Semelhante a Sling Models Overview (20)

Sightly_techInsight
Sightly_techInsightSightly_techInsight
Sightly_techInsight
 
Design Patterns - Part 2 of 2
Design Patterns - Part 2 of 2Design Patterns - Part 2 of 2
Design Patterns - Part 2 of 2
 
AEM and Sling
AEM and SlingAEM and Sling
AEM and Sling
 
Deepak khetawat sling_models_sightly_jsp
Deepak khetawat sling_models_sightly_jspDeepak khetawat sling_models_sightly_jsp
Deepak khetawat sling_models_sightly_jsp
 
Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Efficient content structures and queries in CRX/CQ
Efficient content structures and queries in CRX/CQEfficient content structures and queries in CRX/CQ
Efficient content structures and queries in CRX/CQ
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
CloudStack Meetup Santa Clara
CloudStack Meetup Santa Clara CloudStack Meetup Santa Clara
CloudStack Meetup Santa Clara
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Many
 
Mastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin EdelsonMastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin Edelson
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
 
Storage Plug-ins
Storage Plug-ins Storage Plug-ins
Storage Plug-ins
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaert
Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D BosschaertLeveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaert
Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaert
 
Android architecture
Android architecture Android architecture
Android architecture
 
SOLID
SOLIDSOLID
SOLID
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdf
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 

Último

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 

Último (20)

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 

Sling Models Overview

  • 1. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Justin Edelson | Technical Architect Sling Models
  • 2. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Agenda  Background & Goals  Usage  Extensions 2
  • 3. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. What is Sling Models?  Let’s say you want to adapt a Resource into some domain object… 3
  • 4. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. What is Sling Models? public class OldModel { private String title; private String description; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } } 4
  • 5. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. What is Sling Models? @Component @Service @Properties({ @Property(name=AdapterFactory.ADAPTABLE_CLASSES, value="org.apache.sling.api.Resource"), @Property(name=AdapterFactory.ADAPTER_CLASSES, value="com.adobe.people.jedelson.slingmodels.demo.OldModel") }) public class OldModelAdapterFactory implements AdapterFactory { @SuppressWarnings("unchecked") public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) { if (adaptable instanceof Resource && type.equals(OldModel.class)) { OldModel model = new OldModel(); ValueMap map = ResourceUtil.getValueMap((Resource) adaptable); model.setTitle(map.get(”title", String.class)); model.setDescription(map.get(”description", String.class)); return (AdapterType) model; } else { return null; } } } 5
  • 6. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. What is Sling Models? OldModel myModel = resource.adaptTo(OldModel.class) <sling:adaptTo adaptable="${resource}" adaptTo=”… OldModel" var=”myModel" /> <div data-sly-use.myModel =“…OldModel”></div> 6
  • 7. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. What is Sling Models? @Model(adaptables = Resource.class) public class NewModel { @Inject private String title; @Inject private String description; public String getTitle() { return title; } public String getDescription() { return description; } } 7
  • 8. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. What is Sling Models? NewModel myModel = resource.adaptTo(NewModel.class) <sling:adaptTo adaptable="${resource}" adaptTo=”… NewModel" var=”myModel" /> <div data-sly-use.myModel=“…NewModel”></div> 8
  • 9. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. What is Sling Models?  The “old” way: 30+ LOC  The “new” way: 13 LOC  Plus one extra bundle header: <Sling-Model-Packages>com.adobe.people.jedelson.slingmodels.demo</Sling-Model-Packages> 9
  • 10. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. What is Sling Models? @Model(adaptables = Resource.class) public interface NewModel2 { @Inject public String getTitle(); @Inject public String getDescription(); } 10
  • 11. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Design Goals  Entirely annotation driven. "Pure" POJOs.  Use standard annotations where possible.  Pluggable  OOTB, support resource properties (via ValueMap), SlingBindings, OSGi services, request attributes  Adapt multiple objects - minimal required Resource and SlingHttpServletRequest  Client doesn't know/care that these objects are different than any other adapter factory  Support both classes and interfaces.  Work with existing Sling infrastructure (i.e. not require changes to other bundles). 11
  • 12. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Timeline  December 2013 – YAMF prototype announced on sling-dev  January 2014 – API formalized and renamed to Sling Models  Feburary 2014 – 1.0.0 release; Included in AEM 6.0 Beta  March 2014 – 1.0.2 release; Included in AEM 6.0 Release  May 2014 – 1.0.4 release; Memory leak bug fix. 12
  • 13. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage – What can be injected?  In order…  SlingBindings objects  ValueMap properties (with Resource -> ValueMap adaptation)  Child Resources  Request Attributes  OSGi Services  This is just the default set. 13
  • 14. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage - Annotations  @org.apache.sling.models.annotations.Model  @javax.inject.Inject  @javax.inject.Named  @org.apache.sling.models.annotations.Optional  @org.apache.sling.models.annotations.Source  @org.apache.sling.models.annotations.Filter  @javax.inject.PostConstruct  @org.apache.sling.models.annotations.Via  @org.apache.sling.models.annotations.Default 14
  • 15. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage - @Model  @Model(adaptables = Resource.class)  @Model(adaptables = SlingHttpServletRequest.class)  @Model(adaptables = { Resource.class, ValueMap.class }) 15
  • 16. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage - @Inject  @Inject private String title;  valueMap.get(“title”, String.class);  @Inject public String getTitle();  valueMap.get(“title”, String.class);  @Inject private String[] columnNames;  valueMap.get(“columnNames”, String[].class);  @Inject private List<Filter> filters;  bundleContext.getServiceReferences(“javax.servlet.Filter”) 16
  • 17. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage - @Named  By default, the name of the field or method is used to perform the injection.  @Inject @Named(“jcr:title”) private String title;  valueMap.get(“jcr:title”, String.class); 17
  • 18. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage - @Optional  By default, all @Inject points are required.  resource.adaptTo(Model.class) <- returns null  @Inject @Optional private String title; 18
  • 19. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage - @Source  request.getAttribute(“text”) <- returns “goodbye”  slingBindings.get(“text”) <- returns “hello”  @Inject private String text; <- “hello” (SlingBindings is checked first)  @Inject @Source(“request-attributes”) private String text; <- “goodbye” 19
  • 20. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage - @Source 20
  • 21. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage - @Filter  Specifically for OSGi services:  @Inject @Filter("(sling.servlet.extensions=json)") private List<Servlet> servlets;  Implicitly applies @Source(“osgi-services”) 21
  • 22. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage - @PostConstruct  @Inject private String text;  @PostConstruct protected void doSomething() { log.info("text = {}", text); };  Superclass @PostConstruct methods called first. 22
  • 23. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage - @Via @Model(adaptables = SlingHttpServletRequest.class) public class ViaModel { @Inject @Via("resource") private String firstProperty; public String getFirstProperty() { return firstProperty; } } 23
  • 24. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage - @Default  @Inject @Default(values=“default text”) private String text;  Also  booleanValues  doubleValues  floatValues  intValues  longValues  shortValues 24
  • 25. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage – Constructor Injection  If you need the adaptable itself @Model(adaptables = SlingHttpServletRequest.class) public class WithOneConstructorModel { private final SlingHttpServletRequest request; @Inject private int attribute; public WithOneConstructorModel(SlingHttpServletRequest request) { this.request = request; } public int getAttribute() { return attribute; } public SlingHttpServletRequest getRequest() { return request; } } 25
  • 26. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage – Child Adaptation @Model(adaptables = Resource.class) public interface ChildValueMapModel { @Inject public ValueMap getFirstChild(); }  resource.getChild(“firstChild”).adaptTo(ValueMap.class) 26
  • 27. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage – Fancy Child Adaptation @Model(adaptables = Resource.class) public interface ParentModel { @Inject public ChildModel getFirstChild(); }  Works even if resource.adaptTo(ChildModel.class) isn’t done by Sling Models 27
  • 28. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Extensions – Custom Injectors  Injectors are OSGi services implementing the org.apache.sling.models.spi.Injector interface  Object getValue(Object adaptable, String name, Type type, AnnotatedElement element, DisposalCallbackRegistry callbackRegistry)  adaptable – the object being adapted  name – the name (either using @Named or the default name)  element – the method or field  callbackRegistry – Injector gets notified when the adapted model is garbage collected 28
  • 29. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Extensions – Custom Injector public Object getValue(Object adaptable, String name, Type type, AnnotatedElement element, DisposalCallbackRegistry callbackRegistry) { Resource resource = getResource(adaptable); if (resource == null) { return null; } else if (type instanceof Class<?>) { InheritanceValueMap map = new HierarchyNodeInheritanceValueMap(resource); return map.getInherited(name, (Class<?>) type); } else { return null; } } 29
  • 30. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Extensions – Custom Annotation  Some injectors need extra data  Example: OSGi service filters @Target({ ElementType.FIELD, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Qualifier @Source("resource-path") public @interface ResourcePath { String value(); } 30
  • 31. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Extensions – Custom Annotations public Object getValue(Object adaptable, String name, Type declaredType, AnnotatedElement element, DisposalCallbackRegistry callbackRegistry) { ResourcePath path = element.getAnnotation(ResourcePath.class); if (path == null) { return null; } ResourceResolver resolver = getResourceResolver(adaptable); if (resolver == null) { return null; } return resolver.getResource(path.value()); } 31
  • 32. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Extensions – Custom Annotations @Model(adaptables = Resource.class) public interface ResourcePathModel { @Inject @ResourcePath("/content/dam") Resource getResource(); } 32
  • 33. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Availability  Bundles can be downloaded from http://sling.apache.org/downloads.cgi  Content Package can be downloaded from https://github.com/Adobe- Consulting-Services/com.adobe.acs.bundles.sling-models/releases  Bleeding edge code can be built from http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/models 33
  • 34. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Future Roadmap  Custom Annotations  More Standard Injectors  Grandchild Resource Lists  AEM-specific injectors in ACS AEM Commons  Pluggable @Via support 34
  • 35. © 2013 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Notas do Editor

  1. Or less…
  2. @Model determines what classes can be adapted from. It’s essentially the equivelant of the adaptables service property on an Adapter Factory
  3. @Inject marks an injection point. In a class, can be on a field. In an interface, on a method. Arrays and Lists are supported.
  4. Possibly in the future, a class-level annotation could be used to set the default to @Optional, at which point we’ll add @Required
  5. Source names are listed on http://sling.apache.org/documentation/bundles/models.html. Also http://localhost:4502/system/console/status-slingmodels
  6. Obviously only for classes. Doesn’t apply to interfaces
  7. Constructor must only have a single argument. The argument can be a superclass, i.e. HttpServletRequest