/*=============================================================================*
* 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.resourceadmin;
import org.apache.ws.addressing.EndpointReference;
import org.apache.ws.addressing.XmlBeansEndpointReference;
import org.apache.ws.muse.example.ExampleConstants;
import org.apache.ws.muse.example.application.ApplicationHome;
import org.apache.ws.muse.example.application.ApplicationResource;
import org.apache.ws.muse.example.businessprocesstype.BusinessprocesstypeHome;
import org.apache.ws.muse.example.businessprocesstype.BusinessprocesstypeResource;
import org.apache.ws.muse.example.host.HostHome;
import org.apache.ws.muse.example.host.HostResource;
import org.apache.ws.muse.example.integrationserver.IntegrationserverHome;
import org.apache.ws.muse.example.integrationserver.IntegrationserverResource;
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.util.XmlBeanUtils;
import org.apache.xmlbeans.XmlObject;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.ReferencePropertiesType;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.xml.namespace.QName;
import java.util.Map;
/**
*
* @author Kinga Dziembowski
*
* This class should be generated ONCE (and not overwritten) to maintain user-added code.
* If there is a change to the WSDL, then the generated implemented interfaces
* (representing the "base" portTypes) will change, thus showing a compile error to the
* user.
*
* NOTE: This class is generated. However, it will not be overwritten by subsequent
* calls to the code generator.
*
*/
public class ResourceadminService
extends AbstractResourceadminService
implements ResourceadminCustomOperationsPortType
{
/**
* 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 Namespace for 2004 addressing to compensate the wsdm spec inconsistency in usage of addressing namespace
*
*/
public static final String ADRESSING_2004_08_NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
/**
* Creates a new {@link ResourceadminService } object.
*
* @param resourceContext DOCUMENT_ME
*/
public ResourceadminService( ResourceContext resourceContext )
{
super( resourceContext );
init( );
}
/**
* DOCUMENT_ME
*
* @param requestDoc DOCUMENT_ME
*
* @return DOCUMENT_ME
*
* @throws org.apache.ws.muse.example.resourceadmin.InvalidResourcePropertiesException DOCUMENT_ME
* @throws org.apache.ws.muse.example.resourceadmin.ResourceUnknownFaultException DOCUMENT_ME
* @throws org.apache.ws.muse.example.resourceadmin.CreateFaultException DOCUMENT_ME
* @throws CreateFaultException DOCUMENT_ME
*/
public org.apache.ws.muse.example.resourceadmin.properties.CreateResponseDocument Create( org.apache.ws.muse.example.resourceadmin.properties.CreateDocument requestDoc )
throws org.apache.ws.muse.example.resourceadmin.InvalidResourcePropertiesException,
org.apache.ws.muse.example.resourceadmin.ResourceUnknownFaultException,
org.apache.ws.muse.example.resourceadmin.CreateFaultException
{
EndpointReference epr =
null;
org.apache.ws.muse.example.resourceadmin.properties.CreateResponseDocument responseDocument =
org.apache.ws.muse.example.resourceadmin.properties.CreateResponseDocument.Factory.newInstance( );
org.apache.ws.muse.example.resourceadmin.properties.CreateResponseDocument.CreateResponse response =
responseDocument.addNewCreateResponse( );
try
{
String reqType = requestDoc.getCreate( ).getCreateParams( ).getResourceType( );
if ( reqType.compareTo( "HostMachine" ) == 0 )
{
epr = createHost( getResourceContext( ),
requestDoc.getCreate( ).getCreateParams( ) );
}
else if ( reqType.compareTo( "BusinessProcess" ) == 0 )
{
epr = createBusinessProcess( getResourceContext( ),
requestDoc.getCreate( ).getCreateParams( ) );
}
else if ( reqType.compareTo( "EnterpriseApplication" ) == 0 )
{
epr =
createEnterpriseApplication( getResourceContext( ),
requestDoc.getCreate( ).getCreateParams( ) );
}
else if ( reqType.compareTo( "IntegrationServer" ) == 0 )
{
epr = createIntegretionServer( getResourceContext( ),
requestDoc.getCreate( ).getCreateParams( ) );
}
if ( epr instanceof XmlBeansEndpointReference )
{
XmlBeansEndpointReference eprType = (XmlBeansEndpointReference) epr;
XmlObject obj = eprType.getXmlObject( org.apache.ws.addressing.v2004_08_10.AddressingConstants.NSURI_ADDRESSING_SCHEMA );
if ( obj instanceof EndpointReferenceType )
{
response.setEndpointReference( (EndpointReferenceType) obj );
}
else
{
throw new Exception( "Expected type - EndpointReferenceType" );
}
}
else
{
throw new Exception( "no resourcetype specified" );
}
}
catch ( Exception e )
{
throw new CreateFaultException( getNamespaceSet( ), "Error when creating new resource " + e.toString( ) );
}
return responseDocument;
}
/**
* DOCUMENT_ME
*
* @param requestDoc DOCUMENT_ME
*
* @return DOCUMENT_ME
*
* @throws org.apache.ws.muse.example.resourceadmin.InvalidResourcePropertiesException DOCUMENT_ME
* @throws org.apache.ws.muse.example.resourceadmin.DestroyResourceFaultException DOCUMENT_ME
* @throws org.apache.ws.muse.example.resourceadmin.ResourceUnknownFaultException DOCUMENT_ME
* @throws ResourceUnknownFaultException DOCUMENT_ME
*/
public org.apache.ws.muse.example.resourceadmin.properties.DestroyResourceResponseDocument DestroyResource( org.apache.ws.muse.example.resourceadmin.properties.DestroyResourceDocument requestDoc )
throws org.apache.ws.muse.example.resourceadmin.InvalidResourcePropertiesException,
org.apache.ws.muse.example.resourceadmin.DestroyResourceFaultException,
org.apache.ws.muse.example.resourceadmin.ResourceUnknownFaultException
{
ResourceadminHome resourceAdminHome =
(ResourceadminHome) getResourceContext( ).getResourceHome();
org.apache.ws.muse.example.resourceadmin.properties.DestroyResourceResponseDocument responseDocument =
org.apache.ws.muse.example.resourceadmin.properties.DestroyResourceResponseDocument.Factory.newInstance( );
responseDocument.addNewDestroyResourceResponse( );
try
{
Context initialContext = new InitialContext( );
QName[] resourceIDQNames = resourceAdminHome.getResourcesKeyNameQnames( );
String reqType =
requestDoc.getDestroyResource( ).getDestroyResourceParams( ).getResourceType( );
if ( !validateType( reqType ) )
{
throw new DestroyResourceFaultException( getNamespaceSet( ),
"Attempt to destroy Resource of unknown type" );
}
ReferencePropertiesType refProps =
requestDoc.getDestroyResource( ).getDestroyResourceParams( ).getEndpointReference( )
.getReferenceProperties( );
boolean found = false;
for ( int i = 0; i < resourceIDQNames.length; i++ )
{
XmlObject[] childElems = XmlBeanUtils.getChildElements( refProps, resourceIDQNames[i] );
if ( childElems.length > 0 )
{
XmlObject obj = childElems[0];
String value = XmlBeanUtils.getValue( obj );
Map resources = resourceAdminHome.getResources( );
if ( resources.containsKey( value ) )
{
found = true;
Resource resource = (Resource) resources.get( value );
if ( resource instanceof ApplicationResource )
{
ApplicationResource appResource = (ApplicationResource) resource;
ApplicationHome appHome =
(ApplicationHome) initialContext.lookup( ApplicationHome.HOME_LOCATION );
appHome.remove( value );
resourceAdminHome.getResources( ).remove( appResource.getID( ) );
}
else if ( resource instanceof HostResource )
{
HostResource hostResource = (HostResource) resource;
HostHome hostHome = (HostHome) initialContext.lookup( HostHome.HOME_LOCATION );
hostHome.remove( value );
resourceAdminHome.getResources( ).remove( hostResource.getID( ) );
}
else if ( resource instanceof IntegrationserverResource )
{
IntegrationserverResource isResource = (IntegrationserverResource) resource;
IntegrationserverHome isHome =
(IntegrationserverHome) initialContext.lookup( IntegrationserverHome.HOME_LOCATION );
isHome.remove( value );
resourceAdminHome.getResources( ).remove( isResource.getID( ) );
}
else if ( resource instanceof BusinessprocesstypeResource )
{
BusinessprocesstypeResource bpResource = (BusinessprocesstypeResource) resource;
BusinessprocesstypeHome bpHome =
(BusinessprocesstypeHome) initialContext.lookup( BusinessprocesstypeHome.HOME_LOCATION );
bpHome.remove( value );
resourceAdminHome.getResources( ).remove( bpResource.getID( ) );
}
else
{
throw new Exception( "The EPR is unknown." );
}
break;
}
}
}
if ( !found )
{
throw new Exception( "Error finding Resource" );
}
}
catch ( Exception e )
{
throw new ResourceUnknownFaultException( getNamespaceSet( ),
"Error destroying resource " + e.toString( ) );
}
return responseDocument;
}
/**
* DOCUMENT_ME
*
* @param requestDoc DOCUMENT_ME
*
* @return DOCUMENT_ME
*
* @throws org.apache.ws.muse.example.resourceadmin.RemoveRelationshipFaultException DOCUMENT_ME
* @throws org.apache.ws.muse.example.resourceadmin.ResourceUnknownFaultException DOCUMENT_ME
* @throws ResourceUnknownFaultException DOCUMENT_ME
*/
public org.apache.ws.muse.example.resourceadmin.properties.RemoveRelationshipResponseDocument RemoveRelationship( org.apache.ws.muse.example.resourceadmin.properties.RemoveRelationshipDocument requestDoc )
throws org.apache.ws.muse.example.resourceadmin.RemoveRelationshipFaultException,
org.apache.ws.muse.example.resourceadmin.ResourceUnknownFaultException
{
org.apache.ws.muse.example.resourceadmin.properties.RemoveRelationshipResponseDocument responseDocument =
org.apache.ws.muse.example.resourceadmin.properties.RemoveRelationshipResponseDocument.Factory
.newInstance( );
responseDocument.addNewRemoveRelationshipResponse( );
try
{
ResourceadminHome aHome = (ResourceadminHome) getResourceContext().getResourceHome( );
QName[] resourceIDQNames = aHome.getResourcesKeyNameQnames( );
// Assume that the first partici[pant in the relationship own the relationship
// then the remove relationship will be dispatched to the resource identified
// in the first participant.
ReferencePropertiesType refProp =
requestDoc.getRemoveRelationship( ).getRelationship( ).getParticipantArray( 0 )
.getManageabilityEndpointReferenceArray( 0 ).getReferenceProperties( );
boolean found = false;
for ( int i = 0; i < resourceIDQNames.length; i++ )
{
XmlObject[] childElems = XmlBeanUtils.getChildElements( refProp, resourceIDQNames[i] );
if ( childElems.length > 0 )
{
found = true;
XmlObject obj = childElems[0];
String value = XmlBeanUtils.getValue( obj );
Map resources = aHome.getResources( );
if ( resources.containsKey( value ) )
{
Resource resource = (Resource) resources.get( value );
if ( resource instanceof ApplicationResource )
{
ApplicationResource appServer = (ApplicationResource) resource;
appServer.removeRelationship( requestDoc );
}
else if ( resource instanceof HostResource )
{
throw new Exception( "HostResource do not support Relationship Capability - cannot be contain relationships " );
}
else if ( resource instanceof IntegrationserverResource )
{
IntegrationserverResource integrationServer = (IntegrationserverResource) resource;
integrationServer.removeRelationship( requestDoc );
}
else if ( resource instanceof BusinessprocesstypeResource )
{
BusinessprocesstypeResource bpServer = (BusinessprocesstypeResource) resource;
bpServer.removeRelationship( requestDoc );
}
else
{
throw new Exception( "Paticipant is unregistered." );
}
break;
}
}
}
if ( !found )
{
throw new Exception( "Error finding Participant" );
}
}
catch ( Exception e )
{
throw new ResourceUnknownFaultException( getNamespaceSet( ),
"Error removing relationship " + e.toString( ) );
}
return responseDocument;
}
/**
* DOCUMENT_ME
*
* @param requestDoc DOCUMENT_ME
*
* @return DOCUMENT_ME
*
* @throws org.apache.ws.muse.example.resourceadmin.ResourceUnknownFaultException DOCUMENT_ME
* @throws org.apache.ws.muse.example.resourceadmin.SetRelationshipFaultException DOCUMENT_ME
* @throws ResourceUnknownFaultException DOCUMENT_ME
*/
public org.apache.ws.muse.example.resourceadmin.properties.SetRelationshipResponseDocument SetRelationship( org.apache.ws.muse.example.resourceadmin.properties.SetRelationshipDocument requestDoc )
throws org.apache.ws.muse.example.resourceadmin.ResourceUnknownFaultException,
org.apache.ws.muse.example.resourceadmin.SetRelationshipFaultException
{
org.apache.ws.muse.example.resourceadmin.properties.SetRelationshipResponseDocument responseDocument =
org.apache.ws.muse.example.resourceadmin.properties.SetRelationshipResponseDocument.Factory.newInstance( );
responseDocument.addNewSetRelationshipResponse( );
try
{
ResourceadminHome aHome = (ResourceadminHome) getResourceContext().getResourceHome( );
QName[] resourceIDQNames = aHome.getResourcesKeyNameQnames( );
ReferencePropertiesType refProp =
requestDoc.getSetRelationship( ).getRelationshipFrom( ).getParticipant( )
.getManageabilityEndpointReferenceArray( 0 ).getReferenceProperties( );
boolean found = false;
for ( int i = 0; i < resourceIDQNames.length; i++ )
{
XmlObject[] childElems = XmlBeanUtils.getChildElements( refProp, resourceIDQNames[i] );
if ( childElems.length > 0 )
{
found = true;
XmlObject obj = childElems[0];
String value = XmlBeanUtils.getValue( obj );
Map resources = aHome.getResources( );
if ( resources.containsKey( value ) )
{
Resource resource = (Resource) resources.get( value );
if ( resource instanceof ApplicationResource )
{
ApplicationResource appServer = (ApplicationResource) resource;
appServer.setRelationship( requestDoc );
}
else if ( resource instanceof HostResource )
{
throw new Exception( "HostResource do not support Relationship Capability - cannot be contain relationships " );
}
else if ( resource instanceof IntegrationserverResource )
{
IntegrationserverResource integrationServer = (IntegrationserverResource) resource;
integrationServer.setRelationship( requestDoc );
}
else if ( resource instanceof BusinessprocesstypeResource )
{
BusinessprocesstypeResource bpServer = (BusinessprocesstypeResource) resource;
bpServer.setRelationship( requestDoc );
}
else
{
throw new Exception( "Paticipant is unregistered " );
}
break;
}
}
}
if ( !found )
{
throw new Exception( "Error finding Participant" );
}
}
catch ( Exception e )
{
throw new ResourceUnknownFaultException( getNamespaceSet( ),
"Error setting relationship " + e.toString( ) );
}
return responseDocument;
}
/**
* DOCUMENT_ME
*
* @param context DOCUMENT_ME
* @param createparams DOCUMENT_ME
*
* @return DOCUMENT_ME
*
* @throws Exception DOCUMENT_ME
*/
public EndpointReference createBusinessProcess( ResourceContext context,
CreateParamsType createparams )
throws Exception
{
Context initialContext = new InitialContext( );
BusinessprocesstypeHome home =
(BusinessprocesstypeHome) initialContext.lookup( BusinessprocesstypeHome.HOME_LOCATION );
BusinessprocesstypeResource resource = (BusinessprocesstypeResource) home.create( context, createparams );
ResourceadminHome aHome = (ResourceadminHome) getResourceContext().getResourceHome( );
aHome.getResources( ).put( resource.getID( ),
resource );
return resource.getEndpointReference( );
}
/**
* DOCUMENT_ME
*
* @param context DOCUMENT_ME
* @param createparams DOCUMENT_ME
*
* @return DOCUMENT_ME
*
* @throws Exception DOCUMENT_ME
*/
public EndpointReference createEnterpriseApplication( ResourceContext context,
CreateParamsType createparams )
throws Exception
{
Context initialContext = new InitialContext( );
ApplicationHome home = (ApplicationHome) initialContext.lookup( ApplicationHome.HOME_LOCATION );
ApplicationResource resource = (ApplicationResource) home.create( context, createparams );
ResourceadminHome aHome = (ResourceadminHome) getResourceContext().getResourceHome( );
aHome.getResources( ).put( resource.getID( ),
resource );
return resource.getEndpointReference( );
}
/**
* DOCUMENT_ME
*
* @param context DOCUMENT_ME
* @param createparams DOCUMENT_ME
*
* @return DOCUMENT_ME
*
* @throws Exception DOCUMENT_ME
*/
public EndpointReference createHost( ResourceContext context,
CreateParamsType createparams )
throws Exception
{
Context initialContext = new InitialContext( );
HostHome home = (HostHome) initialContext.lookup( HostHome.HOME_LOCATION );
HostResource resource = (HostResource) home.create( context, createparams );
ResourceadminHome aHome = (ResourceadminHome) context.getResourceHome( );
aHome.getResources( ).put( resource.getID( ),
resource );
return resource.getEndpointReference( );
}
/**
* DOCUMENT_ME
*
* @param context DOCUMENT_ME
* @param createparams DOCUMENT_ME
*
* @return DOCUMENT_ME
*
* @throws Exception DOCUMENT_ME
*/
public EndpointReference createIntegretionServer( ResourceContext context,
CreateParamsType createparams )
throws Exception
{
Context initialContext = new InitialContext( );
IntegrationserverHome home =
(IntegrationserverHome) initialContext.lookup( IntegrationserverHome.HOME_LOCATION );
IntegrationserverResource resource = (IntegrationserverResource) home.create( context, createparams );
ResourceadminHome aHome = (ResourceadminHome) context.getResourceHome( );
aHome.getResources( ).put( resource.getID( ),
resource );
return resource.getEndpointReference( );
}
/**
* Returns a collection of Spec Namespaces associated with this Service
*
* @return A NamespaceVersionHolder impl which represents the collection of spec namespaces
* associated with this service.
*/
protected org.apache.ws.resource.properties.NamespaceVersionHolder getNamespaceSet( )
{
return SPEC_NAMESPACE_SET;
}
/**
* DOCUMENT_ME
*
* @param aType DOCUMENT_ME
*
* @return DOCUMENT_ME
*/
protected boolean validateType( String aType )
{
String[] knownTypes = ExampleConstants.getKnownResourceTypes( );
for ( int i = 0; i < knownTypes.length; i++ )
{
if ( knownTypes[i].compareTo( aType ) == 0 )
{
return true;
}
}
return false;
}
}