KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2004-2007 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 java.net.URL JavaDoc;
22
23 import org.java.plugin.registry.Documentation;
24 import org.java.plugin.registry.Identity;
25 import org.java.plugin.registry.ManifestProcessingException;
26 import org.java.plugin.registry.PluginDescriptor;
27 import org.java.plugin.registry.PluginFragment;
28 import org.java.plugin.registry.PluginRegistry;
29 import org.java.plugin.registry.Version;
30
31 /**
32  * @version $Id: PluginFragmentImpl.java,v 1.6 2007/01/05 13:32:08 ddimon Exp $
33  */

34 class PluginFragmentImpl extends IdentityImpl implements PluginFragment {
35     private final PluginRegistry registry;
36     private final URL JavaDoc location;
37     private final ModelPluginFragment model;
38     private Documentation doc;
39
40     PluginFragmentImpl(final PluginRegistry aRegistry,
41             final ModelPluginFragment aModel, final URL JavaDoc aLocation)
42             throws ManifestProcessingException {
43         super(aModel.getId());
44         registry = aRegistry;
45         model = aModel;
46         location = aLocation;
47         if (model.getVendor() == null) {
48             model.setVendor(""); //$NON-NLS-1$
49
}
50         if ((model.getPluginId() == null)
51                 || (model.getPluginId().trim().length() == 0)) {
52             throw new ManifestProcessingException(
53                     PluginRegistryImpl.PACKAGE_NAME,
54                     "fragmentPliginIdIsBlank", getId()); //$NON-NLS-1$
55
}
56         if (getId().equals(model.getPluginId())) {
57             throw new ManifestProcessingException(
58                     PluginRegistryImpl.PACKAGE_NAME,
59                     "invalidFragmentPluginId", getId()); //$NON-NLS-1$
60
}
61         if ((model.getDocsPath() == null)
62                 || (model.getDocsPath().trim().length() == 0)) {
63             model.setDocsPath("docs"); //$NON-NLS-1$
64
}
65         if (model.getDocumentation() != null) {
66             doc = new DocumentationImpl(this, model.getDocumentation());
67         }
68         if (log.isDebugEnabled()) {
69             log.debug("object instantiated: " + this); //$NON-NLS-1$
70
}
71     }
72     
73     ModelPluginFragment getModel() {
74         return model;
75     }
76
77     /**
78      * @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
79      */

80     public String JavaDoc getUniqueId() {
81         return registry.makeUniqueId(getId(), model.getVersion());
82     }
83
84     /**
85      * @see org.java.plugin.registry.PluginFragment#getVendor()
86      */

87     public String JavaDoc getVendor() {
88         return model.getVendor();
89     }
90
91     /**
92      * @see org.java.plugin.registry.PluginFragment#getVersion()
93      */

94     public Version getVersion() {
95         return model.getVersion();
96     }
97
98     /**
99      * @see org.java.plugin.registry.PluginFragment#getPluginId()
100      */

101     public String JavaDoc getPluginId() {
102         return model.getPluginId();
103     }
104
105     /**
106      * @see org.java.plugin.registry.PluginFragment#getPluginVersion()
107      */

108     public Version getPluginVersion() {
109         return model.getPluginVersion();
110     }
111
112     /**
113      * @see org.java.plugin.registry.PluginFragment#getRegistry()
114      */

115     public PluginRegistry getRegistry() {
116         return registry;
117     }
118
119     /**
120      * @see org.java.plugin.registry.PluginFragment#matches(
121      * org.java.plugin.registry.PluginDescriptor)
122      */

123     public boolean matches(final PluginDescriptor descr) {
124         return PluginPrerequisiteImpl.matches(model.getPluginVersion(),
125                 descr.getVersion(), model.getMatch());
126     }
127
128     /**
129      * @see org.java.plugin.registry.Documentable#getDocumentation()
130      */

131     public Documentation getDocumentation() {
132         return doc;
133     }
134
135     /**
136      * @see org.java.plugin.registry.PluginFragment#getDocsPath()
137      */

138     public String JavaDoc getDocsPath() {
139         return model.getDocsPath();
140     }
141
142     /**
143      * @see org.java.plugin.registry.PluginFragment#getLocation()
144      */

145     public URL JavaDoc getLocation() {
146         return location;
147     }
148
149     /**
150      * @see org.java.plugin.registry.xml.IdentityImpl#isEqualTo(
151      * org.java.plugin.registry.Identity)
152      */

153     protected boolean isEqualTo(final Identity idt) {
154         if (!(idt instanceof PluginFragmentImpl)) {
155             return false;
156         }
157         PluginFragmentImpl other = (PluginFragmentImpl) idt;
158         return getUniqueId().equals(other.getUniqueId())
159             && getLocation().toExternalForm().equals(
160                     other.getLocation().toExternalForm());
161     }
162
163     /**
164      * @see java.lang.Object#toString()
165      */

166     public String JavaDoc toString() {
167         return "{PluginFragment: uid=" + getUniqueId() + "}"; //$NON-NLS-1$ //$NON-NLS-2$
168
}
169 }
170
Popular Tags