Java 类org.jivesoftware.smack.packet.Element 实例源码

项目:Smack    文件:XMPPTCPConnection.java   
/**
 * Sends the specified element to the server.
 *
 * @param element the element to send.
 * @throws NotConnectedException 
 */
protected void sendStreamElement(Element element) throws NotConnectedException {
    throwNotConnectedExceptionIfDoneAndResumptionNotPossible();
    //向写队列中加入一个xml片段
    boolean enqueued = false;
    while (!enqueued) {
        try {
            queue.put(element);
            enqueued = true;
        }
        catch (InterruptedException e) {
            throwNotConnectedExceptionIfDoneAndResumptionNotPossible();
            // If the method above did not throw, then the sending thread was interrupted
            // TODO in a later version of Smack the InterruptedException should be thrown to
            // allow users to interrupt a sending thread that is currently blocking because
            // the queue is full.
            LOGGER.log(Level.WARNING, "Sending thread was interrupted", e);
        }
    }
}
项目:Smack    文件:XMPPTCPConnection.java   
/**
 * Maybe return the next available element from the queue for writing. If the queue is shut down <b>or</b> a
 * spurious interrupt occurs, <code>null</code> is returned. So it is important to check the 'done' condition in
 * that case.
 *
 * @return the next element for writing or null.
 */
// 从队列中取出包
// 然后放到流上发送
private Element nextStreamElement() {
    // It is important the we check if the queue is empty before removing an element from it
    if (queue.isEmpty()) {
        shouldBundleAndDefer = true;
    }
    Element packet = null;
    try {
        packet = queue.take();
    }
    catch (InterruptedException e) {
        if (!queue.isShutdown()) {
            // Users shouldn't try to interrupt the packet writer thread
            LOGGER.log(Level.WARNING, "Packet writer thread was interrupted. Don't do that. Use disconnect() instead.", e);
        }
    }
    return packet;
}
项目:androidclient    文件:XMPPTCPConnection.java   
/**
 * Sends the specified element to the server.
 *
 * @param element the element to send.
 * @throws NotConnectedException
 * @throws InterruptedException
 */
protected void sendStreamElement(Element element) throws NotConnectedException, InterruptedException {
    throwNotConnectedExceptionIfDoneAndResumptionNotPossible();
    try {
        queue.put(element);
    }
    catch (InterruptedException e) {
        // put() may throw an InterruptedException for two reasons:
        // 1. If the queue was shut down
        // 2. If the thread was interrupted
        // so we have to check which is the case
        throwNotConnectedExceptionIfDoneAndResumptionNotPossible();
        // If the method above did not throw, then the sending thread was interrupted
        throw e;
    }
}
项目:Smack    文件:XMPPTCPConnection.java   
private void drainWriterQueueToUnacknowledgedStanzas() {
    List<Element> elements = new ArrayList<Element>(queue.size());
    queue.drainTo(elements);
    for (Element element : elements) {
        if (element instanceof Stanza) {
            unacknowledgedStanzas.add((Stanza) element);
        }
    }
}
项目:Smack    文件:XMPPBOSHConnection.java   
private void sendElement(Element element) {
    try {
        send(ComposableBody.builder().setPayloadXML(element.toXML().toString()).build());
        if (element instanceof Stanza) {
            firePacketSendingListeners((Stanza) element);
        }
    }
    catch (BOSHException e) {
        LOGGER.log(Level.SEVERE, "BOSHException in sendStanzaInternal", e);
    }
}
项目:Smack    文件:DataFormTest.java   
@Test
public void testValidation() throws XmlPullParserException, IOException, SmackException {
    //Build a Form
    DataForm df = new DataForm(DataForm.Type.submit);
    String instruction = "InstructionTest1";
    df.addInstruction(instruction);
    FormField field = new FormField("testField1");
    df.addField(field);

    ValidateElement dv = new RangeValidateElement("xs:integer","1111", "9999");
    field.setValidateElement(dv);

    assertNotNull( df.toXML());
    String output = df.toXML().toString();
    assertEquals(TEST_OUTPUT_3, output);

    XmlPullParser parser = PacketParserUtils.getParserFor(output);

    df = pr.parse(parser);

    assertNotNull(df);
    assertNotNull(df.getFields());
    assertEquals(1 , df.getFields().size() );
    Element element = df.getFields().get(0).getValidateElement();
    assertNotNull(element);
    dv = (ValidateElement) element;

    assertEquals("xs:integer" , dv.getDatatype());

    assertNotNull( df.toXML());
    output = df.toXML().toString();
    assertEquals(TEST_OUTPUT_3, output);
}
项目:androidclient    文件:XMPPTCPConnection.java   
/**
 * Maybe return the next available element from the queue for writing. If the queue is shut down <b>or</b> a
 * spurious interrupt occurs, <code>null</code> is returned. So it is important to check the 'done' condition in
 * that case.
 *
 * @return the next element for writing or null.
 */
