/** * Every managed context must specify a unique context name and the context change event * interface it supports. * * @param contextName Unique name for this context. * @param eventInterface The context change interface supported by this managed context. * @param initialContext The initial context state. May be null. */ protected ManagedContext(String contextName, Class<? extends IContextEvent> eventInterface, DomainClass initialContext) { this.contextName = contextName; this.eventInterface = eventInterface; setPending(initialContext); commit(true); }
/** * @see org.carewebframework.api.context.IManagedContext#addSubscribers(java.lang.Iterable) */ @Override public boolean addSubscribers(Iterable<Object> subscribers) { boolean result = false; for (Object subscriber : subscribers) { result |= addSubscriber(subscriber); } return result; }
/** * @see org.carewebframework.api.context.IManagedContext#setContextItems(org.carewebframework.api.context.ContextItems) */ @Override public boolean setContextItems(ContextItems contextItems) { DomainClass domainObject = fromCCOWContext(contextItems); if (domainObject == null) { return false; } setPending(domainObject); return true; }
/** * Commits or rejects the pending context change. * * @param accept If true, the pending change is committed. If false, the pending change is * canceled. */ @Override public void commit(boolean accept) { super.commit(accept); }
map = new HashMap<>(); map.put("action", accept ? "committed" : "canceled"); map.put("context", getContextName()); for (IContextEvent event : getIterable(all)) { IStopWatch sw = null; eventManager.fireLocalEvent(getEventName(), getContextObject(false));
map = new HashMap<String, Object>(); map.put("action", accept ? "committed" : "canceled"); map.put("context", getContextName()); for (IContextEvent event : getIterable(all)) { IStopWatch sw = null; eventManager.fireLocalEvent("CONTEXT.CHANGED." + getContextName(), getContextObject(false));
/** * @see org.carewebframework.api.context.IManagedContext#getContextItems(boolean) */ @Override public ContextItems getContextItems(boolean pending) { contextItems.clear(); DomainClass domainObject = getContextObject(pending); return domainObject == null ? contextItems : toCCOWContext(domainObject); }
/** * @see org.carewebframework.api.context.ISharedContext#requestContextChange(Object) */ @Override public void requestContextChange(DomainClass newContextObject) throws ContextException { if (isSameContext(newContextObject, getContextObject(false))) { return; } if (isPending) { throw new ContextException("A context change is already pending."); } contextManager.localChangeBegin(this); domainObject[CONTEXT_PENDING] = newContextObject; isPending = true; contextManager.localChangeEnd(this, null); }
/** * @see org.carewebframework.api.context.IManagedContext#removeSubscribers(java.lang.Iterable) */ @Override public void removeSubscribers(Iterable<IContextEvent> subscribers) { for (IContextEvent subscriber : subscribers) { removeSubscriber(subscriber); } }
/** * @see org.carewebframework.api.context.IManagedContext#surveySubscribers(boolean, * ISurveyCallback) */ @Override public void surveySubscribers(boolean silent, ISurveyCallback callback) { SurveyResponse response = new SurveyResponse(silent); Iterator<IContextEvent> iter = getIterable(true).iterator(); surveySubscribers(iter, response, callback); }
/** * @see org.carewebframework.api.context.IManagedContext#init() */ @Override public void init() { reset(); }
/** * Compares by priority, with higher priorities collating first. */ @Override public int compareTo(IManagedContext<DomainClass> o) { int pri1 = o.getPriority(); int pri2 = getPriority(); return this == o ? 0 : pri1 < pri2 ? -1 : 1; }
/** * Returns the name of the event fired after a successful context change. * * @return The name of the event fired after a successful context change. */ private String getEventName() { return "CONTEXT.CHANGED." + getContextName(); }
/** * @see org.carewebframework.api.context.IManagedContext#surveySubscribers(boolean) */ @Override public String surveySubscribers(boolean silent) { StringBuilder result = new StringBuilder(); for (IContextEvent event : getIterable(true)) { try { ContextManager.appendResponse(result, event.pending(silent)); } catch (Throwable e) { log.error("Error during surveysubscribers.", e); ContextManager.appendResponse(result, e.toString()); } surveyed.add(event); // Add to list of surveyed subscribers. if (!silent && result.length() > 0) { break; } } return result.toString(); }
/** * Commits or rejects the pending context change. * * @param accept If true, the pending change is committed. If false, the pending change is * canceled. */ @Override public void commit(boolean accept) { super.commit(accept); }
/** * @see org.carewebframework.api.context.IManagedContext#getContextItems(boolean) */ @Override public ContextItems getContextItems(boolean pending) { contextItems.clear(); DomainClass domainObject = getContextObject(pending); return domainObject == null ? contextItems : toCCOWContext(domainObject); }
/** * @see org.carewebframework.api.context.ISharedContext#requestContextChange(Object) */ @Override public void requestContextChange(DomainClass newContextObject) throws ContextException { if (isSameContext(newContextObject, getContextObject(false))) { return; } if (isPending) { throw new ContextException("A context change is already pending."); } contextManager.localChangeBegin(this); domainObject[CONTEXT_PENDING] = newContextObject; isPending = true; contextManager.localChangeEnd(this); }
/** * @see org.carewebframework.api.context.IManagedContext#removeSubscribers(java.lang.Iterable) */ @Override public void removeSubscribers(Iterable<Object> subscribers) { for (Object subscriber : subscribers) { removeSubscriber(subscriber); } }
/** * @see org.carewebframework.api.context.IManagedContext#init() */ @Override public void init() { reset(); }
/** * Compares by priority, with higher priorities collating first. */ @Override public int compareTo(IManagedContext o) { int pri1 = o.getPriority(); int pri2 = getPriority(); return this == o ? 0 : pri1 < pri2 ? -1 : 1; }