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:
018: package org.apache.jetspeed.serializer.objects;
019:
020: import org.apache.commons.lang.StringEscapeUtils;
021:
022: import javolution.xml.XMLFormat;
023: import javolution.xml.stream.XMLStreamException;
024:
025: public abstract class JSSnapshot {
026:
027: private String name;
028:
029: private int savedVersion;
030:
031: private int savedSubversion;
032:
033: private String dateCreated;
034:
035: private String dataSource;
036:
037: /**
038: * check the software version and subvversion against the saved
039: * version...and verify whether it is compatible...
040: *
041: * @return the current software can process this file
042: */
043: public boolean checkVersion() {
044: return true;
045: }
046:
047: public JSSnapshot() {
048: System.out.println(this .getClass().getName() + " created");
049: }
050:
051: public JSSnapshot(String name) {
052: this .name = name;
053: }
054:
055: /**
056: * @return Returns the name.
057: */
058: public final String getName() {
059: return name;
060: }
061:
062: /**
063: * @return Returns the softwareSubVersion.
064: */
065: public abstract int getSoftwareSubVersion();
066:
067: /**
068: * @return Returns the softwareVersion.
069: */
070: public abstract int getSoftwareVersion();
071:
072: /**
073: * @return Returns the dataSource.
074: */
075: public final String getDataSource() {
076: return dataSource;
077: }
078:
079: /**
080: * @param dataSource
081: * The dataSource to set.
082: */
083: public final void setDataSource(String dataSource) {
084: this .dataSource = dataSource;
085: }
086:
087: /**
088: * @return Returns the dateCreated.
089: */
090: public final String getDateCreated() {
091: return dateCreated;
092: }
093:
094: /**
095: * @param dateCreated
096: * The dateCreated to set.
097: */
098: public final void setDateCreated(String dateCreated) {
099: this .dateCreated = dateCreated;
100: }
101:
102: /**
103: * @return Returns the savedSubversion.
104: */
105: public final int getSavedSubversion() {
106: return savedSubversion;
107: }
108:
109: /**
110: * @param savedSubversion
111: * The savedSubversion to set.
112: */
113: public final void setSavedSubversion(int savedSubversion) {
114: this .savedSubversion = savedSubversion;
115: }
116:
117: /**
118: * @return Returns the savedVersion.
119: */
120: public final int getSavedVersion() {
121: return savedVersion;
122: }
123:
124: /**
125: * @param savedVersion
126: * The savedVersion to set.
127: */
128: public final void setSavedVersion(int savedVersion) {
129: this .savedVersion = savedVersion;
130: }
131:
132: /**
133: * @param name
134: * The name to set.
135: */
136: public final void setName(String name) {
137: this .name = name;
138: }
139:
140: /***************************************************************************
141: * SERIALIZER
142: */
143: protected static final XMLFormat XML = new XMLFormat(
144: JSSnapshot.class) {
145:
146: public void write(Object o, OutputElement xml)
147: throws XMLStreamException {
148:
149: try {
150: JSSnapshot g = (JSSnapshot) o;
151:
152: /** attributes here */
153:
154: xml.setAttribute("name", g.getName());
155:
156: /** named fields HERE */
157:
158: xml.add(String.valueOf(g.getSoftwareVersion()),
159: "softwareVersion");
160: xml.add(String.valueOf(g.getSoftwareSubVersion()),
161: "softwareSubVersion");
162: } catch (Exception e) {
163: e.printStackTrace();
164: }
165: }
166:
167: public void read(InputElement xml, Object o) {
168: try {
169: JSSnapshot g = (JSSnapshot) o;
170: g.name = StringEscapeUtils.unescapeHtml(xml
171: .getAttribute("name", "unknown"));
172: Object o1 = xml.get("softwareVersion", String.class);
173: if (o1 instanceof String)
174: g.savedVersion = Integer.parseInt(((String) o1));
175: o1 = xml.get("softwareSubVersion", String.class);
176: if (o1 instanceof String)
177: g.savedSubversion = Integer.parseInt(((String) o1));
178: } catch (Exception e) {
179: e.printStackTrace();
180: }
181: }
182: };
183:
184: }
|