Package org.apache.muse.ws.resource.properties.query.impl

Source Code of org.apache.muse.ws.resource.properties.query.impl.QueryRequest

/*=============================================================================*
*  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.resource.properties.query.impl;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import org.apache.muse.util.messages.Messages;
import org.apache.muse.util.messages.MessagesFactory;
import org.apache.muse.ws.resource.ext.faults.InvalidMessageFormatFault;
import org.apache.muse.ws.resource.properties.WsrpConstants;
import org.apache.muse.util.xml.XmlSerializable;
import org.apache.muse.util.xml.XmlUtils;

/**
*
* QueryRequest is a serializer/deserializer for the WS-ResourceProperties
* QueryResourceProperties operation's request content.
*
* @author Dan Jemiolo (danj)
*
*/

public class QueryRequest implements XmlSerializable
{
    //
    // Used to lookup all exception messages
    //
    private static Messages _MESSAGES = MessagesFactory.get(QueryRequest.class);
   
    //
    // The language of the query string
    //
    private String _dialect = null;
   
    //
    // The query to run against the WS-RP doc
    //
    private String _query = null;
   
    public QueryRequest(Element request)
        throws InvalidMessageFormatFault
    {
        if (request == null)
            throw new NullPointerException(_MESSAGES.get("NullRequestElement"));
       
        Element expression =
            XmlUtils.getElement(request, WsrpConstants.QUERY_EXPRESSION_QNAME);
       
        if (expression == null)
            throw new InvalidMessageFormatFault(_MESSAGES.get("NoQueryExpressionFound"));
       
        _dialect = expression.getAttribute(WsrpConstants.DIALECT);
       
        if (_dialect == null || _dialect.length() == 0)
            throw new InvalidMessageFormatFault(_MESSAGES.get("NoDialectFound"));
       
        _query = XmlUtils.extractText(expression);
       
        if (_query == null)
            throw new InvalidMessageFormatFault(_MESSAGES.get("NoQueryFound"));
    }
   
    public QueryRequest(String query, String dialect)
    {
        if (query == null)
            throw new NullPointerException(_MESSAGES.get("NullQuery"));
       
        if (dialect == null)
            throw new NullPointerException(_MESSAGES.get("NullDialect"));
       
        _query = query;
        _dialect = dialect;
    }

    public String getDialect()
    {
        return _dialect;
    }
   
    public String getQuery()
    {
        return _query;
    }
   
    public String toString()
    {
        return XmlUtils.toString(toXML(), false);
    }
   
    public Element toXML()
    {
        return toXML(XmlUtils.EMPTY_DOC);
    }
   
    public Element toXML(Document doc)
    {
        if (doc == null)
            throw new NullPointerException(_MESSAGES.get("NullDocument"));
       
        Element root = XmlUtils.createElement(doc, WsrpConstants.QUERY_QNAME);
       
        Element query =
            XmlUtils.createElement(doc, WsrpConstants.QUERY_EXPRESSION_QNAME);
        root.appendChild(query);
       
        query.setAttribute(WsrpConstants.DIALECT, getDialect());
       
        Node text = doc.createTextNode(getQuery());
        query.appendChild(text);
       
        return root;
    }
}
TOP

Related Classes of org.apache.muse.ws.resource.properties.query.impl.QueryRequest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.