![JAR search and dependency download from the Maven repository](/logo.png)
templates.java.ExceptionUtils.vm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of andromda-java-cartridge Show documentation
Show all versions of andromda-java-cartridge Show documentation
Produces generic Java code, such as: value objects, enumerations, exceptions, interfaces, etc.
The newest version!
## Contains exception utilities used within the exception templates
#if ($webFault)
#set ($exceptionAttribute = $stringUtils.uncapitalize(${class.name}))
// protected Object $exceptionAttribute;
/*
* Create webservice exception with detail exception.
* @param message Exception message
* @param ${exceptionAttribute}In webservice Throwable detail
public ${class.name}(String message, Object ${exceptionAttribute}In)
{
super(message);
this.$exceptionAttribute = ${exceptionAttribute}In;
}
*/
/*
* Create webservice exception with detail exception.
* @param message Exception message
* @param ${exceptionAttribute}In webservice Throwable detail
* @param cause webservice Throwable cause
public ${class.name}(String message, Object ${exceptionAttribute}In, Throwable cause)
{
super(message, cause);
this.$exceptionAttribute = ${exceptionAttribute}In;
}
*/
/*
* Get webservice detail exception.
* @return this.$exceptionAttribute com.sun.org.apache.xerces.internal.dom.ElementNSImpl
public Object getFaultInfo()
{
return this.$exceptionAttribute;
}
*/
/**
private String faultCode;
* Get webservice faultCode.
* @return this.$exceptionAttribute com.sun.org.apache.xerces.internal.dom.ElementNSImpl
public Object getFaultCode()
{
return this.faultCode;
}
*/
/**
private String faultString;
* Get webservice detail exception.
* @return this.faultString
public Object getFaultString()
{
return this.faultString;
}
*/
// Must override default Exception stackTrace in order to avoid the JAX-WS Error
// java.lang.StackTraceElement in Sun JDK5 and 6 does not have a no-arg default constructor
/**
* @see java.lang.Throwable#getStackTrace()
*/
@Override
//@XmlTransient
public StackTraceElement[] getStackTrace()
{
return super.getStackTrace();
}
/**
* @see java.lang.Throwable#setStackTrace(StackTraceElement[])
*/
@Override
@javax.xml.bind.annotation.XmlTransient
public void setStackTrace(StackTraceElement[] element)
{
super.setStackTrace(element);
}
#end
/**
* Finds the root cause of the parent exception
* by traveling up the exception tree. Performs printStackTrace if
* an exception is thrown.
* @param th Throwable to find the cause from
* @return targetException Throwable cause
*/
private static Throwable findRootCause(Throwable th)
{
if (th != null)
{
// Reflectively get any JMX or EJB exception causes.
try
{
Throwable targetException = null;
// java.lang.reflect.InvocationTargetException
// or javax.management.ReflectionException
String exceptionProperty = "targetException";
if (PropertyUtils.isReadable(th, exceptionProperty))
{
targetException = (Throwable)PropertyUtils.getProperty(th, exceptionProperty);
}
else
{
exceptionProperty = "causedByException";
//javax.ejb.EJBException
if (PropertyUtils.isReadable(th, exceptionProperty))
{
targetException = (Throwable)PropertyUtils.getProperty(th, exceptionProperty);
}
}
if (targetException != null)
{
th = targetException;
}
}
catch (Exception ex)
{
// just print the exception and continue
ex.printStackTrace();
}
if (th.getCause() != null)
{
th = th.getCause();
th = findRootCause(th);
}
}
return th;
}
#foreach ($operation in $class.operations)
#set ($returnType = $operation.returnType)
#set ($returnObject = "returnValue")
/**
$operation.getDocumentation(" * ")
#foreach ($parameter in $operation.parameters)
#if ($parameter.inParameter)
* @param $parameter.name default=$parameter.defaultValue required=$parameter.required
#end
#end
#if ($operation.returnTypePresent)
* @return $operation.getterSetterReturnTypeName
#end
#if ($operation.exceptionsPresent)
* @throws $operation.exceptionList
#end
*/
$operation.visibility $operation.getterSetterReturnTypeName $operation.signature
#if ($operation.exceptionsPresent)
throws $operation.exceptionList
#end
{
// ${toDoTag} implement $operation.visibility $operation.getterSetterReturnTypeName $operation.signature
#set ($returnTypeName = $operation.type.fullyQualifiedName)
#if ($operation.returnTypePresent)
#if (!$operation.type.primitive)
return null;
#elseif ("boolean" == $returnTypeName)
return false;
#else
return ($returnTypeName)0;
#end
#else
throw new UnsupportedOperationException("${class.fullyQualifiedName}.${operation.signature} Not implemented!");
#end
}
#end
## webFault has properties in the fault bean which must be referenced instead of these properties
#if (!$webFault)
#foreach ($attribute in $class.properties)
private $attribute.getterSetterTypeName $attribute.name#if ($attribute.defaultValuePresent) = $attribute.defaultValue#end;
/**
* $attribute.documentation
##$attribute.getDocumentation(" * ")
* @return ${attribute.name}
*/
public $attribute.getterSetterTypeName ${attribute.getterName}()
{
return this.${attribute.name};
}
## - always have as public, having read-only causes too many issues when attempting to
## use in other cartridges
/**
* $attribute.documentation
##$attribute.getDocumentation(" * ")
* @param ${attribute.name}In
*/
public void ${attribute.setterName}($attribute.getterSetterTypeName ${attribute.name}In)
{
this.${attribute.name} = ${attribute.name}In;
}
#end
#end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy