View Javadoc

1   /* 
2    * Copyright 2002-2004 The 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  package org.apache.struts.flow.core.source.impl;
18  
19  import java.io.IOException;
20  import java.net.MalformedURLException;
21  import java.util.Map;
22  
23  import org.apache.struts.flow.core.Factory;
24  import org.apache.struts.flow.core.Logger;
25  
26  import org.apache.struts.flow.core.source.Source;
27  import org.apache.struts.flow.core.source.SourceException;
28  import org.apache.struts.flow.core.source.SourceFactory;
29  
30  /***
31   * A factory for the Resource protocol
32   * 
33   * @avalon.component
34   * @avalon.service type=SourceFactory
35   * @x-avalon.info name=resource-source
36   * @x-avalon.lifestyle type=singleton
37   *
38   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
39   * @version $Id: ResourceSourceFactory.java,v 1.4 2004/02/28 11:47:24 cziegeler Exp $
40   */
41  public class ResourceSourceFactory implements SourceFactory
42  {
43      /***
44       * Get a {@link Source} object.
45       * The factory creates a new {@link Source} object that can be used
46       * by the application. However, when this source object is not needed
47       * anymore it has to be released again using the {@link #release(Source)}
48       * method.
49       * 
50       * @param location   The URI to resolve - this URI includes the protocol.
51       * @param parameters This is optional.
52       */
53      public Source getSource( String location, Map parameters )
54          throws MalformedURLException, IOException, SourceException
55      {
56          if( getLogger().isDebugEnabled() )
57          {
58              final String message = "Creating source object for " + location;
59              getLogger().debug( message );
60          }
61          return new ResourceSource( location );
62      }
63      
64      /***
65       * Release a {@link Source} object.
66       */
67      public void release( Source source ) 
68      {
69          if( null != source && getLogger().isDebugEnabled() )
70          {
71              final String message = "Releasing source object for " + source.getURI();
72              getLogger().debug( message );
73          }
74          // do nothing here
75      }
76      
77      public Logger getLogger() {
78          return Factory.getLogger();
79      }
80      
81  }