Search in sources :

Example 1 with CheckPolicyException

use of org.jaffa.applications.jaffa.modules.admin.components.checkpolicy.ui.exceptions.CheckPolicyException in project jaffa-framework by jaffa-projects.

the class CheckPolicyComponent method readFunctions.

/**
 * This reads the bussiness-functions from the bussiness-functions.xml file
 * @throws ApplicationExceptions if any error occurs.
 */
private List readFunctions() throws ApplicationExceptions {
    ApplicationExceptions appExps = new ApplicationExceptions();
    ArrayList bflist = new ArrayList();
    InputStream stream = null;
    try {
        stream = URLHelper.newExtendedURL("resources/business-functions.xml").openStream();
        // create a JAXBContext capable of handling classes generated into the package
        JAXBContext jc = JAXBContext.newInstance("org.jaffa.security.businessfunctionsdomain");
        // create an Unmarshaller
        Unmarshaller u = jc.createUnmarshaller();
        // enable validation
        u.setSchema(JAXBHelper.createSchema(SCHEMA));
        // unmarshal a document into a tree of Java content objects composed of classes from the package.
        BusinessFunctions businessFunctions = (BusinessFunctions) u.unmarshal(XmlHelper.stripDoctypeDeclaration(stream));
        for (Iterator i = businessFunctions.getBusinessFunction().iterator(); i.hasNext(); ) {
            bflist.add(((BusinessFunction) i.next()).getName());
        }
    } catch (Exception e) {
        appExps.add(new CheckPolicyException(CheckPolicyException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
        throw appExps;
    } finally {
        try {
            if (stream != null) {
                stream.close();
            }
        } catch (IOException e) {
        // do nothing
        }
    }
    return bflist;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) InputStream(java.io.InputStream) BusinessFunctions(org.jaffa.security.businessfunctionsdomain.BusinessFunctions) CheckPolicyException(org.jaffa.applications.jaffa.modules.admin.components.checkpolicy.ui.exceptions.CheckPolicyException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) Unmarshaller(javax.xml.bind.Unmarshaller) FrameworkException(org.jaffa.exceptions.FrameworkException) CheckPolicyException(org.jaffa.applications.jaffa.modules.admin.components.checkpolicy.ui.exceptions.CheckPolicyException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 CheckPolicyException (org.jaffa.applications.jaffa.modules.admin.components.checkpolicy.ui.exceptions.CheckPolicyException)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 BusinessFunctions (org.jaffa.security.businessfunctionsdomain.BusinessFunctions)1