Added splash screen code to my package

Posted by Youssef on Stack Overflow See other posts from Stack Overflow or by Youssef
Published on 2010-04-14T14:20:45Z Indexed on 2010/04/14 14:23 UTC
Read the original article Hit count: 442

Filed under:

Please i need support to added splash screen code to my package

/* * T24_Transformer_FormView.java */

package t24_transformer_form; import org.jdesktop.application.Action; import org.jdesktop.application.ResourceMap; import org.jdesktop.application.SingleFrameApplication; import org.jdesktop.application.FrameView; import org.jdesktop.application.TaskMonitor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileFilter; // old T24 Transformer imports import java.io.File; import java.io.FileWriter; import java.io.StringWriter; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; //import java.util.Properties; import java.util.StringTokenizer; import javax.swing.; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.w3c.dom.Document; import org.w3c.dom.DocumentFragment; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import com.ejada.alinma.edh.xsdtransform.util.ConfigKeys; import com.ejada.alinma.edh.xsdtransform.util.XSDElement; import com.sun.org.apache.xml.internal.serialize.OutputFormat; import com.sun.org.apache.xml.internal.serialize.XMLSerializer; /* * The application's main frame. */ public class T24_Transformer_FormView extends FrameView { /**} * static holders for application-level utilities * { */ //private static Properties appProps;

private static Logger appLogger;

/**
 *
 */
private StringBuffer columnsCSV = null;
private ArrayList<String> singleValueTableColumns = null;
private HashMap<String, String> multiValueTablesSQL = null;
private HashMap<Object, HashMap<String, Object>> groupAttrs = null;
private ArrayList<XSDElement> xsdElementsList = null;

/**
 * initialization    */
private void init() /*throws Exception*/ {
    // init the properties object

            //FileReader in = new FileReader(appConfigPropsPath);
    //appProps.load(in);

            // log4j.properties constant
            String PROP_LOG4J_CONFIG_FILE = "log4j.properties";
    // init the logger
    if ((PROP_LOG4J_CONFIG_FILE != null)
            && (!PROP_LOG4J_CONFIG_FILE.equals(""))) {
        PropertyConfigurator.configure(PROP_LOG4J_CONFIG_FILE);
        if (appLogger == null) {
            appLogger = Logger.getLogger(T24_Transformer_FormView.class.getName());
        }
        appLogger.info("Application initialization successful.");
    }

    columnsCSV = new StringBuffer(ConfigKeys.FIELD_TAG + "," + ConfigKeys.FIELD_NUMBER + ","
            + ConfigKeys.FIELD_DATA_TYPE + "," + ConfigKeys.FIELD_FMT + "," + ConfigKeys.FIELD_LEN + ","
            + ConfigKeys.FIELD_INPUT_LEN + "," + ConfigKeys.FIELD_GROUP_NUMBER + "," + ConfigKeys.FIELD_MV_GROUP_NUMBER
            + "," + ConfigKeys.FIELD_SHORT_NAME + "," + ConfigKeys.FIELD_NAME + "," + ConfigKeys.FIELD_COLUMN_NAME + ","
            + ConfigKeys.FIELD_GROUP_NAME + "," + ConfigKeys.FIELD_MV_GROUP_NAME + "," + ConfigKeys.FIELD_JUSTIFICATION
            + "," + ConfigKeys.FIELD_TYPE + "," + ConfigKeys.FIELD_SINGLE_OR_MULTI + System.getProperty("line.separator"));
    singleValueTableColumns = new ArrayList<String>();
    singleValueTableColumns.add(ConfigKeys.COLUMN_XPK_ROW + ConfigKeys.DELIMITER_COLUMN_TYPE
            + ConfigKeys.DATA_TYPE_XSD_NUMERIC);
    multiValueTablesSQL = new HashMap<String, String>();
    groupAttrs = new HashMap<Object, HashMap<String, Object>>();
    xsdElementsList = new ArrayList<XSDElement>();
}

/**
 * initialize the <code>DocumentBuilder</code> and read the XSD file
 *
 * @param docPath
 * @return the <code>Document</code> object representing the read XSD file
 */
private Document retrieveDoc(String docPath) {
    Document xsdDoc = null;

    File file = new File(docPath);
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        xsdDoc = builder.parse(file);
    } catch (Exception e) {
        appLogger.error(e.getMessage());
    }

    return xsdDoc;
}

