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++;
   }
 }
 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);
 }
  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;
  }