001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.om.page.impl;
018:
019: import java.util.HashMap;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.apache.jetspeed.om.common.SecurityConstraint;
025: import org.apache.jetspeed.om.page.PageSecurity;
026: import org.apache.jetspeed.om.page.SecurityConstraintsDef;
027: import org.apache.jetspeed.page.document.impl.DocumentImpl;
028: import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
029:
030: /**
031: * PageSecurityImpl
032: *
033: * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
034: * @version $Id$
035: */
036: public class PageSecurityImpl extends DocumentImpl implements
037: PageSecurity {
038: private List constraintsDefs;
039: private List globalConstraintsRefs;
040:
041: private PageSecurityConstraintsDefList securityConstraintsDefs;
042: private Map securityConstraintsDefsMap;
043: private PageSecurityConstraintsRefList globalSecurityConstraintsRefs;
044:
045: public PageSecurityImpl() {
046: super (null);
047: }
048:
049: /**
050: * accessConstraintsDefs
051: *
052: * Access mutable persistent collection member for List wrappers.
053: *
054: * @return persistent collection
055: */
056: List accessConstraintsDefs() {
057: // create initial collection if necessary
058: if (constraintsDefs == null) {
059: constraintsDefs = DatabasePageManagerUtils.createList();
060: }
061: return constraintsDefs;
062: }
063:
064: /**
065: * accessGlobalConstraintsRefs
066: *
067: * Access mutable persistent collection member for List wrappers.
068: *
069: * @return persistent collection
070: */
071: List accessGlobalConstraintsRefs() {
072: // create initial collection if necessary
073: if (globalConstraintsRefs == null) {
074: globalConstraintsRefs = DatabasePageManagerUtils
075: .createList();
076: }
077: return globalConstraintsRefs;
078: }
079:
080: /**
081: * clearSecurityConstraintsDefsMap
082: *
083: * Clear previously cached security constraints definitions map.
084: */
085: synchronized void clearSecurityConstraintsDefsMap() {
086: securityConstraintsDefsMap = null;
087: }
088:
089: /* (non-Javadoc)
090: * @see org.apache.jetspeed.om.common.SecuredResource#newSecurityConstraint()
091: */
092: public SecurityConstraint newSecurityConstraint() {
093: // return specific security constraint definition instance
094: return new PageSecuritySecurityConstraintImpl();
095: }
096:
097: /* (non-Javadoc)
098: * @see org.apache.jetspeed.om.page.PageSecurity#getSecurityConstraintsDefs()
099: */
100: public List getSecurityConstraintsDefs() {
101: // return mutable constraints defs list
102: // by using list wrapper to manage
103: // element uniqueness
104: if (securityConstraintsDefs == null) {
105: securityConstraintsDefs = new PageSecurityConstraintsDefList(
106: this );
107: }
108: return securityConstraintsDefs;
109: }
110:
111: /* (non-Javadoc)
112: * @see org.apache.jetspeed.om.common.SecuredResource#newSecurityConstraintsDef()
113: */
114: public SecurityConstraintsDef newSecurityConstraintsDef() {
115: // return specific security constraints definition instance
116: return new SecurityConstraintsDefImpl();
117: }
118:
119: /* (non-Javadoc)
120: * @see org.apache.jetspeed.om.page.PageSecurity#setSecurityConstraintsDefs(java.util.List)
121: */
122: public void setSecurityConstraintsDefs(List definitions) {
123: // set constraints defs by replacing existing
124: // entries with new elements if new collection
125: // is specified
126: List securityConstraintsDefs = getSecurityConstraintsDefs();
127: if (definitions != securityConstraintsDefs) {
128: // replace all constraints definitions
129: securityConstraintsDefs.clear();
130: if (definitions != null) {
131: securityConstraintsDefs.addAll(definitions);
132: }
133: }
134: // clear cached security constraints definition map
135: clearSecurityConstraintsDefsMap();
136: }
137:
138: /* (non-Javadoc)
139: * @see org.apache.jetspeed.om.page.PageSecurity#getSecurityConstraintsDef(java.lang.String)
140: */
141: public synchronized SecurityConstraintsDef getSecurityConstraintsDef(
142: String name) {
143: // build and cache security constraints definitions
144: // map if necessary upon realization or after modification
145: if ((getSecurityConstraintsDefs() != null)
146: && (securityConstraintsDefsMap == null)) {
147: securityConstraintsDefsMap = new HashMap(
148: (getSecurityConstraintsDefs().size() * 2) + 1);
149: Iterator definitionsIter = getSecurityConstraintsDefs()
150: .iterator();
151: while (definitionsIter.hasNext()) {
152: SecurityConstraintsDef definition = (SecurityConstraintsDef) definitionsIter
153: .next();
154: String definitionName = definition.getName();
155: if (!securityConstraintsDefsMap
156: .containsKey(definitionName)) {
157: securityConstraintsDefsMap.put(definitionName,
158: definition);
159: }
160: }
161: }
162: // lookup constraints definition using cached map
163: if (securityConstraintsDefsMap != null) {
164: return (SecurityConstraintsDef) securityConstraintsDefsMap
165: .get(name);
166: }
167: return null;
168: }
169:
170: /* (non-Javadoc)
171: * @see org.apache.jetspeed.om.page.PageSecurity#getGlobalSecurityConstraintsRefs()
172: */
173: public List getGlobalSecurityConstraintsRefs() {
174: // return mutable constraints refs list
175: // by using list wrapper to manage apply
176: // order and element uniqueness
177: if (globalSecurityConstraintsRefs == null) {
178: globalSecurityConstraintsRefs = new PageSecurityConstraintsRefList(
179: this );
180: }
181: return globalSecurityConstraintsRefs;
182: }
183:
184: /* (non-Javadoc)
185: * @see org.apache.jetspeed.om.page.PageSecurity#setGlobalSecurityConstraintsRefs(java.util.List)
186: */
187: public void setGlobalSecurityConstraintsRefs(List constraintsRefs) {
188: // set constraints refs using ordered ref
189: // names by replacing existing entries with
190: // new elements if new collection is specified
191: List globalSecurityConstraintsRefs = getGlobalSecurityConstraintsRefs();
192: if (constraintsRefs != globalSecurityConstraintsRefs) {
193: // replace all constraints ref names
194: globalSecurityConstraintsRefs.clear();
195: if (constraintsRefs != null) {
196: globalSecurityConstraintsRefs.addAll(constraintsRefs);
197: }
198: }
199: }
200:
201: /* (non-Javadoc)
202: * @see org.apache.jetspeed.page.document.Node#getType()
203: */
204: public String getType() {
205: return DOCUMENT_TYPE;
206: }
207: }
|