Ejemplo n.º 1
0
 public Object newRootInstance(Class<?> clazz) throws Exception {
   Object bean = newInstance(clazz);
   ModeExtender w = (ModeExtender) Reflection.call(bean, "getWrapper");
   w.getMode().setRoot(root);
   w.getMode().setExtender(bean);
   return bean;
 }
Ejemplo n.º 2
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public Object newInstance(final Class<?> clazz) throws Exception {
    Mode<?> mode = null;

    Object obj = instantiateClass(clazz);
    HashMap<String, Object> map = scanClass(obj);

    mode = new Mode();
    mode.setAnnotatedObject(clazz.getCanonicalName());
    mode.setElResolver(this.elResolver);
    mode.setStControl(this.structureControl);
    mode.setRootClass((Class<?>) map.get(ROOTOBJECTRESULT));

    FunctionResult fr = new FunctionResult();
    fr.setResultExpression((String) map.get(FUNCTIONRESULT));
    this.structureControl.setAnnotation(
        clazz.getCanonicalName(),
        DCMetaInfoLevel.Class,
        clazz.getCanonicalName(),
        DCMetaInfo.FunctionResult,
        fr);

    // CreateTrigger
    CreateTrigger createTrigger = (CreateTrigger) map.get(CREATETRIGGER);
    RemoteMethod createMethod = new RemoteMethod();
    createMethod.setMethod(createTrigger.objectAction());
    createMethod.setProxyObject(map.get(createTrigger.object()));
    for (int j = 0; j < createTrigger.parameters().value().length; j++) {

      createMethod.addParamClass(createTrigger.parameters().value()[j].type());
      createMethod.addExpression(createTrigger.parameters().value()[j].expression());
      createMethod.addValue(createTrigger.parameters().value()[j].value());
    }
    this.structureControl.setAnnotation(
        clazz.getCanonicalName(),
        DCMetaInfoLevel.Class,
        clazz.getCanonicalName(),
        DCMetaInfo.CreateTrigger,
        createMethod);

    // InsertTrigger
    InsertTrigger insertTrigger = (InsertTrigger) map.get(INSERTTRIGGER);
    RemoteMethod insertMethod = new RemoteMethod();
    insertMethod.setMethod(insertTrigger.objectAction());
    insertMethod.setProxyObject(map.get(insertTrigger.object()));
    for (int j = 0; j < insertTrigger.parameters().value().length; j++) {

      insertMethod.addParamClass(insertTrigger.parameters().value()[j].type());
      insertMethod.addExpression(insertTrigger.parameters().value()[j].expression());
      insertMethod.addValue(insertTrigger.parameters().value()[j].value());
    }
    this.structureControl.setAnnotation(
        clazz.getCanonicalName(),
        DCMetaInfoLevel.Class,
        clazz.getCanonicalName(),
        DCMetaInfo.InsertTrigger,
        insertMethod);

    // UpdateTrigger
    UpdateTrigger updateTrigger = (UpdateTrigger) map.get(UPDATETRIGGER);
    RemoteMethod updateMethod = new RemoteMethod();
    updateMethod.setMethod(updateTrigger.objectAction());
    updateMethod.setProxyObject(map.get(updateTrigger.object()));
    for (int j = 0; j < updateTrigger.parameters().value().length; j++) {

      updateMethod.addParamClass(updateTrigger.parameters().value()[j].type());
      updateMethod.addExpression(updateTrigger.parameters().value()[j].expression());
      updateMethod.addValue(updateTrigger.parameters().value()[j].value());
    }
    this.structureControl.setAnnotation(
        clazz.getCanonicalName(),
        DCMetaInfoLevel.Class,
        clazz.getCanonicalName(),
        DCMetaInfo.UpdateTrigger,
        updateMethod);

    // RemoveTrigger
    RemoveTrigger removeTrigger = (RemoveTrigger) map.get(REMOVETRIGGER);
    RemoteMethod removeMethod = new RemoteMethod();
    removeMethod.setMethod(removeTrigger.objectAction());
    removeMethod.setProxyObject(map.get(removeTrigger.object()));
    for (int j = 0; j < removeTrigger.parameters().value().length; j++) {

      removeMethod.addParamClass(removeTrigger.parameters().value()[j].type());
      removeMethod.addExpression(removeTrigger.parameters().value()[j].expression());
      removeMethod.addValue(removeTrigger.parameters().value()[j].value());
    }
    this.structureControl.setAnnotation(
        clazz.getCanonicalName(),
        DCMetaInfoLevel.Class,
        clazz.getCanonicalName(),
        DCMetaInfo.RemoveTrigger,
        removeMethod);

    // SearchTrigger
    SearchTrigger searchTrigger = (SearchTrigger) map.get(SEARCHTRIGGER);
    RemoteMethod searchMethod = new RemoteMethod();
    searchMethod.setMethod(searchTrigger.objectAction());
    searchMethod.setProxyObject(map.get(searchTrigger.object()));
    for (int j = 0; j < searchTrigger.parameters().value().length; j++) {

      searchMethod.addParamClass(searchTrigger.parameters().value()[j].type());
      searchMethod.addExpression(searchTrigger.parameters().value()[j].expression());
      searchMethod.addValue(searchTrigger.parameters().value()[j].value());
    }
    this.structureControl.setAnnotation(
        clazz.getCanonicalName(),
        DCMetaInfoLevel.Class,
        clazz.getCanonicalName(),
        DCMetaInfo.SearchTrigger,
        searchMethod);

    POSTCreateTrigger postCreateTrigger = (POSTCreateTrigger) map.get(POSTCREATETRIGGER);
    if (postCreateTrigger != null) {
      Trigger trigger = new Trigger(postCreateTrigger.clazz(), postCreateTrigger.method());
      this.structureControl.setAnnotation(
          clazz.getCanonicalName(),
          DCMetaInfoLevel.Class,
          clazz.getCanonicalName(),
          DCMetaInfo.POSTCreateTrigger,
          trigger);
    }

    POSTQueryTrigger postQueryTrigger = (POSTQueryTrigger) map.get(POSTQUERYTRIGGER);
    if (postQueryTrigger != null) {
      Trigger trigger = new Trigger(postQueryTrigger.clazz(), postQueryTrigger.method());
      this.structureControl.setAnnotation(
          clazz.getCanonicalName(),
          DCMetaInfoLevel.Class,
          clazz.getCanonicalName(),
          DCMetaInfo.POSTQueryTrigger,
          trigger);
    }

    PREQueryTrigger preQueryTrigger = (PREQueryTrigger) map.get(PREQUERYTRIGGER);
    if (preQueryTrigger != null) {
      Trigger trigger = new Trigger(preQueryTrigger.clazz(), preQueryTrigger.method());
      this.structureControl.setAnnotation(
          clazz.getCanonicalName(),
          DCMetaInfoLevel.Class,
          clazz.getCanonicalName(),
          DCMetaInfo.PREQueryTrigger,
          trigger);
    }

    PREInsertTrigger preInsertTrigger = (PREInsertTrigger) map.get(PREINSERTTRIGGER);
    if (preInsertTrigger != null) {
      Trigger trigger = new Trigger(preInsertTrigger.clazz(), preInsertTrigger.method());
      this.structureControl.setAnnotation(
          clazz.getCanonicalName(),
          DCMetaInfoLevel.Class,
          clazz.getCanonicalName(),
          DCMetaInfo.PREInsertTrigger,
          trigger);
    }

    DefaultOrderBys defaultOrderBys = clazz.getAnnotation(DefaultOrderBys.class);

    ArrayList<OrderCriteria> ordLst = new ArrayList<OrderCriteria>();
    if ((defaultOrderBys != null)
        && (defaultOrderBys.orders() != null)
        && (defaultOrderBys.orders().length != 0)) {
      for (int i = 0; i < defaultOrderBys.orders().length; i++) {
        OrderCriteria ord = new OrderCriteria();
        ord.setName(defaultOrderBys.orders()[i].field());
        ord.setOrder(defaultOrderBys.orders()[i].type().name());
        ordLst.add(ord);
      }
    } else {
      OrderCriteria ord = new OrderCriteria();
      ord.setName((String) map.get(ID));
      ord.setOrder(OrderType.ASC.name());
      ordLst.add(ord);
    }
    mode.setDefaultOrderby(ordLst);

    DefaultSearchCriterias defaultSearchCriteria =
        clazz.getAnnotation(DefaultSearchCriterias.class);

    if (defaultSearchCriteria != null) {
      ArrayList<org.elsoft.platform.datacontrol.metainfo.DefaultSearchCriteria> schLst =
          new ArrayList<org.elsoft.platform.datacontrol.metainfo.DefaultSearchCriteria>();
      HashMap<String, Object> dependList = new HashMap<String, Object>();
      for (int i = 0; i < defaultSearchCriteria.criterias().length; i++) {
        org.elsoft.platform.datacontrol.metainfo.DefaultSearchCriteria sch =
            new org.elsoft.platform.datacontrol.metainfo.DefaultSearchCriteria();
        sch.setName(defaultSearchCriteria.criterias()[i].field());
        sch.setClassName(defaultSearchCriteria.criterias()[i].type().getName());
        sch.setComparator(defaultSearchCriteria.criterias()[i].comparator().name());
        if ((defaultSearchCriteria.criterias()[i].expression() != null)
            && (!defaultSearchCriteria.criterias()[i].expression().equals(""))) {
          dependList.put(defaultSearchCriteria.criterias()[i].expression(), "");
        }
        sch.setExpression(defaultSearchCriteria.criterias()[i].expression());
        sch.setValue(defaultSearchCriteria.criterias()[i].value());
        schLst.add(sch);
      }
      mode.setDefaultFilter(schLst);
      mode.setDependency(dependList);
    }

    Dependencies dependencies = clazz.getAnnotation(Dependencies.class);
    if (dependencies != null) {
      mode.getDependency();
      HashMap<String, Object> dependList = mode.getDependency();
      if (dependList == null) {
        dependList = new HashMap<String, Object>();
        mode.setDependency(dependList);
      }
      for (int i = 0; i < dependencies.dependency().length; i++) {
        dependList.put(dependencies.dependency()[i].expression(), "");
      }
    }

    ArtificialProperties artificialProperties = clazz.getAnnotation(ArtificialProperties.class);

    if (artificialProperties != null) {
      for (int i = 0; i < artificialProperties.fields().length; i++) {
        org.elsoft.platform.datacontrol.metainfo.ArtificialProperty art =
            new org.elsoft.platform.datacontrol.metainfo.ArtificialProperty();
        art.setProperty(artificialProperties.fields()[i].field());
        art.setType(artificialProperties.fields()[i].type());
        art.setDefaultValue(artificialProperties.fields()[i].defaulValue());
        structureControl.setAnnotation(
            clazz.getCanonicalName(),
            DCMetaInfoLevel.Field,
            artificialProperties.fields()[i].field(),
            DCMetaInfo.ArtificialProperty,
            art);
      }
    }
    /*
     * org.elsoft.platform.datacontrol.metainfo.ArtificialProperty art = new
     * org.elsoft.platform.datacontrol.metainfo.ArtificialProperty();
     * art.setProperty("rowIndex"); art.setType(Integer.class);
     * art.setDefaultValue("");
     * structureControl.setAnnotation(clazz.getCanonicalName(),
     * DCMetaInfoLevel.Field, "rowIndex", DCMetaInfo.ArtificialProperty,
     * art);
     */

    this.structureControl.setAnnotation(
        clazz.getCanonicalName(), DCMetaInfoLevel.Field, (String) map.get(ID), DCMetaInfo.Id, null);

    this.structureControl.setAnnotation(
        clazz.getCanonicalName(),
        DCMetaInfoLevel.Field,
        (String) map.get(VERSION),
        DCMetaInfo.Version,
        null);

    DataControl InsDomainDC = new InsModeDataControl();
    mode.addMode(RootModeSwitch.INSERT_MODE, InsDomainDC, true);

    DataControl QryDomainDC = new QryModeDataControl();
    mode.addMode(RootModeSwitch.QUERY_MODE, QryDomainDC, false);

    mode.addTransition(
        RootModeSwitch.INSERT_MODE, RootModeSwitch.QUERY_MODE, new Ins2QryActivity());
    mode.addTransition(
        RootModeSwitch.QUERY_MODE, RootModeSwitch.INSERT_MODE, new Qry2InsActivity());

    return ModeExtender.newInstance(clazz, mode, this);
  }