2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shale.remoting.impl;
19  
20  import java.io.Serializable;
21  import java.util.ArrayList;
22  import java.util.Iterator;
23  import java.util.List;
24  import javax.faces.application.ViewHandler;
25  import org.apache.shale.remoting.Mapping;
26  import org.apache.shale.remoting.Mappings;
27  
28  /***
29   * <p>Default implementation of {@link Mappings}.</p>
30   */
31  public class MappingsImpl implements Mappings, Serializable {
32  
33  
34      // ------------------------------------------------------ Instance Variables
35  
36  
37      /***
38       * Serial version UID.
39       */
40      private static final long serialVersionUID = 7761184295213057256L;
41  
42  
43      /***
44       * <p>The extension that will replace the <code>FacesServlet</code>
45       * extension, if the servlet is extension mapped.</p>
46       */
47      private String extension = ViewHandler.DEFAULT_SUFFIX;
48  
49  
50      /***
51       * <p>A list of {@link Mapping} instances we understand.</p>
52       */
53      private List mappings = new ArrayList();
54  
55  
56      /***
57       * <p>The zero relative index of the URL pattern, in the <code>patterns</code>
58       * array, to use for generating resource URLs.</p>
59       */
60      private int patternIndex = 0;
61  
62  
63      /***
64       * <p>The list of URL patterns for <code>FacesServlet</code>.</p>
65       */
66      private String[] patterns = new String[0];
67  
68  
69      // -------------------------------------------------------- Mappings Methods
70  
71  
72      /*** {@inheritDoc} */
73      public void addMapping(Mapping mapping) {
74          if (mapping == null) {
75              throw new NullPointerException();
76          }
77          synchronized (mappings) {
78              if (!mappings.contains(mapping)) {
79                  mappings.add(mapping);
80              }
81          }
82      }
83  
84  
85      /*** {@inheritDoc} */
86      public String getExtension() {
87          return this.extension;
88      }
89  
90  
91      /*** {@inheritDoc} */
92      public Mapping getMapping(String pattern) {
93          if (pattern == null) {
94              throw new NullPointerException();
95          }
96          synchronized (mappings) {
97              Iterator items = mappings.iterator();
98              while (items.hasNext()) {
99                  Mapping item = (Mapping) items.next();
100                 if (pattern.equals(item.getPattern())) {
101                     return item;
102                 }
103             }
104             return null;
105         }
106     }
107 
108 
109     /*** {@inheritDoc} */
110     public List getMappings() {
111         return this.mappings;
112     }
113 
114 
115     /*** {@inheritDoc} */
116     public int getPatternIndex() {
117         return this.patternIndex;
118     }
119 
120 
121     /*** {@inheritDoc} */
122     public void setPatternIndex(int patternIndex) {
123         this.patternIndex = patternIndex;
124     }
125 
126 
127     /*** {@inheritDoc} */
128     public String[] getPatterns() {
129         return this.patterns;
130     }
131 
132 
133     /*** {@inheritDoc} */
134     public void removeMapping(Mapping mapping) {
135         if (mapping == null) {
136             throw new NullPointerException();
137         }
138         synchronized (mappings) {
139             mappings.remove(mapping);
140         }
141     }
142 
143 
144     /*** {@inheritDoc} */
145     public void setExtension(String extension) {
146         this.extension = extension;
147     }
148 
149 
150     /*** {@inheritDoc} */
151     public void setPatterns(String[] patterns) {
152         this.patterns = patterns;
153     }
154 
155 
156 }