/webportal/src/main/java/au/org/emii/portal/util/PortalSessionCloner.java

http://alageospatialportal.googlecode.com/ · Java · 80 lines · 34 code · 14 blank · 32 comment · 8 complexity · a6b06b465e2bfa0d9b3586690929e6b3 MD5 · raw file

  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package au.org.emii.portal.util;
  6. import au.org.emii.portal.value.BoundingBox;
  7. import au.org.emii.portal.menu.MapLayer;
  8. import au.org.emii.portal.session.PortalSession;
  9. import org.apache.log4j.Logger;
  10. /**
  11. *
  12. * @author geoff
  13. */
  14. public class PortalSessionCloner {
  15. private PortalSessionUtilities portalSessionUtilities = null;
  16. private Logger logger = Logger.getLogger(getClass());
  17. public PortalSessionUtilities getPortalSessionUtilities() {
  18. return portalSessionUtilities;
  19. }
  20. public void setPortalSessionUtilities(PortalSessionUtilities portalSessionUtilities) {
  21. this.portalSessionUtilities = portalSessionUtilities;
  22. }
  23. public PortalSession clone(PortalSession masterPortalSession) throws CloneNotSupportedException {
  24. PortalSession portalSession = (PortalSession) masterPortalSession.clone();
  25. /* super.clone will leave references to existing objects
  26. * in place, e.g. portalSession.mapLayers == mapLayers is
  27. * currently true - to fix this, we will re-init all these
  28. * fields now
  29. *
  30. * although we don't mind sharing these between users, they
  31. * have to be defined 'later' when we call clone() because
  32. * the config file has not yet been loaded if we try earlier
  33. */
  34. portalSession.reset();
  35. // step1: data sources and search catalogues
  36. // maplayers
  37. if (masterPortalSession.getMapLayers() != null) {
  38. for (MapLayer mapLayer : masterPortalSession.getMapLayers()) {
  39. portalSession.addMapLayer((MapLayer) mapLayer.clone());
  40. }
  41. }
  42. // step 2: copy regions/facilities and settings
  43. // default map bounding box
  44. if (masterPortalSession.getDefaultBoundingBox() == null) {
  45. portalSession.setDefaultBoundingbox((BoundingBox) masterPortalSession.getDefaultBoundingBox().clone());
  46. }
  47. // step 4: clone active layers
  48. if (masterPortalSession.getActiveLayers() != null) {
  49. for (MapLayer mapLayer : masterPortalSession.getActiveLayers()) {
  50. portalSession.getActiveLayers().add((MapLayer) mapLayer.clone());
  51. }
  52. }
  53. /* step 5: skip things
  54. *
  55. * o userDefined
  56. * o UserDefinedMenu
  57. * All get skipped because for new sessions they should
  58. * all be empty lists/objects
  59. */
  60. /* step 6: create an initial user defined menu tree - isn't done on creating
  61. * during stage 2 because otherwise we would have to bother cloning everything
  62. */
  63. logger.debug("Session cloned as: " + portalSessionUtilities.dump(portalSession));
  64. return portalSession;
  65. }
  66. }