View Javadoc

1   package org.codehaus.mojo.javascript.assembler;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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   * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
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       * {@inheritDoc}
45       * 
46       * @see org.codehaus.mojo.javascript.assembler.AssemblerReaderManager#getAssemblerReader(java.io.File)
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       * {@inheritDoc}
61       * 
62       * @see org.codehaus.mojo.javascript.assembler.AssemblerReaderManager#getAssemblerReader(java.lang.String)
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  }