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.businessobjects.environment;
16  
17  import org.figure8.join.core.EntityObject;
18  
19  import java.util.List;
20  import java.util.ArrayList;
21  /**
22   * Helper class for implementing persistent Resources.
23   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
24   * @version $Revision: 1.3 $
25   *
26   * @hibernate.class table="join_resources"
27   * @hibernate.discriminator column="resource_category" type="string" not-null="true"
28   * @hibernate.cache usage="read-write"
29   *
30   * @hibernate.query name="join.resource_findByType"
31   *    query="from AbstractResource res where res.resourceType = :resType"
32   * @hibernate.query name="join.resource_findByName"
33   *    query="from AbstractResource res left join fetch res.resourceType where res.name = :resName"
34   */
35  public abstract class AbstractResource extends EntityObject implements Resource{
36  
37     // Attributes ---------------------------------------------------------------
38  
39     /** This resource name (must be unique) */
40     private String name;
41     /** The path to the log directory of this resource */
42     private String logDirPath;
43     /** The path to the current log file of this resource */
44     private String logFilePath;
45     /** A list of <code>ResourceMapping</code> objects that are currently valid */
46     private List currentMappings = new ArrayList();
47     
48     /** The physical machine hosting this resource */
49     private Machine machine;
50     /** The type of this resource (this impl uses {@link AbstractResourceType} impl) */
51     private AbstractResourceType resourceType;
52  
53  
54     // Constructors -------------------------------------------------------------
55  
56     /** Creates a new instance of AbstractResource */
57     public AbstractResource(){
58     }
59  
60     /**
61      * Creates a new instance of AbstractResource with mandatory attribute
62      * @param name This resource name (must be unique)
63      * @param resourceType The type of the resource to create
64      */
65     public AbstractResource(String name, AbstractResourceType resourceType){
66        this.name = name;
67        this.resourceType = resourceType;
68     }
69  
70  
71     // Public -------------------------------------------------------------------
72  
73     /** @param name This resource unique name */
74     public void setName(String name){
75        this.name = name;
76     }
77  
78     /** @param logDirPath The path to directory where this resource stores log files */
79     public void setLogDirPath(String logDirPath){
80        this.logDirPath = logDirPath;
81     }
82  
83      /** @param logFilePath The path to the current log file for this resource */
84     public void setLogFilePath(String logFilePath){
85        this.logFilePath = logFilePath;
86     }
87  
88     /** @param machine The physical machine hosting this resource */
89     public void setMachine(Machine machine){
90        this.machine = machine;
91     }
92  
93     /** @param resourceType The type of this resource */
94     public void setResourceType(AbstractResourceType resourceType){
95        this.resourceType = resourceType;
96     }
97  
98     /**
99      * @hibernate.bag cascade="save-update" lazy="true" where="d_end is null"
100     * @hibernate.collection-key column="n_resource_fk"
101     * @hibernate.collection-one-to-many class="org.figure8.join.businessobjects.environment.ResourceMapping"
102     * @return A list of <code>ResourceMapping</code> objects that are currently valid
103     */
104    public List getCurrentMappings(){
105       return currentMappings;
106    }
107    /** @param mappings The list of <code>ResourceMapping</code> objects that are currently valid */
108    public void setCurrentMappings(List mappings){
109       this.currentMappings = mappings;
110    }
111 
112    /**
113     * Return the category information on this resource. Should
114     * be implemented in a static way by resource subclasses.
115     * @return The category information as character string
116     */
117    public abstract String getCategory();
118 
119 
120    // Implementation of Resource -----------------------------------------------
121 
122    /**
123     * @hibernate.property column="s_name"
124     *    not-null="true" unique="true"
125     *    length="40"
126     * @return This resource unique name */
127    public String getName(){
128       return name;
129    }
130 
131    /**
132     * @hibernate.property column="s_logdir" length="200"
133     * @return The path to directory where this resource stores log files
134     */
135    public String getLogDirPath(){
136       return logDirPath;
137    }
138 
139    /**
140     * @hibernate.property column="s_logfile" length="200"
141     * @return The path to current log file for this resource
142     */
143    public String getLogFilePath(){
144       return logFilePath;
145    }
146 
147    /**
148     * @hibernate.many-to-one column="n_machine_fk"
149     * @return The physical machine hosting this resource (if any)
150     */
151    public Machine getMachine(){
152       return machine;
153    }
154 
155    /**
156     * @hibernate.many-to-one column="n_type_fk"
157     *    not-null="true" outer-join="true"
158     *    class="org.figure8.join.businessobjects.environment.AbstractResourceType"
159     * @return The type of this resource
160     */
161    public ResourceType getResourceType(){
162       return resourceType;
163    }
164    
165    /** @return The physical environments that are using this resource */
166    public List getPhysicalEnvironments(){
167       // Extract physical environments from current mappings.
168       List result = new ArrayList(currentMappings.size());
169       for (int i=0; i<currentMappings.size(); i++){
170          ResourceMapping mapping = (ResourceMapping)currentMappings.get(i);
171          result.add(i, mapping);
172       }
173       return result;
174    }
175 }