/**
 * perform the iteration/modification on the document
 * iterate to the level which contains all the elements (Single-Value, and Groups) and start processing each
 *
 * @param xsdDoc
 * @return
 */
private Document processDoc(Document xsdDoc) {
    ArrayList<Object> newElementsList = new ArrayList<Object>();
    HashMap<String, Object> docAttrMap = new HashMap<String, Object>();
    Element sequenceElement = null;
    Element schemaElement = null;

    // get document's root element
    NodeList nodes = xsdDoc.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        if (ConfigKeys.TAG_SCHEMA.equals(nodes.item(i).getNodeName())) {
            schemaElement = (Element) nodes.item(i);
            break;
        }
    }

    // process the document (change single-value elements, collect list of new elements to be added)
    for (int i1 = 0; i1 < schemaElement.getChildNodes().getLength(); i1++) {
        Node childLevel1 = (Node) schemaElement.getChildNodes().item(i1);

        // <ComplexType> element
        if (childLevel1.getNodeName().equals(ConfigKeys.TAG_COMPLEX_TYPE)) {

            // first, get the main attributes and put it in the csv file
            for (int i6 = 0; i6 < childLevel1.getChildNodes().getLength(); i6++) {
                Node child6 = childLevel1.getChildNodes().item(i6);
                if (ConfigKeys.TAG_ATTRIBUTE.equals(child6.getNodeName())) {
                    if (child6.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME) != null) {
                        String attrName = child6.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME).getNodeValue();
                        if (((Element) child6).getElementsByTagName(ConfigKeys.TAG_SIMPLE_TYPE).getLength() != 0) {
                            Node simpleTypeElement = ((Element) child6).getElementsByTagName(ConfigKeys.TAG_SIMPLE_TYPE)
                                    .item(0);
                            if (((Element) simpleTypeElement).getElementsByTagName(ConfigKeys.TAG_RESTRICTION).getLength() != 0) {
                                Node restrictionElement = ((Element) simpleTypeElement).getElementsByTagName(
                                        ConfigKeys.TAG_RESTRICTION).item(0);
                                if (((Element) restrictionElement).getElementsByTagName(ConfigKeys.TAG_MAX_LENGTH).getLength() != 0) {
                                    Node maxLengthElement = ((Element) restrictionElement).getElementsByTagName(
                                            ConfigKeys.TAG_MAX_LENGTH).item(0);
                                    HashMap<String, String> elementProperties = new HashMap<String, String>();
                                    elementProperties.put(ConfigKeys.FIELD_TAG, attrName);
                                    elementProperties.put(ConfigKeys.FIELD_NUMBER, "0");
                                    elementProperties.put(ConfigKeys.FIELD_DATA_TYPE, ConfigKeys.DATA_TYPE_XSD_STRING);
                                    elementProperties.put(ConfigKeys.FIELD_FMT, "");
                                    elementProperties.put(ConfigKeys.FIELD_NAME, attrName);
                                    elementProperties.put(ConfigKeys.FIELD_SHORT_NAME, attrName);
                                    elementProperties.put(ConfigKeys.FIELD_COLUMN_NAME, attrName);
                                    elementProperties.put(ConfigKeys.FIELD_SINGLE_OR_MULTI, "S");
                                    elementProperties.put(ConfigKeys.FIELD_LEN, maxLengthElement.getAttributes().getNamedItem(
                                            ConfigKeys.ATTR_VALUE).getNodeValue());
                                    elementProperties.put(ConfigKeys.FIELD_INPUT_LEN, maxLengthElement.getAttributes()
                                            .getNamedItem(ConfigKeys.ATTR_VALUE).getNodeValue());
                                    constructElementRow(elementProperties);
                                    // add the attribute as a column in the single-value table
                                    singleValueTableColumns.add(attrName + ConfigKeys.DELIMITER_COLUMN_TYPE
                                            + ConfigKeys.DATA_TYPE_XSD_STRING + ConfigKeys.DELIMITER_COLUMN_TYPE
                                            + maxLengthElement.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE).getNodeValue());
                                    // add the attribute as an element in the elements list
                                    addToElementsList(attrName, attrName);

                                    appLogger.debug("added attribute: " + attrName);
                                }
                            }
                        }
                    }
                }
            }

            // now, loop on the elements and process them
            for (int i2 = 0; i2 < childLevel1.getChildNodes().getLength(); i2++) {
                Node childLevel2 = (Node) childLevel1.getChildNodes().item(i2);

                // <Sequence> element
                if (childLevel2.getNodeName().equals(ConfigKeys.TAG_SEQUENCE)) {
                    sequenceElement = (Element) childLevel2;

                    for (int i3 = 0; i3 < childLevel2.getChildNodes().getLength(); i3++) {
                        Node childLevel3 = (Node) childLevel2.getChildNodes().item(i3);

                        // <Element> element
                        if (childLevel3.getNodeName().equals(ConfigKeys.TAG_ELEMENT)) {
                            // check if single element or group
                            if (isGroup(childLevel3)) {
                                processGroup(childLevel3, true, null, null, docAttrMap, xsdDoc, newElementsList);
                                // insert a new comment node with the contents of the group tag
                                sequenceElement.insertBefore(xsdDoc.createComment(serialize(childLevel3)), childLevel3);
                                // remove the group tag
                                sequenceElement.removeChild(childLevel3);
                            } else {
                                processElement(childLevel3);
                            }
                        }
                    }
                }
            }
        }
    }

    // add new elements
    // this step should be after finishing processing the whole document.  when you add new elements to the document
    // while you are working on it, those new elements will be included in the processing.  We don't need that!
    for (int i = 0; i < newElementsList.size(); i++)  {
        sequenceElement.appendChild((Element) newElementsList.get(i));
    }

    // write the new required attributes to the schema element
    Iterator<String> attrIter = docAttrMap.keySet().iterator();
    while(attrIter.hasNext()) {
        Element attr = (Element) docAttrMap.get(attrIter.next());
        Element newAttrElement = xsdDoc.createElement(ConfigKeys.TAG_ATTRIBUTE);

        appLogger.debug("appending attr. [" + attr.getAttribute(ConfigKeys.ATTR_NAME) + "]...");

        newAttrElement.setAttribute(ConfigKeys.ATTR_NAME, attr.getAttribute(ConfigKeys.ATTR_NAME));
        newAttrElement.setAttribute(ConfigKeys.ATTR_TYPE, attr.getAttribute(ConfigKeys.ATTR_TYPE));
        schemaElement.appendChild(newAttrElement);
    }

    return xsdDoc;
}

