Package org.codehaus.enunciate.apt

Examples of org.codehaus.enunciate.apt.EnunciateFreemarkerModel


      URL jsonComplexTypeTemplate = getTemplateURL("json-complex-type.fmt");
      URL jsonSimpleTypeTemplate = getTemplateURL("json-simple-type.fmt");
      URL jsonEnumTypeTemplate = getTemplateURL("json-enum-type.fmt");

      EnunciateFreemarkerModel model = getModel();
      Map<String, String> conversions = getClientPackageConversions();
      ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions);
      classnameFor.setJdk15(true);
      model.put("packageFor", new ClientPackageForMethod(conversions));
      model.put("classnameFor", classnameFor);
      model.put("simpleNameFor", new SimpleNameWithParamsMethod(classnameFor));

      debug("Generating the Java client classes...");
      model.setFileOutputDirectory(getClientGenerateDir());
      HashMap<String, WebFault> allFaults = new HashMap<String, WebFault>();

      Set<String> seeAlsos = new TreeSet<String>();
      // Process the annotations, the request/response beans, and gather the set of web faults
      // for each endpoint interface.
      for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
        for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
          if (FacetFilter.accept(ei)) {
            for (WebMethod webMethod : ei.getWebMethods()) {
              if (FacetFilter.accept(webMethod)) {
                for (WebMessage webMessage : webMethod.getMessages()) {
                  if (webMessage instanceof RequestWrapper) {
                    model.put("message", webMessage);
                    processTemplate(requestBeanTemplate, model);
                    seeAlsos.add(getBeanName(classnameFor, ((RequestWrapper) webMessage).getRequestBeanName()));
                  }
                  else if (webMessage instanceof ResponseWrapper) {
                    model.put("message", webMessage);
                    processTemplate(responseBeanTemplate, model);
                    seeAlsos.add(getBeanName(classnameFor, ((ResponseWrapper) webMessage).getResponseBeanName()));
                  }
                  else if (webMessage instanceof WebFault) {
                    WebFault fault = (WebFault) webMessage;
                    allFaults.put(fault.getQualifiedName(), fault);
                  }
                }
              }
            }
          }
        }
      }

      //gather the annotation information and process the possible beans for each web fault.
      for (WebFault webFault : allFaults.values()) {
        boolean implicit = webFault.isImplicitSchemaElement();
        String faultBean = implicit ? getBeanName(classnameFor, webFault.getImplicitFaultBeanQualifiedName()) : classnameFor.convert(webFault.getExplicitFaultBeanType());
        seeAlsos.add(faultBean);

        if (implicit) {
          model.put("fault", webFault);
          processTemplate(faultBeanTemplate, model);
        }
      }

      model.put("seeAlsoBeans", seeAlsos);
      for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
        if (wsdlInfo.getProperty("filename") == null) {
          throw new EnunciateException("WSDL " + wsdlInfo.getId() + " doesn't have a filename.");
        }
        model.put("wsdlFileName", wsdlInfo.getProperty("filename"));

        for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
          if (FacetFilter.accept(ei)) {
            model.put("endpointInterface", ei);

            processTemplate(eiTemplate, model);
            processTemplate(soapImplTemplate, model);
          }
        }
      }

      AntPatternMatcher matcher = new AntPatternMatcher();
      matcher.setPathSeparator(".");
      for (WebFault webFault : allFaults.values()) {
        if (useServerSide(webFault, matcher)) {
          SourcePosition position = webFault.getPosition();
          if (position == null || position.file() == null) {
            throw new IllegalStateException("Unable to find source file for " + webFault.getQualifiedName());
          }
          File sourceFile = position.file();
          getEnunciate().copyFile(sourceFile, getServerSideDestFile(sourceFile, webFault));
        }
        else {
          ClassDeclaration superFault = webFault.getSuperclass().getDeclaration();
          if (superFault != null && allFaults.containsKey(superFault.getQualifiedName()) && allFaults.get(superFault.getQualifiedName()).isImplicitSchemaElement()) {
            model.put("superFault", allFaults.get(superFault.getQualifiedName()));
          }
          else {
            model.remove("superFault");
          }

          model.put("fault", webFault);
          processTemplate(faultTemplate, model);
        }
      }

      final Set<String> uniquePackages = new TreeSet<String>();
      for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
          if (FacetFilter.accept(typeDefinition)) {
            if (useServerSide(typeDefinition, matcher)) {
              SourcePosition position = typeDefinition.getPosition();
              if (position == null || position.file() == null) {
                throw new IllegalStateException("Unable to find source file for " + typeDefinition.getQualifiedName());
              }
              File sourceFile = position.file();
              getEnunciate().copyFile(sourceFile, getServerSideDestFile(sourceFile, typeDefinition));
            }
            else {
              model.put("rootEl", model.findRootElementDeclaration(typeDefinition));
              model.put("type", typeDefinition);
              URL template = typeDefinition.isEnum() ? typeDefinition instanceof QNameEnumTypeDefinition ? qnameEnumTypeTemplate : enumTypeTemplate : typeDefinition.isSimple() ? simpleTypeTemplate : complexTypeTemplate;
              processTemplate(template, model);
            }

            if (typeDefinition.getPackage() != null) {
              uniquePackages.add(typeDefinition.getPackage().getQualifiedName());
            }
          }
        }
        for (Registry registry : schemaInfo.getRegistries()) {
          model.put("registry", registry);
          processTemplate(registryTemplate, model);
        }
      }

      boolean generateJsonJar = isGenerateJsonJar();
      model.put("generateJson", generateJsonJar);
      if (generateJsonJar) {
        //first set up the json client package conversions.
        Map<String, String> jsonConversions = getJsonPackageConversions(uniquePackages);
        model.setFileOutputDirectory(getJsonClientGenerateDir());
        ClientClassnameForMethod jsonClassnameFor = new ClientClassnameForMethod(jsonConversions);
        jsonClassnameFor.setJdk15(true);
        model.put("packageFor", new ClientPackageForMethod(jsonConversions));
        model.put("classnameFor", jsonClassnameFor);
        model.put("simpleNameFor", new SimpleNameWithParamsMethod(jsonClassnameFor));

        debug("Generating the Java JSON client classes...");
        for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
          for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
            if (FacetFilter.accept(typeDefinition)) {
              model.put("type", typeDefinition);
              URL template = typeDefinition.isEnum() ? jsonEnumTypeTemplate : typeDefinition.isSimple() ? jsonSimpleTypeTemplate : jsonComplexTypeTemplate;
              processTemplate(template, model);
            }
          }
        }
