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 it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * 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 MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * ConfigSerializer
022: * LPS
023: * Sep 14, 2007
024: */package com.bostechcorp.cbesb.common.util.generators.wsdl.extensions;
025:
026: import java.io.PrintWriter;
027: import java.io.Serializable;
028: import java.util.List;
029: import java.util.Properties;
030:
031: import javax.wsdl.Definition;
032: import javax.wsdl.WSDLException;
033: import javax.wsdl.extensions.ExtensibilityElement;
034: import javax.wsdl.extensions.ExtensionDeserializer;
035: import javax.wsdl.extensions.ExtensionRegistry;
036: import javax.wsdl.extensions.ExtensionSerializer;
037: import javax.xml.namespace.QName;
038:
039: import org.w3c.dom.Element;
040: import org.w3c.dom.Node;
041:
042: import com.ibm.wsdl.Constants;
043: import com.ibm.wsdl.util.xml.DOMUtils;
044:
045: /**
046: * @author LPS
047: *
048: */
049: public class ConfigSerializer implements ExtensionSerializer,
050: ExtensionDeserializer, Serializable {
051:
052: private static final long serialVersionUID = 9176371648303572783L;
053:
054: /* (non-Javadoc)
055: * @see javax.wsdl.extensions.ExtensionSerializer#marshall(java.lang.Class, javax.xml.namespace.QName, javax.wsdl.extensions.ExtensibilityElement, java.io.PrintWriter, javax.wsdl.Definition, javax.wsdl.extensions.ExtensionRegistry)
056: */
057: public void marshall(Class parentType, QName elementType,
058: ExtensibilityElement extension, PrintWriter pw,
059: Definition def, ExtensionRegistry extReg)
060: throws WSDLException {
061: ConfigExtension config = (ConfigExtension) extension;
062: if (config != null) {
063: String tagName = DOMUtils.getQualifiedValue(config
064: .getElementType().getNamespaceURI(),
065: ConfigConstants.ELEM_CONFIG, def);
066: pw.print(" <" + tagName);
067:
068: for (Object attrName : config.getAttributes().keySet()) {
069: DOMUtils.printAttribute((String) attrName,
070: config.getAttributes().getProperty(
071: (String) attrName), pw);
072: }
073: ;
074:
075: Boolean required = config.getRequired();
076:
077: if (required != null) {
078: DOMUtils.printQualifiedAttribute(
079: Constants.Q_ATTR_REQUIRED, required.toString(),
080: def, pw);
081: }
082:
083: if (config.getTrxId() != null) {
084: pw.println(">");
085: TrxIdSerializer trxIdSerializer = new TrxIdSerializer();
086: trxIdSerializer.marshall(ConfigExtension.class,
087: TrxIdConstants.Q_ELEM_TRX_ID_NOPREFIX, config
088: .getTrxId(), pw, def, extReg);
089: pw.println("</" + tagName + ">");
090: } else {
091: pw.println("/>");
092: }
093:
094: }
095: }
096:
097: @SuppressWarnings("unchecked")
098: public ExtensibilityElement unmarshall(Class parentType,
099: QName elementType, Element el, Definition def,
100: ExtensionRegistry extReg) throws WSDLException {
101: ConfigExtension config = (ConfigExtension) extReg
102: .createExtension(parentType, elementType);
103:
104: Properties prop = new Properties();
105:
106: List<Node> attributes = DOMUtils.getAttributes(el);
107: for (Node node : attributes) {
108: prop.setProperty(node.getNodeName(), node.getNodeValue());
109: }
110: config.addAttributes(prop);
111: return config;
112: }
113:
114: }
|