001: /*****************************************************************************
002: * Java Plug-in Framework (JPF)
003: * Copyright (C) 2004-2007 Dmitry Olshansky
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *****************************************************************************/package org.java.plugin.registry.xml;
019:
020: import java.net.URL;
021:
022: import org.java.plugin.registry.Documentation;
023: import org.java.plugin.registry.Identity;
024: import org.java.plugin.registry.ManifestProcessingException;
025: import org.java.plugin.registry.MatchingRule;
026: import org.java.plugin.registry.PluginDescriptor;
027: import org.java.plugin.registry.PluginFragment;
028: import org.java.plugin.registry.PluginRegistry;
029: import org.java.plugin.registry.Version;
030:
031: /**
032: * @version $Id: PluginFragmentImpl.java,v 1.4 2007/03/03 17:16:26 ddimon Exp $
033: */
034: class PluginFragmentImpl extends IdentityImpl implements PluginFragment {
035: private final PluginRegistry registry;
036: private final ModelPluginFragment model;
037: private Documentation<PluginFragment> doc;
038:
039: PluginFragmentImpl(final PluginRegistry aRegistry,
040: final ModelPluginFragment aModel)
041: throws ManifestProcessingException {
042: super (aModel.getId());
043: registry = aRegistry;
044: model = aModel;
045: if (model.getVendor() == null) {
046: model.setVendor(""); //$NON-NLS-1$
047: }
048: if ((model.getPluginId() == null)
049: || (model.getPluginId().trim().length() == 0)) {
050: throw new ManifestProcessingException(
051: PluginRegistryImpl.PACKAGE_NAME,
052: "fragmentPliginIdIsBlank", getId()); //$NON-NLS-1$
053: }
054: if (getId().equals(model.getPluginId())) {
055: throw new ManifestProcessingException(
056: PluginRegistryImpl.PACKAGE_NAME,
057: "invalidFragmentPluginId", getId()); //$NON-NLS-1$
058: }
059: if ((model.getDocsPath() == null)
060: || (model.getDocsPath().trim().length() == 0)) {
061: model.setDocsPath("docs"); //$NON-NLS-1$
062: }
063: if (model.getDocumentation() != null) {
064: doc = new DocumentationImpl<PluginFragment>(this , model
065: .getDocumentation());
066: }
067: if (log.isDebugEnabled()) {
068: log.debug("object instantiated: " + this ); //$NON-NLS-1$
069: }
070: }
071:
072: ModelPluginFragment getModel() {
073: return model;
074: }
075:
076: /**
077: * @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
078: */
079: public String getUniqueId() {
080: return registry.makeUniqueId(getId(), model.getVersion());
081: }
082:
083: /**
084: * @see org.java.plugin.registry.PluginFragment#getVendor()
085: */
086: public String getVendor() {
087: return model.getVendor();
088: }
089:
090: /**
091: * @see org.java.plugin.registry.PluginFragment#getVersion()
092: */
093: public Version getVersion() {
094: return model.getVersion();
095: }
096:
097: /**
098: * @see org.java.plugin.registry.PluginFragment#getPluginId()
099: */
100: public String getPluginId() {
101: return model.getPluginId();
102: }
103:
104: /**
105: * @see org.java.plugin.registry.PluginFragment#getPluginVersion()
106: */
107: public Version getPluginVersion() {
108: return model.getPluginVersion();
109: }
110:
111: /**
112: * @see org.java.plugin.registry.PluginFragment#getRegistry()
113: */
114: public PluginRegistry getRegistry() {
115: return registry;
116: }
117:
118: /**
119: * @see org.java.plugin.registry.PluginFragment#matches(
120: * org.java.plugin.registry.PluginDescriptor)
121: */
122: public boolean matches(final PluginDescriptor descr) {
123: return PluginPrerequisiteImpl.matches(model.getPluginVersion(),
124: descr.getVersion(), model.getMatchingRule());
125: }
126:
127: /**
128: * @see org.java.plugin.registry.PluginFragment#getMatchingRule()
129: */
130: public MatchingRule getMatchingRule() {
131: return model.getMatchingRule();
132: }
133:
134: /**
135: * @see org.java.plugin.registry.Documentable#getDocumentation()
136: */
137: public Documentation<PluginFragment> getDocumentation() {
138: return doc;
139: }
140:
141: /**
142: * @see org.java.plugin.registry.PluginFragment#getDocsPath()
143: */
144: public String getDocsPath() {
145: return model.getDocsPath();
146: }
147:
148: /**
149: * @see org.java.plugin.registry.PluginFragment#getLocation()
150: */
151: public URL getLocation() {
152: return model.getLocation();
153: }
154:
155: /**
156: * @see org.java.plugin.registry.xml.IdentityImpl#isEqualTo(
157: * org.java.plugin.registry.Identity)
158: */
159: @Override
160: protected boolean isEqualTo(final Identity idt) {
161: if (!(idt instanceof PluginFragmentImpl)) {
162: return false;
163: }
164: PluginFragmentImpl other = (PluginFragmentImpl) idt;
165: return getUniqueId().equals(other.getUniqueId())
166: && getLocation().toExternalForm().equals(
167: other.getLocation().toExternalForm());
168: }
169:
170: /**
171: * @see java.lang.Object#toString()
172: */
173: @Override
174: public String toString() {
175: return "{PluginFragment: uid=" + getUniqueId() + "}"; //$NON-NLS-1$ //$NON-NLS-2$
176: }
177: }
|