/** * @see org.carewebframework.api.context.IContextManager#localChangeBegin */ @Override public void localChangeBegin(IManagedContext<?> managedContext) throws ContextException { if (pendingStack.contains(managedContext) || commitStack.contains(managedContext)) { throw new ContextException("Circular context change detected."); } pendingStack.push(managedContext); }
/** * @see org.carewebframework.api.context.IContextManager#localChangeBegin */ @Override public void localChangeBegin(IManagedContext managedContext) throws ContextException { if (pendingStack.contains(managedContext) || commitStack.contains(managedContext)) { throw new ContextException("Circular context change detected."); } pendingStack.push(managedContext); }
@Override public void defer() { if (silent) { throw new ContextException("May not defer a response in silent mode"); } updateState(ResponseState.DEFERRED); }
private void updateState(ResponseState newState) { if (state != newState) { switch (state) { case NULL: state = newState; break; case ACCEPTED: case REJECTED: throw new ContextException("A response has already been registered for this subscriber."); case DEFERRED: state = newState; if (callback != null) { callback.response(this); } } } }
/** * @see org.carewebframework.api.context.IContextManager#getSharedContext */ @Override public ISharedContext<?> getSharedContext(String className) { try { Class<?> contextClass = Class.forName(className); for (ISharedContext<?> sharedContext : managedContexts) { if (contextClass.isInstance(sharedContext)) { return sharedContext; } } IManagedContext<?> ctx = (IManagedContext<?>) contextClass.newInstance(); registerObject(ctx); return ctx; } catch (Exception e) { throw new ContextException(e.getMessage()); } }
/** * @see org.carewebframework.api.context.IContextManager#getContextMarshaller */ @Override public ContextMarshaller getContextMarshaller(String keyStoreName) throws ContextException { try { return new ContextMarshaller(appFramework.getApplicationContext().getBean(keyStoreName, IDigitalSignature.class)); } catch (Exception e) { throw new ContextException( "An exception occurred while trying to access a context marshaller for the specified key store.", e); } }
/** * @see org.carewebframework.api.context.IContextManager#getContextMarshaller */ @Override public ContextMarshaller getContextMarshaller(String keyStoreName) throws ContextException { try { return new ContextMarshaller( appFramework.getApplicationContext().getBean(keyStoreName, IDigitalSignature.class)); } catch (Exception e) { throw new ContextException( "An exception occurred while trying to access a context marshaller for the specified key store.", e); } }
throw new ContextException("Illegal context change nesting.");
throw new ContextException("Illegal context change nesting.");
/** * Returns an object of the specified class. The class must have an associated context * serializer registered. * * @param itemName Item name * @param clazz Class of item to be returned. * @return Deserialized item of specified class. * @throws ContextException If no context serializer found. */ @SuppressWarnings("unchecked") public <T> T getItem(String itemName, Class<T> clazz) throws ContextException { String item = getItem(itemName); if (item == null || item.isEmpty()) { return null; } IContextSerializer<?> contextSerializer = ContextSerializerRegistry.getInstance().get(clazz); if (contextSerializer == null) { throw new ContextException("No serializer found for type " + clazz.getName()); } return (T) contextSerializer.deserialize(item); }
/** * Returns an object of the specified class. The class must have an associated context * serializer registered. * * @param <T> The item's class. * @param itemName Item name * @param clazz Class of item to be returned. * @return Deserialized item of specified class. * @throws ContextException If no context serializer found. */ @SuppressWarnings("unchecked") public <T> T getItem(String itemName, Class<T> clazz) throws ContextException { String item = getItem(itemName); if (item == null || item.isEmpty()) { return null; } ISerializer<?> contextSerializer = ContextSerializerRegistry.getInstance().get(clazz); if (contextSerializer == null) { throw new ContextException("No serializer found for type " + clazz.getName()); } return (T) contextSerializer.deserialize(item); }
/** * Sets a context item value. * * @param itemName Item name. * @param value The value to set. The value's class must have an associated context serializer * registered for it. */ public void setItem(String itemName, Object value) { if (value == null) { setItem(itemName, (String) null); } else { @SuppressWarnings("unchecked") ISerializer<Object> contextSerializer = (ISerializer<Object>) ContextSerializerRegistry.getInstance() .get(value.getClass()); if (contextSerializer == null) { throw new ContextException("No serializer found for type " + value.getClass().getName()); } setItem(itemName, contextSerializer.serialize(value)); } }
/** * Sets a context item value. * * @param itemName Item name. * @param value The value to set. The value's class must have an associated context serializer * registered for it. */ public void setItem(String itemName, Object value) { if (value == null) { setItem(itemName, (String) null); } else { @SuppressWarnings("unchecked") IContextSerializer<Object> contextSerializer = (IContextSerializer<Object>) ContextSerializerRegistry .getInstance().get(value.getClass()); if (contextSerializer == null) { throw new ContextException("No serializer found for type " + value.getClass().getName()); } setItem(itemName, contextSerializer.serialize(value)); } }
/** * @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.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); }