nl.pbemengine.engine.ng.base.autowire
Class AutowireRepository

java.lang.Object
  extended by nl.pbemengine.engine.ng.base.autowire.AutowireRepository

public class AutowireRepository
extends java.lang.Object

A repository for classes that can be autowired for a specific context. Please note that each Ruleset maintains its own set of autowire classes

Author:
Jeroen Steenbeeke

Field Summary
static java.lang.String ROOT_CONTEXT
          Name of the root context
 
Method Summary
 boolean accessible(java.lang.String context, java.lang.Class c)
          Check if we can autowire a certain class in the given context, or the root context
 java.lang.Object createWiredObject(java.lang.String context, java.lang.Class target)
          Create an autowired object according to the indicated context
protected  java.lang.Object createWiredObject(java.lang.String context, java.lang.Class target, java.util.LinkedList<java.lang.Class> current, org.hibernate.Session session)
          Create an autowired object according to the indicated context
static AutowireRepository getInstance()
          Get an instance of the AutowireRepository
 void registerClass(java.lang.String context, java.lang.Class cl)
          Register a class for a given context
 void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
          Set the Hibernate Session Factory for this Repository
 void unwire(java.lang.Object o, java.lang.String context)
          Checks an object and any autowired dependencies for Hibernate sessions, and closes them
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_CONTEXT

public static final java.lang.String ROOT_CONTEXT
Name of the root context

See Also:
Constant Field Values
Method Detail

getInstance

public static AutowireRepository getInstance()
Get an instance of the AutowireRepository

Returns:
An AutowireRepository instance

registerClass

public void registerClass(java.lang.String context,
                          java.lang.Class cl)
Register a class for a given context

Parameters:
context - The context in which the class is located
cl - The class to add

setSessionFactory

public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Set the Hibernate Session Factory for this Repository

Parameters:
sessionFactory - The Session Factory

accessible

public boolean accessible(java.lang.String context,
                          java.lang.Class c)
Check if we can autowire a certain class in the given context, or the root context

Parameters:
context - The context to check
c - The class to check
Returns:
true if we can autowire this class, false otherwise

createWiredObject

public java.lang.Object createWiredObject(java.lang.String context,
                                          java.lang.Class target)
                                   throws CircularReferenceException
Create an autowired object according to the indicated context

Parameters:
context - The context of the object
target - The target class of the created object
Returns:
An autowired object, or null if something went seriously wrong with trying to invoke the constructor
Throws:
CircularReferenceException

createWiredObject

protected java.lang.Object createWiredObject(java.lang.String context,
                                             java.lang.Class target,
                                             java.util.LinkedList<java.lang.Class> current,
                                             org.hibernate.Session session)
                                      throws CircularReferenceException
Create an autowired object according to the indicated context

Parameters:
context - The context of the object
target - The target class of the created object
current - A List of objects currently being autowired
session - A Hibernate session created in earlier iterations - passed to ensure only 1 is created for each autowired object and its dependencies
Returns:
An autowired object, or null if something went seriously wrong with trying to invoke the constructor
Throws:
CircularReferenceException

unwire

public void unwire(java.lang.Object o,
                   java.lang.String context)
Checks an object and any autowired dependencies for Hibernate sessions, and closes them

Parameters:
o - The object to unwire
context - The context in which the object was wired


Copyright © 2008. All Rights Reserved.