/*
* Copyright 2001-2004 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.juddi.handler;
import java.util.Vector;
import org.apache.juddi.datatype.Name;
import org.apache.juddi.datatype.RegistryObject;
import org.apache.juddi.datatype.response.ServiceInfo;
import org.apache.juddi.util.xml.XMLUtils;
import org.w3c.dom.Element;
/**
* ServiceInfoHandler
*
* @author Steve Viens (sviens@apache.org)
* @author Anou Mana (anou_mana@users.sourceforge.net)
*/
public class ServiceInfoHandler extends AbstractHandler
{
public static final String TAG_NAME = "serviceInfo";
private HandlerMaker maker = null;
protected ServiceInfoHandler(HandlerMaker maker)
{
this.maker = maker;
}
public RegistryObject unmarshal(Element element)
{
ServiceInfo obj = new ServiceInfo();
Vector nodeList = null;
AbstractHandler handler = null;
// Attributes
obj.setServiceKey(element.getAttribute("serviceKey"));
obj.setBusinessKey(element.getAttribute("businessKey"));
// Text Node Value
// {none}
// Child Elements
nodeList = XMLUtils.getChildElementsByTagName(element,NameHandler.TAG_NAME);
for (int i=0; i<nodeList.size(); i++)
{
handler = maker.lookup(NameHandler.TAG_NAME);
Name name = (Name )handler.unmarshal((Element)nodeList.elementAt(i));
if (name != null)
obj.addName(name);
}
return obj;
}
public void marshal(RegistryObject object,Element parent)
{
ServiceInfo info = (ServiceInfo)object;
String generic = getGeneric(null);
String namespace = getUDDINamespace(generic);
Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
AbstractHandler handler = null;
// required attribute
String serviceKey = info.getServiceKey();
element.setAttribute("serviceKey",(serviceKey != null) ? serviceKey : "");
// required attribute
String businessKey = info.getBusinessKey();
element.setAttribute("businessKey",(businessKey != null) ? businessKey : "");
Vector vector = info.getNameVector();
if ((vector!=null) && (vector.size() > 0))
{
handler = maker.lookup(NameHandler.TAG_NAME);
for (int i=0; i < vector.size(); i++)
handler.marshal((Name)vector.elementAt(i),element);
}
parent.appendChild(element);
}
/***************************************************************************/
/***************************** TEST DRIVER *********************************/
/***************************************************************************/
public static void main(String args[])
throws Exception
{
}
}