Search in sources :

Example 1 with SchemaException

use of com.sun.identity.sm.SchemaException in project OpenAM by OpenRock.

the class SMSFlatFileObject method getSubEntries.

/**
     * Real routine to get sub entries, used by subEntries() and 
     * schemaSubEntries(). 
     *
     * @throws ServiceNotFoundException if the configuration object is 
     * not found.
     * @throws SchemaException if a sub directory name is not in the 
     * expected "ou=..." format.
     */
protected Set getSubEntries(String objName, String filter, String sidFilter, boolean isSubConfig, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException {
    String objKey = objName.toLowerCase();
    Set subentries = null;
    // wait indefinitely for the read lock.
    mRWLock.readRequest();
    try {
        // Check if object exists.
        String filepath = mNameMap.getProperty(objKey);
        if (filepath == null) {
            String errmsg = "SMSFlatFileObjectBase.getSubEntries: " + objName + " : not found in objects map.";
            mDebug.warning(errmsg);
            throw new ServiceNotFoundException(errmsg);
        }
        File filehandle = new File(filepath);
        File parentDir = filehandle.getParentFile();
        if (!parentDir.isDirectory()) {
            String errmsg = "SMSFlatFileObject.getSubEntries: " + objName + " : " + filehandle.getPath() + " does not exist or is not a directory.";
            mDebug.error(errmsg);
            throw new ServiceNotFoundException(errmsg);
        }
        // Create file filter for filter and sid filter.
        FilenameFilter subentFileFilter = new FilenameFilter(filter);
        FilenameFilter sidFileFilter = null;
        if (sidFilter != null && sidFilter.length() > 0) {
            // are encoded. 
            if (isSubConfig) {
                sidFileFilter = new FilenameFilter(SMSEntry.ATTR_SERVICE_ID + "=" + sidFilter.toLowerCase());
            } else {
                sidFileFilter = new FilenameFilter(SMSEntry.ATTR_XML_KEYVAL + "=" + sidFilter.toLowerCase());
            }
        }
        // Create set for return, use sorted set if sortResults is true.
        if (sortResults) {
            subentries = new CaseInsensitiveTreeSet(ascendingOrder);
        } else {
            subentries = new CaseInsensitiveHashSet();
        }
        // Set all entries that match filter, and that match 
        // sunserviceid/sunxmlkeyvalye if sidFilter was not null.
        File[] subentriesFound = parentDir.listFiles(subentFileFilter);
        int numEntriesAdded = 0;
        boolean done = false;
        for (int i = 0; (i < subentriesFound.length) && !done; i++) {
            File[] sunserviceidFiles = null;
            if (sidFileFilter == null || ((sunserviceidFiles = subentriesFound[i].listFiles(sidFileFilter)) != null && sunserviceidFiles.length > 0)) {
                String filename = subentriesFound[i].getName();
                int equalSign = filename.indexOf('=');
                if (equalSign < 0 || equalSign == (filename.length() - 1)) {
                    String errmsg = "SMSFlatFileObject.getSubEntries: " + "Invalid sub entry name found: " + filename;
                    mDebug.error(errmsg);
                    throw new SchemaException(errmsg);
                }
                String subentryname = FileNameDecoder.decode(filename.substring(equalSign + 1));
                subentries.add(subentryname);
                numEntriesAdded++;
                // stop if number of entries requested has been reached.
                // if sort results, need to get the whole list first.
                done = !sortResults && (numOfEntries > 0) && (numEntriesAdded == numOfEntries);
            }
        }
        if (sortResults && (numOfEntries > 0)) {
            // remove extra entries from the bottom.
            while ((numEntriesAdded - numOfEntries) > 0) {
                Object l = ((CaseInsensitiveTreeSet) subentries).last();
                subentries.remove(l);
                numEntriesAdded--;
            }
        }
    } finally {
        mRWLock.readDone();
    }
    return subentries;
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) SchemaException(com.sun.identity.sm.SchemaException) CaseInsensitiveTreeSet(com.sun.identity.common.CaseInsensitiveTreeSet) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) CaseInsensitiveTreeSet(com.sun.identity.common.CaseInsensitiveTreeSet) File(java.io.File)

