Source Code Cross Referenced for ExtensionImpl.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.ArrayList;
022:        import java.util.Collection;
023:        import java.util.Collections;
024:        import java.util.Date;
025:        import java.util.HashMap;
026:        import java.util.LinkedList;
027:        import java.util.List;
028:        import java.util.Map;
029:
030:        import org.java.plugin.PathResolver;
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.IntegrityCheckReport;
035:        import org.java.plugin.registry.ManifestProcessingException;
036:        import org.java.plugin.registry.ParameterType;
037:        import org.java.plugin.registry.PluginDescriptor;
038:        import org.java.plugin.registry.PluginFragment;
039:        import org.java.plugin.registry.PluginRegistry;
040:        import org.java.plugin.registry.ExtensionPoint.ParameterDefinition;
041:        import org.java.plugin.registry.IntegrityCheckReport.ReportItem;
042:        import org.java.plugin.registry.xml.ExtensionPointImpl.ParameterDefinitionImpl;
043:
044:        /**
045:         * @version $Id$
046:         */
047:        final class ExtensionImpl extends PluginElementImpl<Extension>
048:                implements  Extension {
049:            private final ModelExtension model;
050:            private List<Parameter> parameters;
051:            private Boolean isValid;
052:
053:            ExtensionImpl(final PluginDescriptorImpl descr,
054:                    final PluginFragmentImpl aFragment,
055:                    final ModelExtension aModel)
056:                    throws ManifestProcessingException {
057:                super (descr, aFragment, aModel.getId(), aModel
058:                        .getDocumentation());
059:                model = aModel;
060:                if ((model.getPluginId() == null)
061:                        || (model.getPluginId().trim().length() == 0)) {
062:                    throw new ManifestProcessingException(
063:                            PluginRegistryImpl.PACKAGE_NAME,
064:                            "extensionIdIsBlank", descr.getId()); //$NON-NLS-1$
065:                }
066:                if ((model.getPointId() == null)
067:                        || (model.getPointId().trim().length() == 0)) {
068:                    throw new ManifestProcessingException(
069:                            PluginRegistryImpl.PACKAGE_NAME,
070:                            "extendedPointIdIsBlank", descr.getId()); //$NON-NLS-1$
071:                }
072:                parameters = new ArrayList<Parameter>(model.getParams().size());
073:                for (ModelParameter parameter : model.getParams()) {
074:                    parameters.add(new ParameterImpl(null, parameter));
075:                }
076:                parameters = Collections.unmodifiableList(parameters);
077:                if (log.isDebugEnabled()) {
078:                    log.debug("object instantiated: " + this ); //$NON-NLS-1$
079:                }
080:            }
081:
082:            /**
083:             * @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
084:             */
085:            public String getUniqueId() {
086:                return getDeclaringPluginDescriptor().getRegistry()
087:                        .makeUniqueId(getDeclaringPluginDescriptor().getId(),
088:                                getId());
089:            }
090:
091:            /**
092:             * @see org.java.plugin.registry.Extension#getParameters()
093:             */
094:            public Collection<Parameter> getParameters() {
095:                return parameters;
096:            }
097:
098:            /**
099:             * @see org.java.plugin.registry.Extension#getParameter(java.lang.String)
100:             */
101:            public Parameter getParameter(final String id) {
102:                ParameterImpl result = null;
103:                for (Parameter parameter : parameters) {
104:                    ParameterImpl param = (ParameterImpl) parameter;
105:                    if (param.getId().equals(id)) {
106:                        if (result == null) {
107:                            result = param;
108:                        } else {
109:                            throw new IllegalArgumentException(
110:                                    "more than one parameter with ID " + id //$NON-NLS-1$
111:                                            + " defined in extension " + getUniqueId()); //$NON-NLS-1$
112:                        }
113:                    }
114:                }
115:                return result;
116:            }
117:
118:            /**
119:             * @see org.java.plugin.registry.Extension#getParameters(java.lang.String)
120:             */
121:            public Collection<Parameter> getParameters(final String id) {
122:                List<Parameter> result = new LinkedList<Parameter>();
123:                for (Parameter parameter : parameters) {
124:                    if (parameter.getId().equals(id))
125:                        result.add(parameter);
126:                }
127:                return Collections.unmodifiableList(result);
128:            }
129:
130:            /**
131:             * @see org.java.plugin.registry.Extension#getExtendedPluginId()
132:             */
133:            public String getExtendedPluginId() {
134:                return model.getPluginId();
135:            }
136:
137:            /**
138:             * @see org.java.plugin.registry.Extension#getExtendedPointId()
139:             */
140:            public String getExtendedPointId() {
141:                return model.getPointId();
142:            }
143:
144:            /**
145:             * @see org.java.plugin.registry.Extension#isValid()
146:             */
147:            public boolean isValid() {
148:                if (isValid == null) {
149:                    validate();
150:                }
151:                return isValid.booleanValue();
152:            }
153:
154:            Collection<ReportItem> validate() {
155:                ExtensionPoint point = getExtensionPoint(getExtendedPluginId(),
156:                        getExtendedPointId());
157:                if (point == null) {
158:                    isValid = Boolean.FALSE;
159:                    return Collections
160:                            .singletonList((ReportItem) new IntegrityChecker.ReportItemImpl(
161:                                    IntegrityCheckReport.Severity.ERROR,
162:                                    this ,
163:                                    IntegrityCheckReport.Error.INVALID_EXTENSION,
164:                                    "extPointNotAvailable", new Object[] { //$NON-NLS-1$
165:                                            getDeclaringPluginDescriptor()
166:                                                    .getRegistry()
167:                                                    .makeUniqueId(
168:                                                            getExtendedPluginId(),
169:                                                            getExtendedPointId()),
170:                                            getUniqueId() }));
171:                }
172:                Collection<ReportItem> result = validateParameters(point
173:                        .getParameterDefinitions(), parameters);
174:                isValid = result.isEmpty() ? Boolean.TRUE : Boolean.FALSE;
175:                return result;
176:            }
177:
178:            ExtensionPoint getExtensionPoint(final String uniqueId) {
179:                PluginRegistry registry = getDeclaringPluginDescriptor()
180:                        .getRegistry();
181:                return getExtensionPoint(registry.extractPluginId(uniqueId),
182:                        registry.extractId(uniqueId));
183:            }
184:
185:            ExtensionPoint getExtensionPoint(final String pluginId,
186:                    final String pointId) {
187:                PluginRegistry registry = getDeclaringPluginDescriptor()
188:                        .getRegistry();
189:                if (!registry.isPluginDescriptorAvailable(pluginId)) {
190:                    return null;
191:                }
192:                for (ExtensionPoint point : registry.getPluginDescriptor(
193:                        pluginId).getExtensionPoints()) {
194:                    if (point.getId().equals(pointId)) {
195:                        return point;
196:                    }
197:                }
198:                return null;
199:            }
200:
201:            private Collection<ReportItem> validateParameters(
202:                    final Collection<ParameterDefinition> allDefinitions,
203:                    final Collection<Parameter> allParams) {
204:                List<ReportItem> result = new LinkedList<ReportItem>();
205:                Map<String, Collection<Parameter>> groups = new HashMap<String, Collection<Parameter>>();
206:                for (Parameter param : allParams) {
207:                    ParameterDefinition def = param.getDefinition();
208:                    if (def == null) {
209:                        result.add(new IntegrityChecker.ReportItemImpl(
210:                                IntegrityCheckReport.Severity.ERROR, this ,
211:                                IntegrityCheckReport.Error.INVALID_EXTENSION,
212:                                "cantDetectParameterDef", new Object[] { //$NON-NLS-1$
213:                                param.getId(), getUniqueId() }));
214:                        continue;
215:                    }
216:                    if (groups.containsKey(param.getId())) {
217:                        groups.get(param.getId()).add(param);
218:                    } else {
219:                        Collection<Parameter> paramGroup = new LinkedList<Parameter>();
220:                        paramGroup.add(param);
221:                        groups.put(param.getId(), paramGroup);
222:                    }
223:                }
224:                if (!result.isEmpty()) {
225:                    return result;
226:                }
227:
228:                List<Parameter> empty_paramGroup = Collections.emptyList();
229:                for (ParameterDefinition def : allDefinitions) {
230:                    Collection<Parameter> paramGroup = groups.get(def.getId());
231:                    result.addAll(validateParameters(def,
232:                            (paramGroup != null) ? paramGroup
233:                                    : empty_paramGroup));
234:                }
235:                return result;
236:            }
237:
238:            private Collection<ReportItem> validateParameters(
239:                    final ParameterDefinition def,
240:                    final Collection<Parameter> params) {
241:                if (log.isDebugEnabled()) {
242:                    log.debug("validating parameters for definition " + def); //$NON-NLS-1$
243:                }
244:                switch (def.getMultiplicity()) {
245:                case ONE:
246:                    if (params.size() != 1) {
247:                        return Collections
248:                                .singletonList((ReportItem) new IntegrityChecker.ReportItemImpl(
249:                                        IntegrityCheckReport.Severity.ERROR,
250:                                        this ,
251:                                        IntegrityCheckReport.Error.INVALID_EXTENSION,
252:                                        "tooManyOrFewParams", new Object[] { //$NON-NLS-1$
253:                                        def.getId(), getUniqueId() }));
254:                    }
255:                    break;
256:                case NONE_OR_ONE:
257:                    if (params.size() > 1) {
258:                        return Collections
259:                                .singletonList((ReportItem) new IntegrityChecker.ReportItemImpl(
260:                                        IntegrityCheckReport.Severity.ERROR,
261:                                        this ,
262:                                        IntegrityCheckReport.Error.INVALID_EXTENSION,
263:                                        "tooManyParams", new Object[] { //$NON-NLS-1$
264:                                        def.getId(), getUniqueId() }));
265:                    }
266:                    break;
267:                case ONE_OR_MORE:
268:                    if (params.isEmpty()) {
269:                        return Collections
270:                                .singletonList((ReportItem) new IntegrityChecker.ReportItemImpl(
271:                                        IntegrityCheckReport.Severity.ERROR,
272:                                        this ,
273:                                        IntegrityCheckReport.Error.INVALID_EXTENSION,
274:                                        "tooFewParams", new Object[] { //$NON-NLS-1$
275:                                        def.getId(), getUniqueId() }));
276:                    }
277:                    break;
278:                case ANY:
279:                    // no-op
280:                    break;
281:                }
282:                if (params.isEmpty()) {
283:                    return Collections.emptyList();
284:                }
285:                List<ReportItem> result = new LinkedList<ReportItem>();
286:                int count = 1;
287:                ParameterImpl param;
288:                for (Parameter parameter : params) {
289:                    param = (ParameterImpl) parameter;
290:                    if (!param.isValid()) {
291:                        result.add(new IntegrityChecker.ReportItemImpl(
292:                                IntegrityCheckReport.Severity.ERROR, this ,
293:                                IntegrityCheckReport.Error.INVALID_EXTENSION,
294:                                "invalidParameterValue", new Object[] { //$NON-NLS-1$
295:                                def.getId(), Integer.valueOf(count),
296:                                        getUniqueId() }));
297:                    }
298:                    if ((ParameterType.ANY != def.getType())
299:                            && result.isEmpty()) {
300:                        result
301:                                .addAll(validateParameters(param
302:                                        .getDefinition().getSubDefinitions(),
303:                                        param.getSubParameters()));
304:                    }
305:                    count++; // FIXME in 0.11 not in 0.12
306:                }
307:                return result;
308:            }
309:
310:            /**
311:             * @see java.lang.Object#toString()
312:             */
313:            @Override
314:            public String toString() {
315:                return "{PluginExtension: uid=" + getUniqueId() + "}"; //$NON-NLS-1$ //$NON-NLS-2$
316:            }
317:
318:            void registryChanged() {
319:                isValid = null;
320:            }
321:
322:            private class ParameterImpl extends PluginElementImpl<Parameter>
323:                    implements  Parameter {
324:                private final ModelParameter modelParam;
325:                private ParameterValueParser valueParser;
326:                private List<Parameter> subParameters;
327:                private ParameterDefinition definition = null;
328:                private boolean definitionDetected = false;
329:                private final ParameterImpl super Parameter;
330:
331:                ParameterImpl(final ParameterImpl aSuperParameter,
332:                        final ModelParameter aModel)
333:                        throws ManifestProcessingException {
334:                    super (ExtensionImpl.this .getDeclaringPluginDescriptor(),
335:                            ExtensionImpl.this .getDeclaringPluginFragment(),
336:                            aModel.getId(), aModel.getDocumentation());
337:                    this .super Parameter = aSuperParameter;
338:                    modelParam = aModel;
339:                    subParameters = new ArrayList<Parameter>(modelParam
340:                            .getParams().size());
341:                    for (ModelParameter modelParameter : modelParam.getParams()) {
342:                        subParameters.add(new ParameterImpl(this ,
343:                                modelParameter));
344:                    }
345:                    subParameters = Collections.unmodifiableList(subParameters);
346:                    if (log.isDebugEnabled()) {
347:                        log.debug("object instantiated: " + this ); //$NON-NLS-1$
348:                    }
349:                }
350:
351:                /**
352:                 * @see org.java.plugin.registry.Extension.Parameter#getDeclaringExtension()
353:                 */
354:                public Extension getDeclaringExtension() {
355:                    return ExtensionImpl.this ;
356:                }
357:
358:                /**
359:                 * @see org.java.plugin.registry.PluginElement#getDeclaringPluginDescriptor()
360:                 */
361:                @Override
362:                public PluginDescriptor getDeclaringPluginDescriptor() {
363:                    return ExtensionImpl.this .getDeclaringPluginDescriptor();
364:                }
365:
366:                /**
367:                 * @see org.java.plugin.registry.PluginElement#getDeclaringPluginFragment()
368:                 */
369:                @Override
370:                public PluginFragment getDeclaringPluginFragment() {
371:                    return ExtensionImpl.this .getDeclaringPluginFragment();
372:                }
373:
374:                /**
375:                 * @see org.java.plugin.registry.Extension.Parameter#getDefinition()
376:                 */
377:                public ParameterDefinition getDefinition() {
378:                    if (definitionDetected) {
379:                        return definition;
380:                    }
381:                    definitionDetected = true;
382:                    if (log.isDebugEnabled()) {
383:                        log.debug("detecting definition for parameter " + this ); //$NON-NLS-1$
384:                    }
385:                    Collection<ParameterDefinition> definitions;
386:                    if (super Parameter != null) {
387:                        if (super Parameter.getDefinition() == null) {
388:                            return null;
389:                        }
390:                        if (ParameterType.ANY == super Parameter.getDefinition()
391:                                .getType()) {
392:                            definition = super Parameter.getDefinition();
393:                            if (log.isDebugEnabled()) {
394:                                log
395:                                        .debug("definition detected - " + definition); //$NON-NLS-1$
396:                            }
397:                            return definition;
398:                        }
399:                        definitions = super Parameter.getDefinition()
400:                                .getSubDefinitions();
401:                    } else {
402:                        definitions = getExtensionPoint(
403:                                getDeclaringExtension().getExtendedPluginId(),
404:                                getDeclaringExtension().getExtendedPointId())
405:                                .getParameterDefinitions();
406:                    }
407:                    for (ParameterDefinition def : definitions) {
408:                        if (def.getId().equals(getId())) {
409:                            definition = def;
410:                            break;
411:                        }
412:                    }
413:                    if (log.isDebugEnabled()) {
414:                        log.debug("definition detected - " + definition); //$NON-NLS-1$
415:                    }
416:                    return definition;
417:                }
418:
419:                /**
420:                 * @see org.java.plugin.registry.Extension.Parameter#getSuperParameter()
421:                 */
422:                public Parameter getSuperParameter() {
423:                    return super Parameter;
424:                }
425:
426:                /**
427:                 * @see org.java.plugin.registry.Extension.Parameter#getSubParameters()
428:                 */
429:                public Collection<Parameter> getSubParameters() {
430:                    return subParameters;
431:                }
432:
433:                /**
434:                 * @see org.java.plugin.registry.Extension.Parameter#getSubParameter(
435:                 *      java.lang.String)
436:                 */
437:                public Parameter getSubParameter(final String id) {
438:                    ParameterImpl result = null;
439:                    for (Parameter parameter : subParameters) {
440:                        ParameterImpl param = (ParameterImpl) parameter;
441:                        if (param.getId().equals(id)) {
442:                            if (result == null) {
443:                                result = param;
444:                            } else {
445:                                throw new IllegalArgumentException(
446:                                        "more than one parameter with ID " + id //$NON-NLS-1$
447:                                                + " defined in extension " + getUniqueId()); //$NON-NLS-1$
448:                            }
449:                        }
450:                    }
451:                    return result;
452:                }
453:
454:                /**
455:                 * @see org.java.plugin.registry.Extension.Parameter#getSubParameters(
456:                 *      java.lang.String)
457:                 */
458:                public Collection<Parameter> getSubParameters(final String id) {
459:                    List<Parameter> result = new LinkedList<Parameter>();
460:                    for (Parameter param : subParameters) {
461:                        if (param.getId().equals(id)) {
462:                            result.add(param);
463:                        }
464:                    }
465:                    return Collections.unmodifiableList(result);
466:                }
467:
468:                /**
469:                 * @see org.java.plugin.registry.Extension.Parameter#rawValue()
470:                 */
471:                public String rawValue() {
472:                    return (modelParam.getValue() != null) ? modelParam
473:                            .getValue() : ""; //$NON-NLS-1$
474:                }
475:
476:                boolean isValid() {
477:                    if (valueParser != null) {
478:                        return valueParser.isParsingSucceeds();
479:                    }
480:                    if (log.isDebugEnabled()) {
481:                        log.debug("validating parameter " + this ); //$NON-NLS-1$
482:                    }
483:                    valueParser = new ParameterValueParser(
484:                            getDeclaringPluginDescriptor().getRegistry(),
485:                            getDefinition(), modelParam.getValue());
486:                    if (!valueParser.isParsingSucceeds()) {
487:                        log.warn("parsing value for parameter " + this  //$NON-NLS-1$
488:                                + " failed, message is: " //$NON-NLS-1$
489:                                + valueParser.getParsingMessage());
490:                    }
491:                    return valueParser.isParsingSucceeds();
492:                }
493:
494:                /**
495:                 * @see org.java.plugin.registry.Extension.Parameter#valueAsBoolean()
496:                 */
497:                public Boolean valueAsBoolean() {
498:                    if (!isValid()) {
499:                        throw new UnsupportedOperationException(
500:                                "parameter value is invalid"); //$NON-NLS-1$
501:                    }
502:                    if (ParameterType.BOOLEAN != definition.getType()) {
503:                        throw new UnsupportedOperationException(
504:                                "parameter type is not " //$NON-NLS-1$
505:                                        + ParameterType.BOOLEAN);
506:                    }
507:                    if (valueParser.getValue() == null) {
508:                        return (Boolean) ((ParameterDefinitionImpl) getDefinition())
509:                                .getValueParser().getValue();
510:                    }
511:                    return (Boolean) valueParser.getValue();
512:                }
513:
514:                /**
515:                 * @see org.java.plugin.registry.Extension.Parameter#valueAsDate()
516:                 */
517:                public Date valueAsDate() {
518:                    if (!isValid()) {
519:                        throw new UnsupportedOperationException(
520:                                "parameter value is invalid"); //$NON-NLS-1$
521:                    }
522:                    if ((ParameterType.DATE != definition.getType())
523:                            && (ParameterType.DATE_TIME != definition.getType())
524:                            && (ParameterType.TIME != definition.getType())) {
525:                        throw new UnsupportedOperationException(
526:                                "parameter type is not " //$NON-NLS-1$
527:                                        + ParameterType.DATE + " nor " //$NON-NLS-1$
528:                                        + ParameterType.DATE_TIME + " nor" //$NON-NLS-1$
529:                                        + ParameterType.TIME);
530:                    }
531:                    if (valueParser.getValue() == null) {
532:                        return (Date) ((ParameterDefinitionImpl) getDefinition())
533:                                .getValueParser().getValue();
534:                    }
535:                    return (Date) valueParser.getValue();
536:                }
537:
538:                /**
539:                 * @see org.java.plugin.registry.Extension.Parameter#valueAsNumber()
540:                 */
541:                public Number valueAsNumber() {
542:                    if (!isValid()) {
543:                        throw new UnsupportedOperationException(
544:                                "parameter value is invalid"); //$NON-NLS-1$
545:                    }
546:                    if (ParameterType.NUMBER != definition.getType()) {
547:                        throw new UnsupportedOperationException(
548:                                "parameter type is not " //$NON-NLS-1$
549:                                        + ParameterType.NUMBER);
550:                    }
551:                    if (valueParser.getValue() == null) {
552:                        return (Number) ((ParameterDefinitionImpl) getDefinition())
553:                                .getValueParser().getValue();
554:                    }
555:                    return (Number) valueParser.getValue();
556:                }
557:
558:                /**
559:                 * @see org.java.plugin.registry.Extension.Parameter#valueAsString()
560:                 */
561:                public String valueAsString() {
562:                    if (!isValid()) {
563:                        throw new UnsupportedOperationException(
564:                                "parameter value is invalid"); //$NON-NLS-1$
565:                    }
566:                    if ((ParameterType.STRING != definition.getType())
567:                            && (ParameterType.FIXED != definition.getType())) {
568:                        throw new UnsupportedOperationException(
569:                                "parameter type is not " //$NON-NLS-1$
570:                                        + ParameterType.STRING);
571:                    }
572:                    if (valueParser.getValue() == null) {
573:                        return (String) ((ParameterDefinitionImpl) getDefinition())
574:                                .getValueParser().getValue();
575:                    }
576:                    return (String) valueParser.getValue();
577:                }
578:
579:                /**
580:                 * @see org.java.plugin.registry.Extension.Parameter#valueAsExtension()
581:                 */
582:                public Extension valueAsExtension() {
583:                    if (!isValid()) {
584:                        throw new UnsupportedOperationException(
585:                                "parameter value is invalid"); //$NON-NLS-1$
586:                    }
587:                    if (ParameterType.EXTENSION_ID != definition.getType()) {
588:                        throw new UnsupportedOperationException(
589:                                "parameter type is not " //$NON-NLS-1$
590:                                        + ParameterType.EXTENSION_ID);
591:                    }
592:                    if (valueParser.getValue() == null) {
593:                        return (Extension) ((ParameterDefinitionImpl) getDefinition())
594:                                .getValueParser().getValue();
595:                    }
596:                    return (Extension) valueParser.getValue();
597:                }
598:
599:                /**
600:                 * @see org.java.plugin.registry.Extension.Parameter#valueAsExtensionPoint()
601:                 */
602:                public ExtensionPoint valueAsExtensionPoint() {
603:                    if (!isValid()) {
604:                        throw new UnsupportedOperationException(
605:                                "parameter value is invalid"); //$NON-NLS-1$
606:                    }
607:                    if (ParameterType.EXTENSION_POINT_ID != definition
608:                            .getType()) {
609:                        throw new UnsupportedOperationException(
610:                                "parameter type is not " //$NON-NLS-1$
611:                                        + ParameterType.EXTENSION_POINT_ID);
612:                    }
613:                    if (valueParser.getValue() == null) {
614:                        return (ExtensionPoint) ((ParameterDefinitionImpl) getDefinition())
615:                                .getValueParser().getValue();
616:                    }
617:                    return (ExtensionPoint) valueParser.getValue();
618:                }
619:
620:                /**
621:                 * @see org.java.plugin.registry.Extension.Parameter#valueAsPluginDescriptor()
622:                 */
623:                public PluginDescriptor valueAsPluginDescriptor() {
624:                    if (!isValid()) {
625:                        throw new UnsupportedOperationException(
626:                                "parameter value is invalid"); //$NON-NLS-1$
627:                    }
628:                    if (ParameterType.PLUGIN_ID != definition.getType()) {
629:                        throw new UnsupportedOperationException(
630:                                "parameter type is not " //$NON-NLS-1$
631:                                        + ParameterType.PLUGIN_ID);
632:                    }
633:                    if (valueParser.getValue() == null) {
634:                        return (PluginDescriptor) ((ParameterDefinitionImpl) getDefinition())
635:                                .getValueParser().getValue();
636:                    }
637:                    return (PluginDescriptor) valueParser.getValue();
638:                }
639:
640:                /**
641:                 * @see org.java.plugin.registry.Extension.Parameter#valueAsUrl()
642:                 */
643:                public URL valueAsUrl() {
644:                    return valueAsUrl(null);
645:                }
646:
647:                /**
648:                 * @see org.java.plugin.registry.Extension.Parameter#valueAsUrl(
649:                 *      org.java.plugin.PathResolver)
650:                 */
651:                public URL valueAsUrl(final PathResolver pathResolver) {
652:                    if (!isValid()) {
653:                        throw new UnsupportedOperationException(
654:                                "parameter value is invalid"); //$NON-NLS-1$
655:                    }
656:                    if (ParameterType.RESOURCE != definition.getType()) {
657:                        throw new UnsupportedOperationException(
658:                                "parameter type is not " //$NON-NLS-1$
659:                                        + ParameterType.RESOURCE);
660:                    }
661:                    if ((valueParser.getValue() == null)
662:                            && (rawValue() == null)) {
663:                        return valueAsUrl(
664:                                pathResolver,
665:                                getDefinition().getDeclaringExtensionPoint(),
666:                                (URL) ((ParameterDefinitionImpl) getDefinition())
667:                                        .getValueParser().getValue(),
668:                                getDefinition().getDefaultValue());
669:                    }
670:                    return valueAsUrl(pathResolver,
671:                            getDeclaringPluginDescriptor(), (URL) valueParser
672:                                    .getValue(), rawValue());
673:                }
674:
675:                private URL valueAsUrl(final PathResolver pathResolver,
676:                        final Identity idt, final URL absoluteUrl,
677:                        final String relativeUrl) {
678:                    if ((pathResolver == null) || (absoluteUrl != null)) {
679:                        return absoluteUrl;
680:                    }
681:                    if (relativeUrl == null) {
682:                        return null;
683:                    }
684:                    return pathResolver.resolvePath(idt, relativeUrl);
685:                }
686:
687:                /**
688:                 * @see java.lang.Object#toString()
689:                 */
690:                @Override
691:                public String toString() {
692:                    return "{PluginExtension.Parameter: extUid=" //$NON-NLS-1$
693:                            + getDeclaringExtension().getUniqueId()
694:                            + "; id=" + getId() //$NON-NLS-1$
695:                            + "}"; //$NON-NLS-1$
696:                }
697:
698:                /**
699:                 * @see org.java.plugin.registry.xml.IdentityImpl#isEqualTo(
700:                 *      org.java.plugin.registry.Identity)
701:                 */
702:                @Override
703:                protected boolean isEqualTo(final Identity idt) {
704:                    if (!super .isEqualTo(idt)) {
705:                        return false;
706:                    }
707:                    ParameterImpl other = (ParameterImpl) idt;
708:                    if ((getSuperParameter() == null)
709:                            && (other.getSuperParameter() == null)) {
710:                        return true;
711:                    }
712:                    if ((getSuperParameter() == null)
713:                            || (other.getSuperParameter() == null)) {
714:                        return false;
715:                    }
716:                    return getSuperParameter()
717:                            .equals(other.getSuperParameter());
718:                }
719:            }
720:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.