Package org.codehaus.enunciate.config

Examples of org.codehaus.enunciate.config.SchemaInfo


    TypeDefinition typeDef1 = new ComplexTypeDefinition(declaration);
    RootElementDeclaration element1 = new RootElementDeclaration(declaration, typeDef1);
    String targetNamespace = element1.getNamespace();
    assertNull(model.findRootElementDeclaration(element1));
    model.add(element1);
    SchemaInfo schemaInfo = model.getNamespacesToSchemas().get(targetNamespace);
    assertNull("The element form default should not have been set.", schemaInfo.getElementFormDefault());
    assertNull("The attribute form default should not have been set.", schemaInfo.getAttributeFormDefault());
    assertNotNull("The model should have created a schema information associated with a new type definition.", schemaInfo);
    assertTrue(model.rootElements.contains(element1));
    assertNotNull(model.findRootElementDeclaration(element1));
    assertEquals(targetNamespace, schemaInfo.getNamespace());

    nsCount += 1;
    assertEquals("There should have been one and only one new namespace added", nsCount, model.getNamespacesToPrefixes().size());

    declaration = (ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.BeanThree");
    ComplexTypeDefinition typeDef2 = new ComplexTypeDefinition(declaration);
    RootElementDeclaration element2 = new RootElementDeclaration(declaration, typeDef2);
    targetNamespace = element2.getNamespace();
    assertNull(model.findRootElementDeclaration(element2));
    model.add(element2);
    schemaInfo = model.getNamespacesToSchemas().get(targetNamespace);
    assertNotNull("The model should have created a schema information associated with a new type definition.", schemaInfo);
    assertTrue(model.rootElements.contains(element2));
    assertNotNull(model.findRootElementDeclaration(element2));
    assertEquals(targetNamespace, schemaInfo.getNamespace());
    assertEquals("qualified", schemaInfo.getElementFormDefault());
    assertEquals("qualified", schemaInfo.getAttributeFormDefault());
    nsCount += 3;
    assertEquals("There should have been three new namespaces added, as specified in the package info for the schema.", nsCount, model.getNamespacesToPrefixes().size());

    declaration = (ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.BeanFour");
    ComplexTypeDefinition typeDef3 = new ComplexTypeDefinition(declaration);
    RootElementDeclaration element3 = new RootElementDeclaration(declaration, typeDef3);
    targetNamespace = element3.getNamespace();
    assertNull(model.findRootElementDeclaration(element3));
    model.add(element3);
    schemaInfo = model.getNamespacesToSchemas().get(targetNamespace);
    assertNotNull("The model should have created a schema information associated with a new type definition.", schemaInfo);
    assertTrue(model.rootElements.contains(element3));
    assertNotNull(model.findRootElementDeclaration(element3));
    assertEquals(targetNamespace, schemaInfo.getNamespace());
    assertEquals("There is no @XmlSchema annotation for this new namespace, so the elementFormDefault should be unset.", null, schemaInfo.getElementFormDefault());
    assertEquals("There is no @XmlSchema annotation for this new namespace, so the attributeFormDefault should be unset.", null, schemaInfo.getAttributeFormDefault());
    nsCount += 1;
    assertEquals("There should have been 1 new namespace added.", nsCount, model.getNamespacesToPrefixes().size());

    assertEquals(3, model.rootElements.size());
    assertEquals(0, model.typeDefinitions.size());
View Full Code Here


  /**
   * Tests the "doGenerate" logic.
   */
  public void testDoGenerate() throws Exception {
    SchemaInfo defaultSchemaInfo = new SchemaInfo();
    defaultSchemaInfo.setNamespace("urn:default");
    SchemaInfo customSchemaInfo = new SchemaInfo();
    customSchemaInfo.setNamespace("urn:custom");
    final Map<String, SchemaInfo> ns2schema = new HashMap<String, SchemaInfo>();
    ns2schema.put(defaultSchemaInfo.getNamespace(), defaultSchemaInfo);
    ns2schema.put(customSchemaInfo.getNamespace(), customSchemaInfo);

    WsdlInfo defaultWsdlInfo = new WsdlInfo();
    defaultWsdlInfo.setTargetNamespace("urn:default");
    WsdlInfo customWsdlInfo = new WsdlInfo();
    customWsdlInfo.setTargetNamespace("urn:custom");
    final Map<String, WsdlInfo> ns2wsdl = new HashMap<String, WsdlInfo>();
    ns2wsdl.put(defaultWsdlInfo.getTargetNamespace(), defaultWsdlInfo);
    ns2wsdl.put(customWsdlInfo.getTargetNamespace(), customWsdlInfo);

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

      @Override
      public Map<String, SchemaInfo> getNamespacesToSchemas() {
        return ns2schema;
      }

      @Override
      public Map<String, WsdlInfo> getNamespacesToWSDLs() {
        return ns2wsdl;
      }
    };

    final ArrayList<URL> processList = new ArrayList<URL>(Arrays.asList(XMLDeploymentModule.class.getResource("xml.fmt")));
    XMLDeploymentModule module = new XMLDeploymentModule() {
      @Override
      public EnunciateFreemarkerModel getModel() {
        return model;
      }

      @Override
      protected boolean isUpToDate(File artifactDir) {
        return false;
      }

      @Override
      public void processTemplate(URL templateURL, Object model) {
        processList.remove(templateURL);
      }
    };
    SchemaConfig customSchemaConfig = new SchemaConfig();
    customSchemaConfig.setFile("custom.xsd");
    customSchemaConfig.setLocation("urn:custom.xsd");
    customSchemaConfig.setNamespace("urn:custom");
    module.addSchemaConfig(customSchemaConfig);

    WsdlConfig wsdlConfig = new WsdlConfig();
    wsdlConfig.setNamespace("urn:custom");
    wsdlConfig.setFile("custom.wsdl");
    module.addWsdlConfig(wsdlConfig);

    Enunciate enunciate = new Enunciate(new String[0]);
    File generateDir = enunciate.createTempDir();
    enunciate.setGenerateDir(generateDir);
    module.init(enunciate);
    module.initModel(model);
    module.doFreemarkerGenerate();

    assertTrue("Not all templates were processed.  Unprocessed templates: " + processList.toString(), processList.isEmpty());
    assertEquals("default1.xsd", defaultSchemaInfo.getProperty("filename"));
    assertEquals("default1.xsd", defaultSchemaInfo.getProperty("location"));
    assertEquals("custom.xsd", customSchemaInfo.getProperty("filename"));
    assertEquals("urn:custom.xsd", customSchemaInfo.getProperty("location"));
    assertEquals("default1.wsdl", defaultWsdlInfo.getProperty("filename"));
    assertEquals("custom.wsdl", customWsdlInfo.getProperty("filename"));
    File artifactDir = new File(generateDir, "xml");
    assertEquals(new File(artifactDir, "default1.xsd"), defaultSchemaInfo.getProperty("file"));
    assertEquals(new File(artifactDir, "default1.wsdl"), defaultWsdlInfo.getProperty("file"));
    assertEquals(new File(artifactDir, "custom.xsd"), customSchemaInfo.getProperty("file"));
    assertEquals(new File(artifactDir, "custom.wsdl"), customWsdlInfo.getProperty("file"));

  }
View Full Code Here

  /**
   * tests the get.
   */
  public void testGet() throws Exception {
    SchemaInfo schemaInfo = new SchemaInfo();
    schemaInfo.setProperty("filename", "something.xsd");
    schemaInfo.setProperty("location", "http://localhost:8080/something.xsd");
    SchemaInfoModel model = new SchemaInfoModel(schemaInfo, new BeansWrapper());
    assertEquals("something.xsd", model.get("filename").toString());
    assertEquals("http://localhost:8080/something.xsd", model.get("location").toString());
  }
View Full Code Here

    else if ("alreadyExists".equals(key)) {
      return wrap(wsdlInfo.getProperty("file") != null);
    }
    else if ("importedNamespaces".equals(key)) {
      Set<String> importedNamespaces = wsdlInfo.getImportedNamespaces();
      SchemaInfo associatedSchema = wsdlInfo.getAssociatedSchema();
      Boolean inlineSchema = (Boolean) wsdlInfo.getProperty("inlineSchema");
      if (associatedSchema != null && inlineSchema != null && inlineSchema) {
        importedNamespaces.addAll(associatedSchema.getReferencedNamespaces());
      }
      return wrap(importedNamespaces);
    }
    else if ("importedSchemas".equals(key)) {
      TreeSet<SchemaInfo> schemas = new TreeSet<SchemaInfo>(new SchemaInfoComparator());
      schemas.addAll(wsdlInfo.getImportedSchemas());
      SchemaInfo associatedSchema = wsdlInfo.getAssociatedSchema();
      Boolean inlineSchema = (Boolean) wsdlInfo.getProperty("inlineSchema");
      if (associatedSchema != null && inlineSchema != null && inlineSchema) {
        schemas.addAll(associatedSchema.getImportedSchemas());
      }
      return wrap(schemas);
    }

    return super.get(key);
View Full Code Here

TOP

Related Classes of org.codehaus.enunciate.config.SchemaInfo

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.