📄 plugindescriptorimpl.java
字号:
/*****************************************************************************
* Java Plug-in Framework (JPF)
* Copyright (C) 2004-2007 Dmitry Olshansky
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
package org.java.plugin.registry.xml;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.java.plugin.registry.Documentation;
import org.java.plugin.registry.Extension;
import org.java.plugin.registry.ExtensionPoint;
import org.java.plugin.registry.Identity;
import org.java.plugin.registry.Library;
import org.java.plugin.registry.ManifestProcessingException;
import org.java.plugin.registry.PluginAttribute;
import org.java.plugin.registry.PluginDescriptor;
import org.java.plugin.registry.PluginPrerequisite;
import org.java.plugin.registry.PluginRegistry;
import org.java.plugin.registry.Version;
/**
* @version $Id: PluginDescriptorImpl.java,v 1.6 2007/01/05 13:32:08 ddimon Exp $
*/
class PluginDescriptorImpl extends IdentityImpl implements PluginDescriptor {
private final PluginRegistry registry;
private final URL location;
private final ModelPluginDescriptor model;
private Map pluginPrerequisites;
private Map libraries;
private Map extensionPoints;
private Map extensions;
private Documentation doc;
private List fragments;
private List attributes;
PluginDescriptorImpl(final PluginRegistry aRegistry,
final ModelPluginDescriptor aModel, final URL aLocation)
throws ManifestProcessingException {
super(aModel.getId());
registry = aRegistry;
model = aModel;
location = aLocation;
if (model.getVendor() == null) {
model.setVendor(""); //$NON-NLS-1$
}
if ((model.getClassName() != null)
&& (model.getClassName().trim().length() == 0)) {
model.setClassName(null);
}
if ((model.getDocsPath() == null)
|| (model.getDocsPath().trim().length() == 0)) {
model.setDocsPath("docs"); //$NON-NLS-1$
}
if (model.getDocumentation() != null) {
doc = new DocumentationImpl(this, model.getDocumentation());
}
attributes = new LinkedList();
fragments = new LinkedList();
pluginPrerequisites = new HashMap();
libraries = new HashMap();
extensionPoints = new HashMap();
extensions = new HashMap();
processAttributes(null, model);
processPrerequisites(null, model);
processLibraries(null, model);
processExtensionPoints(null, model);
processExtensions(null, model);
if (log.isDebugEnabled()) {
log.debug("object instantiated: " + this); //$NON-NLS-1$
}
}
void registerFragment(final PluginFragmentImpl fragment)
throws ManifestProcessingException {
fragments.add(fragment);
processAttributes(fragment, fragment.getModel());
processPrerequisites(fragment, fragment.getModel());
processLibraries(fragment, fragment.getModel());
processExtensionPoints(fragment, fragment.getModel());
processExtensions(fragment, fragment.getModel());
}
void unregisterFragment(final PluginFragmentImpl fragment) {
// removing attributes
for (Iterator it = attributes.iterator(); it.hasNext();) {
if (fragment.equals(((PluginAttribute) it.next())
.getDeclaringPluginFragment())) {
it.remove();
}
}
// removing prerequisites
for (Iterator it = pluginPrerequisites.entrySet().iterator();
it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
if (fragment.equals(((PluginPrerequisite) entry.getValue())
.getDeclaringPluginFragment())) {
it.remove();
}
}
// removing libraries
for (Iterator it = libraries.entrySet().iterator();
it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
if (fragment.equals(((Library) entry.getValue())
.getDeclaringPluginFragment())) {
it.remove();
}
}
// removing extension points
for (Iterator it = extensionPoints.entrySet().iterator();
it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
if (fragment.equals(((ExtensionPoint) entry.getValue())
.getDeclaringPluginFragment())) {
it.remove();
}
}
// removing extensions
for (Iterator it = extensions.entrySet().iterator();
it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
if (fragment.equals(((Extension) entry.getValue())
.getDeclaringPluginFragment())) {
it.remove();
}
}
fragments.remove(fragment);
}
private void processAttributes(final PluginFragmentImpl fragment,
final ModelPluginManifest modelManifest)
throws ManifestProcessingException {
for (Iterator it = modelManifest.getAttributes().iterator();
it.hasNext();) {
attributes.add(new PluginAttributeImpl(this, fragment,
(ModelAttribute) it.next(), null));
}
}
private void processPrerequisites(final PluginFragmentImpl fragment,
final ModelPluginManifest modelManifest)
throws ManifestProcessingException {
for (Iterator it = modelManifest.getPrerequisites().iterator();
it.hasNext();) {
PluginPrerequisiteImpl pluginPrerequisite =
new PluginPrerequisiteImpl(this, fragment,
(ModelPrerequisite) it.next());
if (pluginPrerequisites.containsKey(
pluginPrerequisite.getPluginId())) {
throw new ManifestProcessingException(
PluginRegistryImpl.PACKAGE_NAME,
"duplicateImports", new Object[] { //$NON-NLS-1$
pluginPrerequisite.getPluginId(), getId()});
}
pluginPrerequisites.put(pluginPrerequisite.getPluginId(),
pluginPrerequisite);
}
}
private void processLibraries(final PluginFragmentImpl fragment,
final ModelPluginManifest modelManifest)
throws ManifestProcessingException {
for (Iterator it = modelManifest.getLibraries().iterator();
it.hasNext();) {
LibraryImpl lib = new LibraryImpl(this, fragment,
(ModelLibrary) it.next());
if (libraries.containsKey(lib.getId())) {
throw new ManifestProcessingException(
PluginRegistryImpl.PACKAGE_NAME,
"duplicateLibraries", new Object[] { //$NON-NLS-1$
lib.getId(), getId()});
}
libraries.put(lib.getId(), lib);
}
}
private void processExtensionPoints(final PluginFragmentImpl fragment,
final ModelPluginManifest modelManifest)
throws ManifestProcessingException {
for (Iterator it = modelManifest.getExtensionPoints().iterator();
it.hasNext();) {
ExtensionPointImpl extensionPoint =
new ExtensionPointImpl(this, fragment,
(ModelExtensionPoint) it.next());
if (extensionPoints.containsKey(extensionPoint.getId())) {
throw new ManifestProcessingException(
PluginRegistryImpl.PACKAGE_NAME,
"duplicateExtensionPoints", new Object[] { //$NON-NLS-1$
extensionPoint.getId(), getId()});
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -