Package commonj.sdo.helper

Examples of commonj.sdo.helper.XMLHelper


  public DataObject2NodeInfoTransformer(Node2NodeInfoTransformer node2NodeInfoTransformer) {
    this.node2NodeInfoTransformer = node2NodeInfoTransformer;
  }

  public NodeInfo transform(DataObject source, TransformationContext context) {
    XMLHelper helper = HelperProvider.INSTANCE.xmlHelper();
    String name = null;
    if(source.getClass().getInterfaces().length > 0) {
      name = source.getClass().getInterfaces()[0].getSimpleName();
    } else {
      name = source.getClass().getName();
    }
   
    if(name.length() > 0) {
      name = Character.toLowerCase(name.charAt(0)) + name.substring(1, name.length());
    }
   
    DOMResult domResult = new DOMResult();
   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
      helper.save(source, null, name, baos);
      baos.flush();
      baos.close();
    } catch (IOException e) {
      throw new TransformationException(e);
    }
View Full Code Here


    public XMLStreamReader transform(DataObject source, TransformationContext context) {
        try {
            HelperContext helperContext = SDOContextHelper.getHelperContext(context);
            XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext);
            QName elementName = SDOContextHelper.getElement(context.getSourceDataType());
            XMLHelper xmlHelper = helperContext.getXMLHelper();
            XMLDocument document =
                    xmlHelper.createDocument(source, elementName.getNamespaceURI(), elementName.getLocalPart());
            return streamHelper.createXMLStreamReader(document);
        } catch (XMLStreamException e) {
            // TODO: Add context to the exception
            throw new TransformationException(e);
        }
View Full Code Here

        context = SDOUtil.createHelperContext();
        handler = new SDOWrapperHandler();
    }

    public void testWrapperAnyType() throws Exception {
        XMLHelper xmlHelper = context.getXMLHelper();
        XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml"));
        List children = handler.getChildren(document);
        assertEquals(5, children.size());
    }
View Full Code Here

    }

    public void testWrapper() throws Exception {
        XSDHelper xsdHelper = context.getXSDHelper();
        xsdHelper.define(getClass().getResourceAsStream("/wrapper.xsd"), null);
        XMLHelper xmlHelper = context.getXMLHelper();
        XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml"));
        List children = handler.getChildren(document);
        assertEquals(5, children.size());
    }
View Full Code Here

        // Root object
        objectOutput.writeByte(1);

        ByteArrayOutputStream compressedByteArrayOutputStream = new ByteArrayOutputStream();
        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(compressedByteArrayOutputStream);
        XMLHelper xmlHelperLocal = xmlHelper;
        if(objectOutput instanceof SDOObjectOutputStream)
        {
            xmlHelperLocal = ((SDOObjectOutputStream)objectOutput).getHelperContext().getXMLHelper();
        }
        xmlHelperLocal.save(dataObject, "commonj.sdo", "dataObject", gzipOutputStream);
        gzipOutputStream.close(); // Flush the contents

        byte[] byteArray = compressedByteArrayOutputStream.toByteArray();
        objectOutput.writeInt(byteArray.length);
        objectOutput.write(byteArray);
View Full Code Here

            }
            index += bytesRead;
        }
       
        GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(compressedBytes));
        XMLHelper xmlHelperLocal = xmlHelper;
        if (objectInput instanceof SDOObjectInputStream)
        {
            xmlHelperLocal = ((SDOObjectInputStream)objectInput).getHelperContext().getXMLHelper();
        }
        XMLDocument doc = xmlHelperLocal.load(gzipInputStream);
        gzipInputStream.close();

        return doc.getRootObject();
      }
      else
