Search in sources :

Example 1 with ApiClass

use of com.emc.apidocs.model.ApiClass in project coprhd-controller by CoprHD.

the class ApiClassDiffTests method main.

public static void main(String[] args) throws Exception {
    List<ApiField> sequenceA = Lists.newArrayList(newField("A"), newField("B"), newField("P"), newField("C"));
    List<ApiField> sequenceB = Lists.newArrayList(newField("A"), newField("B"), newField("E"), newField("D"), newField("C"));
    List<ApiField> diffList = generateMergedList(sequenceA, sequenceB);
    System.out.println("OUTPUT : ");
    for (ApiField s : diffList) {
        switch(s.changeState) {
            case NOT_CHANGED:
                System.out.print("- ");
                break;
            case REMOVED:
                System.out.print("< ");
                break;
            case ADDED:
                System.out.print("> ");
                break;
        }
        System.out.println(s.name);
    }
    ApiClass apiClass = new ApiClass();
    apiClass.fields = diffList;
    System.out.println("CONTAINS CHANGES :" + containsChanges(apiClass));
}
Also used : ApiClass(com.emc.apidocs.model.ApiClass) ApiField(com.emc.apidocs.model.ApiField)

Example 2 with ApiClass

use of com.emc.apidocs.model.ApiClass in project coprhd-controller by CoprHD.

the class EnunciateFileReader method loadTypes.

