/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.resource.properties.set.impl;
import javax.xml.namespace.QName;
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.resource.basefaults.BaseFault;
import org.apache.muse.ws.resource.ext.faults.InvalidMessageFormatFault;
import org.apache.muse.ws.resource.properties.WsrpConstants;
import org.apache.muse.ws.resource.properties.set.SetOperationFactory;
import org.apache.muse.ws.resource.properties.set.SetRequest;
import org.apache.muse.ws.resource.properties.set.SetRequestComponent;
/**
*
* SimpleSetOperationFactory provides an API for constructing and parsing WS-RP
* SetResourceProperties requests, including the Insert, Delete, and Update
* operations. There are convenience methods for creating outbound requests with
* each operation type as well as a factory method for parsing inbound XML into
* executables.
*
* @author Dan Jemiolo (danj)
*
*/
public class SimpleSetOperationFactory implements SetOperationFactory
{
//
// Used to lookup all exception messages
//
private static Messages _MESSAGES = MessagesFactory.get(SimpleSetOperationFactory.class);
public SetRequest createDelete(QName qname)
{
SetRequest set = new SimpleSetRequest();
set.addRequestComponent(new DeleteRequest(qname));
return set;
}
public SetRequest createInsert(QName qname, Object[] values)
{
SetRequest set = new SimpleSetRequest();
set.addRequestComponent(new InsertRequest(qname, values));
return set;
}
public SetRequest createSet(Element request)
throws BaseFault
{
if (request == null)
throw new NullPointerException(_MESSAGES.get("NullRequestElement"));
Element[] children = XmlUtils.getAllElements(request, WsrpConstants.NAMESPACE_URI);
if (children.length == 0)
throw new InvalidMessageFormatFault(_MESSAGES.get("EmptySetRequest"));
SetRequest set = new SimpleSetRequest();
//
// build the different types of sets from XML. don't bother with a
// table, we only have three command types
//
for (int n = 0; n < children.length; ++n)
{
String type = children[n].getLocalName();
SetRequestComponent operation = null;
if (type.equals(DeleteRequest.OPERATION))
operation = new DeleteRequest(children[n]);
else if (type.equals(InsertRequest.OPERATION))
operation = new InsertRequest(children[n]);
else if (type.equals(UpdateRequest.OPERATION))
operation = new UpdateRequest(children[n]);
else
{
Object[] filler = { type };
throw new InvalidMessageFormatFault(_MESSAGES.get("InvalidSet", filler));
}
set.addRequestComponent(operation);
}
return set;
}
public SetRequest createUpdate(QName qname, Object[] values)
{
SetRequest set = new SimpleSetRequest();
set.addRequestComponent(new UpdateRequest(qname, values));
return set;
}
}