/*=============================================================================*
* Copyright 2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*=============================================================================*/
package org.apache.muse.ws.dm.muws.impl;
import javax.xml.namespace.QName;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.muse.util.messages.Messages;
import org.apache.muse.util.messages.MessagesFactory;
import org.apache.muse.util.xml.XmlSerializable;
import org.apache.muse.util.xml.XmlUtils;
import org.apache.muse.ws.addressing.soap.SoapFault;
import org.apache.muse.ws.dm.muws.MuwsConstants;
/**
*
* QueryRelationships is a serializer/deserializer for the MUWS (Part 2)
* QueryRelationshipsByType operation's request content.
*
* @author Dan Jemiolo (danj)
*
*/
public class QueryRelationships implements XmlSerializable
{
private static Messages _MESSAGES = MessagesFactory.get(QueryRelationships.class);
private QName[] _types = null;
public QueryRelationships(Element xml)
throws SoapFault
{
Element[] children = XmlUtils.getElements(xml, MuwsConstants.REQUESTED_TYPE_QNAME);
if (children.length == 0)
throw new SoapFault(_MESSAGES.get("NoRequestedTypes"));
_types = new QName[children.length];
for (int n = 0; n < children.length; ++n)
_types[n] = XmlUtils.getQName(children[n]);
}
public QueryRelationships(QName[] types)
{
if (types == null)
throw new NullPointerException(_MESSAGES.get("NullQNameArray"));
if (types.length == 0)
throw new IllegalArgumentException(_MESSAGES.get("NoRequestedTypes"));
_types = types;
}
public QName[] getTypes()
{
return _types;
}
public Element toXML()
{
return toXML(XmlUtils.EMPTY_DOC);
}
public Element toXML(Document factory)
{
if (factory == null)
throw new NullPointerException(_MESSAGES.get("NullDocument"));
QName qname = MuwsConstants.QUERY_RELATIONSHIPS_QNAME;
Element root = XmlUtils.createElement(factory, qname);
QName[] types = getTypes();
qname = MuwsConstants.REQUESTED_TYPE_QNAME;
for (int n = 0; n < types.length; ++n)
{
Element next = XmlUtils.createElement(factory, qname, types[n]);
root.appendChild(next);
}
return root;
}
}