Package edu.uiuc.ncsa.security.core.cf
Class CFLoader
- java.lang.Object
-
- edu.uiuc.ncsa.security.core.cf.CFLoader
-
public class CFLoader extends Object
Loads teh configuration from the file or other source. Typical idiom for use:FileInputStream fis = getFileInputStream("alias/cfg-alias.xml");In this case, a file with a relative path is loaded, the bundle created for the given tag (so all of the tags named "service" are in the resulting bundle) and then a specific configuration of type "service" with name "A" is retrieved. This is the top node for that configuration. All environment variables and inheritence has been resolved, so you can just use the CFNode's methods.CFLoaderconfig = new CFLoader();CFBundlebundle = config.loadBundle(fis, "service");CFNodenode = bundle.getNamedConfig("A");
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCFLoader.Builder
-
Field Summary
Fields Modifier and Type Field Description static StringENV_END_ELEMENTstatic StringENV_START_ELEMENTstatic StringENV_TAGstatic StringFILE_TAGstatic StringINCLUDE_TAGstatic StringKEY_TAG
-
Constructor Summary
Constructors Constructor Description CFLoader()CFLoader(CFLoader.Builder builder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FilegetFile()InputStreamgetInputStream()StringgetResource()StringgetTagName()protected booleanhasFile()protected booleanhasInputStream()protected booleanhasResource()protected booleanisEndEnv(String l)Does the trimmed line end with an environment end tag?protected booleanisStartEnv(String l)Does the trimmed line start and environment entry?CFBundleloadBundle()Used with the builder.CFBundleloadBundle(File file, String tagName)Loads the specified file.CFBundleloadBundle(InputStream inputStream, String tagName)Main entry point for loading a configuration.protected CFBundleloadBundle(InputStream inputStream, String tagName, EnvStack envStack, Set<String> loadedFiles)Loads a configuration.CFBundleloadBundle(String resource, String tagName)Loads the specified resource as a stream.protected EnvTable<? extends SKey,? extends EnvEntry>processEnvDocument(InputStream inputStream)Process a single env document from any source.protected DocumentresolveEnvironment(InputStream inputStream, EnvStack stack, Set<String> loadedFiles, boolean isRoot)Returns a valid XML document with the environment references done.protected NoderesolveFileReferences(Document rootDoc, Node cfg, EnvStack stack, Set<String> visitedFiles)All the actual work for loading files is done here.voidsetFile(File file)voidsetInputStream(InputStream inputStream)voidsetResource(String resource)CFLoadersetTagName(String tagName)Supports builder pattern
-
-
-
Field Detail
-
FILE_TAG
public static final String FILE_TAG
- See Also:
- Constant Field Values
-
INCLUDE_TAG
public static final String INCLUDE_TAG
- See Also:
- Constant Field Values
-
ENV_TAG
public static final String ENV_TAG
- See Also:
- Constant Field Values
-
KEY_TAG
public static final String KEY_TAG
- See Also:
- Constant Field Values
-
ENV_START_ELEMENT
public static final String ENV_START_ELEMENT
- See Also:
- Constant Field Values
-
ENV_END_ELEMENT
public static final String ENV_END_ELEMENT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CFLoader
public CFLoader()
-
CFLoader
public CFLoader(CFLoader.Builder builder)
-
-
Method Detail
-
getTagName
public String getTagName()
-
hasFile
protected boolean hasFile()
-
hasResource
protected boolean hasResource()
-
hasInputStream
protected boolean hasInputStream()
-
getInputStream
public InputStream getInputStream()
-
setInputStream
public void setInputStream(InputStream inputStream)
-
getResource
public String getResource()
-
setResource
public void setResource(String resource)
-
getFile
public File getFile()
-
setFile
public void setFile(File file)
-
setTagName
public CFLoader setTagName(String tagName)
Supports builder pattern- Parameters:
tagName-- Returns:
-
loadBundle
public CFBundle loadBundle(String resource, String tagName) throws MyConfigurationException, CircularReferenceException
Loads the specified resource as a stream.- Parameters:
resource-tagName-- Returns:
- Throws:
MyConfigurationExceptionCircularReferenceException
-
loadBundle
public CFBundle loadBundle() throws MyConfigurationException, CircularReferenceException
Used with the builder. Set the source and tagname then invoke.- Returns:
- Throws:
MyConfigurationExceptionCircularReferenceException
-
loadBundle
public CFBundle loadBundle(File file, String tagName) throws MyConfigurationException, CircularReferenceException
Loads the specified file.- Parameters:
file-tagName-- Returns:
- Throws:
MyConfigurationExceptionCircularReferenceException
-
loadBundle
public CFBundle loadBundle(InputStream inputStream, String tagName) throws MyConfigurationException, CircularReferenceException
Main entry point for loading a configuration. This resolves all environment variables and file import, then parses the result as (valid) XML.- Parameters:
inputStream-- Returns:
- Throws:
MyConfigurationExceptionCircularReferenceException
-
loadBundle
protected CFBundle loadBundle(InputStream inputStream, String tagName, EnvStack envStack, Set<String> loadedFiles) throws MyConfigurationException, CircularReferenceException
Loads a configuration. This will also have the environment and- Parameters:
inputStream-loadedFiles-- Returns:
- Throws:
MyConfigurationExceptionCircularReferenceException
-
resolveEnvironment
protected Document resolveEnvironment(InputStream inputStream, EnvStack stack, Set<String> loadedFiles, boolean isRoot) throws Throwable
Returns a valid XML document with the environment references done.- Parameters:
inputStream-stack-- Returns:
- Throws:
Throwable
-
isStartEnv
protected boolean isStartEnv(String l)
Does the trimmed line start and environment entry?- Parameters:
l-- Returns:
-
isEndEnv
protected boolean isEndEnv(String l)
Does the trimmed line end with an environment end tag?- Parameters:
l-- Returns:
-
processEnvDocument
protected EnvTable<? extends SKey,? extends EnvEntry> processEnvDocument(InputStream inputStream) throws Throwable
Process a single env document from any source. The document is a valid XML file and only environment tags are processed. At the end of this, every envionment element will have been processed and put into a table.- Parameters:
inputStream-- Returns:
- Throws:
Throwable
-
resolveFileReferences
protected Node resolveFileReferences(Document rootDoc, Node cfg, EnvStack stack, Set<String> visitedFiles) throws Throwable
All the actual work for loading files is done here. This looks for elements inside the config tag of the form<file include="path"/>These are read and each line is inserted into the document. Included files may also include other files, which will be resolved as well. No promise of ordering is done.Nota Bene
Each include is a complete configuration file, not a fragment! They are processed as if independent (with their own env that retains scope).
- Parameters:
cfg-visitedFiles- Files already processed. Prevents cycles.- Returns:
- Throws:
Throwable
-
-