KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > TR > Impl > ComponentInfoImpl


1 /**
2  * ComponentInfoImpl.java is a part of the SOFA project.
3  * This file was created by pepan on 19.3.2003.
4  */

5 package SOFA.SOFAnode.TR.Impl;
6
7 import java.io.Serializable JavaDoc;
8
9 import SOFA.SOFAnode.TR.ComponentInfo;
10
11 /**
12  * Describes one component. It contains all attributes a component can have.
13  * However, the current implementation does not use them all.
14  * @author Petr Panuska
15  */

16 public class ComponentInfoImpl implements ComponentInfo, Serializable JavaDoc {
17
18   /**
19    * The component name. Usually, it consists of a few strings delimited by '::'.
20    * The first ones define the vendor, the other specify the name hierarchy.
21    */

22   private String JavaDoc name;
23
24   /**
25    * The specification version of the component interface. It is not used in the current
26    * implementation.
27    */

28   private String JavaDoc specificationVersion;
29
30   /**
31    * The implementation version of the component interface provided by a single vendor.
32    */

33   private String JavaDoc implementationVersion;
34
35   /**
36    * The location where this component can be obtained from. It could be either
37    * an absolute URL beginning with 'sofa://' prefix and pointing to a SOFA node, or
38    * a relative path to a directory within a bundle. The latter case is used when
39    * the component is being sent packed in a bundle only.
40    */

41   private String JavaDoc location;
42
43   /**
44    * List of sub-components, this component consists of. It is not used in the current
45    * implementation.
46    */

47   private ComponentInfo[] subComponents;
48
49   /**
50    * Creates a component info where just 2 fields are known.
51    * @param name the component name.
52    * @param implementationVersion the component implementation version.
53    */

54   public ComponentInfoImpl (String JavaDoc name, String JavaDoc implementationVersion) {
55     this.name = name;
56     this.implementationVersion = implementationVersion;
57   }
58
59   /**
60    * Creates a component info where 3 fields are known.
61    * @param name the component name.
62    * @param implementationVersion the component implementation version.
63    * @param location the location where this component can be obtained from.
64    */

65   public ComponentInfoImpl (String JavaDoc name, String JavaDoc implementationVersion, String JavaDoc location) {
66     this(name, implementationVersion);
67     this.location = location;
68   }
69
70   /**
71    * Gets the component name.
72    * @return the component name.
73    */

74   public String JavaDoc getName () {
75     return name;
76   }
77
78   /**
79    * Gets the component specification version.
80    * @return the specification version.
81    */

82   public String JavaDoc getSpecificationVersion () {
83     return specificationVersion;
84   }
85
86   /**
87    * Gets the component implementation version.
88    * @return the implementation version.
89    */

90   public String JavaDoc getImplementationVersion () {
91     return implementationVersion;
92   }
93
94   /**
95    * Gets the location where this componenta can be obtained from.
96    * @return the location of this component.
97    */

98   public String JavaDoc getLocation () {
99     return location;
100   }
101
102   /**
103    * Gets components this component consists of.
104    * @return an array of components.
105    */

106   public ComponentInfo[] getSubComponents () {
107     return subComponents;
108   }
109
110   /**
111    * Sets the location where this component can be obtained from.
112    * @param location an absolute URL beginning with the 'sofa://' prefix, a relative
113    * path to a directory within a bundle otherwise.
114    */

115   void setLocation (String JavaDoc location) {
116     this.location = location;
117   }
118
119   void setSubComponents (ComponentInfoImpl[] subComponents) {
120     this.subComponents = subComponents;
121   }
122
123   /**
124    * Compares this component info with the specified one. Two instances of this class
125    * equal if their names and implementation versions are the same.
126    * @param o the second component info.
127    * @return <code>true</code> if both instances equal.
128    */

129   public boolean equals (Object JavaDoc o) {
130     if (this == o) return true;
131     if (!(o instanceof ComponentInfoImpl)) return false;
132
133     final ComponentInfoImpl componentInfo = (ComponentInfoImpl) o;
134
135     if (!implementationVersion.equals(componentInfo.implementationVersion)) return false;
136     if (!name.equals(componentInfo.name)) return false;
137
138     return true;
139   }
140
141   public int hashCode () {
142     int result;
143     result = name.hashCode();
144     result = 29 * result + implementationVersion.hashCode();
145     return result;
146   }
147
148   /**
149    * Returns a string of following format XXX[YYY]. XXX denotes the component name;
150    * YYY denotes the component implementation version.
151    * @return the describing string.
152    */

153   public String JavaDoc toString () {
154     return name + "[" + implementationVersion + "]";
155   }
156
157   /**
158    * Creates the component info from a string returned by the {@link #toString} method.
159    * Only the name and the implementation version are filled in the created instance.
160    * @param fullName a string consisting of XXX[YYY], where XXX denotes the name and
161    * YYY denotes the implementation version.
162    * @return an instance of this class.
163    */

164   public static ComponentInfoImpl fromString (String JavaDoc fullName) {
165     int delimiter = fullName.lastIndexOf('[');
166     String JavaDoc name = fullName.substring(0, delimiter);
167     String JavaDoc version = fullName.substring(delimiter + 1, fullName.length() - 1);
168     return new ComponentInfoImpl(name, version);
169   }
170 }
171
Popular Tags