View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.servlet;
20  
21  import java.io.IOException;
22  import java.util.Arrays;
23  
24  import org.eclipse.jetty.util.annotation.ManagedAttribute;
25  import org.eclipse.jetty.util.annotation.ManagedObject;
26  
27  @ManagedObject("Servlet Mapping")
28  public class ServletMapping
29  {
30      private String[] _pathSpecs;
31      private String _servletName;
32      private boolean _default;
33      
34  
35      /* ------------------------------------------------------------ */
36      public ServletMapping()
37      {
38      }
39      
40      /* ------------------------------------------------------------ */
41      /**
42       * @return Returns the pathSpecs.
43       */
44      @ManagedAttribute(value="url patterns", readonly=true)
45      public String[] getPathSpecs()
46      {
47          return _pathSpecs;
48      }
49      
50      /* ------------------------------------------------------------ */
51      /**
52       * @return Returns the servletName.
53       */
54      @ManagedAttribute(value="servlet name", readonly=true)
55      public String getServletName()
56      {
57          return _servletName;
58      }
59      
60      /* ------------------------------------------------------------ */
61      /**
62       * @param pathSpecs The pathSpecs to set.
63       */
64      public void setPathSpecs(String[] pathSpecs)
65      {
66          _pathSpecs = pathSpecs;
67      }
68      
69      
70      /* ------------------------------------------------------------ */
71      /** Test if the list of path specs contains a particular one.
72       * @param pathSpec the test pathspec
73       * @return true if pathspec contains test spec
74       */
75      public boolean containsPathSpec (String pathSpec)
76      {
77          if (_pathSpecs == null || _pathSpecs.length == 0)
78              return false;
79          
80          for (String p:_pathSpecs)
81          {
82              if (p.equals(pathSpec))
83                  return true;
84          }
85          return false;
86      }
87  
88      /* ------------------------------------------------------------ */
89      /**
90       * @param pathSpec The pathSpec to set.
91       */
92      public void setPathSpec(String pathSpec)
93      {
94          _pathSpecs = new String[]{pathSpec};
95      }
96      
97      /* ------------------------------------------------------------ */
98      /**
99       * @param servletName The servletName to set.
100      */
101     public void setServletName(String servletName)
102     {
103         _servletName = servletName;
104     }
105     
106     
107     /* ------------------------------------------------------------ */
108     @ManagedAttribute(value="default", readonly=true)
109     public boolean isDefault()
110     {
111         return _default;
112     }
113     
114     
115     /* ------------------------------------------------------------ */
116     public void setDefault(boolean fromDefault)
117     {
118         _default = fromDefault;
119     }
120 
121     /* ------------------------------------------------------------ */
122     public String toString()
123     {
124         return (_pathSpecs==null?"[]":Arrays.asList(_pathSpecs).toString())+"=>"+_servletName; 
125     }
126 
127     /* ------------------------------------------------------------ */
128     public void dump(Appendable out, String indent) throws IOException
129     {
130         out.append(String.valueOf(this)).append("\n");
131     }
132 }