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  
18  package org.apache.jetspeed.serializer.objects;
19  
20  import org.apache.commons.lang.StringEscapeUtils;
21  
22  import javolution.xml.XMLFormat;
23  import javolution.xml.stream.XMLStreamException;
24  
25  public abstract class JSSnapshot
26  {
27  		
28  
29  	    private String name;
30  
31  	    private int savedVersion;
32  
33  	    private int savedSubversion;
34  
35  	    private String dateCreated;
36  
37  	    private String dataSource;
38  
39  
40  	    /***
41  	     * check the software version and subvversion against the saved
42  	     * version...and verify whether it is compatible...
43  	     * 
44  	     * @return the current software can process this file
45  	     */
46  	    public boolean checkVersion()
47  	    {
48  	        return true;
49  	    }
50  
51  	    public JSSnapshot()
52  	    {
53  	        System.out.println(this.getClass().getName() + " created");
54  	    }
55  
56  	    public JSSnapshot(String name)
57  	    {
58  	        this.name = name;
59  	    }
60  
61  	 
62  
63  
64  	    /***
65  	     * @return Returns the name.
66  	     */
67  	    public final String getName()
68  	    {
69  	        return name;
70  	    }
71  
72  
73  	    /***
74  	     * @return Returns the softwareSubVersion.
75  	     */
76  	    public abstract int getSoftwareSubVersion();
77  
78  	    /***
79  	     * @return Returns the softwareVersion.
80  	     */
81  	    public abstract int getSoftwareVersion();
82  
83  	    /***
84  	     * @return Returns the dataSource.
85  	     */
86  	    public final String getDataSource()
87  	    {
88  	        return dataSource;
89  	    }
90  
91  	    /***
92  	     * @param dataSource
93  	     *            The dataSource to set.
94  	     */
95  	    public final  void setDataSource(String dataSource)
96  	    {
97  	        this.dataSource = dataSource;
98  	    }
99  
100 	    /***
101 	     * @return Returns the dateCreated.
102 	     */
103 	    public final  String getDateCreated()
104 	    {
105 	        return dateCreated;
106 	    }
107 
108 	    /***
109 	     * @param dateCreated
110 	     *            The dateCreated to set.
111 	     */
112 	    public final  void setDateCreated(String dateCreated)
113 	    {
114 	        this.dateCreated = dateCreated;
115 	    }
116 
117 
118 	    /***
119 	     * @return Returns the savedSubversion.
120 	     */
121 	    public final  int getSavedSubversion()
122 	    {
123 	        return savedSubversion;
124 	    }
125 
126 	    /***
127 	     * @param savedSubversion
128 	     *            The savedSubversion to set.
129 	     */
130 	    public final  void setSavedSubversion(int savedSubversion)
131 	    {
132 	        this.savedSubversion = savedSubversion;
133 	    }
134 
135 	    /***
136 	     * @return Returns the savedVersion.
137 	     */
138 	    public final  int getSavedVersion()
139 	    {
140 	        return savedVersion;
141 	    }
142 
143 	    /***
144 	     * @param savedVersion
145 	     *            The savedVersion to set.
146 	     */
147 	    public final  void setSavedVersion(int savedVersion)
148 	    {
149 	        this.savedVersion = savedVersion;
150 	    }
151 
152 	    /***
153 	     * @param name
154 	     *            The name to set.
155 	     */
156 	    public final  void setName(String name)
157 	    {
158 	        this.name = name;
159 	    }
160 
161 
162 
163     /****************************************************************************
164      * SERIALIZER
165      */
166     protected static final XMLFormat XML = new XMLFormat(JSSnapshot.class)
167     {
168 
169         public void write(Object o, OutputElement xml)
170                 throws XMLStreamException
171         {
172         	
173             try
174             {
175                 JSSnapshot g = (JSSnapshot) o;
176 
177                 /*** attributes here */
178 
179                 xml.setAttribute("name", g.getName());
180 
181                 /*** named fields HERE */
182 
183                 xml.add(String.valueOf(g.getSoftwareVersion()),
184                         "softwareVersion");
185                 xml.add(String.valueOf(g.getSoftwareSubVersion()),
186                         "softwareSubVersion");
187             } catch (Exception e)
188             {
189                 e.printStackTrace();
190             }
191         }
192 
193         public void read(InputElement xml, Object o)
194         {
195             try
196             {
197                 JSSnapshot g = (JSSnapshot) o;
198                 g.name = StringEscapeUtils.unescapeHtml(xml.getAttribute("name", "unknown"));
199                 Object o1 = xml.get("softwareVersion",String.class);
200                 if (o1 instanceof String)
201                     g.savedVersion = Integer.parseInt(((String) o1));
202                 o1 = xml.get("softwareSubVersion",String.class);
203                 if (o1 instanceof String)
204                     g.savedSubversion = Integer.parseInt(((String) o1));
205            } catch (Exception e)
206             {
207                 e.printStackTrace();
208             }
209         }
210     };
211 
212  
213 }