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

📄 extensionpointimpl.java

📁 java插件系统源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            ParameterDefinition def = (ParameterDefinition) it.next();
            names.add(def.getId());
            newParamDefs.add(def);
        }
        for (Iterator it = parentParamDefs.iterator(); it.hasNext();) {
            ParameterDefinition def = (ParameterDefinition) it.next();
            if (names.contains(def.getId())) {
                continue;
            }
            newParamDefs.add(def);
        }
        paramDefsMerged = true;
        parameterDefinitions = Collections.unmodifiableList(newParamDefs);
        return parameterDefinitions;
    }
    
    /**
     * @see org.java.plugin.registry.ExtensionPoint#getParameterDefinition(
     *      java.lang.String)
     */
    public ParameterDefinition getParameterDefinition(final String id) {
        for (Iterator it = getParameterDefinitions().iterator();
                it.hasNext();) {
            ParameterDefinitionImpl def = (ParameterDefinitionImpl) it.next();
            if (def.getId().equals(id)) {
                return def;
            }
        }
        throw new IllegalArgumentException("parameter definition with ID " + id //$NON-NLS-1$
            + " not found in extension point " + getUniqueId() //$NON-NLS-1$
            + " and all it parents"); //$NON-NLS-1$
    }

    /**
     * @see org.java.plugin.registry.ExtensionPoint#getParentPluginId()
     */
    public String getParentPluginId() {
        return model.getParentPluginId();
    }

    /**
     * @see org.java.plugin.registry.ExtensionPoint#getParentExtensionPointId()
     */
    public String getParentExtensionPointId() {
        return model.getParentPointId();
    }

    /**
     * @see org.java.plugin.registry.ExtensionPoint#isSuccessorOf(
     *      org.java.plugin.registry.ExtensionPoint)
     */
    public boolean isSuccessorOf(final ExtensionPoint extensionPoint) {
        if ((model.getParentPluginId() == null)
                || (model.getParentPointId() == null)) {
            return false;
        }
        if (model.getParentPluginId().equals(
                extensionPoint.getDeclaringPluginDescriptor().getId())
                && model.getParentPointId().equals(extensionPoint.getId())) {
            return true;
        }
        try {
            return getDeclaringPluginDescriptor().getRegistry()
                .getExtensionPoint(model.getParentPluginId(),
                        model.getParentPointId()).isSuccessorOf(extensionPoint);
        } catch (IllegalArgumentException iae) {
            return false;
        }
    }

    private void collectDescendants() {
        descendants = new LinkedList();
        for (Iterator it = getDeclaringPluginDescriptor().getRegistry()
                .getPluginDescriptors().iterator(); it.hasNext();) {
            PluginDescriptor descr = (PluginDescriptor) it.next();
            for (Iterator it2 = descr.getExtensionPoints().iterator();
                    it2.hasNext();) {
                ExtensionPoint extp = (ExtensionPoint) it2.next();
                if (extp.isSuccessorOf(this)) {
                    if (log.isDebugEnabled()) {
                        log.debug("extension point " + extp //$NON-NLS-1$
                                + " is descendant of point " + this); //$NON-NLS-1$
                    }
                    descendants.add(extp);
                }
            }
        }
        descendants = Collections.unmodifiableList(descendants);
    }

    /**
     * @see org.java.plugin.registry.ExtensionPoint#getDescendants()
     */
    public Collection getDescendants() {
        if (descendants == null) {
            collectDescendants();
        }
        return descendants;
    }

    /**
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return "{ExtensionPoint: uid=" + getUniqueId() + "}"; //$NON-NLS-1$ //$NON-NLS-2$
    }
    
    void registryChanged() {
        isValid = null;
        connectedExtensions = null;
        availableExtensions = null;
        descendants = null;
    }
    
    class ParameterDefinitionImpl extends PluginElementImpl
            implements ParameterDefinition {
        private List subDefinitions;
        private final ParameterDefinitionImpl superDefinition;
        private final ModelParameterDef modelParamDef;
        private final ParameterValueParser valueParser;

        ParameterDefinitionImpl(final ParameterDefinitionImpl aSuperDefinition,
                final ModelParameterDef aModel)
                throws ManifestProcessingException {
            super(ExtensionPointImpl.this.getDeclaringPluginDescriptor(),
                    ExtensionPointImpl.this.getDeclaringPluginFragment(),
                    aModel.getId(), aModel.getDocumentation());
            superDefinition = aSuperDefinition;
            modelParamDef = aModel;
            checkType();
            checkMultiplicity();
            valueParser = new ParameterValueParser(
                    getDeclaringPluginDescriptor().getRegistry(), this,
                    modelParamDef.getDefaultValue());
            if (!valueParser.isParsingSucceeds()) {
                log.warn("parsing default value for parameter definition " //$NON-NLS-1$
                        + this + " failed, message is: " //$NON-NLS-1$
                        + valueParser.getParsingMessage());
                throw new ManifestProcessingException(
                        PluginRegistryImpl.PACKAGE_NAME,
                        "invalidDefaultValueAttribute", //$NON-NLS-1$
                        new Object[] {modelParamDef.getDefaultValue(),
                            ExtensionPointImpl.this.getId(),
                            ExtensionPointImpl.this
                                .getDeclaringPluginDescriptor().getId()});
            }
            if (TYPE_ANY.equals(modelParamDef.getType())) {
                subDefinitions = Collections.EMPTY_LIST;
            } else {
                subDefinitions = new ArrayList(
                        modelParamDef.getParamDefs().size());
                Set names = new HashSet();
                for (Iterator it = modelParamDef.getParamDefs().iterator();
                        it.hasNext();) {
                    ParameterDefinitionImpl def = new ParameterDefinitionImpl(
                            this, (ModelParameterDef) it.next());
                    if (names.contains(def.getId())) {
                        throw new ManifestProcessingException(
                                PluginRegistryImpl.PACKAGE_NAME,
                                "duplicateParameterDefinition", //$NON-NLS-1$
                                new Object[] {def.getId(),
                                    ExtensionPointImpl.this.getId(),
                                    ExtensionPointImpl.this.
                                    getDeclaringPluginDescriptor().getId()});
                    }
                    names.add(def.getId());
                    subDefinitions.add(def);
                }
                subDefinitions = Collections.unmodifiableList(subDefinitions);
            }
            if (log.isDebugEnabled()) {
                log.debug("object instantiated: " + this); //$NON-NLS-1$
            }
        }

        private void checkType() throws ManifestProcessingException {
            String type = modelParamDef.getType();
            if (!TYPE_STRING.equals(type)
                    && !TYPE_BOOLEAN.endsWith(type)
                    && !TYPE_NUMBER.equals(type)
                    && !TYPE_DATE.equals(type)
                    && !TYPE_TIME.equals(type)
                    && !TYPE_DATETIME.equals(type)
                    && !TYPE_NULL.equals(type)
                    && !TYPE_ANY.equals(type)
                    && !TYPE_PLUGIN_ID.equals(type)
                    && !TYPE_EXTENSION_POINT_ID.equals(type)
                    && !TYPE_EXTENSION_ID.equals(type)
                    && !TYPE_FIXED.equals(type)
                    && !TYPE_RESOURCE.equals(type)) {
                throw new ManifestProcessingException(
                        PluginRegistryImpl.PACKAGE_NAME,
                        "invalidTypeAttribute", //$NON-NLS-1$
                        new Object[] {type, ExtensionPointImpl.this.getId(),
                            ExtensionPointImpl.this
                                .getDeclaringPluginDescriptor().getId()});
            }
        }

        private void checkMultiplicity() throws ManifestProcessingException {
            String multiplicity = modelParamDef.getMultiplicity();
            if (!MULT_ONE.equals(multiplicity)
                    && !MULT_ANY.equals(multiplicity)
                    && !MULT_NONE_OR_ONE.equals(multiplicity)
                    && !MULT_ONE_OR_MORE.equals(multiplicity)) {
                throw new ManifestProcessingException(
                        PluginRegistryImpl.PACKAGE_NAME,
                        "invalidMultiplicityAttribute", //$NON-NLS-1$
                        new Object[] {multiplicity,
                            ExtensionPointImpl.this.getId(),
                            ExtensionPointImpl.this
                                .getDeclaringPluginDescriptor().getId()});
            }
        }
        
        ParameterValueParser getValueParser() {
            return valueParser;
        }
        
        /**
         * @see org.java.plugin.registry.ExtensionPoint.ParameterDefinition
         *      #getDeclaringExtensionPoint()
         */
        public ExtensionPoint getDeclaringExtensionPoint() {
            return ExtensionPointImpl.this;
        }

        /**
         * @see org.java.plugin.registry.ExtensionPoint.ParameterDefinition
         *      #getMultiplicity()
         */
        public String getMultiplicity() {
            return modelParamDef.getMultiplicity();
        }

        /**
         * @see org.java.plugin.registry.ExtensionPoint.ParameterDefinition
         *      #getSubDefinitions()
         */
        public Collection getSubDefinitions() {
            return subDefinitions;
        }

        /**
         * @see org.java.plugin.registry.ExtensionPoint.ParameterDefinition
         *      #getSuperDefinition()
         */
        public ParameterDefinition getSuperDefinition() {
            return superDefinition;
        }
        
        /**
         * @see org.java.plugin.registry.ExtensionPoint.ParameterDefinition
         *      #getSubDefinition(java.lang.String)
         */
        public ParameterDefinition getSubDefinition(final String id) {
            for (Iterator it = subDefinitions.iterator(); it.hasNext();) {
                ParameterDefinitionImpl def =
                    (ParameterDefinitionImpl) it.next();
                if (def.getId().equals(id)) {
                    return def;
                }
            }
            throw new IllegalArgumentException(
                    "parameter definition with ID " + id //$NON-NLS-1$
                    + " not found in extension point " + getUniqueId()); //$NON-NLS-1$
        }

        /**
         * @see org.java.plugin.registry.ExtensionPoint.ParameterDefinition#getType()
         */
        public String getType() {
            return modelParamDef.getType();
        }

        /**
         * @see org.java.plugin.registry.ExtensionPoint.ParameterDefinition
         *      #getCustomData()
         */
        public String getCustomData() {
            return modelParamDef.getCustomData();
        }
        
        /**
         * @see org.java.plugin.registry.ExtensionPoint.ParameterDefinition
         *      #getDefaultValue()
         */
        public String getDefaultValue() {
            return modelParamDef.getDefaultValue();
        }
        
        /**
         * @see java.lang.Object#toString()
         */
        public String toString() {
            return "{PluginExtensionPoint.ParameterDefinition: extPointUid=" //$NON-NLS-1$
                + getDeclaringExtensionPoint().getUniqueId() + "; id=" + getId() //$NON-NLS-1$
                + "}"; //$NON-NLS-1$
        }
        
        /**
         * @see org.java.plugin.registry.xml.IdentityImpl#isEqualTo(
         *      org.java.plugin.registry.Identity)
         */
        protected boolean isEqualTo(final Identity idt) {
            if (!super.isEqualTo(idt)) {
                return false;
            }
            ParameterDefinitionImpl other = (ParameterDefinitionImpl) idt;
            if ((getSuperDefinition() == null)
                    && (other.getSuperDefinition() == null)) {
                return true;
            }
            if ((getSuperDefinition() == null)
                    || (other.getSuperDefinition() == null)) {
                return false;
            }
            return getSuperDefinition().equals(other.getSuperDefinition());
        }
    }
}

⌨️ 快捷键说明

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