Source Code Cross Referenced for PluginRegistryImpl.java in  » Development » Java-Plugin-Framework » org » java » plugin » registry » xml » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » Java Plugin Framework » org.java.plugin.registry.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*****************************************************************************
0002:         * Java Plug-in Framework (JPF)
0003:         * Copyright (C) 2004-2007 Dmitry Olshansky
0004:         * 
0005:         * This library is free software; you can redistribute it and/or
0006:         * modify it under the terms of the GNU Lesser General Public
0007:         * License as published by the Free Software Foundation; either
0008:         * version 2.1 of the License, or (at your option) any later version.
0009:         * 
0010:         * This library is distributed in the hope that it will be useful,
0011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013:         * Lesser General Public License for more details.
0014:         * 
0015:         * You should have received a copy of the GNU Lesser General Public
0016:         * License along with this library; if not, write to the Free Software
0017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018:         *****************************************************************************/package org.java.plugin.registry.xml;
0019:
0020:        import java.net.URL;
0021:        import java.util.Collection;
0022:        import java.util.Collections;
0023:        import java.util.HashMap;
0024:        import java.util.HashSet;
0025:        import java.util.Iterator;
0026:        import java.util.LinkedList;
0027:        import java.util.List;
0028:        import java.util.Map;
0029:        import java.util.Set;
0030:        import java.util.Map.Entry;
0031:
0032:        import org.apache.commons.logging.Log;
0033:        import org.apache.commons.logging.LogFactory;
0034:        import org.java.plugin.PathResolver;
0035:        import org.java.plugin.registry.Extension;
0036:        import org.java.plugin.registry.ExtensionPoint;
0037:        import org.java.plugin.registry.Identity;
0038:        import org.java.plugin.registry.IntegrityCheckReport;
0039:        import org.java.plugin.registry.ManifestInfo;
0040:        import org.java.plugin.registry.ManifestProcessingException;
0041:        import org.java.plugin.registry.MatchingRule;
0042:        import org.java.plugin.registry.PluginDescriptor;
0043:        import org.java.plugin.registry.PluginFragment;
0044:        import org.java.plugin.registry.PluginPrerequisite;
0045:        import org.java.plugin.registry.PluginRegistry;
0046:        import org.java.plugin.registry.Version;
0047:        import org.java.plugin.registry.IntegrityCheckReport.ReportItem;
0048:        import org.java.plugin.registry.xml.IntegrityChecker.ReportItemImpl;
0049:        import org.java.plugin.util.ExtendedProperties;
0050:
0051:        /**
0052:         * This is an implementation of plug-in registry of XML syntax plug-in
0053:         * manifests. Manifests should be prepared according to
0054:         * <a href="{@docRoot}/../plugin_1_0.dtd">plug-in DTD</a>.
0055:         * <p>
0056:         * <b>Configuration parameters</b>
0057:         * <p>
0058:         * This registry implementation supports following configuration parameters:
0059:         * <dl>
0060:         *   <dt>isValidating</dt>
0061:         *   <dd>Regulates is registry should use validating parser when loading
0062:         *     plug-in manifests. The default parameter value is <code>true</code>.</dd>
0063:         *   <dt>stopOnError</dt>
0064:         *   <dd>Regulates is registry should stop and throw RuntimeException if an
0065:         *     error occurred while {@link PluginRegistry#register(URL[]) registering}
0066:         *     or {@link PluginRegistry#unregister(String[]) un-registering} plug-ins.
0067:         *     If this is <code>false</code>, the registration errors will be stored
0068:         *     in the internal report that is available with
0069:         *     {@link PluginRegistry#checkIntegrity(PathResolver)} method.
0070:         *     The default parameter value is <code>false</code>.</dd>
0071:         * </dl>
0072:         * 
0073:         * @see org.java.plugin.ObjectFactory#createRegistry()
0074:         * 
0075:         * @version $Id: PluginRegistryImpl.java,v 1.6 2007/05/13 16:10:51 ddimon Exp $
0076:         */
0077:        public final class PluginRegistryImpl implements  PluginRegistry {
0078:            static final String PACKAGE_NAME = "org.java.plugin.registry.xml"; //$NON-NLS-1$
0079:            private static final char UNIQUE_SEPARATOR = '@';
0080:            private static final Log log = LogFactory
0081:                    .getLog(PluginRegistryImpl.class);
0082:
0083:            private final List<ReportItem> registrationReport = new LinkedList<ReportItem>();
0084:            private final Map<String, PluginDescriptor> registeredPlugins = new HashMap<String, PluginDescriptor>();
0085:            private final Map<String, PluginFragment> registeredFragments = new HashMap<String, PluginFragment>();
0086:            private final List<RegistryChangeListener> listeners = Collections
0087:                    .synchronizedList(new LinkedList<RegistryChangeListener>());
0088:            private ManifestParser manifestParser;
0089:            private boolean stopOnError = false;
0090:
0091:            /**
0092:             * Creates plug-in registry object.
0093:             */
0094:            public PluginRegistryImpl() {
0095:                registrationReport.add(new ReportItemImpl(
0096:                        IntegrityCheckReport.Severity.INFO, null,
0097:                        IntegrityCheckReport.Error.NO_ERROR,
0098:                        "registryStart", null)); //$NON-NLS-1$
0099:            }
0100:
0101:            /**
0102:             * @see org.java.plugin.registry.PluginRegistry#configure(
0103:             *      ExtendedProperties)
0104:             */
0105:            public void configure(final ExtendedProperties config) {
0106:                stopOnError = "true".equalsIgnoreCase( //$NON-NLS-1$
0107:                        config.getProperty("stopOnError", "false")); //$NON-NLS-1$ //$NON-NLS-2$
0108:                boolean isValidating = !"false".equalsIgnoreCase( //$NON-NLS-1$
0109:                        config.getProperty("isValidating", "true")); //$NON-NLS-1$ //$NON-NLS-2$
0110:                manifestParser = new ManifestParser(isValidating);
0111:                log.info("configured, stopOnError=" + stopOnError //$NON-NLS-1$
0112:                        + ", isValidating=" + isValidating); //$NON-NLS-1$
0113:            }
0114:
0115:            /**
0116:             * @see org.java.plugin.registry.PluginRegistry#readManifestInfo(
0117:             *      java.net.URL)
0118:             */
0119:            public ManifestInfo readManifestInfo(final URL url)
0120:                    throws ManifestProcessingException {
0121:                try {
0122:                    return new ManifestInfoImpl(manifestParser
0123:                            .parseManifestInfo(url));
0124:                } catch (Exception e) {
0125:                    throw new ManifestProcessingException(PACKAGE_NAME,
0126:                            "manifestParsingError", url, e); //$NON-NLS-1$
0127:                }
0128:            }
0129:
0130:            /**
0131:             * General algorithm:
0132:             * <ol>
0133:             *   <li>Collect all currently registered extension points.</li>
0134:             *   <li>Parse given URL's as XML content files and separate them on plug-in
0135:             *       and plug-in fragment descriptors.</li>
0136:             *   <li>Process new plug-in descriptors first:
0137:             *     <ol>
0138:             *       <li>Instantiate new PluginDescriptorImpl object.</li>
0139:             *       <li>Handle versions correctly - register new descriptor as most
0140:             *           recent version or as an old version.</li>
0141:             *       <li>If other versions of the same plug-in already registered, take
0142:             *           their fragments and register them with this version.</li>
0143:             *     </ol>
0144:             *   </li>
0145:             *   <li>Process new plug-in fragments next:
0146:             *     <ol>
0147:             *       <li>Instantiate new PluginFragmentImpl object.</li>
0148:             *       <li>Check if older version of the same fragment already registered.
0149:             *           If yes, un-register it and move to old plug-in fragments
0150:             *           collection.</li>
0151:             *       <li>Register new fragment with all matches plug-in descriptors (if
0152:             *           this fragment is of most recent version).</li>
0153:             *      </ol>
0154:             *    </li>
0155:             *    <li>Notify collected extension points about potential changes in
0156:             *        extensions set.</li>
0157:             *    <li>Propagate events about registry changes.</li>
0158:             * </ol>
0159:             * @see org.java.plugin.registry.PluginRegistry#register(java.net.URL[])
0160:             */
0161:            public Map<String, Identity> register(final URL[] manifests)
0162:                    throws ManifestProcessingException {
0163:                // collecting registered extension points and extensions
0164:                List<ExtensionPoint> registeredPoints = new LinkedList<ExtensionPoint>();
0165:                Map<String, Extension> registeredExtensions = new HashMap<String, Extension>();
0166:                for (PluginDescriptor descriptor : registeredPlugins.values()) {
0167:                    for (ExtensionPoint point : descriptor.getExtensionPoints()) {
0168:                        registeredPoints.add(point);
0169:                        for (Extension ext : point.getConnectedExtensions()) {
0170:                            registeredExtensions.put(ext.getUniqueId(), ext);
0171:                        }
0172:                    }
0173:                }
0174:                Map<String, Identity> result = new HashMap<String, Identity>(
0175:                        manifests.length);
0176:                Map<String, ModelPluginManifest> plugins = new HashMap<String, ModelPluginManifest>();
0177:                Map<String, ModelPluginManifest> fragments = new HashMap<String, ModelPluginManifest>();
0178:                // parsing given manifests
0179:                registrationReport.add(new ReportItemImpl(
0180:                        IntegrityCheckReport.Severity.INFO, null,
0181:                        IntegrityCheckReport.Error.NO_ERROR,
0182:                        "manifestsParsingStart", //$NON-NLS-1$
0183:                        null));
0184:                for (URL url : manifests) {
0185:                    ModelPluginManifest model;
0186:                    try {
0187:                        model = manifestParser.parseManifest(url);
0188:                    } catch (Exception e) {
0189:                        log.error("can't parse manifest file " + url, e); //$NON-NLS-1$
0190:                        if (stopOnError) {
0191:                            throw new ManifestProcessingException(PACKAGE_NAME,
0192:                                    "manifestParsingError", url, e); //$NON-NLS-1$
0193:                        }
0194:                        registrationReport
0195:                                .add(new ReportItemImpl(
0196:                                        IntegrityCheckReport.Severity.ERROR,
0197:                                        null,
0198:                                        IntegrityCheckReport.Error.MANIFEST_PROCESSING_FAILED,
0199:                                        "manifestParsingError", new Object[] { url, e })); //$NON-NLS-1$
0200:                        continue;
0201:                    }
0202:                    if (model instanceof  ModelPluginFragment) {
0203:                        fragments.put(url.toExternalForm(), model);
0204:                        continue;
0205:                    }
0206:                    if (!(model instanceof  ModelPluginDescriptor)) {
0207:                        log.warn("URL " + url //$NON-NLS-1$
0208:                                + " points to XML document of unknown type"); //$NON-NLS-1$
0209:                        continue;
0210:                    }
0211:                    plugins.put(url.toExternalForm(), model);
0212:                }
0213:                if (log.isDebugEnabled()) {
0214:                    log
0215:                            .debug("manifest files parsed, plugins.size=" + plugins.size() //$NON-NLS-1$
0216:                                    + ", fragments.size=" + fragments.size()); //$NON-NLS-1$
0217:                }
0218:                registrationReport.add(new ReportItemImpl(
0219:                        IntegrityCheckReport.Severity.INFO, null,
0220:                        IntegrityCheckReport.Error.NO_ERROR,
0221:                        "manifestsParsingFinish", //$NON-NLS-1$
0222:                        new Object[] { Integer.valueOf(plugins.size()),
0223:                                Integer.valueOf(fragments.size()) }));
0224:                checkVersions(plugins);
0225:                if (log.isDebugEnabled()) {
0226:                    log.debug("plug-ins versions checked, plugins.size=" //$NON-NLS-1$
0227:                            + plugins.size());
0228:                }
0229:                checkVersions(fragments);
0230:                if (log.isDebugEnabled()) {
0231:                    log
0232:                            .debug("plug-in fragments versions checked, fragments.size=" //$NON-NLS-1$
0233:                                    + fragments.size());
0234:                }
0235:                RegistryChangeDataImpl registryChangeData = new RegistryChangeDataImpl();
0236:                // registering new plug-ins
0237:                registrationReport.add(new ReportItemImpl(
0238:                        IntegrityCheckReport.Severity.INFO, null,
0239:                        IntegrityCheckReport.Error.NO_ERROR,
0240:                        "registeringPluginsStart", null)); //$NON-NLS-1$
0241:                for (ModelPluginManifest model : plugins.values()) {
0242:                    PluginDescriptor descr = registerPlugin(
0243:                            (ModelPluginDescriptor) model, registryChangeData);
0244:                    if (descr != null) {
0245:                        result.put(descr.getLocation().toExternalForm(), descr);
0246:                    }
0247:                }
0248:                plugins.clear();
0249:                // registering new plug-in fragments
0250:                registrationReport.add(new ReportItemImpl(
0251:                        IntegrityCheckReport.Severity.INFO, null,
0252:                        IntegrityCheckReport.Error.NO_ERROR,
0253:                        "registeringFragmentsStart", null)); //$NON-NLS-1$
0254:                for (ModelPluginManifest entry : fragments.values()) {
0255:                    PluginFragment fragment = registerFragment(
0256:                            (ModelPluginFragment) entry, registryChangeData);
0257:                    if (fragment != null) {
0258:                        result.put(fragment.getLocation().toExternalForm(),
0259:                                fragment);
0260:                    }
0261:                }
0262:                fragments.clear();
0263:                registrationReport.add(new ReportItemImpl(
0264:                        IntegrityCheckReport.Severity.INFO, null,
0265:                        IntegrityCheckReport.Error.NO_ERROR,
0266:                        "registeringPluginsFinish", //$NON-NLS-1$
0267:                        Integer.valueOf(registeredPlugins.size())));
0268:                registrationReport.add(new ReportItemImpl(
0269:                        IntegrityCheckReport.Severity.INFO, null,
0270:                        IntegrityCheckReport.Error.NO_ERROR,
0271:                        "registeringFragmentsFinish", //$NON-NLS-1$
0272:                        Integer.valueOf(registeredFragments.size())));
0273:                log.info("plug-in and fragment descriptors registered - " //$NON-NLS-1$
0274:                        + result.size());
0275:                dump();
0276:                if (result.isEmpty()) {
0277:                    return result;
0278:                }
0279:                // notify all interested members that plug-ins set has been changed
0280:                for (ExtensionPoint extensionPoint : registeredPoints) {
0281:                    ((ExtensionPointImpl) extensionPoint).registryChanged();
0282:                }
0283:                for (Extension extension : registeredExtensions.values()) {
0284:                    ((ExtensionImpl) extension).registryChanged();
0285:                }
0286:                if (!listeners.isEmpty() || log.isDebugEnabled()) {
0287:                    // analyze changes in extensions set
0288:                    for (PluginDescriptor pluginDescriptor : registeredPlugins
0289:                            .values()) {
0290:                        for (ExtensionPoint extensionPoint : pluginDescriptor
0291:                                .getExtensionPoints()) {
0292:                            for (Extension ext : extensionPoint
0293:                                    .getConnectedExtensions()) {
0294:                                if (!registeredExtensions.containsKey(ext
0295:                                        .getUniqueId())) {
0296:                                    registryChangeData.putAddedExtension(ext
0297:                                            .getUniqueId(), makeUniqueId(ext
0298:                                            .getExtendedPluginId(), ext
0299:                                            .getExtendedPointId()));
0300:                                } else {
0301:                                    registeredExtensions.remove(ext
0302:                                            .getUniqueId());
0303:                                    if (registryChangeData
0304:                                            .modifiedPlugins()
0305:                                            .contains(
0306:                                                    ext
0307:                                                            .getDeclaringPluginDescriptor()
0308:                                                            .getId())
0309:                                            || registryChangeData
0310:                                                    .modifiedPlugins()
0311:                                                    .contains(
0312:                                                            ext
0313:                                                                    .getExtendedPluginId())) {
0314:                                        registryChangeData
0315:                                                .putModifiedExtension(
0316:                                                        ext.getUniqueId(),
0317:                                                        makeUniqueId(
0318:                                                                ext
0319:                                                                        .getExtendedPluginId(),
0320:                                                                ext
0321:                                                                        .getExtendedPointId()));
0322:                                    }
0323:                                }
0324:                            }
0325:                        }
0326:                    }
0327:                    for (Extension ext : registeredExtensions.values()) {
0328:                        registryChangeData.putRemovedExtension(ext
0329:                                .getUniqueId(), makeUniqueId(ext
0330:                                .getExtendedPluginId(), ext
0331:                                .getExtendedPointId()));
0332:                    }
0333:                    // fire event
0334:                    fireEvent(registryChangeData);
0335:                }
0336:                return result;
0337:            }
0338:
0339:            private void checkVersions(
0340:                    final Map<String, ModelPluginManifest> plugins)
0341:                    throws ManifestProcessingException {
0342:                Map<String, Object[]> versions = new HashMap<String, Object[]>(); //<ID, [Version, URL]>
0343:                Set<String> toBeRemovedUrls = new HashSet<String>();
0344:                for (Iterator<Map.Entry<String, ModelPluginManifest>> it = plugins
0345:                        .entrySet().iterator(); it.hasNext();) {
0346:                    Map.Entry<String, ModelPluginManifest> entry = it.next();
0347:                    String url = entry.getKey();
0348:                    ModelPluginManifest model = entry.getValue();
0349:                    if (registeredPlugins.containsKey(model.getId())) {
0350:                        if (stopOnError) {
0351:                            throw new ManifestProcessingException(PACKAGE_NAME,
0352:                                    "duplicatePlugin", //$NON-NLS-1$
0353:                                    model.getId());
0354:                        }
0355:                        it.remove();
0356:                        registrationReport
0357:                                .add(new ReportItemImpl(
0358:                                        IntegrityCheckReport.Severity.ERROR,
0359:                                        null,
0360:                                        IntegrityCheckReport.Error.MANIFEST_PROCESSING_FAILED,
0361:                                        "duplicatedPluginId", model.getId())); //$NON-NLS-1$
0362:                        continue;
0363:                    }
0364:                    if (registeredFragments.containsKey(model.getId())) {
0365:                        if (stopOnError) {
0366:                            throw new ManifestProcessingException(PACKAGE_NAME,
0367:                                    "duplicatePluginFragment", //$NON-NLS-1$
0368:                                    model.getId());
0369:                        }
0370:                        it.remove();
0371:                        registrationReport
0372:                                .add(new ReportItemImpl(
0373:                                        IntegrityCheckReport.Severity.ERROR,
0374:                                        null,
0375:                                        IntegrityCheckReport.Error.MANIFEST_PROCESSING_FAILED,
0376:                                        "duplicatedFragmentId", model.getId())); //$NON-NLS-1$
0377:                        continue;
0378:                    }
0379:                    Object[] version = versions.get(model.getId());
0380:                    if (version == null) {
0381:                        versions.put(model.getId(), new Object[] {
0382:                                model.getVersion(), url });
0383:                        continue;
0384:                    }
0385:                    if (((Version) version[0]).compareTo(model.getVersion()) < 0) {
0386:                        toBeRemovedUrls.add((String) version[1]);
0387:                        versions.put(model.getId(), new Object[] {
0388:                                model.getVersion(), url });
0389:                    } else {
0390:                        toBeRemovedUrls.add(url);
0391:                    }
0392:                }
0393:                versions.clear();
0394:                for (String url : toBeRemovedUrls) {
0395:                    plugins.remove(url);
0396:                }
0397:                toBeRemovedUrls.clear();
0398:            }
0399:
0400:            private PluginDescriptor registerPlugin(
0401:                    final ModelPluginDescriptor model,
0402:                    final RegistryChangeDataImpl registryChangeData)
0403:                    throws ManifestProcessingException {
0404:                if (log.isDebugEnabled()) {
0405:                    log
0406:                            .debug("registering plug-in, URL - " + model.getLocation()); //$NON-NLS-1$
0407:                }
0408:                PluginDescriptorImpl result = null;
0409:                try {
0410:                    result = new PluginDescriptorImpl(this , model);
0411:                    registryChangeData.addedPlugins().add(result.getId());
0412:                    // applying fragments to the new plug-in
0413:                    for (PluginFragment pluginFragment : registeredFragments
0414:                            .values()) {
0415:                        PluginFragmentImpl fragment = (PluginFragmentImpl) pluginFragment;
0416:                        if (fragment.matches(result)) {
0417:                            result.registerFragment(fragment);
0418:                        }
0419:                    }
0420:                    registrationReport.add(new ReportItemImpl(
0421:                            IntegrityCheckReport.Severity.INFO, null,
0422:                            IntegrityCheckReport.Error.NO_ERROR,
0423:                            "pluginRegistered", result.getUniqueId())); //$NON-NLS-1$
0424:                } catch (ManifestProcessingException mpe) {
0425:                    log.error("failed registering plug-in, URL - " //$NON-NLS-1$
0426:                            + model.getLocation(), mpe);
0427:                    if (stopOnError) {
0428:                        throw mpe;
0429:                    }
0430:                    registrationReport
0431:                            .add(new ReportItemImpl(
0432:                                    IntegrityCheckReport.Severity.ERROR,
0433:                                    null,
0434:                                    IntegrityCheckReport.Error.MANIFEST_PROCESSING_FAILED,
0435:                                    "pluginRegistrationFailed", //$NON-NLS-1$
0436:                                    new Object[] { model.getLocation(), mpe }));
0437:                    return null;
0438:                }
0439:                registeredPlugins.put(result.getId(), result);
0440:                return result;
0441:            }
0442:
0443:            private PluginFragment registerFragment(
0444:                    final ModelPluginFragment model,
0445:                    final RegistryChangeDataImpl registryChangeData)
0446:                    throws ManifestProcessingException {
0447:                if (log.isDebugEnabled()) {
0448:                    log.debug("registering plug-in fragment descriptor, URL - " //$NON-NLS-1$
0449:                            + model.getLocation());
0450:                }
0451:                PluginFragmentImpl result = null;
0452:                try {
0453:                    result = new PluginFragmentImpl(this , model);
0454:                    // register fragment with all matches plug-ins
0455:                    boolean isRegistered = false;
0456:                    PluginDescriptorImpl descr = (PluginDescriptorImpl) getPluginDescriptor(result
0457:                            .getPluginId());
0458:                    if (result.matches(descr)) {
0459:                        descr.registerFragment(result);
0460:                        if (!registryChangeData.addedPlugins().contains(
0461:                                descr.getId())) {
0462:                            registryChangeData.modifiedPlugins().add(
0463:                                    descr.getId());
0464:                        }
0465:                        isRegistered = true;
0466:                    }
0467:                    if (!isRegistered) {
0468:                        log.warn("no matching plug-ins found for fragment " //$NON-NLS-1$
0469:                                + result.getUniqueId());
0470:                        registrationReport.add(new ReportItemImpl(
0471:                                IntegrityCheckReport.Severity.WARNING, null,
0472:                                IntegrityCheckReport.Error.NO_ERROR,
0473:                                "noMatchingPluginFound", result.getUniqueId())); //$NON-NLS-1$
0474:                    }
0475:                    registrationReport.add(new ReportItemImpl(
0476:                            IntegrityCheckReport.Severity.INFO, null,
0477:                            IntegrityCheckReport.Error.NO_ERROR,
0478:                            "fragmentRegistered", result.getUniqueId())); //$NON-NLS-1$
0479:                } catch (ManifestProcessingException mpe) {
0480:                    log.error(
0481:                            "failed registering plug-in fragment descriptor, URL - " //$NON-NLS-1$
0482:                                    + model.getLocation(), mpe);
0483:                    if (stopOnError) {
0484:                        throw mpe;
0485:                    }
0486:                    registrationReport
0487:                            .add(new ReportItemImpl(
0488:                                    IntegrityCheckReport.Severity.ERROR,
0489:                                    null,
0490:                                    IntegrityCheckReport.Error.MANIFEST_PROCESSING_FAILED,
0491:                                    "fragmentRegistrationFailed", //$NON-NLS-1$
0492:                                    new Object[] { model.getLocation(), mpe }));
0493:                    return null;
0494:                }
0495:                registeredFragments.put(result.getId(), result);
0496:                return result;
0497:            }
0498:
0499:            /**
0500:             * @see org.java.plugin.registry.PluginRegistry#unregister(java.lang.String[])
0501:             */
0502:            public Collection<String> unregister(final String[] ids) {
0503:                // collecting registered extension points and extensions
0504:                final List<ExtensionPoint> registeredPoints = new LinkedList<ExtensionPoint>();
0505:                final Map<String, Extension> registeredExtensions = new HashMap<String, Extension>();
0506:                for (PluginDescriptor pluginDescriptor : registeredPlugins
0507:                        .values()) {
0508:                    for (ExtensionPoint point : pluginDescriptor
0509:                            .getExtensionPoints()) {
0510:                        registeredPoints.add(point);
0511:                        for (Extension ext : point.getConnectedExtensions()) {
0512:                            registeredExtensions.put(ext.getUniqueId(), ext);
0513:                        }
0514:                    }
0515:                }
0516:                final Set<String> result = new HashSet<String>();
0517:                RegistryChangeDataImpl registryChangeData = new RegistryChangeDataImpl();
0518:                // collect objects to be unregistered
0519:                registrationReport.add(new ReportItemImpl(
0520:                        IntegrityCheckReport.Severity.INFO, null,
0521:                        IntegrityCheckReport.Error.NO_ERROR,
0522:                        "unregisteringPrepare", //$NON-NLS-1$
0523:                        null));
0524:                Map<String, PluginDescriptor> removingPlugins = new HashMap<String, PluginDescriptor>();
0525:                Map<String, PluginFragment> removingFragments = new HashMap<String, PluginFragment>();
0526:                for (String element : ids) {
0527:                    PluginDescriptor descr = registeredPlugins.get(element);
0528:                    if (descr != null) {
0529:                        for (PluginDescriptor depDescr : getDependingPlugins(descr)) {
0530:                            removingPlugins.put(depDescr.getId(), depDescr);
0531:                            registryChangeData.removedPlugins().add(
0532:                                    depDescr.getId());
0533:                        }
0534:                        removingPlugins.put(descr.getId(), descr);
0535:                        registryChangeData.removedPlugins().add(descr.getId());
0536:                        continue;
0537:                    }
0538:                    PluginFragment fragment = registeredFragments.get(element);
0539:                    if (fragment != null) {
0540:                        removingFragments.put(fragment.getId(), fragment);
0541:                        continue;
0542:                    }
0543:                    registrationReport.add(new ReportItemImpl(
0544:                            IntegrityCheckReport.Severity.WARNING, null,
0545:                            IntegrityCheckReport.Error.NO_ERROR,
0546:                            "pluginToUngregisterNotFound", element)); //$NON-NLS-1$
0547:                }
0548:                for (PluginDescriptor descr : removingPlugins.values()) {
0549:                    for (PluginFragment fragment : descr.getFragments()) {
0550:                        if (removingFragments.containsKey(fragment.getId())) {
0551:                            continue;
0552:                        }
0553:                        removingFragments.put(fragment.getId(), fragment);
0554:                    }
0555:                }
0556:                // notify about plug-ins removal first
0557:                fireEvent(registryChangeData);
0558:                registrationReport.add(new ReportItemImpl(
0559:                        IntegrityCheckReport.Severity.INFO, null,
0560:                        IntegrityCheckReport.Error.NO_ERROR,
0561:                        "unregisteringFragmentsStart", null)); //$NON-NLS-1$
0562:                for (PluginFragment pluginFragment : removingFragments.values()) {
0563:                    PluginFragmentImpl fragment = (PluginFragmentImpl) pluginFragment;
0564:                    unregisterFragment(fragment);
0565:                    if (!removingPlugins.containsKey(fragment.getPluginId())) {
0566:                        registryChangeData.modifiedPlugins().add(
0567:                                fragment.getPluginId());
0568:                    }
0569:                    result.add(fragment.getUniqueId());
0570:                }
0571:                removingFragments.clear();
0572:                registrationReport.add(new ReportItemImpl(
0573:                        IntegrityCheckReport.Severity.INFO, null,
0574:                        IntegrityCheckReport.Error.NO_ERROR,
0575:                        "unregisteringPluginsStart", null)); //$NON-NLS-1$
0576:                for (PluginDescriptor pluginDescriptor : removingPlugins
0577:                        .values()) {
0578:                    PluginDescriptorImpl descr = (PluginDescriptorImpl) pluginDescriptor;
0579:                    unregisterPlugin(descr);
0580:                    result.add(descr.getUniqueId());
0581:                }
0582:                removingPlugins.clear();
0583:                registrationReport.add(new ReportItemImpl(
0584:                        IntegrityCheckReport.Severity.INFO, null,
0585:                        IntegrityCheckReport.Error.NO_ERROR,
0586:                        "unregisteringPluginsFinish", //$NON-NLS-1$
0587:                        Integer.valueOf(registeredPlugins.size())));
0588:                registrationReport.add(new ReportItemImpl(
0589:                        IntegrityCheckReport.Severity.INFO, null,
0590:                        IntegrityCheckReport.Error.NO_ERROR,
0591:                        "unregisteringFragmentsFinish", //$NON-NLS-1$
0592:                        Integer.valueOf(registeredFragments.size())));
0593:                log.info("plug-in and fragment descriptors unregistered - " //$NON-NLS-1$
0594:                        + result.size());
0595:                dump();
0596:                if (result.isEmpty()) {
0597:                    return result;
0598:                }
0599:                // notify all interested members that plug-ins set has been changed
0600:                for (ExtensionPoint extensionPoint : registeredPoints) {
0601:                    ((ExtensionPointImpl) extensionPoint).registryChanged();
0602:                }
0603:                for (Extension extension : registeredExtensions.values()) {
0604:                    ((ExtensionImpl) extension).registryChanged();
0605:                }
0606:                if (!listeners.isEmpty() || log.isDebugEnabled()) {
0607:                    // analyze changes in extensions set
0608:                    for (PluginDescriptor descriptor : registeredPlugins
0609:                            .values()) {
0610:                        for (ExtensionPoint point : descriptor
0611:                                .getExtensionPoints()) {
0612:                            for (Extension ext : point.getConnectedExtensions()) {
0613:                                if (!registeredExtensions.containsKey(ext
0614:                                        .getUniqueId())) {
0615:                                    registryChangeData.putAddedExtension(ext
0616:                                            .getUniqueId(), makeUniqueId(ext
0617:                                            .getExtendedPluginId(), ext
0618:                                            .getExtendedPointId()));
0619:                                } else {
0620:                                    registeredExtensions.remove(ext
0621:                                            .getUniqueId());
0622:                                    if (registryChangeData
0623:                                            .modifiedPlugins()
0624:                                            .contains(
0625:                                                    ext
0626:                                                            .getDeclaringPluginDescriptor()
0627:                                                            .getId())
0628:                                            || registryChangeData
0629:                                                    .modifiedPlugins()
0630:                                                    .contains(
0631:                                                            ext
0632:                                                                    .getExtendedPluginId())) {
0633:                                        registryChangeData
0634:                                                .putModifiedExtension(
0635:                                                        ext.getUniqueId(),
0636:                                                        makeUniqueId(
0637:                                                                ext
0638:                                                                        .getExtendedPluginId(),
0639:                                                                ext
0640:                                                                        .getExtendedPointId()));
0641:                                    }
0642:                                }
0643:                            }
0644:                        }
0645:                    }
0646:                    for (Extension ext : registeredExtensions.values()) {
0647:                        registryChangeData.putRemovedExtension(ext
0648:                                .getUniqueId(), makeUniqueId(ext
0649:                                .getExtendedPluginId(), ext
0650:                                .getExtendedPointId()));
0651:                    }
0652:                    // fire event
0653:                    fireEvent(registryChangeData);
0654:                }
0655:                return result;
0656:            }
0657:
0658:            private void unregisterPlugin(final PluginDescriptorImpl descr) {
0659:                registeredPlugins.remove(descr.getId());
0660:                registrationReport.add(new ReportItemImpl(
0661:                        IntegrityCheckReport.Severity.INFO, null,
0662:                        IntegrityCheckReport.Error.NO_ERROR,
0663:                        "pluginUnregistered", descr.getUniqueId())); //$NON-NLS-1$
0664:            }
0665:
0666:            private void unregisterFragment(final PluginFragmentImpl fragment) {
0667:                PluginDescriptorImpl descr = (PluginDescriptorImpl) registeredPlugins
0668:                        .get(fragment.getPluginId());
0669:                if (descr != null) {
0670:                    descr.unregisterFragment(fragment);
0671:                }
0672:                registeredFragments.remove(fragment.getId());
0673:                registrationReport.add(new ReportItemImpl(
0674:                        IntegrityCheckReport.Severity.INFO, null,
0675:                        IntegrityCheckReport.Error.NO_ERROR,
0676:                        "fragmentUnregistered", fragment.getUniqueId())); //$NON-NLS-1$
0677:            }
0678:
0679:            private void dump() {
0680:                if (!log.isDebugEnabled()) {
0681:                    return;
0682:                }
0683:                StringBuilder buf = new StringBuilder();
0684:                buf
0685:                        .append("PLUG-IN REGISTRY DUMP:\r\n") //$NON-NLS-1$
0686:                        .append(
0687:                                "-------------- DUMP BEGIN -----------------\r\n") //$NON-NLS-1$
0688:                        .append("\tPlug-ins: " + registeredPlugins.size() //$NON-NLS-1$
0689:                                + "\r\n"); //$NON-NLS-1$
0690:                for (PluginDescriptor descriptor : registeredPlugins.values()) {
0691:                    buf.append("\t\t") //$NON-NLS-1$
0692:                            .append(descriptor).append("\r\n"); //$NON-NLS-1$
0693:                }
0694:                buf.append("\tFragments: " + registeredFragments.size() //$NON-NLS-1$
0695:                        + "\r\n"); //$NON-NLS-1$
0696:                for (PluginFragment fragment : registeredFragments.values()) {
0697:                    buf.append("\t\t") //$NON-NLS-1$
0698:                            .append(fragment).append("\r\n"); //$NON-NLS-1$
0699:                }
0700:                buf.append("Memory TOTAL/FREE/MAX: ") //$NON-NLS-1$
0701:                        .append(Runtime.getRuntime().totalMemory()).append("/") //$NON-NLS-1$
0702:                        .append(Runtime.getRuntime().freeMemory()).append("/") //$NON-NLS-1$
0703:                        .append(Runtime.getRuntime().maxMemory())
0704:                        .append("\r\n"); //$NON-NLS-1$
0705:                buf.append("-------------- DUMP END -----------------\r\n"); //$NON-NLS-1$
0706:                log.debug(buf.toString());
0707:            }
0708:
0709:            /**
0710:             * @see org.java.plugin.registry.PluginRegistry#getExtensionPoint(
0711:             *      java.lang.String, java.lang.String)
0712:             */
0713:            public ExtensionPoint getExtensionPoint(final String pluginId,
0714:                    final String pointId) {
0715:                PluginDescriptor descriptor = registeredPlugins.get(pluginId);
0716:                if (descriptor == null) {
0717:                    throw new IllegalArgumentException("unknown plug-in ID " //$NON-NLS-1$
0718:                            + pluginId
0719:                            + " provided for extension point " + pointId); //$NON-NLS-1$
0720:                }
0721:                for (ExtensionPoint point : descriptor.getExtensionPoints()) {
0722:                    if (point.getId().equals(pointId)) {
0723:                        if (point.isValid()) {
0724:                            return point;
0725:                        }
0726:                        log.warn("extension point " + point.getUniqueId() //$NON-NLS-1$
0727:                                + " is invalid and ignored by registry"); //$NON-NLS-1$
0728:                        break;
0729:                    }
0730:                }
0731:                throw new IllegalArgumentException(
0732:                        "unknown extension point ID - " //$NON-NLS-1$
0733:                                + makeUniqueId(pluginId, pointId));
0734:            }
0735:
0736:            /**
0737:             * @see org.java.plugin.registry.PluginRegistry#getExtensionPoint(java.lang.String)
0738:             */
0739:            public ExtensionPoint getExtensionPoint(final String uniqueId) {
0740:                return getExtensionPoint(extractPluginId(uniqueId),
0741:                        extractId(uniqueId));
0742:            }
0743:
0744:            /**
0745:             * @see org.java.plugin.registry.PluginRegistry#isExtensionPointAvailable(
0746:             *      java.lang.String, java.lang.String)
0747:             */
0748:            public boolean isExtensionPointAvailable(final String pluginId,
0749:                    final String pointId) {
0750:                PluginDescriptor descriptor = registeredPlugins.get(pluginId);
0751:                if (descriptor == null) {
0752:                    return false;
0753:                }
0754:                for (ExtensionPoint point : descriptor.getExtensionPoints()) {
0755:                    if (point.getId().equals(pointId)) {
0756:                        return point.isValid();
0757:                    }
0758:                }
0759:                return false;
0760:            }
0761:
0762:            /**
0763:             * @see org.java.plugin.registry.PluginRegistry#isExtensionPointAvailable(
0764:             *      java.lang.String)
0765:             */
0766:            public boolean isExtensionPointAvailable(final String uniqueId) {
0767:                return isExtensionPointAvailable(extractPluginId(uniqueId),
0768:                        extractId(uniqueId));
0769:            }
0770:
0771:            /**
0772:             * @see org.java.plugin.registry.PluginRegistry#getPluginDescriptor(java.lang.String)
0773:             */
0774:            public PluginDescriptor getPluginDescriptor(final String pluginId) {
0775:                PluginDescriptor result = registeredPlugins.get(pluginId);
0776:                if (result == null) {
0777:                    throw new IllegalArgumentException("unknown plug-in ID - " //$NON-NLS-1$
0778:                            + pluginId);
0779:                }
0780:                return result;
0781:            }
0782:
0783:            /**
0784:             * @see org.java.plugin.registry.PluginRegistry#isPluginDescriptorAvailable(java.lang.String)
0785:             */
0786:            public boolean isPluginDescriptorAvailable(final String pluginId) {
0787:                return registeredPlugins.containsKey(pluginId);
0788:            }
0789:
0790:            /**
0791:             * @see org.java.plugin.registry.PluginRegistry#getPluginDescriptors()
0792:             */
0793:            public Collection<PluginDescriptor> getPluginDescriptors() {
0794:                final Collection<PluginDescriptor> empty_collection = Collections
0795:                        .emptyList();
0796:                return registeredPlugins.isEmpty() ? empty_collection
0797:                        : Collections.unmodifiableCollection(registeredPlugins
0798:                                .values());
0799:            }
0800:
0801:            /**
0802:             * @see org.java.plugin.registry.PluginRegistry#getPluginFragments()
0803:             */
0804:            public Collection<PluginFragment> getPluginFragments() {
0805:                final Collection<PluginFragment> empty_collection = Collections
0806:                        .emptyList();
0807:                return registeredFragments.isEmpty() ? empty_collection
0808:                        : Collections
0809:                                .unmodifiableCollection(registeredFragments
0810:                                        .values());
0811:            }
0812:
0813:            /**
0814:             * @see org.java.plugin.registry.PluginRegistry#getDependingPlugins(
0815:             *      org.java.plugin.registry.PluginDescriptor)
0816:             */
0817:            public Collection<PluginDescriptor> getDependingPlugins(
0818:                    final PluginDescriptor descr) {
0819:                Map<String, PluginDescriptor> result = new HashMap<String, PluginDescriptor>();
0820:                for (PluginDescriptor dependedDescr : getPluginDescriptors()) {
0821:                    if (dependedDescr.getId().equals(descr.getId())) {
0822:                        continue;
0823:                    }
0824:                    for (PluginPrerequisite pre : dependedDescr
0825:                            .getPrerequisites()) {
0826:                        if (!pre.getPluginId().equals(descr.getId())
0827:                                || !pre.matches()) {
0828:                            continue;
0829:                        }
0830:                        if (!result.containsKey(dependedDescr.getId())) {
0831:                            result.put(dependedDescr.getId(), dependedDescr);
0832:                            for (PluginDescriptor descriptor : getDependingPlugins(dependedDescr)) {
0833:                                if (!result.containsKey(descriptor.getId())) {
0834:                                    result.put(descriptor.getId(), descriptor);
0835:                                }
0836:                            }
0837:                        }
0838:                        break;
0839:                    }
0840:                }
0841:                return result.values();
0842:            }
0843:
0844:            /**
0845:             * @see org.java.plugin.registry.PluginRegistry#checkIntegrity(
0846:             *      org.java.plugin.PathResolver)
0847:             */
0848:            public IntegrityCheckReport checkIntegrity(
0849:                    final PathResolver pathResolver) {
0850:                return checkIntegrity(pathResolver, false);
0851:            }
0852:
0853:            /**
0854:             * @see org.java.plugin.registry.PluginRegistry#checkIntegrity(
0855:             *      org.java.plugin.PathResolver, boolean)
0856:             */
0857:            public IntegrityCheckReport checkIntegrity(
0858:                    final PathResolver pathResolver,
0859:                    final boolean includeRegistrationReport) {
0860:                final Collection<ReportItem> empty_collection = Collections
0861:                        .emptyList();
0862:                IntegrityChecker intergityCheckReport = new IntegrityChecker(
0863:                        this , includeRegistrationReport ? registrationReport
0864:                                : empty_collection);
0865:                intergityCheckReport.doCheck(pathResolver);
0866:                return intergityCheckReport;
0867:            }
0868:
0869:            /**
0870:             * @see org.java.plugin.registry.PluginRegistry#getRegistrationReport()
0871:             */
0872:            public IntegrityCheckReport getRegistrationReport() {
0873:                return new IntegrityChecker(this , registrationReport);
0874:            }
0875:
0876:            /**
0877:             * @see org.java.plugin.registry.PluginRegistry#makeUniqueId(
0878:             *      java.lang.String, java.lang.String)
0879:             */
0880:            public String makeUniqueId(final String pluginId, final String id) {
0881:                return pluginId + UNIQUE_SEPARATOR + id;
0882:            }
0883:
0884:            /**
0885:             * @see org.java.plugin.registry.PluginRegistry#makeUniqueId(
0886:             *      java.lang.String, org.java.plugin.registry.Version)
0887:             */
0888:            public String makeUniqueId(final String pluginId,
0889:                    final Version version) {
0890:                return pluginId + UNIQUE_SEPARATOR + version;
0891:            }
0892:
0893:            /**
0894:             * @see org.java.plugin.registry.PluginRegistry#extractPluginId(java.lang.String)
0895:             */
0896:            public String extractPluginId(final String uniqueId) {
0897:                int p = uniqueId.indexOf(UNIQUE_SEPARATOR);
0898:                if ((p <= 0) || (p >= (uniqueId.length() - 1))) {
0899:                    throw new IllegalArgumentException("invalid unique ID - " //$NON-NLS-1$
0900:                            + uniqueId);
0901:                }
0902:                return uniqueId.substring(0, p);
0903:            }
0904:
0905:            /**
0906:             * @see org.java.plugin.registry.PluginRegistry#extractId(java.lang.String)
0907:             */
0908:            public String extractId(final String uniqueId) {
0909:                int p = uniqueId.indexOf(UNIQUE_SEPARATOR);
0910:                if ((p <= 0) || (p >= (uniqueId.length() - 1))) {
0911:                    throw new IllegalArgumentException("invalid unique ID - " //$NON-NLS-1$
0912:                            + uniqueId);
0913:                }
0914:                return uniqueId.substring(p + 1);
0915:            }
0916:
0917:            /**
0918:             * @see org.java.plugin.registry.PluginRegistry#extractVersion(java.lang.String)
0919:             */
0920:            public Version extractVersion(final String uniqueId) {
0921:                int p = uniqueId.indexOf(UNIQUE_SEPARATOR);
0922:                if ((p <= 0) || (p >= (uniqueId.length() - 1))) {
0923:                    throw new IllegalArgumentException("invalid unique ID - " //$NON-NLS-1$
0924:                            + uniqueId);
0925:                }
0926:                return Version.parse(uniqueId.substring(p + 1));
0927:            }
0928:
0929:            /**
0930:             * @see org.java.plugin.registry.PluginRegistry#registerListener(
0931:             *      org.java.plugin.registry.PluginRegistry.RegistryChangeListener)
0932:             */
0933:            public void registerListener(final RegistryChangeListener listener) {
0934:                if (listeners.contains(listener)) {
0935:                    throw new IllegalArgumentException("listener " + listener //$NON-NLS-1$
0936:                            + " already registered"); //$NON-NLS-1$
0937:                }
0938:                listeners.add(listener);
0939:            }
0940:
0941:            /**
0942:             * @see org.java.plugin.registry.PluginRegistry#unregisterListener(
0943:             *      org.java.plugin.registry.PluginRegistry.RegistryChangeListener)
0944:             */
0945:            public void unregisterListener(final RegistryChangeListener listener) {
0946:                if (!listeners.remove(listener)) {
0947:                    log.warn("unknown listener " + listener); //$NON-NLS-1$
0948:                }
0949:            }
0950:
0951:            void fireEvent(final RegistryChangeDataImpl data) {
0952:                data.dump();
0953:                if (listeners.isEmpty()) {
0954:                    return;
0955:                }
0956:                // make local copy
0957:                RegistryChangeListener[] arr = listeners
0958:                        .toArray(new RegistryChangeListener[listeners.size()]);
0959:                data.beforeEventFire();
0960:                if (log.isDebugEnabled()) {
0961:                    log.debug("propagating registry change event"); //$NON-NLS-1$
0962:                }
0963:                for (RegistryChangeListener element : arr) {
0964:                    element.registryChanged(data);
0965:                }
0966:                if (log.isDebugEnabled()) {
0967:                    log.debug("registry change event propagated"); //$NON-NLS-1$
0968:                }
0969:                data.afterEventFire();
0970:            }
0971:
0972:            private static final class RegistryChangeDataImpl implements 
0973:                    RegistryChangeData {
0974:                private Set<String> addedPlugins;
0975:                private Set<String> removedPlugins;
0976:                private Set<String> modifiedPlugins;
0977:                private Map<String, String> addedExtensions;
0978:                private Map<String, String> removedExtensions;
0979:                private Map<String, String> modifiedExtensions;
0980:
0981:                protected RegistryChangeDataImpl() {
0982:                    reset();
0983:                }
0984:
0985:                private void reset() {
0986:                    addedPlugins = new HashSet<String>();
0987:                    removedPlugins = new HashSet<String>();
0988:                    modifiedPlugins = new HashSet<String>();
0989:                    addedExtensions = new HashMap<String, String>();
0990:                    removedExtensions = new HashMap<String, String>();
0991:                    modifiedExtensions = new HashMap<String, String>();
0992:                }
0993:
0994:                protected void beforeEventFire() {
0995:                    addedPlugins = Collections.unmodifiableSet(addedPlugins);
0996:                    removedPlugins = Collections
0997:                            .unmodifiableSet(removedPlugins);
0998:                    modifiedPlugins = Collections
0999:                            .unmodifiableSet(modifiedPlugins);
1000:                    addedExtensions = Collections
1001:                            .unmodifiableMap(addedExtensions);
1002:                    removedExtensions = Collections
1003:                            .unmodifiableMap(removedExtensions);
1004:                    modifiedExtensions = Collections
1005:                            .unmodifiableMap(modifiedExtensions);
1006:                }
1007:
1008:                protected void afterEventFire() {
1009:                    reset();
1010:                }
1011:
1012:                protected void dump() {
1013:                    Log logger = LogFactory.getLog(getClass());
1014:                    if (!logger.isDebugEnabled()) {
1015:                        return;
1016:                    }
1017:                    StringBuilder buf = new StringBuilder();
1018:                    buf
1019:                            .append("PLUG-IN REGISTRY CHANGES DUMP:\r\n") //$NON-NLS-1$
1020:                            .append(
1021:                                    "-------------- DUMP BEGIN -----------------\r\n") //$NON-NLS-1$
1022:                            .append("\tAdded plug-ins: " + addedPlugins.size() //$NON-NLS-1$
1023:                                    + "\r\n"); //$NON-NLS-1$
1024:                    for (Object element : addedPlugins) {
1025:                        buf.append("\t\t") //$NON-NLS-1$
1026:                                .append(element).append("\r\n"); //$NON-NLS-1$
1027:                    }
1028:                    buf.append("\tRemoved plug-ins: " + removedPlugins.size() //$NON-NLS-1$
1029:                            + "\r\n"); //$NON-NLS-1$
1030:                    for (Object element : removedPlugins) {
1031:                        buf.append("\t\t") //$NON-NLS-1$
1032:                                .append(element).append("\r\n"); //$NON-NLS-1$
1033:                    }
1034:                    buf.append("\tModified plug-ins: " + modifiedPlugins.size() //$NON-NLS-1$
1035:                            + "\r\n"); //$NON-NLS-1$
1036:                    for (Object element : modifiedPlugins) {
1037:                        buf.append("\t\t") //$NON-NLS-1$
1038:                                .append(element).append("\r\n"); //$NON-NLS-1$
1039:                    }
1040:                    buf.append("\tAdded extensions: " + addedExtensions.size() //$NON-NLS-1$
1041:                            + "\r\n"); //$NON-NLS-1$
1042:                    for (Object element : addedExtensions.entrySet()) {
1043:                        buf.append("\t\t") //$NON-NLS-1$
1044:                                .append(element).append("\r\n"); //$NON-NLS-1$
1045:                    }
1046:                    buf
1047:                            .append("\tRemoved extensions: " + removedExtensions.size() //$NON-NLS-1$
1048:                                    + "\r\n"); //$NON-NLS-1$
1049:                    for (Object element : removedExtensions.entrySet()) {
1050:                        buf.append("\t\t") //$NON-NLS-1$
1051:                                .append(element).append("\r\n"); //$NON-NLS-1$
1052:                    }
1053:                    buf
1054:                            .append("\tModified extensions: " + modifiedExtensions.size() //$NON-NLS-1$
1055:                                    + "\r\n"); //$NON-NLS-1$
1056:                    for (Object element : modifiedExtensions.entrySet()) {
1057:                        buf.append("\t\t") //$NON-NLS-1$
1058:                                .append(element).append("\r\n"); //$NON-NLS-1$
1059:                    }
1060:                    buf.append("Memory TOTAL/FREE/MAX: ") //$NON-NLS-1$
1061:                            .append(Runtime.getRuntime().totalMemory()).append(
1062:                                    "/") //$NON-NLS-1$
1063:                            .append(Runtime.getRuntime().freeMemory()).append(
1064:                                    "/") //$NON-NLS-1$
1065:                            .append(Runtime.getRuntime().maxMemory()).append(
1066:                                    "\r\n"); //$NON-NLS-1$
1067:                    buf.append("-------------- DUMP END -----------------\r\n"); //$NON-NLS-1$
1068:                    logger.debug(buf.toString());
1069:                }
1070:
1071:                /**
1072:                 * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#addedPlugins()
1073:                 */
1074:                public Set<String> addedPlugins() {
1075:                    return addedPlugins;
1076:                }
1077:
1078:                /**
1079:                 * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
1080:                 *      removedPlugins()
1081:                 */
1082:                public Set<String> removedPlugins() {
1083:                    return removedPlugins;
1084:                }
1085:
1086:                /**
1087:                 * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
1088:                 *      modifiedPlugins()
1089:                 */
1090:                public Set<String> modifiedPlugins() {
1091:                    return modifiedPlugins;
1092:                }
1093:
1094:                void putAddedExtension(final String extensionUid,
1095:                        final String extensionPointUid) {
1096:                    addedExtensions.put(extensionUid, extensionPointUid);
1097:                }
1098:
1099:                /**
1100:                 * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
1101:                 *      addedExtensions()
1102:                 */
1103:                public Set<String> addedExtensions() {
1104:                    return addedExtensions.keySet();
1105:                }
1106:
1107:                /**
1108:                 * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
1109:                 *      addedExtensions(java.lang.String)
1110:                 */
1111:                public Set<String> addedExtensions(
1112:                        final String extensionPointUid) {
1113:                    final Set<String> result = new HashSet<String>();
1114:                    Entry<String, String> entry;
1115:                    for (Iterator<Entry<String, String>> it = addedExtensions
1116:                            .entrySet().iterator(); it.hasNext();) {
1117:                        entry = it.next();
1118:                        if (entry.getValue().equals(extensionPointUid)) {
1119:                            result.add(entry.getKey());
1120:                        }
1121:                    }
1122:                    return Collections.unmodifiableSet(result);
1123:                }
1124:
1125:                void putRemovedExtension(final String extensionUid,
1126:                        final String extensionPointUid) {
1127:                    removedExtensions.put(extensionUid, extensionPointUid);
1128:                }
1129:
1130:                /**
1131:                 * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
1132:                 *      removedExtensions()
1133:                 */
1134:                public Set<String> removedExtensions() {
1135:                    return removedExtensions.keySet();
1136:                }
1137:
1138:                /**
1139:                 * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
1140:                 *      removedExtensions(java.lang.String)
1141:                 */
1142:                public Set<String> removedExtensions(
1143:                        final String extensionPointUid) {
1144:                    final Set<String> result = new HashSet<String>();
1145:                    Entry<String, String> entry;
1146:                    for (Iterator<Entry<String, String>> it = removedExtensions
1147:                            .entrySet().iterator(); it.hasNext();) {
1148:                        entry = it.next();
1149:                        if (entry.getValue().equals(extensionPointUid)) {
1150:                            result.add(entry.getKey());
1151:                        }
1152:                    }
1153:                    return Collections.unmodifiableSet(result);
1154:                }
1155:
1156:                void putModifiedExtension(final String extensionUid,
1157:                        final String extensionPointUid) {
1158:                    modifiedExtensions.put(extensionUid, extensionPointUid);
1159:                }
1160:
1161:                /**
1162:                 * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
1163:                 *      modifiedExtensions()
1164:                 */
1165:                public Set<String> modifiedExtensions() {
1166:                    return modifiedExtensions.keySet();
1167:                }
1168:
1169:                /**
1170:                 * @see org.java.plugin.registry.PluginRegistry.RegistryChangeData#
1171:                 *      modifiedExtensions(java.lang.String)
1172:                 */
1173:                public Set<String> modifiedExtensions(
1174:                        final String extensionPointUid) {
1175:                    final Set<String> result = new HashSet<String>();
1176:                    Entry<String, String> entry;
1177:                    for (Iterator<Entry<String, String>> it = modifiedExtensions
1178:                            .entrySet().iterator(); it.hasNext();) {
1179:                        entry = it.next();
1180:                        if (entry.getValue().equals(extensionPointUid)) {
1181:                            result.add(entry.getKey());
1182:                        }
1183:                    }
1184:                    return Collections.unmodifiableSet(result);
1185:                }
1186:            }
1187:
1188:            private static final class ManifestInfoImpl implements  ManifestInfo {
1189:                private final ModelManifestInfo model;
1190:
1191:                ManifestInfoImpl(final ModelManifestInfo aModel) {
1192:                    model = aModel;
1193:                }
1194:
1195:                /**
1196:                 * @see org.java.plugin.registry.ManifestInfo#getId()
1197:                 */
1198:                public String getId() {
1199:                    return model.getId();
1200:                }
1201:
1202:                /**
1203:                 * @see org.java.plugin.registry.ManifestInfo#getVersion()
1204:                 */
1205:                public Version getVersion() {
1206:                    return model.getVersion();
1207:                }
1208:
1209:                /**
1210:                 * @see org.java.plugin.registry.ManifestInfo#getVendor()
1211:                 */
1212:                public String getVendor() {
1213:                    return model.getVendor();
1214:                }
1215:
1216:                /**
1217:                 * @see org.java.plugin.registry.ManifestInfo#getPluginId()
1218:                 */
1219:                public String getPluginId() {
1220:                    return model.getPluginId();
1221:                }
1222:
1223:                /**
1224:                 * @see org.java.plugin.registry.ManifestInfo#getPluginVersion()
1225:                 */
1226:                public Version getPluginVersion() {
1227:                    return model.getPluginVersion();
1228:                }
1229:
1230:                /**
1231:                 * @see org.java.plugin.registry.ManifestInfo#getMatchingRule()
1232:                 */
1233:                public MatchingRule getMatchingRule() {
1234:                    return model.getMatchRule();
1235:                }
1236:            }
1237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.