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.Iterator;
020: import java.util.List;
021:
022: import org.apache.jetspeed.om.preference.FragmentPreference;
023: import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
024: import org.apache.pluto.om.common.Preference;
025: import org.apache.pluto.om.common.PreferenceCtrl;
026:
027: /**
028: * FragmentPreferenceImpl
029: *
030: * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
031: * @version $Id$
032: */
033: public class FragmentPreferenceImpl implements Preference,
034: PreferenceCtrl, FragmentPreference {
035: private int id;
036: private String name;
037: private boolean readOnly;
038: private List values;
039:
040: private FragmentPreferenceValueList preferenceValues;
041:
042: /**
043: * accessValues
044: *
045: * Access mutable persistent collection member for List wrappers.
046: *
047: * @return persistent collection
048: */
049: List accessValues() {
050: // create initial collection if necessary
051: if (values == null) {
052: values = DatabasePageManagerUtils.createList();
053: }
054: return values;
055: }
056:
057: /* (non-Javadoc)
058: * @see org.apache.jetspeed.om.preference.FragmentPreference#getName()
059: * @see org.apache.pluto.om.common.Preference#getName()
060: */
061: public String getName() {
062: return name;
063: }
064:
065: /* (non-Javadoc)
066: * @see org.apache.jetspeed.om.preference.FragmentPreference#setName(java.lang.String)
067: * @see org.apache.pluto.om.common.PreferenceCtrl#setName(java.lang.String)
068: */
069: public void setName(String name) {
070: this .name = name;
071: }
072:
073: /* (non-Javadoc)
074: * @see org.apache.jetspeed.om.preference.FragmentPreference#isReadOnly()
075: * @see org.apache.pluto.om.common.Preference#isReadOnly()
076: */
077: public boolean isReadOnly() {
078: return readOnly;
079: }
080:
081: /* (non-Javadoc)
082: * @see org.apache.jetspeed.om.preference.FragmentPreference#setReadOnly(boolean)
083: */
084: public void setReadOnly(boolean readOnly) {
085: this .readOnly = readOnly;
086: }
087:
088: /* (non-Javadoc)
089: * @see org.apache.jetspeed.om.preference.FragmentPreference#getValueList()
090: */
091: public List getValueList() {
092: // return mutable preference value list
093: // using list wrapper to manage value order
094: if (preferenceValues == null) {
095: preferenceValues = new FragmentPreferenceValueList(this );
096: }
097: return preferenceValues;
098: }
099:
100: /* (non-Javadoc)
101: * @see org.apache.jetspeed.om.preference.FragmentPreference#setValueList(java.util.List)
102: */
103: public void setValueList(List values) {
104: // set preference values by replacing existing
105: // entries with new elements if new collection
106: // is specified
107: List preferenceValues = getValueList();
108: if (values != preferenceValues) {
109: // replace all values
110: preferenceValues.clear();
111: if (values != null) {
112: preferenceValues.addAll(values);
113: }
114: }
115: }
116:
117: /* (non-Javadoc)
118: * @see org.apache.pluto.om.common.Preference#getValues()
119: */
120: public Iterator getValues() {
121: return getValueList().iterator();
122: }
123:
124: /* (non-Javadoc)
125: * @see org.apache.pluto.om.common.Preference#isValueSet()
126: */
127: public boolean isValueSet() {
128: return !getValueList().isEmpty();
129: }
130:
131: /* (non-Javadoc)
132: * @see org.apache.pluto.om.common.PreferenceCtrl#setValues(java.util.List)
133: */
134: public void setValues(List values) {
135: setValueList(values);
136: }
137:
138: /* (non-Javadoc)
139: * @see org.apache.pluto.om.common.PreferenceCtrl#setReadOnly(java.lang.String)
140: */
141: public void setReadOnly(String readOnly) {
142: setReadOnly(new Boolean(readOnly).booleanValue());
143: }
144:
145: /* (non-Javadoc)
146: * @see java.lang.Object#equals(java.lang.Object)
147: */
148: public boolean equals(Object o) {
149: if (o instanceof FragmentPreferenceImpl) {
150: if (name != null) {
151: return name.equals(((FragmentPreferenceImpl) o)
152: .getName());
153: }
154: return (((FragmentPreferenceImpl) o).getName() == null);
155: }
156: return false;
157: }
158:
159: /* (non-Javadoc)
160: * @see java.lang.Object#hashCode()
161: */
162: public int hashCode() {
163: if (name != null) {
164: return name.hashCode();
165: }
166: return 0;
167: }
168: }
|