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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations