Guest User

Untitled

a guest
Oct 19th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. /*
  2. * echo-messaging / ActionContext
  3. *
  4. * Copyright (c) 2011 Digital Chocolate, Inc. This program is not published or
  5. * distributed in source code form; accordingly, this source code is and remains
  6. * confidential to and a trade secret of Digital Chocolate, Inc.
  7. *
  8. * All rights reserved. SVN Version: $Revision: 323165 $
  9. */
  10. package com.dchoc.echo.messaging.command;
  11.  
  12. import java.util.HashMap;
  13. import java.util.Map;
  14.  
  15. import com.dchoc.echo.dao.IBaseType;
  16. import com.google.inject.Singleton;
  17.  
  18. /**
  19. * Keeps track of entities used by the actions.
  20. *
  21. * @author mrazola
  22. * @created May 27, 2011
  23. * @version 1
  24. * @serial $Id: ExtendedActionContext.java 323165 2011-06-08 15:45:05Z jmartin $
  25. */
  26. @Singleton
  27. @Deprecated
  28. public class ExtendedActionContext {
  29.  
  30. private static ThreadLocal<ExtendedActionContext> contextHolder = new ThreadLocal<ExtendedActionContext>();
  31.  
  32. @SuppressWarnings("rawtypes")
  33. private final Map<Class<? extends IBaseType>, Map<String, IBaseType>> entities;
  34.  
  35. @SuppressWarnings("rawtypes")
  36. private ExtendedActionContext() {
  37. this.entities = new HashMap<Class<? extends IBaseType>, Map<String, IBaseType>>();
  38. }
  39.  
  40. public static void createContext() {
  41. contextHolder.set(new ExtendedActionContext());
  42. }
  43.  
  44. public static void releaseContext() {
  45. contextHolder.remove();
  46. }
  47.  
  48. public static ExtendedActionContext getContext() {
  49. return contextHolder.get();
  50. }
  51.  
  52. @SuppressWarnings("rawtypes")
  53. public <T extends IBaseType> ExtendedActionContext put(final String key, final Class<T> type, final T object) {
  54. if (this.entities.get(type) == null) {
  55. this.entities.put(type, new HashMap<String, IBaseType>());
  56. }
  57. Map<String, IBaseType> objects = this.entities.get(type);
  58. objects.put(key, object);
  59. return this;
  60. }
  61.  
  62. @SuppressWarnings({ "rawtypes", "unchecked" })
  63. public <T extends IBaseType> T get(final String key, final Class<T> type) {
  64. if (this.entities.get(type) != null) {
  65. return (T) this.entities.get(type).get(key);
  66. }
  67. return null;
  68. }
  69. }
Add Comment
Please, Sign In to add comment