Example #1
0
 /**
  * @param nd
  * @param value
  * @return
  */
 public static <E extends Enum<E>> Object convertToEnum(NodeType nd, Object value) {
   for (EnumValueSpec enumValue : nd.getEnumSpec().getEnumValues()) {
     if (enumValue.getId().equals(value)) {
       if (nd.getEnumType() != null) {
         /*
          * ok we have the enum class, so we will return the real enum value
          */
         Class<E> enumType = nd.getEnumType();
         try {
           Object result = Enum.valueOf(enumType, enumValue.getName());
           LOG.debug("Converted " + value + " to enum value " + enumValue.getName());
           return result;
         } catch (IllegalArgumentException x) {
           LOG.warn("Could not find enum value with name '" + enumValue.getName() + "'");
           return null;
         }
       } else {
         /*
          * we do not have the enum class so we return the string name of the enum value
          */
         LOG.debug("Converted " + value + " to enum string value " + enumValue.getName());
         return enumValue.getName();
       }
     }
   }
   return null;
 }
Example #2
0
 public static NodeType create(EntityType entityType, NodeSpec nodeSpec) {
   NodeType nodeType = new NodeType(entityType);
   nodeType.name = nodeSpec.getName();
   nodeType.javaType = nodeSpec.getJavaType();
   System.out.println(
       nodeSpec.getEntity().getClassName()
           + "."
           + nodeSpec.getName()
           + "  "
           + nodeSpec.getRelationSpec());
   if (nodeSpec.getRelationSpec() != null) {
     RelationSpec spec = nodeSpec.getRelationSpec();
     NodeSpec backReference = spec.getBackReference();
     NodeSpec sortNode = spec.getSortNode();
     NodeSpec onwardJoin = spec.getOwnwardJoin();
     nodeType.relation =
         new Relation(
             spec.getEntitySpec().getClassName(),
             spec.getType(),
             backReference != null ? backReference.getName() : null,
             sortNode != null ? sortNode.getName() : null,
             onwardJoin != null ? onwardJoin.getName() : null);
   }
   nodeType.columnName = nodeSpec.getColumnName();
   nodeType.jdbcType = nodeSpec.getJdbcType();
   nodeType.mandatory = nodeSpec.getNullable() == Nullable.NOT_NULL;
   nodeType.optimisticLock = nodeSpec.isOptimisticLock();
   nodeType.enumSpec = nodeSpec.getEnumSpec();
   if (nodeType.getEnumSpec() != null) {
     try {
       nodeType.enumType =
           NodeType.class.getClassLoader().loadClass(nodeSpec.getEnumSpec().getClassName());
     } catch (ClassNotFoundException e) {
       LOG.info("Enum class " + nodeSpec.getEnumSpec().getClassName() + " is not available.");
     }
   }
   if (nodeSpec.getFixedValue() != null) {
     if (nodeType.getEnumSpec() != null) {
       nodeType.fixedValue = convertToEnum(nodeType, nodeSpec.getFixedValue());
     } else {
       nodeType.fixedValue = nodeSpec.getFixedValue();
     }
   }
   nodeType.typeConverterFqn = nodeSpec.getTypeConverter();
   return nodeType;
 }