use of com.webcohesion.enunciate.metadata.ClientName in project enunciate by stoicflame.
the class TypeNameForMethod method convert.
@Override
public String convert(TypeElement declaration) throws TemplateModelException {
String fqn = declaration.getQualifiedName().toString();
if (classConversions.containsKey(fqn)) {
return classConversions.get(fqn);
} else if (declaration.getKind() == ElementKind.ENUM) {
return "string";
} else if (isCollection(declaration) || isMap(declaration)) {
return "array";
}
AdapterType adapterType = JAXBUtil.findAdapterType(declaration, this.jaxbContext);
if (adapterType != null) {
return convert(adapterType.getAdaptingType());
}
String convertedPackage = convertPackage(this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration));
ClientName specifiedName = declaration.getAnnotation(ClientName.class);
String simpleName = specifiedName == null ? declaration.getSimpleName().toString() : specifiedName.value();
return "\\" + convertedPackage + getPackageSeparator() + simpleName;
}
use of com.webcohesion.enunciate.metadata.ClientName in project enunciate by stoicflame.
the class CSharpXMLClientModule method usesUnmappableElements.
protected boolean usesUnmappableElements() {
boolean usesUnmappableElements = false;
if (this.jaxwsModule != null && this.jaxwsModule.getJaxwsContext() != null) {
for (EndpointInterface ei : this.jaxwsModule.getJaxwsContext().getEndpointInterfaces()) {
Map<String, javax.lang.model.element.Element> paramsByName = new HashMap<String, javax.lang.model.element.Element>();
for (WebMethod webMethod : ei.getWebMethods()) {
for (WebParam webParam : webMethod.getWebParameters()) {
// no out or in/out non-header parameters!
if (webParam.isHeader()) {
// unique parameter names for all header parameters of a given ei
javax.lang.model.element.Element conflict = paramsByName.put(webParam.getElementName(), webParam);
if (conflict != null) {
warn("%s: C# requires that all header parameters defined in the same endpoint interface have unique names. This parameter conflicts with the one at %s.", positionOf(webParam), positionOf(conflict));
usesUnmappableElements = true;
}
DecoratedTypeMirror paramType = (DecoratedTypeMirror) webParam.getType();
if (paramType.isCollection()) {
warn("%s: C# can't handle header parameters that are collections.", positionOf(webParam));
usesUnmappableElements = true;
}
} else if (webParam.getMode() != javax.jws.WebParam.Mode.IN) {
warn("%s: C# doesn't support non-header parameters of mode %s.", positionOf(webParam), webParam.getMode());
usesUnmappableElements = true;
}
// parameters/results can't be maps
if (webParam.getType() instanceof MapType) {
warn("%s: C# can't handle parameter types that are maps.", positionOf(webParam));
usesUnmappableElements = true;
}
}
// web result cannot be a header.
if (webMethod.getWebResult().isHeader()) {
javax.lang.model.element.Element conflict = paramsByName.put(webMethod.getWebResult().getElementName(), webMethod);
if (conflict != null) {
warn("%s: C# requires that all header parameters defined in the same endpoint interface have unique names. This return parameter conflicts with the one at %s.", positionOf(webMethod), positionOf(conflict));
usesUnmappableElements = true;
}
}
if (webMethod.getWebResult().getType() instanceof MapType) {
warn("%s: C# can't handle return types that are maps.", positionOf(webMethod));
usesUnmappableElements = true;
}
if (ElementUtils.capitalize(webMethod.getClientSimpleName()).equals(ei.getClientSimpleName())) {
warn("%s: C# can't handle methods that are of the same name as their containing class. Either rename the method, or use the @org.codehaus.enunciate.ClientName annotation to rename the method (or type) on the client-side.", positionOf(webMethod));
usesUnmappableElements = true;
}
}
}
}
if (this.jaxbModule != null && this.jaxbModule.getJaxbContext() != null && !this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
for (TypeDefinition complexType : schemaInfo.getTypeDefinitions()) {
for (Attribute attribute : complexType.getAttributes()) {
if (ElementUtils.capitalize(attribute.getClientSimpleName()).equals(complexType.getClientSimpleName())) {
warn("%s: C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename the property/field on the client-side.", positionOf(attribute));
usesUnmappableElements = true;
}
}
if (complexType.getValue() != null) {
if (ElementUtils.capitalize(complexType.getValue().getClientSimpleName()).equals(complexType.getClientSimpleName())) {
warn("%s: C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename the property/field on the client-side.", positionOf(complexType.getValue()));
usesUnmappableElements = true;
}
}
for (Element element : complexType.getElements()) {
if (ElementUtils.capitalize(element.getClientSimpleName()).equals(complexType.getClientSimpleName())) {
warn("%s: C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename the property/field on the client-side.", positionOf(element));
usesUnmappableElements = true;
}
if (element.getAccessorType() instanceof MapType && !element.isAdapted()) {
warn("%s: The C# client doesn't have a built-in way of serializing a Map. Use @XmlJavaTypeAdapter to supply your own adapter for the Map.", positionOf(element));
usesUnmappableElements = true;
}
}
if (complexType instanceof EnumTypeDefinition) {
List<VariableElement> enums = complexType.enumValues();
for (VariableElement enumItem : enums) {
if (isIgnored(enumItem)) {
continue;
}
String simpleName = enumItem.getSimpleName().toString();
ClientName clientNameInfo = enumItem.getAnnotation(ClientName.class);
if (clientNameInfo != null) {
simpleName = clientNameInfo.value();
}
if ("event".equals(simpleName)) {
warn("%s: C# can't handle an enum constant named 'Event'. Either rename the enum constant, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename it on the client-side.", positionOf(enumItem));
usesUnmappableElements = true;
} else if (simpleName.equals(complexType.getClientSimpleName())) {
warn("C# can't handle properties/fields that are of the same name as their containing class. Either rename the property/field, or use the @com.webcohesion.enunciate.metadata.ClientName annotation to rename the property/field on the client-side.", positionOf(enumItem));
usesUnmappableElements = true;
}
}
}
if (ElementUtils.isMap(complexType)) {
warn("%s: C# client doesn't handles types that implement java.util.Map. Use @XmlJavaTypeAdapter to supply your own adapter for the Map.", positionOf(complexType));
usesUnmappableElements = true;
}
}
}
}
return usesUnmappableElements;
}
use of com.webcohesion.enunciate.metadata.ClientName in project enunciate by stoicflame.
the class ClientClassnameForMethod method convert.
@Override
public String convert(TypeElement declaration) throws TemplateModelException {
String fqn = declaration.getQualifiedName().toString();
if (classConversions.containsKey(fqn)) {
return classConversions.get(fqn);
} else if (isCollection(declaration)) {
return "global::System.Collections.ArrayList";
}
AdapterType adapterType = JAXBUtil.findAdapterType(declaration, this.jaxbContext);
if (adapterType != null) {
return convert(adapterType.getAdaptingType());
}
if (declaration.getKind() == ElementKind.CLASS) {
DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment());
if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) {
// for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement
return convert(superType);
}
}
String convertedPackage = convertPackage(this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration));
ClientName specifiedName = declaration.getAnnotation(ClientName.class);
String simpleName = specifiedName == null ? declaration.getSimpleName().toString() : specifiedName.value();
return convertedPackage + getPackageSeparator() + simpleName;
}
use of com.webcohesion.enunciate.metadata.ClientName in project enunciate by stoicflame.
the class EndpointImplementation method getClientSimpleName.
/**
* The simple name for client-side code generation.
*
* @return The simple name for client-side code generation.
*/
public String getClientSimpleName() {
String clientSimpleName = getSimpleName().toString();
ClientName clientName = getAnnotation(ClientName.class);
if (clientName != null) {
clientSimpleName = clientName.value();
}
return clientSimpleName;
}
use of com.webcohesion.enunciate.metadata.ClientName in project enunciate by stoicflame.
the class ClientClassnameForMethod method convert.
@Override
public String convert(TypeElement declaration) throws TemplateModelException {
if (classConversions.containsKey(declaration.getQualifiedName().toString())) {
return classConversions.get(declaration.getQualifiedName().toString());
} else if (isCollection(declaration)) {
return "com.google.gwt.core.client.JsArray";
}
TypeMirror adaptingType = jsonContext.findAdaptingType(declaration);
if (adaptingType != null) {
return convert(adaptingType);
}
if (declaration.getKind() == ElementKind.CLASS) {
DecoratedTypeMirror superType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(declaration.getSuperclass(), this.context.getProcessingEnvironment());
if (superType != null && superType.isInstanceOf(JAXBElement.class.getName())) {
// for client conversions, we're going to generalize subclasses of JAXBElement to JAXBElement
return convert(superType);
}
}
String convertedPackage = convertPackage(this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration));
ClientName specifiedName = declaration.getAnnotation(ClientName.class);
String simpleName = specifiedName == null ? declaration.getSimpleName().toString() : specifiedName.value();
return convertedPackage + getPackageSeparator() + simpleName;
}
Aggregations