Esempio n. 1
0
 private void readPositionalFieldNode(Node node, PositionalRecordDescriptor recordDescriptorIn)
     throws MetadataReaderException {
   PositionalFieldDescriptor positionalFieldDescriptor = new PositionalFieldDescriptor();
   if (node.hasAttributes()) {
     NamedNodeMap attributes = node.getAttributes();
     for (int i = 0; i < attributes.getLength(); i++) {
       Node attr = attributes.item(i);
       if (attr.getNodeName().equals("name")) {
         String fieldName = attr.getNodeValue();
         Method getter;
         try {
           getter =
               ReflectUtil.getGetterFromFieldName(fieldName, recordDescriptorIn.getRecordClazz());
         } catch (SecurityException e) {
           throw new MetadataReaderException(e);
         } catch (NoSuchMethodException e) {
           throw new MetadataReaderException(
               "Getter method not found for field name: " + fieldName, e);
         }
         positionalFieldDescriptor.setGetter(getter);
       } else if (attr.getNodeName().equals("decorator-class")) {
         String decoratorClazzName = attr.getNodeValue();
         FieldDecorator<?> decorator;
         try {
           Object decoratorObj = Class.forName(decoratorClazzName).newInstance();
           if (FieldDecorator.class.isInstance(decoratorObj)) {
             decorator = (FieldDecorator<?>) decoratorObj;
           } else {
             throw new MetadataReaderException(
                 "Decorator class must be a subtype of " + FieldDecorator.class);
           }
         } catch (ClassNotFoundException e) {
           throw new MetadataReaderException(
               "Decorator class not found on classpath: " + decoratorClazzName, e);
         } catch (Exception e) {
           throw new MetadataReaderException(
               "Error while instantiating decorator class: " + decoratorClazzName, e);
         }
         positionalFieldDescriptor.setDecorator(decorator);
       } else if (attr.getNodeName().equals("initial-position")) {
         int initialPosition = Integer.parseInt(attr.getNodeValue());
         positionalFieldDescriptor.setInitialPosition(initialPosition);
       } else if (attr.getNodeName().equals("final-position")) {
         int finalPosition = Integer.parseInt(attr.getNodeValue());
         positionalFieldDescriptor.setFinalPosition(finalPosition);
       } else if (attr.getNodeName().equals("padding-align")) {
         PaddingAlign paddingAlign = PaddingAlign.valueOf(attr.getNodeValue());
         positionalFieldDescriptor.setPaddingAlign(paddingAlign);
       } else if (attr.getNodeName().equals("padding-character")) {
         String paddingCharacter = attr.getNodeValue();
         positionalFieldDescriptor.setPaddingCharacter(paddingCharacter.charAt(0));
       } else if (attr.getNodeName().equals("trim-on-read")) {
         boolean trimOnRead = Boolean.valueOf(attr.getNodeValue());
         positionalFieldDescriptor.setTrimOnRead(trimOnRead);
       }
     }
   }
   recordDescriptorIn.getFieldDescriptors().add(positionalFieldDescriptor);
 }
Esempio n. 2
0
 private RecordDescriptor readFFPojoNode(Node node) throws MetadataReaderException {
   RecordDescriptor recordDescriptor = null;
   Class<?> recordClazz = null;
   if (node.hasAttributes()) {
     NamedNodeMap attributes = node.getAttributes();
     for (int i = 0; i < attributes.getLength(); i++) {
       Node attr = attributes.item(i);
       if (attr.getNodeName().equals("class")) {
         String recordClazzName = attr.getNodeValue();
         try {
           recordClazz = Class.forName(recordClazzName);
         } catch (ClassNotFoundException e) {
           throw new MetadataReaderException(
               "Record class not found on classpath: " + recordClazzName, e);
         }
       }
     }
   }
   if (node.hasChildNodes()) {
     NodeList childNodes = node.getChildNodes();
     for (int i = 0; i < childNodes.getLength(); i++) {
       Node childNode = childNodes.item(i);
       if (childNode.getNodeType() == Node.ELEMENT_NODE) {
         if (childNode.getNodeName().equals("positional")) {
           PositionalRecordDescriptor positionalRecordDescriptor =
               new PositionalRecordDescriptor();
           positionalRecordDescriptor.setRecordClazz(recordClazz);
           readPositionalNode(childNode, positionalRecordDescriptor);
           recordDescriptor = positionalRecordDescriptor;
         } else if (childNode.getNodeName().equals("delimited")) {
           DelimitedRecordDescriptor delimitedRecordDescriptor = new DelimitedRecordDescriptor();
           delimitedRecordDescriptor.setRecordClazz(recordClazz);
           readDelimitedNode(childNode, delimitedRecordDescriptor);
           recordDescriptor = delimitedRecordDescriptor;
         }
       }
     }
   }
   return recordDescriptor;
 }