/**
 * add a new <code>XSDElement</code> with the given <code>name</code> and <code>businessName</code> to
 * the elements list
 *
 * @param name
 * @param businessName
 */
private void addToElementsList(String name, String businessName) {
    xsdElementsList.add(new XSDElement(name, businessName));
}

/**
 * add the given <code>XSDElement</code> to the elements list
 *
 * @param element
 */
private void addToElementsList(XSDElement element) {
    xsdElementsList.add(element);
}

/**
 * check if the <code>element</code> sent is single-value element or group
 * element. the comparison depends on the children of the element. if found one of type
 * <code>ComplexType</code> then it's a group element, and if of type
 * <code>SimpleType</code> then it's a single-value element
 *
 * @param element
 * @return <code>true</code> if the element is a group element,
 *         <code>false</code> otherwise
 */
private boolean isGroup(Node element) {
    for (int i = 0; i < element.getChildNodes().getLength(); i++) {
        Node child = (Node) element.getChildNodes().item(i);
        if (child.getNodeName().equals(ConfigKeys.TAG_COMPLEX_TYPE)) { // found a ComplexType child (Group element)
            return true;
        } else if (child.getNodeName().equals(ConfigKeys.TAG_SIMPLE_TYPE)) { // found a SimpleType child (Single-Value element)
            return false;
        }
    }

    return false;
    /*
    String attrName = null;
    if (element.getAttributes() != null) {
        Node attribute = element.getAttributes().getNamedItem(XSDTransformer.ATTR_NAME);
        if (attribute != null) {
            attrName = attribute.getNodeValue();
        }
    }
    if (attrName.startsWith("g")) { // group element
        return true;
    } else { // single element
        return false;
    }
    */
}

/**
 * process a group element.  recursively, process groups till no more group elements are found
 *
 * @param element
 * @param isFirstLevelGroup
 * @param attrMap
 * @param docAttrMap
 * @param xsdDoc
 * @param newElementsList
 */
