use of com.webobjects.foundation.NSMutableSet in project wonder-slim by undur.
the class ERXFileNotificationCenter method fileHasChanged.
/**
* Only used internally. Notifies all of the observers who have been
* registered for the given file.
*
* @param file
* file that has changed
*/
protected void fileHasChanged(File file) {
NSMutableSet observers = (NSMutableSet) _observersByFilePath.objectForKey(cacheKeyForFile(file));
if (observers == null)
log.warn("Unable to find observers for file: {}", file);
else {
NSNotification notification = new NSNotification(FileDidChange, file);
for (Enumeration e = observers.objectEnumerator(); e.hasMoreElements(); ) {
_ObserverSelectorHolder holder = (_ObserverSelectorHolder) e.nextElement();
try {
holder.selector.invoke(holder.observer, notification);
} catch (Exception ex) {
log.error("Catching exception when invoking method on observer: {}", ex, ex);
}
}
registerLastModifiedDateForFile(file);
}
}
use of com.webobjects.foundation.NSMutableSet in project wonder-slim by undur.
the class NSSetSerializer method unmarshall.
public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
try {
JSONObject jso = (JSONObject) o;
String java_class = jso.getString("javaClass");
if (java_class == null) {
throw new UnmarshallException("no type hint");
}
NSMutableSet abset = null;
if (java_class.equals("com.webobjects.foundation.NSSet") || java_class.equals("com.webobjects.foundation.NSMutableSet")) {
abset = new NSMutableSet();
} else {
throw new UnmarshallException("not a Set");
}
JSONObject jsonset = jso.getJSONObject("set");
if (jsonset == null) {
throw new UnmarshallException("set missing");
}
Iterator i = jsonset.keys();
String key = null;
try {
while (i.hasNext()) {
key = (String) i.next();
Object setElement = jsonset.get(key);
Object unmarshalledObject = ser.unmarshall(state, null, setElement);
abset.addObject(unmarshalledObject);
}
} catch (UnmarshallException e) {
throw new UnmarshallException("key " + i + e.getMessage());
}
return abset;
} catch (JSONException e) {
throw new UnmarshallException("Failed to unmarshall NSSet.", e);
}
}
use of com.webobjects.foundation.NSMutableSet in project wonder-slim by undur.
the class ERXSimpleTemplateParser method keysInTemplate.
/**
* Calculates the set of keys used in a given template
* for a given delimiter.
*
* @param template to check for keys
* @param delimiter for finding keys
* @return array of keys
*/
public NSArray keysInTemplate(String template, String delimiter) {
NSMutableSet keys = new NSMutableSet();
if (delimiter == null) {
delimiter = DEFAULT_DELIMITER;
}
NSArray components = NSArray.componentsSeparatedByString(template, delimiter);
if (!isLoggingDisabled) {
log.debug("Components: {}", components);
}
// if the template starts with delim, the first component will be a zero-length string
boolean deriveElement = false;
for (Enumeration e = components.objectEnumerator(); e.hasMoreElements(); ) {
String element = (String) e.nextElement();
if (deriveElement) {
if (element.length() == 0) {
throw new IllegalArgumentException("\"\" is not a valid keypath");
}
keys.addObject(element);
deriveElement = false;
} else {
deriveElement = true;
}
}
return keys.allObjects();
}
use of com.webobjects.foundation.NSMutableSet in project wonder-slim by undur.
the class ERXFileNotificationCenter method addObserver.
/**
* Used to register file observers for a particular file.
*
* @param observer
* object to be notified when a file changes
* @param selector
* selector to be invoked on the observer when the file changes.
* @param file
* file to watch for changes
*/
public void addObserver(Object observer, NSSelector selector, File file) {
if (file == null)
throw new RuntimeException("Attempting to register a null file.");
if (observer == null)
throw new RuntimeException("Attempting to register null observer for file: " + file);
if (selector == null)
throw new RuntimeException("Attempting to register null selector for file: " + file);
if (!developmentMode && checkFilesPeriod() == 0) {
log.info("Registering an observer when file checking is disabled (WOCaching must be " + "disabled or the er.extensions.ERXFileNotificationCenter.CheckFilesPeriod " + "property must be set). This observer will not ever by default be called: {}", file);
}
String filePath = cacheKeyForFile(file);
log.debug("Registering Observer for file at path: {}", filePath);
// Register last modified date.
registerLastModifiedDateForFile(file);
// FIXME: This retains the observer. This is not ideal. With the 1.3 JDK
// we can use a ReferenceQueue to maintain weak references.
NSMutableSet observerSet = (NSMutableSet) _observersByFilePath.objectForKey(filePath);
if (observerSet == null) {
observerSet = new NSMutableSet();
_observersByFilePath.setObjectForKey(observerSet, filePath);
}
observerSet.addObject(new _ObserverSelectorHolder(observer, selector));
}
Aggregations