org.jicarilla.container

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » JicarillaHTTP » org.jicarilla.container 
org.jicarilla.container

The jicarilla container provides a compact inversion-of-control container API. It is so compact, in fact, that it can do so without requiring any interface representation!

Overview

Typical usage involves registering some classes and some component definitions with a container builder, retrieving a resolver from that builder, and then retrieving instances of the registered classes from that resolver. Behind the scenes, the container does its magic:

  • it handles the instantiation, initialization and disposal of the instances;
  • it provides the instances with their external dependencies and their configuration;
  • it can transparently support different "lifestyles", like "singleton" instances, single-use instances, per-thread instances, per-request instances, pooled instances, and others;
  • it can handle the lookup of instances from some kind of server or directory, using protocols like JNDI, JMX, SOAP, RMI or AltRMI. It can even use these instances in satisfying the dependencies of other instances;
  • it can handle the exporting of hosted instances to a similar server or directory, providing transparent interoperability with many diverse environments;
  • it can handle the activation and passivation (persistence) of instances, using mechanisms such as Hibernate, Prevayler, XStream or JDO;
  • do many other things depending on what extensions you plug in (do instrumentation and profiling, method tracing, custom interception, load balancing, etc etc.);

Most importantly, though each and every one of these features, and all the other features not mentioned yet, are fully pluggable. This means that you can start with a really small and simple container that does none of these things, and gradually add extensions to make it do exactly what you want. No more and no less. And because of this highly modular architecture, it is quite easy to create and add your own extensions.

