Package org.codehaus.enunciate.apt

Examples of org.codehaus.enunciate.apt.EnunciateFreemarkerModel


  /**
   * tests getting the base type and enum values.
   */
  public void testBasic() throws Exception {
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    FreemarkerModel.set(model);
    ClassDeclaration decl = (ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.SimpleTypeSimpleContentBean");
    ComplexTypeDefinition type = new ComplexTypeDefinition(decl);
    model.add(type);

    EnumTypeDefinition bean1 = new EnumTypeDefinition((EnumDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.EnumBeanOne"));
    EnumTypeDefinition bean2 = new EnumTypeDefinition((EnumDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.EnumBeanTwo"));
    EnumTypeDefinition bean3 = new EnumTypeDefinition((EnumDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.EnumBeanThree"));

View Full Code Here


   * see https://jira.codehaus.org/browse/ENUNCIATE-626
   */
  public void testAdaptingSubclassedAdapter() throws Exception {
    TypeDeclaration decl = getDeclaration("org.codehaus.enunciate.samples.anotherschema.BeanWithPropertyAdaptedBySubclass");
    ComplexTypeDefinition ct = new ComplexTypeDefinition((ClassDeclaration) decl);
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    FreemarkerModel.set(model);
    model.add(ct);
    Element el = ct.getElements().first();
    assertEquals(KnownXmlType.LONG.getQname(), el.getBaseType().getQname());
//    assertEquals("org.codehaus.enunciate.samples.anotherschema.BeanTwo", ((DeclaredType) el.getAdapterType().getAdaptedType()).getDeclaration().getQualifiedName());
  }
View Full Code Here

   * see https://jira.codehaus.org/browse/ENUNCIATE-514
   */
  public void testAdaptingIfaceToImpl() throws Exception {
    TypeDeclaration decl = getDeclaration("org.codehaus.enunciate.samples.schema.BeanWithAdaptedIfaceAccessor");
    ComplexTypeDefinition ct = new ComplexTypeDefinition((ClassDeclaration) decl);
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    FreemarkerModel.set(model);
    model.add(ct);
    Element el = ct.getElements().first();
    assertEquals(new QName("urn:adaptediface", "adaptediface"), el.getBaseType().getQname());
//    assertEquals("org.codehaus.enunciate.samples.anotherschema.BeanTwo", ((DeclaredType) el.getAdapterType().getAdaptedType()).getDeclaration().getQualifiedName());
  }
View Full Code Here

  /**
   * tests getting the base xml type of the accessor.
   */
  public void testGetBaseType() throws Exception {
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    FreemarkerModel.set(model);

    ArrayList<QName> baseTypes = new ArrayList<QName>();
    baseTypes.add(new QName("http://www.w3.org/2001/XMLSchema", "ID"));
    baseTypes.add(new QName("http://www.w3.org/2001/XMLSchema", "IDREF"));
View Full Code Here

  /**
   * tests getting the base type.
   */
  public void testBaseType() throws Exception {
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    FreemarkerModel.set(model);

    SimpleTypeDefinition simpleType = new SimpleTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.SimpleTypeSimpleContentBean"));
    XmlType baseType = simpleType.getBaseType();
    assertEquals(KnownXmlType.INT.getQname(), baseType.getQname());
View Full Code Here

      //load the references to the templates....
      URL amfEndpointTemplate = getTemplateURL("amf-endpoint.fmt");
      URL amfTypeTemplate = getTemplateURL("amf-type.fmt");
      URL amfTypeMapperTemplate = getTemplateURL("amf-type-mapper.fmt");

      EnunciateFreemarkerModel model = getModel();
      model.setFileOutputDirectory(serverGenerateDir);
      model.put("useSpringDI", this.springDIFound);

      TreeMap<String, String> packages = new TreeMap<String, String>(new Comparator<String>() {
        public int compare(String package1, String package2) {
          int comparison = package1.length() - package2.length();
          if (comparison == 0) {
            return package1.compareTo(package2);
          }
          return comparison;
        }
      });

      for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
          if (!isFacetExcluded(typeDefinition)) {
            String packageName = typeDefinition.getPackage().getQualifiedName();
            packages.put(packageName, packageName + ".amf");
          }
        }
      }

      debug("Generating the AMF externalizable types and their associated mappers...");
      AMFClassnameForMethod amfClassnameForMethod = new AMFClassnameForMethod(packages);
      model.put("simpleNameFor", new SimpleNameWithParamsMethod(amfClassnameForMethod));
      model.put("classnameFor", amfClassnameForMethod);
      for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
          if (!isFacetExcluded(typeDefinition)) {
            model.put("type", typeDefinition);
            processTemplate(amfTypeTemplate, model);
            processTemplate(amfTypeMapperTemplate, model);
          }
        }
      }

      debug("Generating the AMF endpoint beans...");
      for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
        for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
          if (!isFacetExcluded(ei)) {
            model.put("endpointInterface", ei);
            processTemplate(amfEndpointTemplate, model);
          }
        }
      }

      URL endpointTemplate = getTemplateURL("as3-endpoint.fmt");
      URL typeTemplate = getTemplateURL("as3-type.fmt");
      URL enumTypeTemplate = getTemplateURL("as3-enum-type.fmt");

      //build up the list of as3Aliases...
      HashMap<String, String> as3Aliases = new HashMap<String, String>();
      for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
          if (!isFacetExcluded(typeDefinition)) {
            as3Aliases.put(amfClassnameForMethod.convert(typeDefinition), typeDefinition.getClientSimpleName());
          }
        }
      }

      model.setFileOutputDirectory(clientGenerateDir);
      HashMap<String, String> conversions = new HashMap<String, String>();
      //todo: accept client-side package mappings?
      ClientPackageForMethod as3PackageFor = new ClientPackageForMethod(conversions);
      as3PackageFor.setUseClientNameConversions(true);
      model.put("packageFor", as3PackageFor);
      AS3UnqualifiedClassnameForMethod as3ClassnameFor = new AS3UnqualifiedClassnameForMethod(conversions);
      as3ClassnameFor.setUseClientNameConversions(true);
      model.put("classnameFor", as3ClassnameFor);
      model.put("simpleNameFor", new SimpleNameWithParamsMethod(as3ClassnameFor));
      ComponentTypeForMethod as3ComponentTypeFor = new ComponentTypeForMethod(conversions);
      as3ComponentTypeFor.setUseClientNameConversions(true);
      model.put("componentTypeFor", as3ComponentTypeFor);
      model.put("amfClassnameFor", amfClassnameForMethod);
      model.put("amfComponentTypeFor", new ComponentTypeForMethod(packages));
      model.put("forEachAS3Import", new ForEachAS3ImportTransform(null, as3ClassnameFor));
      model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
      model.put("as3Aliases", as3Aliases);

      debug("Generating the ActionScript types...");
      for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
          if (!isFacetExcluded(typeDefinition)) {
            model.put("type", typeDefinition);
            URL template = typeDefinition.isEnum() ? enumTypeTemplate : typeTemplate;
            processTemplate(template, model);
          }
        }
      }

      for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
        for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
          if (!isFacetExcluded(ei)) {
            model.put("endpointInterface", ei);
            processTemplate(endpointTemplate, model);
          }
        }
      }

      File servicesConfigXML = new File(xmlGenerateDir, "services-config.xml");
      URL servicesConfigTemplate = getTemplateURL("services-config-xml.fmt");

      model.setFileOutputDirectory(xmlGenerateDir);
      debug("Generating the configuration files.");
      processTemplate(servicesConfigTemplate, model);

      File mergeTarget = new File(xmlGenerateDir, "merged-services-config.xml");
      if (this.mergeServicesConfigXML != null) {
        URL servicesConfigXmlToMerge = enunciate.resolvePath(this.mergeServicesConfigXML).toURL();

        try {
          model.put("source1", loadMergeXmlModel(servicesConfigXmlToMerge.openStream()));
          model.put("source2", loadMergeXmlModel(new FileInputStream(servicesConfigXML)));
          processTemplate(getMergeServicesConfigXmlTemplateURL(), model);
        }
        catch (TemplateException e) {
          throw new EnunciateException("Error while merging services-config xml files.", e);
        }
View Full Code Here

  /**
   * tests getting the base type.
   */
  public void testGetBaseType() throws Exception {
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    FreemarkerModel.set(model);

    ComplexTypeDefinition complexContentType = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.BeanOne"));
    assertEquals(KnownXmlType.ANY_TYPE, complexContentType.getBaseType());
    model.add(complexContentType);
    ComplexTypeDefinition exComplexContentType = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.ExtendedBeanOne"));
    XmlType baseType = exComplexContentType.getBaseType();
    assertEquals(complexContentType.getName(), baseType.getName());
    assertEquals(complexContentType.getNamespace(), baseType.getNamespace());
  }
View Full Code Here

  /**
   * tests getting the content type of the complex type.
   */
  public void testGetContentType() throws Exception {
    EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
    FreemarkerModel.set(model);
    ComplexTypeDefinition simpleContentType = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.SimpleTypeComplexContentBean"));
    assertEquals(ContentType.SIMPLE, simpleContentType.getContentType());
    ComplexTypeDefinition complexContentType = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.BeanOne"));
    model.add(complexContentType);
    assertEquals(ContentType.IMPLIED, complexContentType.getContentType());
    ComplexTypeDefinition exComplexContentType = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.ExtendedBeanOne"));
    assertEquals(ContentType.COMPLEX, exComplexContentType.getContentType());
    ComplexTypeDefinition emptyContentType = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.BeanOne")) {
      @Override
View Full Code Here

    final Map<String, String> ns2prefix = new HashMap<String, String>();
    ns2prefix.put("urn:default", "default1");
    ns2prefix.put("urn:custom", "default2");

    final EnunciateFreemarkerModel model = new EnunciateFreemarkerModel() {
      @Override
      public Map<String, String> getNamespacesToPrefixes() {
        return ns2prefix;
      }
View Full Code Here

  }

  @Override
  public void doFreemarkerGenerate() throws IOException, TemplateException {
    if (!enunciate.isUpToDateWithSources(getWebInfDir())) {
      EnunciateFreemarkerModel model = getModel();

      //standard spring configuration:
      model.put("springImports", getSpringImportURIs());
      model.put("applicationContextFilename", getApplicationContextFilename());
      model.put("spring3", this.spring3);
      Object docsDir = enunciate.getProperty("docs.webapp.dir");
      if (docsDir == null) {
        docsDir = "";
      }
      model.put("docsDir", docsDir);
      if (!globalServiceInterceptors.isEmpty()) {
        for (GlobalServiceInterceptor interceptor : this.globalServiceInterceptors) {
          if ((interceptor.getBeanName() == null) && (interceptor.getInterceptorClass() == null)) {
            throw new IllegalStateException("A global interceptor must have either a bean name or a class set.");
          }
        }
        model.put("globalServiceInterceptors", this.globalServiceInterceptors);
      }
      if (!handlerInterceptors.isEmpty()) {
        for (HandlerInterceptor interceptor : this.handlerInterceptors) {
          if ((interceptor.getBeanName() == null) && (interceptor.getInterceptorClass() == null)) {
            throw new IllegalStateException("A handler interceptor must have either a bean name or a class set.");
          }
        }
        model.put("handlerInterceptors", this.handlerInterceptors);
      }

      model.setFileOutputDirectory(getWebInfDir());
      processTemplate(getApplicationContextTemplateURL(), model);

      copySpringConfig();

    }
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.