Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/dghda/module/Module.java


1   /* Copyright (C) 2001 Duane Griffin <duanegriffin@users.sourceforge.net>
2      This file is part of Kent.
3   
4      Kent is free software; you can redistribute it and/or
5      modify it under the terms of the GNU General Public License as
6      published by the Free Software Foundation; either version 2 of the
7      License, or (at your option) any later version.
8   
9      Kent is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     General Public License for more details.
13  
14     You should have received a copy of the GNU General Public
15     License along with Kent; see the file COPYING.  If not,
16     write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17     Boston, MA 02111-1307, USA.
18  */
19  
20  package com.dghda.module;
21  
22  /**
23     A loadable module.
24     
25     The module's version information is implicitly included in the 
26     configuration settings. The property names containing the settings 
27     are given in the ModuleVersion class.
28  */
29  public interface Module {
30    
31    /** A class which encapsulates a module's version information. */
32    final public class ModuleVersion implements Comparable {
33      
34      /** The name of the property containing the module's major version number. */
35      static final public String VERSION_MAJOR = "version.major";
36      
37      /** The name of the property containing the module's minor version number. */
38      static final public String VERSION_MINOR = "version.minor";
39      
40      /** The name of the property containing the module's author. */
41      static final public String VERSION_AUTHOR = "version.author";
42      
43      /** Constructs a new version object. */
44      public ModuleVersion (int maj, int min, String aut) {
45        major = maj;
46        minor = min;
47        author = aut;
48      }
49      
50      /**
51         Checks two versions for equality.
52         The author is ignored in checking for equality.
53      */
54      public boolean equals (Object obj) {
55        if (obj instanceof ModuleVersion)
56          return (compareTo (obj) == 0);
57        else
58          return false;
59      }
60      
61      /**
62         Compares two versions.
63         Only the version numbers are taken into account when comparing versions.
64      */
65      public int compareTo (Object obj) {
66        ModuleVersion version = (ModuleVersion) obj;
67        if (major > version.major) {
68          return 1;
69        } else if (major < version.major) {
70          return -1;
71        } else {
72          if (minor > version.minor)
73            return 1;
74          else if (minor < version.minor)
75            return -1;
76          else
77            return 0;
78        }
79      }
80      
81      /** The major version number. */
82      public int major;
83      
84      /** The minor version number. */
85      public int minor;
86      
87      /** The module's author. */
88      public String author;
89      
90      /**
91         Sets the version properties in the given properties object.
92         @param id The ID of the module.
93         @param config The properties to set the version configuration in.
94      */
95      public void setProperties (String id, java.util.Properties config) {
96        config.setProperty (id + "." + VERSION_MAJOR, Integer.toString (major));
97        config.setProperty (id + "." + VERSION_MINOR, Integer.toString (minor));
98        config.setProperty (id + "." + VERSION_AUTHOR, author);
99      }
100     
101     public String toString() {
102       StringBuffer buffer = new StringBuffer();
103       buffer.append (major);
104       buffer.append ('.');
105       buffer.append (minor);
106       buffer.append (" (");
107       buffer.append (author);
108       buffer.append (')');
109       return buffer.toString();
110     }
111   }
112   
113   /**
114      Returns the ID of the module.
115      This ID should be globally unique.
116   */
117   public String getID();
118   
119   /**
120      Returns the name of the module.
121      This name should be suitable for display.
122   */
123   public String getName();
124   
125   /** Returns version information about the module. */
126   public ModuleVersion getVersion();
127   
128   /** Returns a description of the module. */
129   public String getDescription();
130 }