0
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.s60tools.apiquery.cache.configuration;
|
|
19 |
|
|
20 |
|
|
21 |
import java.io.FileNotFoundException;
|
|
22 |
import java.io.IOException;
|
|
23 |
|
|
24 |
import com.nokia.s60tools.apiquery.cache.resources.Messages;
|
|
25 |
import com.nokia.s60tools.apiquery.cache.xml.MetadataXMLToUIMappingRules;
|
|
26 |
import com.nokia.s60tools.apiquery.shared.datatypes.APIDetails;
|
|
27 |
import com.nokia.s60tools.apiquery.shared.datatypes.config.AbstractEntry;
|
|
28 |
import com.nokia.s60tools.apiquery.shared.exceptions.XMLNotValidException;
|
|
29 |
import com.nokia.s60tools.apiquery.shared.util.xml.XMLUtils;
|
|
30 |
import com.nokia.s60tools.sdk.SdkInformation;
|
|
31 |
import com.nokia.s60tools.util.resource.FileUtils;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* Stores information for a single API Metadata information from the SDK entry.
|
|
35 |
*/
|
|
36 |
public class CacheEntry extends AbstractEntry {
|
|
37 |
|
|
38 |
//
|
|
39 |
// Column sorting indices for table column sorter
|
|
40 |
//
|
|
41 |
public static final int NAME_COLUMN_INDEX = 0;
|
|
42 |
public static final int FOLDER_COLUMN_INDEX = 1;
|
|
43 |
|
|
44 |
/**
|
|
45 |
* file size
|
|
46 |
*/
|
|
47 |
private long size;
|
|
48 |
/**
|
|
49 |
* File name
|
|
50 |
*/
|
|
51 |
private String name;
|
|
52 |
|
|
53 |
/**
|
|
54 |
* Date of file creation
|
|
55 |
*/
|
|
56 |
private long date = 0;
|
|
57 |
|
|
58 |
/**
|
|
59 |
* SDK Id as given by {@link SdkInformation#getSdkId()}
|
|
60 |
*/
|
|
61 |
private String sdkid;
|
|
62 |
|
|
63 |
private String apiName;
|
|
64 |
|
|
65 |
|
|
66 |
/**
|
|
67 |
* API Details (XML data file contents readed to memory)
|
|
68 |
*/
|
|
69 |
private APIDetails APIDetails = null;
|
|
70 |
|
|
71 |
|
|
72 |
/**
|
|
73 |
* Constructor.
|
|
74 |
* @param id Entry id that is unique per search method.
|
|
75 |
* @param name If Sheet entry name.
|
|
76 |
* @param size Folder path name.
|
|
77 |
* @param isSelected Is this server entry used for queries.
|
|
78 |
*/
|
|
79 |
public CacheEntry(String id, String name, String SDKID, boolean isSelected, long size, long date,String apiName){
|
|
80 |
super(id, isSelected);//There are no not selected entries in Metadata data source
|
|
81 |
sdkid = SDKID;
|
|
82 |
this.date = date;
|
|
83 |
validateArguments(id, name);
|
|
84 |
this.name = name;
|
|
85 |
this.size = size;
|
|
86 |
this.apiName =apiName;
|
|
87 |
}
|
|
88 |
|
|
89 |
|
|
90 |
/**
|
|
91 |
* Validates that all the datafiles are valid
|
|
92 |
* i.e. currently checking that they all contain values.
|
|
93 |
* @param id file name with absolutely path
|
|
94 |
* @param name entry (file) name.
|
|
95 |
* @param size File size on disk.
|
|
96 |
* @throws IllegalArgumentException
|
|
97 |
*/
|
|
98 |
private void validateArguments(String id, String name) throws IllegalArgumentException{
|
|
99 |
if( ( id == null || name == null )
|
|
100 |
||
|
|
101 |
( id.length() == 0 || name.length() == 0 )){
|
|
102 |
throw new IllegalArgumentException(new String(Messages.getString("CacheEntry.Cannot_Contain_Empty_Field_ErrMsg"))); //$NON-NLS-1$
|
|
103 |
}
|
|
104 |
}
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
/**
|
|
109 |
* @return the folder in file system
|
|
110 |
*/
|
|
111 |
public long getSize() {
|
|
112 |
return size;
|
|
113 |
}
|
|
114 |
|
|
115 |
/* (non-Javadoc)
|
|
116 |
* @see com.nokia.s60tools.apiquery.web.configuration.AbstractEntry#updateEntryTypeSpecificDataFields(com.nokia.s60tools.apiquery.web.configuration.AbstractEntry)
|
|
117 |
*/
|
|
118 |
public void updateEntryTypeSpecificDataFields(AbstractEntry entryWithUpdatedData) {
|
|
119 |
CacheEntry entry = (CacheEntry) entryWithUpdatedData;
|
|
120 |
this.size = entry.getSize();
|
|
121 |
this.name = entry.getName();
|
|
122 |
this.date = entry.getDate();
|
|
123 |
this.sdkid = entry.getSDKID();
|
|
124 |
this.isSelected = entry.isSelected;
|
|
125 |
}
|
|
126 |
|
|
127 |
|
|
128 |
/**
|
|
129 |
* Get ID for SDK where entry belongs to
|
|
130 |
* @return SDK Id as given by {@link SdkInformation#getSdkId()}
|
|
131 |
*/
|
|
132 |
public String getSDKID() {
|
|
133 |
return sdkid;
|
|
134 |
}
|
|
135 |
|
|
136 |
/**
|
|
137 |
* return the file name
|
|
138 |
* @return
|
|
139 |
*/
|
|
140 |
public String getName() {
|
|
141 |
return name;
|
|
142 |
}
|
|
143 |
|
|
144 |
/**
|
|
145 |
* return the file creation date
|
|
146 |
* @return date
|
|
147 |
*/
|
|
148 |
public long getDate() {
|
|
149 |
return date;
|
|
150 |
}
|
|
151 |
|
|
152 |
/**
|
|
153 |
* Set API details
|
|
154 |
* @param APIDetails
|
|
155 |
*/
|
|
156 |
public void setAPIDetails(APIDetails APIDetails) {
|
|
157 |
this.APIDetails = APIDetails;
|
|
158 |
}
|
|
159 |
|
|
160 |
/**
|
|
161 |
* get API details
|
|
162 |
* @return API Details
|
|
163 |
*/
|
|
164 |
public APIDetails getAPIDetails() {
|
|
165 |
//If details is null, it must not be loaded now, because of lot of time taken
|
|
166 |
//and UpdateSDKSelectionJob gets API Details when saving current situation to ram
|
|
167 |
//for user cancel situation data restore.
|
|
168 |
return APIDetails;
|
|
169 |
}
|
|
170 |
|
|
171 |
/**
|
|
172 |
* Load file contents for this entry.
|
|
173 |
*
|
|
174 |
* if load() fails for some reason, this entry will be set as not selected.
|
|
175 |
* @see CacheEntry#setSelected(false)
|
|
176 |
*
|
|
177 |
* @throws FileNotFoundException
|
|
178 |
* @throws IOException
|
|
179 |
*/
|
|
180 |
public void load() throws XMLNotValidException{
|
|
181 |
|
|
182 |
try {
|
|
183 |
StringBuffer buf = FileUtils.loadDataFromFile(getId());
|
|
184 |
|
|
185 |
APIDetails details = XMLUtils.extractAPIDetailsData(buf.toString(), new MetadataXMLToUIMappingRules());
|
|
186 |
|
|
187 |
MetadataHeadersFinder headerFinder = new MetadataHeadersFinder();
|
|
188 |
details.addOrUpdateField(MetadataXMLToUIMappingRules.HEADERS, headerFinder.getHeadersForEntry(this));
|
|
189 |
setAPIDetails(details);
|
|
190 |
} catch (FileNotFoundException e) {
|
|
191 |
setSelected(false, true);//Because load was failed, this cannot be selected as data source, if is, search will fail
|
|
192 |
throw new XMLNotValidException(e.getMessage(), getId());
|
|
193 |
} catch (IOException e) {
|
|
194 |
setSelected(false, true);//Because load was failed, this cannot be selected as data source, if is, search will fail
|
|
195 |
throw new XMLNotValidException(e.getMessage(), getId());
|
|
196 |
}catch (Exception e) {
|
|
197 |
setSelected(false, true);//Because load was failed, this cannot be selected as data source, if is, search will fail
|
|
198 |
e.printStackTrace();
|
|
199 |
throw new XMLNotValidException(e.getMessage(), getId());
|
|
200 |
}
|
|
201 |
|
|
202 |
}
|
|
203 |
|
|
204 |
/**
|
|
205 |
* Release API details from memory by setting API Details to <code>null</code>.
|
|
206 |
*/
|
|
207 |
public void unload() {
|
|
208 |
setAPIDetails(null);
|
|
209 |
}
|
|
210 |
|
|
211 |
public String getAPIName()
|
|
212 |
{
|
|
213 |
return apiName;
|
|
214 |
}
|
|
215 |
|
|
216 |
}
|