Search in sources :

Example 1 with CaseInsensitiveProperties

use of com.sun.identity.common.CaseInsensitiveProperties in project OpenAM by OpenRock.

the class SMSFlatFileObject method loadMapper.

/**
     * Loads the name mapper, create it if it doesn't exist.
     **/
protected void loadMapper() throws SMSException {
    StringBuffer nameMapFilename = new StringBuffer(mRootDir);
    nameMapFilename.append(File.separatorChar);
    nameMapFilename.append(DEFAULT_NAMEMAP_FILENAME);
    mNameMapHandle = new File(nameMapFilename.toString());
    if (mNameMapHandle.isFile()) {
        if (!mNameMapHandle.canRead()) {
            String errmsg = "SMSFlatFileObject.initialize: cannot read file " + mNameMapHandle.getPath();
            mDebug.error(errmsg);
            throw new SMSException(errmsg);
        }
        mNameMap = loadProperties(mNameMapHandle, null);
    } else {
        try {
            mNameMapHandle.createNewFile();
        } catch (IOException e) {
            String errmsg = "SMSFlatFileObject.initialize: " + "cannot create file, " + nameMapFilename + ". Exception " + e.getMessage();
            mDebug.error(errmsg);
            throw new SMSException(errmsg);
        } catch (SecurityException e) {
            String errmsg = "SMSFlatFileObject.initialize: " + "cannot create file " + nameMapFilename + ". Exception " + e.getMessage();
            mDebug.error(errmsg);
            throw new SMSException(errmsg);
        }
        mNameMap = new CaseInsensitiveProperties();
        // create root dn if this is a new directory.
        try {
            create(null, mRootDN, new HashMap());
            if (mDebug.messageEnabled()) {
                mDebug.message("SMSFlatFileObject.initialize: " + "created SMS object for " + mRootDN);
            }
        } catch (SSOException e) {
        // not possible
        } catch (ServiceAlreadyExistsException e) {
            if (mDebug.messageEnabled()) {
                mDebug.message("SMSFlatFileObject.initialize: " + mRootDN + " already exists");
            }
        }
        // also create ou=services this is a new directory.
        try {
            create(null, "ou=services," + mRootDN, new HashMap());
            if (mDebug.messageEnabled()) {
                mDebug.message("SMSFlatFileObject.initialize: " + "created SMS object for ou=services," + mRootDN);
            }
        } catch (SSOException e) {
        // not possible
        } catch (ServiceAlreadyExistsException e) {
            if (mDebug.messageEnabled()) {
                mDebug.message("SMSFlatFileObject.initialize: " + "ou=services," + mRootDN + " already exists");
            }
        }
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) CaseInsensitiveProperties(com.sun.identity.common.CaseInsensitiveProperties) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) File(java.io.File) ServiceAlreadyExistsException(com.sun.identity.sm.ServiceAlreadyExistsException)

Example 2 with CaseInsensitiveProperties

use of com.sun.identity.common.CaseInsensitiveProperties in project OpenAM by OpenRock.

the class SMSFlatFileObjectBase method loadProperties.

/**
     * Loads properties from the attribute file handle. 
     * @return Properties object of the configuration object.
     * @throws ServiceNotFoundException if the attributes file is not found.
     * @throws SMSException if an IO error occurred while reading the 
     * attributes properties file.
     * @throws SchemaException if a format error occurred while reading the 
     * attributes properties file.
     */
protected Properties loadProperties(File filehandle, String objName) throws SMSException {
    // read file contents into properties and 
    // form the attributes map to be returned from the properties. 
    FileInputStream fileistr = null;
    try {
        fileistr = new FileInputStream(filehandle);
        Properties props = new CaseInsensitiveProperties();
        props.load(fileistr);
        return props;
    } catch (FileNotFoundException e) {
        String errmsg = "SMSFlatFileObject.loadProperties: " + objName + " File, " + filehandle.getPath() + e.getMessage();
        mDebug.error("SMSFlatFileObject.loadProperties", e);
        throw new ServiceNotFoundException(errmsg);
    } catch (IOException e) {
        String errmsg = "SMSFlatFileObject.loadProperties: " + objName + " File, " + filehandle.getPath() + e.getMessage();
        mDebug.error("SMSFlatFileObject.loadProperties", e);
        throw new ServiceNotFoundException(errmsg);
    } catch (IllegalArgumentException e) {
        String errmsg = "SMSFlatFileObject.loadProperties: " + objName + " File, " + filehandle.getPath() + e.getMessage();
        mDebug.error("SMSFlatFileObject.loadProperties", e);
        throw new ServiceNotFoundException(errmsg);
    } finally {
        if (fileistr != null) {
            try {
                fileistr.close();
            } catch (IOException e) {
            // ignored
            }
        }
    }
}
Also used : CaseInsensitiveProperties(com.sun.identity.common.CaseInsensitiveProperties) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SystemProperties(com.iplanet.am.util.SystemProperties) CaseInsensitiveProperties(com.sun.identity.common.CaseInsensitiveProperties) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Aggregations

CaseInsensitiveProperties (com.sun.identity.common.CaseInsensitiveProperties)2 IOException (java.io.IOException)2 SystemProperties (com.iplanet.am.util.SystemProperties)1 SSOException (com.iplanet.sso.SSOException)1 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)1 SMSException (com.sun.identity.sm.SMSException)1 ServiceAlreadyExistsException (com.sun.identity.sm.ServiceAlreadyExistsException)1 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1