View Javadoc

1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.view;
16  
17  import org.figure8.join.businessobjects.environment.ResourceMapping;
18  import org.figure8.join.businessobjects.environment.PhysicalEnvironment;
19  
20  import java.util.Map;
21  import java.util.Date;
22  import java.util.List;
23  import java.util.HashMap;
24  import java.util.ArrayList;
25  import java.io.Serializable;
26  /**
27   * This a JavaBean encasulating a PhysicalEnvironment domain model object
28   * and its information on resource mappings done during a tracking period.
29   * Instance of <code>PhysicalEnvironmentTrackingView</code> class are intended
30   * to be stored within an Http layer context.
31   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
32   * @version $Revision: 1.2 $
33   */
34  public class PhysicalEnvironmentTrackingView implements Serializable{
35  
36     // Attributes ---------------------------------------------------------------
37  
38     /** The start date of the tracking period for PhysicalEnvironment changes */
39     protected Date startDate;
40     /** The end date of the tracking period for PhysicalEnvironment changes */
41     protected Date endDate;
42     /** The encapsulated environment domain object */
43     protected PhysicalEnvironment environment = null;
44  
45     /** A map of mappings done during tracking period, organized on resource type */
46     protected Map resourceMappings = new HashMap();
47     /** A map of mappings for versioned resources done during transking period */
48     protected Map versionedResourceMappings = new HashMap();
49  
50  
51     // Constructors -------------------------------------------------------------
52  
53     /**
54      * Creates a new instance of PhysicalEnvironmentTrackingView
55      * @param environment The encapsulated environment domain object
56      * @param startDate The start date of the tracking period
57      * @param endDate The end date of the tracking period
58      */
59     public PhysicalEnvironmentTrackingView(PhysicalEnvironment environment, Date startDate, Date endDate){
60        this.environment = environment;
61        this.startDate = startDate;
62        this.endDate = endDate;
63     }
64  
65  
66     // Public -------------------------------------------------------------------
67  
68     /** @return The start date of the tracking period for PhysicalEnvironment changes */
69     public Date getStartDate(){
70        return startDate;
71     }
72     /** @return The end date of the tracking period for PhysicalEnvironment changes */
73     public Date getEndDate(){
74        return endDate;
75     }
76     /** @return The encapsulated environment domain object */
77     public PhysicalEnvironment getEnvironment(){
78        return environment;
79     }
80  
81     /**
82      * Get the resource mappings done during the tracking period
83      * @return A map where keys are the resource type and values are list of mappings for the type
84      */
85     public Map getResourceMappings(){
86        return resourceMappings;
87     }
88     /**
89      * Add a ResourceMapping to existing mappings for this tracking view
90      * @param mapping The resource mapping to add
91      */
92     public void addResourceMapping(ResourceMapping mapping){
93        // Retrieve mappings for this resource type.
94        List mappings = (List)resourceMappings.get(mapping.getResource().getResourceType());
95        // Add mapping to list of mappings.
96        if (mappings == null) mappings = new ArrayList();
97        mappings.add(mapping);
98        // Update the map of resource mappings.
99        resourceMappings.put(mapping.getResource().getResourceType(), mappings);
100    }
101 
102    /**
103     * Get the versioned resource mappings done during the tracking period
104     * @return A map where keys are the versioned resource type and values are list of mappings
105     */
106    public Map getVersionedResourceMappings(){
107       return versionedResourceMappings;
108    }
109    /**
110     * Add a VersionedResourceMapping to existing mappings for this tracking view
111     * @param mapping The versioned mapping to add
112     */
113    public void addVersionedResourceMapping(VersionedResourceMapping mapping){
114       // Retrieve mappings for this resource type.
115       List mappings = (List)versionedResourceMappings.get(mapping.getResourceView().getResource().getResourceType());
116       // Add mapping to list of mappings.
117       if (mappings == null) mappings = new ArrayList();
118       mappings.add(mapping);
119       // Update the map of versioned resource mappings.
120       versionedResourceMappings.put(mapping.getResourceView().getResource().getResourceType(), mappings);
121    }
122 }