Skip to content
Permalink
Browse files
Push some common methods down into an abstract class where they can b…
…e reused
  • Loading branch information
Lloyd Watkin committed Aug 17, 2012
1 parent e376bf2 commit a9e5d24e5d18860eafd755866e9d39b8654e2fa1
@@ -0,0 +1,78 @@
package org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub;

import java.util.concurrent.BlockingQueue;

import org.buddycloud.channelserver.Configuration;
import org.buddycloud.channelserver.channel.node.configuration.Helper;
import org.buddycloud.channelserver.db.DataStore;
import org.dom4j.Element;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;

public abstract class PubSubElementProcessorAbstract
implements PubSubElementProcessor
{

protected BlockingQueue<Packet> outQueue;
protected DataStore dataStore;
protected Element element;
protected IQ response;
protected IQ request;
protected JID actor;
protected String serverDomain;
protected String topicsDomain;
protected String node;
protected Helper configurationHelper;

public void setOutQueue(BlockingQueue<Packet> outQueue)
{
this.outQueue = outQueue;
}

public void setDataStore(DataStore dataStore)
{
this.dataStore = dataStore;
}

public void setServerDomain(String domain)
{
serverDomain = domain;
}

protected String getServerDomain()
{
if (null == serverDomain) {
serverDomain = Configuration.getInstance()
.getProperty("server.domain");
}
return serverDomain;
}

public void setTopicsDomain(String domain)
{
topicsDomain = domain;
}

protected String getTopicsDomain()
{
if (null == topicsDomain) {
serverDomain = Configuration.getInstance()
.getProperty("server.domain.topics");
}
return topicsDomain;
}

public void setConfigurationHelper(Helper helper)
{
configurationHelper = helper;
}

protected Helper getNodeConfigurationHelper()
{
if (null == configurationHelper) {
configurationHelper = new Helper();
}
return configurationHelper;
}
}
@@ -12,6 +12,7 @@
import org.buddycloud.channelserver.db.DataStoreException;
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.JabberPubsub;
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.PubSubElementProcessor;
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.PubSubElementProcessorAbstract;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.dom.DOMElement;
@@ -22,20 +23,9 @@
import org.xmpp.packet.PacketError.Condition;
import org.xmpp.packet.PacketError.Type;

public class NodeCreate implements PubSubElementProcessor
public class NodeCreate extends PubSubElementProcessorAbstract
{
private static final Logger LOGGER = Logger.getLogger(NodeCreate.class);

private BlockingQueue<Packet> outQueue;
private DataStore dataStore;
private Element element;
private IQ response;
private IQ request;
private JID actor;
private String serverDomain;
private String topicsDomain;
private String node;
private Helper configurationHelper;

private static final Pattern nodeExtract = Pattern.compile("^/user/[^@]+@([^/]+)/[^/]+$");
private static final String NODE_REG_EX = "^/user/[^@]+@[^/]+/[^/]+$";
@@ -46,16 +36,6 @@ public NodeCreate(BlockingQueue<Packet> outQueue, DataStore dataStore)
setOutQueue(outQueue);
}

public void setOutQueue(BlockingQueue<Packet> outQueue)
{
this.outQueue = outQueue;
}

public void setDataStore(DataStore dataStore)
{
this.dataStore = dataStore;
}

public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm)
throws Exception
{
@@ -101,13 +81,6 @@ private void createNode() throws InterruptedException
outQueue.put(response);
}

private Helper getNodeConfigurationHelper()
{
if (null == configurationHelper) {
configurationHelper = new Helper();
}
return configurationHelper;
}

public boolean accept(Element elm)
{
@@ -184,44 +157,11 @@ private boolean nodeHandledByThisServer()
}
return true;
}

public void setServerDomain(String domain)
{
serverDomain = domain;
}

private String getServerDomain()
{
if (null == serverDomain) {
serverDomain = Configuration.getInstance()
.getProperty("server.domain");
}
return serverDomain;
}

public void setTopicsDomain(String domain)
{
topicsDomain = domain;
}

private String getTopicsDomain()
{
if (null == topicsDomain) {
serverDomain = Configuration.getInstance()
.getProperty("server.domain.topics");
}
return topicsDomain;
}

private void setErrorCondition(Type type, Condition condition)
{
response.setType(IQ.Type.error);
PacketError error = new PacketError(condition, type);
response.setError(error);
}

public void setConfigurationHelper(Helper helper)
{
configurationHelper = helper;
}
}

0 comments on commit a9e5d24

Please sign in to comment.