private void processGroup(Node element, boolean isFirstLevelGroup, Node parentGroup, XSDElement parentGroupElement, HashMap<String, Object> docAttrMap,
        Document xsdDoc, ArrayList<Object> newElementsList) {
    String elementName = null;
    HashMap<String, Object> groupAttrMap = new HashMap<String, Object>();
    HashMap<String, Object> parentGroupAttrMap = new HashMap<String, Object>();
    XSDElement groupElement = null;

    if (element.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME) != null) {
        elementName = element.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME).getNodeValue();
    }
    appLogger.debug("processing group [" + elementName + "]...");

    groupElement = new XSDElement(elementName, elementName);

    // get the attributes if a non-first-level-group
    // attributes are: groups's own attributes + parent group's attributes
    if (!isFirstLevelGroup) {
        // get the current element (group) attributes
        for (int i1 = 0; i1 < element.getChildNodes().getLength(); i1++) {
            if (ConfigKeys.TAG_COMPLEX_TYPE.equals(element.getChildNodes().item(i1).getNodeName())) {
                Node complexTypeNode = element.getChildNodes().item(i1);
                for (int i2 = 0; i2 < complexTypeNode.getChildNodes().getLength(); i2++) {
                    if (ConfigKeys.TAG_ATTRIBUTE.equals(complexTypeNode.getChildNodes().item(i2).getNodeName())) {
                        appLogger.debug("add group attr: "
                                + ((Element) complexTypeNode.getChildNodes().item(i2)).getAttribute(ConfigKeys.ATTR_NAME));
                        groupAttrMap.put(((Element) complexTypeNode.getChildNodes().item(i2)).getAttribute(ConfigKeys.ATTR_NAME),
                                complexTypeNode.getChildNodes().item(i2));
                        docAttrMap.put(((Element) complexTypeNode.getChildNodes().item(i2)).getAttribute(ConfigKeys.ATTR_NAME),
                                complexTypeNode.getChildNodes().item(i2));
                    }
                }
            }
        }

        // now, get the parent's attributes
        parentGroupAttrMap = groupAttrs.get(parentGroup);
        if (parentGroupAttrMap != null) {
            Iterator<String> iter = parentGroupAttrMap.keySet().iterator();
            while (iter.hasNext()) {
                String attrName = iter.next();
                groupAttrMap.put(attrName, parentGroupAttrMap.get(attrName));
            }
        }

        // add the attributes to the group element that will be added to the elements list
        Iterator<String> itr = groupAttrMap.keySet().iterator();
        while(itr.hasNext()) {
            groupElement.addAttribute(itr.next());
        }

        // put the attributes in the attributes map
        groupAttrs.put(element, groupAttrMap);
    }

    for (int i = 0; i < element.getChildNodes().getLength(); i++) {
        Node childLevel1 = (Node) element.getChildNodes().item(i);
        if (childLevel1.getNodeName().equals(ConfigKeys.TAG_COMPLEX_TYPE)) {
            for (int j = 0; j < childLevel1.getChildNodes().getLength(); j++) {
                Node childLevel2 = (Node) childLevel1.getChildNodes().item(j);
                if (childLevel2.getNodeName().equals(ConfigKeys.TAG_SEQUENCE)) {
                    for (int k = 0; k < childLevel2.getChildNodes().getLength(); k++) {
                        Node childLevel3 = (Node) childLevel2.getChildNodes().item(k);
                        if (childLevel3.getNodeName().equals(ConfigKeys.TAG_ELEMENT)) {
                            // check if single element or group
                            if (isGroup(childLevel3)) { // another group element..
                                                                                    // unfortunately, a recursion is
                                                                                    // needed here!!! :-(
                                processGroup(childLevel3, false, element, groupElement, docAttrMap, xsdDoc, newElementsList);
                            } else { // reached a single-value element.. copy it under the
                                             // main sequence and apply the name<>shorname replacement
                                processGroupElement(childLevel3, element, groupElement, isFirstLevelGroup, xsdDoc, newElementsList);
                            }
                        }
                    }
                }
            }
        }
    }

    if (isFirstLevelGroup) {
        addToElementsList(groupElement);
    } else {
        parentGroupElement.addChild(groupElement);
    }

    appLogger.debug("finished processing group [" + elementName + "].");
}

/**
 * process the sent <code>element</code> to extract/modify required
 * information:
 * 1. replace the <code>name</code> attribute with the <code>shortname</code>.
 *
 * @param element
 */
