KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > java > plugin > registry > xml > PluginPrerequisiteImpl


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2004-2006 Dmitry Olshansky
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *****************************************************************************/

19 package org.java.plugin.registry.xml;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.java.plugin.registry.Documentation;
24 import org.java.plugin.registry.ManifestProcessingException;
25 import org.java.plugin.registry.PluginDescriptor;
26 import org.java.plugin.registry.PluginFragment;
27 import org.java.plugin.registry.PluginPrerequisite;
28 import org.java.plugin.registry.Version;
29
30 /**
31  * @version $Id: PluginPrerequisiteImpl.java,v 1.7 2006/06/05 18:16:43 ddimon Exp $
32  */

33 class PluginPrerequisiteImpl implements PluginPrerequisite {
34     private static Log log = LogFactory.getLog(PluginPrerequisiteImpl.class);
35
36     static boolean matches(final Version source, final Version target,
37             final String JavaDoc match) {
38         if (source == null) {
39             return true;
40         }
41         if (MATCH_EQUAL.equals(match)) {
42             return target.equals(source);
43         } else if (MATCH_EQUIVALENT.equals(match)) {
44             return target.isEquivalentTo(source);
45         } else if (MATCH_COMPATIBLE.equals(match)) {
46             return target.isCompatibleWith(source);
47         } else if (MATCH_GREATER_OR_EQUAL.equals(match)) {
48             return target.isGreaterOrEqualTo(source);
49         }
50         return target.isCompatibleWith(source);
51     }
52     
53     private final PluginDescriptorImpl descriptor;
54     private final PluginFragmentImpl fragment;
55     private final ModelPrerequisite model;
56     private DocumentationImpl doc;
57     
58     PluginPrerequisiteImpl(final PluginDescriptorImpl descr,
59             final PluginFragmentImpl aFragment, final ModelPrerequisite aModel)
60             throws ManifestProcessingException {
61         super();
62         descriptor = descr;
63         fragment = aFragment;
64         model = aModel;
65         if ((model.getPluginId() == null)
66                 || (model.getPluginId().trim().length() == 0)) {
67             throw new ManifestProcessingException(
68                     PluginRegistryImpl.PACKAGE_NAME,
69                     "prerequisitePliginIdIsBlank", descr.getId()); //$NON-NLS-1$
70
}
71         if (descr.getId().equals(model.getPluginId())) {
72             throw new ManifestProcessingException(
73                     PluginRegistryImpl.PACKAGE_NAME,
74                     "invalidPrerequisitePluginId", descr.getId()); //$NON-NLS-1$
75
}
76         if ((model.getId() == null) || (model.getId().trim().length() == 0)) {
77             model.setId("prerequisite:" + model.getPluginId()); //$NON-NLS-1$
78
}
79         if (model.getDocumentation() != null) {
80             doc = new DocumentationImpl(this, model.getDocumentation());
81         }
82         if (log.isDebugEnabled()) {
83             log.debug("object instantiated: " + this); //$NON-NLS-1$
84
}
85     }
86
87     /**
88      * @see org.java.plugin.registry.PluginPrerequisite#getPluginId()
89      */

90     public String JavaDoc getPluginId() {
91         return model.getPluginId();
92     }
93
94     /**
95      * @see org.java.plugin.registry.PluginPrerequisite#getPluginVersion()
96      */

97     public Version getPluginVersion() {
98         return model.getPluginVersion();
99     }
100
101     /**
102      * @see org.java.plugin.registry.PluginPrerequisite#getDeclaringPluginDescriptor()
103      */

104     public PluginDescriptor getDeclaringPluginDescriptor() {
105         return descriptor;
106     }
107
108     /**
109      * @see org.java.plugin.registry.PluginPrerequisite#getDeclaringPluginFragment()
110      */

111     public PluginFragment getDeclaringPluginFragment() {
112         return fragment;
113     }
114
115     /**
116      * @see org.java.plugin.registry.PluginPrerequisite#isOptional()
117      */

118     public boolean isOptional() {
119         return model.isOptional();
120     }
121     
122     /**
123      * @see org.java.plugin.registry.PluginPrerequisite#isReverseLookup()
124      */

125     public boolean isReverseLookup() {
126         return model.isReverseLookup();
127     }
128
129     /**
130      * @see org.java.plugin.registry.PluginPrerequisite#matches()
131      */

132     public boolean matches() {
133         PluginDescriptor descr = null;
134         try {
135             descr = this.descriptor.getRegistry().getPluginDescriptor(
136                     model.getPluginId());
137         } catch (IllegalArgumentException JavaDoc iae) {
138             return false;
139         }
140         return matches(model.getPluginVersion(), descr.getVersion(),
141                 model.getMatch());
142     }
143
144     /**
145      * @see org.java.plugin.registry.PluginPrerequisite#getMatch()
146      */

147     public String JavaDoc getMatch() {
148         return model.getMatch();
149     }
150
151     /**
152      * @see org.java.plugin.registry.PluginPrerequisite#isExported()
153      */

154     public boolean isExported() {
155         return model.isExported();
156     }
157
158     /**
159      * @see org.java.plugin.registry.Identity#getId()
160      */

161     public String JavaDoc getId() {
162         return model.getId();
163     }
164     
165     /**
166      * @see org.java.plugin.registry.Documentable#getDocsPath()
167      */

168     public String JavaDoc getDocsPath() {
169         return (fragment != null) ? fragment.getDocsPath()
170                 : descriptor.getDocsPath();
171     }
172     
173     /**
174      * @see org.java.plugin.registry.Documentable#getDocumentation()
175      */

176     public Documentation getDocumentation() {
177         return doc;
178     }
179
180     /**
181      * @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
182      */

183     public String JavaDoc getUniqueId() {
184         return descriptor.getRegistry().makeUniqueId(descriptor.getId(),
185                 getId());
186     }
187     
188     /**
189      * @see java.lang.Object#toString()
190      */

191     public String JavaDoc toString() {
192         return "{Prerequisite: uid=" + getUniqueId() + "}"; //$NON-NLS-1$ //$NON-NLS-2$
193
}
194 }
195
Popular Tags