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: * CustomTagSerializer
022: * LPS
023: * Sep 19, 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 CustomTagSerializer implements ExtensionSerializer,
050: ExtensionDeserializer, Serializable {
051: private static final long serialVersionUID = 8429822588981321108L;
052:
053: /**
054: *
055: */
056: public CustomTagSerializer() {
057: }
058:
059: public void marshall(Class parentType, QName elementType,
060: ExtensibilityElement extension, PrintWriter pw,
061: Definition def, ExtensionRegistry extReg)
062: throws WSDLException {
063: CustomTagExtension config = (CustomTagExtension) extension;
064: if (config != null) {
065: String tagName = DOMUtils.getQualifiedValue(config
066: .getElementType().getNamespaceURI(), elementType
067: .getLocalPart(), def);
068: pw.print(" <" + tagName);
069:
070: for (Object attrName : config.getAttributes().keySet()) {
071: DOMUtils.printAttribute((String) attrName,
072: config.getAttributes().getProperty(
073: (String) attrName), pw);
074: }
075: ;
076:
077: Boolean required = config.getRequired();
078:
079: if (required != null) {
080: DOMUtils.printQualifiedAttribute(
081: Constants.Q_ATTR_REQUIRED, required.toString(),
082: def, pw);
083: }
084:
085: pw.println("/>");
086: }
087: }
088:
089: @SuppressWarnings("unchecked")
090: public ExtensibilityElement unmarshall(Class parentType,
091: QName elementType, Element el, Definition def,
092: ExtensionRegistry extReg) throws WSDLException {
093: CustomTagExtension config = (CustomTagExtension) extReg
094: .createExtension(parentType, elementType);
095:
096: Properties prop = new Properties();
097:
098: List<Node> attributes = DOMUtils.getAttributes(el);
099: for (Node node : attributes) {
100: prop.setProperty(node.getNodeName(), node.getNodeValue());
101: }
102: config.addAttributes(prop);
103: return config;
104: }
105:
106: }
|