Of course, many users have no desire to do all this feature selection themselves and just want a package that does what they need "with a few clicks". To support this desire, jicarilla-container is packaged up together with preconfigured settings into several different profiles. Just like java itself has different distributions (mobile, core, enterprise), we package up the jicarilla container in several different ways as well:

  • micro. Just the basics in a jar. If you want to do everything yourself.
  • gui. The basics, plus all the materials you need for productive GUI client applications.
  • power. The basics, plus lots of extensions that integrate the jicarilla container seamlessly with other container solutions and with many remote registries.
  • web. The power profile, with additional extensions that integrate the jicarilla container inside the prevalent web technologies (servlets, struts, webwork, hibernate, ...)
  • enterprise. The web profile with additional extensions that integrate the jicarilla container inside the prevalent enterprise technologies (JMX, JNDI, EJB, ..._
  • kitchensink. All of the above, plus a huge preloaded library of components, applications and examples.

Inversion of Control Basics

You may associate Inversion of Control (or IoC for short) with big and complex server application frameworks like Avalon, or solutions for developing J2EE-based web applications like Spring Framework. Fortunately, the basics of IoC are far simpler than any of those:

    public Apu apu = new ApuImpl();
    public Marge marge = new MargeImpl();
    public Homer homer = new HomerImpl( marge );
    public Bart bart = new BartImpl( homer, marge );
    public Lisa lisa = new LisaImpl( homer, marge );
    public Maggie maggie = new MaggieImpl( homer, marge );

    public HomerAndApuScript first = new HomerAndApuScript(
            (HotdogBuyer)homer, apu );
    public AllInTheFamilyScript second = new AllInTheFamilyScript(
            homer, marge, bart, lisa, maggie );

    public Script dbl = new DoubleEpisodeScript( first, second );
    dbl.runEpisode();

The important idea is that we have a container (in this case just a short code snippet) that is responsible for creating components, glueing them together, and telling them what to do. Control over the application flow starts at the top (with the container) and flows down (to the components).

A lot of people have written a lot more about inversion of control (or the "hollywood principle" as it has also been called), and you can find links to various papers on the Jicarilla website.

Getting Started with the Builder and Resolver

The easiest way to get a feel for how to work with the jicarilla container is to look at an example. Continuing the Simpsons example... here's a jicarilla-container-based version of the "manual" Simpson container above:

    Resolver resolver =
        DefaultBuilder.newInstance()
                .addComponent( "homer-and-apu", HomerAndApuScript.class )
                .addComponent( "all-in-the-family",
                        AllInTheFamilyScript.class )
                .addComponent( ApuImpl.class )
                .addComponent( BartImpl.class )
                .addComponent( HomerImpl.class )
                .addComponent( LisaImpl.class )
                .addComponent( MaggieImpl.class )
                .addComponent( MargeImpl.class )
                .addComponent(
                    new CustomComponentFactory // todo: create this class
                    (
                        DoubleEpisodeScript.class,
                        new Object[]
                        {
                            "homer-and-apu",
                            "all-in-the-family"
                        }
                    )
                )
                .create();

    Script script = (Script)resolver.get( Script.class );
    script.runEpisode();

From this simple example, it may not be immediately apparent what benefit you get from using jicarilla. After all, the functionality is the same, and the second one is easier to read and understand. But take another look at the second example. Note how the episode scripts are added before we add any of the Simpsons characters themselves. You don't have to worry about correctly ordering all your object creations. This is but a small taste of the huge benefits you can get from using the jicarilla-container package.

Core Interfaces

    {@link org.jicarilla.container.builder.Builder}
      The Builder is half of your main interface to the jicarilla-container package. It hides much of the complexity and magic that goes on "behind the screen" in the internals of the container package. You use it just like we did in the example above, to create and populate a Container instance with all your components. When you are finished populating the container, you call {@link org.jicarilla.container.builder.Builder#create()} to get access to an instance of a Resolver:
    {@link org.jicarilla.container.Resolver}
      The Resolver is that other half of your main interface to the jicarilla-container package. You use it just like we did in the example above, to retrieve references to components that live inside a Container. This may lead you to compare the Resolver with a naming or directory service like JNDI. While you could use a resolver much like you use JNDI, this is not usually a good idea. Instead of all your components looking up things inside the JNDI directory, the container is responsible for doing that for them. So your components are never aware of the existence of the Resolver. In fact, your components are never aware that they are living a Container at all!
    {@link org.jicarilla.container.Container}, {@link org.jicarilla.container.KeyRelayingContainer},
      The Container is the "meat" of the jicarilla-container package. It is the "fundamental abstraction", the spider in the center of the web. If jicarilla-container where an operating system, the Ccode>Container is what we would call the kernel. And just like 99% of the time, you have no particular interest in interacting directly with the operating system kernel, you usually don't interact directly with the Container either.
    {@link org.jicarilla.container.Adapter}, {@link org.jicarilla.container.KeyAwareAdapter}
      These two interfaces are the "smart trick" that makes jicarilla-container so agile, flexible and extensible. A lot of responsibility is taken away from the container and lives inside Adapters instead. In operating system terms, that means we would call the Container a microkernel. While in the majority of cases, you have little reason to use an Adapter directly, if you're doing really advanced stuff (like linking components living within your own variant of CORBA into the jicarilla-container system), Adapters are what you would need to write to make it happen.
    {@link org.jicarilla.container.Factory}
      You're probably familiar with the concept of Factories. They are "helper objects", often associated with a particular class, that are responsible for creating new instances of that class. They're commonly used when simply putting all the creation and instantiation directly inside the class constructor results in a really big and ugly constructor. The use of factories inside the jicarilla-container package is no different. The main thing that sets the jicarilla Factories apart from other factories is that they are quite "general". By using some pretty smart reflection and introspection magic, a handful of factories can be used for the instantiation of dozens (or thousands in a complex system, or even millions if you want to get silly) of different classes.

Type-1, Type-2, Type-3, Type-4, Type-e^2 IoC Support

You may have heard the buzz surrounding Inversion of Control, and the new buzzword introduced recently, "dependency injection". You may also have been quite ignorant of it all. Either case, jicarilla-container provides built-in, no-brainer, complete, simple, and integrated support for all the flavors of IoC that are currently popular. And its real easy to add support for new flavors as well.

In other words, this means that you'll be able to easily plug in components written for

With little effort and without having to rewrite (or even recompile) your components. Neath, huh?

todo: specific documentation on doing this kind of thing.

Non-IoC Component Support

But it doesn't stop there! With (usually) just a teeny weeny little bit more effort, you can plug in EJBs, servlets, Plain Old Java Objects (POJOs), JDBC data sources, xml files (!), property files, JNDI-hosted components, JMX-exported components, OSGi bundles, eclipse plugins, SOAP services, CORBA objects, RMI-exported services, and 20-year-old punchcards! Okay, I may be getting just a little carried away here, but you get the general idea, I hope.

todo: specific documentation on doing this kind of thing, rather than just bragging about it.

Java Source File NameTypeComment
Adapter.javaInterface

An adapter is used to plug "something" into a Container .

Container.javaInterface A container holds Adapter adapters , and provides a Resolver resolver to retrieve components from those adapters, and return them to those adapters.
CustomizableResolver.javaInterface
CyclicDependencyException.javaClass

Exception that is thrown when a Container detects a cyclic dependency.

DefaultContainer.javaClass

A straightforward implementation of the Container interface that is backed by a Switch .

DefaultCustomizableResolver.javaClass

A rather complex implementation of the Resolver interface that is backed by another Resolver , and can be used to override some of the container's autowiring policy.

You will normally not want to create instances of this class directly.

DefaultKeyRelayingContainer.javaClass

A straightforward implementation of the KeyRelayingContainer interface that is backed by a Switch .

DefaultKeyRelayingResolver.javaClass

A simple extension of DefaultResolver that adds handling for KeyAwareAdapter s.

DefaultResolver.javaClass

A Straightforward implementation of the Resolver interface that is backed by a ResolverCallback instance.

Factory.javaInterface

A factory is responsible for creating new instances of "something". Factories are commonly used in the implementation of Adapteradapters .

Note that while the interfaces for adapters and factories are nearly the same, the two don't do quite the same thing.

IllegalAdapterException.javaClass A JicarillaException that is thrown by a Container if a provided adapter is not supported by that container (if it is null, for example, or if it is not of some subtype that the container requires).
IllegalKeyException.javaClass A JicarillaException that is thrown by a Container if the criterion exposed by a provided selector or a provided key itself is not supported by that container.
IllegalSelectorException.javaClass A JicarillaException that is thrown by a Container if a provided selector is not supported by that container (if it is null, for example, or if it is not a org.jicarilla.lang.CriterionExposingSelector and the container requires it to be).
InitializationException.javaClass A JicarillaException that is thrown by containers, adapters, factories or resolvers if initialization of an instance fails.
JicarillaClassNotFoundException.javaClass A JicarillaException that is thrown by containers, adapters, factories or resolvers if an attempt to load a class fails.
JicarillaException.javaClass

The root exception for all of the more specific errors that are thrown by classes in the org.jicarilla.container package.

Since this is a RuntimeException , no explicit checking for any of these exceptions needs to take place in client code if you choose not to do so.

JicarillaIllegalAccessException.javaClass A JicarillaException that is thrown by containers, adapters, factories or resolvers if they have a problem accessing some external resource and are thus unable to create or provide an instance.
JicarillaIllegalStateException.javaClass A JicarillaException that is thrown by containers, adapters, factories or resolvers if a method is called on them while they are not ready for it.
JicarillaInstantiationException.javaClass A JicarillaException that is thrown by containers, adapters, factories or resolvers if they have has a problem creating an instance.
JicarillaInvocationTargetException.javaClass A JicarillaException that is thrown by containers, adapters, factories or resolvers if they have has a problem invoking some external resource and are thus unable to create or return an instance.
KeyAlreadyRegisteredException.javaClass A JicarillaException that is thrown by a Container if the criterion exposed by a provided selector or a provided key itself is already registered and the container does not support duplicate keys.
KeyAwareAdapter.javaInterface
KeyRelayingContainer.javaInterface A variant on the Container interface that passes on criterions passed to the Resolver resolver it ResolverProvider.getResolver provides to the adapters that are registered with it.
NoPublicConstructorAvailableException.javaClass Exception that is thrown when an Adapter or Factory cannot create an instance because there is no public constructor available.
NoSatisfiableConstructorAvailableException.javaClass Exception that is thrown when an Adapter or Factory cannot create an instance because none of its public constructors has an argument list that can be properly satisfied.
RegistrationException.javaClass A JicarillaException thrown by a Container or KeyRelayingContainer if an error occurs registering an adapter, selector and/or key.
ResolutionException.javaClass A JicarillaException thrown by a Resolver if no instance can be found for a provided key.
Resolver.javaInterface

A resolver provides basic means to query, retrieve and return object instances from "something".

ResolverCallback.javaInterface Represents the contract between a DefaultContainer or DefaultKeyRelayingContainer and the associated Resolver .
ResolverProvider.javaInterface A simple interface that any component that provides a Resolver should implement.
SynchronizationUtil.javaClass

Utility methods that create thread safe wrappers around the core abstractions of this package.

UnsatisfiableDependencyException.javaClass Exception that is thrown when an Adapter or Factory cannot create an instance because the instance has a dependency that cannot be satisfied.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.