private Element nextStreamElement() {
    Element packet = null;
    try {
        packet = queue.take();
    }
    catch (InterruptedException e) {
        if (!queue.isShutdown()) {
            // Users shouldn't try to interrupt the packet writer thread
            LOGGER.log(Level.WARNING, "Packet writer thread was interrupted. Don't do that. Use disconnect() instead.", e);
        }
    }
    return packet;
}
项目:androidclient    文件:XMPPTCPConnection.java   
private void drainWriterQueueToUnacknowledgedStanzas() {
    List<Element> elements = new ArrayList<Element>(queue.size());
    queue.drainTo(elements);
    for (Element element : elements) {
        if (element instanceof Stanza) {
            unacknowledgedStanzas.add((Stanza) element);
        }
    }
}
项目:Smack    文件:XmlStringBuilder.java   
public XmlStringBuilder optElement(Element element) {
    if (element != null) {
        append(element.toXML());
    }
    return this;
}
项目:Smack    文件:XmlStringBuilder.java   
public XmlStringBuilder optAppend(Element element) {
    if (element != null) {
        append(element.toXML());
    }
    return this;
}
项目:Smack    文件:XmlStringBuilder.java   
public XmlStringBuilder append(Collection<? extends Element> elements) {
    for (Element element : elements) {
        append(element.toXML());
    }
    return this;
}
项目:Smack    文件:DataForm.java   
public void addExtensionElement(Element element) {
    extensionElements.add(element);
}
项目:Smack    文件:DataForm.java   
public List<Element> getExtensionElements() {
    return Collections.unmodifiableList(extensionElements);
}
项目:Smack    文件:DataFormTest.java   
@Test
public void testLayout() throws XmlPullParserException, IOException, SmackException {
    //Build a Form
    DataForm df = new DataForm(DataForm.Type.submit);
    String instruction = "InstructionTest1";
    df.addInstruction(instruction);
    FormField field = new FormField("testField1");
    df.addField(field);

    DataLayout layout = new DataLayout("Label");
    Fieldref reffield = new Fieldref("testField1");
    layout.getPageLayout().add(reffield);
    Section section = new Section("section Label");
    section.getSectionLayout().add(new Text("SectionText"));
    layout.getPageLayout().add(section);
    layout.getPageLayout().add(new Text("PageText"));

    df.addExtensionElement(layout);


    assertNotNull( df.toXML());
    String output = df.toXML().toString();
    assertEquals(TEST_OUTPUT_2, output);

    XmlPullParser parser = PacketParserUtils.getParserFor(output);

    df = pr.parse(parser);

    assertNotNull(df);
    assertNotNull(df.getExtensionElements());
    assertEquals(1 , df.getExtensionElements().size() );
    Element element = df.getExtensionElements().get(0);
    assertNotNull(element);
    layout = (DataLayout) element;

    assertEquals(3 , layout.getPageLayout().size());

    assertNotNull( df.toXML());
    output = df.toXML().toString();
    assertEquals(TEST_OUTPUT_2, output);
}
项目:jitsi-hammer    文件:JingleProvider.java   
@Override
public NewJingleIQ parse(XmlPullParser parser, int initialDepth)
        throws XmlPullParserException, IOException
{
    NewJingleIQ jingleIQ = new NewJingleIQ();
    NewJingleAction action = NewJingleAction.parseString(parser.getAttributeValue("", "action"));
    String initiator = parser.getAttributeValue("", "initiator");
    String responder = parser.getAttributeValue("", "responder");
    String sid = parser.getAttributeValue("", "sid");

    jingleIQ.setAction(action);
    jingleIQ.setInitiator(initiator);
    jingleIQ.setResponder(responder);
    jingleIQ.setSID(sid);
    boolean done = false;

    try
    {
        while (!done)
        {
            int eventType = parser.next();
            String elementName = parser.getName();
            String namespace = parser.getNamespace();
            if (eventType == XmlPullParser.START_TAG)
            {
                ExtensionElementProvider provider = ProviderManager.getExtensionProvider(elementName, namespace);
                if (provider != null)
                {
                    Element child = provider.parse(parser);
                    if (child instanceof NewContentPacketExtension)
                    {
                        jingleIQ.addContent((NewContentPacketExtension)child);
                    }
                    else
                    {
                        throw new IOException("JingleProvider doesn't handle child element " + elementName +
                            " in namespace " + namespace);
                    }
                }
                else
                {
                    throw new IOException("JingleProvider: no provider found for element " +
                            elementName + " in namespace " + namespace);
                }
            }

            if (eventType == XmlPullParser.END_TAG && parser.getName().equals("jingle"))
            {
                done = true;
            }
        }
    }
    catch (Exception e)
    {
    }

    return jingleIQ;
}
项目:jitsi-hammer    文件:NewAbstractExtensionElement.java   
/**
 * Adds the specified <tt>childExtension</tt> to the list of extensions
 * registered with this packet.
 * <p/>
 * Overriding extensions may need to override this method if they would like
 * to have anything more elaborate than just a list of extensions (e.g.
 * casting separate instances to more specific.
 *
 * @param childExtension the extension we'd like to add here.
 */
public void addChildExtension(Element childExtension)
{
    childExtensions.add(childExtension);
}
项目:jitsi-hammer    文件:NewAbstractExtensionElement.java   
/**
 * Returns all sub-elements for this <tt>NewAbstractExtensionElement</tt> or
 * <tt>null</tt> if there aren't any.
 * <p>
 * Overriding extensions may need to override this method if they would like
 * to have anything more elaborate than just a list of extensions.
 *
 * @return the {@link List} of elements that this packet extension contains.
 */
public List<Element> getChildExtensions()
{
    return childExtensions;
}