View Full Code Here


  /**
   * test validating a simple type.
   */
  public void testValidateSimpleType() throws Exception {
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    FreemarkerModel.set(model);

    final Counter typeDefCounter = new Counter();
    DefaultValidator validator = new DefaultValidator() {
      @Override
      public ValidationResult validateTypeDefinition(TypeDefinition typeDef) {
        typeDefCounter.increment();
        return new ValidationResult();
      }
    };

    ComplexTypeDefinition complexType = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.SimpleTypeComplexContentBean"));
    model.add(complexType);
    SimpleTypeDefinition simpleType = new SimpleTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.SimpleTypeThatExtendsComplexType"));
    assertTrue("A simple type definition should not be valid if it exends a complex type.", validator.validateSimpleType(simpleType).hasErrors());
    assertEquals(1, typeDefCounter.getCount());

    simpleType = new SimpleTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.SimpleTypeWithoutAValue"));
View Full Code Here

  public void testValidateTypeDefinition() throws Exception {
    ClassDeclaration elementBeanOneDecl = (ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.ElementBeanOne");
    ComplexTypeDefinition elementBeanOneType = new ComplexTypeDefinition(elementBeanOneDecl);
    RootElementDeclaration elementBeanOne = new RootElementDeclaration(elementBeanOneDecl, elementBeanOneType);

    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    model.add(elementBeanOneType);
    model.add(elementBeanOne);
    FreemarkerModel.set(model);

    final Counter packageCounter = new Counter();
    final Counter attributeCounter = new Counter();
    final Counter valueCounter = new Counter();
View Full Code Here

  /**
   * tests validating an attribute.
   */
  public void testValidateAttribute() throws Exception {
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    model.add(new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.BeanOne")));
    FreemarkerModel.set(model);

    final Counter accessorCounter = new Counter();
    DefaultValidator validator = new DefaultValidator() {
      @Override
View Full Code Here

  /**
   * tests validating an value.
   */
  public void testValidateValue() throws Exception {
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    model.add(new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.BeanOne")));
    FreemarkerModel.set(model);

    final Counter accessorCounter = new Counter();
    DefaultValidator validator = new DefaultValidator() {
      @Override
View Full Code Here

  public void testBasicElementRef() throws Exception {
    ClassDeclaration elementBeanOneDecl = (ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.ElementBeanOne");
    ComplexTypeDefinition elementBeanOneType = new ComplexTypeDefinition(elementBeanOneDecl);
    RootElementDeclaration elementBeanOne = new RootElementDeclaration(elementBeanOneDecl, elementBeanOneType);

    EnunciateFreemarkerModel model = ((EnunciateFreemarkerModel) FreemarkerModel.get());
    model.add(elementBeanOneType);
    model.add(elementBeanOne);

    ComplexTypeDefinition typeDef = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.ElementRefBeanOne"));
    PropertyDeclaration property = findProperty(typeDef, "property1");
    ElementRef element = new ElementRef(property, typeDef);
    assertEquals(1, element.getChoices().size());
View Full Code Here

  /**
   * tests validating an element.
   */
  public void testValidateElement() throws Exception {
    FreemarkerModel.set(new EnunciateFreemarkerModel());
    final Counter accessorCounter = new Counter();
    DefaultValidator validator = new DefaultValidator() {
      @Override
      public ValidationResult validateAccessor(Accessor accessor) {
        accessorCounter.increment();
View Full Code Here

  /**
   * tests validating an element ref.
   */
  public void testValidateElementRef() throws Exception {
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    model.add(new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.ElementBeanOne")));
    FreemarkerModel.set(model);

    final Counter accessorCounter = new Counter();
    DefaultValidator validator = new DefaultValidator() {
      @Override
View Full Code Here

  public void testExplicitTypeElementRef() throws Exception {
    ClassDeclaration elementBeanOneDecl = (ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.ElementBeanOne");
    ComplexTypeDefinition elementBeanOneType = new ComplexTypeDefinition(elementBeanOneDecl);
    RootElementDeclaration elementBeanOne = new RootElementDeclaration(elementBeanOneDecl, elementBeanOneType);

    EnunciateFreemarkerModel model = ((EnunciateFreemarkerModel) FreemarkerModel.get());
    model.add(elementBeanOneType);
    model.add(elementBeanOne);

    ComplexTypeDefinition typeDef = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.ElementRefBeanOne"));
    PropertyDeclaration property = findProperty(typeDef, "property2");
    ElementRef element = new ElementRef(property, typeDef);
    assertEquals(1, element.getChoices().size());
View Full Code Here

  public void testJAXBElementRef() throws Exception {
    ClassDeclaration elementBeanOneDecl = (ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.ElementBeanOne");
    ComplexTypeDefinition elementBeanOneType = new ComplexTypeDefinition(elementBeanOneDecl);
    RootElementDeclaration elementBeanOne = new RootElementDeclaration(elementBeanOneDecl, elementBeanOneType);

    EnunciateFreemarkerModel model = ((EnunciateFreemarkerModel) FreemarkerModel.get());
    model.add(elementBeanOneType);
    model.add(elementBeanOne);

    ComplexTypeDefinition typeDef = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.ElementRefBeanOne"));
    PropertyDeclaration property = findProperty(typeDef, "property3");
    ElementRef element = new ElementRef(property, typeDef);
    assertEquals(1, element.getChoices().size());
View Full Code Here

TOP

Related Classes of org.codehaus.enunciate.apt.EnunciateFreemarkerModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.