1 package org.codehaus.mojo.javascript.assembler;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.File;
20
21 import org.codehaus.plexus.PlexusConstants;
22 import org.codehaus.plexus.PlexusContainer;
23 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
24 import org.codehaus.plexus.context.Context;
25 import org.codehaus.plexus.context.ContextException;
26 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
27 import org.codehaus.plexus.util.FileUtils;
28
29
30
31
32 public class DefaultAssemblerReaderManager
33 implements AssemblerReaderManager, Contextualizable
34 {
35 private PlexusContainer container;
36
37 public void contextualize( Context context )
38 throws ContextException
39 {
40 container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
41 }
42
43
44
45
46
47
48 public AssemblerReader getAssemblerReader( File file )
49 throws NoSuchAssemblerReaderException
50 {
51 String ext = FileUtils.getExtension( file.getName() ).toLowerCase();
52 if ( "xml".equals( ext ) )
53 {
54 return getAssemblerReader( "default" );
55 }
56 return getAssemblerReader( ext );
57 }
58
59
60
61
62
63
64 public AssemblerReader getAssemblerReader( String name )
65 throws NoSuchAssemblerReaderException
66 {
67 try
68 {
69 return (AssemblerReader) container.lookup( AssemblerReader.ROLE, name );
70 }
71 catch ( ComponentLookupException e )
72 {
73 throw new NoSuchAssemblerReaderException( name );
74 }
75 }
76 }