|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jvnet.ws.wadl2java.common.BaseResourceClassGenerator
public abstract class BaseResourceClassGenerator
Generator class for nested static classes used to represent web resources.
| Nested Class Summary | |
|---|---|
protected static class |
BaseResourceClassGenerator.MethodType
|
| Field Summary | |
|---|---|
protected com.sun.codemodel.JCodeModel |
codeModel
|
protected static String |
CREATE_CLIENT_INSTANCE
The method that can be called to create the client instance so that generators can override factory methods |
protected static String |
CREATE_CLIENT_METHOD
The method that can be called to create a fully configured client |
protected static String |
CUSTOMIZE_CLIENT_METHOD
The method that can be called so that generators have a simple template to customise the client |
protected com.sun.codemodel.JPackage |
pkg
|
| Constructor Summary | |
|---|---|
BaseResourceClassGenerator(MessageListener messageListener,
Resolver resolver,
com.sun.codemodel.JCodeModel codeModel,
com.sun.codemodel.JPackage pkg,
String generatedPackages,
JavaDocUtil javaDoc,
com.sun.codemodel.JDefinedClass clazz)
Creates a new instance of BaseResourceClassGenerator. |
|
BaseResourceClassGenerator(MessageListener messageListener,
Resolver resolver,
com.sun.codemodel.JCodeModel codeModel,
com.sun.codemodel.JPackage pkg,
String generatedPackages,
JavaDocUtil javaDoc,
ResourceNode resource)
Creates a new instance of BaseResourceClassGenerator. |
|
| Method Summary | |
|---|---|
protected abstract String |
buildMethod()
|
protected abstract String |
clientFactoryMethod()
|
protected abstract com.sun.codemodel.JClass |
clientFactoryType()
|
protected abstract com.sun.codemodel.JClass |
clientResponseClientType()
|
protected abstract com.sun.codemodel.JClass |
clientType()
|
protected abstract com.sun.codemodel.JExpression[] |
createProcessInvocation(MethodNode method,
com.sun.codemodel.JBlock $methodBody,
com.sun.codemodel.JVar $resourceBuilder,
String methodString,
RepresentationNode inputRep,
com.sun.codemodel.JType returnType,
com.sun.codemodel.JExpression $returnTypeExpr,
com.sun.codemodel.JExpression $entityExpr)
|
protected abstract com.sun.codemodel.JVar |
createRequestBuilderAndAccept(com.sun.codemodel.JBlock $methodBody,
com.sun.codemodel.JVar $resource,
RepresentationNode outputRep)
|
void |
generateBeanProperty(com.sun.codemodel.JDefinedClass $impl,
List<Param> matrixParameters,
Param p,
boolean isAbstract)
Generate a bean setter and getter for a parameter. |
protected void |
generateBody(MethodNode method,
boolean isJAXB,
Map<com.sun.codemodel.JType,com.sun.codemodel.JDefinedClass> exceptionMap,
RepresentationNode outputRep,
com.sun.codemodel.JVar $genericMethodParameter,
boolean wrapInputTypeInJAXBElement,
com.sun.codemodel.JType inputType,
com.sun.codemodel.JType returnType,
com.sun.codemodel.JVar $resourceBuilder,
RepresentationNode inputRep,
com.sun.codemodel.JBlock $methodBody)
Generate a method body that uses a JAXBDispatcher, used when the payloads are XML. |
com.sun.codemodel.JDefinedClass |
generateClass(com.sun.codemodel.JDefinedClass parentClass,
com.sun.codemodel.JVar $global_base_uri)
Generate a static member class that represents a WADL resource. |
protected abstract void |
generateClientFactoryMethod(com.sun.codemodel.JDefinedClass parentClass)
This method should create a static private method called CREATE_CLIENT_METHOD that generate the right factory code for this particular implementation |
protected void |
generateConditionalForFaultNode(MethodNode method,
com.sun.codemodel.JBlock $methodBody,
com.sun.codemodel.JVar $response,
com.sun.codemodel.JType returnType,
com.sun.codemodel.JExpression $returnTypeExpr)
Generates the switch block based on status code that will throw exceptions for a specified failure |
protected com.sun.codemodel.JDefinedClass |
generateExceptionClass(FaultNode f)
Create an exception class that wraps an element used for indicating a fault condition. |
protected abstract com.sun.codemodel.JDefinedClass |
generateExceptionClassInternal(String exName,
FaultNode f)
Try to create a new exception class that is relevant for the platform |
protected void |
generateIfOnStatus(com.sun.codemodel.JBlock block,
com.sun.codemodel.JVar $response,
com.sun.codemodel.JType returnType,
com.sun.codemodel.JExpression $returnTypeExpr)
Create a if statement in a block that will throw an exception if the status is >= 400 is the returnType and return expression are not if the type clientReponseType |
protected void |
generateMethodDecl(Map<com.sun.codemodel.JType,com.sun.codemodel.JDefinedClass> exceptionMap,
MethodNode method,
boolean includeOptionalParams,
RepresentationNode inputRep,
RepresentationNode outputRep,
BaseResourceClassGenerator.MethodType methodType,
boolean isAbstract)
Generate a Java method for a specified combination of WADL method,
input representation and output representation
elements. |
void |
generateMethodDecls(MethodNode method,
boolean isAbstract)
Generate a set of method declarations for a WADL method element. |
protected void |
generateMethodVariants(Map<com.sun.codemodel.JType,com.sun.codemodel.JDefinedClass> exceptionMap,
MethodNode method,
boolean includeOptionalParams,
RepresentationNode inputRep,
RepresentationNode outputRep,
boolean isAbstract)
Generate one or two Java methods for a specified combination of WADL method,
input representation and output representation
elements. |
protected abstract void |
generateThrowWebApplicationExceptionFromResponse(com.sun.codemodel.JBlock caseBody,
com.sun.codemodel.JVar $response)
Invoked when we need to throw a generic failure exception because we don't have an element mapped. |
protected abstract com.sun.codemodel.JClass |
genericTypeType()
|
protected com.sun.codemodel.JDefinedClass |
getGeneratedClass()
Get the class for which methods will be generated. |
protected String |
getMethodName(MethodNode method,
RepresentationNode inputRep,
RepresentationNode outputRep,
com.sun.codemodel.JType returnType)
Generate a name for the method. |
protected com.sun.codemodel.JType |
getTypeFromElement(QName element)
Get the Java type generated for the specified XML element name. |
protected com.sun.codemodel.JType |
getTypeFromURI(String path)
Get the Java type generated for the specified JSON URI |
protected void |
overrideMessageOnException(com.sun.codemodel.JDefinedClass $exception)
Override the getMessage class on an exception to make sure the status code is displayed |
protected abstract com.sun.codemodel.JClass |
resourceBuilderType()
|
protected abstract String |
resourceFromClientMethod()
|
protected abstract com.sun.codemodel.JClass |
resourceType()
|
protected abstract String |
responseGetEntityMethod()
|
protected abstract com.sun.codemodel.JClass |
uriTemplateType()
|
protected com.sun.codemodel.JClass |
webApplicationExceptionType()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final String CREATE_CLIENT_METHOD
protected static final String CUSTOMIZE_CLIENT_METHOD
protected static final String CREATE_CLIENT_INSTANCE
protected com.sun.codemodel.JPackage pkg
protected com.sun.codemodel.JCodeModel codeModel
| Constructor Detail |
|---|
public BaseResourceClassGenerator(MessageListener messageListener,
Resolver resolver,
com.sun.codemodel.JCodeModel codeModel,
com.sun.codemodel.JPackage pkg,
String generatedPackages,
JavaDocUtil javaDoc,
ResourceNode resource)
javaDoc - a JavaDocUtil instance for use when generating documentation.resolver - the schema2java model to use for element to class mapping lookups.codeModel - code model instance to use when generating code.pkg - package for new classes.resource - the resource element for which to generate a class.
public BaseResourceClassGenerator(MessageListener messageListener,
Resolver resolver,
com.sun.codemodel.JCodeModel codeModel,
com.sun.codemodel.JPackage pkg,
String generatedPackages,
JavaDocUtil javaDoc,
com.sun.codemodel.JDefinedClass clazz)
javaDoc - a JavaDocUtil instance for use when generating documentation.resolver - the schema2java model to use for element to class mapping lookups.codeModel - code model instance to use when generating code.pkg - package for new classes.clazz - the existing class.| Method Detail |
|---|
protected abstract void generateClientFactoryMethod(com.sun.codemodel.JDefinedClass parentClass)
parentClass - The root class to add the method toprotected com.sun.codemodel.JDefinedClass getGeneratedClass()
protected abstract com.sun.codemodel.JClass clientType()
protected abstract com.sun.codemodel.JClass clientFactoryType()
protected abstract String clientFactoryMethod()
protected abstract com.sun.codemodel.JClass clientResponseClientType()
protected abstract com.sun.codemodel.JClass genericTypeType()
protected abstract com.sun.codemodel.JClass resourceType()
protected abstract com.sun.codemodel.JClass uriTemplateType()
protected abstract String resourceFromClientMethod()
protected abstract com.sun.codemodel.JClass resourceBuilderType()
protected abstract String buildMethod()
protected abstract String responseGetEntityMethod()
protected com.sun.codemodel.JClass webApplicationExceptionType()
protected void overrideMessageOnException(com.sun.codemodel.JDefinedClass $exception)
$exception -
protected abstract com.sun.codemodel.JVar createRequestBuilderAndAccept(com.sun.codemodel.JBlock $methodBody,
com.sun.codemodel.JVar $resource,
RepresentationNode outputRep)
protected abstract com.sun.codemodel.JExpression[] createProcessInvocation(MethodNode method,
com.sun.codemodel.JBlock $methodBody,
com.sun.codemodel.JVar $resourceBuilder,
String methodString,
RepresentationNode inputRep,
com.sun.codemodel.JType returnType,
com.sun.codemodel.JExpression $returnTypeExpr,
com.sun.codemodel.JExpression $entityExpr)
public com.sun.codemodel.JDefinedClass generateClass(com.sun.codemodel.JDefinedClass parentClass,
com.sun.codemodel.JVar $global_base_uri)
throws com.sun.codemodel.JClassAlreadyExistsException
generateClass in interface ResourceClassGeneratorparentClass - the parent class for the generated class.$global_base_uri - a reference to the field that contains the base URI.
com.sun.codemodel.JClassAlreadyExistsException - if a class with
the same name already exists.protected com.sun.codemodel.JDefinedClass generateExceptionClass(FaultNode f)
f - the WADL fault element for which to generate the exception class.
protected abstract com.sun.codemodel.JDefinedClass generateExceptionClassInternal(String exName,
FaultNode f)
throws com.sun.codemodel.JClassAlreadyExistsException
com.sun.codemodel.JClassAlreadyExistsException - should it already exists
protected abstract void generateThrowWebApplicationExceptionFromResponse(com.sun.codemodel.JBlock caseBody,
com.sun.codemodel.JVar $response)
protected void generateConditionalForFaultNode(MethodNode method,
com.sun.codemodel.JBlock $methodBody,
com.sun.codemodel.JVar $response,
com.sun.codemodel.JType returnType,
com.sun.codemodel.JExpression $returnTypeExpr)
protected void generateIfOnStatus(com.sun.codemodel.JBlock block,
com.sun.codemodel.JVar $response,
com.sun.codemodel.JType returnType,
com.sun.codemodel.JExpression $returnTypeExpr)
block - $response -
public void generateMethodDecls(MethodNode method,
boolean isAbstract)
method element.
Generates two Java methods per returned representation type for each request type, one with all optional parameters and one without. I.e. if the WADL method specifies two possible request representation formats and three supported response representation formats, this method will generate twelve Java methods, one for each combination.
generateMethodDecls in interface ResourceClassGeneratorisAbstract - controls whether the generated methods will have a body false
or not true.method - the WADL method element to process.protected com.sun.codemodel.JType getTypeFromElement(QName element)
Note that the specified element must be declared as a top-level element in a
schema imported by the WADL file otherwise no such Java type will have been
generated and this method will return Object.
element - the name of the XML element.
null
if no matching generated type was found.protected com.sun.codemodel.JType getTypeFromURI(String path)
null
if no matching generated type was found.
protected void generateMethodVariants(Map<com.sun.codemodel.JType,com.sun.codemodel.JDefinedClass> exceptionMap,
MethodNode method,
boolean includeOptionalParams,
RepresentationNode inputRep,
RepresentationNode outputRep,
boolean isAbstract)
method,
input representation and output representation
elements. Always generates one method that works with DataSources and
generates an additional method that uses JAXB_MAPPING when XML representations are used
and the document element is specified.
isAbstract - controls whether the generated methods will have a body false
or not true.exceptionMap - maps generated types to the corresponding exception class. Used to generate the
throws clause for the method and the code to map output types to exceptions when
the output type is designated as a fault.method - the WADL method element for the Java method being generated.includeOptionalParams - whether to include optional parameters in the method signature or not.inputRep - the WADL representation element for the request format.outputRep - the WADL representation element for the response format.
protected String getMethodName(MethodNode method,
RepresentationNode inputRep,
RepresentationNode outputRep,
com.sun.codemodel.JType returnType)
method - the WADL method element for the Java method being generated.inputRep - the WADL representation element for the request format.outputRep - the WADL representation element for the response format.returnType - a reference to the Java return type.
protected void generateMethodDecl(Map<com.sun.codemodel.JType,com.sun.codemodel.JDefinedClass> exceptionMap,
MethodNode method,
boolean includeOptionalParams,
RepresentationNode inputRep,
RepresentationNode outputRep,
BaseResourceClassGenerator.MethodType methodType,
boolean isAbstract)
method,
input representation and output representation
elements.
methodType - BaseResourceClassGenerator.MethodTypeisAbstract - controls whether the generated methods will have a body false
or not true.exceptionMap - maps generated types to the corresponding exception class. Used to generate the
throws clause for the method and the code to map output types to exceptions when
the output type is designated as a fault.method - the WADL method element for the Java method being generated.includeOptionalParams - whether to include optional parameters in the method signature or not.inputRep - the WADL representation element for the request format.outputRep - the WADL representation element for the response format.
protected void generateBody(MethodNode method,
boolean isJAXB,
Map<com.sun.codemodel.JType,com.sun.codemodel.JDefinedClass> exceptionMap,
RepresentationNode outputRep,
com.sun.codemodel.JVar $genericMethodParameter,
boolean wrapInputTypeInJAXBElement,
com.sun.codemodel.JType inputType,
com.sun.codemodel.JType returnType,
com.sun.codemodel.JVar $resourceBuilder,
RepresentationNode inputRep,
com.sun.codemodel.JBlock $methodBody)
method - the method to generate a body for.isJAXB, - whether we are generating a generic of JAXB_MAPPING version.exceptionMap - the generated exceptions that the method can raise.outputRep - the output representation.$genericMethodParameter - TODO.wrapInputTypeInJAXBElement - If the JAX-B element is not @XmlRootElement we have to do more.returnType - the type of the method return.$resourceBuilder - TODO.inputRep - the input representation.$methodBody - a reference to the method body in which to generate code.
public void generateBeanProperty(com.sun.codemodel.JDefinedClass $impl,
List<Param> matrixParameters,
Param p,
boolean isAbstract)
generateBeanProperty in interface ResourceClassGenerator$impl - The class or interface to add the bean setter and getter to.p - the WADL parameter for which to create the setter and getter.isAbstract - controls whether a method body is created false or not true. Set to true
for interface methods, false for class methods.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||