gov.nih.nci.cagrid.introduce.common
Class CommonTools

java.lang.Object
  extended by gov.nih.nci.cagrid.introduce.common.CommonTools

public final class CommonTools
extends java.lang.Object

Author:
Shannon Hastings , Scott Oster , Stephen Langella

Field Summary
static java.lang.String ALLOWED_EXISTING_JAVA_PACKAGE_REGEX
           
static java.lang.String ALLOWED_JAVA_CLASS_REGEX
           
static java.lang.String ALLOWED_JAVA_FIELD_REGEX
           
static java.lang.String ALLOWED_JAVA_OP_NAME
           
static java.lang.String ALLOWED_JAVA_PACKAGE_REGEX
           
static java.util.List JAVA_KEYWORDS
           
static java.lang.String SUGGESTED_JAVA_PACKAGE_REGEX
           
 
Method Summary
static void addMethod(ServiceType service, MethodType method)
          Adds a method to a service
static void addNamespace(ServiceDescription serviceD, NamespaceType nsType)
          Adds a namespace type to a service description
static void addResourcePropety(ServiceType service, ResourcePropertyType resource)
          Adds a resource property to a service
static void addService(ServicesType servicesType, ServiceType serviceType)
          Adds aservice type to the services list
static void addServicePropety(ServiceDescription introService, ServicePropertiesProperty property)
           
static java.lang.Process createAndOutputProcess(java.lang.String cmd)
           
static NamespaceType createNamespaceType(java.lang.String xsdFilename, java.io.File serviceSchemaDir)
          This method will create a namespaceType fully populated with the schema elements.
static boolean equals(ServiceSecurity ss, MethodSecurity ms)
           
static java.io.File findSchema(java.lang.String schemaNamespace, java.io.File dir)
           
static java.lang.String getGlobusLocation()
           
static MethodType getMethod(MethodsType methods, java.lang.String name)
          Gets a method by its name
static NamespaceType getNamespaceType(NamespacesType namespacesType, java.lang.String namespaceURI)
           
static java.lang.String getPackageDir(ServiceType service)
          Gets the directory which corresponds to a Java package name
static java.lang.String getPackageName(java.lang.String fullNamespace)
          Gets a package name for a namespace using a namespace to package mapper utility
static java.lang.String getPackageName(java.lang.String fullNamespace, NamespacesType namespaceTypes)
          Gets a package name for a namespace
static java.util.List getProvidedNamespaces(java.io.File startDir)
           
static ResourcePropertyType[] getResourcePropertiesOfType(ServiceType service, javax.xml.namespace.QName type)
          Gets all resource properties from a service which have a specified QName
static java.lang.String getResourcePropertyVariableName(ResourcePropertiesListType metadataList, int index)
          Define a unique name for use as a variable for the metadata at the specified index given the scope of the ServiceMetadataListType.
static SchemaElementType getSchemaElementType(NamespaceType nsType, java.lang.String name)
           
static SchemaInformation getSchemaInformation(NamespacesType namespacesType, javax.xml.namespace.QName qname)
           
static ServiceType getService(ServicesType services, java.lang.String name)
          Gets a service by name from the services container type
static java.lang.String getServicePropertyValue(ServiceDescription desc, java.lang.String key)
          Gets the value of a service property from service information
static java.lang.String getTargetNamespace(java.io.File file)
           
static void getTargetNamespaces(java.util.List namespaces, java.io.File dir)
           
static java.util.Set getUnavailableUsedTypes(ServiceDescription desc)
          Gets the types from a service description which are referenced in the service but not available in the namespace types of it
static void importMethod(MethodTypeImportInformation importInformation, java.io.File fromDir, java.io.File toDir, java.lang.String fromService, java.lang.String toService, java.lang.String methodName, boolean copyFiles)
           
