Package ch.semafor.gendas.model

Examples of ch.semafor.gendas.model.Element


    }
    logger.debug("creating Element  ({})", elType.toString());
    if (beanElementMap.containsKey(bean)) {
      return beanElementMap.get(bean); // NOPMD by wim on 9/20/10 2:54 PM
    }
    final Element element = new Element(elType);
    beanElementMap.put(bean, element);

    ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
      public void doWith(final Method method) throws IllegalArgumentException,
          IllegalAccessException {
        try {
          logger.debug("Method is {}", method.getName());
          if (((method.getName().startsWith("get") && method.getName().length() > 3) || (method
              .getName().startsWith("is") && method.getName().length() > 2))
              && !method.getName().equals("getClass")) {
            final Class retType = method.getReturnType();
            logger.debug("checking method return type {}",
                retType.getCanonicalName());
            if (isPrimitiveType(retType)) {
              final String propName = getPropertyName(method);
              logger.debug("property name {} type {}", propName,
                  retType.getCanonicalName());

              setProperty(propName, method.invoke(bean), retType, element);
            } else {
              Class genArgType = null;
              String type = retType.getCanonicalName();
              if (method.getReturnType().equals(java.util.List.class)) {
                genArgType = getGenericArgType(method.getGenericReturnType());
                type = genArgType.getCanonicalName();
              }
              logger.debug("composite {}", type);
              final String propName = getPropertyName(method);
              logger.debug("about to add reference {}", propName);
              final Object ref = method.invoke(bean);
              if (ref != null) {
                try {
                  if (ref instanceof java.util.List) {
                    logger.debug("LIST SIZE {}",
                        ((java.util.List) ref).size());
                    if (isPrimitiveType(genArgType)) {
                      logger.debug("LIST ELEMENTS TYPE {}",
                          genArgType.getCanonicalName());
                      setProperty(propName, (java.util.List) ref, genArgType,
                          element);
                    } else { // a list of composite types
                      logger.debug("adding list reference {}", propName);
                      final List<Element> elements = new ArrayList<Element>();
                      for (Object o : (java.util.List) ref) {
                        if (o != null) {
                          elements.add(create(o, genArgType));
                        }
                      }
                      logger.debug("end");
                        element.setListOfElements(propName, elements);
                    }
                  } else { // not a list
                    logger.debug("adding reference {}", propName);
                    element.addElement(propName, create(ref, genArgType));
                  }
                } catch (CoreException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace(); // NOPMD by wim on 9/20/10 2:57 PM
                  } catch (ElementCreationException e) {
View Full Code Here


  public Element save(final Object bean, final Long id, final String idName, final String idVersion) // NOPMD by wildi on 9/21/10 6:30 AM
      throws CoreException, ElementCreationException {
      logger.info(bean.getClass().getCanonicalName());
      final ElementCreator creator = new ElementCreator(elementTypeDao, elementDao, propertyTypeDao, idName, idVersion);
      logger.debug("about to create element tree for {}", bean.toString());
      final Element newElement = creator.create(bean,null);
      logger.debug("created element tree: {}", bean.toString());
    // eliminate empty nodes
    newElement.crunch();
    // do not change it, uses System.out.println
    if( logger.isDebugEnabled()){
      newElement.print(0, "new Element after crunch()");
    }
  Element element=null;
    if( id!=null && id>0L ){
    element = elementDao.get(id);
   }
   if( element == null ){
     element = new Element( newElement.getElementType() );
    }
    element.resetAssigned();
    element.assign( newElement, elementDao );
    if( logger.isDebugEnabled()){
      element.print(0, "Element after assign() before save()");
    }
    element = elementDao.save( element );
    creator.resetMaps();
   
    creator.setMatchingIdsAndVersions(bean, element, null);
    putCachedObject(element.getId(), null, bean);
    return element;
  }
View Full Code Here

  @Transactional(readOnly=true)
  public Object load(final Long id, final Long revision, final String idName, final String idVersion) throws CoreException, ElementCreationException { // NOPMD by wildi on 9/21/10 6:30 AM
    Object obj = getCachedObject(id, revision);
    if( obj != null )
      return obj;
    final Element e = elementDao.get(id); // NOPMD by wildi on 9/21/10 6:30 AM
    if( logger.isDebugEnabled()){
      e.print(0,"loaded element id " + id);
    }
    try {
    final Class clazz = Class.forName(e.getElementType().getName());
    final Constructor constr = clazz.getConstructor();
    final Object bean = constr.newInstance();
    final ElementCreator creator = new ElementCreator(elementTypeDao, elementDao, propertyTypeDao, idName, idVersion);
    obj = creator.load(e, revision, bean, clazz);
    putCachedObject(id, revision, obj);
View Full Code Here

    }

  }
  @Transactional(readOnly=true)
  public List<Modification> getHistories(final Long id){ // NOPMD by wildi on 9/21/10 6:35 AM
    final Element e = elementDao.get(id); // NOPMD by wildi on 9/21/10 6:35 AM
    return new ArrayList<Modification>(e.getHistories());
  }
View Full Code Here

  }
 
  @Transactional(readOnly=true)
  public Long getLastRevision(final Long id){ // NOPMD by wildi on 9/21/10 6:35 AM
    try{
      final Element e = elementDao.get(id); // NOPMD by wildi on 9/21/10 6:35 AM
      final Modification h = e.getLastHistory(); // NOPMD by wildi on 9/21/10 6:37 AM
      return h.getRevision(); // NOPMD by wildi on 9/21/10 6:27 AM
    }
    catch(CoreException e){
      //ToDO, PMD:AvoidPrintStackTrace
      e.printStackTrace();
    }
    return null;
  }
View Full Code Here

    final List objectsList = new ArrayList();

    try{
    logger.debug("searching elements {} with id {}", beanClass.getCanonicalName(), id);
      final ElementCreator creator = new ElementCreator(elementTypeDao, elementDao, propertyTypeDao, id, idVersion);
      final Element eref = creator.create(ref, null);
      for (Element e: elementDao.findByTypeAndReference(beanClass.getCanonicalName(), eref)) {
        // only elements of beanClass:
        objectsList.add(load(e.getId(),id,idVersion));
      }
    } catch (SecurityException e) {
View Full Code Here

    }
    logger.debug("creating Element  ({})", elType.toString());
    if (beanElementMap.containsKey(bean)) {
      return beanElementMap.get(bean); // NOPMD by wim on 9/20/10 2:54 PM
    }
    final Element element = new Element(elType);
    beanElementMap.put(bean, element);

    ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
      public void doWith(final Method method) throws IllegalArgumentException,
          IllegalAccessException {
        try {
          logger.debug("Method is {}", method.getName());
          if (((method.getName().startsWith("get") &&
              method.getName().length() > 3) ||
              (method.getName().startsWith("is") &&
                  method.getName().length() > 2)) &&
                  !method.getName().equals("getClass")) {
            final Class retType = method.getReturnType();
            logger.debug("checking method return type {}",
                retType.getCanonicalName());
            if (isPrimitiveType(retType)) {
              String propName = getPropertyName(method);
              logger.debug("property name {} type {}", propName,
                  retType.getCanonicalName());
              if( elType.isBeanId( propName )){
                if( method.getReturnType().equals( Long.class)){
                  element.setId( (Long)method.invoke(bean));
                }
                else if( method.getReturnType().equals( String.class)){
                  String id = (String)method.invoke(bean);
                  if( id!= null ){
                    element.setId( new Long(id));
                  }
                  else {
                    element.setId( null );
                  }
                }
              }
              else if( elType.isBeanVersionId(propName)){
                   Long v = 0L;
                    if (retType.equals(java.lang.Integer.class)
                        || retType.getCanonicalName().equals("int")) {
                      v = new Long((Integer)method.invoke(bean));
                      // above line as suggested by FB: DM_NUMBER_CTOR v = new Long((Integer)
                      // (value));
                    } else if (retType.equals(java.lang.Long.class)
                        || retType.getCanonicalName().equals("long")) {
                      v = (Long) method.invoke(bean);
                    }
                    element.setVersion(v); // property must be Int of Long!!
              }
              else {
                setProperty(propName, method.invoke(bean), retType, element);
              }
            } else {
              Class genArgType = null;
              String type = retType.getCanonicalName();
              if (method.getReturnType().equals(java.util.List.class)) {
                genArgType = getGenericArgType(method.getGenericReturnType());
                type = genArgType.getCanonicalName();
              }
              logger.debug("composite {}", type);
              String propName = getPropertyName(method);
              logger.debug("about to add reference {}", propName);
              final Object ref = method.invoke(bean);
              if (ref != null) {
                try {
                  if (ref instanceof java.util.List) {
                    logger.debug("LIST SIZE {}",
                        ((java.util.List) ref).size());
                    if (isPrimitiveType(genArgType)) {
                      logger.debug("LIST ELEMENTS TYPE {}",
                          genArgType.getCanonicalName());
                      setProperty(propName, (java.util.List) ref, genArgType,
                          element);
                    } else { // a list of composite types
                      logger.debug("adding list reference {}", propName);
                      final List<Element> elements = new ArrayList<Element>();
                      for (Object o : (java.util.List) ref) {
                        if (o != null) {
                          elements.add(create(o, genArgType));
                        }
                      }
                      logger.debug("end");
                        element.setListOfElements(propName, elements);
                    }
                  } else { // not a list
                    logger.debug("adding reference {}", propName);
                    element.addElement(propName, create(ref, genArgType));
                  }
                } catch (CoreException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace(); // NOPMD by wim on 9/20/10 2:57 PM
                  } catch (ElementCreationException e) {
View Full Code Here

      throws CoreException, ElementCreationException {
    logger.info(bean.getClass().getCanonicalName());
    final ElementCreator creator = new ElementCreator(elementTypeDao,
        elementDao, propertyTypeDao, cache);
    logger.debug("about to create element tree for {}", bean.toString());
    final Element newElement = creator.create(bean, null);
    logger.debug("created element tree: {}", bean.toString());
    // eliminate empty nodes
    newElement.crunch();
    // do not change it, uses System.out.println
    if (logger.isDebugEnabled()) {
      newElement.print(0, "new Element after crunch()");
    }
    Element element = null;
    Long id = newElement.getId();
    if (id != null && id > 0L) {
      element = elementDao.get(id);
    }
    if (element == null) {
      element = new Element(newElement.getElementType());
    }
    List<Element> knownElements = new ArrayList<Element>();
    knownElements.add(element);
    element.assign(newElement, knownElements, elementDao);
    if (logger.isDebugEnabled()) {
      element.print(0, "Element after assign() before save()");
    }
    element = elementDao.save(element);
    // invalidate cached element
    //if( cache != null ){
    cache.remove(element.getId(), Modification.MaxRevision);
    //}

    creator.resetMaps();

    creator.setMatchingIdsAndVersions(bean, element, null);
View Full Code Here

  @SuppressWarnings({ "unchecked", "rawtypes" })
  @Transactional(readOnly = true)
  public Object load(final Long id, final Long revision) throws CoreException,
      ElementCreationException {
    final Element e = elementDao.get(id);
//    logger.info("loaded element id {} use cache {}", id, useCache);
    if (logger.isDebugEnabled()) {
      e.print(0, "loaded element id " + id);
    }
    try {
      final ElementCreator creator = new ElementCreator(elementTypeDao,
          elementDao, propertyTypeDao, useCache?cache:null);
      Object obj = creator.load(e, revision);
View Full Code Here

  @Transactional(readOnly = true)
  public List<Modification> getModifications(final Long id) { // NOPMD by
                                // wildi on
                                // 9/21/10 6:35
                                // AM
    final Element e = elementDao.get(id); // NOPMD by wildi on 9/21/10 6:35
                        // AM
    return new ArrayList<Modification>(e.getModifications());
  }
View Full Code Here

TOP

Related Classes of ch.semafor.gendas.model.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.