Package org.apache.ws.notification.topics.expression.impl

Source Code of org.apache.ws.notification.topics.expression.impl.SimpleTopicExpressionEvaluator

/*=============================================================================*
*  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.topics.expression.impl;

import org.apache.ws.notification.topics.Topic;
import org.apache.ws.notification.topics.TopicSpace;
import org.apache.ws.notification.topics.TopicSpaceSet;
import org.apache.ws.notification.topics.expression.InvalidTopicExpressionException;
import org.apache.ws.notification.topics.expression.TopicExpression;
import org.apache.ws.notification.topics.expression.TopicExpressionEvaluator;
import org.apache.ws.notification.topics.expression.TopicExpressionException;
import org.apache.ws.notification.topics.expression.TopicExpressionResolutionException;
import org.apache.ws.notification.topics.expression.TopicPathDialectUnknownException;
import org.apache.ws.notification.topics.expression.impl.AbstractTopicExpressionEvaluator;
import org.apache.ws.notification.topics.v2004_06.TopicsConstants;
import org.apache.ws.util.xml.NamespaceContext;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;

/**
* Topic expression evalutor for the WS-Topics "Simple" topic dialect.
*
* @see org.apache.ws.notification.topics.expression.TopicExpressionEvaluator
*
* @author Ian Springer (ian DOT springer AT hp DOT com)
*/
public class SimpleTopicExpressionEvaluator
   extends AbstractTopicExpressionEvaluator
{
   //private static final Log LOG = LogFactory.getLog(SimpleTopicExpressionEvaluator.class.getName());
   private static final String[] SUPPORTED_DIALECTS =
                                                      {
                                                         TopicsConstants.TOPIC_EXPR_DIALECT_SIMPLE
                                                      };

   /**
    * DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   public String[] getDialects(  )
   {
      return SUPPORTED_DIALECTS;
   }

   /**
    * DOCUMENT_ME
    *
    * @param topicSpaceSet DOCUMENT_ME
    * @param topicExpr DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    *
    * @throws TopicPathDialectUnknownException DOCUMENT_ME
    * @throws TopicExpressionResolutionException DOCUMENT_ME
    * @throws InvalidTopicExpressionException DOCUMENT_ME
    * @throws TopicExpressionException DOCUMENT_ME
    */
   public Topic[] evaluate( TopicSpaceSet   topicSpaceSet,
                            TopicExpression topicExpr )
   throws TopicPathDialectUnknownException,
          TopicExpressionResolutionException,
          InvalidTopicExpressionException,
          TopicExpressionException
   {
      String           expr          = getContent( topicExpr );
      NamespaceContext nsContext     = getNamespaceContext( topicExpr );
      QName            topicPath     = toQName( expr, nsContext );
      List             matchedTopics = evaluateTopicPath( topicSpaceSet, topicPath );
      return (Topic[]) matchedTopics.toArray( new Topic[0] );
   }

   private List evaluateTopicPath( TopicSpaceSet topicSpaceSet,
                                   QName         topicPath )
   throws TopicExpressionResolutionException,
          InvalidTopicExpressionException
   {
      List       matchedTopics = new ArrayList(  );
      TopicSpace topicSpace = getTopicSpace( topicSpaceSet, topicPath );
      if ( ( topicPath.getLocalPart(  ).indexOf( "/" ) != -1 )
           || ( topicPath.getLocalPart(  ).indexOf( "*" ) != -1 )
           || ( topicPath.getLocalPart(  ).indexOf( "|" ) != -1 )
           || ( topicPath.getLocalPart(  ).indexOf( "." ) != -1 ) )
      {
         throw new InvalidTopicExpressionException( "Topic path '" + topicPath
                                                    + "' contains one or more illegal characters ('/', '*', '|' or '.')." );
      }

      String name  = topicPath.getLocalPart(  );
      Topic  topic = topicSpace.getTopic( name );
      if ( topic != null )
      {
         matchedTopics.add( topic );
      }

      return matchedTopics;
   }
}
TOP

Related Classes of org.apache.ws.notification.topics.expression.impl.SimpleTopicExpressionEvaluator

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.