Package org.apache.ws.notification.tool

Source Code of org.apache.ws.notification.tool.WsnWsdl2Java

/*=============================================================================*
*  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.tool;

import org.apache.velocity.VelocityContext;
import org.apache.ws.notification.base.v2004_06.impl.WsnNamespaceVersionHolderImpl;
import org.apache.ws.notification.base.v2004_06.porttype.NotificationProducerPortType;
import org.apache.ws.notification.tool.v2004_06.NotificationConsumerPortType2JavaInfo;
import org.apache.ws.notification.tool.v2004_06.NotificationProducerPortType2JavaInfo;
import org.apache.ws.notification.tool.v2004_06.SubscriptionManagerPortType2JavaInfo;
import org.apache.ws.resource.ResourceDefinition;
import org.apache.ws.resource.tool.Wsdl2Java;
import org.apache.ws.resource.tool.velocity.ServiceProperties;
import java.io.File;

/**
* Generates Java Web service types and skeletons from a WSRF/WSN WSDL.
*
* @author Ian Springer (ian DOT springer AT hp DOT com)
*/
public class WsnWsdl2Java
   extends Wsdl2Java
{
   private static final String VCTY_CTX_PROP_CHANGE          = "propChange";
   private static final String VCTY_CTX_RESOURCE_TERMINATION = "resourceTermination";
   private static final String VCTY_CTX_NOTIF_PRODUCER       = "notificationProducer";

   /** DOCUMENT_ME */
   protected String WEBAPP_NAME = "pubscribe";

   /**
    * Creates a new {@link WsnWsdl2Java} object.
    *
    * @param wsdlFiles DOCUMENT_ME
    * @param outputDir DOCUMENT_ME
    * @param classpath DOCUMENT_ME
    * @param options DOCUMENT_ME
    *
    * @throws Exception DOCUMENT_ME
    */
   public WsnWsdl2Java( File[]           wsdlFiles,
                        File             outputDir,
                        File[]           classpath,
                        Wsdl2JavaOptions options )
   throws Exception
   {
      super( wsdlFiles, outputDir, classpath, options );
      initPortTypeInfoMap(  );
   }

   /**
    * Returns the name of the webapp for use in generating code.
    *
    * @return the webapp name.
    */
   protected String getWebbappName(  )
   {
      return WEBAPP_NAME;
   }

   /**
    * Adds to the {@link ServiceProperties} object by making a call to super and
    * then adding anything impl specific to be used by the VelocityContext for code generation.
    *
    * {@see Wsdl2Java#buildServiceProperties(ResourceDefinition resourceDefinition, File wsdlfile, File servicedir)}
    *
    * @param resourceDefinition  The definition we are working on.
    * @param wsdlfile  The wsdl file.
    * @param servicedir The directory we are generating to for this service.
    * @return the updated ServiceProperties
    */
   protected ServiceProperties buildServiceProperties( ResourceDefinition resourceDefinition,
                                                       File               wsdlfile,
                                                       File               servicedir )
   {
      ServiceProperties serviceProperties =
         super.buildServiceProperties( resourceDefinition, wsdlfile, servicedir );
      serviceProperties.setNamespaceVersionHolder( WsnNamespaceVersionHolderImpl.class ); //make sure to add different ones as new versions comeout

      //tell service props which properties we handle for the user...
      if ( hasNotificationProducer( resourceDefinition ) )
      {
         serviceProperties.addImplementedProperty( NotificationProducerPortType.PROP_QNAME_FIXED_TOPIC_SET );
         serviceProperties.addImplementedProperty( NotificationProducerPortType.PROP_QNAME_TOPIC );
         serviceProperties.addImplementedProperty( NotificationProducerPortType.PROP_QNAME_TOPIC_EXPRESSION_DIALECTS );
      }

      return serviceProperties;
   }

   /**
    * Provides a hook for adding directly to the Velocity Context.
    *
    * @param context
    * @return VelocityContext
    */
   protected VelocityContext updateVelocityContext( VelocityContext    context,
                                                    ResourceDefinition resourceDef )
   {
      VelocityContext velocityContext = super.updateVelocityContext( context, resourceDef );
      if ( hasPropChange( resourceDef ) )
      {
         velocityContext.put( VCTY_CTX_PROP_CHANGE, "true" );
      }

      if ( hasResourceTermination( resourceDef ) )
      {
         velocityContext.put( VCTY_CTX_RESOURCE_TERMINATION, "true" );
      }

      if ( hasNotificationProducer( resourceDef ) )
      {
         velocityContext.put( VCTY_CTX_NOTIF_PRODUCER, "true" );
      }

      return velocityContext;
   }

   private boolean hasNotificationProducer( ResourceDefinition resourceDef )
   {
      return resourceDef.implementsResourceCapability( org.apache.ws.notification.base.v2004_06.porttype.NotificationProducerPortType.NAME );
   }

   private boolean hasPropChange( ResourceDefinition resourceDef )
   {
      if ( resourceDef.implementsResourceCapability( org.apache.ws.resource.properties.v2004_06.porttype.SetResourcePropertiesPortType.NAME )
           || resourceDef.implementsResourceCapability( org.apache.ws.resource.properties.v2004_11.porttype.DeleteResourcePropertiesPortType.NAME )
           || resourceDef.implementsResourceCapability( org.apache.ws.resource.properties.v2004_11.porttype.InsertResourcePropertiesPortType.NAME )
           || resourceDef.implementsResourceCapability( org.apache.ws.resource.properties.v2004_11.porttype.SetResourcePropertiesPortType.NAME )
           || resourceDef.implementsResourceCapability( org.apache.ws.resource.properties.v2004_11.porttype.UpdateResourcePropertiesPortType.NAME ) )
      {
         return true;
      }

      return false;
   }

   private boolean hasResourceTermination( ResourceDefinition resourceDef )
   {
      if ( resourceDef.implementsResourceCapability( org.apache.ws.resource.lifetime.v2004_06.porttype.ImmediateResourceTerminationPortType.NAME )
           || resourceDef.implementsResourceCapability( org.apache.ws.resource.lifetime.v2004_06.porttype.ScheduledResourceTerminationPortType.NAME )
           || resourceDef.implementsResourceCapability( org.apache.ws.resource.lifetime.v2004_11.porttype.ImmediateResourceTerminationPortType.NAME )
           || resourceDef.implementsResourceCapability( org.apache.ws.resource.lifetime.v2004_11.porttype.ScheduledResourceTerminationPortType.NAME ) )
      {
         return true;
      }

      return false;
   }

   private void initPortTypeInfoMap(  )
   {
      addPortType2JavaInfo( new NotificationConsumerPortType2JavaInfo(  ) );
      addPortType2JavaInfo( new NotificationProducerPortType2JavaInfo(  ) );
      addPortType2JavaInfo( new SubscriptionManagerPortType2JavaInfo(  ) );
   }
}
TOP

Related Classes of org.apache.ws.notification.tool.WsnWsdl2Java

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.