Package ch.semafor.gendas.model

Examples of ch.semafor.gendas.model.ElementType


  /**
   * @throws ElementTypeNotFoundException
   * */
  private ElementType getElementType(final String typeName)
      throws CoreException {
    final ElementType elType = elementTypeDao.findByName(typeName);
    if (elType == null) {
      throw new CoreException("ElementType " + typeName + " not found");
    }
    return elType;
  }
View Full Code Here


   *
   */
  public void setMatchingIdsAndVersions(final Object bean, final Element element, final Class genArgType ) throws CoreException{
    final Class<?> clazz = bean.getClass();
    logger.debug("class {}", clazz.getCanonicalName());
    final ElementType elType; // NOPMD PMD: AvoidFinalLocalVariable by wim on 9/20/10 2:59 PM
    if (bean instanceof java.util.List) {
      logger.debug("bean {} instance of list<{}>", clazz.getCanonicalName(),
          genArgType.getCanonicalName() + ">");
      elType = getElementType(genArgType.getCanonicalName());
    } else {
      elType = getElementType(clazz.getCanonicalName());
    }
    logger.debug("checking Element  ({})", elType.toString());
    if (beanElementMap.containsKey(bean)) {
      return;
    }
    beanElementMap.put(bean, element);
    setId(bean, element.getId());
    if( element.getVersion() != null){
      Integer v = Integer.valueOf(element.getVersion().intValue());
      setVersion(bean, v);
    }
   
    ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
      public void doWith(final Method method) {
        try {
          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)) {
              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);
              if (elType.hasChild(type)) {
                final String propName = getPropertyName(method);
                logger.debug("about to get reference {}", propName);
                final Object ref = method.invoke(bean);
                if (ref != null && ref instanceof java.util.List) {
                    logger.debug("LIST SIZE {}",
View Full Code Here

  public Element create(final Object bean, final Class genArgType)
      throws CoreException, ElementCreationException {

    final Class<?> clazz = bean.getClass();
    logger.debug("class {}", clazz.getCanonicalName());
    final ElementType elType; // NOPMD PMD: AvoidFinalLocalVariableby wim on
                              // 9/20/10 2:59 PM
    if (bean instanceof java.util.List) {
      logger.debug("bean {} instance of list<{}>", clazz.getCanonicalName(),
          genArgType.getCanonicalName() + ">");
      elType = getElementType(genArgType.getCanonicalName());
    } else {
      elType = getElementType(clazz.getCanonicalName());
    }
    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);
View Full Code Here

    }

    @SuppressWarnings("rawtypes") // NOPMD by wildi on 9/21/10 6:34 AM
  @Transactional
  public ElementType createElementType(final Class beanClass) {
  final ElementType t = new ElementTypeCreator(elementTypeDao, propertyTypeDao).create(beanClass); // NOPMD by wildi on 9/21/10 6:30 AM
  elementTypeDao.save(t);
  return t;
    }
View Full Code Here

  private ElementType getElementType(final String name) {
    if (elementTypeDao.exists(name)) {
      return elementTypeDao.findByName(name); // NOPMD by wildi on 9/21/10 6:14
                                              // AM
    }
    ElementType et = elementTypes.get(name); // NOPMD by wildi on 9/21/10 6:14
                                             // AM
    if (et != null) { // NOPMD by wildi on 9/21/10 6:14 AM
      et.setCreated();
    } else {
      logger.debug("Created Element Type {}", name);
      et = new ElementType(name);
      elementTypes.put(name, et);
    }
    return et;
  }
View Full Code Here

    return propertyTypeDao.save(p);
  }

  public ElementType create(final Class beanClass) {
    final String name = beanClass.getCanonicalName();
    final ElementType elementType = getElementType(name);
    if (!elementType.isCreated()) {
      // ToDo, unnest, PMD:AvoidDeeplyNestedIfStmts
      ReflectionUtils.doWithMethods(beanClass,
          new ReflectionUtils.MethodCallback() {
            public void doWith(final Method method) {
              if (method.getName().startsWith("get")
                  || method.getName().startsWith("is")
                  && !method.getName().equals("getClass")) {
                final Class retType = method.getReturnType();
                if (isPrimitiveType(retType)) {
                  final PropertyType propType = getPropertyType(method);
                  elementType.add(propType);
                } else if (!retType.equals(java.lang.ClassLoader.class)
                    && !retType.equals(java.lang.annotation.Annotation.class)
                    && !retType.equals(java.lang.Class.class)) {
                  Class argType = retType;
                  if (retType.equals(java.util.List.class)) { // see above
                    final Class genArgType = getGenericArgType(method
                        .getGenericReturnType());
                    if (genArgType != null) {
                      argType = genArgType;
                    }
                  }
                  if (!elementType.hasChild(argType.getCanonicalName())
                      && !elementType.getName().equals(
                          argType.getCanonicalName())) {
                    if( isPrimitiveType(argType)){
                      final PropertyType propType = getPropertyType(method);
                      logger.debug("adding list property {}", name );
                      elementType.add(propType);
                    }
                    logger.debug("adding reference {} for {}",
                        argType.getCanonicalName(), name);
                    elementType.addReference(create(argType));
                  }
                }
              }
            }
          }); // ToDo, unnest, PMD:AvoidDeeplyNestedIfStmts
View Full Code Here

  /**
   * @throws ElementTypeNotFoundException
   * */
  private ElementType getElementType(final String typeName)
      throws CoreException {
    final ElementType elType = elementTypeDao.findByName(typeName);
    if (elType == null) {
      throw new CoreException("ElementType " + typeName + " not found");
    }
    return elType;
  }
View Full Code Here

        logger.info(ex.getMessage());
      }
    }
 
  private void setIdAndVersion(final Object bean, final Element element, final Class genArgType ) throws CoreException{
    final ElementType elType; // NOPMD PMD: AvoidFinalLocalVariable by wim on 9/20/10 2:59 PM
      if (bean instanceof java.util.List) {
        logger.debug("bean {} instance of list<{}>", bean.getClass().getCanonicalName(),
            genArgType.getCanonicalName() + ">");
        elType = getElementType(genArgType.getCanonicalName());
      } else {
        elType = getElementType(bean.getClass().getCanonicalName());
      }
      logger.info( "setting bean property {} for type {}", elType.getBeanId(), elType.getName() );
      setId(bean, element.getId(), elType.getBeanId());
      if( element.getVersion() != null){
        Integer v = Integer.valueOf(element.getVersion().intValue());
        setVersion(bean, v, elType.getBeanVersionId());
      }
  }
View Full Code Here

  public Element create(final Object bean, final Class genArgType)
      throws CoreException, ElementCreationException {

    final Class<?> clazz = bean.getClass();
    logger.debug("class {}", clazz.getCanonicalName());
    final ElementType elType; // NOPMD PMD: AvoidFinalLocalVariableby wim on
                              // 9/20/10 2:59 PM
    if (bean instanceof java.util.List) {
      logger.debug("bean {} instance of list<{}>", clazz.getCanonicalName(),
          genArgType.getCanonicalName() + ">");
      elType = getElementType(genArgType.getCanonicalName());
    } else {
      elType = getElementType(clazz.getCanonicalName());
    }
    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)
View Full Code Here

  @SuppressWarnings("rawtypes")
  // NOPMD by wildi on 9/21/10 6:34 AM
  @Transactional
  public ElementType createElementType(final Class beanClass, String idName, String versionName) {
    final ElementType t = new ElementTypeCreator(elementTypeDao,
        propertyTypeDao).create(beanClass, idName, versionName); // NOPMD by wildi on 9/21/10
                          // 6:30 AM   
    elementTypeDao.save(t);
    return t;
  }
View Full Code Here

TOP

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

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.