Package org.codehaus.enunciate.apt

Examples of org.codehaus.enunciate.apt.EnunciateFreemarkerModel


  @Override
  public void doFreemarkerGenerate() throws IOException, TemplateException {
    File genDir = getGenerateDir();
    if (!isUpToDate(genDir)) {
      EnunciateFreemarkerModel model = getModel();
      model.put("Introspector", BeansWrapper.getDefaultInstance().getStaticModels().get("java.beans.Introspector"));
      Map<String, WsdlInfo> ns2wsdl = model.getNamespacesToWSDLs();

      URL requestBeanTemplate = JAXWSSupportDeploymentModule.class.getResource("request-bean.fmt");
      URL responseBeanTemplate = JAXWSSupportDeploymentModule.class.getResource("response-bean.fmt");
      URL faultBeanTemplate = JAXWSSupportDeploymentModule.class.getResource("fault-bean.fmt");

      TreeSet<WebFault> visitedFaults = new TreeSet<WebFault>(new TypeDeclarationComparator());
      for (WsdlInfo wsdlInfo : ns2wsdl.values()) {
        for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
          for (WebMethod webMethod : ei.getWebMethods()) {
            for (WebMessage webMessage : webMethod.getMessages()) {
              if (webMessage instanceof RequestWrapper) {
                model.put("message", webMessage);
                processTemplate(requestBeanTemplate, model);
              }
              else if (webMessage instanceof ResponseWrapper) {
                model.put("message", webMessage);
                processTemplate(responseBeanTemplate, model);
              }
              else if ((webMessage instanceof WebFault) && ((WebFault) webMessage).isImplicitSchemaElement() && visitedFaults.add((WebFault) webMessage)) {
                model.put("message", webMessage);
                processTemplate(faultBeanTemplate, model);
              }
            }
          }
        }
      }

      //we're going to process the JAX-RS thrown types annotated with @WebFault in case we ever want to serialize the fault beans as XML...
      for (RootResource rootResource : model.getRootResources()) {
        for (ResourceMethod resourceMethod : rootResource.getResourceMethods(true)) {
          for (ReferenceType referenceType : resourceMethod.getThrownTypes()) {
            if (!(referenceType instanceof DeclaredType)) {
              throw new ValidationException(resourceMethod.getPosition(), "Method " + resourceMethod + " of " + resourceMethod.getParent().getQualifiedName() + ": thrown type must be a declared type.");
            }

            TypeDeclaration declaration = ((DeclaredType) referenceType).getDeclaration();

            if (declaration == null) {
              throw new ValidationException(resourceMethod.getPosition(), "Method " + resourceMethod + " of " + resourceMethod.getParent().getQualifiedName() + ": unknown declaration for " + referenceType);
            }
            else if (declaration.getAnnotation(javax.xml.ws.WebFault.class) != null) {
              WebFault fault = new WebFault((ClassDeclaration) declaration);
              if (fault.isImplicitSchemaElement() && visitedFaults.add(fault)) {
                model.put("message", fault);
                processTemplate(faultBeanTemplate, model);
              }
            }
          }
        }
View Full Code Here


    jacksonAvailable |= classes.contains("org.codehaus.jackson.jaxrs.JacksonJsonProvider");
  }

  public void doFreemarkerGenerate() throws EnunciateException, IOException, TemplateException {
    if (!isUpToDate()) {
      EnunciateFreemarkerModel model = getModel();
      model.put("forName", new ClassForNameMethod());
      processTemplate(getRootResourceListTemplateURL(), model);
      processTemplate(getProvidersListTemplateURL(), model);
      processTemplate(getJaxbTypesTemplateURL(), model);

      Map<String, String> conentTypesToIds = model.getContentTypesToIds();
      Properties mappings = new Properties();
      for (Map.Entry<String, String> contentTypeToId : conentTypesToIds.entrySet()) {
        mappings.put(contentTypeToId.getValue(), contentTypeToId.getKey());
      }
      File file = new File(getGenerateDir(), "media-type-mappings.properties");
      FileOutputStream out = new FileOutputStream(file);
      mappings.store(out, "JAX-RS media type mappings.");
      out.flush();
      out.close();

      Map<String, String> ns2prefixes = model.getNamespacesToPrefixes();
      mappings = new Properties();
      for (Map.Entry<String, String> ns2prefix : ns2prefixes.entrySet()) {
        mappings.put(ns2prefix.getKey() == null ? "" : ns2prefix.getKey(), ns2prefix.getValue());
      }
      if (this.defaultNamespace != null) {
View Full Code Here

  /**
   * Tests finding the specified type of a given declaration.
   */
  public void testFindSpecifiedType() throws Exception {
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    FreemarkerModel.set(model);

    model.add(new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.AdaptedBeanTwo")));

    ClassDeclaration adaptedBeanExamplesDeclaration = (ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.AdaptedBeanExamples");
    ComplexTypeDefinition examples = new ComplexTypeDefinition(adaptedBeanExamplesDeclaration);
    Accessor beanOneField = null;
    Accessor beanThreeField = null;
View Full Code Here

  /**
   * Getting the xml type for a specified type.
   */
  public void testGetXmlType() throws Exception {
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    FreemarkerModel.set(model);

    DeclaredType stringType = Context.getCurrentEnvironment().getTypeUtils().getDeclaredType(getDeclaration("java.lang.String"));
    XmlType stringXmlType = XmlTypeFactory.getXmlType(stringType);
    assertSame(KnownXmlType.STRING, stringXmlType);
    assertSame(stringXmlType, XmlTypeFactory.getXmlType(String.class));

    ClassDeclaration decl = (ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.BeanThree");
    ComplexTypeDefinition definition = new ComplexTypeDefinition(decl);
    model.add(definition);
    DeclaredType beanThreeType = Context.getCurrentEnvironment().getTypeUtils().getDeclaredType(decl);
    assertNotNull("The xml type for bean three should have been created.", XmlTypeFactory.getXmlType(beanThreeType));
  }
View Full Code Here

  public void testMergeWebXml() throws Exception {
    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    final PrintWriter out = new PrintWriter(bytesOut);

    BasicAppModule module = new BasicAppModule();
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    EnunciateFileTransform transform = new EnunciateFileTransform(null) {
      @Override
      public FileStrategy newStrategy() {
        return new EnunciateFileStrategy(null) {
          @Override
          public PrintWriter getWriter() throws IOException, MissingParameterException {
            return out;
          }
        };
      }
    };
    model.put("file", transform);
    Document src1 = new BasicAppModule().loadMergeXml(TestMergeWebXml.class.getResourceAsStream("web.1.xml"));
    NodeModel.simplify(src1);
    model.put("source1", NodeModel.wrap(src1.getDocumentElement()));
    Document src2 = new BasicAppModule().loadMergeXml(TestMergeWebXml.class.getResourceAsStream("web.2.xml"));
    NodeModel.simplify(src2);
    model.put("source2", NodeModel.wrap(src2.getDocumentElement()));
    module.processTemplate(BasicAppModule.class.getResource("merge-web-xml.fmt"), model);
    src2 = new BasicAppModule().loadMergeXml(TestMergeWebXml.class.getResourceAsStream("web.3.xml"));
    NodeModel.simplify(src2);
    model.put("source2", NodeModel.wrap(src2.getDocumentElement()));
    module.processTemplate(BasicAppModule.class.getResource("merge-web-xml.fmt"), model);
    src2 = new BasicAppModule().loadMergeXml(TestMergeWebXml.class.getResourceAsStream("web.4.xml"));
    NodeModel.simplify(src2);
    model.put("source1", NodeModel.wrap(src2.getDocumentElement()));
    model.put("source2", NodeModel.wrap(src1.getDocumentElement()));
    module.processTemplate(BasicAppModule.class.getResource("merge-web-xml.fmt"), model);

    //todo: better tests?
    assertTrue(bytesOut.size() > 0);
    //uncomment to see what's being written.
View Full Code Here

  public void testMergePetclinicWebXml() throws Exception {
    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    final PrintWriter out = new PrintWriter(bytesOut);

    BasicAppModule module = new BasicAppModule();
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    EnunciateFileTransform transform = new EnunciateFileTransform(null) {
      @Override
      public FileStrategy newStrategy() {
        return new EnunciateFileStrategy(null) {
          @Override
          public PrintWriter getWriter() throws IOException, MissingParameterException {
            return out;
          }
        };
      }
    };
    model.put("file", transform);
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(false);
    NodeModel.setDocumentBuilderFactory(builderFactory);
    model.put("source1", new BasicAppModule().loadMergeXml(TestMergeWebXml.class.getResourceAsStream("web.1.xml")));
    model.put("source2", new BasicAppModule().loadMergeXml(TestMergeWebXml.class.getResourceAsStream("petclinic.web.xml")));
    module.processTemplate(BasicAppModule.class.getResource("merge-web-xml.fmt"), model);

    //todo: better tests?
    assertTrue(bytesOut.size() > 0);
    //uncomment to see what's being written.
View Full Code Here

  /**
   * getting the referenced namespaces of the schema info.
   */
  public void testGetReferencedNamespaces() throws Exception {
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    FreemarkerModel.set(model);

    final ComplexTypeDefinition beanThree = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.BeanThree"));
    final ComplexTypeDefinition beanFour = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.BeanFour"));
    final ComplexTypeDefinition simpleTypeComplexContentBean = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.SimpleTypeComplexContentBean"));
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.