Examples of XMLType


Examples of org.teiid.core.types.XMLType

     * @return Outgoing value of target type
     * @throws TransformationException if value is an incorrect input type or
     * the transformation fails
     */
    public Object transformDirect(Object value) throws TransformationException {
        XMLType source = (XMLType)value;
        Reader reader = null;
        try {      
            char[] result = new char[DataTypeManager.MAX_STRING_LENGTH];
            reader = source.getCharacterStream();
            int read = reader.read(result);
            return new String(result, 0, read);
        } catch (SQLException e) {
            throw new TransformationException(e, CorePlugin.Util.getString("failed_convert", new Object[] {getSourceType().getName(), getTargetType().getName()})); //$NON-NLS-1$           
        } catch (IOException e) {
View Full Code Here

Examples of org.teiid.core.types.XMLType

    public void testXMLValue() throws Exception {
        String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$
        SQLXMLImpl xml = new SQLXMLImpl(testString);
       
        XMLType xv = new XMLType(xml);
        assertEquals(testString, xv.getString());
    }
View Full Code Here

Examples of org.teiid.core.types.XMLType

   
    public void testXMLValuePersistence() throws Exception {
        String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$
        SQLXMLImpl xml = new SQLXMLImpl(testString);
       
        XMLType xv = new XMLType(xml);
        String key = xv.getReferenceStreamId();
       
        // now force to serialize
        File saved = new File(UnitTestUtil.getTestScratchPath()+"/xmlsaved.bin"); //$NON-NLS-1$
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(saved));
        out.writeObject(xv);
        out.close();
       
        // now read back the object from serilized state
        ObjectInputStream in = new ObjectInputStream(new FileInputStream(saved));
        XMLType read = (XMLType)in.readObject();
               
        // make sure we have kept the reference stream id
        assertEquals(key, read.getReferenceStreamId());
       
        // and lost the original object
        assertNull(read.getReference());
       
        saved.delete();
    }
View Full Code Here

Examples of org.teiid.core.types.XMLType

        throw new TeiidProcessingException(e);
      } catch (IOException e) {
        fs.remove();
        throw new TeiidProcessingException(e);
      }
          XMLType result = new XMLType(new SQLXMLImpl(fsisf));
          result.setType(Type.CONTENT);
          return result;
    }
View Full Code Here

Examples of org.teiid.core.types.XMLType

    }
    if (!valueExists) {
      return null;
    }

    XMLType result = new XMLType(XMLSystemFunctions.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
     
      @Override
      public void translate(Writer writer) throws TransformerException,
          IOException {
        try {
          XMLOutputFactory factory = getOutputFactory();
          XMLEventWriter eventWriter = factory.createXMLEventWriter(writer);
          XMLEventFactory eventFactory = XMLEventFactory.newInstance();
          for (Evaluator.NameValuePair nameValuePair : values) {
            if (nameValuePair.value == null) {
              continue;
            }
            addElement(nameValuePair.name, writer, eventWriter, eventFactory, namespaces, null, Collections.singletonList(nameValuePair.value));
          }
          eventWriter.close();
        } catch (XMLStreamException e) {
          throw new TransformerException(e);
        }
      }
    }));
    result.setType(Type.CONTENT);
    return result;
  }
View Full Code Here

Examples of org.teiid.core.types.XMLType

   * @throws TeiidComponentException
   * @throws TeiidProcessingException
   */
  public static XMLType xmlElement(CommandContext context, final String name,
      final Evaluator.NameValuePair<String>[] namespaces, final Evaluator.NameValuePair<?>[] attributes, final List<?> contents) throws TeiidComponentException, TeiidProcessingException {
    XMLType result = new XMLType(XMLSystemFunctions.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
     
      @Override
      public void translate(Writer writer) throws TransformerException,
          IOException {
        try {
          XMLOutputFactory factory = getOutputFactory();
          XMLEventWriter eventWriter = factory.createXMLEventWriter(writer);
          XMLEventFactory eventFactory = XMLEventFactory.newInstance();
          addElement(name, writer, eventWriter, eventFactory, namespaces, attributes, contents);
          eventWriter.close();
        } catch (XMLStreamException e) {
          throw new TransformerException(e);
        }
      }

    }));
    result.setType(Type.ELEMENT);
    return result;
  }
View Full Code Here

Examples of org.teiid.core.types.XMLType

    eventWriter.add(eventFactory.createEndElement("", null, name)); //$NON-NLS-1$
  }
 
  public static XMLType xmlConcat(CommandContext context, final XMLType xml, final Object... other) throws TeiidProcessingException {
    //determine if there is just a single xml value and return it
    XMLType singleValue = xml;
    XMLType.Type type = null;
    for (Object object : other) {
      if (object != null) {
        if (singleValue != null) {
          type = Type.CONTENT;
View Full Code Here

Examples of org.teiid.core.types.XMLType

    int start = 0;
    char[] chars = content.toCharArray();
    while (start < chars.length && chars[start] == ' ') {
      start++;
    }
    XMLType result = new XMLType(new SQLXMLImpl("<?" + name + " " + content.substring(start) + "?>")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    result.setType(Type.PI);
    return result;
  }
View Full Code Here

Examples of org.teiid.core.types.XMLType

      return;
    }
    Reader r = null;
    try {
      if (object instanceof XMLType) {
        XMLType xml = (XMLType)object;
        r = xml.getCharacterStream();
        Type type = xml.getType();
        convertReader(writer, eventWriter, r, type);
      } else if (object instanceof Clob) {
        Clob clob = (Clob)object;
        r = clob.getCharacterStream();
        convertReader(writer, eventWriter, r, Type.TEXT);
View Full Code Here

Examples of org.teiid.core.types.XMLType

      break;
    }
  }
 
  public static XMLType xmlComment(String comment) {
    return new XMLType(new SQLXMLImpl("<!--" + comment + "-->")); //$NON-NLS-1$ //$NON-NLS-2$
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.