1 19 package org.netbeans.mdr.storagemodel; 20 21 import java.io.*; 22 import java.util.*; 23 24 import javax.jmi.model.*; 25 import javax.jmi.reflect.*; 26 27 import org.netbeans.mdr.persistence.*; 28 import org.netbeans.mdr.util.*; 29 import org.netbeans.mdr.handlers.BaseObjectHandler; 30 31 36 public abstract class StorableFeatured extends StorableBaseObject implements Streamable { 37 43 public StorableFeatured(MdrStorage mdrStorage, org.netbeans.mdr.persistence.MOFID immediatePackage, org.netbeans.mdr.persistence.MOFID meta) throws StorageException { 44 this (mdrStorage, immediatePackage, meta, null); 45 } 46 47 public StorableFeatured (MdrStorage mdrStorage, org.netbeans.mdr.persistence.MOFID immediatePackage, org.netbeans.mdr.persistence.MOFID meta, String storageId) throws StorageException { 48 super (mdrStorage, immediatePackage, meta, storageId); 49 } 50 51 55 public StorableFeatured() { 56 super(); 57 } 58 59 protected void checkValue(StorableClass.AttributeDescriptor desc, Object value) { 60 if (desc.getMofId() == null) return; 61 if (desc.isMultivalued() || !desc.isChangeable()) { 62 throw new InvalidCallException(getMdrStorage().getRepository().getHandler(this), getMetaElement(desc.getMofId())); 63 } else { 64 if (value == null) { 65 if (desc.getMinSize() > 0) { 66 throw new NullPointerException (); 67 } 68 } else { 69 if (!desc.getType().isInstance(value)) { 70 throw new TypeMismatchException(desc.getType(), value, getMetaElement(desc.getMofId())); 71 } 72 } 73 } 74 } 75 76 private void checkInitValue(StorableClass.AttributeDescriptor desc, Object value) { 77 if (desc.getMofId() == null) return; 78 if (desc.isMultivalued()) { 79 throw new InvalidCallException(getMdrStorage().getRepository().getHandler(this), getMetaElement(desc.getMofId())); 80 } 81 if ((value != null) && !desc.getType().isInstance(value)) { 82 throw new TypeMismatchException(desc.getType(), value, getMetaElement(desc.getMofId())); 83 } 84 } 85 86 protected Object getInitialValue(StorableClass.AttributeDescriptor desc, Object value) throws StorageException { 87 Object result; 88 if (desc.isMultivalued()) { 89 if (desc.isChangeable()) { 90 if (desc.isUnique()) { 91 result = desc.isOrdered() ? (Collection) new AttrUList(this, desc, (List) value) : (Collection) new AttrSet(this, desc, (Collection) value); 92 } else { 93 result = desc.isOrdered() ? (Collection) new AttrList(this, desc, (List) value) : (Collection) new AttrCollection(this, desc, (Collection) value); 94 } 95 } else { 96 result = desc.isUnique() ? (List) new AttrImmutUList(this, desc, (Collection) value) : (List) new AttrImmutList(this, desc, (Collection) value); 97 } 98 } else { 99 try { 100 checkInitValue (desc, value); 101 } catch (RuntimeException e) { 102 Logger.getDefault().annotate(e, "multivalued: " + desc.isMultivalued() + ", name: " + desc.getName()); 103 Logger.getDefault().annotate(e, "maxSize: " + desc.getMaxSize() + ", minSize: " + desc.getMinSize()); 104 throw e; 105 } 106 result = value; 107 if (result instanceof RefObject) { 108 StorableObject storableObj = (StorableObject) ((BaseObjectHandler) result)._getDelegate(); 109 storableObj.setComposite(this, storableObj.getMofId(), desc.getMofId()); 110 } 111 } return result; 113 } 114 115 private RefObject getMetaElement(org.netbeans.mdr.persistence.MOFID mofId) { 116 try { 117 return (RefObject) getMdrStorage().getRepository().getHandler(getMdrStorage().getObject(mofId)); 118 } catch (StorageException e) { 119 Logger.getDefault().notify(Logger.INFORMATIONAL, e); 120 return null; 121 } 122 } 123 124 129 public abstract void setAttribute(String featureName, Object value) throws StorageException; 130 131 public abstract Object getAttribute(String featureName) throws StorageException; 132 133 public abstract StorableClass getClassProxy() throws StorageException; 134 } 135 | Popular Tags |