/*=============================================================================*
* 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.events.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.XmlUtils;
import org.apache.muse.ws.dm.muws.events.Component;
import org.apache.muse.ws.dm.muws.events.ComponentAddress;
import org.apache.muse.ws.dm.muws.events.WefConstants;
import org.apache.muse.ws.dm.muws.events.WefFactory;
/**
*
* @author Dan Jemiolo (danj)
*
*/
public class SimpleComponent
extends AbstractExtendedElements implements Component
{
//
// used to lookup all exception messages
//
private static Messages _MESSAGES = MessagesFactory.get(SimpleComponent.class);
private ComponentAddress _address = null;
private QName _name = null;
private String _resourceID = null;
public SimpleComponent()
{
//
// no default action - allow people to create "blank"
// components and validate in toXML()
//
}
public SimpleComponent(Element xml, WefFactory factory)
{
_name = XmlUtils.getElementQName(xml);
Element addressXML = XmlUtils.getElement(xml, WefConstants.COMP_ADDRESS_QNAME);
_address = factory.createComponentAddress(addressXML);
}
public ComponentAddress getAddress()
{
return _address;
}
public QName getName()
{
return _name;
}
public String getResourceID()
{
return _resourceID;
}
public void setAddress(ComponentAddress address)
{
_address = address;
}
public void setName(QName name)
{
_name = name;
}
public void setResourceID(String resourceID)
{
_resourceID = resourceID;
}
public String toString()
{
return XmlUtils.toString(toXML(), false);
}
public Element toXML()
{
return toXML(XmlUtils.EMPTY_DOC);
}
public Element toXML(Document factory)
{
QName name = getName();
if (name == null)
throw new RuntimeException(_MESSAGES.get("NoComponentName"));
Element componentXML = XmlUtils.createElement(factory, name);
ComponentAddress address = getAddress();
if (address != null)
{
Element addressXML = address.toXML(factory);
componentXML.appendChild(addressXML);
}
String resourceID = getResourceID();
if (resourceID != null)
XmlUtils.setElement(componentXML, WefConstants.RESOURCE_ID_QNAME, resourceID);
appendExtendedElements(componentXML);
return componentXML;
}
}