Example usage for org.apache.thrift TBase deepCopy

List of usage examples for org.apache.thrift TBase deepCopy

Introduction

In this page you can find the example usage for org.apache.thrift TBase deepCopy.

Prototype

public T deepCopy();

Source Link

Usage

From source file:ezbake.thrift.utils.xml2thrift.sax.TagEnd.java

License:Apache License

/**
 * //from www. jav a2 s  .  co  m
 * @param qName The qName 
 * @param mapper The current mapper object 
 * @return True if set 
 */
public static boolean makeNest(String qName, TBaseMapper mapper) {

    Class<?> clazz = getParentClass(mapper);
    Object parentObject = getParentObject(mapper);

    if (parentObject == null) {
        log.warn("Missed field: " + qName);
        return false;
    }

    /* If the qName matches, then the current object is a child */
    for (Field field : clazz.getFields()) {

        Object childObject = getObject(qName, field, mapper);

        /* To counter act primitive's with the same name as parent classes 
         * Need to find an optimal place... */
        if (XMLUtil.isPrimitive(field)) {
            continue;
        }

        if (XMLUtil.compareTypes(qName, field, childObject)) {

            // Need to check children
            mapper.getCallStack().clear();
            mapper.getCallStack().add(qName);
            hasChildren(qName, mapper, childObject);

            // Set parent-child nesting - after child's children are set
            if (XMLUtil.setObject(parentObject, field, childObject)) {
                /* Remove from map after it's been set 
                 * if not in map, look in comparables and remove */
                mapper.getData().remove(qName.toLowerCase(), childObject);
                if (mapper.getComparables().containsKey(qName.toLowerCase())) {
                    String name = mapper.getComparables().get(qName.toLowerCase());
                    mapper.getData().remove(name.toLowerCase(), childObject);
                }
            }

            mapper.setRecurse(false);
            return true;
        } else if (qName.equalsIgnoreCase(field.getName())) {
            try {

                TBase<?, ?> temp = (TBase<?, ?>) XMLUtil.getObjectFromList(mapper.getData().get(qName), 0);
                if (temp instanceof TBase) {
                    childObject = temp.deepCopy();
                }

                if (XMLUtil.setObject(parentObject, field, childObject)) {
                    return true;
                }
            } catch (Exception e) {
                log.error("TagEnd.makeNest: ", e);
            }
        }
    }

    return false;
}