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.businessobjects.environment;
16
17 import org.figure8.join.core.EntityObject;
18
19 import java.util.List;
20 import java.util.ArrayList;
21 /**
22 * This is the representation of a physical environment managed by Join.
23 * <br/>
24 * A PhysicalEnvironment has no knowledge of the integration process step
25 * and release for whom it is used. Is defines a purely technical place which
26 * is composed of infrastructure elements or resources (services, versioned
27 * resources and gateways) hosted on many machines.
28 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
29 * @version $Revision: 1.1 $
30 *
31 * @see org.figure8.join.businessobjects.environment.Machine
32 * @see org.figure8.join.businessobjects.environment.Resource
33 *
34 * @hibernate.class table="join_physicalenvs" lazy="true"
35 * @hibernate.cache usage="read-write"
36 *
37 * @hibernate.query name="join.physicalenv_findByKey"
38 * query="from PhysicalEnvironment env where env.key = :envKey"
39 */
40 public class PhysicalEnvironment extends EntityObject{
41
42
43
44 /** This physical environment key */
45 private String key;
46 /** This physical environment name */
47 private String name;
48 /** The list of active environment mappings (should be only one) */
49 private List activeMappings = new ArrayList();
50 /** The list of active resource mappings (many resources bound at same time) */
51 private List activeResourceMappings = new ArrayList();
52
53
54
55
56 /** Creates a new instance of PhysicalEnvironment. */
57 public PhysicalEnvironment(){
58 }
59
60 /**
61 * Creates a new instance of PhysicalEnvironment with mandatory attributes.
62 * @param key The key of this environment
63 * @param name The display name for this environment
64 */
65 public PhysicalEnvironment(String key, String name){
66 this.key = key;
67 this.name = name;
68 }
69
70
71
72
73 /**
74 * @hibernate.property column="s_key"
75 * not-null="true" unique="true"
76 * update="false" length="10"
77 * @return This environment unique key
78 */
79 public String getKey(){
80 return key;
81 }
82 /** @param key This environment unique key */
83 public void setKey(String key){
84 this.key = key;
85 }
86
87 /**
88 * @hibernate.property column="s_name"
89 * not-null="true" unique="true"
90 * length="40"
91 * @return This environment distinct name
92 */
93 public String getName(){
94 return name;
95 }
96 /** @param name This environment display name */
97 public void setName(String name){
98 this.name = name;
99 }
100
101 /**
102 * @hibernate.bag cascade="save-update" lazy="true" inverse="true"
103 * where="d_end is null" order-by="d_start desc"
104 * @hibernate.collection-key column="n_physicalenv_fk"
105 * @hibernate.collection-one-to-many class="org.figure8.join.businessobjects.environment.EnvironmentMapping"
106 * @return A set of {@code EnvironmentMapping}s that are active now
107 */
108 public List getActiveEnvironmentMappings(){
109 return activeMappings;
110 }
111 /** @param mappings The set of {@code EnvironmentMapping}s that are active now */
112 public void setActiveEnvironmentMappings(List mappings){
113 this.activeMappings = mappings;
114 }
115
116 /**
117 * Get the most recent active EnvironmentMapping for this environment
118 * @return The last mapping that has been created
119 */
120 public EnvironmentMapping getActiveEnvironmentMapping(){
121
122 List actives = getActiveEnvironmentMappings();
123 if (actives.isEmpty()) return null;
124
125 return (EnvironmentMapping)actives.get(0);
126 }
127 /** @param mapping The EnvironmentMapping to set as active one */
128 public void setActiveEnvironmentMapping(EnvironmentMapping mapping){
129 closeActiveEnvironmentMappings();
130 activeMappings.add(mapping);
131 }
132
133 /**
134 * @hibernate.bag cascade="save-update" lazy="true" inverse="true"
135 * where="d_end is null" order-by="d_start desc"
136 * @hibernate.collection-key column="n_physicalenv_fk"
137 * @hibernate.collection-one-to-many class="org.figure8.join.businessobjects.environment.ResourceMapping"
138 * @return A set of {@code ResourceMapping}s that are active now
139 */
140 public List getActiveResourceMappings(){
141 return activeResourceMappings;
142 }
143 /** @param mappings The set of {@code ResourceMapping}s that are active now */
144 public void setActiveResourceMappings(List mappings){
145 this.activeResourceMappings = mappings;
146 }
147
148 /**
149 * Convenient method for adding a mapped resource into mapping list
150 * This method closes the previously existing mapping for this kind of resource.
151 * @param mapping The mapping to an infratructure resource to add
152 */
153 public void addActiveResourceMapping(ResourceMapping mapping){
154 closeActiveResourceMapping(mapping.getResource().getResourceType());
155 activeResourceMappings.add(mapping);
156 }
157
158
159
160
161 /** Close the currently active environment mappings */
162 private void closeActiveEnvironmentMappings(){
163
164 for (int i=0; i<activeMappings.size(); i++){
165 EnvironmentMapping mapping = (EnvironmentMapping)activeMappings.get(i);
166 mapping.close();
167 }
168 }
169
170 /** Close the active resource mappings for this kind of resource type */
171 private void closeActiveResourceMapping(ResourceType type){
172
173 for (int i=0; i<activeResourceMappings.size(); i++){
174 ResourceMapping mapping = (ResourceMapping)activeResourceMappings.get(i);
175 if (mapping.getResource().getResourceType().equals(type))
176 mapping.close();
177 }
178 }
179 }