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  package org.apache.jetspeed.om.page.impl;
18  
19  import java.util.List;
20  
21  import org.apache.jetspeed.om.page.SecurityConstraintsDef;
22  import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
23  
24  /***
25   * SecurityConstraintsDefImpl
26   *
27   * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
28   * @version $Id$
29   */
30  public class SecurityConstraintsDefImpl implements SecurityConstraintsDef
31  {
32      private int id;
33      private String name;
34      private List constraintDefs = DatabasePageManagerUtils.createList();
35  
36      private SecurityConstraintDefList securityConstraintDefs;
37  
38      /***
39       * accessConstraintDefs
40       *
41       * Access mutable persistent collection member for List wrappers.
42       *
43       * @return persistent collection
44       */
45      List accessConstraintDefs()
46      {
47          // create initial collection if necessary
48          if (constraintDefs == null)
49          {
50              constraintDefs = DatabasePageManagerUtils.createList();
51          }
52          return constraintDefs;
53      }
54  
55      /* (non-Javadoc)
56       * @see org.apache.jetspeed.om.page.SecurityConstraintsDef#getName()
57       */
58      public String getName()
59      {
60          return name;
61      }
62  
63      /* (non-Javadoc)
64       * @see org.apache.jetspeed.om.page.SecurityConstraintsDef#setName(java.lang.String)
65       */
66      public void setName(String name)
67      {
68          this.name = name;
69      }
70  
71      /* (non-Javadoc)
72       * @see org.apache.jetspeed.om.page.SecurityConstraintsDef#getSecurityConstraints()
73       */
74      public List getSecurityConstraints()
75      {
76          // return mutable constraint def list
77          // by using list wrapper to manage apply order
78          if (securityConstraintDefs == null)
79          {
80              securityConstraintDefs = new SecurityConstraintDefList(this);
81          }
82          return securityConstraintDefs;
83      }
84      
85      /* (non-Javadoc)
86       * @see org.apache.jetspeed.om.page.SecurityConstraintsDef#setSecurityConstraints(java.util.List)
87       */
88      public void setSecurityConstraints(List constraints)
89      {
90          // set constraint defs by replacing existing
91          // entries with new elements if new collection
92          // is specified
93          List securityConstraintDefs = getSecurityConstraints();
94          if (constraints != securityConstraintDefs)
95          {
96              // replace all constraints
97              securityConstraintDefs.clear();
98              if (constraints != null)
99              {
100                 securityConstraintDefs.addAll(constraints);
101             }
102         }
103     }
104 
105     /* (non-Javadoc)
106      * @see java.lang.Object#equals(java.lang.Object)
107      */
108     public boolean equals(Object o)
109     {
110         if (o instanceof SecurityConstraintsDefImpl)
111         {
112             if (name != null)
113             {
114                 return name.equals(((SecurityConstraintsDefImpl)o).getName());
115             }
116             return (((SecurityConstraintsDefImpl)o).getName() == null);
117         }
118         return false;
119     }
120 
121     /* (non-Javadoc)
122      * @see java.lang.Object#hashCode()
123      */
124     public int hashCode()
125     {
126         if (name != null)
127         {
128             return name.hashCode();
129         }
130         return 0;
131     }
132 }