Example 2 with SchemaException

use of com.sun.identity.sm.SchemaException in project OpenAM by OpenRock.

the class SMSEnhancedFlatFileObject method getSubEntries.

/**
     * Real routine to get sub entries, used by subEntries() and 
     * schemaSubEntries(). 
     *
     * @throws ServiceNotFoundException if the configuration object is 
     * not found.
     * @throws SchemaException if a sub directory name is not in the 
     * expected "ou=..." format.
     */
protected Set getSubEntries(String objName, String filter, String sidFilter, boolean isSubConfig, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException {
    String objKey = objName.toLowerCase();
    Set subentries = null;
    // wait indefinitely for the read lock.
    mRWLock.readRequest();
    try {
        SMSFlatFileTreeNode node = root.getChild(objKey);
        if (node == null) {
            String errmsg = "SMSEnhancedFlatFileObject.getSubEntries: " + objName + " : not found in objects map.";
            mDebug.warning(errmsg);
            throw new ServiceNotFoundException(errmsg);
        }
        // Create file filter for filter and sid filter.
        NodeNameFilter subEntNodeFilter = new NodeNameFilter(filter);
        NodeNameFilter sidNameFilter = getSidNodeFilter(sidFilter, isSubConfig);
        // Create set for return, use sorted set if sortResults is true.
        if (sortResults) {
            subentries = new CaseInsensitiveTreeSet(ascendingOrder);
        } else {
            subentries = new CaseInsensitiveHashSet();
        }
        // Set all entries that match filter, and that match 
        // sunserviceid/sunxmlkeyvalye if sidFilter was not null.
        Set subEntries = node.searchChildren(subEntNodeFilter, false);
        int numEntriesAdded = 0;
        int sz = subEntries.size();
        boolean done = false;
        for (Iterator i = subEntries.iterator(); i.hasNext() && !done; ) {
            SMSFlatFileTreeNode n = (SMSFlatFileTreeNode) i.next();
            String nodeDN = n.getName();
            boolean accept = (sidNameFilter == null);
            if (!accept) {
                Set sids = n.searchChildren(sidNameFilter, false);
                accept = (sids != null) && !sids.isEmpty();
            }
            if (accept) {
                int idx = nodeDN.indexOf('=');
                if ((idx == -1) || (idx == (nodeDN.length() - 1))) {
                    String errmsg = "SMSEnhancedFlatFileObject.getSubEntries: " + "Invalid sub entry name found: " + nodeDN;
                    mDebug.error(errmsg);
                    throw new SchemaException(errmsg);
                }
                String subentryname = FileNameDecoder.decode(nodeDN.substring(idx + 1));
                subentries.add(subentryname);
                numEntriesAdded++;
                // stop if number of entries requested has been reached.
                // if sort results, need to get the whole list first.
                done = !sortResults && (numOfEntries > 0) && (numEntriesAdded == numOfEntries);
            }
        }
        if (sortResults && (numOfEntries > 0)) {
            while ((numEntriesAdded - numOfEntries) > 0) {
                Object l = ((CaseInsensitiveTreeSet) subentries).last();
                subentries.remove(l);
                numEntriesAdded--;
            }
        }
    } finally {
        mRWLock.readDone();
    }
    return subentries;
}
Also used : CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) SchemaException(com.sun.identity.sm.SchemaException) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) CaseInsensitiveTreeSet(com.sun.identity.common.CaseInsensitiveTreeSet) Set(java.util.Set) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) Iterator(java.util.Iterator) CaseInsensitiveTreeSet(com.sun.identity.common.CaseInsensitiveTreeSet)

Aggregations

CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)2 CaseInsensitiveTreeSet (com.sun.identity.common.CaseInsensitiveTreeSet)2 SchemaException (com.sun.identity.sm.SchemaException)2 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)2 Set (java.util.Set)2 File (java.io.File)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1