/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* 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.
*/
import org.apache.ws.notification.topics.Topic;
import org.apache.ws.pubsub.NotificationConsumer;
import org.apache.ws.pubsub.NotificationProducer;
import org.apache.ws.pubsub.NotificationProducerFactory;
import org.apache.ws.pubsub.Publisher;
import org.apache.ws.pubsub.PublisherFactory;
import org.apache.ws.pubsub.Subscription;
import org.apache.ws.pubsub.SubscriptionEndConsumer;
import org.apache.ws.pubsub.TopicFilter;
import org.apache.ws.pubsub.XPathFilter;
public class PubSubWSmanager {
public NotificationProducer nprod;
public int outport;
public int inportL;
public int inportS;
public org.apache.ws.notification.topics.TopicNamespace topicNs;
/** Creates a new instance of PubSubWSmanager */
public PubSubWSmanager(String pubscribe_home) throws Exception{
java.util.Random r = new java.util.Random(System.currentTimeMillis());
outport= r.nextInt(60000)+1024;
inportL =r.nextInt(60000)+1024;
inportS =r.nextInt(60000)+1024;
JettyAxisServer jas = new JettyAxisServer();
jas.setPort(inportS);
jas.setResourceBase(pubscribe_home);
jas.start();
NotificationProducerFactory nprodF = NotificationProducerFactory.getInstance();
//TODO
//nprod= nprodF.createNotificationProducer("http://localhost:"+outport+"/axis/services/NotificationProducer","jndi-config_wsn.xml");
nprod= nprodF.createNotificationProducer("http://localhost:"+outport+"/axis/services/NotificationProducer","jndi-config_wse.xml");
topicNs = org.apache.ws.notification.topics.util.TopicSpaceParser.parse(Thread.currentThread().getContextClassLoader().getResourceAsStream("topicspace.xml"));
System.out.println("topicSpace : "+topicNs);
}
public Subscription subscribe(SubscriptionListModel sl, NotificationListModel nl, String xpath, Topic t, java.util.Calendar termtime, boolean subend){
try{
TopicFilter tf = null;
XPathFilter xf = null;
if(xpath!=null)
xf= new XPathFilter(xpath);
if(t!=null)
tf= new TopicFilter(t);
NotificationConsumer c = new GUIConsumer("http://localhost:"+inportL+"/axis/services/NotificationPort",nl);
SubscriptionEndConsumer ec = new GUIEndConsumer("http://localhost:"+inportL+"/axis/services/SubscriptionEndPort",sl);
org.apache.ws.pubsub.Subscription s = nprod.subscribe(c,ec,tf,xf,termtime,true);
return s;
}catch(Exception e){
e.printStackTrace();
}
return null;
}
public void publish(String text, Topic t){
Publisher p = PublisherFactory.getInstance().createPublisher("http://localhost:"+outport+"/axis/services/NotificationPort");
p.publish(text,t);
}
}