Download presentation
Presentation is loading. Please wait.
Published byErin Glenn Modified over 8 years ago
1
Developing with the Framework Zach A. Thomas, Texas State University zach.thomas@txstate.edu
2
Framework is… System facilities at your disposal The way those pieces interrelate so you can use them Conventions to adopt so that your modules will play nice
3
What facilities? AuthzGroupService SiteService ToolManager SessionManager ContentHostingService CourseManagementService … too many to mention!
4
Taking a Look Around project.xml = an artifact an artifact is a jar or a war
5
Sakai is servlets… Runs in Tomcat Familiar webapps directory WEB-INF, web.xmlweb.xml
6
Except when it’s not The components directory A shared registry of parts
7
the General Idea We want Sakai to be modular. We want to reconfigure it easily. We want to re-use code.
8
Parts of a module api: the service Interfaces impl: the classes that implement the api pack: a war file for deploying impl tool: an application. views, controllers, app logic.
9
Spring Framework A big box of tools for building J2EE apps with less overhead and pain. Includes MVC, AOP, transactions, JDBC, ORM. Underlying everything is the bean container.
10
Overhead and Pain Having to inherit from a framework class Having to implement tedious interfaces A proliferation of objects A tangled nest of checked exceptions Dependencies hard-coded in your class
11
Dependency Injection The properties of your objects are set at runtime. Your classes need not be aware of the concrete types of its properties.
13
robot.setBrain(new P4());robot.setEngine(new Diesel());robot.setWeapon(new Blades());
15
Spring beans Spring can manage your application’s objects if they follow a few non-invasive rules. Provide standard getters and setters for your object’s properties. Provide an init() method that Spring can call after all the dependent beans have been instantiated.
16
No more “new.” Anytime you write new Something() in Java, you are committing to a particular class. If you ever type “new,” ask yourself if it’s ok to have a dependency that you can only change by editing your source code and recompiling.
17
ComponentManager Wrapper for a Spring ApplicationContext Allows getting beans out either by id or by Class mgr.get(“org.sakaiproject.site.api.SiteService”);
18
How to get Springy add ContextLoaderListener to web.xml.web.xml create bean definitions for your objects. set any Sakai services you want to use as properties of your beans.
19
Springy JSPs web.context.support.WebApplicationContextUtils <% ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); SiteService ss = (SiteService) applicationContext.getBean("org.sakaiproject.site.api.SiteService"); ToolManager tm = (ToolManager) applicationContext.getBean("org.sakaiproject.tool.api.ToolManager"); %>
20
Demo
21
Questions? zach.thomas@txstate.edu
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.