Source Code Cross Referenced for PluginDescriptorImpl.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) 


001:        /*****************************************************************************
002:         * Java Plug-in Framework (JPF)
003:         * Copyright (C) 2004-2007 Dmitry Olshansky
004:         * 
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * Lesser General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         *****************************************************************************/package org.java.plugin.registry.xml;
019:
020:        import java.net.URL;
021:        import java.util.Collection;
022:        import java.util.Collections;
023:        import java.util.HashMap;
024:        import java.util.Iterator;
025:        import java.util.LinkedList;
026:        import java.util.List;
027:        import java.util.Map;
028:        import java.util.Map.Entry;
029:
030:        import org.java.plugin.registry.Documentation;
031:        import org.java.plugin.registry.Extension;
032:        import org.java.plugin.registry.ExtensionPoint;
033:        import org.java.plugin.registry.Identity;
034:        import org.java.plugin.registry.Library;
035:        import org.java.plugin.registry.ManifestProcessingException;
036:        import org.java.plugin.registry.PluginAttribute;
037:        import org.java.plugin.registry.PluginDescriptor;
038:        import org.java.plugin.registry.PluginFragment;
039:        import org.java.plugin.registry.PluginPrerequisite;
040:        import org.java.plugin.registry.PluginRegistry;
041:        import org.java.plugin.registry.Version;
042:
043:        /**
044:         * @version $Id: PluginDescriptorImpl.java,v 1.4 2007/03/03 17:16:25 ddimon Exp $
045:         */
046:        class PluginDescriptorImpl extends IdentityImpl implements 
047:                PluginDescriptor {
048:            private final PluginRegistry registry;
049:            private final ModelPluginDescriptor model;
050:            private Map<String, PluginPrerequisite> pluginPrerequisites;
051:            private Map<String, Library> libraries;
052:            private Map<String, ExtensionPoint> extensionPoints;
053:            private Map<String, Extension> extensions;
054:            private Documentation<PluginDescriptor> doc;
055:            private List<PluginFragment> fragments;
056:            private List<PluginAttribute> attributes;
057:
058:            PluginDescriptorImpl(final PluginRegistry aRegistry,
059:                    final ModelPluginDescriptor aModel)
060:                    throws ManifestProcessingException {
061:                super (aModel.getId());
062:                registry = aRegistry;
063:                model = aModel;
064:                if (model.getVendor() == null) {
065:                    model.setVendor(""); //$NON-NLS-1$
066:                }
067:                if ((model.getClassName() != null)
068:                        && (model.getClassName().trim().length() == 0)) {
069:                    model.setClassName(null);
070:                }
071:                if ((model.getDocsPath() == null)
072:                        || (model.getDocsPath().trim().length() == 0)) {
073:                    model.setDocsPath("docs"); //$NON-NLS-1$
074:                }
075:                if (model.getDocumentation() != null) {
076:                    doc = new DocumentationImpl<PluginDescriptor>(this , model
077:                            .getDocumentation());
078:                }
079:
080:                attributes = new LinkedList<PluginAttribute>();
081:                fragments = new LinkedList<PluginFragment>();
082:                pluginPrerequisites = new HashMap<String, PluginPrerequisite>();
083:                libraries = new HashMap<String, Library>();
084:                extensionPoints = new HashMap<String, ExtensionPoint>();
085:                extensions = new HashMap<String, Extension>();
086:
087:                processAttributes(null, model);
088:                processPrerequisites(null, model);
089:                processLibraries(null, model);
090:                processExtensionPoints(null, model);
091:                processExtensions(null, model);
092:
093:                if (log.isDebugEnabled()) {
094:                    log.debug("object instantiated: " + this ); //$NON-NLS-1$
095:                }
096:            }
097:
098:            void registerFragment(final PluginFragmentImpl fragment)
099:                    throws ManifestProcessingException {
100:                fragments.add(fragment);
101:                processAttributes(fragment, fragment.getModel());
102:                processPrerequisites(fragment, fragment.getModel());
103:                processLibraries(fragment, fragment.getModel());
104:                processExtensionPoints(fragment, fragment.getModel());
105:                processExtensions(fragment, fragment.getModel());
106:            }
107:
108:            void unregisterFragment(final PluginFragmentImpl fragment) {
109:                // removing attributes
110:                for (Iterator<PluginAttribute> it = attributes.iterator(); it
111:                        .hasNext();) {
112:                    if (fragment.equals(it.next().getDeclaringPluginFragment())) {
113:                        it.remove();
114:                    }
115:                }
116:                // removing prerequisites
117:                for (Iterator<Entry<String, PluginPrerequisite>> it = pluginPrerequisites
118:                        .entrySet().iterator(); it.hasNext();) {
119:                    Entry<String, PluginPrerequisite> entry = it.next();
120:                    if (fragment.equals(entry.getValue()
121:                            .getDeclaringPluginFragment())) {
122:                        it.remove();
123:                    }
124:                }
125:                // removing libraries
126:                for (Iterator<Entry<String, Library>> it = libraries.entrySet()
127:                        .iterator(); it.hasNext();) {
128:                    Entry<String, Library> entry = it.next();
129:                    if (fragment.equals(entry.getValue()
130:                            .getDeclaringPluginFragment())) {
131:                        it.remove();
132:                    }
133:                }
134:                // removing extension points
135:                for (Iterator<Entry<String, ExtensionPoint>> it = extensionPoints
136:                        .entrySet().iterator(); it.hasNext();) {
137:                    Entry<String, ExtensionPoint> entry = it.next();
138:                    if (fragment.equals(entry.getValue()
139:                            .getDeclaringPluginFragment())) {
140:                        it.remove();
141:                    }
142:                }
143:                // removing extensions
144:                for (Iterator<Entry<String, Extension>> it = extensions
145:                        .entrySet().iterator(); it.hasNext();) {
146:                    Entry<String, Extension> entry = it.next();
147:                    if (fragment.equals(entry.getValue()
148:                            .getDeclaringPluginFragment())) {
149:                        it.remove();
150:                    }
151:                }
152:                fragments.remove(fragment);
153:            }
154:
155:            private void processAttributes(final PluginFragmentImpl fragment,
156:                    final ModelPluginManifest modelManifest)
157:                    throws ManifestProcessingException {
158:                for (ModelAttribute modelAttribute : modelManifest
159:                        .getAttributes()) {
160:                    attributes.add(new PluginAttributeImpl(this , fragment,
161:                            modelAttribute, null));
162:                }
163:            }
164:
165:            private void processPrerequisites(
166:                    final PluginFragmentImpl fragment,
167:                    final ModelPluginManifest modelManifest)
168:                    throws ManifestProcessingException {
169:                for (ModelPrerequisite modelPrerequisite : modelManifest
170:                        .getPrerequisites()) {
171:                    PluginPrerequisiteImpl pluginPrerequisite = new PluginPrerequisiteImpl(
172:                            this , fragment, modelPrerequisite);
173:                    if (pluginPrerequisites.containsKey(pluginPrerequisite
174:                            .getPluginId())) {
175:                        throw new ManifestProcessingException(
176:                                PluginRegistryImpl.PACKAGE_NAME,
177:                                "duplicateImports", new Object[] { //$NON-NLS-1$
178:                                pluginPrerequisite.getPluginId(), getId() });
179:                    }
180:                    pluginPrerequisites.put(pluginPrerequisite.getPluginId(),
181:                            pluginPrerequisite);
182:                }
183:            }
184:
185:            private void processLibraries(final PluginFragmentImpl fragment,
186:                    final ModelPluginManifest modelManifest)
187:                    throws ManifestProcessingException {
188:                for (ModelLibrary modelLibrary : modelManifest.getLibraries()) {
189:                    LibraryImpl lib = new LibraryImpl(this , fragment,
190:                            modelLibrary);
191:                    if (libraries.containsKey(lib.getId())) {
192:                        throw new ManifestProcessingException(
193:                                PluginRegistryImpl.PACKAGE_NAME,
194:                                "duplicateLibraries", new Object[] { //$NON-NLS-1$
195:                                lib.getId(), getId() });
196:                    }
197:                    libraries.put(lib.getId(), lib);
198:                }
199:            }
200:
201:            private void processExtensionPoints(
202:                    final PluginFragmentImpl fragment,
203:                    final ModelPluginManifest modelManifest)
204:                    throws ManifestProcessingException {
205:                for (ModelExtensionPoint modelExtensionPoint : modelManifest
206:                        .getExtensionPoints()) {
207:                    ExtensionPointImpl extensionPoint = new ExtensionPointImpl(
208:                            this , fragment, modelExtensionPoint);
209:                    if (extensionPoints.containsKey(extensionPoint.getId())) {
210:                        throw new ManifestProcessingException(
211:                                PluginRegistryImpl.PACKAGE_NAME,
212:                                "duplicateExtensionPoints", new Object[] { //$NON-NLS-1$
213:                                extensionPoint.getId(), getId() });
214:                    }
215:                    extensionPoints.put(extensionPoint.getId(), extensionPoint);
216:                }
217:            }
218:
219:            private void processExtensions(final PluginFragmentImpl fragment,
220:                    final ModelPluginManifest modelManifest)
221:                    throws ManifestProcessingException {
222:                for (ModelExtension modelExtension : modelManifest
223:                        .getExtensions()) {
224:                    ExtensionImpl extension = new ExtensionImpl(this , fragment,
225:                            modelExtension);
226:                    if (extensions.containsKey(extension.getId())) {
227:                        throw new ManifestProcessingException(
228:                                PluginRegistryImpl.PACKAGE_NAME,
229:                                "duplicateExtensions", new Object[] { //$NON-NLS-1$
230:                                extension.getId(), getId() });
231:                    }
232:                    if (!getId().equals(extension.getExtendedPluginId())
233:                            && !pluginPrerequisites.containsKey(extension
234:                                    .getExtendedPluginId())) {
235:                        throw new ManifestProcessingException(
236:                                PluginRegistryImpl.PACKAGE_NAME,
237:                                "pluginNotDeclaredInPrerequisites", new Object[] { //$NON-NLS-1$
238:                                extension.getExtendedPluginId(),
239:                                        extension.getId(), getId() });
240:                    }
241:                    extensions.put(extension.getId(), extension);
242:                }
243:                //extensions = Collections.unmodifiableMap(extensions);
244:            }
245:
246:            /**
247:             * @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
248:             */
249:            public String getUniqueId() {
250:                return registry.makeUniqueId(getId(), model.getVersion());
251:            }
252:
253:            /**
254:             * @see org.java.plugin.registry.PluginDescriptor#getVendor()
255:             */
256:            public String getVendor() {
257:                return model.getVendor();
258:            }
259:
260:            /**
261:             * @see org.java.plugin.registry.PluginDescriptor#getVersion()
262:             */
263:            public Version getVersion() {
264:                return model.getVersion();
265:            }
266:
267:            /**
268:             * @see org.java.plugin.registry.PluginDescriptor#getPrerequisites()
269:             */
270:            public Collection<PluginPrerequisite> getPrerequisites() {
271:                return Collections.unmodifiableCollection(pluginPrerequisites
272:                        .values());
273:            }
274:
275:            /**
276:             * @see org.java.plugin.registry.PluginDescriptor#getPrerequisite(java.lang.String)
277:             */
278:            public PluginPrerequisite getPrerequisite(final String id) {
279:                return pluginPrerequisites.get(id);
280:            }
281:
282:            /**
283:             * @see org.java.plugin.registry.PluginDescriptor#getExtensionPoints()
284:             */
285:            public Collection<ExtensionPoint> getExtensionPoints() {
286:                return Collections.unmodifiableCollection(extensionPoints
287:                        .values());
288:            }
289:
290:            /**
291:             * @see org.java.plugin.registry.PluginDescriptor#getExtensionPoint(java.lang.String)
292:             */
293:            public ExtensionPoint getExtensionPoint(final String id) {
294:                return extensionPoints.get(id);
295:            }
296:
297:            /**
298:             * @see org.java.plugin.registry.PluginDescriptor#getExtensions()
299:             */
300:            public Collection<Extension> getExtensions() {
301:                return Collections.unmodifiableCollection(extensions.values());
302:            }
303:
304:            /**
305:             * @see org.java.plugin.registry.PluginDescriptor#getExtension(java.lang.String)
306:             */
307:            public Extension getExtension(final String id) {
308:                return extensions.get(id);
309:            }
310:
311:            /**
312:             * @see org.java.plugin.registry.PluginDescriptor#getLibraries()
313:             */
314:            public Collection<Library> getLibraries() {
315:                return Collections.unmodifiableCollection(libraries.values());
316:            }
317:
318:            /**
319:             * @see org.java.plugin.registry.PluginDescriptor#getLibrary(java.lang.String)
320:             */
321:            public Library getLibrary(final String id) {
322:                return libraries.get(id);
323:            }
324:
325:            /**
326:             * @see org.java.plugin.registry.PluginDescriptor#getRegistry()
327:             */
328:            public PluginRegistry getRegistry() {
329:                return registry;
330:            }
331:
332:            /**
333:             * @see org.java.plugin.registry.PluginDescriptor#getPluginClassName()
334:             */
335:            public String getPluginClassName() {
336:                return model.getClassName();
337:            }
338:
339:            /**
340:             * @see java.lang.Object#toString()
341:             */
342:            @Override
343:            public String toString() {
344:                return "{PluginDescriptor: uid=" + getUniqueId() + "}"; //$NON-NLS-1$ //$NON-NLS-2$
345:            }
346:
347:            /**
348:             * @see org.java.plugin.registry.Documentable#getDocumentation()
349:             */
350:            public Documentation<PluginDescriptor> getDocumentation() {
351:                return doc;
352:            }
353:
354:            /**
355:             * @see org.java.plugin.registry.PluginDescriptor#getFragments()
356:             */
357:            public Collection<PluginFragment> getFragments() {
358:                return Collections.unmodifiableCollection(fragments);
359:            }
360:
361:            /**
362:             * @see org.java.plugin.registry.PluginDescriptor#getAttribute(java.lang.String)
363:             */
364:            public PluginAttribute getAttribute(final String id) {
365:                PluginAttributeImpl result = null;
366:                for (PluginAttribute attribute : attributes) {
367:                    PluginAttributeImpl attr = (PluginAttributeImpl) attribute;
368:                    if (attr.getId().equals(id)) {
369:                        if (result == null) {
370:                            result = attr;
371:                        } else {
372:                            throw new IllegalArgumentException(
373:                                    "more than one attribute with ID " + id //$NON-NLS-1$
374:                                            + " defined in plug-in " + getUniqueId()); //$NON-NLS-1$
375:                        }
376:                    }
377:                }
378:                return result;
379:            }
380:
381:            /**
382:             * @see org.java.plugin.registry.PluginDescriptor#getAttributes()
383:             */
384:            public Collection<PluginAttribute> getAttributes() {
385:                return Collections.unmodifiableCollection(attributes);
386:            }
387:
388:            /**
389:             * @see org.java.plugin.registry.PluginDescriptor#getAttributes(java.lang.String)
390:             */
391:            public Collection<PluginAttribute> getAttributes(final String id) {
392:                List<PluginAttribute> result = new LinkedList<PluginAttribute>();
393:                for (PluginAttribute attribute : attributes) {
394:                    PluginAttributeImpl param = (PluginAttributeImpl) attribute;
395:                    if (param.getId().equals(id)) {
396:                        result.add(param);
397:                    }
398:                }
399:                return Collections.unmodifiableList(result);
400:            }
401:
402:            /**
403:             * @see org.java.plugin.registry.PluginDescriptor#getDocsPath()
404:             */
405:            public String getDocsPath() {
406:                return model.getDocsPath();
407:            }
408:
409:            /**
410:             * @see org.java.plugin.registry.PluginDescriptor#getLocation()
411:             */
412:            public URL getLocation() {
413:                return model.getLocation();
414:            }
415:
416:            /**
417:             * @see org.java.plugin.registry.xml.IdentityImpl#isEqualTo(
418:             *      org.java.plugin.registry.Identity)
419:             */
420:            @Override
421:            protected boolean isEqualTo(final Identity idt) {
422:                if (!(idt instanceof  PluginDescriptorImpl)) {
423:                    return false;
424:                }
425:                PluginDescriptorImpl other = (PluginDescriptorImpl) idt;
426:                return getUniqueId().equals(other.getUniqueId())
427:                        && getLocation().toExternalForm().equals(
428:                                other.getLocation().toExternalForm());
429:            }
430:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.