⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manifesthandler.java

📁 java插件系统源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
 * Java Plug-in Framework (JPF)
 * Copyright (C) 2004-2006 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 org.java.plugin.registry.ExtensionPoint;
import org.java.plugin.registry.PluginPrerequisite;
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
import org.xml.sax.SAXException;

/**
 * @version $Id: ManifestHandler.java,v 1.6 2006/08/19 17:37:21 ddimon Exp $
 */
final class ManifestHandler extends BaseHandler {
    private ModelPluginManifest manifest = null;
    private ModelDocumentation documentation = null;
    private ModelPrerequisite prerequisite;
    private ModelLibrary library;
    private ModelExtensionPoint extensionPoint;
    private ModelExtension extension;
    private StringBuffer docText = null;
    private SimpleStack attributeStack = null;
    private ModelAttribute attribute;
    private SimpleStack paramDefStack = null;
    private ModelParameterDef paramDef;
    private SimpleStack paramStack = null;
    private ModelParameter param;
    private StringBuffer paramValue = null;

    ManifestHandler(final EntityResolver anEntityResolver) {
        super(anEntityResolver);
    }
    
    /**
     * @see org.xml.sax.ContentHandler#startElement(java.lang.String,
     *      java.lang.String, java.lang.String, org.xml.sax.Attributes)
     */
    public void startElement(final String uri, final String localName,
            final String qName, final Attributes attributes)
            throws SAXException {
        if (log.isDebugEnabled()) {
            log.debug("startElement - [" + uri + "]/[" //$NON-NLS-1$ //$NON-NLS-2$
                    + localName + "]/[" + qName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        String name = qName;
        if ("plugin".equals(name)) { //$NON-NLS-1$
            if (manifest != null) {
                throw new SAXException("unexpected [" + name //$NON-NLS-1$
                        + "] element (manifest already defined)"); //$NON-NLS-1$
            }
            manifest = new ModelPluginDescriptor();
            manifest.setId(attributes.getValue("id")); //$NON-NLS-1$
            manifest.setVersion(attributes.getValue("version")); //$NON-NLS-1$
            manifest.setVendor(attributes.getValue("vendor")); //$NON-NLS-1$
            manifest.setDocsPath(attributes.getValue("docs-path")); //$NON-NLS-1$
            ((ModelPluginDescriptor) manifest).setClassName(
                    attributes.getValue("class")); //$NON-NLS-1$
        } else if ("plugin-fragment".equals(name)) { //$NON-NLS-1$
            if (manifest != null) {
                throw new SAXException("unexpected [" + name //$NON-NLS-1$
                        + "] element (manifest already defined)"); //$NON-NLS-1$
            }
            manifest = new ModelPluginFragment();
            manifest.setId(attributes.getValue("id")); //$NON-NLS-1$
            manifest.setVersion(attributes.getValue("version")); //$NON-NLS-1$
            manifest.setVendor(attributes.getValue("vendor")); //$NON-NLS-1$
            manifest.setDocsPath(attributes.getValue("docs-path")); //$NON-NLS-1$
            ((ModelPluginFragment) manifest).setPluginId(
                    attributes.getValue("plugin-id")); //$NON-NLS-1$
            if (attributes.getValue("plugin-version") != null) { //$NON-NLS-1$
                ((ModelPluginFragment) manifest).setPluginVersion(
                        attributes.getValue("plugin-version")); //$NON-NLS-1$
            }
            if (attributes.getValue("match") != null) { //$NON-NLS-1$
                ((ModelPluginFragment) manifest).setMatch(
                        attributes.getValue("match")); //$NON-NLS-1$
            } else {
                ((ModelPluginFragment) manifest).setMatch(PluginPrerequisite.MATCH_COMPATIBLE);
            }
        } else if ("doc".equals(name)) { //$NON-NLS-1$
            documentation = new ModelDocumentation();
            documentation.setCaption(attributes.getValue("caption")); //$NON-NLS-1$
        } else if ("doc-ref".equals(name)) { //$NON-NLS-1$
            if (documentation == null) {
                if (entityResolver != null) {
                    throw new SAXException("[doc-ref] element found " //$NON-NLS-1$
                            + "outside of [doc] element"); //$NON-NLS-1$
                }
                // ignore this element
                log.warn("[doc-ref] element found outside of [doc] element"); //$NON-NLS-1$
                return;
            }
            ModelDocumentationReference docRef =
                new ModelDocumentationReference();
            docRef.setPath(attributes.getValue("path")); //$NON-NLS-1$
            docRef.setCaption(attributes.getValue("caption")); //$NON-NLS-1$
            documentation.getReferences().add(docRef);
        } else if ("doc-text".equals(name)) { //$NON-NLS-1$
            if (documentation == null) {
                if (entityResolver != null) {
                    throw new SAXException("[doc-text] element found " //$NON-NLS-1$
                            + "outside of [doc] element"); //$NON-NLS-1$
                }
                // ignore this element
                log.warn("[doc-text] element found outside of [doc] element"); //$NON-NLS-1$
                return;
            }
            docText = new StringBuffer();
        } else if ("attributes".equals(name)) { //$NON-NLS-1$
            attributeStack = new SimpleStack();
        } else if ("attribute".equals(name)) { //$NON-NLS-1$
            if (attributeStack == null) {
                if (entityResolver != null) {
                    throw new SAXException("[attribute] element found " //$NON-NLS-1$
                            + "outside of [attributes] element"); //$NON-NLS-1$
                }
                // ignore this element
                log.warn("[attribute] element found " //$NON-NLS-1$
                        + "outside of [attributes] element"); //$NON-NLS-1$
                return;
            }
            if (attribute != null) {
                attributeStack.push(attribute);
            }
            attribute = new ModelAttribute();
            attribute.setId(attributes.getValue("id")); //$NON-NLS-1$
            attribute.setValue(attributes.getValue("value")); //$NON-NLS-1$
        } else if ("requires".equals(name)) { //$NON-NLS-1$
            // no-op
        } else if ("import".equals(name)) { //$NON-NLS-1$
            prerequisite = new ModelPrerequisite();
            if (attributes.getValue("id") != null) { //$NON-NLS-1$
                prerequisite.setId(attributes.getValue("id")); //$NON-NLS-1$
            }
            prerequisite.setPluginId(attributes.getValue("plugin-id")); //$NON-NLS-1$
            if (attributes.getValue("plugin-version") != null) { //$NON-NLS-1$
                prerequisite.setPluginVersion(
                        attributes.getValue("plugin-version")); //$NON-NLS-1$
            }
            if (attributes.getValue("match") != null) { //$NON-NLS-1$
                prerequisite.setMatch(attributes.getValue("match")); //$NON-NLS-1$
            } else {
                prerequisite.setMatch(PluginPrerequisite.MATCH_COMPATIBLE);
            }
            prerequisite.setExported(attributes.getValue("exported")); //$NON-NLS-1$
            prerequisite.setOptional(attributes.getValue("optional")); //$NON-NLS-1$
            prerequisite.setReverseLookup(
                    attributes.getValue("reverse-lookup")); //$NON-NLS-1$
        } else if ("runtime".equals(name)) { //$NON-NLS-1$
            // no-op
        } else if ("library".equals(name)) { //$NON-NLS-1$
            library = new ModelLibrary();
            library.setId(attributes.getValue("id")); //$NON-NLS-1$
            library.setPath(attributes.getValue("path")); //$NON-NLS-1$
            library.setCodeLibrary(attributes.getValue("type")); //$NON-NLS-1$
            if (attributes.getValue("version") != null) { //$NON-NLS-1$
                library.setVersion(attributes.getValue("version")); //$NON-NLS-1$
            }
        } else if ("export".equals(name)) { //$NON-NLS-1$
            if (library == null) {
                if (entityResolver != null) {
                    throw new SAXException("[export] element found " //$NON-NLS-1$
                            + "outside of [library] element"); //$NON-NLS-1$
                }
                // ignore this element
                log.warn("[export] element found outside of [library] element"); //$NON-NLS-1$
                return;
            }
            library.getExports().add(attributes.getValue("prefix")); //$NON-NLS-1$
        } else if ("extension-point".equals(name)) { //$NON-NLS-1$
            extensionPoint = new ModelExtensionPoint();
            extensionPoint.setId(attributes.getValue("id")); //$NON-NLS-1$
            extensionPoint.setParentPluginId(
                    attributes.getValue("parent-plugin-id")); //$NON-NLS-1$
            extensionPoint.setParentPointId(
                    attributes.getValue("parent-point-id")); //$NON-NLS-1$
            if (attributes.getValue("extension-multiplicity") != null) { //$NON-NLS-1$
                extensionPoint.setExtensionMultiplicity(
                        attributes.getValue("extension-multiplicity")); //$NON-NLS-1$
            } else {
                extensionPoint.setExtensionMultiplicity(ExtensionPoint.EXT_MULT_ANY);
            }
            paramDefStack = new SimpleStack();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -