001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.core.impl.portlet.state;
023:
024: import org.jboss.portal.common.value.StringValue;
025: import org.jboss.portal.common.value.Value;
026:
027: import java.io.Serializable;
028:
029: /**
030: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
031: * @version $Revision: 8786 $
032: */
033: public class PersistentPortletStateEntry implements Serializable {
034:
035: /** The primary key. */
036: private Long key;
037:
038: /** The name. */
039: private String name;
040:
041: /** The access mode. */
042: private boolean readOnly;
043:
044: /** The preference type. */
045: private int type;
046:
047: /** The preference values. */
048: private String[] strings;
049:
050: /** The value implementation. */
051: private Value value;
052:
053: // This flag is used because the value is made up of strings and type
054: // and it is not possible to update the value when strings or type
055: // is updated, so when strings of type is modified with set dirty
056: private boolean dirty;
057:
058: public PersistentPortletStateEntry() {
059: this .key = null;
060: this .name = null;
061: this .readOnly = false;
062: this .type = 0;
063: this .strings = null;
064: this .value = null;
065: this .dirty = false;
066: }
067:
068: public PersistentPortletStateEntry(String name, Value value) {
069: if (value == null) {
070: throw new IllegalArgumentException();
071: }
072: this .key = null;
073: this .name = name;
074: this .readOnly = false;
075: this .type = 1;
076: this .strings = value.asStringArray();
077: this .value = value;
078: this .dirty = false;
079: }
080:
081: public Long getKey() {
082: return key;
083: }
084:
085: public void setKey(Long key) {
086: this .key = key;
087: }
088:
089: /**
090: *
091: */
092: public String getName() {
093: return name;
094: }
095:
096: /** Called by hibernate. */
097: public void setName(String name) {
098: this .name = name;
099: }
100:
101: /**
102: *
103: */
104: public int getType() {
105: return type;
106: }
107:
108: /** Called by hibernate. */
109: public void setType(int type) {
110: this .type = type;
111: this .dirty = true;
112: }
113:
114: public boolean isReadOnly() {
115: return readOnly;
116: }
117:
118: public void setReadOnly(boolean readOnly) {
119: this .readOnly = readOnly;
120: }
121:
122: /**
123: *
124: */
125: public String[] getStrings() {
126: return strings;
127: }
128:
129: /** Called by hibernate. */
130: public void setStrings(String[] strings) {
131: this .strings = strings;
132: this .dirty = true;
133: }
134:
135: public Value getValue() {
136: if (dirty) {
137: value = new StringValue(strings);
138: dirty = false;
139: }
140: return value;
141: }
142:
143: /**
144: *
145: */
146: public void setValue(Value value) {
147: this .value = value;
148: this .strings = value.asStringArray();
149: }
150:
151: /** Provide a default impl. */
152: public String toString() {
153: StringBuffer buffer = new StringBuffer("[").append(name)
154: .append(",");
155: if (strings == null) {
156: buffer.append("null,");
157: } else {
158: buffer.append("(");
159: for (int i = 0; i < strings.length; i++) {
160: String s = strings[i];
161: buffer.append(i > 0 ? "," : "").append(s);
162: }
163: buffer.append("),");
164: }
165: buffer.append(value).append("]");
166: return buffer.toString();
167: }
168: }
|