private void processElement(Node element) {
    String fieldShortName = null;
    String fieldColumnName = null;
    String fieldDataType = null;
    String fieldFormat = null;
    String fieldInputLength = null;
    String elementName = null;
    HashMap<String, String> elementProperties = new HashMap<String, String>();

    if (element.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME) != null) {
        elementName = element.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME).getNodeValue();
    }
    appLogger.debug("processing element [" + elementName + "]...");

    for (int i = 0; i < element.getChildNodes().getLength(); i++) {
        Node childLevel1 = (Node) element.getChildNodes().item(i);
        if (childLevel1.getNodeName().equals(ConfigKeys.TAG_ANNOTATION)) {
            for (int j = 0; j < childLevel1.getChildNodes().getLength(); j++) {
                Node childLevel2 = (Node) childLevel1.getChildNodes().item(j);
                if (childLevel2.getNodeName().equals(ConfigKeys.TAG_APP_INFO)) {
                    for (int k = 0; k < childLevel2.getChildNodes().getLength(); k++) {
                        Node childLevel3 = (Node) childLevel2.getChildNodes().item(k);
                        if (childLevel3.getNodeName().equals(ConfigKeys.TAG_HAS_PROPERTY)) {
                            if (childLevel3.getAttributes() != null) {
                                String attrName = null;
                                Node attribute = childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME);
                                if (attribute != null) {
                                    attrName = attribute.getNodeValue();
                                    elementProperties.put(attrName, childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE)
                                            .getNodeValue());
                                    if (attrName.equals(ConfigKeys.FIELD_SHORT_NAME)) {
                                        fieldShortName = childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE)
                                                .getNodeValue();
                                    } else if (attrName.equals(ConfigKeys.FIELD_COLUMN_NAME)) {
                                        fieldColumnName = childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE)
                                                .getNodeValue();
                                    } else if (attrName.equals(ConfigKeys.FIELD_DATA_TYPE)) {
                                        fieldDataType = childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE)
                                                .getNodeValue();
                                    } else if (attrName.equals(ConfigKeys.FIELD_FMT)) {
                                        fieldFormat = childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE)
                                                .getNodeValue();
                                    } else if (attrName.equals(ConfigKeys.FIELD_INPUT_LEN)) {
                                        fieldInputLength = childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE)
                                                .getNodeValue();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    // replace the name attribute with the shortname
    if (element.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME) != null) {
        element.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME).setNodeValue(fieldShortName);
    }

    elementProperties.put(ConfigKeys.FIELD_SINGLE_OR_MULTI, "S");
    constructElementRow(elementProperties);
    singleValueTableColumns.add(fieldShortName + ConfigKeys.DELIMITER_COLUMN_TYPE + fieldDataType + fieldFormat
            + ConfigKeys.DELIMITER_COLUMN_TYPE + fieldInputLength);

    // add the element to elements list
    addToElementsList(fieldShortName, fieldColumnName);

    appLogger.debug("finished processing element [" + elementName + "].");
}

/**
 * process the sent <code>element</code> to extract/modify required
 * information:
 * 1. copy the element under the main sequence
 * 2. replace the <code>name</code> attribute with the <code>shortname</code>.
 * 3. add the attributes of the parent groups (if non-first-level-group)
 *
 * @param element
 */
