Author: bdaw
Date: 2009-02-02 16:05:20 -0500 (Mon, 02 Feb 2009)
New Revision: 273
Modified:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/IdentitySessionFactoryImpl.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/configuration/jaxb2/JAXB2IdentityConfiguration.java
Log:
patch from TomB. Pass configuration with resource
Modified:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/IdentitySessionFactoryImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/IdentitySessionFactoryImpl.java 2009-02-02
21:04:42 UTC (rev 272)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/IdentitySessionFactoryImpl.java 2009-02-02
21:05:20 UTC (rev 273)
@@ -45,6 +45,7 @@
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @author Tom Baeyens
* @version : 0.1 $
*/
public class IdentitySessionFactoryImpl implements IdentitySessionFactory
@@ -70,6 +71,14 @@
}
+ public IdentitySessionFactoryImpl(String configResource) throws Exception
+ {
+ IdentityConfigurationMetaData configMD =
JAXB2IdentityConfiguration.createConfigurationMetaData(configResource);
+
+ realmMap = createSessionMap(configMD);
+
+ }
+
private Map<String, IdentitySession>
createSessionMap(IdentityConfigurationMetaData configMD) throws Exception
{
//TODO: some validation, sanity checks and error reporting
Modified:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/configuration/jaxb2/JAXB2IdentityConfiguration.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/configuration/jaxb2/JAXB2IdentityConfiguration.java 2009-02-02
21:04:42 UTC (rev 272)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/configuration/jaxb2/JAXB2IdentityConfiguration.java 2009-02-02
21:05:20 UTC (rev 273)
@@ -56,6 +56,9 @@
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
@@ -65,6 +68,7 @@
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @author Tom Baeyens
* @version : 0.1 $
*/
public abstract class JAXB2IdentityConfiguration
@@ -79,16 +83,43 @@
attributeTypes.add("binary");
}
+ public static IdentityConfigurationMetaData createConfigurationMetaData(File
configFile) throws IdentityConfigurationException
+ {
+ if (configFile == null)
+ {
+ throw new IllegalArgumentException("Identity config file is null");
+ }
+
+ InputStream inputStream;
+ try
+ {
+ inputStream = new FileInputStream(configFile);
+ } catch (FileNotFoundException e)
+ {
+ throw new IllegalArgumentException("Identity config file
"+configFile.getAbsolutePath()+" does not exist");
+ }
+ return createConfigurationMetaData(inputStream);
+ }
-
- public static IdentityConfigurationMetaData createConfigurationMetaData(File
xmlConfig) throws IdentityConfigurationException
+ public static IdentityConfigurationMetaData createConfigurationMetaData(String
configResource) throws IdentityConfigurationException
{
- if (xmlConfig == null || !xmlConfig.exists())
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ InputStream inputStream = classLoader.getResourceAsStream(configResource);
+ if (inputStream == null)
{
- throw new IllegalArgumentException("File does not exist");
+ throw new IllegalArgumentException("Resource "+configResource+"
does not exist");
}
+ return createConfigurationMetaData(inputStream);
+ }
+ public static IdentityConfigurationMetaData createConfigurationMetaData(InputStream
configInputStream) throws IdentityConfigurationException
+ {
+ if (configInputStream == null)
+ {
+ throw new IllegalArgumentException("no config resource");
+ }
+
JAXBElement<JbossIdentityType> jiElement = null;
Object o = null;
@@ -97,7 +128,7 @@
JAXBContext jaxbContext =
JAXBContext.newInstance("org.jboss.identity.idm.impl.configuration.jaxb2.generated");
Unmarshaller unMarshaller = jaxbContext.createUnmarshaller();
- jiElement =
(JAXBElement<JbossIdentityType>)unMarshaller.unmarshal(xmlConfig);
+ jiElement =
(JAXBElement<JbossIdentityType>)unMarshaller.unmarshal(configInputStream);
}
catch (JAXBException e)
{
Show replies by date