private Map<String, ApiClass> loadTypes(Document document) {
    Map<String, ApiClass> types = Maps.newHashMap();
    NodeList typeNodes = XMLUtils.getNodeList(document, EnunciateConstants.TYPE);
    for (int i = 0; i < typeNodes.getLength(); i++) {
        Node typeNode = typeNodes.item(i);
        ApiClass apiClass = toApiClass(typeNode);
        types.put(apiClass.name, apiClass);
    }
    return types;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ApiClass(com.emc.apidocs.model.ApiClass)

Example 3 with ApiClass

use of com.emc.apidocs.model.ApiClass in project coprhd-controller by CoprHD.

the class JaxbClassProcessor method convertToApiClass.

public static ApiClass convertToApiClass(ClassDoc classDoc) {
    ApiClass classDescriptor = new ApiClass();
    classDescriptor.name = AnnotationUtils.getAnnotationValue(classDoc, KnownAnnotations.XMLElement_Annotation, "name", null);
    if (classDescriptor.name == null) {
        classDescriptor.name = AnnotationUtils.getAnnotationValue(classDoc, KnownAnnotations.XMLRoot_Annotation, "name", classDoc.simpleTypeName());
    }
    ClassDoc currentClass = classDoc;
    while (currentClass.qualifiedName().startsWith("com.emc")) {
        String xmlAccessType = getXmlAccessType(classDoc);
        // Read Fields
        for (FieldDoc field : currentClass.fields(false)) {
            if (shouldIncludeField(field, xmlAccessType)) {
                ApiField fieldDescriptor = new ApiField();
                fieldDescriptor.name = AnnotationUtils.getAnnotationValue(field, KnownAnnotations.XMLElement_Annotation, "name", field.name());
                fieldDescriptor.required = AnnotationUtils.getAnnotationValue(field, KnownAnnotations.XMLElement_Annotation, "required", false);
                fieldDescriptor.description = field.commentText();
                if (AnnotationUtils.hasAnnotation(field, KnownAnnotations.XMLElementWrapper_Annotation)) {
                    fieldDescriptor.wrapperName = AnnotationUtils.getAnnotationValue(field, KnownAnnotations.XMLElementWrapper_Annotation, "name", Utils.lowerCaseFirstChar(field.name()));
                }
                addFieldType(field.type(), fieldDescriptor);
                addValidValues(field, fieldDescriptor);
                classDescriptor.addField(fieldDescriptor);
            }
            if (AnnotationUtils.hasAnnotation(field, KnownAnnotations.XMLAttribute_Annotation)) {
                ApiField attributeDescriptor = new ApiField();
                attributeDescriptor.name = AnnotationUtils.getAnnotationValue(field, KnownAnnotations.XMLAttribute_Annotation, "name", field.name());
                attributeDescriptor.required = AnnotationUtils.getAnnotationValue(field, KnownAnnotations.XMLAttribute_Annotation, "required", false);
                attributeDescriptor.description = field.commentText();
                addFieldType(field.type(), attributeDescriptor);
                addValidValues(field, attributeDescriptor);
                classDescriptor.addAttribute(attributeDescriptor);
            }
        }
        // Read Public Property Methods
        for (MethodDoc method : currentClass.methods()) {
            if (shouldIncludeMethod(method, xmlAccessType, currentClass)) {
                ApiField methodDescriptor = new ApiField();
                final String defaultName = method.name().startsWith("get") ? Utils.lowerCaseFirstChar(method.name().substring(3)) : method.name();
                final MemberDoc member = findJAXBAnnotatedMember(method);
                if (null == member) {
                    methodDescriptor.name = defaultName;
                    methodDescriptor.required = false;
                } else {
                    methodDescriptor.name = AnnotationUtils.getAnnotationValue(member, KnownAnnotations.XMLElement_Annotation, "name", defaultName);
                    methodDescriptor.required = AnnotationUtils.getAnnotationValue(member, KnownAnnotations.XMLElement_Annotation, "required", false);
                    if (AnnotationUtils.hasAnnotation(member, KnownAnnotations.XMLElementWrapper_Annotation)) {
                        methodDescriptor.wrapperName = AnnotationUtils.getAnnotationValue(member, KnownAnnotations.XMLElementWrapper_Annotation, "name", null);
                        if (methodDescriptor.wrapperName == null) {
                            if (method.name().startsWith("get")) {
                                methodDescriptor.wrapperName = Utils.lowerCaseFirstChar(method.name().substring(3));
                            } else if (method.name().startsWith("is")) {
                                methodDescriptor.wrapperName = Utils.lowerCaseFirstChar(method.name().substring(2));
                            } else {
                                throw new RuntimeException("Unable to work out JavaBean property name " + method.qualifiedName());
                            }
                        }
                    }
                }
                methodDescriptor.description = method.commentText();
                // process JsonProperty annotation
                String jsonName = AnnotationUtils.getAnnotationValue(method, KnownAnnotations.JsonProperty_Annotation, KnownAnnotations.Value_Element, null);
                if (jsonName != null) {
                    methodDescriptor.jsonName = jsonName;
                }
                addFieldType(method.returnType(), methodDescriptor);
                addValidValues(method, methodDescriptor);
                classDescriptor.addField(methodDescriptor);
            }
        }
        currentClass = currentClass.superclass();
    }
    return classDescriptor;
}
Also used : FieldDoc(com.sun.javadoc.FieldDoc) MethodDoc(com.sun.javadoc.MethodDoc) ApiClass(com.emc.apidocs.model.ApiClass) MemberDoc(com.sun.javadoc.MemberDoc) ApiField(com.emc.apidocs.model.ApiField) ClassDoc(com.sun.javadoc.ClassDoc)

Example 4 with ApiClass

use of com.emc.apidocs.model.ApiClass in project coprhd-controller by CoprHD.

the class EnunciateFileReader method loadType.

private ApiClass loadType(String name, Document document) {
    if (resolvedClasses.containsKey(name)) {
        return resolvedClasses.get(name);
    }
    Node typeNode = XMLUtils.getNode(document, XMLUtils.getXPath("//schema/types/type[@name=\"" + name + "\"]"));
    if (typeNode == null) {
        throw new RuntimeException("Type " + name + " not found in document");
    }
    ApiClass apiClass = toApiClass(typeNode);
    resolvedClasses.put(name, apiClass);
    System.out.println("Loaded Class " + name);
    return apiClass;
}
Also used : Node(org.w3c.dom.Node) ApiClass(com.emc.apidocs.model.ApiClass)

Example 5 with ApiClass

use of com.emc.apidocs.model.ApiClass in project coprhd-controller by CoprHD.

the class EnunciateFileReader method loadServices.

private Map<String, ApiService> loadServices(Document document) {
    Map<String, ApiClass> apiClasses = loadTypes(document);
    Map<String, ApiService> apiServices = Maps.newHashMap();
    NodeList resourceNodes = XMLUtils.getNodeList(document, EnunciateConstants.RESOURCES);
    for (int f = 0; f < resourceNodes.getLength(); f++) {
        Node resourceNode = resourceNodes.item(f);
        String serviceClass = XMLUtils.getNodeText(resourceNode, EnunciateConstants.RESOURCE_SERVICE_CLASS);
        ApiService apiService = null;
        if (apiClasses.containsKey(serviceClass)) {
            apiService = apiServices.get(serviceClass);
        } else {
            apiService = new ApiService();
            apiService.javaClassName = serviceClass;
            apiServices.put(serviceClass, apiService);
        }
        ApiMethod apiMethod = toApiMethod(resourceNode, apiClasses);
        System.out.println("Loaded Method " + serviceClass + " " + apiMethod.httpMethod + " " + apiMethod.path);
        apiService.addMethod(apiMethod);
    }
    return apiServices;
}
Also used : ApiService(com.emc.apidocs.model.ApiService) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ApiMethod(com.emc.apidocs.model.ApiMethod) ApiClass(com.emc.apidocs.model.ApiClass)

Aggregations

ApiClass (com.emc.apidocs.model.ApiClass)6 Node (org.w3c.dom.Node)4 ApiField (com.emc.apidocs.model.ApiField)3 NodeList (org.w3c.dom.NodeList)3 ApiMethod (com.emc.apidocs.model.ApiMethod)1 ApiService (com.emc.apidocs.model.ApiService)1 ClassDoc (com.sun.javadoc.ClassDoc)1 FieldDoc (com.sun.javadoc.FieldDoc)1 MemberDoc (com.sun.javadoc.MemberDoc)1 MethodDoc (com.sun.javadoc.MethodDoc)1