private void processGroupElement(Node element, Node parentGroup, XSDElement parentGroupElement, boolean isFirstLevelGroup, Document xsdDoc, ArrayList<Object> newElementsList) {
    String fieldShortName = null;
    String fieldColumnName = null;
    String fieldDataType = null;
    String fieldFormat = null;
    String fieldInputLength = null;
    String elementName = null;
    Element newElement = null;
    HashMap<String, String> elementProperties = new HashMap<String, String>();
    ArrayList<String> tableColumns = new ArrayList<String>();
    HashMap<String, Object> groupAttrMap = null;

    if (element.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME) != null) {
        elementName = element.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME).getNodeValue();
    }

    appLogger.debug("processing element [" + elementName + "]...");

    // 1. copy the element
    newElement = (Element) element.cloneNode(true);
    newElement.setAttribute(ConfigKeys.ATTR_MAX_OCCURS, "unbounded");

    // 2. if non-first-level-group, replace the element's SimpleType tag with a ComplexType tag
    if (!isFirstLevelGroup) {
        if (((Element) newElement).getElementsByTagName(ConfigKeys.TAG_SIMPLE_TYPE).getLength() != 0) {
          // there should be only one tag of SimpleType
            Node simpleTypeNode = ((Element) newElement).getElementsByTagName(ConfigKeys.TAG_SIMPLE_TYPE).item(0);

            // create the new ComplexType element
            Element complexTypeNode = xsdDoc.createElement(ConfigKeys.TAG_COMPLEX_TYPE);
            complexTypeNode.setAttribute(ConfigKeys.ATTR_MIXED, "true");
            // get the list of attributes for the parent group
            groupAttrMap = groupAttrs.get(parentGroup);
            Iterator<String> attrIter = groupAttrMap.keySet().iterator();
            while(attrIter.hasNext()) {
                Element attr = (Element) groupAttrMap.get(attrIter.next());
                Element newAttrElement = xsdDoc.createElement(ConfigKeys.TAG_ATTRIBUTE);

                appLogger.debug("adding attr. [" + attr.getAttribute(ConfigKeys.ATTR_NAME) + "]...");

                newAttrElement.setAttribute(ConfigKeys.ATTR_REF, attr.getAttribute(ConfigKeys.ATTR_NAME));
                newAttrElement.setAttribute(ConfigKeys.ATTR_USE, "optional");
                complexTypeNode.appendChild(newAttrElement);
            }

            // replace the old SimpleType node with the new ComplexType node
            newElement.replaceChild(complexTypeNode, simpleTypeNode);
        }
    }

    // 3. replace the name with the shortname in the new element
    for (int i = 0; i < newElement.getChildNodes().getLength(); i++) {
        Node childLevel1 = (Node) newElement.getChildNodes().item(i);
        if (childLevel1.getNodeName().equals(ConfigKeys.TAG_ANNOTATION)) {
            for (int j = 0; j < childLevel1.getChildNodes().getLength(); j++) {
                Node childLevel2 = (Node) childLevel1.getChildNodes().item(j);
                if (childLevel2.getNodeName().equals(ConfigKeys.TAG_APP_INFO)) {
                    for (int k = 0; k < childLevel2.getChildNodes().getLength(); k++) {
                        Node childLevel3 = (Node) childLevel2.getChildNodes().item(k);
                        if (childLevel3.getNodeName().equals(ConfigKeys.TAG_HAS_PROPERTY)) {
                            if (childLevel3.getAttributes() != null) {
                                String attrName = null;
                                Node attribute = childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME);
                                if (attribute != null) {
                                    attrName = attribute.getNodeValue();
                                    elementProperties.put(attrName, childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE)
                                            .getNodeValue());
                                    if (attrName.equals(ConfigKeys.FIELD_SHORT_NAME)) {
                                        fieldShortName = childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE)
                                                .getNodeValue();
                                    } else if (attrName.equals(ConfigKeys.FIELD_COLUMN_NAME)) {
                                        fieldColumnName = childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE)
                                                .getNodeValue();
                                    } else if (attrName.equals(ConfigKeys.FIELD_DATA_TYPE)) {
                                        fieldDataType = childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE)
                                                .getNodeValue();
                                    } else if (attrName.equals(ConfigKeys.FIELD_FMT)) {
                                        fieldFormat = childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE)
                                                .getNodeValue();
                                    } else if (attrName.equals(ConfigKeys.FIELD_INPUT_LEN)) {
                                        fieldInputLength = childLevel3.getAttributes().getNamedItem(ConfigKeys.ATTR_VALUE)
                                                .getNodeValue();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (newElement.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME) != null) {
        newElement.getAttributes().getNamedItem(ConfigKeys.ATTR_NAME).setNodeValue(fieldShortName);
    }

    // 4. save the new element to be added to the sequence list
    newElementsList.add(newElement);

    elementProperties.put(ConfigKeys.FIELD_SINGLE_OR_MULTI, "M");
    constructElementRow(elementProperties);
    // create the MULTI-VALUE table

    // 0. Primary Key
    tableColumns.add(ConfigKeys.COLUMN_XPK_ROW + ConfigKeys.DELIMITER_COLUMN_TYPE + ConfigKeys.DATA_TYPE_XSD_STRING
            + ConfigKeys.DELIMITER_COLUMN_TYPE + ConfigKeys.COLUMN_XPK_ROW_LENGTH);

    // 1. foreign key
    tableColumns.add(ConfigKeys.COLUMN_FK_ROW + ConfigKeys.DELIMITER_COLUMN_TYPE + ConfigKeys.DATA_TYPE_XSD_NUMERIC);

    // 2. field value
    tableColumns.add(fieldShortName + ConfigKeys.DELIMITER_COLUMN_TYPE + fieldDataType + fieldFormat
            + ConfigKeys.DELIMITER_COLUMN_TYPE + fieldInputLength);
    // 3. attributes
    if (groupAttrMap != null) {
        Iterator<String> attrIter = groupAttrMap.keySet().iterator();
        while (attrIter.hasNext()) {
            Element attr = (Element) groupAttrMap.get(attrIter.next());
            tableColumns.add(attr.getAttribute(ConfigKeys.ATTR_NAME) + ConfigKeys.DELIMITER_COLUMN_TYPE
                    + ConfigKeys.DATA_TYPE_XSD_NUMERIC);
        }
    }

    multiValueTablesSQL.put(sub_table_prefix.getText() + fieldShortName, constructMultiValueTableSQL(
            sub_table_prefix.getText() + fieldShortName, tableColumns));

    // add the element to it's parent group children
    parentGroupElement.addChild(new XSDElement(fieldShortName, fieldColumnName));

    appLogger.debug("finished processing element [" + elementName + "].");
}

/**
 * write resulted files
 *
 * @param xsdDoc
 * @param docPath
 */
private void writeResults(Document xsdDoc, String resultsDir, String newXSDFileName, String csvFileName) {
    String rsDir = resultsDir + File.separator + new SimpleDateFormat("yyyyMMdd-HHmm").format(new Date());
    try {
        File resultsDirFile = new File(rsDir);
        if (!resultsDirFile.exists()) {
            resultsDirFile.mkdirs();
        }

        // write the XSD doc
        appLogger.info("writing the transformed XSD...");
        Source source = new DOMSource(xsdDoc);
        Result result = new StreamResult(rsDir + File.separator + newXSDFileName);
        Transformer xformer = TransformerFactory.newInstance().newTransformer();
        // xformer.setOutputProperty("indent", "yes");
        xformer.transform(source, result);
        appLogger.info("finished writing the transformed XSD.");

        // write the CSV columns file
        appLogger.info("writing the CSV file...");
        FileWriter csvWriter = new FileWriter(rsDir + File.separator + csvFileName);
        csvWriter.write(columnsCSV.toString());
        csvWriter.close();
        appLogger.info("finished writing the CSV file.");

        // write the master single-value table
        appLogger.info("writing the creation script for master table (single-values)...");
        FileWriter masterTableWriter = new FileWriter(rsDir + File.separator
                + main_edh_table_name.getText() + ".sql");
        masterTableWriter.write(constructSingleValueTableSQL(main_edh_table_name.getText(),
                singleValueTableColumns));
        masterTableWriter.close();
        appLogger.info("finished writing the creation script for master table (single-values).");

        // write the multi-value tables sql
        appLogger.info("writing the creation script for slave tables (multi-values)...");
        Iterator<String> iter = multiValueTablesSQL.keySet().iterator();
        while (iter.hasNext()) {
            String tableName = iter.next();
            String sql = multiValueTablesSQL.get(tableName);
            FileWriter tableSQLWriter = new FileWriter(rsDir + File.separator + tableName + ".sql");
            tableSQLWriter.write(sql);
            tableSQLWriter.close();
        }
        appLogger.info("finished writing the creation script for slave tables (multi-values).");

        // write the single-value view
        appLogger.info("writing the creation script for single-value selection view...");
        FileWriter singleValueViewWriter = new FileWriter(rsDir + File.separator
                + view_name_single.getText() + ".sql");
        singleValueViewWriter.write(constructViewSQL(ConfigKeys.SQL_VIEW_SINGLE));
        singleValueViewWriter.close();
        appLogger.info("finished writing the creation script for single-value selection view.");

        // debug
        for (int i = 0; i < xsdElementsList.size(); i++) {
            getMultiView(xsdElementsList.get(i));

/*// if (xsdElementsList.get(i).getAllDescendants() != null) { // for (int j = 0; j < xsdElementsList.get(i).getAllDescendants().size(); j++) { // appLogger.debug(main_edh_table_name.getText() + "." + ConfigKeys.COLUMN_XPK_ROW // + "=" + xsdElementsList.get(i).getAllDescendants().get(j).getName() + "." + ConfigKeys.COLUMN_FK_ROW); // } // } */ } } catch (Exception e) { appLogger.error(e.getMessage()); } }

private String getMultiView(XSDElement element)

© Stack Overflow or respective owner

Related posts about java