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

📄 pluginregistryimpl.java

📁 java插件系统源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        listeners.add(listener);
    }

    /**
     * @see org.java.plugin.registry.PluginRegistry#unregisterListener(
     *      org.java.plugin.registry.PluginRegistry.RegistryChangeListener)
     */
    public void unregisterListener(final RegistryChangeListener listener) {
        if (!listeners.remove(listener)) {
            log.warn("unknown listener " + listener); //$NON-NLS-1$
        }
    }
    
    void fireEvent(final RegistryChangeDataImpl data) {
        data.dump();
        if (listeners.isEmpty()) {
            return;
        }
        // make local copy
        RegistryChangeListener[] arr =
            (RegistryChangeListener[]) listeners.toArray(
                new RegistryChangeListener[listeners.size()]);
        data.beforeEventFire();
        if (log.isDebugEnabled()) {
            log.debug("propagating registry change event"); //$NON-NLS-1$
        }
        for (int i = 0; i < arr.length; i++) {
            arr[i].registryChanged(data);
        }
        if (log.isDebugEnabled()) {
            log.debug("registry change event propagated"); //$NON-NLS-1$
        }
        data.afterEventFire();
    }
    
    private static final class RegistryChangeDataImpl
            implements RegistryChangeData {
        private Set addedPlugins;
        private Set removedPlugins;
        private Set modifiedPlugins;
        private Map addedExtensions;
        private Map removedExtensions;
        private Map modifiedExtensions;
        
        protected RegistryChangeDataImpl() {
            reset();
        }
        
        private void reset() {
            addedPlugins = new HashSet();
            removedPlugins = new HashSet();
            modifiedPlugins = new HashSet();
            addedExtensions = new HashMap();
            removedExtensions = new HashMap();
            modifiedExtensions = new HashMap();
        }
        
        protected void beforeEventFire() {
            addedPlugins = Collections.unmodifiableSet(addedPlugins);
            removedPlugins = Collections.unmodifiableSet(removedPlugins);
            modifiedPlugins = Collections.unmodifiableSet(modifiedPlugins);
            addedExtensions = Collections.unmodifiableMap(addedExtensions);
            removedExtensions = Collections.unmodifiableMap(removedExtensions);
            modifiedExtensions =
                Collections.unmodifiableMap(modifiedExtensions);
        }
        
        protected void afterEventFire() {
            reset();
        }
        
        protected void dump() {
            Log logger = LogFactory.getLog(getClass());
            if (!logger.isDebugEnabled()) {
                return;
            }
            StringBuffer buf = new StringBuffer();
            buf.append("PLUG-IN REGISTRY CHANGES DUMP:\r\n") //$NON-NLS-1$
                .append("-------------- DUMP BEGIN -----------------\r\n") //$NON-NLS-1$
                .append("\tAdded plug-ins: " + addedPlugins.size() //$NON-NLS-1$
                        + "\r\n"); //$NON-NLS-1$
            for (Iterator it = addedPlugins.iterator();
                    it.hasNext();) {
                buf.append("\t\t") //$NON-NLS-1$
                    .append(it.next())
                    .append("\r\n"); //$NON-NLS-1$
            }
            buf.append("\tRemoved plug-ins: " + removedPlugins.size() //$NON-NLS-1$
                    + "\r\n"); //$NON-NLS-1$
            for (Iterator it = removedPlugins.iterator();
                    it.hasNext();) {
                buf.append("\t\t") //$NON-NLS-1$
                .append(it.next())
                .append("\r\n"); //$NON-NLS-1$
            }
            buf.append("\tModified plug-ins: " + modifiedPlugins.size() //$NON-NLS-1$
                    + "\r\n"); //$NON-NLS-1$
            for (Iterator it = modifiedPlugins.iterator();
                    it.hasNext();) {
                buf.append("\t\t") //$NON-NLS-1$
                .append(it.next())
                .append("\r\n"); //$NON-NLS-1$
            }
            buf.append("\tAdded extensions: " + addedExtensions.size() //$NON-NLS-1$
                    + "\r\n"); //$NON-NLS-1$
            for (Iterator it = addedExtensions.entrySet().iterator();
                    it.hasNext();) {
                buf.append("\t\t") //$NON-NLS-1$
                    .append(it.next())
                    .append("\r\n"); //$NON-NLS-1$
            }
            buf.append("\tRemoved extensions: " + removedExtensions.size() //$NON-NLS-1$
                    + "\r\n"); //$NON-NLS-1$
            for (Iterator it = removedExtensions.entrySet().iterator();
                    it.hasNext();) {
                buf.append("\t\t") //$NON-NLS-1$
                .append(it.next())
                .append("\r\n"); //$NON-NLS-1$
            }
            buf.append("\tModified extensions: " + modifiedExtensions.size() //$NON-NLS-1$
                    + "\r\n"); //$NON-NLS-1$
            for (Iterator it = modifiedExtensions.entrySet().iterator();
                    it.hasNext();) {
                buf.append("\t\t") //$NON-NLS-1$
                .append(it.next())
                .append("\r\n"); //$NON-NLS-1$
            }
            buf.append("Memory TOTAL/FREE/MAX: ") //$NON-NLS-1$
                .append(Runtime.getRuntime().totalMemory())
                .append("/") //$NON-NLS-1$
                .append(Runtime.getRuntime().freeMemory())
                .append("/") //$NON-NLS-1$
                .append(Runtime.getRuntime().maxMemory())
                .append("\r\n"); //$NON-NLS-1$
            buf.append("-------------- DUMP END -----------------\r\n"); //$NON-NLS-1$
            logger.debug(buf.toString());
        }
        
        /**
         * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#addedPlugins()
         */
        public Set addedPlugins() {
            return addedPlugins;
        }
        
        /**
         * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
         *      removedPlugins()
         */
        public Set removedPlugins() {
            return removedPlugins;
        }

        /**
         * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
         *      modifiedPlugins()
         */
        public Set modifiedPlugins() {
            return modifiedPlugins;
        }
        
        void putAddedExtension(final String extensionUid,
                final String extensionPointUid) {
            addedExtensions.put(extensionUid, extensionPointUid);
        }

        /**
         * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
         *      addedExtensions()
         */
        public Set addedExtensions() {
            return addedExtensions.keySet();
        }

        /**
         * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
         *      addedExtensions(java.lang.String)
         */
        public Set addedExtensions(final String extensionPointUid) {
            Set result = new HashSet();
            for (Iterator it = addedExtensions.entrySet().iterator();
                    it.hasNext();) {
                Map.Entry entry = (Map.Entry) it.next();
                if (entry.getValue().equals(extensionPointUid)) {
                    result.add(entry.getKey());
                }
            }
            return Collections.unmodifiableSet(result);
        }
        
        void putRemovedExtension(final String extensionUid,
                final String extensionPointUid) {
            removedExtensions.put(extensionUid, extensionPointUid);
        }
        
        /**
         * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
         *      removedExtensions()
         */
        public Set removedExtensions() {
            return removedExtensions.keySet();
        }

        /**
         * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
         *      removedExtensions(java.lang.String)
         */
        public Set removedExtensions(final String extensionPointUid) {
            Set result = new HashSet();
            for (Iterator it = removedExtensions.entrySet().iterator();
                    it.hasNext();) {
                Map.Entry entry = (Map.Entry) it.next();
                if (entry.getValue().equals(extensionPointUid)) {
                    result.add(entry.getKey());
                }
            }
            return Collections.unmodifiableSet(result);
        }
        
        void putModifiedExtension(final String extensionUid,
                final String extensionPointUid) {
            modifiedExtensions.put(extensionUid, extensionPointUid);
        }

        /**
         * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
         *      modifiedExtensions()
         */
        public Set modifiedExtensions() {
            return modifiedExtensions.keySet();
        }

        /**
         * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
         *      modifiedExtensions(java.lang.String)
         */
        public Set modifiedExtensions(final String extensionPointUid) {
            Set result = new HashSet();
            for (Iterator it = modifiedExtensions.entrySet().iterator();
                    it.hasNext();) {
                Map.Entry entry = (Map.Entry) it.next();
                if (entry.getValue().equals(extensionPointUid)) {
                    result.add(entry.getKey());
                }
            }
            return Collections.unmodifiableSet(result);
        }
    }
    
    private static final class ManifestInfoImpl implements ManifestInfo {
        private final ModelManifestInfo model;

        ManifestInfoImpl(final ModelManifestInfo aModel) {
            model = aModel;
        }
        
        /**
         * @see org.java.plugin.registry.PluginRegistry.ManifestInfo#getId()
         */
        public String getId() {
            return model.getId();
        }

        /**
         * @see org.java.plugin.registry.PluginRegistry.ManifestInfo#
         *      getVersion()
         */
        public Version getVersion() {
            return model.getVersion();
        }

        /**
         * @see org.java.plugin.registry.PluginRegistry.ManifestInfo#
         *      getVendor()
         */
        public String getVendor() {
            return model.getVendor();
        }

        /**
         * @see org.java.plugin.registry.PluginRegistry.ManifestInfo#
         *      getPluginId()
         */
        public String getPluginId() {
            return model.getPluginId();
        }

        /**
         * @see org.java.plugin.registry.PluginRegistry.ManifestInfo#
         *      getPluginVersion()
         */
        public Version getPluginVersion() {
            return model.getPluginVersion();
        }

        /**
         * @see org.java.plugin.registry.PluginRegistry.ManifestInfo#
         *      getMatchingRule()
         */
        public String getMatchingRule() {
            return model.getMatch();
        }
    }
}

⌨️ 快捷键说明

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