#57114: Read the classname from metamodel when a structure is part of another structure.
1.1 --- a/mdr/src/org/netbeans/mdr/util/IOUtils.java Tue Apr 19 19:32:33 2005 +0000
1.2 +++ b/mdr/src/org/netbeans/mdr/util/IOUtils.java Thu Apr 21 14:49:18 2005 +0000
1.3 @@ -20,6 +20,10 @@
1.4 import java.lang.reflect.Field;
1.5
1.6 import javax.jmi.reflect.*;
1.7 +import javax.jmi.model.*;
1.8 +
1.9 +import org.netbeans.mdr.NBMDRepositoryImpl;
1.10 +import org.netbeans.mdr.handlers.gen.TagSupport;
1.11
1.12 import org.netbeans.mdr.storagemodel.*;
1.13 import org.netbeans.mdr.persistence.MOFID;
1.14 @@ -27,7 +31,6 @@
1.15 import org.netbeans.mdr.persistence.StorageException;
1.16 import org.netbeans.mdr.util.DebugException;
1.17 import org.netbeans.mdr.handlers.*;
1.18 -import org.openide.util.io.NbObjectInputStream;
1.19
1.20 /**
1.21 *
1.22 @@ -503,11 +506,16 @@
1.23 for (int i = 0; i < size; i++) {
1.24 Object field = storage.values(storable.getMofId()).resolve(readInt(inputStream));
1.25 fields.add(field);
1.26 - values.put(field, read(inputStream));
1.27 + values.put(field, read(inputStream, storable));
1.28 }
1.29
1.30 Class clazz;
1.31
1.32 + if (className == null) {
1.33 + StorableObject struct = resolveByFQN(storable, qualifiedName);
1.34 + className = TagSupport.getDataTypeName(struct);
1.35 + }
1.36 +
1.37 try {
1.38 clazz = BaseObjectHandler.resolveInterface(className);
1.39 } catch (ClassNotFoundException e) {
1.40 @@ -528,27 +536,8 @@
1.41 } catch (ClassNotFoundException e) {
1.42 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
1.43 }
1.44 -// } case T_OBJECT: {
1.45 -// if (storable == null) Logger.getDefault().notify(Logger.INFORMATIONAL, new DebugException());
1.46 -// try {
1.47 -// return storable.getMdrStorage().getRepository().getHandler(storable.getMdrStorage().getObject(readMOFID(inputStream, storable.getMdrStorage(), storable.getMofId())));
1.48 -// } catch (StorageException e) {
1.49 -// throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
1.50 -// }
1.51 } case T_MOFID: {
1.52 return readMOFID (inputStream, storable.getMdrStorage (), storable.getMofId());
1.53 -/* } case T_SERIALIZABLE: {
1.54 - // [PENDING] the following code should not be needed once the serialization will be rewritten
1.55 - try {
1.56 - return new ObjectInputStream(inputStream).readObject();
1.57 - } catch (ClassNotFoundException e) {
1.58 - try {
1.59 - return new NbObjectInputStream(inputStream).readObject();
1.60 - } catch (ClassNotFoundException ex) {
1.61 - throw Logger.getDefault().annotate(new DebugException(), e);
1.62 - }
1.63 - }
1.64 - */
1.65 } case T_STORABLE: {
1.66 Class cls = (Class) read(inputStream, storable);
1.67 try {
1.68 @@ -572,6 +561,44 @@
1.69 }
1.70 }
1.71
1.72 + private static StorableObject resolveByFQN(StorableBaseObject obj, List qualifiedName) {
1.73 + try {
1.74 + RefPackage pkg = (RefPackage) obj.getMdrStorage().getRepository().getHandler(obj.getMetaObject().getOutermostPackage());
1.75 + RefObject result = resolveByFQN(pkg , qualifiedName);
1.76 + return (StorableObject) (result == null ? null : ((BaseObjectHandler) result)._getDelegate());
1.77 + } catch (Exception e) {
1.78 + Logger.getDefault().notify(e);
1.79 + return null;
1.80 + }
1.81 + }
1.82 +
1.83 + private static RefObject resolveByFQN(RefPackage pkg, List qualifiedName) {
1.84 + qualifiedName = new ArrayList(qualifiedName);
1.85 + String name = (String) qualifiedName.remove(0);
1.86 + MofPackage outer = findPackage(pkg, name);
1.87 + if (outer == null) {
1.88 + for (Iterator it = pkg.refAllPackages().iterator(); it.hasNext() && outer == null;) {
1.89 + outer = findPackage((RefPackage) it.next(), name);
1.90 + }
1.91 + }
1.92 + if (outer == null) return null;
1.93 + try {
1.94 + return outer.resolveQualifiedName(qualifiedName);
1.95 + } catch (NameNotResolvedException e) {
1.96 + return null;
1.97 + }
1.98 + }
1.99 +
1.100 + private static MofPackage findPackage(RefPackage pkg, String name) {
1.101 + for (Iterator it = ((ModelPackage) pkg).getMofPackage().refAllOfType().iterator(); it.hasNext();) {
1.102 + MofPackage result = (MofPackage) it.next();
1.103 + if (name.equals(result.getName()) && result.refImmediateComposite() == null) {
1.104 + return result;
1.105 + }
1.106 + }
1.107 + return null;
1.108 + }
1.109 +
1.110 /** Implementors must also declare: <br>
1.111 * <pre>public static Object read(InputStream inputStream, StorableBaseObject storable) throws IOException</pre>
1.112 */