PageRenderTime 18ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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