Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java')
-rw-r--r--bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java73
1 files changed, 69 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java
index 8d9c5366d..a87275e3d 100644
--- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java
+++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java
@@ -13,15 +13,18 @@
*******************************************************************************/
package org.eclipse.equinox.metatype.impl;
+import java.io.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.util.Hashtable;
+import java.util.*;
import javax.xml.parsers.*;
import org.eclipse.equinox.metatype.EquinoxMetaTypeInformation;
import org.eclipse.equinox.metatype.EquinoxMetaTypeService;
+import org.eclipse.equinox.metatype.impl.Persistence.Reader;
+import org.eclipse.equinox.metatype.impl.Persistence.Writer;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.*;
-import org.osgi.service.log.LogService;
+import org.osgi.service.metatype.MetaTypeInformation;
import org.osgi.util.tracker.ServiceTracker;
import org.xml.sax.SAXException;
@@ -29,7 +32,7 @@ import org.xml.sax.SAXException;
* Implementation of MetaTypeService
*/
public class MetaTypeServiceImpl implements EquinoxMetaTypeService, SynchronousBundleListener {
-
+ private static String CACHE_FILE = "metaTypeCache"; //$NON-NLS-1$
SAXParserFactory _parserFactory;
private Hashtable<Long, EquinoxMetaTypeInformation> _mtps = new Hashtable<Long, EquinoxMetaTypeInformation>(7);
@@ -71,7 +74,7 @@ public class MetaTypeServiceImpl implements EquinoxMetaTypeService, SynchronousB
try {
impl = new MetaTypeInformationImpl(b, newParser(), loggerTemp);
} catch (Exception e) {
- loggerTemp.log(LogService.LOG_ERROR, NLS.bind(MetaTypeMsg.METADATA_PARSE_ERROR, b.getBundleId(), b.getSymbolicName()), e);
+ loggerTemp.log(LogTracker.LOG_ERROR, NLS.bind(MetaTypeMsg.METADATA_PARSE_ERROR, b.getBundleId(), b.getSymbolicName()), e);
}
if (impl == null || !impl._isThereMeta)
return new MetaTypeProviderTracker(b, loggerTemp, tracker);
@@ -135,4 +138,66 @@ public class MetaTypeServiceImpl implements EquinoxMetaTypeService, SynchronousB
break;
}
}
+
+ void load(BundleContext context, LogTracker log, ServiceTracker<Object, Object> tracker) throws IOException {
+ File cache = context.getDataFile(CACHE_FILE);
+ // using system context to see all bundles by the ID
+ BundleContext systemContext = context.getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext();
+ if (cache.isFile()) {
+ try (Reader reader = new Reader(new DataInputStream(new BufferedInputStream(new FileInputStream(cache))))) {
+
+ int numService = reader.readInt();
+ for (int i = 0; i < numService; i++) {
+ long id = reader.readLong();
+ Bundle b = systemContext.getBundle(id);
+ if (b != null) {
+ _mtps.put(b.getBundleId(), new MetaTypeProviderTracker(b, log, tracker));
+ }
+ }
+
+ reader.readIndexedStrings();
+
+ int numXML = reader.readInt();
+ for (int i = 0; i < numXML; i++) {
+ MetaTypeInformationImpl info = MetaTypeInformationImpl.load(systemContext, log, reader);
+ if (info != null) {
+ _mtps.put(info.getBundle().getBundleId(), info);
+ }
+ }
+ }
+ }
+ }
+
+ void save(BundleContext context) throws IOException {
+ File cache = context.getDataFile(CACHE_FILE);
+ try (Writer writer = new Writer(new DataOutputStream(new BufferedOutputStream(new FileOutputStream(cache))))) {
+ List<MetaTypeInformation> serviceInfos = new ArrayList<>();
+ List<MetaTypeInformationImpl> xmlInfos = new ArrayList<>();
+ synchronized (_mtps) {
+ for (MetaTypeInformation info : _mtps.values()) {
+ if (info instanceof MetaTypeInformationImpl) {
+ xmlInfos.add((MetaTypeInformationImpl) info);
+ } else {
+ serviceInfos.add(info);
+ }
+ }
+ }
+
+ writer.writeInt(serviceInfos.size());
+ for (MetaTypeInformation info : serviceInfos) {
+ writer.writeLong(info.getBundle().getBundleId());
+ }
+
+ Set<String> strings = new HashSet<>();
+ for (MetaTypeInformationImpl info : xmlInfos) {
+ info.getStrings(strings);
+ }
+ writer.writeIndexedStrings(strings);
+
+ writer.writeInt(xmlInfos.size());
+ for (MetaTypeInformationImpl info : xmlInfos) {
+ info.write(writer);
+ }
+ }
+ }
}

Back to the top