/** * Only specific enums should be added to the schema; most enums in the * model should not. This method returns true for enums that should be * added to the schema, and false for enums that should not. */ public boolean isSchemaEnum(Type type) { return SCHEMA_ENUMS.contains(type.getName()); }
private String getName(Type type) { return names.getCapitalized(type.getName()); }
private String getMemberSchemaTypeName(Type declaringType, Type memberType, Name memberName) { String exception = getMemberSchemaTypeNameException(declaringType.getName(), memberName); if (exception != null) { return exception; } return schemaNames.getSchemaTypeName(memberType); }
private String getAttributePath(List<MemberInvolvementTree> list, String paramName, Operator operator) { StringBuilder attributePath = new StringBuilder(); for (int i=0; i<list.size(); i++) { MemberInvolvementTree current = list.get(i); attributePath.append(isOrGet(current.getType())).append(javaNames.getJavaClassStyleName(current.getName())).append("()"); if (current.isCollection()) { Name name = ((ListType)current.getType()).getElementType().getName(); String getterName = javaNames.getJavaClassStyleName(name) + "s"; if (i==list.size()-1) { //the last element of the expression is a collection StringBuilder soFar = new StringBuilder(paramName).append(attributePath).append(".get").append(getterName).append("()"); if (operator==Operator.AND) { attributePath.append("!=null && ").append(soFar).append("!=null && "); attributePath.append(soFar).append(".size() > 0"); } else { attributePath.append("==null || ").append(soFar).append("==null || "); attributePath.append(soFar).append(".size() == 0"); } } else { attributePath.append(".get").append(getterName).append("().get(0)"); } } } return attributePath.toString(); }
private String getTypeRef(Type type) { if (type instanceof StructType || type instanceof PrimitiveType || type instanceof EnumType) { return type.getName().toString(); } if (type instanceof ListType) { ListType listType = (ListType) type; Type elementType = listType.getElementType(); return getTypeRef(elementType) + "[]"; } return ""; }
private String getTypeRef(Type type) { if (type instanceof StructType || type instanceof PrimitiveType || type instanceof EnumType) { return type.getName().toString(); } if (type instanceof ListType) { ListType listType = (ListType) type; Type elementType = listType.getElementType(); return getTypeRef(elementType) + "[]"; } return ""; }
private JavaClassName getTypeName(Type type, String packageName, Name prefix, Name suffix) { if (type instanceof PrimitiveType) { return getPrimitiveTypeName((PrimitiveType) type, true); } if (type instanceof StructType || type instanceof EnumType) { Name name = decorateName(type.getName(), prefix, suffix); JavaClassName typeName = new JavaClassName(); typeName.setPackageName(packageName); typeName.setSimpleName(javaNames.getJavaClassStyleName(name)); return typeName; } throw new RuntimeException("Don't know how to calculate the Java type name for type \"" + type + "\""); }
private JavaTypeReference getXjcListTypeReference(ListType type) { Type elementType = type.getElementType(); if (elementType instanceof StructType) { JavaTypeReference reference = new JavaTypeReference(); String text = getSchemaTypeName(names.getPlural(elementType.getName())); reference.setText(text); reference.addImport(javaPackages.getXjcPackageName(), text); return reference; } else { throw new RuntimeException("Don't know how to calculate the Java type reference for type \"" + type + "\""); } }
public String getSchemaTypeName(Type type) { Model model = type.getModel(); if (type == model.getBooleanType()) { return "xs:boolean"; } if (type == model.getStringType()) { return "xs:string"; } if (type == model.getIntegerType()) { return "xs:int"; } if (type == model.getDateType()) { return "xs:dateTime"; } if (type == model.getDecimalType()) { return "xs:decimal"; } if (type instanceof ListType) { ListType listType = (ListType) type; Type elementType = listType.getElementType(); return getSchemaTypeName(names.getPlural(elementType.getName())); } return getSchemaTypeName(type.getName()); }
private void generateValidationMethodName(Method method) { Parameter parameter = jaxrsGeneratorUtils.getMainAddParameter(method); javaBuffer.addImports(schemaNames.getXjcTypeReference(parameter.getType()).getImports()); javaBuffer.addLine("public static void validate%s(%s %s) {", javaNames.getJavaClassStyleName(method.getName()), javaNames.getJavaClassStyleName(parameter.getType().getName()), javaNames.getJavaMemberStyleName(parameter.getName())); }
private void handleSignature(Name parentMethodName, Method signature, Name parameterName, Type parameterType) { Parameter parameter = signature.getParameter(parameterName); Iterator<MemberInvolvementTree> iterator = parameter.getMandatoryAttributes().iterator(); if (iterator.hasNext()) {//if there are any mandatory attributes javaBuffer.addDocComment(signature.getName().toString()); javaBuffer.addLine("if (" +javaNames.getJavaMemberStyleName(parameter.getName()) + "!=null"); while (iterator.hasNext()) { MemberInvolvementTree attribute = iterator.next(); List<MemberInvolvementTree> list = stackAttributeComponents(attribute); String attributeCheck = getFullAttributeCheck(javaNames.getJavaMemberStyleName(parameter.getName()), list, Operator.AND, true); if (attribute.getAlternative()!=null) {//'or' expression list = stackAttributeComponents(attribute.getAlternative()); String alternativeCheck = getFullAttributeCheck(javaNames.getJavaMemberStyleName(parameter.getName()), list, Operator.AND, true); String fullCheck = mergeChecks(attributeCheck, alternativeCheck); javaBuffer.addLine(fullCheck); } else { javaBuffer.addLine(attributeCheck); } } javaBuffer.addLine(") {"); javaBuffer.addLine("return " + resourceName.getSimpleName() + ".class.getMethod(\"" + javaNames.getJavaMemberStyleName(parentMethodName) + javaNames.getJavaClassStyleName(signature.getName()) + "\", " + javaNames.getJavaClassStyleName(parameter.getType().getName()) + ".class);"); javaBuffer.addLine("}"); } }
private void generateSignatureDetection(Method method) { Set<Method> signatures = baseMethods.get(method); if (mandatoryAttributeExists(signatures)) { javaBuffer.addImport(java.lang.reflect.Method.class); Parameter parameter = jaxrsGeneratorUtils.getMainAddParameter(method); Name parameterName = parameter.getName(); javaBuffer.addImports(schemaNames.getXjcTypeReference(parameter.getType()).getImports()); Name methodName = getSignatureDetectionMethodName(method); javaBuffer.addLine("public static Method %s(%s %s) throws NoSuchMethodException, SecurityException {", javaNames.getJavaMemberStyleName(methodName), javaNames.getJavaClassStyleName(parameter.getType().getName()), javaNames.getJavaMemberStyleName(parameterName)); generateParameterValidation(parameter); CyclicIterator iterator = new CyclicIterator(signatures); while (iterator.hasNext()) { Method signature = iterator.next(); if (!jaxrsHelperGeneratorUtils.isContained(signature, signatures)) { handleSignature(method.getName(), signature, parameterName, parameter.getType()); iterator.remove(); } } closeSignatureDetectionMethod(); } //TODO: in the future fail for this // else { // throw new ValidationException(method.getName() + "'s signatures have 0 mandatory attributes (any signature must have at least 1 mandatory attribute)"); // } }
private void generateWriteMany(Type type) { Name singularName = type.getName(); Name pluralName = names.getPlural(singularName); String singularTag = schemaNames.getSchemaTagName(singularName);
writer.writeAttribute("type", schemaNames.getSchemaTypeName(names.getPlural(elementType.getName()))); writer.writeAttribute("minOccurs", "0"); writer.writeAttribute("maxOccurs", "1");
if (elementType instanceof StructType) { JavaClassName writerName = javaTypes.getXmlWriterName(elementType); String elementTag = schemaNames.getSchemaTagName(elementType.getName()); javaBuffer.addImport(writerName); javaBuffer.addLine(