コード例 #1
0
 @SuppressWarnings({"unchecked", "rawtypes"})
 static Generator<Object> createMultiplicityWrapper(
     ComponentDescriptor instance, Generator<?> generator, BeneratorContext context) {
   String container = instance.getContainer();
   if (container == null) {
     Generator<Long> longCountGenerator =
         DescriptorUtil.createDynamicCountGenerator(instance, 1L, 1L, true, context);
     NonNullGenerator<Integer> countGenerator =
         WrapperFactory.asNonNullGenerator(
             new AsIntegerGeneratorWrapper<Number>((Generator) longCountGenerator));
     return new SimplifyingSingleSourceArrayGenerator(generator, countGenerator);
   }
   // handle container
   Generator<Long> longCountGenerator;
   if (instance.getLocalType().getSource() != null)
     longCountGenerator =
         DescriptorUtil.createDynamicCountGenerator(instance, null, null, true, context);
   else
     longCountGenerator =
         DescriptorUtil.createDynamicCountGenerator(instance, 1L, 1L, true, context);
   NonNullGenerator<Integer> countGenerator =
       WrapperFactory.asNonNullGenerator(
           new AsIntegerGeneratorWrapper<Number>((Generator) longCountGenerator));
   if ("array".equals(container))
     return new SingleSourceArrayGenerator(
         generator, generator.getGeneratedType(), countGenerator);
   else if ("list".equals(container))
     return new SingleSourceCollectionGenerator(generator, ArrayList.class, countGenerator);
   else if ("set".equals(container))
     return new SingleSourceCollectionGenerator(generator, HashSet.class, countGenerator);
   else if ("map".equals(container)) return (Generator<Object>) generator;
   else throw new SyntaxError("Not a supported container", container);
 }
コード例 #2
0
 private void writeHeaderRow(Entity entity, HSSFSheet sheet) {
   HSSFRow headerRow = sheet.createRow(0);
   int colnum = 0;
   for (Map.Entry<String, Object> component : getComponents(entity)) {
     String componentName = component.getKey();
     headerRow.createCell(colnum).setCellValue(new HSSFRichTextString(componentName));
     ComponentDescriptor cd = entity.descriptor().getComponent(componentName);
     PrimitiveType primitiveType;
     if (cd.getTypeDescriptor() instanceof SimpleTypeDescriptor)
       primitiveType = ((SimpleTypeDescriptor) cd.getTypeDescriptor()).getPrimitiveType();
     else
       throw new UnsupportedOperationException(
           "Can only export simple type attributes, "
               + "failed to export "
               + entity.type()
               + '.'
               + cd.getName());
     Class<?> javaType = (primitiveType != null ? primitiveType.getJavaType() : String.class);
     String formatString = null;
     if (BeanUtil.isIntegralNumberType(javaType)) formatString = getIntegralPattern();
     else if (BeanUtil.isDecimalNumberType(javaType)) formatString = getDecimalPattern();
     else if (Time.class.isAssignableFrom(javaType)) formatString = getTimePattern();
     else if (Timestamp.class.isAssignableFrom(javaType)) formatString = getTimestampPattern();
     else if (Date.class.isAssignableFrom(javaType)) formatString = getDatePattern();
     if (formatString != null) {
       HSSFDataFormat dataFormat = workbook.createDataFormat();
       CellStyle columnStyle = workbook.createCellStyle();
       columnStyle.setDataFormat(dataFormat.getFormat(formatString));
       sheet.setDefaultColumnStyle(colnum, columnStyle);
     }
     colnum++;
   }
 }
コード例 #3
0
 protected static ComponentBuilder<?> createScriptBuilder(
     ComponentDescriptor component, BeneratorContext context) {
   TypeDescriptor type = component.getTypeDescriptor();
   if (type == null) return null;
   String scriptText = type.getScript();
   if (scriptText == null) return null;
   Script script = ScriptUtil.parseScriptText(scriptText);
   Generator<?> generator = new ScriptGenerator(script);
   generator =
       DescriptorUtil.createConvertingGenerator(component.getTypeDescriptor(), generator, context);
   return builderFromGenerator(generator, component, context);
 }
コード例 #4
0
 private static ComponentBuilder<?> builderFromGenerator(
     Generator<?> source, ComponentDescriptor descriptor, BeneratorContext context) {
   boolean nullability = DescriptorUtil.isNullable(descriptor, context);
   Double nullQuota = descriptor.getNullQuota();
   if (nullQuota != null && nullQuota != 0)
     source = context.getGeneratorFactory().applyNullSettings(source, nullability, nullQuota);
   TypeDescriptor typeDescriptor = descriptor.getTypeDescriptor();
   String scope = (typeDescriptor != null ? typeDescriptor.getScope() : null);
   if (descriptor instanceof ArrayElementDescriptor) {
     int index = ((ArrayElementDescriptor) descriptor).getIndex();
     return new ArrayElementBuilder(index, source, scope);
   } else return new PlainEntityComponentBuilder(descriptor.getName(), source, scope);
 }
コード例 #5
0
 @SuppressWarnings({"unchecked", "rawtypes"})
 static ComponentBuilder<?> wrapWithCondition(
     ComponentDescriptor descriptor, ComponentBuilder<?> builder) {
   TypeDescriptor typeDescriptor = descriptor.getTypeDescriptor();
   if (typeDescriptor == null) return builder;
   String conditionText = typeDescriptor.getCondition();
   if (!StringUtil.isEmpty(conditionText)) {
     Expression<Boolean> condition = new ScriptExpression<Boolean>(conditionText);
     return new ConditionalComponentBuilder(builder, condition);
   } else return builder;
 }
コード例 #6
0
  public static ComponentBuilder<?> createComponentBuilder(
      ComponentDescriptor descriptor, Uniqueness ownerUniqueness, BeneratorContext context) {
    LOGGER.debug("createComponentBuilder({})", descriptor.getName());

    ComponentBuilder<?> result = null;
    if (descriptor instanceof ArrayElementDescriptor)
      result = createPartBuilder(descriptor, ownerUniqueness, context);
    else if (descriptor instanceof PartDescriptor) {
      TypeDescriptor type = descriptor.getTypeDescriptor();
      if (type instanceof AlternativeGroupDescriptor)
        result =
            createAlternativeGroupBuilder(
                (AlternativeGroupDescriptor) type, ownerUniqueness, context);
      else result = createPartBuilder(descriptor, ownerUniqueness, context);
    } else if (descriptor instanceof ReferenceDescriptor)
      result = createReferenceBuilder((ReferenceDescriptor) descriptor, context);
    else if (descriptor instanceof IdDescriptor)
      result = createIdBuilder((IdDescriptor) descriptor, ownerUniqueness, context);
    else throw new ConfigurationError("Not a supported element: " + descriptor.getClass());
    result = wrapWithCondition(descriptor, result);
    return result;
  }