[overlord-commits] Overlord SVN: r479 - in cdl/trunk/validator/jbossesb: src and 8 other directories.

overlord-commits at lists.jboss.org overlord-commits at lists.jboss.org
Fri Feb 6 07:18:24 EST 2009


Author: objectiser
Date: 2009-02-06 07:18:23 -0500 (Fri, 06 Feb 2009)
New Revision: 479

Added:
   cdl/trunk/validator/jbossesb/src/
   cdl/trunk/validator/jbossesb/src/main/
   cdl/trunk/validator/jbossesb/src/main/java/
   cdl/trunk/validator/jbossesb/src/main/java/org/
   cdl/trunk/validator/jbossesb/src/main/java/org/jboss/
   cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/
   cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/
   cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/
   cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/
   cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ESBUtil.java
   cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidationAction.java
   cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorFilter.java
   cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorGenerator.java
   cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorManager.java
Modified:
   cdl/trunk/validator/jbossesb/
Log:
Move Service Validators from pi4soa to Overlord project codebase, as originally developed before Overlord was established, but now is an integral part of the CDL component of this project.


Property changes on: cdl/trunk/validator/jbossesb
___________________________________________________________________
Name: svn:ignore
   + lib
.classpath
.project


Added: cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ESBUtil.java
===================================================================
--- cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ESBUtil.java	                        (rev 0)
+++ cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ESBUtil.java	2009-02-06 12:18:23 UTC (rev 479)
@@ -0,0 +1,149 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+import java.util.logging.Logger;
+
+import org.pi4soa.common.util.NamesUtil;
+import org.pi4soa.common.xml.NameSpaceUtil;
+
+public class ESBUtil {
+
+	/**
+	 * This method returns the pi4soa message associated
+	 * with the supplied JBoss ESB message.
+	 * 
+	 * @param message The esb message
+	 * @return The pi4soa message
+	 */
+	public static java.io.Serializable getMessage(
+			org.jboss.soa.esb.message.Message message) {
+		java.io.Serializable ret=null;
+		
+		ret = (java.io.Serializable)message.getBody().get();
+
+		// Check if should return a multipart message
+		if (ret == null) {
+			
+			// Check if single or multipart message
+			if (message.getBody().getNames() != null &&
+					message.getBody().getNames().length == 1) {
+				
+				Object mesg=message.getBody().get(message.getBody().getNames()[0]);
+				
+				if (logger.isLoggable(java.util.logging.Level.FINEST)) {
+					logger.finest("MESSAGE("+
+							message.getBody().getNames()[0]+")="+mesg);
+				}
+				
+				if (mesg instanceof java.io.Serializable) {
+					ret = (java.io.Serializable)mesg;
+				}
+				
+			} else if (message.getBody().getNames() != null &&
+					message.getBody().getNames().length > 1) {
+				
+				java.util.Hashtable multipart=new java.util.Hashtable();
+				
+				for (int i=0; i < message.getBody().getNames().length; i++) {
+					multipart.put(message.getBody().getNames()[i],
+							message.getBody().get(message.getBody().getNames()[i]));
+				}
+				
+				ret = multipart;
+			}
+		}
+		
+		if (ret instanceof byte[]) {
+			ret = new String((byte[])ret);
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the JBoss ESB message associated
+	 * with the supplied pi4soa message.
+	 * 
+	 * @param message The pi4soa message
+	 * @return The esb message
+	 */
+	public static org.jboss.soa.esb.message.Message getMessage(
+					org.pi4soa.service.Message message) {
+		org.jboss.soa.esb.message.Message ret=
+			org.jboss.soa.esb.message.format.MessageFactory.getInstance().getMessage();
+		
+		// Check if multi-part message
+		if (message.isMultiPart()) {
+			if (message.getValue() instanceof java.util.Map) {
+				java.util.Map parts=(java.util.Map)message.getValue();
+				
+				java.util.Iterator iter=parts.keySet().iterator();
+				while (iter.hasNext()) {
+					String key=(String)iter.next();
+					
+					ret.getBody().add(key, parts.get(key));
+				}
+			} else {
+				logger.severe("JBossESB message " +
+						"is not a valid multi-part message");
+			}
+		} else {
+			ret.getBody().add(message.getValue());
+		}
+
+		// Determine if the message represents a fault
+		if (NamesUtil.isSet(message.getFaultName())) {
+			String namespace=NameSpaceUtil.getNamespace(message.getFaultName());
+			String localpart=NameSpaceUtil.getLocalPart(message.getFaultName());
+			
+			try {
+				ret.getFault().setCode(new java.net.URI(
+						namespace+"/"+localpart));
+			} catch(Exception e) {
+				logger.severe("JBossESB message " +
+							"failed to set fault code: "+e);
+			}
+		}
+		
+		return(ret);
+	}
+	
+	public static String encodeServiceParameter(String param) {
+		return(param.replaceAll(":", "/colon/"));
+	}
+	
+	public static String decodeServiceParameter(String param) {
+		return(param.replaceAll("/colon/", ":"));
+	}
+	
+	public static String getCategory(String category) {
+		String ret=category;
+		
+		if (ret.startsWith("http://")) {
+			ret = ret.substring(7);
+		}
+		
+		// Convert '/' into another separator
+		ret = ret.replace('/', '_');
+		
+		return(ret);
+	}
+
+	private static Logger logger = Logger.getLogger("org.pi4soa.jbossesb.util");	
+}

Added: cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidationAction.java
===================================================================
--- cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidationAction.java	                        (rev 0)
+++ cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidationAction.java	2009-02-06 12:18:23 UTC (rev 479)
@@ -0,0 +1,247 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.soa.esb.actions.*;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+import org.pi4soa.common.util.MessageUtil;
+import org.pi4soa.service.*;
+import org.pi4soa.service.behavior.*;
+import org.pi4soa.service.monitor.*;
+import org.pi4soa.common.util.NamesUtil;
+
+/**
+ * This class provides the action implementation for validation
+ * against the pi4soa state machine.
+ */
+public class ValidationAction extends AbstractActionLifecycle {
+
+	private static final String ACTIVE_ATTR = "active";
+	private static final String INBOUND_ATTR = "inbound";
+	public static final String CDM_FILE_PATH="cdmFilePath";
+	public static final String PARTICIPANT_TYPE="participantType";
+
+	/**
+	 * This constructor initializes the actions with the
+	 * service configuration details.
+	 * 
+	 * @param config The service configuration
+	 */
+	public ValidationAction(ConfigTree config) {
+		m_config = config;
+	}
+	
+	/**
+	 * This method initializes the service action.
+	 */
+	public void initialise() throws ActionLifecycleException {
+		
+		if (logger.isLoggable(Level.FINE)) {
+			logger.fine("ValidationAction initialise: "+this);
+		}
+		
+		super.initialise();
+		
+    	String direction=
+			m_config.getAttribute(INBOUND_ATTR);
+    	
+    	if (direction != null && direction.equalsIgnoreCase("false")) {
+    		m_inbound = false;
+    	}
+    	
+    	String active=
+			m_config.getAttribute(ACTIVE_ATTR);
+    	
+    	if (active != null && active.equalsIgnoreCase("false")) {
+    		m_active = false;
+    	}
+    	
+		getServiceMonitor();
+	}
+	
+	/**
+	 * This method returns the service monitor associated with
+	 * the ESB service.
+	 * 
+	 * @return The service monitor
+	 */
+	protected synchronized ServiceMonitor getServiceMonitor() {
+		
+		if (m_serviceMonitor == null) {
+
+			try {
+				ServiceDescription sdesc=null;				
+				String cdmFilePath=
+					m_config.getAttribute(CDM_FILE_PATH);
+				String participantType=
+					m_config.getAttribute(PARTICIPANT_TYPE);
+			
+				if (logger.isLoggable(Level.FINEST)) {
+					logger.finest("ValidationAction config: cdm="+
+							cdmFilePath+" participant="+participantType);
+				}
+				
+				if (NamesUtil.isSet(cdmFilePath) &&
+								NamesUtil.isSet(participantType)) {
+					
+					java.io.InputStream is=ValidationAction.class.
+							getClassLoader().getResourceAsStream(cdmFilePath);
+				
+					if (is == null) {
+						
+						is = ClassLoader.getSystemResourceAsStream(cdmFilePath);
+						
+						if (is == null) {
+							throw new ServiceException("Failed to locate path '"+
+										cdmFilePath+"'");
+						}
+					}
+					
+					if (is != null) {
+						sdesc = org.pi4soa.service.util.DescriptionRetrievalUtil.instance().getServiceDescription(is, participantType);
+					}
+				} else {
+			   		logger.severe("Choreography file and Participant Type not specified: "+this);
+				}
+							       	
+		       	if (sdesc != null) {
+		       		m_serviceDescriptionName = sdesc.getFullyQualifiedName();
+					
+					// Obtain the service container
+			       	m_serviceMonitor = ValidatorManager.createServiceContainer(
+			       					sdesc);
+		       	} else {
+			   		logger.severe("Service description could not be loaded: "+
+			   				cdmFilePath+" participant="+participantType);			       		
+		       	}
+			       	
+			} catch(Exception e) {
+				logger.log(Level.SEVERE,
+						"Failed to initialize ValidationAction", e);
+			}
+		}
+		
+		return(m_serviceMonitor);
+	}
+  
+	/**
+	 * This method processes a message for the service associated
+	 * with this ESB action.
+	 * 
+	 * @param message The message
+	 * @return The message
+	 */
+	public Message processMessage(Message message) throws ActionProcessingException {
+		
+		if (logger.isLoggable(Level.FINEST)) {
+			logger.finest("ValidationAction: "+this+" message="+message);
+		}
+
+        try {
+        	java.io.Serializable value=ESBUtil.getMessage(message);
+        	
+        	if (value == null) {
+        		throw new ServiceException("Failed to obtain value from message: "+message);
+        	}
+        	
+        	String mesgType=MessageUtil.getMessageType(value);
+
+        	org.pi4soa.service.Message mesg=
+        		getServiceMonitor().createMessage(mesgType, null,
+        				null, value, null, null);
+        	
+       		try {
+	       		if (m_inbound) {
+	       			getServiceMonitor().messageReceived(mesg);
+	       		} else {
+	       			getServiceMonitor().messageSent(mesg);
+	       		} 
+       		} catch(OutOfSequenceMessageException osme) {
+       			
+       			if (m_active) {
+       				throw osme;
+       			} else {
+       				logger.severe("Out of sequence message detected");
+       				if (logger.isLoggable(Level.FINEST)) {
+       					logger.finest(message.toString());
+       				}
+       			}
+       		} catch(UnexpectedMessageException ume) {
+       			
+       			if (m_active) {
+       				throw ume;
+      			} else {
+       				logger.severe("Unexpected message detected");
+       				if (logger.isLoggable(Level.FINEST)) {
+       					logger.finest(message.toString());
+       				}
+       			}
+       		}
+	       		
+        } catch(Throwable t) {
+        	logger.log(java.util.logging.Level.SEVERE,
+        			"Failed to handle message", t);
+        	
+        	throw new ActionProcessingException("Failed to handle message", t);
+        }
+        
+		if (logger.isLoggable(Level.FINEST)) {
+			logger.finest("ValidationAction: "+this+
+					"serviceDescriptionName="+
+					m_serviceDescriptionName+
+					" finished processing message="+message);
+		}
+
+		return(message);
+	} 
+
+	/**
+	 * This method is called to tidy up after the action is
+	 * no longer required.
+	 */
+	public void destroy() throws ActionLifecycleException {
+		if (logger.isLoggable(Level.FINE)) {
+			logger.fine("ValidationAction destroy: "+this);
+		}
+		
+		super.destroy();
+		
+		if (m_serviceMonitor != null &&
+						m_serviceDescriptionName != null) {
+			try {
+				ValidatorManager.releaseServiceMonitor(m_serviceDescriptionName);
+			} catch(org.pi4soa.service.ServiceException se) {
+				throw new ActionLifecycleException("Failed to destroy service monitor",
+								se);
+			}
+		}
+	}
+  
+	private static final Logger logger = Logger.getLogger("org.pi4soa.jbossesb.validator");
+
+	private ConfigTree	m_config=null;
+	private String m_serviceDescriptionName=null;
+	private ServiceMonitor m_serviceMonitor=null;
+	private boolean m_inbound=true;
+	private boolean m_active=true;
+}
\ No newline at end of file

Added: cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorFilter.java
===================================================================
--- cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorFilter.java	                        (rev 0)
+++ cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorFilter.java	2009-02-06 12:18:23 UTC (rev 479)
@@ -0,0 +1,616 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.soa.esb.message.*;
+import org.jboss.soa.esb.couriers.*;
+import org.jboss.soa.esb.helpers.*;
+import org.pi4soa.common.util.MessageUtil;
+import org.pi4soa.common.util.NamesUtil;
+import org.pi4soa.common.xml.XMLUtils;
+import org.pi4soa.service.OutOfSequenceMessageException;
+import org.pi4soa.service.ServiceException;
+import org.pi4soa.service.UnexpectedMessageException;
+import org.pi4soa.service.monitor.*;
+
+import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
+
+public class ValidatorFilter extends org.jboss.soa.esb.filter.InputOutputFilter {
+	
+	private static final String CONFIG_FILE = "validator-config.xml";
+	public static final String CDM_FILE_PATH="cdmFilePath";
+	public static final String PARTICIPANT_TYPE="participantType";
+	public static final String VALIDATE="validate";
+	
+	public ValidatorFilter() {
+		initialize();
+	}
+	
+	public Message onOutput(Message msg, java.util.Map params)
+			throws CourierException {
+		
+		String key=getKey(msg);
+
+		if (key != null) {
+			ServiceMonitor sm=(ServiceMonitor)m_outputServices.get(key);
+			
+			if (logger.isLoggable(Level.FINEST)) {
+				logger.finest("ValidationFilter: "+this+" message="+
+						msg+" monitor="+sm);
+			}
+
+			if (sm != null) {
+		        try {
+		        	java.io.Serializable value=ESBUtil.getMessage(msg);
+		        	
+		        	if (value == null) {
+		        		throw new ServiceException("Failed to obtain value from message: "+msg);
+		        	}
+		        	
+		        	String mesgType=MessageUtil.getMessageType(value);
+	
+		        	org.pi4soa.service.Message mesg=
+		        			sm.createMessage(mesgType,
+		        				null, null, value, null, null);
+		        	
+		       		try {
+			       		sm.messageSent(mesg); 
+		       		} catch(OutOfSequenceMessageException osme) {
+		       			
+		       			if (m_active) {
+		       				throw osme;
+		       			} else {
+		       				logger.severe("Out of sequence message detected");
+		       				if (logger.isLoggable(Level.FINEST)) {
+		       					logger.finest(msg.toString());
+		       				}
+		       			}
+		       		} catch(UnexpectedMessageException ume) {
+		       			
+		       			if (m_active) {
+		       				throw ume;
+		       			} else {
+		       				logger.severe("Unexpected message detected");
+		       				if (logger.isLoggable(Level.FINEST)) {
+		       					logger.finest(msg.toString());
+		       				}
+		       			}
+		       		}
+			       		
+		        } catch(Throwable t) {
+		        	logger.log(java.util.logging.Level.SEVERE,
+		        			"Failed to handle message", t);
+		        	
+		        	throw new CourierException("Failed to handle message", t);
+		        }
+			}
+		}
+	        
+		return(msg);
+	}
+	
+	public Message onInput(Message msg, java.util.Map params)
+			throws CourierException {
+		
+		String key=getKey(msg);
+
+		if (key != null) {
+			ServiceMonitor sm=(ServiceMonitor)m_inputServices.get(key);
+			
+			if (logger.isLoggable(Level.FINEST)) {
+				logger.finest("ValidationFilter: "+this+" message="+msg+" monitor="+sm);
+			}
+
+			if (sm != null) {
+		        try {
+		        	java.io.Serializable value=ESBUtil.getMessage(msg);
+		        	
+		        	if (value == null) {
+		        		throw new ServiceException("Failed to obtain value from message: "+msg);
+		        	}
+		        	
+		        	String mesgType=MessageUtil.getMessageType(value);
+	
+		        	org.pi4soa.service.Message mesg=
+		        			sm.createMessage(mesgType,
+		        				null, null, value, null, null);
+		        	
+		       		try {
+			       		sm.messageReceived(mesg); 
+		       		} catch(OutOfSequenceMessageException osme) {
+		       			
+		       			if (m_active) {
+		       				throw osme;
+		       			} else {
+		       				logger.severe("Out of sequence message detected");
+		       				if (logger.isLoggable(Level.FINEST)) {
+		       					logger.finest(msg.toString());
+		       				}
+		       			}
+		       		} catch(UnexpectedMessageException ume) {
+		       			
+		       			if (m_active) {
+		       				throw ume;
+		       			} else {
+		       				logger.severe("Unexpected message detected");
+		       				if (logger.isLoggable(Level.FINEST)) {
+		       					logger.finest(msg.toString());
+		       				}
+		       			}
+		       		}
+			       		
+		        } catch(Throwable t) {
+		        	logger.log(java.util.logging.Level.SEVERE,
+		        			"Failed to handle message", t);
+		        	
+		        	throw new CourierException("Failed to handle message", t);
+		        }
+			}
+		}
+
+		return(msg);
+	}
+	
+	protected void initialize() {
+		
+		java.net.URL url=
+			ValidatorFilter.class.getClassLoader().getResource(CONFIG_FILE);
+		
+		System.out.println("CONFIG FILE URL="+url);
+		System.out.println("CONFIG FILE URL TYPE="+url.getClass());
+		
+		if (url != null) {
+			java.io.File file=new java.io.File(url.getFile());
+			
+			java.io.File[] files=file.getParentFile().listFiles();
+			java.io.File models=null;
+			
+			for (int i=0; models == null && i < files.length; i++) {
+				if (files[i].getName().equals("models") &&
+						files[i].isDirectory()) {
+					models = files[i];
+				}
+			}
+			
+			if (models != null) {
+				ValidatorConfigChangeMonitor mon=new ValidatorConfigChangeMonitor(file, models);
+				
+				new Thread(mon).start();
+			}
+		}
+	}
+	
+	/**
+	 * This method performs the update of the configuration of
+	 * service monitors, based on the information in the validator
+	 * configuration XML file, and the choreographies defined in the
+	 * models folder.
+	 */
+	protected void updateConfiguration(java.io.InputStream is,
+			java.util.Set<String> existingServiceDescriptions,
+			java.util.Set<String> existingInputKeys,
+			java.util.Set<String> existingOutputKeys) {
+		
+		try {
+			updateConfiguration(ConfigTree.fromInputStream(is),
+					existingServiceDescriptions, existingInputKeys,
+					existingOutputKeys);
+		} catch(Exception e) {
+		
+			logger.log(Level.SEVERE,
+					"Failed to update configuration from input stream", e);
+		}
+	}
+	
+	/**
+	 * This method performs the update of the configuration of
+	 * service monitors, based on the information in the validator
+	 * configuration XML file, and the choreographies defined in the
+	 * models folder.
+	 */
+	protected void updateConfiguration(org.w3c.dom.Element elem,
+			java.util.Set<String> existingServiceDescriptions,
+			java.util.Set<String> existingInputKeys,
+			java.util.Set<String> existingOutputKeys) {
+		
+		try {
+			updateConfiguration(ConfigTree.fromElement(elem),
+					existingServiceDescriptions, existingInputKeys,
+					existingOutputKeys);
+		} catch(Exception e) {
+		
+			logger.log(Level.SEVERE,
+					"Failed to update configuration from DOM element", e);
+		}
+	}
+	
+	/**
+	 * This method performs the update of the configuration of
+	 * service monitors, based on the information in the validator
+	 * configuration XML file, and the choreographies defined in the
+	 * models folder.
+	 */
+	protected void updateConfiguration(ConfigTree config,
+			java.util.Set<String> existingServiceDescriptions,
+			java.util.Set<String> existingInputKeys,
+			java.util.Set<String> existingOutputKeys) {
+		logger.info("Update Service Validator Configuration");
+		
+		if (config != null) {
+			try {				
+				if (config.getName().equals(VALIDATOR_NODE)) {
+					String active=config.getAttribute(ACTIVE_ATTR);
+					
+					if (active != null && active.equalsIgnoreCase("true")) {
+						
+						logger.info("Setting validator into active mode");
+						m_active = true;
+					}
+				}
+				
+				ConfigTree[] services=config.getChildren(SERVICE_NODE);
+				
+				if (logger.isLoggable(Level.FINEST)) {
+					if (services != null) {
+						logger.finest("ValidationFilter: services="+services.length);
+					} else {
+						logger.finest("ValidationFilter: services null");
+					}
+				}
+
+				for (int i=0; i < services.length; i++) {
+		       		org.pi4soa.service.monitor.ServiceMonitor sm=null;
+					
+					// Create service monitor for service
+					String cdmFilePath=
+						services[i].getAttribute(CDM_FILE_PATH);
+					String participantType=
+						services[i].getAttribute(PARTICIPANT_TYPE);
+					boolean validate=
+						services[i].getBooleanAttribute(VALIDATE, true);
+
+					if (NamesUtil.isSet(participantType)) {
+				
+						if (NamesUtil.isSet(cdmFilePath)) {
+							java.io.InputStream is = ValidatorFilter.class.
+									getClassLoader().getResourceAsStream(
+											cdmFilePath);
+				
+							if (is != null) {
+								org.pi4soa.service.behavior.ServiceDescription sdesc=
+									org.pi4soa.service.util.DescriptionRetrievalUtil.instance().getServiceDescription(is, participantType);
+	
+						       	if (sdesc != null) {
+									
+									// Obtain the service container
+						       		sm = ValidatorManager.createServiceContainer(sdesc, validate);
+						       		
+						       		if (logger.isLoggable(Level.FINE)) {
+						       			logger.fine("Service monitor for '"+cdmFilePath+
+						       					"' and participantType '"+participantType+"' = "+sm);
+						       		}
+						       		
+						       		// Remove service description from list
+						       		existingServiceDescriptions.remove(sdesc.getFullyQualifiedName());
+						       		
+						       	} else {
+							   		logger.severe("Service description could not be loaded");			       		
+						       	}
+							       	
+							} else {
+						   		logger.severe("Choreography file path not found: "+this);							
+							}
+						} else if (validate == false) {
+							
+							logger.fine("Create non-validating service monitor for: "+
+									participantType);
+							
+							// Just record information for participant
+							// using the service tracker
+							org.pi4soa.service.behavior.ServiceDescription sdesc=
+								org.pi4soa.service.behavior.BehaviorFactory.eINSTANCE.createServiceDescription();
+							sdesc.setName(participantType);
+							
+							sm = ValidatorManager.createServiceContainer(sdesc, validate);
+											       		
+				       		// Remove service description from list
+				       		existingServiceDescriptions.remove(sdesc.getFullyQualifiedName());
+						
+						} else {
+					   		logger.severe("Choreography file path not specified: "+this);
+						}
+					} else {
+				   		logger.severe("Participant type not specified: "+this);
+					}
+					
+					if (sm != null) {
+						// Map inputs to service
+						ConfigTree[] inputs=services[i].getChildren(INPUT_NODE);
+						
+						for (int j=0; j < inputs.length; j++) {
+							String epr=inputs[j].getAttribute(EPR_ATTR);
+							
+							if (epr != null) {
+								
+								if (logger.isLoggable(Level.FINEST)) {
+									logger.finest("Storing input epr '"+
+										epr+"' against monitor: "+sm);									
+								}
+								
+								// Check if EPR associated with different
+								// input service
+								ServiceMonitor tmp=m_inputServices.get(epr);
+								
+								if (tmp != null && tmp != sm) {
+									logger.severe("Input EPR '"+epr+
+										"' already associated with another Service Monitor");
+								}
+								
+								m_inputServices.put(epr, sm);
+								
+								existingInputKeys.remove(epr);
+							}
+						}
+	
+						// Map outputs to service
+						ConfigTree[] outputs=services[i].getChildren(OUTPUT_NODE);
+						
+						for (int j=0; j < outputs.length; j++) {
+							String epr=outputs[j].getAttribute(EPR_ATTR);
+							
+							if (epr != null) {
+								if (logger.isLoggable(Level.FINEST)) {
+									logger.finest("Storing output epr '"+
+										epr+"' against monitor: "+sm);									
+								}
+								
+								// Check if EPR associated with different
+								// output service
+								ServiceMonitor tmp=m_outputServices.get(epr);
+								
+								if (tmp != null && tmp != sm) {
+									logger.severe("Output EPR '"+epr+
+										"' already associated with another Service Monitor");
+								}
+								
+								m_outputServices.put(epr, sm);
+								
+								existingOutputKeys.remove(epr);
+							}
+						}
+					}
+				}
+			} catch(Exception e) {
+				logger.log(java.util.logging.Level.SEVERE,
+						"Failed to load validator config", e);
+			}
+		}
+	}
+	
+	/**
+	 * This method returns a key associated with the 'to'
+	 * destination of the supplied message.
+	 * 
+	 * @param msg The message
+	 * @return The key, or null if not relevant
+	 */
+	protected String getKey(Message msg) {
+		String ret=null;
+		
+		if (msg != null && msg.getHeader() != null && 
+				msg.getHeader().getCall() != null &&
+				msg.getHeader().getCall().getTo() != null &&
+				msg.getHeader().getCall().getTo().getAddr() != null) {
+				
+			String key=msg.getHeader().getCall().getTo().getAddr().getAddress();
+			int ind=-1;
+			
+			if (key.startsWith(JMS_PROTOCOL_PREFIX) && 
+					((ind=key.indexOf(QUEUE_PREFIX)) != -1 ||
+					(ind=key.indexOf(TOPIC_PREFIX)) != -1)) {
+				ret = JMS_PROTOCOL_PREFIX+key.substring(ind);
+			}
+		}
+		
+		if (logger.isLoggable(Level.FINEST)) {
+			logger.finest("Key for message '"+msg+"' is: "+ret);
+		}
+		
+		return(ret);
+	}
+	
+	private static final Logger logger = Logger.getLogger("org.pi4soa.jbossesb.validator");
+
+	private static final String TOPIC_PREFIX = "topic/";
+	private static final String QUEUE_PREFIX = "queue/";
+	private static final String JMS_PROTOCOL_PREFIX = "jms:";
+	private static final String EPR_ATTR = "epr";
+	private static final String OUTPUT_NODE = "output";
+	private static final String INPUT_NODE = "input";
+	private static final String SERVICE_NODE = "service";
+	private static final String ACTIVE_ATTR = "active";
+	private static final String VALIDATOR_NODE = "validator";
+
+	private java.util.Map<String,ServiceMonitor> m_inputServices=new java.util.Hashtable<String,ServiceMonitor>();
+	private java.util.Map<String,ServiceMonitor> m_outputServices=new java.util.Hashtable<String,ServiceMonitor>();
+	private boolean m_active=false;
+	
+	public class ValidatorConfigChangeMonitor implements java.lang.Runnable {
+		
+		public ValidatorConfigChangeMonitor(java.io.File validatorConfigFile,
+						java.io.File modelsDir) {
+			m_validatorConfigFile = validatorConfigFile;
+			m_modelsDir = modelsDir;
+			
+			// Do initial check for updates, so monitors
+			// initialized before returning from construct,
+			// as remainder of checks will be in a separate
+			// thread - so we need to ensure that the monitors
+			// are configured before the first message is
+			// passed through the filter.
+			checkForUpdates();
+		}
+		
+		public void run() {
+			
+			while (true) {
+				checkForUpdates();
+				
+				try {
+					synchronized(ValidatorConfigChangeMonitor.this) {
+						wait(30000);
+					}
+				} catch(Exception e) {
+					e.printStackTrace();
+				}
+			}
+		}
+		
+		protected void checkForUpdates() {
+			logger.info("Checking for config updates");
+			
+			// Get last update time
+			long lastUpdate=getLastUpdate();
+			
+			if (lastUpdate > m_lastUpdate) {
+				
+				updateConfigurations();
+				
+				m_lastUpdate = lastUpdate;
+			}			
+		}
+		
+		protected void updateConfigurations() {
+			java.util.Set<String> existingServiceDescriptions=
+				ValidatorManager.getServiceDescriptionNames();
+			
+			java.util.Set<String> existingInputKeys=
+				new java.util.HashSet<String>(m_inputServices.keySet());
+	
+			java.util.Set<String> existingOutputKeys=
+				new java.util.HashSet<String>(m_outputServices.keySet());
+	
+			java.io.InputStream is=ValidatorFilter.class.getClassLoader().
+						getResourceAsStream(CONFIG_FILE);
+	
+			if (logger.isLoggable(Level.FINEST)) {
+				logger.finest("ValidationFilter: config="+CONFIG_FILE+" is="+is);
+			}
+
+			updateConfiguration(is, existingServiceDescriptions,
+					existingInputKeys, existingOutputKeys);
+			
+			// Work through choreography files in the models directory
+			java.io.File[] files=m_modelsDir.listFiles();
+			
+			for (int i=0; i < files.length; i++) {
+				if (files[i].getName().endsWith(".cdm")) {
+					
+					try {
+						java.io.FileInputStream fis=new java.io.FileInputStream(files[i]);
+						
+						org.pi4soa.cdl.Package cdlpack=
+							org.pi4soa.service.util.DescriptionRetrievalUtil.instance().getCDLPackage(fis);
+						
+						ValidatorGenerator generator=new ValidatorGenerator();
+						
+						org.w3c.dom.Element validator=
+								generator.generate(cdlpack, files[i].getName());
+								
+						if (logger.isLoggable(Level.FINEST)) {
+							logger.finest("ValidationFilter: model="+files[i].getName()+
+									" cdlpack="+cdlpack+" config=\r\n"+
+									XMLUtils.getText(validator, true));
+						}
+
+						updateConfiguration(validator,
+								existingServiceDescriptions,
+								existingInputKeys, existingOutputKeys);
+						
+						fis.close();
+					} catch(Exception e) {
+						logger.log(Level.SEVERE,
+								"Failed to update configuration for model '"+
+								files[i].getName()+"'", e);
+					}
+				}
+			}
+			
+			// Any remaining service description names need to
+			// have their associated monitors removed
+			java.util.Iterator<String> iter=
+					existingServiceDescriptions.iterator();
+			
+			while (iter.hasNext()) {
+				String sdescName=iter.next();
+				
+				try {
+					logger.info("Removing service monitor for '"+sdescName+"'");
+					ValidatorManager.removeServiceMonitor(sdescName);
+				} catch(Exception e) {
+					logger.log(Level.SEVERE,
+							"Failed to remove service monitor '"+sdescName+"'", e);
+				}
+			}
+			
+			// Any remaining input keys need to be removed
+			iter = existingInputKeys.iterator();
+			
+			while (iter.hasNext()) {
+				String key=iter.next();
+				m_inputServices.remove(key);
+			}
+			
+			// Any remaining output keys need to be removed
+			iter = existingOutputKeys.iterator();
+			
+			while (iter.hasNext()) {
+				String key=iter.next();
+				m_outputServices.remove(key);
+			}
+		}
+		
+		protected long getLastUpdate() {
+			long ret=0;
+			
+			if (m_validatorConfigFile != null) {
+				ret = m_validatorConfigFile.lastModified();
+			}
+			
+			if (m_modelsDir != null) {
+				java.io.File[] files=m_modelsDir.listFiles();
+				
+				for (int i=0; i < files.length; i++) {
+					if (files[i].getName().endsWith(".cdm") &&
+							ret < files[i].lastModified()) {
+						ret = files[i].lastModified();
+					}
+				}
+			}
+			
+			return(ret);
+		}
+		
+		private java.io.File m_validatorConfigFile=null;
+		private java.io.File m_modelsDir=null;
+		private long m_lastUpdate=0;
+	}
+}

Added: cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorGenerator.java
===================================================================
--- cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorGenerator.java	                        (rev 0)
+++ cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorGenerator.java	2009-02-06 12:18:23 UTC (rev 479)
@@ -0,0 +1,229 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.pi4soa.cdl.*;
+import org.pi4soa.common.annotations.*;
+import org.pi4soa.common.xml.XMLUtils;
+
+/**
+ * This class provides a generator for the JBossESB Validator
+ * configuration.
+ */
+public class ValidatorGenerator {
+
+	private static final String CDM_FILE_PATH_ATTR = "cdmFilePath";
+	private static final String FILE_PATH_PREFIX = "models/";
+	private static final String SERVICE_ELEMENT = "service";
+	private static final String VALIDATOR_ELEMENT = "validator";
+
+	public ValidatorGenerator() {
+	}
+	
+	public org.w3c.dom.Element generate(org.pi4soa.cdl.Package cdlpack,
+					String cdmFileName) {
+		org.w3c.dom.Element ret=null;
+		
+		try {
+			ret = createValidatorConfig();
+		
+			String cdmFilePath=getFilePath(cdmFileName);
+			
+			// Create the new entries for the supplied choreography
+			createEntries(ret, cdmFilePath, cdlpack);
+			
+		} catch(Exception e) {
+			e.printStackTrace();
+		}
+		
+		return(ret);
+	}
+	
+	protected org.w3c.dom.Element createValidatorConfig()
+							throws Exception {
+		org.w3c.dom.Element ret=null;
+		
+		org.w3c.dom.Document doc=
+				javax.xml.parsers.DocumentBuilderFactory.
+				newInstance().newDocumentBuilder().newDocument();
+		
+		ret = doc.createElement(VALIDATOR_ELEMENT);
+		
+		doc.appendChild(ret);
+		
+		return(ret);
+	}
+		
+	protected void createEntries(org.w3c.dom.Element validator,
+						String cdmFilePath, org.pi4soa.cdl.Package cdlpack) {
+		
+		for (int i=0; i < cdlpack.getTypeDefinitions().getParticipantTypes().size(); i++) {
+			org.pi4soa.cdl.ParticipantType ptype=
+				cdlpack.getTypeDefinitions().getParticipantTypes().get(i);
+			
+			org.w3c.dom.Element service=
+				validator.getOwnerDocument().createElement(SERVICE_ELEMENT);
+		
+			service.setAttribute(CDM_FILE_PATH_ATTR, cdmFilePath);
+			service.setAttribute("participantType", ptype.getName());
+			
+			cdlpack.visit(new InputOutputAnalyser(ptype, service));
+
+			if (service.getFirstChild() != null) {
+				validator.appendChild(service);
+			}
+		}
+	}
+	
+	protected String getFilePath(String cdmFileName) {
+		return(FILE_PATH_PREFIX+cdmFileName);
+	}
+	
+	private static Logger logger = Logger.getLogger("org.jboss.tools.overlord.cdl.validator.jbossesb.actions");
+
+	public class InputOutputAnalyser extends DefaultCDLVisitor {
+		
+		private static final String JBOSSESB_ANNOTATION = "jbossesb";
+		private static final String JBOSSESB_ELEMENT = "jbossesb";
+		private static final String DESTINATION_ELEMENT = "destination";
+		private static final String NAME_ATTR = "name";
+		private static final String EPR_ATTR = "epr";
+		private static final String INPUT_ELEMENT = "input";
+		private static final String OUTPUT_ELEMENT = "output";
+		
+		public InputOutputAnalyser(org.pi4soa.cdl.ParticipantType ptype,
+							org.w3c.dom.Element service) {
+			m_participantType = ptype;
+			m_service = service;
+			
+			m_templateProcessor =
+				org.pi4soa.common.annotations.AnnotationsManagerFactory.getAnnotationsManager().getTemplateProcessor(JBOSSESB_ANNOTATION);
+		}
+		
+		public void interaction(Interaction interaction) {
+			if (m_participantType.getRoleTypes().contains(interaction.getFromRoleType()) ||
+					(interaction.getFromParticipant() != null &&
+						Collections.disjoint(m_participantType.getRoleTypes(),
+								interaction.getFromParticipant().getRoleTypes()) == false)) {
+				
+				for (int i=0; i < interaction.getExchangeDetails().size(); i++) {
+					processExchangeDetails(interaction.getExchangeDetails().get(i), true);
+				}
+			} else if (m_participantType.getRoleTypes().contains(interaction.getToRoleType()) ||
+					(interaction.getToParticipant() != null &&
+							Collections.disjoint(m_participantType.getRoleTypes(),
+									interaction.getToParticipant().getRoleTypes()) == false)) {
+				for (int i=0; i < interaction.getExchangeDetails().size(); i++) {
+					processExchangeDetails(interaction.getExchangeDetails().get(i), false);
+				}
+			}
+		}
+		
+		protected void processExchangeDetails(ExchangeDetails details, boolean from) {
+
+			for (int i=0; i < details.getSemanticAnnotations().size(); i++) {
+				SemanticAnnotation sa=details.getSemanticAnnotations().get(i);
+				org.w3c.dom.Element dest=null;
+				
+				if (sa.getAnnotation() != null && sa.getName() != null &&
+						sa.getName().equals(JBOSSESB_ANNOTATION)) {
+					try {
+						// Transform the text representation to DOM
+						DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance();
+						fact.setNamespaceAware(true);
+						
+						DocumentBuilder builder=fact.newDocumentBuilder();
+						org.w3c.dom.Document doc=
+								builder.parse(new java.io.ByteArrayInputStream(
+										sa.getAnnotation().getBytes()));
+						
+						if (doc.getDocumentElement() != null &&
+								doc.getDocumentElement().getNodeName().equals(
+											JBOSSESB_ELEMENT)) {
+							org.w3c.dom.NodeList nl=
+								doc.getDocumentElement().getElementsByTagName(DESTINATION_ELEMENT);
+							
+							if (nl.getLength() == 1) {
+								dest = (org.w3c.dom.Element)nl.item(0);
+							} else if (nl.getLength() > 1) {
+								logger.severe("Too many destination elements ("+
+										nl.getLength()+") found");
+							} else {
+								logger.severe("No destinations found");
+							}
+						}
+						
+					} catch(Exception e) {
+						logger.log(Level.SEVERE,
+								"Failed to load jbossesb annotation", e);
+					}
+				}
+				
+				if (dest != null) {
+					processDestination(details, dest, from);
+				}
+			}
+		}
+				
+		protected void processDestination(ExchangeDetails details,
+					org.w3c.dom.Element dest, boolean from) {
+			String elemName=null;
+			
+			if (dest != null &&
+					dest.getAttribute("temporary").equalsIgnoreCase("true") == false) {
+				if (from) {
+					if (details.getAction() == ExchangeActionType.REQUEST) {
+						elemName = OUTPUT_ELEMENT;
+					} else {
+						elemName = INPUT_ELEMENT;
+					}
+				} else {
+					if (details.getAction() == ExchangeActionType.REQUEST) {
+						elemName = INPUT_ELEMENT;
+					} else {
+						elemName = OUTPUT_ELEMENT;
+					}
+				}
+				
+				// Parameter has been stored in a structured manner
+				// to support use of templates and presentations,
+				// so need to extract the value
+				java.util.List<TemplateParameter> params=
+					m_templateProcessor.getTemplateParameters(dest.getAttribute(NAME_ATTR));
+				
+				if (params != null && params.size() > 0) {
+					org.w3c.dom.Element elem=m_service.getOwnerDocument().createElement(elemName);
+					elem.setAttribute(EPR_ATTR, params.get(0).getValue());
+					
+					m_service.appendChild(elem);
+				}
+			}
+		}
+
+		private ParticipantType m_participantType=null;
+		private org.w3c.dom.Element m_service=null;
+		private org.pi4soa.common.annotations.TemplateProcessor m_templateProcessor=null;
+	}
+}

Added: cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorManager.java
===================================================================
--- cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorManager.java	                        (rev 0)
+++ cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorManager.java	2009-02-06 12:18:23 UTC (rev 479)
@@ -0,0 +1,234 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.pi4soa.service.ServiceException;
+import org.pi4soa.service.behavior.ServiceDescription;
+import org.pi4soa.service.monitor.*;
+
+public class ValidatorManager {
+
+	/**
+	 * This method returns a reference to the service monitor
+	 * associated with the supplied service description name,
+	 * or null if one does not exist.
+	 * 
+	 * @param sdesc The service description name
+	 * @return The service monitor, or null if does not exist
+	 */
+	public static ServiceMonitor getServiceMonitor(String sdesc) {
+		ServiceMonitor ret=null;
+		
+		synchronized(m_serviceMonitors) {
+			ret = (ServiceMonitor)m_serviceMonitors.get(sdesc);
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns a reference counted Service Monitor
+	 * associated with the supplied service description.
+	 * 
+	 * @param sdesc The service description
+	 * @return The service monitor
+	 */
+	public static ServiceMonitor createServiceContainer(ServiceDescription sdesc) {
+		return(createServiceContainer(sdesc, true));
+	}
+	
+	/**
+	 * This method returns a reference counted Service Monitor
+	 * associated with the supplied service description.
+	 * 
+	 * @param sdesc The service description
+	 * @param validate Whether the behavior should be validated
+	 * @return The service monitor
+	 */
+	public static ServiceMonitor createServiceContainer(ServiceDescription sdesc,
+							boolean validate) {
+		ServiceMonitor ret=null;
+		
+		synchronized(m_serviceMonitors) {
+
+			if ((ret = (ServiceMonitor)m_serviceMonitors.get(
+					sdesc.getFullyQualifiedName())) == null) {
+				
+				if (logger.isLoggable(Level.FINE)) {
+					logger.fine("Service monitor for '"+
+								sdesc.getFullyQualifiedName()+
+								"' being created");
+				}
+
+				try {
+					// Use XML configuration, to enable alternative
+					// runtime configuration to be specified by
+					// including a pi4soa.xml file in the environment
+					DefaultMonitorConfiguration conf=
+						new XMLMonitorConfiguration();
+					
+					conf.setValidateBehaviour(validate);
+
+					ret = ServiceMonitorFactory.getServiceMonitor(conf);
+					
+					// Register service description
+					ret.getConfiguration().getServiceRepository().
+								addServiceDescription(sdesc);
+					
+					logger.info("Created monitor for service description "+sdesc.getFullyQualifiedName());
+
+					m_serviceMonitors.put(sdesc.getFullyQualifiedName(), ret);
+
+					//m_serviceMonitorCounters.put(sdesc.getFullyQualifiedName(), new Integer(1));
+					
+				} catch(Exception e) {
+					logger.severe("Failed to initialize service monitor: "+e);
+				}
+			} else {
+				
+				// Service monitor already in use for the service
+				// description, so update description
+				try {
+					// Clear previous version of the service description
+					ServiceDescription[] sdescs=
+							ret.getConfiguration().getServiceRepository().getServiceDescriptions();
+					
+					for (int i=0; sdescs != null && i < sdescs.length; i++) {
+						ret.getConfiguration().getServiceRepository().
+									removeServiceDescription(sdescs[i]);
+					}
+					
+					logger.info("Updating service description for "+sdesc.getFullyQualifiedName());
+					
+					ret.getConfiguration().getServiceRepository().addServiceDescription(sdesc);
+				} catch(Exception e) {
+					logger.log(Level.SEVERE, "Failed to update service description '"+
+									sdesc.getFullyQualifiedName()+"'", e);
+				}
+				
+				/* MAY REMOVE
+				 * 
+				// Increment the counter
+				Integer counter=(Integer)m_serviceMonitorCounters.get(sdesc.getFullyQualifiedName());
+				if (counter != null) {
+					counter = new Integer(counter.intValue()+1);
+					m_serviceMonitorCounters.put(sdesc.getFullyQualifiedName(), counter);
+					
+					if (logger.isLoggable(Level.FINE)) {
+						logger.fine("Service monitor for '"+
+							sdesc.getFullyQualifiedName()+"' reference count now: "+counter);
+					}
+				} else {
+					logger.severe("Failed to find counter for "+sdesc.getFullyQualifiedName());
+				}
+				 */
+			}
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method removes the service monitor associated with
+	 * the supplied service description name.
+	 * 
+	 * @param sdesc The service description name
+	 * @throws ServiceException Failed to remove the service monitor
+	 */
+	public static void removeServiceMonitor(String sdesc)
+							throws ServiceException {
+		synchronized(m_serviceMonitors) {
+			ServiceMonitor monitor=(ServiceMonitor)
+					m_serviceMonitors.remove(sdesc);
+
+			if (monitor != null) {
+				monitor.close();
+			}
+		}
+	}
+	
+	/**
+	 * This method decrements the service monitor reference count
+	 * associated with the service description, and if reaches zero,
+	 * then it will close the service monitor.
+	 * 
+	 * @param sdesc The service description name
+	 * @throws ServiceException Failed to release the service monitor
+	 */
+	public static void releaseServiceMonitor(String sdesc)
+							throws ServiceException {
+		
+		/* MAY REMOVE
+		 * 
+		synchronized(m_serviceMonitors) {
+
+			Integer counter=(Integer)m_serviceMonitorCounters.get(sdesc);
+			if (counter != null) {
+				
+				if (counter.intValue() > 1) {
+					counter = new Integer(counter.intValue()-1);
+					m_serviceMonitorCounters.put(sdesc, counter);
+
+					if (logger.isLoggable(Level.FINE)) {
+						logger.fine("Service monitor for '"+
+							sdesc+"' reference count now: "+counter);
+					}
+				} else {
+					if (logger.isLoggable(Level.FINE)) {
+						logger.fine("Service monitor for '"+
+							sdesc+"' being closed");
+					}
+
+					m_serviceMonitorCounters.remove(sdesc);
+					
+					ServiceMonitor monitor=(ServiceMonitor)
+								m_serviceMonitors.remove(sdesc);
+					
+					monitor.close();
+				}
+			} else {
+				logger.severe("Failed to find counter for "+sdesc);
+			}
+		}
+		 */
+	}
+	
+	/**
+	 * This method returns the set of service description names
+	 * that are associated with service monitors.
+	 * 
+	 * @return The set of service monitors
+	 */
+	public static java.util.Set<String> getServiceDescriptionNames() {
+		java.util.Set<String> ret=new java.util.HashSet<String>();
+		
+		// Return copy to ensure changes in the map, do not
+		// affect the returned set of names
+		ret.addAll(m_serviceMonitors.keySet());
+		
+		return(ret);
+	}
+
+	private static Logger logger = Logger.getLogger("org.pi4soa.jbossesb.validator");
+
+	private static java.util.Map<String,ServiceMonitor> m_serviceMonitors=new java.util.Hashtable<String,ServiceMonitor>();
+	//private static java.util.Map<String,Integer> m_serviceMonitorCounters=new java.util.Hashtable<String,Integer>();
+}




More information about the overlord-commits mailing list