/*=============================================================================*
* 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.v2004_06.impl;
import org.apache.commons.collections.map.ReferenceMap;
import org.apache.ws.addressing.EndpointReference;
import org.apache.ws.notification.base.Subscription;
import org.apache.ws.notification.base.WsnNamespaceVersionHolder;
import org.apache.ws.notification.topics.expression.TopicExpression;
import org.apache.ws.resource.JndiConstants;
import org.apache.ws.resource.ResourceException;
import org.apache.ws.resource.impl.AbstractResourceHome;
import org.apache.ws.resource.properties.NamespaceVersionHolder;
import org.apache.ws.resource.properties.query.QueryExpression;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.xml.namespace.QName;
import java.lang.reflect.Constructor;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* The home for the builtin SubscriptionManager service.
*/
public class SubscriptionHome
extends AbstractResourceHome
{
/**
* The service endpoint name as registered with the SOAP Platform. This is useful for building EPR's. *
*/
public static final javax.xml.namespace.QName SERVICE_NAME =
javax.xml.namespace.QName.valueOf( "{http://ws.apache.org/notification/base/service/SubscriptionManager}SubscriptionManager" );
/**
* The management PortType associated with this resource. This is useful for building EPR's.*
*/
public static final javax.xml.namespace.QName PORT_TYPE =
javax.xml.namespace.QName.valueOf( "{http://ws.apache.org/notification/base/service/SubscriptionManager}SubscriptionManagerPortType" );
/**
* The WSDL Port name associated with the resource. This is useful for building EPR's. *
*/
public static final String PORT_NAME = "SubscriptionManager";
/**
* The name of the resource key for this resource. *
*/
public static final javax.xml.namespace.QName RESOURCE_KEY_NAME =
javax.xml.namespace.QName.valueOf( "{http://ws.apache.org/notification/base/service/SubscriptionManager}ResourceID" );
/** DOCUMENT_ME */
public static final String HOME_LOCATION =
JndiConstants.CONTEXT_NAME_SERVICES + "/" + SERVICE_NAME.getLocalPart( ) + "/"
+ JndiConstants.ATOMIC_NAME_HOME;
private static final NamespaceVersionHolder SPEC_NAMESPACE_SET = new WsnNamespaceVersionHolderImpl( );
/**
* Map containing all FilesystemResource instances - this map <em>must</em> be static for
* compatibility with certain JNDI providers.
*/
private static Map s_resources;
/**
* DOCUMENT_ME
*
* @return DOCUMENT_ME
*/
public org.apache.ws.resource.properties.NamespaceVersionHolder getNamespaceVersionHolder( )
{
return SPEC_NAMESPACE_SET;
}
/**
* DOCUMENT_ME
*
* @return DOCUMENT_ME
*/
public QName getPortType( )
{
return PORT_TYPE;
}
/**
* DOCUMENT_ME
*
* @return DOCUMENT_ME
*/
public QName getResourceKeyNameQName( )
{
return RESOURCE_KEY_NAME;
}
/**
* DOCUMENT_ME
*
* @return DOCUMENT_ME
*/
public QName getServiceName( )
{
return SERVICE_NAME;
}
/**
* DOCUMENT_ME
*
* @return DOCUMENT_ME
*/
public String getServicePortName( )
{
return PORT_NAME;
}
/**
* DOCUMENT_ME
*
* @param subscriptionResourceClass DOCUMENT_ME
* @param consumerReference DOCUMENT_ME
* @param producerReference DOCUMENT_ME
* @param initialTerminationTime DOCUMENT_ME
* @param policy DOCUMENT_ME
* @param precondition DOCUMENT_ME
* @param selector DOCUMENT_ME
* @param producerId DOCUMENT_ME
* @param producerHomeLocation DOCUMENT_ME
* @param topicExpression DOCUMENT_ME
* @param useNotify DOCUMENT_ME
* @param nsSet DOCUMENT_ME
*
* @return DOCUMENT_ME
*
* @throws ResourceException DOCUMENT_ME
*/
public Subscription create( Class subscriptionResourceClass,
EndpointReference consumerReference,
EndpointReference producerReference,
Calendar initialTerminationTime,
Object policy,
QueryExpression precondition,
QueryExpression selector,
Object producerId,
String producerHomeLocation,
TopicExpression topicExpression,
boolean useNotify,
WsnNamespaceVersionHolder nsSet )
throws ResourceException
{
try
{
Constructor constructor =
subscriptionResourceClass.getConstructor( new Class[]
{
EndpointReference.class,
EndpointReference.class,
Object.class,
String.class,
TopicExpression.class
} );
Subscription subscription =
(Subscription) constructor.newInstance( new Object[]
{
consumerReference,
producerReference,
producerId,
producerHomeLocation,
topicExpression
} );
subscription.setTerminationTime( initialTerminationTime );
subscription.setUseNotify( useNotify );
subscription.setSelector( selector );
subscription.setPrecondition( precondition );
subscription.setPolicy( policy );
subscription.init( ); // initialize resource properties
String id = (String) subscription.getID( );
EndpointReference subscriptionEPR = getEndpointReference( id );
//do this here (rather than in find() ) since we need the EPR to be returned on the subscribe request.
subscription.setEndpointReference( subscriptionEPR );
add( subscription );
return subscription;
}
catch ( Exception e )
{
throw new ResourceException( "Failed to create Subscription resource.", e );
}
}
/**
* Returns a map of all FilesystemResource instances. Used by the {@link AbstractResourceHome}
* superclass.
*/
protected final synchronized Map getResourceMap( )
{
if ( s_resources == null )
{
s_resources = AbstractResourceHome.createResourceMap( m_resourceIsPersistent );
}
return s_resources;
}
/**
* Do not modify this method.
*/
protected final Map initResourceMap( )
throws NamingException
{
Context initialContext = new InitialContext( );
if ( m_resourceIsPersistent )
{
s_resources = new ReferenceMap( ReferenceMap.HARD, ReferenceMap.SOFT, true );
initCachePolicy( initialContext );
}
else
{
s_resources = new HashMap( );
}
s_resources = Collections.synchronizedMap( s_resources );
return s_resources;
}
}