mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 10:19:41 +02:00
Apply builder pattern to DiscoverInfo
This is the first transformation of an IQ type to the builder type.
This commit is contained in:
parent
36072fb25a
commit
6e32305987
30 changed files with 749 additions and 233 deletions
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.packet;
|
||||
|
||||
import org.jivesoftware.smack.packet.id.StanzaIdSource;
|
||||
import org.jivesoftware.smack.util.ToStringUtil;
|
||||
|
||||
public abstract class AbstractIqBuilder<IB extends AbstractIqBuilder<IB>> extends StanzaBuilder<IB> implements IqView {
|
||||
|
||||
protected IQ.Type type = IQ.Type.get;
|
||||
|
||||
AbstractIqBuilder(AbstractIqBuilder<?> other) {
|
||||
super(other);
|
||||
type = other.type;
|
||||
}
|
||||
|
||||
AbstractIqBuilder(StanzaIdSource stanzaIdSource) {
|
||||
super(stanzaIdSource);
|
||||
}
|
||||
|
||||
AbstractIqBuilder(String stanzaId) {
|
||||
super(stanzaId);
|
||||
}
|
||||
|
||||
public static IqBuilder createResponse(IqView request) {
|
||||
return createResponse(request, IQ.ResponseType.result);
|
||||
}
|
||||
|
||||
public static IqBuilder createErrorResponse(IqView request) {
|
||||
return createResponse(request, IQ.ResponseType.error);
|
||||
}
|
||||
|
||||
protected static IqBuilder createResponse(IqView request, IQ.ResponseType responseType) {
|
||||
if (!(request.getType() == IQ.Type.get || request.getType() == IQ.Type.set)) {
|
||||
throw new IllegalArgumentException("IQ request must be of type 'set' or 'get'. Original IQ: " + request);
|
||||
}
|
||||
|
||||
IqBuilder commonResponseIqData = buildResponse(request, s -> {
|
||||
return StanzaBuilder.buildIq(s);
|
||||
});
|
||||
commonResponseIqData.ofType(responseType.getType());
|
||||
|
||||
return commonResponseIqData;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void addStanzaSpecificAttributes(ToStringUtil.Builder builder) {
|
||||
builder.addValue("type", getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IQ.Type getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ public class EmptyResultIQ extends IQ {
|
|||
}
|
||||
|
||||
public EmptyResultIQ(IQ request) {
|
||||
this(StanzaBuilder.buildIqResultFor(request));
|
||||
this(AbstractIqBuilder.createResponse(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -68,7 +68,7 @@ public abstract class IQ extends Stanza implements IqView {
|
|||
this(IqBuilder.EMPTY, childElementName, childElementNamespace);
|
||||
}
|
||||
|
||||
protected IQ(IqBuilder iqBuilder, String childElementName, String childElementNamespace) {
|
||||
protected IQ(AbstractIqBuilder<?> iqBuilder, String childElementName, String childElementNamespace) {
|
||||
super(iqBuilder);
|
||||
|
||||
type = iqBuilder.type;
|
||||
|
@ -376,6 +376,25 @@ public abstract class IQ extends Stanza implements IqView {
|
|||
}
|
||||
}
|
||||
|
||||
public enum ResponseType {
|
||||
|
||||
result(Type.result),
|
||||
|
||||
error(Type.error),
|
||||
|
||||
;
|
||||
|
||||
final Type type;
|
||||
|
||||
ResponseType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
Type getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
public static class IQChildElementXmlStringBuilder extends XmlStringBuilder {
|
||||
private final String element;
|
||||
|
||||
|
|
|
@ -16,16 +16,18 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.packet;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smack.packet.id.StandardStanzaIdSource;
|
||||
import org.jivesoftware.smack.packet.id.StanzaIdSource;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.ToStringUtil;
|
||||
|
||||
public final class IqBuilder extends StanzaBuilder<IqBuilder> implements IqView {
|
||||
// TODO: Rename to IqData.
|
||||
public final class IqBuilder extends AbstractIqBuilder<IqBuilder> {
|
||||
|
||||
static final IqBuilder EMPTY = new IqBuilder(StandardStanzaIdSource.DEFAULT);
|
||||
|
||||
IQ.Type type = Type.get;
|
||||
IqBuilder(IqBuilder other) {
|
||||
super(other);
|
||||
}
|
||||
|
||||
IqBuilder(StanzaIdSource stanzaIdSource) {
|
||||
super(stanzaIdSource);
|
||||
|
@ -35,11 +37,6 @@ public final class IqBuilder extends StanzaBuilder<IqBuilder> implements IqView
|
|||
super(stanzaId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addStanzaSpecificAttributes(ToStringUtil.Builder builder) {
|
||||
builder.addValue("type", type);
|
||||
}
|
||||
|
||||
public IqBuilder ofType(IQ.Type type) {
|
||||
this.type = Objects.requireNonNull(type);
|
||||
return getThis();
|
||||
|
@ -49,9 +46,4 @@ public final class IqBuilder extends StanzaBuilder<IqBuilder> implements IqView
|
|||
public IqBuilder getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ.Type getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.packet;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
||||
// TODO: Rename to IqBuilder.
|
||||
public abstract class IqBuilderWithBuild<IB extends IqBuilderWithBuild<IB, I>, I extends IQ>
|
||||
extends AbstractIqBuilder<IB> {
|
||||
|
||||
protected IqBuilderWithBuild(AbstractIqBuilder<?> other) {
|
||||
super(other);
|
||||
}
|
||||
|
||||
protected IqBuilderWithBuild(XMPPConnection connection) {
|
||||
super(connection.getStanzaFactory().getStanzaIdSource());
|
||||
}
|
||||
|
||||
protected IqBuilderWithBuild(String stanzaId) {
|
||||
super(stanzaId);
|
||||
}
|
||||
|
||||
public IB ofType(IQ.Type type) {
|
||||
this.type = Objects.requireNonNull(type);
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public abstract I build();
|
||||
|
||||
}
|
|
@ -21,8 +21,8 @@ import java.util.List;
|
|||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smack.packet.id.StanzaIdSource;
|
||||
import org.jivesoftware.smack.util.Function;
|
||||
import org.jivesoftware.smack.util.MultiMap;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.ToStringUtil;
|
||||
|
@ -46,6 +46,17 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
|
|||
|
||||
MultiMap<QName, ExtensionElement> extensionElements = new MultiMap<>();
|
||||
|
||||
protected StanzaBuilder(StanzaBuilder<?> other) {
|
||||
stanzaIdSource = other.stanzaIdSource;
|
||||
stanzaId = other.stanzaId;
|
||||
|
||||
to = other.to;
|
||||
from = other.from;
|
||||
stanzaError = other.stanzaError;
|
||||
language = other.language;
|
||||
extensionElements = other.extensionElements.clone();
|
||||
}
|
||||
|
||||
protected StanzaBuilder(StanzaIdSource stanzaIdSource) {
|
||||
this.stanzaIdSource = stanzaIdSource;
|
||||
this.stanzaId = null;
|
||||
|
@ -282,20 +293,14 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
|
|||
return new IqBuilder(stanzaId);
|
||||
}
|
||||
|
||||
public static IqBuilder buildIqResultFor(IQ request) {
|
||||
if (!(request.getType() == Type.get || request.getType() == Type.set)) {
|
||||
throw new IllegalArgumentException(
|
||||
"IQ request must be of type 'set' or 'get'. Original IQ: " + request.toXML());
|
||||
}
|
||||
public static <SB extends StanzaBuilder<?>> SB buildResponse(StanzaView request, Function<SB, String> builderFromStanzaId) {
|
||||
SB responseBuilder = builderFromStanzaId.apply(request.getStanzaId());
|
||||
|
||||
return buildIq(request.getStanzaId())
|
||||
.to(request.getFrom())
|
||||
.from(request.getTo())
|
||||
.ofType(IQ.Type.result);
|
||||
responseBuilder.to(request.getFrom())
|
||||
.from(request.getTo())
|
||||
;
|
||||
|
||||
return responseBuilder;
|
||||
}
|
||||
|
||||
public static EmptyResultIQ buildEmptyIqResultFor(IQ request) {
|
||||
IqBuilder iqBuilder = buildIqResultFor(request);
|
||||
return new EmptyResultIQ(iqBuilder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,10 @@ public final class StanzaFactory {
|
|||
|
||||
private final StanzaIdSource stanzaIdSource;
|
||||
|
||||
StanzaIdSource getStanzaIdSource() {
|
||||
return stanzaIdSource;
|
||||
}
|
||||
|
||||
public StanzaFactory(StanzaIdSource stanzaIdSource) {
|
||||
this.stanzaIdSource = stanzaIdSource;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.provider;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.jivesoftware.smack.packet.Element;
|
||||
|
||||
public class AbstractProvider<E extends Element> {
|
||||
|
||||
private final Class<E> elementClass;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected AbstractProvider() {
|
||||
Type currentType = getClass().getGenericSuperclass();
|
||||
while (!(currentType instanceof ParameterizedType)) {
|
||||
Class<?> currentClass = (Class<?>) currentType;
|
||||
currentType = currentClass.getGenericSuperclass();
|
||||
}
|
||||
ParameterizedType parameterizedGenericSuperclass = (ParameterizedType) currentType;
|
||||
Type[] actualTypeArguments = parameterizedGenericSuperclass.getActualTypeArguments();
|
||||
Type elementType = actualTypeArguments[0];
|
||||
|
||||
elementClass = (Class<E>) elementType;
|
||||
}
|
||||
|
||||
public final Class<E> getElementClass() {
|
||||
return elementClass;
|
||||
}
|
||||
}
|
|
@ -17,15 +17,53 @@
|
|||
|
||||
package org.jivesoftware.smack.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.IqBuilder;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* <b>Deprecation Notice:</b> This class is deprecated, use {@link IQProvider} instead.
|
||||
* </p>
|
||||
* An abstract class for parsing custom IQ packets. Each IQProvider must be registered with
|
||||
* the ProviderManager class for it to be used. Every implementation of this
|
||||
* abstract class <b>must</b> have a public, no-argument constructor.
|
||||
*
|
||||
* @author Matt Tucker
|
||||
*/
|
||||
public abstract class IQProvider<I extends IQ> extends Provider<I> {
|
||||
public abstract class IQProvider<I extends IQ> extends IqProvider<I> {
|
||||
|
||||
public final I parse(XmlPullParser parser) throws IOException, XmlPullParserException, SmackParsingException {
|
||||
return parse(parser, (XmlEnvironment) null);
|
||||
}
|
||||
|
||||
public final I parse(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws IOException, XmlPullParserException, SmackParsingException {
|
||||
// XPP3 calling convention assert: Parser should be at start tag
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
|
||||
final int initialDepth = parser.getDepth();
|
||||
final XmlEnvironment xmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);
|
||||
|
||||
I e = parse(parser, initialDepth, xmlEnvironment);
|
||||
|
||||
// XPP3 calling convention assert: Parser should be at end tag of the consumed/parsed element
|
||||
ParserUtils.forwardToEndTagOfDepth(parser, initialDepth);
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final I parse(XmlPullParser parser, int initialDepth, IqBuilder iqData, XmlEnvironment xmlEnvironment)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
// Old-style IQ parsers do not need IqData.
|
||||
return parse(parser, initialDepth, xmlEnvironment);
|
||||
}
|
||||
|
||||
public abstract I parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException;
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public final class IQProviderInfo extends AbstractProviderInfo {
|
|||
* @param namespace Namespace that provider parses.
|
||||
* @param iqProvider The provider implementation.
|
||||
*/
|
||||
public IQProviderInfo(String elementName, String namespace, IQProvider<IQ> iqProvider) {
|
||||
public IQProviderInfo(String elementName, String namespace, IqProvider<IQ> iqProvider) {
|
||||
super(elementName, namespace, iqProvider);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.IqBuilder;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
public abstract class IqProvider<I extends IQ> extends AbstractProvider<I> {
|
||||
|
||||
public final I parse(XmlPullParser parser, IqBuilder iqCommon)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
return parse(parser, iqCommon, null);
|
||||
}
|
||||
|
||||
public final I parse(XmlPullParser parser, IqBuilder iqData, XmlEnvironment outerXmlEnvironment)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
final int initialDepth = parser.getDepth();
|
||||
final XmlEnvironment xmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);
|
||||
|
||||
return parse(parser, initialDepth, iqData, xmlEnvironment);
|
||||
}
|
||||
|
||||
public abstract I parse(XmlPullParser parser, int initialDepth, IqBuilder iqData, XmlEnvironment xmlEnvironment)
|
||||
throws XmlPullParserException, IOException, SmackParsingException;
|
||||
|
||||
}
|
|
@ -18,8 +18,6 @@
|
|||
package org.jivesoftware.smack.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.jivesoftware.smack.packet.Element;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
|
@ -40,27 +38,7 @@ import org.jivesoftware.smack.xml.XmlPullParserException;
|
|||
* @author Florian Schmaus
|
||||
* @param <E> the type of the resulting element.
|
||||
*/
|
||||
public abstract class Provider<E extends Element> {
|
||||
|
||||
private final Class<E> elementClass;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Provider() {
|
||||
Type currentType = getClass().getGenericSuperclass();
|
||||
while (!(currentType instanceof ParameterizedType)) {
|
||||
Class<?> currentClass = (Class<?>) currentType;
|
||||
currentType = currentClass.getGenericSuperclass();
|
||||
}
|
||||
ParameterizedType parameterizedGenericSuperclass = (ParameterizedType) currentType;
|
||||
Type[] actualTypeArguments = parameterizedGenericSuperclass.getActualTypeArguments();
|
||||
Type elementType = actualTypeArguments[0];
|
||||
|
||||
elementClass = (Class<E>) elementType;
|
||||
}
|
||||
|
||||
public final Class<E> getElementClass() {
|
||||
return elementClass;
|
||||
}
|
||||
public abstract class Provider<E extends Element> extends AbstractProvider<E> {
|
||||
|
||||
public final E parse(XmlPullParser parser) throws IOException, XmlPullParserException, SmackParsingException {
|
||||
return parse(parser, null);
|
||||
|
|
|
@ -80,8 +80,8 @@ public class ProviderFileLoader implements ProviderLoader {
|
|||
// an IQ class, add the class object itself, then we'll use
|
||||
// reflection later to create instances of the class.
|
||||
// Add the provider to the map.
|
||||
if (IQProvider.class.isAssignableFrom(provider)) {
|
||||
IQProvider<IQ> iqProvider = (IQProvider<IQ>) provider.getConstructor().newInstance();
|
||||
if (IqProvider.class.isAssignableFrom(provider)) {
|
||||
IqProvider<IQ> iqProvider = (IqProvider<IQ>) provider.getConstructor().newInstance();
|
||||
iqProviders.add(new IQProviderInfo(elementName, namespace, iqProvider));
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -113,7 +113,7 @@ import org.jivesoftware.smack.util.XmppElementUtil;
|
|||
public final class ProviderManager {
|
||||
|
||||
private static final Map<QName, ExtensionElementProvider<ExtensionElement>> extensionProviders = new ConcurrentHashMap<>();
|
||||
private static final Map<QName, IQProvider<IQ>> iqProviders = new ConcurrentHashMap<>();
|
||||
private static final Map<QName, IqProvider<IQ>> iqProviders = new ConcurrentHashMap<>();
|
||||
private static final Map<QName, ExtensionElementProvider<ExtensionElement>> streamFeatureProviders = new ConcurrentHashMap<>();
|
||||
private static final Map<QName, NonzaProvider<? extends Nonza>> nonzaProviders = new ConcurrentHashMap<>();
|
||||
|
||||
|
@ -167,7 +167,7 @@ public final class ProviderManager {
|
|||
* @param namespace the XML namespace.
|
||||
* @return the IQ provider.
|
||||
*/
|
||||
public static IQProvider<IQ> getIQProvider(String elementName, String namespace) {
|
||||
public static IqProvider<IQ> getIQProvider(String elementName, String namespace) {
|
||||
QName key = getQName(elementName, namespace);
|
||||
return iqProviders.get(key);
|
||||
}
|
||||
|
@ -179,8 +179,8 @@ public final class ProviderManager {
|
|||
*
|
||||
* @return all IQProvider instances.
|
||||
*/
|
||||
public static List<IQProvider<IQ>> getIQProviders() {
|
||||
List<IQProvider<IQ>> providers = new ArrayList<>(iqProviders.size());
|
||||
public static List<IqProvider<IQ>> getIQProviders() {
|
||||
List<IqProvider<IQ>> providers = new ArrayList<>(iqProviders.size());
|
||||
providers.addAll(iqProviders.values());
|
||||
return providers;
|
||||
}
|
||||
|
@ -200,10 +200,10 @@ public final class ProviderManager {
|
|||
validate(elementName, namespace);
|
||||
// First remove existing providers
|
||||
QName key = removeIQProvider(elementName, namespace);
|
||||
if (provider instanceof IQProvider) {
|
||||
iqProviders.put(key, (IQProvider<IQ>) provider);
|
||||
if (provider instanceof IqProvider) {
|
||||
iqProviders.put(key, (IqProvider<IQ>) provider);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Provider must be an IQProvider");
|
||||
throw new IllegalArgumentException("Provider must be an instance of IqProvider");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.jivesoftware.smack.packet.EmptyResultIQ;
|
|||
import org.jivesoftware.smack.packet.ErrorIQ;
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.IqBuilder;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
|
@ -51,7 +52,7 @@ import org.jivesoftware.smack.packet.XmlEnvironment;
|
|||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.parsing.StandardExtensionElementProvider;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.provider.IqProvider;
|
||||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
import org.jivesoftware.smack.xml.SmackXmlParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
@ -542,9 +543,16 @@ public class PacketParserUtils {
|
|||
StanzaError error = null;
|
||||
|
||||
final String id = parser.getAttributeValue("", "id");
|
||||
IqBuilder iqData = StanzaBuilder.buildIq(id);
|
||||
|
||||
final Jid to = ParserUtils.getJidAttribute(parser, "to");
|
||||
iqData.to(to);
|
||||
|
||||
final Jid from = ParserUtils.getJidAttribute(parser, "from");
|
||||
iqData.from(from);
|
||||
|
||||
final IQ.Type type = IQ.Type.fromString(parser.getAttributeValue("", "type"));
|
||||
iqData.ofType(type);
|
||||
|
||||
outerloop: while (true) {
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
@ -560,9 +568,9 @@ public class PacketParserUtils {
|
|||
// Otherwise, see if there is a registered provider for
|
||||
// this element name and namespace.
|
||||
default:
|
||||
IQProvider<IQ> provider = ProviderManager.getIQProvider(elementName, namespace);
|
||||
IqProvider<IQ> provider = ProviderManager.getIQProvider(elementName, namespace);
|
||||
if (provider != null) {
|
||||
iqPacket = provider.parse(parser, outerXmlEnvironment);
|
||||
iqPacket = provider.parse(parser, iqData, outerXmlEnvironment);
|
||||
}
|
||||
// Note that if we reach this code, it is guranteed that the result IQ contained a child element
|
||||
// (RFC 6120 § 8.2.3 6) because otherwhise we would have reached the END_ELEMENT first.
|
||||
|
@ -915,6 +923,18 @@ public class PacketParserUtils {
|
|||
return new Session.Feature(optional);
|
||||
}
|
||||
|
||||
public static void addExtensionElement(StanzaBuilder<?> stanzaBuilder, XmlPullParser parser, XmlEnvironment outerXmlEnvironment)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
addExtensionElement(stanzaBuilder, parser, parser.getName(), parser.getNamespace(), outerXmlEnvironment);
|
||||
}
|
||||
|
||||
public static void addExtensionElement(StanzaBuilder<?> stanzaBuilder, XmlPullParser parser, String elementName,
|
||||
String namespace, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
ExtensionElement extensionElement = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
|
||||
stanzaBuilder.addExtension(extensionElement);
|
||||
}
|
||||
|
||||
public static void addExtensionElement(Stanza packet, XmlPullParser parser, XmlEnvironment outerXmlEnvironment)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue