Package org.apache.ws.notification.base.impl

Source Code of org.apache.ws.notification.base.impl.XmlBeansTopicExpression

/*=============================================================================*
*  Copyright 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.ws.notification.base.impl;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.Soap1_1Constants;
import org.apache.ws.XmlObjectWrapper;
import org.apache.ws.notification.topics.expression.InvalidTopicExpressionException;
import org.apache.ws.notification.topics.expression.TopicExpression;
import org.apache.ws.resource.faults.FaultException;
import org.apache.ws.resource.i18n.Keys;
import org.apache.ws.resource.i18n.MessagesImpl;
import org.apache.ws.resource.properties.query.impl.XmlBeansQueryExpression;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.ws.util.i18n.Messages;
import org.apache.ws.util.xml.impl.XmlBeansNamespaceContext;
import org.apache.xmlbeans.XmlObject;
import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionType;
import javax.xml.rpc.JAXRPCException;
import java.net.URI;
import java.net.URISyntaxException;

/**
* A TopicExpression impl that wraps a TopicExpressionType XMLBean.
*
* @author Ian Springer
*/
public class XmlBeansTopicExpression
   implements TopicExpression,
              XmlObjectWrapper
{
   private static final Log     LOG = LogFactory.getLog( XmlBeansQueryExpression.class );

   /** DOCUMENT_ME */
   public static final Messages MSG = MessagesImpl.getInstance(  );
   private XmlObject            m_topicExprXBean;
   private URI                  m_dialect;
   private Object               m_content;
   private Object               m_nsContext;

   /**
    * Creates a new {@link XmlBeansTopicExpression} object.
    *
    * @param topicExprXBean DOCUMENT_ME
    *
    * @throws JAXRPCException          DOCUMENT_ME
    */
   public XmlBeansTopicExpression( TopicExpressionType topicExprXBean )
   throws InvalidTopicExpressionException
   {
      this( topicExprXBean,
            getDialect( topicExprXBean ) );
   }

   /**
    * Creates a new {@link XmlBeansTopicExpression} object.
    *
    * @param xBean DOCUMENT_ME
    * @param dialect DOCUMENT_ME
    *
    * @throws InvalidTopicExpressionException DOCUMENT_ME
    */
   protected XmlBeansTopicExpression( XmlObject xBean,
                                      URI       dialect )
   throws InvalidTopicExpressionException
   {
      m_topicExprXBean    = xBean;
      m_dialect           = dialect;
      XmlObject[] childElems = XmlBeanUtils.getChildElements( m_topicExprXBean );
      if ( childElems.length > 1 )
      {
         throw new InvalidTopicExpressionException( MSG.getMessage( Keys.QUERY_ONLY_ONE_NODE ) );
      }

      if ( childElems.length == 1 )
      {
         m_content = childElems[0];
      }
      else
      {
         m_content = XmlBeanUtils.getValue( m_topicExprXBean );
      }

      m_nsContext = new XmlBeansNamespaceContext( m_topicExprXBean );
      if ( LOG.isDebugEnabled(  ) )
      {
         LOG.debug( MSG.getMessage( Keys.QUERY_EXPR,
                                    toString(  ) ) );
      }
   }

   /**
    * DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   public Object getContent(  )
   {
      return m_content;
   }

   /**
    * DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   public URI getDialect(  )
   {
      return m_dialect;
   }

   /**
    * DOCUMENT_ME
    *
    * @param nsContext DOCUMENT_ME
    */
   public void setNamespaceContext( Object nsContext )
   {
      m_nsContext = nsContext;
   }

   /**
    * DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   public Object getNamespaceContext(  )
   {
      return m_nsContext;
   }

   /**
    * DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   public XmlObject getXmlObject(  )
   {
      return m_topicExprXBean;
   }

   /**
    * DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   public String toString(  )
   {
      return new ToStringBuilder( this ).append( MSG.getMessage( Keys.DIALECT ),
                                                 m_dialect ).append( MSG.getMessage( Keys.CONTENT ),
                                                                     m_content ).toString(  );
   }

   private static URI getDialect( TopicExpressionType topicExprElem )
   {
      if ( !topicExprElem.isSetDialect(  ) )
      {
         throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
                                   "The Dialect attribute is required by the WS-BaseNotification TopicExpressionType." );
      }

      try
      {
         return new URI( topicExprElem.getDialect(  ) );
      }
      catch ( URISyntaxException urise )
      {
         throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
                                   "The Dialect attribute of the WS-BaseNotification TopicExpressionType must be a valid URI." );
      }
   }
}
TOP

Related Classes of org.apache.ws.notification.base.impl.XmlBeansTopicExpression

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.