View Full Code Here

 
  public void testDefineDataType() throws Exception
  {
    TypeHelper types = hc.getTypeHelper();
    DataFactory factory = hc.getDataFactory();
    XMLHelper xmlHelper = hc.getXMLHelper();
    XSDHelper xsdHelper = hc.getXSDHelper();

    Property xmlElementProp = hc.getXSDHelper().getGlobalProperty("commonj.sdo/xml", "xmlElement", false);
    Property javaClassProperty = xsdHelper.getGlobalProperty("commonj.sdo/java", "javaClass", false);
   
    // create a data types
    DataObject intType = factory.create("commonj.sdo", "Type");
    intType.set("uri", "http://example.com/customer");
    intType.set("name", "MyIntType");
    intType.setBoolean("dataType", true);
    intType.set(javaClassProperty, "int");
   
    DataObject stringType = factory.create("commonj.sdo", "Type");
    stringType.set("uri", "http://example.com/customer");
    stringType.set("name", "MyStringType");
    stringType.setBoolean("dataType", true);
    stringType.set(javaClassProperty, "java.lang.String");
   
    // create a new Type for Customers
    DataObject customerType = factory.create("commonj.sdo",
    "Type");
    customerType.set("uri", "http://example.com/customer");
    customerType.set("name", "Customer");
   
    // create a customer number property
    DataObject custNumProperty = customerType.createDataObject("property");
    custNumProperty.set("name", "custNum");
    custNumProperty.set("type", intType);
    custNumProperty.setBoolean(xmlElementProp, false);

    // create a first name property
    DataObject firstNameProperty =
    customerType.createDataObject("property");
    firstNameProperty.set("name", "firstName");
    firstNameProperty.set("type", stringType);
    firstNameProperty.setBoolean(xmlElementProp, false);

    // create a last name property
    DataObject lastNameProperty = customerType.createDataObject("property");
    lastNameProperty.set("name", "lastName");
    lastNameProperty.set("type", stringType);
    lastNameProperty.setBoolean(xmlElementProp, false);

    // now define the Customer type so that customers can be made
    types.define(customerType);
   
    DataObject customer1 = factory.create("http://example.com/customer",
    "Customer");
   
    customer1.setInt("custNum", 1);
    customer1.set("firstName", "John");
    customer1.set("lastName", "Adams");
    DataObject customer2 = factory.create("http://example.com/customer",
    "Customer");
    customer2.setInt("custNum", 2);
    customer2.set("firstName", "Jeremy");
    customer2.set("lastName", "Pavick");
   
    assertNotNull(customer1);
    Type type = customer1.getType();
    assertNotNull(type.getProperty("custNum"));
    assertNotNull(type.getProperty("firstName"));
    assertNotNull(type.getProperty("lastName"));
    assertNotNull(type.getProperty("custNum"));
    assertNotNull(type.getProperty("firstName"));
    assertNotNull(type.getProperty("lastName"));
   
    type = type.getProperty("custNum").getType();
    assertEquals(type.getURI(), "http://example.com/customer");
    assertEquals(type.getName(), "MyIntType");
    assertTrue(type.isDataType());
   
    assertNotNull(customer2);
    assertNotNull(types.getOpenContentProperty("http://example.com/customer", "customer"));
   
    type = customer2.getType();
    assertNotNull(type.getProperty("custNum"));
    assertNotNull(type.getProperty("firstName"));
    assertNotNull(type.getProperty("lastName"));
    assertNotNull(type.getProperty("custNum"));
    assertNotNull(type.getProperty("firstName"));
    assertNotNull(type.getProperty("lastName"));
   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    xmlHelper.save(
      customer1,
      "http://example.com/customer",
      "Customer", baos);
    assertTrue(
      TestUtil.equalXmlFiles(
        new ByteArrayInputStream(baos.toByteArray()),
        getClass().getResource(CUSTOMER1_XML)));
   
    baos = new ByteArrayOutputStream();
    xmlHelper.save(
      customer2,
      "http://example.com/customer",
      "Customer", baos);
    assertTrue(
        TestUtil.equalXmlFiles(
View Full Code Here

 
  public void testFastDefineType() throws Exception
  {
    TypeHelper types = hc.getTypeHelper();
    DataFactory factory = hc.getDataFactory();
    XMLHelper xmlHelper = hc.getXMLHelper();

    Type intType = types.getType("commonj.sdo", "Int");
    Type stringType = types.getType("commonj.sdo", "String");
   
    // create a new Type for Customers
    Type customerType = SDOUtil.createType(hc, "http://example.com/customer", "Customer", false);

    // create a customer number property
    Property custNumProperty = SDOUtil.createProperty(customerType, "custNum", intType);
    SDOUtil.setPropertyXMLKind(custNumProperty, false);

    // create a first name property
    Property firstNameProperty = SDOUtil.createProperty(customerType, "firstName", stringType);
    SDOUtil.setPropertyXMLKind(firstNameProperty, false);

    // create a last name property
    Property lastNameProperty = SDOUtil.createProperty(customerType, "lastName", stringType);
    SDOUtil.setPropertyXMLKind(lastNameProperty, false);

    DataObject customer1 = factory.create("http://example.com/customer",
    "Customer");
    customer1.setInt("custNum", 1);
    customer1.set("firstName", "John");
    customer1.set("lastName", "Adams");
    DataObject customer2 = factory.create("http://example.com/customer",
    "Customer");
    customer2.setInt("custNum", 2);
    customer2.set("firstName", "Jeremy");
    customer2.set("lastName", "Pavick");
   
    assertNotNull(customer1);
    Type type = customer1.getType();
    assertNotNull(type.getProperty("custNum"));
    assertNotNull(type.getProperty("firstName"));
    assertNotNull(type.getProperty("lastName"));
    assertEquals(type.getProperty("custNum").getType(), intType);
    assertEquals(type.getProperty("firstName").getType(), stringType);
    assertEquals(type.getProperty("lastName").getType(), stringType);
   
    assertNotNull(customer2);
    type = customer2.getType();
    assertNotNull(type.getProperty("custNum"));
    assertNotNull(type.getProperty("firstName"));
    assertNotNull(type.getProperty("lastName"));
    assertEquals(type.getProperty("custNum").getType(), intType);
    assertEquals(type.getProperty("firstName").getType(), stringType);
    assertEquals(type.getProperty("lastName").getType(), stringType)
   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    xmlHelper.save(
      customer1,
      "http://example.com/customer",
      "Customer", baos);
    assertTrue(
      TestUtil.equalXmlFiles(
        new ByteArrayInputStream(baos.toByteArray()),
        getClass().getResource(CUSTOMER1_XML)));
   
    baos = new ByteArrayOutputStream();
    xmlHelper.save(
      customer2,
      "http://example.com/customer",
      "Customer", baos);
    assertTrue(
        TestUtil.equalXmlFiles(
View Full Code Here

  public void testDefineSequencedType() throws Exception
  {

    TypeHelper types = hc.getTypeHelper();
    DataFactory factory = hc.getDataFactory();
    XMLHelper xmlHelper = hc.getXMLHelper();
   
    Type stringType = types.getType("commonj.sdo", "String");
    Type decimalType = types.getType("commonj.sdo", "Decimal");
   
    // Define a new mixed type - MixedQuote
    DataObject mixedQuoteType = factory.create("commonj.sdo", "Type");
    mixedQuoteType.set("uri", "http://www.example.com/mixed");
    mixedQuoteType.set("name", "MixedQuote");
    mixedQuoteType.set("sequenced", Boolean.TRUE);
   
    DataObject symbolProperty = mixedQuoteType.createDataObject("property");
    symbolProperty.set("name", "symbol");
    symbolProperty.set("type", stringType);
   
    DataObject companyNameProperty = mixedQuoteType.createDataObject("property");
    companyNameProperty.set("name", "companyName");
    companyNameProperty.set("type", stringType);
   
    DataObject priceProperty = mixedQuoteType.createDataObject("property");
    priceProperty.set("name", "price");
    priceProperty.set("type", decimalType);
   
    DataObject quotesProperty = mixedQuoteType.createDataObject("property");
    quotesProperty.set("name", "quotes");
    quotesProperty.set("type", mixedQuoteType);
    quotesProperty.set("many", Boolean.TRUE);
    quotesProperty.set("containment", Boolean.TRUE);
   
    types.define(mixedQuoteType);
   
    DataObject quote = factory.create("http://www.example.com/mixed", "MixedQuote");

    assertTrue(quote.getType().isSequenced());
   
    Sequence sequence = quote.getSequence();

    sequence.addText("\n  ");

    quote.setString("symbol", "fbnt");

    sequence.addText("\n  ");

    quote.setString("companyName", "FlyByNightTechnology");

    sequence.addText("\n  some text\n  ");

    DataObject child = quote.createDataObject("quotes");
    child.setBigDecimal("price", new BigDecimal("2000.0"));

    sequence.addText("\n  more text\n  ");

    // quote.setBigDecimal("price", new BigDecimal("1000.0"));
    sequence.add("price", new BigDecimal("1000.0"));

    sequence.addText("\n");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    xmlHelper.save(quote, "http://www.example.com/mixed", "mixedStockQuote", baos);
    assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(MIXED_XML)));
  }
View Full Code Here

 
  public void testDefineSequencedOpenType() throws Exception
  {
    TypeHelper types = hc.getTypeHelper();
    DataFactory factory = hc.getDataFactory();
    XMLHelper xmlHelper = hc.getXMLHelper();
   
    Type stringType = types.getType("commonj.sdo", "String");
    Type decimalType = types.getType("commonj.sdo", "Decimal");
   
    // Define a new mixed type - MixedQuote
    DataObject mixedQuoteType = factory.create("commonj.sdo", "Type");
    mixedQuoteType.set("uri", "http://www.example.com/mixed");
    mixedQuoteType.set("name", "MixedOpenQuote");
    mixedQuoteType.set("sequenced", Boolean.TRUE);
    mixedQuoteType.set("open", Boolean.TRUE);
   
//    DataObject symbolProperty = mixedQuoteType.createDataObject("property");
//    symbolProperty.set("name", "symbol");
//    symbolProperty.set("type", stringType);
   
    DataObject companyNameProperty = mixedQuoteType.createDataObject("property");
    companyNameProperty.set("name", "companyName");
    companyNameProperty.set("type", stringType);
   
    DataObject priceProperty = mixedQuoteType.createDataObject("property");
    priceProperty.set("name", "price");
    priceProperty.set("type", decimalType);
   
    DataObject quotesProperty = mixedQuoteType.createDataObject("property");
    quotesProperty.set("name", "quotes");
    quotesProperty.set("type", mixedQuoteType);
    quotesProperty.set("many", Boolean.TRUE);
    quotesProperty.set("containment", Boolean.TRUE);
   
    types.define(mixedQuoteType);
   
    // Define a global type
    DataObject globalType = factory.create("commonj.sdo", "Type");
    globalType.set("uri", "http://www.example.com/open");
    // Don't set the type's name - null is used for types containing global properties.
   
    DataObject symbolProperty = globalType.createDataObject("property");
    symbolProperty.set("name", "symbol");
    symbolProperty.set("type", stringType);
    symbolProperty.set("containment", Boolean.TRUE);
   
    types.define(globalType);
   
    DataObject quote = factory.create("http://www.example.com/mixed", "MixedOpenQuote");

    assertTrue(quote.getType().isSequenced());
   
    Sequence sequence = quote.getSequence();

    sequence.addText("\n  ");

    Type definedGlobalType = types.getType("http://www.example.com/open", "DocumentRoot");
   
    Property definedSymbolProperty = definedGlobalType.getProperty("symbol");
    quote.setString(definedSymbolProperty, "fbnt");

    sequence.addText("\n  ");

    quote.setString("companyName", "FlyByNightTechnology");

    sequence.addText("\n  some text\n  ");

    DataObject child = quote.createDataObject("quotes");
    child.setBigDecimal("price", new BigDecimal("2000.0"));

    sequence.addText("\n  more text\n  ");

    // quote.setBigDecimal("price", new BigDecimal("1000.0"));
    sequence.add("price", new BigDecimal("1000.0"));

    sequence.addText("\n");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    xmlHelper.save(quote, "http://www.example.com/mixed", "mixedOpenStockQuote", baos);
    assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(MIXEDOPEN_XML)));
  }
View Full Code Here

TOP

Related Classes of commonj.sdo.helper.XMLHelper

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.