Beispiel #1
0
  @SuppressWarnings("unchecked")
  public final <T> T instance(String item, Object index) {
    ExtendedObject object;
    ComplexDocument document;
    ComplexModelItem cmodelitem = cmodel.getItems().get(item);

    if (cmodelitem.model != null) {
      object = new ExtendedObject(cmodelitem.model);
      if (cmodelitem.index != null) {
        if (index == null) throw new RuntimeException("indexed item can't have null key");
        object.set(cmodelitem.index, index);
      }
      add(object);
      return (T) object;
    }

    document = new ComplexDocument(cmodelitem.cmodel);
    if (cmodelitem.index != null) {
      document.set(cmodelitem.index, index);
    } else
      for (DocumentModelKey key : cmodelitem.cmodel.getHeader().getKeys()) {
        document.set(key.getModelItemName(), index);
        break;
      }
    add(document);
    return (T) document;
  }
Beispiel #2
0
 private final Object getKey(
     ComplexModel cmodel, DocumentModel model, ExtendedObject object, String alias) {
   ComplexModelItem citem = cmodel.getItems().get(alias);
   if (citem.index != null) return object.get(citem.index);
   for (DocumentModelKey modelkey : model.getKeys())
     return object.get(modelkey.getModelItemName());
   return null;
 }
Beispiel #3
0
  /**
   * Adds an item to the document
   *
   * @param object extended object
   */
  public final void add(ExtendedObject object) {
    String alias;
    Object key;
    DocumentModel model;
    ComplexModelItem citem;
    ComplexDocumentItems cdocitems;

    if (object == null) return;
    model = object.getModel();
    alias = cmodel.getModelItemName(model.getName());
    if (alias == null) throw new RuntimeException("Invalid object model.");
    citem = cmodel.getItems().get(alias);
    key = (citem.index == null) ? getKey(cmodel, model, object, alias) : object.get(citem.index);
    cdocitems = items.get(alias);
    if (key == null) key = cdocitems.objects.size();
    items.get(alias).objects.put(key, object);
  }
Beispiel #4
0
 public final void remove(ExtendedObject object) {
   String alias;
   DocumentModel model;
   if (object == null) return;
   model = object.getModel();
   alias = cmodel.getModelItemName(model.getName());
   if (alias == null) throw new RuntimeException("Invalid object model.");
   items.get(alias).objects.remove(getKey(cmodel, model, object, alias));
 }
Beispiel #5
0
 /** @param ns */
 public final void setNS(Object ns) {
   header.setNS(ns);
   ;
 }
Beispiel #6
0
 /**
  * @param field
  * @param value
  */
 public final void set(String field, Object value) {
   header.set(field, value);
 }
Beispiel #7
0
 /** @return */
 public final String getstKey() {
   for (DocumentModelKey key : cmodel.getHeader().getKeys())
     return header.getst(key.getModelItemName());
   return null;
 }
Beispiel #8
0
 /** @return */
 public final Object getNS() {
   return header.getNS();
 }
Beispiel #9
0
 /** @return */
 public final long getlKey() {
   for (DocumentModelKey key : cmodel.getHeader().getKeys())
     return header.getl(key.getModelItemName());
   return 0;
 }
Beispiel #10
0
 /** @return */
 @SuppressWarnings("unchecked")
 public final <T> T getKey() {
   for (DocumentModelKey key : cmodel.getHeader().getKeys())
     return (T) header.get(key.getModelItemName());
   return null;
 }