Search in sources :

Example 11 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class NSArraySerializer method marshall.

public Object marshall(SerializerState state, Object p, Object o) throws MarshallException {
    NSArray nsarray = (NSArray) o;
    JSONObject obj = new JSONObject();
    JSONArray arr = new JSONArray();
    // Have a single function to do it.
    if (ser.getMarshallClassHints()) {
        try {
            obj.put("javaClass", o.getClass().getName());
        } catch (JSONException e) {
            throw new MarshallException("javaClass not found!");
        }
    }
    try {
        obj.put("nsarray", arr);
        state.push(o, arr, "nsarray");
    } catch (JSONException e) {
        throw new MarshallException("Error setting nsarray: " + e);
    }
    int index = 0;
    try {
        Enumeration e = nsarray.objectEnumerator();
        while (e.hasMoreElements()) {
            Object json = ser.marshall(state, arr, e.nextElement(), Integer.valueOf(index));
            if (JSONSerializer.CIRC_REF_OR_DUPLICATE != json) {
                arr.put(json);
            } else {
                // put a slot where the object would go, so it can be fixed up properly in the fix up phase
                arr.put(JSONObject.NULL);
            }
            index++;
        }
    } catch (MarshallException e) {
        throw (MarshallException) new MarshallException("element " + index).initCause(e);
    } finally {
        state.pop();
    }
    return obj;
}
Also used : Enumeration(java.util.Enumeration) JSONObject(org.json.JSONObject) NSArray(com.webobjects.foundation.NSArray) MarshallException(org.jabsorb.serializer.MarshallException) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject)

Example 12 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class WOEventDisplayPage method displayLevelForEvent.

public int displayLevelForEvent(EOEvent e) {
    int index, i, n;
    NSArray children;
    index = selectionPath.indexOfObject(e);
    if (index != NSArray.NotFound)
        return index;
    children = rootEventList();
    if (children.containsObject(e))
        return 0;
    int count = selectionPath.count();
    for (i = 0, n = count; i < n; i++) {
        children = (NSArray) cache.objectForKey(selectionPath.objectAtIndex(i));
        if (null == children)
            break;
        if (children.containsObject(e))
            return i + 1;
    }
    return -1;
}
Also used : NSArray(com.webobjects.foundation.NSArray)

Example 13 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class WOEventDisplayPage method childrenForEvent.

public NSArray childrenForEvent(EOEvent event) {
    NSArray anArray;
    int level, tag;
    anArray = (NSArray) cache.objectForKey(event);
    if (null != anArray) {
        if (anArray.count() == 0)
            return null;
        else
            return anArray;
    }
    anArray = event.subevents();
    if (anArray == null || (anArray.count() == 0)) {
        cache.setObjectForKey(NSArray.EmptyArray, event);
        return null;
    }
    level = displayLevelForEvent(event) + 1;
    if (level == -1)
        level = selectionPath.count() + 1;
    tag = groupTagForDisplayLevel(level);
    if (tag >= 0)
        anArray = EOEvent.groupEvents(anArray, tag);
    tag = aggregateTagForDisplayLevel(level);
    if (tag >= 0)
        anArray = EOEvent.aggregateEvents(anArray, tag);
    anArray = filterEvents(anArray, level);
    cache.setObjectForKey(anArray, event);
    return anArray;
}
Also used : NSArray(com.webobjects.foundation.NSArray)

Example 14 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class WOEventDisplayPage method filterEvents.

public NSArray filterEvents(NSArray evs, int level) {
    int i, n;
    NSArray filtered;
    if (evs == null) {
        return NSArray.EmptyArray;
    }
    // by their plain duration, which is what the default implementation does.
    try {
        if (_displayMode != 4 || level != 0) {
            try {
                filtered = evs.sortedArrayUsingComparator(_eventAscendingComparator);
            } catch (IllegalStateException ex) {
                filtered = evs;
            }
        } else {
            // For association mode, we need to filter out unwanted events,
            // i.e. those which are not related to associations.
            int count = evs.count();
            NSMutableArray mutableFiltered = new NSMutableArray(count);
            for (i = 0, n = count; i < n; i++) {
                if (childrenForEvent((EOEvent) evs.objectAtIndex(i)).count() != 0)
                    mutableFiltered.addObject(evs.objectAtIndex(i));
            }
            mutableFiltered.sortUsingComparator(_eventAscendingComparator);
            filtered = mutableFiltered;
        }
    } catch (NSComparator.ComparisonException e) {
        throw NSForwardException._runtimeExceptionForThrowable(e);
    }
    return filtered;
}
Also used : NSComparator(com.webobjects.foundation.NSComparator) NSArray(com.webobjects.foundation.NSArray) NSMutableArray(com.webobjects.foundation.NSMutableArray)

Example 15 with NSArray

use of com.webobjects.foundation.NSArray in project wonder-slim by undur.

the class WOEventDisplayPage method _cacheWebEofEvents.

public void _cacheWebEofEvents() {
    if (webEvents != null)
        return;
    NSArray allCenters = EOEventCenter.allEventsForAllCenters();
    int halfCount = allCenters.count() / 2;
    webEvents = new NSMutableArray(halfCount);
    eofEvents = new NSMutableArray(halfCount);
    Enumeration anEnumerator = allCenters.objectEnumerator();
    while (anEnumerator.hasMoreElements()) {
        EOEvent e = (EOEvent) anEnumerator.nextElement();
        if (e instanceof WOEvent)
            webEvents.addObject(e);
        else
            eofEvents.addObject(e);
    }
}
Also used : EOEvent(com.webobjects.eocontrol.EOEvent) WOEvent(com.webobjects.appserver.WOEvent) Enumeration(java.util.Enumeration) NSArray(com.webobjects.foundation.NSArray) NSMutableArray(com.webobjects.foundation.NSMutableArray)

Aggregations

NSArray (com.webobjects.foundation.NSArray)53 Enumeration (java.util.Enumeration)17 NSMutableArray (com.webobjects.foundation.NSMutableArray)13 NSBundle (com.webobjects.foundation.NSBundle)5 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)5 File (java.io.File)4 List (java.util.List)4 WOAssociation (com.webobjects.appserver.WOAssociation)3 WOComponent (com.webobjects.appserver.WOComponent)3 NSDictionary (com.webobjects.foundation.NSDictionary)3 IOException (java.io.IOException)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 WOElement (com.webobjects.appserver.WOElement)2 WOResponse (com.webobjects.appserver.WOResponse)2 WOConstantValueAssociation (com.webobjects.appserver._private.WOConstantValueAssociation)2 EOEvent (com.webobjects.eocontrol.EOEvent)2 EOSortOrdering (com.webobjects.eocontrol.EOSortOrdering)2 NSForwardException (com.webobjects.foundation.NSForwardException)2 NSKeyValueCoding (com.webobjects.foundation.NSKeyValueCoding)2