static boolean isNamespaceTypeInUse(NamespaceType nsType, ServiceDescription desc)
          Determines if schema element types from a namespace type are referenced in other parts of the service (e.g.
static boolean isSuggestedPackageName(java.lang.String packageName)
           
static boolean isValidClassName(java.lang.String classname)
           
static boolean isValidJavaField(java.lang.String serviceName)
           
static boolean isValidJavaMethod(java.lang.String methodName)
           
static boolean isValidNoStubPackageName(java.lang.String packageName)
           
static boolean isValidPackageAndClassName(java.lang.String packageclass)
           
static boolean isValidPackageName(java.lang.String packageName)
           
static boolean isValidServiceName(java.lang.String serviceName)
           
static java.lang.String lowerCaseFirstCharacter(java.lang.String variableName)
          Returns the input string with the first character converted to lower case
static java.lang.String methodTypeToString(MethodType method)
           
static NamespaceType reCreateNamespaceType(java.lang.String xsdFilename, java.io.File serviceSchemaDir, NamespaceType oldType)
          This method will create a namespaceType fully populated with the schema elements.
static void removeMethod(MethodsType methodsType, MethodType method)
          Removes a method from a MethodsType container object
static void removeNamespace(ServiceDescription serviceD, java.lang.String namespace)
           
static void removeResourceProperty(ServiceType service, javax.xml.namespace.QName resourcePropertyType)
           
static boolean removeServiceProperty(ServiceDescription desc, java.lang.String key)
          Removes a service property from service information
static boolean servicePropertyExists(ServiceDescription desc, java.lang.String key)
          Determines if a service information object contains the specified service property
static void setServiceProperty(ServiceDescription desc, java.lang.String key, java.lang.String value, boolean isFromETC)
          Sets a service property on the service information.
static void setServiceProperty(ServiceDescription desc, java.lang.String key, java.lang.String value, boolean isFromETC, java.lang.String description)
          Sets a service property on the service information.
static java.lang.String upperCaseFirstCharacter(java.lang.String variableName)
          Returns the input string with the first character converted to uppercase
static boolean usedTypesAvailable(ServiceDescription desc)
          Determines if all schema element types used in the service are still available in the service's namespace types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALLOWED_JAVA_CLASS_REGEX

public static final java.lang.String ALLOWED_JAVA_CLASS_REGEX
See Also:
Constant Field Values

ALLOWED_JAVA_FIELD_REGEX

public static final java.lang.String ALLOWED_JAVA_FIELD_REGEX
See Also:
Constant Field Values

ALLOWED_JAVA_OP_NAME

public static final java.lang.String ALLOWED_JAVA_OP_NAME
See Also:
Constant Field Values

ALLOWED_JAVA_PACKAGE_REGEX

public static final java.lang.String ALLOWED_JAVA_PACKAGE_REGEX
See Also:
Constant Field Values

SUGGESTED_JAVA_PACKAGE_REGEX

public static final java.lang.String SUGGESTED_JAVA_PACKAGE_REGEX
See Also:
Constant Field Values

ALLOWED_EXISTING_JAVA_PACKAGE_REGEX

public static final java.lang.String ALLOWED_EXISTING_JAVA_PACKAGE_REGEX
See Also:
Constant Field Values

JAVA_KEYWORDS

public static final java.util.List JAVA_KEYWORDS
Method Detail

createAndOutputProcess

public static java.lang.Process createAndOutputProcess(java.lang.String cmd)
                                                throws java.lang.Exception
Throws:
java.lang.Exception

getProvidedNamespaces

public static java.util.List getProvidedNamespaces(java.io.File startDir)

findSchema

public static java.io.File findSchema(java.lang.String schemaNamespace,
                                      java.io.File dir)

getTargetNamespaces

public static void getTargetNamespaces(java.util.List namespaces,
                                       java.io.File dir)

getTargetNamespace

public static java.lang.String getTargetNamespace(java.io.File file)
                                           throws java.lang.Exception
Throws:
java.lang.Exception

isValidPackageAndClassName

public static boolean isValidPackageAndClassName(java.lang.String packageclass)

isValidPackageName

public static boolean isValidPackageName(java.lang.String packageName)

isSuggestedPackageName

public static boolean isSuggestedPackageName(java.lang.String packageName)

isValidNoStubPackageName

public static boolean isValidNoStubPackageName(java.lang.String packageName)

isValidServiceName

public static boolean isValidServiceName(java.lang.String serviceName)

isValidClassName

public static boolean isValidClassName(java.lang.String classname)

isValidJavaField

public static boolean isValidJavaField(java.lang.String serviceName)

isValidJavaMethod

public static boolean isValidJavaMethod(java.lang.String methodName)

getPackageName

public static java.lang.String getPackageName(java.lang.String fullNamespace)
Gets a package name for a namespace using a namespace to package mapper utility

Parameters:
fullNamespace - The namespace to derive a package name for
Returns:
The package name

getPackageName

public static java.lang.String getPackageName(java.lang.String fullNamespace,
                                              NamespacesType namespaceTypes)
Gets a package name for a namespace

Parameters:
fullNamespace - The namespace to get a package name for
namespaceTypes - The namespace types of a service
Returns:
The package name

equals

public static boolean equals(ServiceSecurity ss,
                             MethodSecurity ms)

createNamespaceType

public static NamespaceType createNamespaceType(java.lang.String xsdFilename,
                                                java.io.File serviceSchemaDir)
                                         throws java.lang.Exception
This method will create a namespaceType fully populated with the schema elements. It will set default the location to the relative path from the serviceSchemaDir.

Parameters:
xsdFilename - The file name of the XSD schema
serviceSchemaDir - the directory where the service's schemas (wsdls) are
Returns:
The NamespaceType representation of the schema
Throws:
java.lang.Exception

reCreateNamespaceType

public static NamespaceType reCreateNamespaceType(java.lang.String xsdFilename,
                                                  java.io.File serviceSchemaDir,
                                                  NamespaceType oldType)
                                           throws java.lang.Exception
This method will create a namespaceType fully populated with the schema elements. It will set default the location to the relative path from the serviceSchemaDir.

Parameters:
xsdFilename - The file name of the XSD schema
serviceSchemaDir - the directory where the service's schemas (wsdls) are
Returns:
The NamespaceType representation of the schema
Throws:
java.lang.Exception

getSchemaElementType

public static SchemaElementType getSchemaElementType(NamespaceType nsType,
                                                     java.lang.String name)

getService

public static ServiceType getService(ServicesType services,
                                     java.lang.String name)
Gets a service by name from the services container type

Parameters:
services - The services container type
name - The name of the service
Returns:
The named service or null if not found

getMethod

public static MethodType getMethod(MethodsType methods,
                                   java.lang.String name)
Gets a method by its name

Parameters:
methods - The methods container type
name - The name of the method
Returns:
The named method, or null if not found

methodTypeToString

public static java.lang.String methodTypeToString(MethodType method)

importMethod

public static void importMethod(MethodTypeImportInformation importInformation,
                                java.io.File fromDir,
                                java.io.File toDir,
                                java.lang.String fromService,
                                java.lang.String toService,
                                java.lang.String methodName,
                                boolean copyFiles)
                         throws java.lang.Exception
Throws:
java.lang.Exception

getPackageDir

public static java.lang.String getPackageDir(ServiceType service)
Gets the directory which corresponds to a Java package name

Parameters:
service - The service
Returns:
The service's package name changed to a relative directory

getNamespaceType

public static NamespaceType getNamespaceType(NamespacesType namespacesType,
                                             java.lang.String namespaceURI)

getSchemaInformation

public static SchemaInformation getSchemaInformation(NamespacesType namespacesType,
                                                     javax.xml.namespace.QName qname)

addServicePropety

public static void addServicePropety(ServiceDescription introService,
                                     ServicePropertiesProperty property)

addResourcePropety

public static void addResourcePropety(ServiceType service,
                                      ResourcePropertyType resource)
Adds a resource property to a service

Parameters:
service - The service to add a resource property to
resource - The resource property to be added

removeResourceProperty

public static void removeResourceProperty(ServiceType service,
                                          javax.xml.namespace.QName resourcePropertyType)

getResourcePropertiesOfType

public static ResourcePropertyType[] getResourcePropertiesOfType(ServiceType service,
                                                                 javax.xml.namespace.QName type)
Gets all resource properties from a service which have a specified QName

Parameters:
service - The service to find resource properties of
type - The type of resource properties to locate
Returns:
An Array of ResourcePropertyTypes which have the specified QName

addMethod

public static void addMethod(ServiceType service,
                             MethodType method)
Adds a method to a service

Parameters:
service - The service to add a new method to
method - The method to be added

removeMethod

public static void removeMethod(MethodsType methodsType,
                                MethodType method)
Removes a method from a MethodsType container object

Parameters:
methodsType - The container object to remove a method from
method - The method to be removed

addNamespace

public static void addNamespace(ServiceDescription serviceD,
                                NamespaceType nsType)
Adds a namespace type to a service description

Parameters:
serviceD - The service description
nsType - The namespace type to add

removeNamespace

public static void removeNamespace(ServiceDescription serviceD,
                                   java.lang.String namespace)

addService

public static void addService(ServicesType servicesType,
                              ServiceType serviceType)
Adds aservice type to the services list

Parameters:
servicesType - The services descriptions
serviceType - The service type to add

getResourcePropertyVariableName

public static java.lang.String getResourcePropertyVariableName(ResourcePropertiesListType metadataList,
                                                               int index)
Define a unique name for use as a variable for the metadata at the specified index given the scope of the ServiceMetadataListType.

Parameters:
metadataList - the list of metadata
index - the index into the metadata list of the targeted metadata item
Returns:
the variable name to use

setServiceProperty

public static void setServiceProperty(ServiceDescription desc,
                                      java.lang.String key,
                                      java.lang.String value,
                                      boolean isFromETC)
Sets a service property on the service information. If no service properties are found, a new array of properties is created and initialized with a single property containing the key and value specified. If the property is found to exist in the service, it's value is changed to the one specified.

Parameters:
desc - The service information to set a property on
key - The key of the service property to set
value - The value to associate with the property key

setServiceProperty

public static void setServiceProperty(ServiceDescription desc,
                                      java.lang.String key,
                                      java.lang.String value,
                                      boolean isFromETC,
                                      java.lang.String description)
Sets a service property on the service information. If no service properties are found, a new array of properties is created and initialized with a single property containing the key and value specified. If the property is found to exist in the service, it's value is changed to the one specified.

Parameters:
desc - The service information to set a property on
key - The key of the service property to set
value - The value to associate with the property key
description - The description of the service property

servicePropertyExists

public static boolean servicePropertyExists(ServiceDescription desc,
                                            java.lang.String key)
Determines if a service information object contains the specified service property

Parameters:
desc - The service description
key - The property to check for
Returns:
True if a property with the key name is found, false otherwise

getServicePropertyValue

public static java.lang.String getServicePropertyValue(ServiceDescription desc,
                                                       java.lang.String key)
                                                throws java.lang.Exception
Gets the value of a service property from service information

Parameters:
desc - The service information to pull a property value from
key - The key of the property value to find
Returns:
The value of the property
Throws:
java.lang.Exception - If no property with the specified key is found

removeServiceProperty

public static boolean removeServiceProperty(ServiceDescription desc,
                                            java.lang.String key)
Removes a service property from service information

Parameters:
desc - The service information to remove a property from
key - The key name of the property to remove
Returns:
True if the property existed and was removed, false otherwise

isNamespaceTypeInUse

public static boolean isNamespaceTypeInUse(NamespaceType nsType,
                                           ServiceDescription desc)
Determines if schema element types from a namespace type are referenced in other parts of the service (e.g. Methods, Exceptions)

Parameters:
nsType -
desc -
Returns:
True if the namespace type is in use in the service, false otherwise

usedTypesAvailable

public static boolean usedTypesAvailable(ServiceDescription desc)
Determines if all schema element types used in the service are still available in the service's namespace types.

Parameters:
desc -
Returns:
True if all of the types referenced by a service are still present in the service description

getUnavailableUsedTypes

public static java.util.Set getUnavailableUsedTypes(ServiceDescription desc)
Gets the types from a service description which are referenced in the service but not available in the namespace types of it

Parameters:
desc - The service description
Returns:
The set of unavailable types

lowerCaseFirstCharacter

public static java.lang.String lowerCaseFirstCharacter(java.lang.String variableName)
Returns the input string with the first character converted to lower case

Parameters:
variableName - string to fix
Returns:
the input string with the first character converted to lowercase

upperCaseFirstCharacter

public static java.lang.String upperCaseFirstCharacter(java.lang.String variableName)
Returns the input string with the first character converted to uppercase

Parameters:
variableName - string to fix
Returns:
the input string with the first character converted to uppercase

getGlobusLocation

public static java.lang.String getGlobusLocation()