{
return (SessionFactory)new InitialContext().lookup(sfJNDIName);
}
catch (NamingException e)
{
throw new IdentityException("Cannot obtain hibernate SessionFactory from provided JNDI name: " + sfJNDIName, e);
}
}
else if (sfRegistryName != null)
{
Object registryObject = configurationContext.getConfigurationRegistry().getObject(sfRegistryName);
if (registryObject == null)
{
throw new IdentityException("Cannot obtain hibernate SessionFactory from provided registry name: " + sfRegistryName);
}
if (!(registryObject instanceof SessionFactory))
{
throw new IdentityException("Cannot obtain hibernate SessionFactory from provided registry name: " + sfRegistryName
+ "; Registered object is not an instance of SessionFactory: " + registryObject.getClass().getName());
}
return (SessionFactory)registryObject;
}
else if (hibernateConfiguration != null)
{
try
{
AnnotationConfiguration config = new AnnotationConfiguration().configure(hibernateConfiguration);
//TODO: make it optional to add annotated classes here
if (addMappedClasses != null && addMappedClasses.equals("false"))
{
return config.buildSessionFactory();
}
else
{
return config.addAnnotatedClass(HibernateIdentityObject.class)
.addAnnotatedClass(HibernateIdentityObjectAttribute.class)
.addAnnotatedClass(HibernateIdentityObjectBinaryAttribute.class)
.addAnnotatedClass(HibernateIdentityObjectBinaryAttributeValue.class)
.addAnnotatedClass(HibernateIdentityObjectTextAttribute.class)
.addAnnotatedClass(HibernateIdentityObjectCredential.class)
.addAnnotatedClass(HibernateIdentityObjectCredentialType.class)
.addAnnotatedClass(HibernateIdentityObjectRelationship.class)
.addAnnotatedClass(HibernateIdentityObjectRelationshipName.class)
.addAnnotatedClass(HibernateIdentityObjectRelationshipType.class)
.addAnnotatedClass(HibernateIdentityObjectType.class)
.addAnnotatedClass(HibernateRealm.class).buildSessionFactory();
}
}
catch (Exception e)
{
throw new IdentityException("Cannot obtain hibernate SessionFactory using provided hibernate configuration: "+ hibernateConfiguration, e);
}
}
throw new IdentityException("Cannot obtain hibernate SessionFactory. None of supported options specified: "
+ HIBERNATE_SESSION_FACTORY_JNDI_NAME + ", " + HIBERNATE_SESSION_FACTORY_REGISTRY_NAME + ", " + HIBERNATE_CONFIGURATION);
}