use of org.openide.util.io.NbMarshalledObject in project netbeans-rcp-lite by outersky.
the class Repository method readExternal.
/**
* Reads object from stream.
* Reads all filesystems. Persistent and system filesystems are untouched; all others are removed and possibly reread.
* @param ois object input stream
* @exception IOException if an error occures
* @exception ClassNotFoundException if read class is not found
* @deprecated Unused.
*/
@Deprecated
public final synchronized void readExternal(ObjectInput ois) throws IOException, ClassNotFoundException {
ArrayList<FileSystem> temp = new ArrayList<FileSystem>(10);
for (; ; ) {
Object obj = ois.readObject();
if (obj == null) {
// all system has been read in
break;
}
FileSystem fs;
if (obj instanceof FileSystem) {
fs = (FileSystem) obj;
} else {
try {
NbMarshalledObject mar = (NbMarshalledObject) obj;
fs = (FileSystem) mar.get();
} catch (IOException ex) {
ExternalUtil.exception(ex);
fs = null;
} catch (ClassNotFoundException ex) {
ExternalUtil.exception(ex);
fs = null;
}
}
if (fs != null) {
// add the new filesystem
temp.add(fs);
}
}
Enumeration<? extends FileSystem> ee = getFileSystems();
FileSystem fs;
while (ee.hasMoreElements()) {
fs = ee.nextElement();
if (!fs.isDefault()) {
removeFileSystem(fs);
}
}
// in init assigned is checked and we force 'system' to be added again
system.assigned = false;
init();
// all is successfuly read
for (FileSystem fileSystem : temp) {
addFileSystem(fileSystem);
}
}
use of org.openide.util.io.NbMarshalledObject in project netbeans-rcp-lite by outersky.
the class NbSheet method readExternal.
/**
* Deserialize this property sheet.
*/
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
try {
super.readExternal(in);
} catch (SafeException se) {
// ignore--we really do not care about the explorer manager that much
// System.err.println("ignoring a SafeException: " + se.getLocalizedMessage ());
}
Object obj = in.readObject();
if (obj instanceof NbMarshalledObject || obj instanceof ExplorerManager) {
// old version read the Boolean
global = ((Boolean) in.readObject()).booleanValue();
} else {
Node[] ns;
if (obj == null) {
// handles can also be null for global
// property sheet
ns = TopComponent.getRegistry().getActivatedNodes();
} else {
// new version, first read the nodes and then the global boolean
Node.Handle[] arr = (Node.Handle[]) obj;
try {
ns = NodeOp.fromHandles(arr);
} catch (IOException ex) {
Exceptions.attachLocalizedMessage(ex, NbBundle.getBundle(NbSheet.class).getString("EXC_CannotLoadNodes"));
Logger.getLogger(NbSheet.class.getName()).log(Level.WARNING, null, ex);
ns = new Node[0];
}
}
global = in.readBoolean();
// NOI18N
setNodes(ns, true, "readExternal");
}
/*
if (obj instanceof Boolean) {
global = (Boolean)in.readObject ()
global = ((Boolean)in.readObject()).booleanValue();
/*
// start global listening if needed, but wait until
// deserialization is done (ExplorerManager is uses
// post-deserialization validating too, so we are forced
// to use it)
((ObjectInputStream)in).registerValidation(
new ObjectInputValidation () {
public void validateObject () {
updateGlobalListening(false);
}
}, 0
);
*/
// JST: I guess we are not and moreover the type casting is really ugly
// updateGlobalListening (global);
}
use of org.openide.util.io.NbMarshalledObject in project netbeans-rcp-lite by outersky.
the class NbLoaderPool method readPool.
/**
* Reads loader from the input stream.
* @param ois object input stream to read from
*/
private static synchronized void readPool(ObjectInputStream ois, NbLoaderPool pool) throws IOException, ClassNotFoundException {
/*installBefores = (Map)*/
ois.readObject();
/*installAfters = (Map)*/
ois.readObject();
HashSet<Class> classes = new HashSet<Class>();
LinkedList<DataLoader> l = new LinkedList<DataLoader>();
Iterator<? extends ModuleInfo> mit = Lookup.getDefault().lookupAll(ModuleInfo.class).iterator();
Map<String, ModuleInfo> modules = new HashMap<String, ModuleInfo>();
while (mit.hasNext()) {
ModuleInfo m = mit.next();
modules.put(m.getCodeNameBase(), m);
}
for (; ; ) {
Object o1 = ois.readObject();
if (o1 == null) {
if (err.isLoggable(Level.FINE))
err.fine("reading null");
break;
}
NbMarshalledObject obj;
if (o1 instanceof String) {
String name = (String) o1;
if (name.length() > 0 && name.charAt(0) == '=') {
// NOI18N
// #27190: unmodified loader, just here for the ordering.
String cname = name.substring(1);
DataLoader dl = names2Loaders.get(cname);
if (dl != null) {
if (err.isLoggable(Level.FINE))
err.fine("reading unmodified " + cname);
l.add(dl);
classes.add(dl.getClass());
} else {
// No such known loaded - presumably disabled module.
if (err.isLoggable(Level.FINE))
err.fine("skipping unmodified nonexistent " + cname);
}
continue;
}
// Module information.
int rel = ois.readInt();
String spec = (String) ois.readObject();
obj = (NbMarshalledObject) ois.readObject();
ModuleInfo m = modules.get(name);
if (m == null) {
if (err.isLoggable(Level.FINE))
err.fine("No known module " + name + ", skipping loader");
continue;
}
if (!m.isEnabled()) {
if (err.isLoggable(Level.FINE))
err.fine("Module " + name + " is disabled, skipping loader");
continue;
}
if (m.getCodeNameRelease() < rel) {
if (err.isLoggable(Level.FINE))
err.fine("Module " + name + " is too old (major vers.), skipping loader");
continue;
}
if (spec != null) {
SpecificationVersion v = m.getSpecificationVersion();
if (v == null || v.compareTo(new SpecificationVersion(spec)) < 0) {
if (err.isLoggable(Level.FINE))
err.fine("Module " + name + " is too old (spec. vers.), skipping loader");
continue;
}
}
if (err.isLoggable(Level.FINE))
err.fine("Module " + name + " is OK, will try to restore loader");
} else {
// Loader with no known module, or backward compatibility.
obj = (NbMarshalledObject) o1;
}
Exception t = null;
try {
DataLoader loader = (DataLoader) obj.get();
if (loader == null) {
// issue 38658)
continue;
}
Class<?> clazz = loader.getClass();
if (err.isLoggable(Level.FINE))
err.fine("reading modified " + clazz.getName());
l.add(loader);
classes.add(clazz);
} catch (IOException ex) {
t = ex;
} catch (ClassNotFoundException ex) {
t = ex;
}
}
// Read system loaders. But not into any particular order.
for (; ; ) {
NbMarshalledObject obj = (NbMarshalledObject) ois.readObject();
if (obj == null) {
if (err.isLoggable(Level.FINE))
err.fine("reading null");
break;
}
Exception t = null;
try {
// Just reads its shared state, nothing more.
DataLoader loader = (DataLoader) obj.get();
if (err.isLoggable(Level.FINE))
err.fine("reading " + loader.getClass().getName());
} catch (IOException ex) {
t = ex;
} catch (ClassNotFoundException ex) {
t = ex;
}
}
if (err.isLoggable(Level.FINE))
err.fine("done reading");
// Explanation: modules are permitted to restoreDefault () before
// the loader pool is de-externalized. This means that all loader manifest
// sections will add a default-instance entry to the pool at startup
// time. Later, when the pool is restored, this may reorder existing ones,
// as well as change properties. But if any loader is missing (typically
// due to failed deserialization), it will nonetheless be added to the end
// now (and the pool resorted just in case).
Iterator it = loaders.iterator();
while (it.hasNext()) {
DataLoader loader = (DataLoader) it.next();
if (!classes.contains(loader.getClass())) {
l.add(loader);
}
}
// NOI18N
if (l.size() > new HashSet<DataLoader>(l).size())
throw new IllegalStateException("Duplicates in " + l);
loaders = l;
// Always "resort": if the existing order was in fact compatible with the
// current install-befores/afters, then this is no op (besides firing an
// update event). Cf. #29671.
resort(pool);
}
use of org.openide.util.io.NbMarshalledObject in project netbeans-rcp-lite by outersky.
the class NbLoaderPool method writePool.
/**
* Stores all the objects into stream.
* @param oos object output stream to write to
*/
private static synchronized void writePool(ObjectOutputStream oos, NbLoaderPool pool) throws IOException {
if (err.isLoggable(Level.FINE))
err.fine("writePool");
// No longer bother storing these (#29671):
oos.writeObject(new HashMap());
oos.writeObject(new HashMap());
Iterator it = loaders.iterator();
while (it.hasNext()) {
DataLoader l = (DataLoader) it.next();
if (!isModified(l)) {
// #27190 - no real need to write this in detail.
String c = l.getClass().getName();
if (err.isLoggable(Level.FINE))
err.fine("writing unmodified " + c);
// '=' not a permissible part of a cnb, so this distinguishes it
// NOI18N
oos.writeObject("=" + c);
continue;
}
NbMarshalledObject obj;
try {
obj = new NbMarshalledObject(l);
} catch (IOException ex) {
err.log(Level.WARNING, null, ex);
obj = null;
}
if (obj != null) {
if (err.isLoggable(Level.FINE))
err.fine("writing modified " + l.getClass().getName());
// Find its module, if any.
boolean found = false;
ModuleInfo m = Modules.getDefault().ownerOf(l.getClass());
if (m != null && m.isEnabled()) {
if (err.isLoggable(Level.FINE))
err.fine("belongs to module: " + m.getCodeNameBase());
oos.writeObject(m.getCodeNameBase());
int r = m.getCodeNameRelease();
// might be -1, note
oos.writeInt(r);
SpecificationVersion v = m.getSpecificationVersion();
if (v != null) {
oos.writeObject(v.toString());
} else {
oos.writeObject(null);
}
found = true;
}
if (!found) {
if (err.isLoggable(Level.FINE))
err.fine("does not belong to any module");
// just write the NbMarshalledObject<DataLoader> itself;
// we need to support that for compatibility of old loader
// pools anyway
}
oos.writeObject(obj);
}
}
if (err.isLoggable(Level.FINE))
err.fine("writing null");
oos.writeObject(null);
// Write out system loaders now:
Enumeration e = pool.allLoaders();
while (e.hasMoreElements()) {
DataLoader l = (DataLoader) e.nextElement();
if (loaders.contains(l))
continue;
if (!isModified(l)) {
// #27190 again. No need to write anything
String c = l.getClass().getName();
if (err.isLoggable(Level.FINE))
err.fine("skipping unmodified " + c);
continue;
}
NbMarshalledObject obj;
try {
obj = new NbMarshalledObject(l);
} catch (IOException ex) {
err.log(Level.WARNING, null, ex);
obj = null;
}
if (obj != null) {
if (err.isLoggable(Level.FINE))
err.fine("writing " + l.getClass().getName());
// No associated module, no need to write such info.
oos.writeObject(obj);
}
}
if (err.isLoggable(Level.FINE))
err.fine("writing null");
oos.writeObject(null);
if (err.isLoggable(Level.FINE))
err.fine("done writing");
}
use of org.openide.util.io.NbMarshalledObject in project netbeans-rcp-lite by outersky.
the class Services method writeObject.
/**
* Write the object down.
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
Enumeration en = services();
while (en.hasMoreElements()) {
ServiceType s = (ServiceType) en.nextElement();
NbMarshalledObject obj;
try {
obj = new NbMarshalledObject(s);
} catch (IOException ex) {
Logger.getLogger(Services.class.getName()).log(Level.WARNING, null, ex);
// skip the object if it cannot be serialized
obj = null;
}
if (obj != null) {
oos.writeObject(obj);
}
}
oos.writeObject(null);
}
Aggregations