KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > extension > Extension


1 /*
2  * Copyright 2004 Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.extension;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.StringTokenizer JavaDoc;
24 import java.util.jar.Attributes JavaDoc;
25 import java.util.jar.Manifest JavaDoc;
26
27 /**
28  * <p>Utility class that represents either an available "Optional Package"
29  * (formerly known as "Standard Extension") as described in the manifest
30  * of a JAR file, or the requirement for such an optional package.</p>
31  *
32  * <p>For more information about optional packages, see the document
33  * <em>Optional Package Versioning</em> in the documentation bundle for your
34  * Java2 Standard Edition package, in file
35  * <code>guide/extensions/versioning.html</code>.</p>
36  *
37  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
38  * @version $Revision: 1.3 $ $Date: 2004/04/06 07:42:48 $
39  */

40 public final class Extension
41 {
42     /**
43      * Manifest Attribute Name object for EXTENSION_LIST.
44      * @see java.util.jar.Attributes.Name#EXTENSION_LIST
45      */

46     public static final Attributes.Name JavaDoc EXTENSION_LIST = Attributes.Name.EXTENSION_LIST;
47
48     /**
49      * <code>Name</code> object for <code>Optional-Extension-List</code>
50      * manifest attribute used for declaring optional dependencies on
51      * installed extensions. Note that the dependencies declared by this method
52      * are not required for the library to operate but if present will be used.
53      * It is NOT part of the official "Optional Package" specification.
54      *
55      * @see <a HREF="http://java.sun.com/j2se/1.3/docs/guide/extensions/spec.html#dependnecy">
56      * Installed extension dependency</a>
57      */

58     public static final Attributes.Name JavaDoc OPTIONAL_EXTENSION_LIST =
59         new Attributes.Name JavaDoc( "Optional-Extension-List" );
60
61     /**
62      * Manifest Attribute Name object for EXTENSION_NAME.
63      * @see java.util.jar.Attributes.Name#EXTENSION_NAME
64      */

65     public static final Attributes.Name JavaDoc EXTENSION_NAME =
66         Attributes.Name.EXTENSION_NAME;
67
68     /**
69      * Manifest Attribute Name object for SPECIFICATION_VERSION.
70      * @see java.util.jar.Attributes.Name#SPECIFICATION_VERSION
71      */

72     public static final Attributes.Name JavaDoc SPECIFICATION_VERSION =
73         Attributes.Name.SPECIFICATION_VERSION;
74
75     /**
76      * Manifest Attribute Name object for SPECIFICATION_VENDOR.
77      * @see java.util.jar.Attributes.Name#SPECIFICATION_VENDOR
78      */

79     public static final Attributes.Name JavaDoc SPECIFICATION_VENDOR =
80         Attributes.Name.SPECIFICATION_VENDOR;
81
82     /**
83      * Manifest Attribute Name object for IMPLEMENTATION_VERSION.
84      * @see java.util.jar.Attributes.Name#IMPLEMENTATION_VERSION
85      */

86     public static final Attributes.Name JavaDoc IMPLEMENTATION_VERSION =
87         Attributes.Name.IMPLEMENTATION_VERSION;
88
89     /**
90      * Manifest Attribute Name object for IMPLEMENTATION_VENDOR.
91      * @see java.util.jar.Attributes.Name#IMPLEMENTATION_VENDOR
92      */

93     public static final Attributes.Name JavaDoc IMPLEMENTATION_VENDOR =
94         Attributes.Name.IMPLEMENTATION_VENDOR;
95
96     /**
97      * Manifest Attribute Name object for IMPLEMENTATION_URL.
98      * @see java.util.jar.Attributes.Name#IMPLEMENTATION_URL
99      */

100     public static final Attributes.Name JavaDoc IMPLEMENTATION_URL =
101         Attributes.Name.IMPLEMENTATION_URL;
102
103     /**
104      * Manifest Attribute Name object for IMPLEMENTATION_VENDOR_ID.
105      * @see java.util.jar.Attributes.Name#IMPLEMENTATION_VENDOR_ID
106      */

107     public static final Attributes.Name JavaDoc IMPLEMENTATION_VENDOR_ID =
108         Attributes.Name.IMPLEMENTATION_VENDOR_ID;
109
110     /**
111      * Enum indicating that extension is compatible with other extension.
112      */

113     public static final Compatability COMPATIBLE =
114         new Compatability( "COMPATIBLE" );
115
116     /**
117      * Enum indicating that extension requires an upgrade
118      * of specification to be compatible with other extension.
119      */

120     public static final Compatability REQUIRE_SPECIFICATION_UPGRADE =
121         new Compatability( "REQUIRE_SPECIFICATION_UPGRADE" );
122
123     /**
124      * Enum indicating that extension requires a vendor
125      * switch to be compatible with other extension.
126      */

127     public static final Compatability REQUIRE_VENDOR_SWITCH =
128         new Compatability( "REQUIRE_VENDOR_SWITCH" );
129
130     /**
131      * Enum indicating that extension requires an upgrade
132      * of implementation to be compatible with other extension.
133      */

134     public static final Compatability REQUIRE_IMPLEMENTATION_UPGRADE =
135         new Compatability( "REQUIRE_IMPLEMENTATION_UPGRADE" );
136
137     /**
138      * Enum indicating that extension is incompatible with
139      * other extension in ways other than other enums
140      * indicate). ie For example the other extension may have
141      * a different ID.
142      */

143     public static final Compatability INCOMPATIBLE =
144         new Compatability( "INCOMPATIBLE" );
145
146     /**
147      * The name of the optional package being made available, or required.
148      */

149     private String JavaDoc m_extensionName;
150
151     /**
152      * The version number (dotted decimal notation) of the specification
153      * to which this optional package conforms.
154      */

155     private DeweyDecimal m_specificationVersion;
156
157     /**
158      * The name of the company or organization that originated the
159      * specification to which this optional package conforms.
160      */

161     private String JavaDoc m_specificationVendor;
162
163     /**
164      * The unique identifier of the company that produced the optional
165      * package contained in this JAR file.
166      */

167     private String JavaDoc m_implementationVendorID;
168
169     /**
170      * The name of the company or organization that produced this
171      * implementation of this optional package.
172      */

173     private String JavaDoc m_implementationVendor;
174
175     /**
176      * The version number (dotted decimal notation) for this implementation
177      * of the optional package.
178      */

179     private String JavaDoc m_implementationVersion;
180
181     /**
182      * The URL from which the most recent version of this optional package
183      * can be obtained if it is not already installed.
184      */

185     private String JavaDoc m_implementationURL;
186
187     /**
188      * Return an array of <code>Extension</code> objects representing optional
189      * packages that are available in the JAR file associated with the
190      * specified <code>Manifest</code>. If there are no such optional
191      * packages, a zero-length array is returned.
192      *
193      * @param manifest Manifest to be parsed
194      * @return the "available" extensions in specified manifest
195      */

196     public static Extension[] getAvailable( final Manifest JavaDoc manifest )
197     {
198         if( null == manifest )
199         {
200             return new Extension[ 0 ];
201         }
202
203         final ArrayList JavaDoc results = new ArrayList JavaDoc();
204
205         final Attributes JavaDoc mainAttributes = manifest.getMainAttributes();
206         if( null != mainAttributes )
207         {
208             final Extension extension = getExtension( "", mainAttributes );
209             if( null != extension )
210             {
211                 results.add( extension );
212             }
213         }
214
215         final Map JavaDoc entries = manifest.getEntries();
216         final Iterator JavaDoc keys = entries.keySet().iterator();
217         while( keys.hasNext() )
218         {
219             final String JavaDoc key = (String JavaDoc)keys.next();
220             final Attributes JavaDoc attributes = (Attributes JavaDoc)entries.get( key );
221             final Extension extension = getExtension( "", attributes );
222             if( null != extension )
223             {
224                 results.add( extension );
225             }
226         }
227
228         return (Extension[])results.toArray( new Extension[ results.size() ] );
229     }
230
231     /**
232      * Retrieve the set of <code>Extension</code> objects that are available
233      * by the specified Manifest objects. If there are no such optional
234      * packages, a zero-length list is returned.
235      *
236      * @param manifests the manifests to scan
237      * @return the extensions
238      */

239     public static Extension[] getAvailable( final Manifest JavaDoc[] manifests )
240     {
241         final ArrayList JavaDoc set = new ArrayList JavaDoc();
242
243         for( int i = 0; i < manifests.length; i++ )
244         {
245             final Extension[] extensions = getAvailable( manifests[ i ] );
246             for( int j = 0; j < extensions.length; j++ )
247             {
248                 set.add( extensions[ j ] );
249             }
250         }
251
252         return (Extension[])set.toArray( new Extension[ set.size() ] );
253     }
254
255     /**
256      * Return the set of <code>Extension</code> objects representing optional
257      * packages that are required by the application contained in the JAR
258      * file associated with the specified <code>Manifest</code>. If there
259      * are no such optional packages, a zero-length list is returned.
260      *
261      * @param manifest Manifest to be parsed
262      * @return the dependencies that are specified in manifes
263      */

264     public static Extension[] getRequired( final Manifest JavaDoc manifest )
265     {
266         return getListed( manifest, EXTENSION_LIST );
267     }
268
269     /**
270      * Retrieve the set of <code>Extension</code> objects that are required
271      * by the specified Manifest objects. If there are no such optional
272      * packages, a zero-length list is returned.
273      *
274      * @param manifests the manifests to scan
275      * @return the extensions
276      */

277     public static Extension[] getRequired( final Manifest JavaDoc[] manifests )
278     {
279         final ArrayList JavaDoc set = new ArrayList JavaDoc();
280
281         for( int i = 0; i < manifests.length; i++ )
282         {
283             final Extension[] extensions = getRequired( manifests[ i ] );
284             for( int j = 0; j < extensions.length; j++ )
285             {
286                 set.add( extensions[ j ] );
287             }
288         }
289
290         return (Extension[])set.toArray( new Extension[ set.size() ] );
291     }
292
293     /**
294      * Return the set of <code>Extension</code> objects representing "Optional
295      * Packages" that the application declares they will use if present. If
296      * there are no such optional packages, a zero-length list is returned.
297      *
298      * @param manifest Manifest to be parsed
299      * @return the optional dependencies that are specified in manifest
300      */

301     public static Extension[] getOptions( final Manifest JavaDoc manifest )
302     {
303         return getListed( manifest, OPTIONAL_EXTENSION_LIST );
304     }
305
306     /**
307      * Add Extension to the specified manifest Attributes.
308      *
309      * @param attributes the attributes of manifest to add to
310      * @param extension the extension
311      */

312     public static void addExtension( final Extension extension,
313                                      final Attributes JavaDoc attributes )
314     {
315         addExtension( extension, "", attributes );
316     }
317
318     /**
319      * Add Extension to the specified manifest Attributes.
320      * Use the specified prefix so that dependencies can added
321      * with a prefix such as "java3d-" etc.
322      *
323      * @param attributes the attributes of manifest to add to
324      * @param extension the extension
325      * @param prefix the name to prefix to extension
326      */

327     public static void addExtension( final Extension extension,
328                                      final String JavaDoc prefix,
329                                      final Attributes JavaDoc attributes )
330     {
331         attributes.putValue( prefix + EXTENSION_NAME,
332                              extension.getExtensionName() );
333
334         final String JavaDoc specificationVendor = extension.getSpecificationVendor();
335         if( null != specificationVendor )
336         {
337             attributes.putValue( prefix + SPECIFICATION_VENDOR,
338                                  specificationVendor );
339         }
340
341         final DeweyDecimal specificationVersion = extension.getSpecificationVersion();
342         if( null != specificationVersion )
343         {
344             attributes.putValue( prefix + SPECIFICATION_VERSION,
345                                  specificationVersion.toString() );
346         }
347
348         final String JavaDoc implementationVendorID = extension.getImplementationVendorID();
349         if( null != implementationVendorID )
350         {
351             attributes.putValue( prefix + IMPLEMENTATION_VENDOR_ID,
352                                  implementationVendorID );
353         }
354
355         final String JavaDoc implementationVendor = extension.getImplementationVendor();
356         if( null != implementationVendor )
357         {
358             attributes.putValue( prefix + IMPLEMENTATION_VENDOR,
359                                  implementationVendor );
360         }
361
362         final String JavaDoc implementationVersion = extension.getImplementationVersion();
363         if( null != implementationVersion )
364         {
365             attributes.putValue( prefix + IMPLEMENTATION_VERSION,
366                                  implementationVersion.toString() );
367         }
368
369         final String JavaDoc implementationURL = extension.getImplementationURL();
370         if( null != implementationURL )
371         {
372             attributes.putValue( prefix + IMPLEMENTATION_URL,
373                                  implementationURL );
374         }
375     }
376
377     /**
378      * The constructor to create Extension object.
379      * Note that every component is allowed to be specified
380      * but only the extensionName is mandatory.
381      *
382      * @param extensionName the name of extension.
383      * @param specificationVersion the specification Version of extension.
384      * @param specificationVendor the specification Vendor of extension.
385      * @param implementationVersion the implementation Version of extension.
386      * @param implementationVendor the implementation Vendor of extension.
387      * @param implementationVendorId the implementation VendorId of extension.
388      * @param implementationURL the implementation URL of extension.
389      */

390     public Extension( final String JavaDoc extensionName,
391                       final String JavaDoc specificationVersion,
392                       final String JavaDoc specificationVendor,
393                       final String JavaDoc implementationVersion,
394                       final String JavaDoc implementationVendor,
395                       final String JavaDoc implementationVendorId,
396                       final String JavaDoc implementationURL )
397     {
398         m_extensionName = extensionName;
399         m_specificationVendor = specificationVendor;
400
401         if( null != specificationVersion )
402         {
403             try
404             {
405                 m_specificationVersion = new DeweyDecimal( specificationVersion );
406             }
407             catch( final NumberFormatException JavaDoc nfe )
408             {
409                 //
410
// don't complain because maven is generating illegal
411
// spec values by default - instead we leave it as null
412
//
413

414                 //final String error =
415
// "Bad specification version format '" + specificationVersion +
416
// "' in '" + extensionName + "'. (Reason: " + nfe + ")";
417
//throw new IllegalArgumentException( error );
418
}
419         }
420
421         m_implementationURL = implementationURL;
422         m_implementationVendor = implementationVendor;
423         m_implementationVendorID = implementationVendorId;
424         m_implementationVersion = implementationVersion;
425
426         if( null == m_extensionName )
427         {
428             throw new NullPointerException JavaDoc( "extensionName property is null" );
429         }
430     }
431
432     /**
433      * Get the name of the extension.
434      *
435      * @return the name of the extension
436      */

437     public String JavaDoc getExtensionName()
438     {
439         return m_extensionName;
440     }
441
442     /**
443      * Get the vendor of the extensions specification.
444      *
445      * @return the vendor of the extensions specification.
446      */

447     public String JavaDoc getSpecificationVendor()
448     {
449         return m_specificationVendor;
450     }
451
452     /**
453      * Get the version of the extensions specification.
454      *
455      * @return the version of the extensions specification.
456      */

457     public DeweyDecimal getSpecificationVersion()
458     {
459         return m_specificationVersion;
460     }
461
462     /**
463      * Get the url of the extensions implementation.
464      *
465      * @return the url of the extensions implementation.
466      */

467     public String JavaDoc getImplementationURL()
468     {
469         return m_implementationURL;
470     }
471
472     /**
473      * Get the vendor of the extensions implementation.
474      *
475      * @return the vendor of the extensions implementation.
476      */

477     public String JavaDoc getImplementationVendor()
478     {
479         return m_implementationVendor;
480     }
481
482     /**
483      * Get the vendorID of the extensions implementation.
484      *
485      * @return the vendorID of the extensions implementation.
486      */

487     public String JavaDoc getImplementationVendorID()
488     {
489         return m_implementationVendorID;
490     }
491
492     /**
493      * Get the version of the extensions implementation.
494      *
495      * @return the version of the extensions implementation.
496      */

497     public String JavaDoc getImplementationVersion()
498     {
499         return m_implementationVersion;
500     }
501
502     /**
503      * Return a Compatibility enum indicating the relationship of this
504      * <code>Extension</code> with the specified <code>Extension</code>.
505      *
506      * @param required Description of the required optional package
507      * @return the enum indicating the compatability (or lack thereof)
508      * of specifed extension
509      */

510     public Compatability getCompatibilityWith( final Extension required )
511     {
512         // Extension Name must match
513
if( !m_extensionName.equals( required.getExtensionName() ) )
514         {
515             return INCOMPATIBLE;
516         }
517
518         // Available specification version must be >= required
519
final DeweyDecimal specificationVersion = required.getSpecificationVersion();
520         if( null != specificationVersion )
521         {
522             if( null == m_specificationVersion ||
523                 !isCompatible( m_specificationVersion, specificationVersion ) )
524             {
525                 return REQUIRE_SPECIFICATION_UPGRADE;
526             }
527         }
528
529         // Implementation Vendor ID must match
530
final String JavaDoc implementationVendorId = required.getImplementationVendorID();
531         if( null != implementationVendorId )
532         {
533             if( null == m_implementationVendorID ||
534                 !m_implementationVendorID.equals( implementationVendorId ) )
535             {
536                 return REQUIRE_VENDOR_SWITCH;
537             }
538         }
539
540
541         // This available optional package satisfies the requirements
542
return COMPATIBLE;
543     }
544
545     /**
546      * Return <code>true</code> if the specified <code>Extension</code>
547      * (which represents an optional package required by an application)
548      * is satisfied by this <code>Extension</code> (which represents an
549      * optional package that is already installed. Otherwise, return
550      * <code>false</code>.
551      *
552      * @param required Description of the required optional package
553      * @return true if the specified extension is compatible with this extension
554      */

555     public boolean isCompatibleWith( final Extension required )
556     {
557         return ( COMPATIBLE == getCompatibilityWith( required ) );
558     }
559
560     /**
561      * Return a String representation of this object.
562      *
563      * @return string representation of object.
564      */

565     public String JavaDoc toString()
566     {
567         final String JavaDoc lineSeparator = System.getProperty( "line.separator" );
568         final String JavaDoc brace = ": ";
569
570         final StringBuffer JavaDoc sb = new StringBuffer JavaDoc( EXTENSION_NAME.toString() );
571         sb.append( brace );
572         sb.append( m_extensionName );
573         sb.append( lineSeparator );
574
575         if( null != m_specificationVersion )
576         {
577             sb.append( SPECIFICATION_VERSION );
578             sb.append( brace );
579             sb.append( m_specificationVersion );
580             sb.append( lineSeparator );
581         }
582
583         if( null != m_specificationVendor )
584         {
585             sb.append( SPECIFICATION_VENDOR );
586             sb.append( brace );
587             sb.append( m_specificationVendor );
588             sb.append( lineSeparator );
589         }
590
591         if( null != m_implementationVersion )
592         {
593             sb.append( IMPLEMENTATION_VERSION );
594             sb.append( brace );
595             sb.append( m_implementationVersion );
596             sb.append( lineSeparator );
597         }
598
599         if( null != m_implementationVendorID )
600         {
601             sb.append( IMPLEMENTATION_VENDOR_ID );
602             sb.append( brace );
603             sb.append( m_implementationVendorID );
604             sb.append( lineSeparator );
605         }
606
607         if( null != m_implementationVendor )
608         {
609             sb.append( IMPLEMENTATION_VENDOR );
610             sb.append( brace );
611             sb.append( m_implementationVendor );
612             sb.append( lineSeparator );
613         }
614
615         if( null != m_implementationURL )
616         {
617             sb.append( IMPLEMENTATION_URL );
618             sb.append( brace );
619             sb.append( m_implementationURL );
620             sb.append( lineSeparator );
621         }
622
623         return sb.toString();
624     }
625
626     /**
627      * Return <code>true</code> if the first version number is greater than
628      * or equal to the second; otherwise return <code>false</code>.
629      *
630      * @param first First version number (dotted decimal)
631      * @param second Second version number (dotted decimal)
632      */

633     private boolean isCompatible( final DeweyDecimal first, final DeweyDecimal second )
634     {
635         return first.isGreaterThanOrEqual( second );
636     }
637
638     /**
639      * Retrieve all the extensions listed under a particular key
640      * (Usually EXTENSION_LIST or OPTIONAL_EXTENSION_LIST).
641      *
642      * @param manifest the manifest to extract extensions from
643      * @param listKey the key used to get list (Usually
644      * EXTENSION_LIST or OPTIONAL_EXTENSION_LIST)
645      * @return the list of listed extensions
646      */

647     private static Extension[] getListed( final Manifest JavaDoc manifest,
648                                           final Attributes.Name JavaDoc listKey )
649     {
650         if( null == manifest )
651           return new Extension[0];
652  
653         final ArrayList JavaDoc results = new ArrayList JavaDoc();
654         final Attributes JavaDoc mainAttributes = manifest.getMainAttributes();
655
656         if( null != mainAttributes )
657         {
658             getExtension( mainAttributes, results, listKey );
659         }
660
661         final Map JavaDoc entries = manifest.getEntries();
662         final Iterator JavaDoc keys = entries.keySet().iterator();
663         while( keys.hasNext() )
664         {
665             final String JavaDoc key = (String JavaDoc)keys.next();
666             final Attributes JavaDoc attributes = (Attributes JavaDoc)entries.get( key );
667             getExtension( attributes, results, listKey );
668         }
669
670         return (Extension[])results.toArray( new Extension[ 0 ] );
671     }
672
673     /**
674      * Add required optional packages defined in the specified attributes entry, if any.
675      *
676      * @param attributes Attributes to be parsed
677      * @param required list to add required optional packages to
678      * @param listKey the key to use to lookup list, usually EXTENSION_LIST
679      * or OPTIONAL_EXTENSION_LIST
680      */

681     private static void getExtension( final Attributes JavaDoc attributes,
682                                       final ArrayList JavaDoc required,
683                                       final Attributes.Name JavaDoc listKey )
684     {
685         final String JavaDoc names = attributes.getValue( listKey );
686         if( null == names )
687         {
688             return;
689         }
690
691         final String JavaDoc[] extentions = split( names, " " );
692         for( int i = 0; i < extentions.length; i++ )
693         {
694             final String JavaDoc prefix = extentions[ i ] + "-";
695             final Extension extension = getExtension( prefix, attributes );
696
697             if( null != extension )
698             {
699                 required.add( extension );
700             }
701         }
702     }
703
704     /**
705      * Splits the string on every token into an array of strings.
706      *
707      * @param string the string
708      * @param onToken the token
709      * @return the resultant array
710      */

711     private static final String JavaDoc[] split( final String JavaDoc string, final String JavaDoc onToken )
712     {
713         final StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc( string, onToken );
714         final String JavaDoc[] result = new String JavaDoc[ tokenizer.countTokens() ];
715
716         for( int i = 0; i < result.length; i++ )
717         {
718             result[ i ] = tokenizer.nextToken();
719         }
720
721         return result;
722     }
723
724     /**
725      * Extract an Extension from Attributes.
726      * Prefix indicates the prefix checked for each string.
727      * Usually the prefix is <em>"&lt;extension&gt;-"</em> if looking for a
728      * <b>Required</b> extension. If you are looking for an <b>Available</b> extension
729      * then the prefix is <em>""</em>.
730      *
731      * @param prefix the prefix for each attribute name
732      * @param attributes Attributes to searched
733      * @return the new Extension object, or null
734      */

735     private static Extension getExtension( final String JavaDoc prefix, final Attributes JavaDoc attributes )
736     {
737         //WARNING: We trim the values of all the attributes because
738
//Some extension declarations are badly defined (ie have spaces
739
//after version or vendorID)
740
final String JavaDoc nameKey = prefix + EXTENSION_NAME;
741         final String JavaDoc name = getTrimmedString( attributes.getValue( nameKey ) );
742         if( null == name )
743         {
744             return null;
745         }
746
747         final String JavaDoc specVendorKey = prefix + SPECIFICATION_VENDOR;
748         final String JavaDoc specVendor = getTrimmedString( attributes.getValue( specVendorKey ) );
749         final String JavaDoc specVersionKey = prefix + SPECIFICATION_VERSION;
750         final String JavaDoc specVersion = getTrimmedString( attributes.getValue( specVersionKey ) );
751
752         final String JavaDoc impVersionKey = prefix + IMPLEMENTATION_VERSION;
753         final String JavaDoc impVersion = getTrimmedString( attributes.getValue( impVersionKey ) );
754         final String JavaDoc impVendorKey = prefix + IMPLEMENTATION_VENDOR;
755         final String JavaDoc impVendor = getTrimmedString( attributes.getValue( impVendorKey ) );
756         final String JavaDoc impVendorIDKey = prefix + IMPLEMENTATION_VENDOR_ID;
757         final String JavaDoc impVendorId = getTrimmedString( attributes.getValue( impVendorIDKey ) );
758         final String JavaDoc impURLKey = prefix + IMPLEMENTATION_URL;
759         final String JavaDoc impURL = getTrimmedString( attributes.getValue( impURLKey ) );
760
761         return new Extension( name, specVersion, specVendor, impVersion,
762                               impVendor, impVendorId, impURL );
763     }
764
765     /**
766      * Trim the supplied string if the string is non-null
767      *
768      * @param value the string to trim or null
769      * @return the trimmed string or null
770      */

771     private static String JavaDoc getTrimmedString( final String JavaDoc value )
772     {
773         if( null == value )
774         {
775             return null;
776         }
777         else
778         {
779             return value.replace('"', ' ').trim();
780         }
781     }
782 }
783
Popular Tags