/*=============================================================================*
* Copyright 2005 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.muse.example.host;
import org.apache.ws.addressing.EndpointReference;
import org.apache.ws.muse.example.resourceadmin.properties.CreateParamsType;
import org.apache.ws.resource.Resource;
import org.apache.ws.resource.ResourceContext;
import org.apache.ws.resource.ResourceContextException;
import org.apache.ws.resource.ResourceException;
import org.apache.ws.resource.ResourceUnknownException;
import org.apache.ws.resource.impl.AbstractResourceHome;
import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.Map;
/**
* @author Kinga Dziembowski
*
* Home for Host WS-Resources.
*/
public class HostHome
extends AbstractResourceHome
implements Serializable
{
/** The service endpoint name as registered with the SOAP Platform. This is useful for building EPR's. **/
public static final QName SERVICE_NAME =
javax.xml.namespace.QName.valueOf( "{http://ws.apache.org/muse/example/host}host" );
/** DOCUMENT_ME */
public static final QName RESOURCE_ID =
javax.xml.namespace.QName.valueOf( "{http://ws.apache.org/muse/example/host}ResourceID" );
/** The management PortType associated with this resource. This is useful for building EPR's.**/
public static final QName PORT_TYPE =
javax.xml.namespace.QName.valueOf( "{http://ws.apache.org/muse/example/host}HostPortType" );
/** The WSDL Port name associated with the resource. This is useful for building EPR's. **/
public static final String PORT_NAME = "host";
/** The name of the resource key for this resource. **/
public static final QName RESOURCE_KEY_NAME = RESOURCE_ID;
/**
* A NamespaceVerionHolder which maintains the QNames of Spec Wsdls
*/
public static final org.apache.ws.muws.v1_0.impl.WsdmNamespaceVersionHolderImpl SPEC_NAMESPACE_SET =
new org.apache.ws.muws.v1_0.impl.WsdmNamespaceVersionHolderImpl( );
/** A constant for the JNDI Lookup name for this home. **/
public static final String HOME_LOCATION =
org.apache.ws.resource.JndiConstants.CONTEXT_NAME_SERVICES + "/" + SERVICE_NAME.getLocalPart( ) + "/"
+ org.apache.ws.resource.JndiConstants.ATOMIC_NAME_HOME;
// keeps track of instances ids
private long m_instances = 0;
/**
* 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 resourceContext DOCUMENT_ME
* @param createParams DOCUMENT_ME
*
* @return DOCUMENT_ME
*
* @throws ResourceException DOCUMENT_ME
* @throws ResourceContextException DOCUMENT_ME
* @throws ResourceUnknownException DOCUMENT_ME
*/
public Resource create( ResourceContext resourceContext,
CreateParamsType createParams )
throws ResourceException,
ResourceContextException,
ResourceUnknownException
{
Resource resource = null;
long currentId = ++m_instances;
Object resourceId = SERVICE_NAME + Long.toString( currentId );
try
{
//resource = createInstance(aKey);
resource = new HostResource( resourceId, createParams );
//The EPRs should be build using "http://schemas.xmlsoap.org/ws/2003/03/addressing" addressing namespace. It introduces spec conflicts
//To work around thes problem the "http://schemas.xmlsoap.org/ws/2004/08/addressing" is used as namespace for addressing
//EndpointReference epr = getEndpointReference(resourceContext.getBaseURL( ) + "/" + getServiceName().getLocalPart() , null, SPEC_NAMESPACE_SET.getAddressingNamespace());
EndpointReference epr =
getEndpointReference( resourceId );
( (HostResource) resource ).setEndpointReference( epr );
resource.init( );
add( resource );
}
catch ( Exception e )
{
throw new ResourceException( e );
}
return resource;
}
/**
* Map containing all FilesystemResource instances - this map <em>must</em> be static for
* compatibility with certain JNDI providers.
*/
private static Map s_resources;
/**
* Returns a map of all FilesystemResource instances. Used by the {@link org.apache.ws.resource.impl.AbstractResourceHome}
* superclass.
*/
protected synchronized final Map getResourceMap()
{
if ( s_resources == null )
{
s_resources = AbstractResourceHome.createResourceMap( m_resourceIsPersistent );
}
return s_resources;
}
public org.apache.ws.resource.properties.NamespaceVersionHolder getNamespaceVersionHolder()
{
return SPEC_NAMESPACE_SET;
}
}