View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
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  package org.springframework.extensions.webscripts;
20  
21  import java.util.Set;
22  
23  import org.springframework.beans.factory.InitializingBean;
24  
25  
26  /**
27   * Set of Format Readers and Writers.
28   * 
29   * @author davidc
30   */
31  public class FormatAdaptorSet implements InitializingBean
32  {
33      private FormatRegistry registry;
34      private Set<FormatReader<Object>> readers;
35      private Set<FormatWriter<Object>> writers;
36  
37      /**
38       * Sets the Format Registry
39       * 
40       * @param registry
41       */
42      public void setRegistry(FormatRegistry registry)
43      {
44          this.registry = registry;
45      }
46      
47      /**
48       * Sets the readers
49       * 
50       * @param readers
51       */
52      public void setReaders(Set<FormatReader<Object>> readers)
53      {
54          this.readers = readers;
55      }
56  
57      /**
58       * Sets the writers
59       * 
60       * @param writers
61       */
62      public void setWriters(Set<FormatWriter<Object>> writers)
63      {
64          this.writers = writers;
65      }
66  
67      /* (non-Javadoc)
68       * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
69       */
70      public void afterPropertiesSet() throws Exception
71      {
72          if (readers != null)
73          {
74              for (FormatReader<Object> reader : readers)
75              {
76                  registry.addReader(reader);
77              }
78          }
79          if (writers != null)
80          {
81              for (FormatWriter<Object> writer : writers)
82              {
83                  registry.addWriter(writer);
84              }
85          }
86      }
87      
88  }