001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License as published by
009: * the Free Software Foundation; either version 2 of the License, or
010: * (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307
020: * USA
021: *
022: * $Id: ConversionUtil.java 6998 2007-04-24 01:13:00Z jzhang $
023: *
024: */
025: package com.bostechcorp.cbesb.ui.util.version;
026:
027: import java.util.List;
028:
029: import org.jdom.Attribute;
030: import org.jdom.Element;
031:
032: /**
033: *
034: */
035: public class ConversionUtil {
036:
037: public static final String CONSUMER = "consumer";
038: public static final String PROVIDER = "provider";
039:
040: public static void convertAttribute(Element element,
041: Element newElement) {
042: if (element != null) {
043: List attributes = element.getAttributes();
044: for (int i = 0; i < attributes.size(); i++) {
045: Attribute attribute = (Attribute) attributes.get(i);
046: newElement.setAttribute(attribute.getName(), attribute
047: .getValue(), attribute.getNamespace());
048: }
049: }
050: }
051:
052: public static Element createCCSL(String type, Element element) {
053: Element ccsl;
054: Element upoc = new Element("upoc");
055: Element presend = new Element("Presend");
056: Element postsend = new Element("Postsend");
057: Element postaccept = new Element("Postaccept");
058: String upocName;
059: if (CONSUMER.equals(type)) {
060: ccsl = new Element("consumerCCSL");
061: upocName = "consumerUpoc";
062: } else {
063: ccsl = new Element("providerCCSL");
064: upocName = "providerUpoc";
065: }
066: if (element != null) {
067: convertAttribute(element.getChild(upocName).getChild(
068: "Presend"), presend);
069: convertAttribute(element.getChild(upocName).getChild(
070: "Postsend"), postsend);
071: convertAttribute(element.getChild(upocName).getChild(
072: "Postaccept"), postaccept);
073: convertAttribute(element.getChild(upocName), upoc);
074: convertAttribute(element, ccsl);
075: }
076: upoc.addContent(presend);
077: upoc.addContent(postsend);
078: upoc.addContent(postaccept);
079: ccsl.addContent(upoc);
080:
081: return ccsl;
082: }
083:
084: public static Element convertCCSL(String type, Element element,
085: String upocName) {
086: Element ccsl;
087: Element upoc = new Element("upoc");
088: Element presend = new Element("Presend");
089: Element postsend = new Element("Postsend");
090: Element postaccept = new Element("Postaccept");
091: if (CONSUMER.equals(type)) {
092: ccsl = new Element("consumerCCSL");
093: } else {
094: ccsl = new Element("providerCCSL");
095: }
096: if (element != null) {
097: convertAttribute(element.getChild(upocName)
098: .getChild("upoc").getChild("Presend"), presend);
099: convertAttribute(element.getChild(upocName)
100: .getChild("upoc").getChild("Postsend"), postsend);
101: convertAttribute(element.getChild(upocName)
102: .getChild("upoc").getChild("Postaccept"),
103: postaccept);
104: convertAttribute(element.getChild(upocName)
105: .getChild("upoc"), upoc);
106: convertAttribute(element.getChild(upocName), ccsl);
107: }
108: upoc.addContent(presend);
109: upoc.addContent(postsend);
110: upoc.addContent(postaccept);
111: ccsl.addContent(upoc);
112: return ccsl;
113: }
114: }
|