Author: thomas.diesler(a)jboss.com
Date: 2007-08-02 02:24:26 -0400 (Thu, 02 Aug 2007)
New Revision: 4072
Added:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/ServiceRefMetaDataParserFactory.java
spi/trunk/src/main/java/org/jboss/wsf/spi/util/
spi/trunk/src/main/java/org/jboss/wsf/spi/util/KernelLocator.java
spi/trunk/src/main/java/org/jboss/wsf/spi/util/ServiceLoader.java
Removed:
spi/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java
spi/trunk/src/main/java/org/jboss/wsf/common/KernelLocator.java
spi/trunk/src/main/java/org/jboss/wsf/common/ServiceLoader.java
Modified:
spi/trunk/src/main/java/org/jboss/wsf/spi/SPIProviderResolver.java
spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/DeploymentAspect.java
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/ServiceRefMetaDataParser.java
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedHandlerMetaData.java
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedPortComponentRefMetaData.java
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedServiceRefMetaData.java
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractConsumer.java
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractProvider.java
Log:
Remove unwanted classes
Deleted: spi/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java 2007-08-01 22:58:35 UTC
(rev 4071)
+++ spi/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java 2007-08-02 06:24:26 UTC
(rev 4072)
@@ -1,619 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY 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 along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.wsf.common;
-
-// $Id$
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.jboss.logging.Logger;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-/**
- * DOM2 utilites
- *
- * @author Thomas.Diesler(a)jboss.org
- */
-public final class DOMUtils
-{
- private static Logger log = Logger.getLogger(DOMUtils.class);
-
- // All elements created by the same thread are created by the same builder and belong
to the same doc
- private static ThreadLocal documentThreadLocal = new ThreadLocal();
- private static ThreadLocal builderThreadLocal = new ThreadLocal()
- {
- protected Object initialValue()
- {
- try
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setValidating(false);
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- setEntityResolver(builder);
- return builder;
- }
- catch (ParserConfigurationException e)
- {
- throw new RuntimeException("Failed to create DocumentBuilder", e);
- }
- }
-
- private void setEntityResolver(DocumentBuilder builder)
- {
- String[] resolvers = new String[] {
"org.jboss.ws.core.utils.JBossWSEntityResolver",
"org.jboss.util.xml.JBossEntityResolver" };
-
- EntityResolver entityResolver = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- for (String resolver : resolvers)
- {
- try
- {
- Class<?> resolverClass = loader.loadClass(resolver);
- entityResolver = (EntityResolver)resolverClass.newInstance();
- }
- catch (Exception ex)
- {
- log.debug("Cannot load: " + resolver);
- }
- }
-
- if (entityResolver != null)
- builder.setEntityResolver(entityResolver);
- }
- };
-
- // Hide the constructor
- private DOMUtils()
- {
- }
-
- /** Initialise the the DocumentBuilder
- */
- public static DocumentBuilder getDocumentBuilder()
- {
- DocumentBuilder builder = (DocumentBuilder)builderThreadLocal.get();
- return builder;
- }
-
- /** Parse the given XML string and return the root Element
- */
- public static Element parse(String xmlString) throws IOException
- {
- try
- {
- return parse(new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
- }
- catch (IOException e)
- {
- log.error("Cannot parse: " + xmlString);
- throw e;
- }
- }
-
- /** Parse the given XML stream and return the root Element
- */
- public static Element parse(InputStream xmlStream) throws IOException
- {
- try
- {
- Document doc = getDocumentBuilder().parse(xmlStream);
- Element root = doc.getDocumentElement();
- return root;
- }
- catch (SAXException e)
- {
- throw new IOException(e.toString());
- }
- }
-
- /** Parse the given input source and return the root Element
- */
- public static Element parse(InputSource source) throws IOException
- {
- try
- {
- Document doc = getDocumentBuilder().parse(source);
- Element root = doc.getDocumentElement();
- return root;
- }
- catch (SAXException e)
- {
- throw new IOException(e.toString());
- }
- }
-
- /** Create an Element for a given name
- */
- public static Element createElement(String localPart)
- {
- Document doc = getOwnerDocument();
- log.trace("createElement {}" + localPart);
- return doc.createElement(localPart);
- }
-
- /** Create an Element for a given name and prefix
- */
- public static Element createElement(String localPart, String prefix)
- {
- Document doc = getOwnerDocument();
- log.trace("createElement {}" + prefix + ":" + localPart);
- return doc.createElement(prefix + ":" + localPart);
- }
-
- /** Create an Element for a given name, prefix and uri
- */
- public static Element createElement(String localPart, String prefix, String uri)
- {
- Document doc = getOwnerDocument();
- if (prefix == null || prefix.length() == 0)
- {
- log.trace("createElement {" + uri + "}" + localPart);
- return doc.createElementNS(uri, localPart);
- }
- else
- {
- log.trace("createElement {" + uri + "}" + prefix +
":" + localPart);
- return doc.createElementNS(uri, prefix + ":" + localPart);
- }
- }
-
- /** Create an Element for a given QName
- */
- public static Element createElement(QName qname)
- {
- return createElement(qname.getLocalPart(), qname.getPrefix(),
qname.getNamespaceURI());
- }
-
- /** Create a org.w3c.dom.Text node
- */
- public static Text createTextNode(String value)
- {
- Document doc = getOwnerDocument();
- return doc.createTextNode(value);
- }
-
- /** Get the qname of the given node.
- */
- public static QName getElementQName(Element el)
- {
- String qualifiedName = el.getNodeName();
- return resolveQName(el, qualifiedName);
- }
-
- /** Transform the given qualified name into a QName
- */
- public static QName resolveQName(Element el, String qualifiedName)
- {
- QName qname;
- String prefix = "";
- String namespaceURI = "";
- String localPart = qualifiedName;
-
- int colIndex = qualifiedName.indexOf(":");
- if (colIndex > 0)
- {
- prefix = qualifiedName.substring(0, colIndex);
- localPart = qualifiedName.substring(colIndex + 1);
-
- if ("xmlns".equals(prefix))
- {
- namespaceURI = "URI:XML_PREDEFINED_NAMESPACE";
- }
- else
- {
- Element nsElement = el;
- while (namespaceURI.equals("") && nsElement != null)
- {
- namespaceURI = nsElement.getAttribute("xmlns:" + prefix);
- if (namespaceURI.equals(""))
- nsElement = getParentElement(nsElement);
- }
- }
-
- if (namespaceURI.equals(""))
- throw new IllegalArgumentException("Cannot find namespace uri for:
" + qualifiedName);
- }
- else
- {
- Element nsElement = el;
- while (namespaceURI.equals("") && nsElement != null)
- {
- namespaceURI = nsElement.getAttribute("xmlns");
- if (namespaceURI.equals(""))
- nsElement = getParentElement(nsElement);
- }
- }
-
- qname = new QName(namespaceURI, localPart, prefix);
- return qname;
- }
-
- /** Get the value from the given attribute
- *
- * @return null if the attribute value is empty or the attribute is not present
- */
- public static String getAttributeValue(Element el, String attrName)
- {
- return getAttributeValue(el, new QName(attrName));
- }
-
- /** Get the value from the given attribute
- *
- * @return null if the attribute value is empty or the attribute is not present
- */
- public static String getAttributeValue(Element el, QName attrName)
- {
- String attr = null;
- if ("".equals(attrName.getNamespaceURI()))
- attr = el.getAttribute(attrName.getLocalPart());
- else attr = el.getAttributeNS(attrName.getNamespaceURI(),
attrName.getLocalPart());
-
- if ("".equals(attr))
- attr = null;
-
- return attr;
- }
-
- /** Get the qname value from the given attribute
- */
- public static QName getAttributeValueAsQName(Element el, String attrName)
- {
- return getAttributeValueAsQName(el, new QName(attrName));
-
- }
-
- /** Get the qname value from the given attribute
- */
- public static QName getAttributeValueAsQName(Element el, QName attrName)
- {
- QName qname = null;
-
- String qualifiedName = getAttributeValue(el, attrName);
- if (qualifiedName != null)
- {
- qname = resolveQName(el, qualifiedName);
- }
-
- return qname;
- }
-
- /** Get the boolean value from the given attribute
- */
- public static boolean getAttributeValueAsBoolean(Element el, String attrName)
- {
- return getAttributeValueAsBoolean(el, new QName(attrName));
- }
-
- /** Get the boolean value from the given attribute
- */
- public static boolean getAttributeValueAsBoolean(Element el, QName attrName)
- {
- String attrVal = getAttributeValue(el, attrName);
- boolean ret = "true".equalsIgnoreCase(attrVal) ||
"1".equalsIgnoreCase(attrVal);
- return ret;
- }
-
- /** Get the integer value from the given attribute
- */
- public static Integer getAttributeValueAsInteger(Element el, String attrName)
- {
- return getAttributeValueAsInteger(el, new QName(attrName));
- }
-
- /** Get the integer value from the given attribute
- */
- public static Integer getAttributeValueAsInteger(Element el, QName attrName)
- {
- String attrVal = getAttributeValue(el, attrName);
- return (attrVal != null ? new Integer(attrVal) : null);
- }
-
- /** Get the attributes as Map<QName, String>
- */
- public static Map getAttributes(Element el)
- {
- Map attmap = new HashMap();
- NamedNodeMap attribs = el.getAttributes();
- for (int i = 0; i < attribs.getLength(); i++)
- {
- Attr attr = (Attr)attribs.item(i);
- String name = attr.getName();
- QName qname = resolveQName(el, name);
- String value = attr.getNodeValue();
- attmap.put(qname, value);
- }
- return attmap;
- }
-
- /** Copy attributes between elements
- */
- public static void copyAttributes(Element destElement, Element srcElement)
- {
- NamedNodeMap attribs = srcElement.getAttributes();
- for (int i = 0; i < attribs.getLength(); i++)
- {
- Attr attr = (Attr)attribs.item(i);
- String uri = attr.getNamespaceURI();
- String qname = attr.getName();
- String value = attr.getNodeValue();
-
- // Prevent DOMException: NAMESPACE_ERR: An attempt is made to create or
- // change an object in a way which is incorrect with regard to namespaces.
- if (uri == null && qname.startsWith("xmlns"))
- {
- log.trace("Ignore attribute: [uri=" + uri + ",qname=" +
qname + ",value=" + value + "]");
- }
- else
- {
- destElement.setAttributeNS(uri, qname, value);
- }
- }
- }
-
- /** True if the node has child elements
- */
- public static boolean hasChildElements(Node node)
- {
- NodeList nlist = node.getChildNodes();
- for (int i = 0; i < nlist.getLength(); i++)
- {
- Node child = nlist.item(i);
- if (child.getNodeType() == Node.ELEMENT_NODE)
- return true;
- }
- return false;
- }
-
- /** Gets child elements
- */
- public static Iterator getChildElements(Node node)
- {
- ArrayList list = new ArrayList();
- NodeList nlist = node.getChildNodes();
- for (int i = 0; i < nlist.getLength(); i++)
- {
- Node child = nlist.item(i);
- if (child.getNodeType() == Node.ELEMENT_NODE)
- list.add(child);
- }
- return list.iterator();
- }
-
- /** Get the concatenated text content, or null.
- */
- public static String getTextContent(Node node)
- {
- boolean hasTextContent = false;
- StringBuffer buffer = new StringBuffer();
- NodeList nlist = node.getChildNodes();
- for (int i = 0; i < nlist.getLength(); i++)
- {
- Node child = nlist.item(i);
- if (child.getNodeType() == Node.TEXT_NODE)
- {
- buffer.append(child.getNodeValue());
- hasTextContent = true;
- }
- }
- return (hasTextContent ? buffer.toString() : null);
- }
-
- /** Gets the first child element
- */
- public static Element getFirstChildElement(Node node)
- {
- return getFirstChildElementIntern(node, null);
- }
-
- /** Gets the first child element for a given local name without namespace
- */
- public static Element getFirstChildElement(Node node, String nodeName)
- {
- return getFirstChildElementIntern(node, new QName(nodeName));
- }
-
- /** Gets the first child element for a given qname
- */
- public static Element getFirstChildElement(Node node, QName nodeName)
- {
- return getFirstChildElementIntern(node, nodeName);
- }
-
- private static Element getFirstChildElementIntern(Node node, QName nodeName)
- {
- Element childElement = null;
- Iterator it = getChildElementsIntern(node, nodeName);
- if (it.hasNext())
- {
- childElement = (Element)it.next();
- }
- return childElement;
- }
-
- /** Gets the child elements for a given local name without namespace
- */
- public static Iterator getChildElements(Node node, String nodeName)
- {
- return getChildElementsIntern(node, new QName(nodeName));
- }
-
- /** Gets the child element for a given qname
- */
- public static Iterator getChildElements(Node node, QName nodeName)
- {
- return getChildElementsIntern(node, nodeName);
- }
-
- private static Iterator getChildElementsIntern(Node node, QName nodeName)
- {
- ArrayList list = new ArrayList();
- NodeList nlist = node.getChildNodes();
- for (int i = 0; i < nlist.getLength(); i++)
- {
- Node child = nlist.item(i);
- if (child.getNodeType() == Node.ELEMENT_NODE)
- {
- if (nodeName == null)
- {
- list.add(child);
- }
- else
- {
- QName qname;
- if (nodeName.getNamespaceURI().length() > 0)
- {
- qname = new QName(child.getNamespaceURI(), child.getLocalName());
- }
- else
- {
- qname = new QName(child.getLocalName());
- }
- if (qname.equals(nodeName))
- {
- list.add(child);
- }
- }
- }
- }
- return list.iterator();
- }
-
- /** Gets parent element or null if there is none
- */
- public static Element getParentElement(Node node)
- {
- Node parent = node.getParentNode();
- return (parent instanceof Element ? (Element)parent : null);
- }
-
- /** Get the owner document that is associated with the current thread */
- public static Document getOwnerDocument()
- {
- Document doc = (Document)documentThreadLocal.get();
- if (doc == null)
- {
- doc = getDocumentBuilder().newDocument();
- documentThreadLocal.set(doc);
- }
- return doc;
- }
-
- public static Element sourceToElement(Source source) throws IOException
- {
- Element retElement = null;
-
- try
- {
- if (source instanceof StreamSource)
- {
- StreamSource streamSource = (StreamSource)source;
-
- InputStream ins = streamSource.getInputStream();
- if (ins != null)
- {
- retElement = DOMUtils.parse(ins);
- }
- else
- {
- Reader reader = streamSource.getReader();
- retElement = DOMUtils.parse(new InputSource(reader));
- }
- }
- else if (source instanceof DOMSource)
- {
- DOMSource domSource = (DOMSource)source;
- Node node = domSource.getNode();
- if (node instanceof Element)
- {
- retElement = (Element)node;
- }
- else if (node instanceof Document)
- {
- retElement = ((Document)node).getDocumentElement();
- }
- else
- {
- throw new RuntimeException("Unsupported Node type: " +
node.getClass().getName());
- }
- }
- else if (source instanceof SAXSource)
- {
- // The fact that JAXBSource derives from SAXSource is an implementation
detail.
- // Thus in general applications are strongly discouraged from accessing
methods defined on SAXSource.
- // The XMLReader object obtained by the getXMLReader method shall be used
only for parsing the InputSource object returned by the getInputSource method.
-
- TransformerFactory tf = TransformerFactory.newInstance();
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- Transformer transformer = tf.newTransformer();
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
"yes");
- transformer.setOutputProperty(OutputKeys.METHOD, "xml");
- transformer.transform(source, new StreamResult(baos));
- retElement = DOMUtils.parse(new ByteArrayInputStream(baos.toByteArray()));
- }
- else
- {
- throw new RuntimeException("Source type not implemented: " +
source.getClass().getName());
- }
-
- }
- catch (TransformerException ex)
- {
- IOException ioex = new IOException();
- ioex.initCause(ex);
- throw ioex;
- }
-
- return retElement;
- }
-}
Deleted: spi/trunk/src/main/java/org/jboss/wsf/common/KernelLocator.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/common/KernelLocator.java 2007-08-01 22:58:35
UTC (rev 4071)
+++ spi/trunk/src/main/java/org/jboss/wsf/common/KernelLocator.java 2007-08-02 06:24:26
UTC (rev 4072)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY 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 along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.wsf.common;
-
-//$Id: KernelLocator.java 3137 2007-05-18 13:41:57Z thomas.diesler(a)jboss.com $
-
-import org.jboss.kernel.Kernel;
-
-/**
- * Locate the single instance of the kernel
- *
- * @author Thomas.Diesler(a)jboss.org
- * @since 12-May-2006
- */
-public class KernelLocator
-{
- private static Kernel kernel;
-
- public static Kernel getKernel()
- {
- return KernelLocator.kernel;
- }
-
- public void setKernel(Kernel kernel)
- {
- KernelLocator.kernel = kernel;
- }
-}
Deleted: spi/trunk/src/main/java/org/jboss/wsf/common/ServiceLoader.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/common/ServiceLoader.java 2007-08-01 22:58:35
UTC (rev 4071)
+++ spi/trunk/src/main/java/org/jboss/wsf/common/ServiceLoader.java 2007-08-02 06:24:26
UTC (rev 4072)
@@ -1,251 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY 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 along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.wsf.common;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Properties;
-
-// $Id$
-
-/**
- * Load a service class using this ordered lookup procedure
- *
- * @author Thomas.Diesler(a)jboss.com
- * @since 14-Dec-2006
- */
-public abstract class ServiceLoader
-{
- /**
- * This method uses the algorithm below using the JAXWS Provider as an example.
- *
- * 1. If a resource with the name of META-INF/services/javax.xml.ws.spi.Provider
exists, then
- * its first line, if present, is used as the UTF-8 encoded name of the implementation
class.
- *
- * 2. If the ${java.home}/lib/jaxws.properties file exists and it is readable by the
- * java.util.Properties.load(InputStream) method and it contains an entry whose key is
- * javax.xml.ws.spi.Provider, then the value of that entry is used as the name of the
implementation class.
- *
- * 3. If a system property with the name javax.xml.ws.spi.Provider is defined, then
its value is used
- * as the name of the implementation class.
- *
- * 4. Finally, a default implementation class name is used.
- */
- public static Object loadService(String propertyName, String defaultFactory)
- {
- Object factory = loadFromServices(propertyName, null);
- if (factory == null)
- {
- factory = loadFromPropertiesFile(propertyName, null);
- }
- if (factory == null)
- {
- factory = loadFromSystemProperty(propertyName, defaultFactory);
- }
- return factory;
- }
-
- /** Use the Services API (as detailed in the JAR specification), if available, to
determine the classname.
- */
- public static Object loadFromServices(String propertyName, String defaultFactory)
- {
- Object factory = null;
- String factoryName = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
- // Use the Services API (as detailed in the JAR specification), if available, to
determine the classname.
- String filename = "META-INF/services/" + propertyName;
- InputStream inStream = loader.getResourceAsStream(filename);
- if (inStream != null)
- {
- try
- {
- BufferedReader br = new BufferedReader(new InputStreamReader(inStream,
"UTF-8"));
- factoryName = br.readLine();
- br.close();
- if (factoryName != null)
- {
- Class factoryClass = loader.loadClass(factoryName);
- factory = factoryClass.newInstance();
- }
- }
- catch (Throwable t)
- {
- throw new IllegalStateException("Failed to load " + propertyName +
": " + factoryName, t);
- }
- }
-
- // Use the default factory implementation class.
- if (factory == null && defaultFactory != null)
- {
- factory = loadDefault(defaultFactory);
- }
-
- return factory;
- }
-
- /** Use the system property
- */
- public static Object loadFromSystemProperty(String propertyName, String
defaultFactory)
- {
- Object factory = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
- PrivilegedAction action = new PropertyAccessAction(propertyName);
- String factoryName = (String)AccessController.doPrivileged(action);
- if (factoryName != null)
- {
- try
- {
- //if(log.isDebugEnabled()) log.debug("Load from system property: "
+ factoryName);
- Class factoryClass = loader.loadClass(factoryName);
- factory = factoryClass.newInstance();
- }
- catch (Throwable t)
- {
- throw new IllegalStateException("Failed to load " + propertyName +
": " + factoryName, t);
- }
- }
-
- // Use the default factory implementation class.
- if (factory == null && defaultFactory != null)
- {
- factory = loadDefault(defaultFactory);
- }
-
- return factory;
- }
-
- /**
- * Use the properties file "${java.home}/lib/jaxws.properties" in the JRE
directory.
- * This configuration file is in standard java.util.Properties format and contains the
- * fully qualified name of the implementation class with the key being the system
property defined above.
- */
- public static Object loadFromPropertiesFile(String propertyName, String
defaultFactory)
- {
- Object factory = null;
- String factoryName = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
- // Use the properties file "lib/jaxm.properties" in the JRE directory.
- // This configuration file is in standard java.util.Properties format and contains
the fully qualified name of the implementation class with the key being the system
property defined above.
- PrivilegedAction action = new PropertyAccessAction("java.home");
- String javaHome = (String)AccessController.doPrivileged(action);
- File jaxmFile = new File(javaHome + "/lib/jaxws.properties");
- if (jaxmFile.exists())
- {
- try
- {
- action = new PropertyFileAccessAction(jaxmFile.getCanonicalPath());
- Properties jaxmProperties =
(Properties)AccessController.doPrivileged(action);
- factoryName = jaxmProperties.getProperty(propertyName);
- if (factoryName != null)
- {
- //if(log.isDebugEnabled()) log.debug("Load from " + jaxmFile +
": " + factoryName);
- Class factoryClass = loader.loadClass(factoryName);
- factory = factoryClass.newInstance();
- }
- }
- catch (Throwable t)
- {
- throw new IllegalStateException("Failed to load " + propertyName +
": " + factoryName, t);
- }
- }
-
- // Use the default factory implementation class.
- if (factory == null && defaultFactory != null)
- {
- factory = loadDefault(defaultFactory);
- }
-
- return factory;
- }
-
- private static Object loadDefault(String defaultFactory)
- {
- Object factory = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
- // Use the default factory implementation class.
- if (defaultFactory != null)
- {
- try
- {
- //if(log.isDebugEnabled()) log.debug("Load from default: " +
factoryName);
- Class factoryClass = loader.loadClass(defaultFactory);
- factory = factoryClass.newInstance();
- }
- catch (Throwable t)
- {
- throw new IllegalStateException("Failed to load: " +
defaultFactory, t);
- }
- }
-
- return factory;
- }
-
- private static class PropertyAccessAction implements PrivilegedAction
- {
- private String name;
-
- PropertyAccessAction(String name)
- {
- this.name = name;
- }
-
- public Object run()
- {
- return System.getProperty(name);
- }
- }
-
- private static class PropertyFileAccessAction implements PrivilegedAction
- {
- private String filename;
-
- PropertyFileAccessAction(String filename)
- {
- this.filename = filename;
- }
-
- public Object run()
- {
- try
- {
- InputStream inStream = new FileInputStream(filename);
- Properties props = new Properties();
- props.load(inStream);
- return props;
- }
- catch (IOException ex)
- {
- throw new SecurityException("Cannot load properties: " + filename,
ex);
- }
- }
- }
-}
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/SPIProviderResolver.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/SPIProviderResolver.java 2007-08-01 22:58:35
UTC (rev 4071)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/SPIProviderResolver.java 2007-08-02 06:24:26
UTC (rev 4072)
@@ -21,8 +21,9 @@
*/
package org.jboss.wsf.spi;
-import org.jboss.wsf.common.ServiceLoader;
+import org.jboss.wsf.spi.util.ServiceLoader;
+
/**
* Locates an SPIProvider.
*
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/DeploymentAspect.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/DeploymentAspect.java 2007-08-01
22:58:35 UTC (rev 4071)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/deployment/DeploymentAspect.java 2007-08-02
06:24:26 UTC (rev 4072)
@@ -27,11 +27,7 @@
import java.util.Set;
import java.util.StringTokenizer;
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.spi.registry.KernelRegistry;
-import org.jboss.kernel.spi.registry.KernelRegistryEntry;
import org.jboss.logging.Logger;
-import org.jboss.wsf.common.KernelLocator;
/**
* A deployment aspect that does nothing.
Modified:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/ServiceRefMetaDataParser.java
===================================================================
---
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/ServiceRefMetaDataParser.java 2007-08-01
22:58:35 UTC (rev 4071)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/ServiceRefMetaDataParser.java 2007-08-02
06:24:26 UTC (rev 4072)
@@ -23,13 +23,6 @@
// $Id$
-import java.util.Iterator;
-
-import javax.xml.namespace.QName;
-
-import org.jboss.logging.Logger;
-import org.jboss.wsf.common.DOMUtils;
-import org.jboss.xb.QNameBuilder;
import org.w3c.dom.Element;
/**
@@ -38,212 +31,15 @@
*
* @author Thomas.Diesler(a)jboss.org
*/
-public class ServiceRefMetaDataParser
+public interface ServiceRefMetaDataParser
{
- private static final Logger log = Logger.getLogger(ServiceRefMetaDataParser.class);
+ public void importStandardXml(Element root, UnifiedServiceRefMetaData sref);
+
+ public void importJBossXml(Element root, UnifiedServiceRefMetaData sref);
- public void importStandardXml(Element root, UnifiedServiceRefMetaData sref)
- {
- sref.setServiceRefName(getElementContent(root, "service-ref-name"));
- sref.setServiceInterface(getOptionalElementContent(root,
"service-interface"));
- sref.setWsdlFile(getOptionalElementContent(root, "wsdl-file"));
- sref.setMappingFile(getOptionalElementContent(root,
"jaxrpc-mapping-file"));
+ public void importStandardXml(Element root, UnifiedPortComponentRefMetaData pcref);
- Element child = DOMUtils.getFirstChildElement(root, "service-qname");
- if (child != null)
- sref.setServiceQName(QNameBuilder.buildQName(child, getTextContent(child)));
+ public void importJBossXml(Element root, UnifiedPortComponentRefMetaData pcref);
- // Parse the port-component-ref elements
- Iterator iterator = DOMUtils.getChildElements(root,
"port-component-ref");
- while (iterator.hasNext())
- {
- Element pcrefElement = (Element)iterator.next();
- UnifiedPortComponentRefMetaData pcrefMetaData = new
UnifiedPortComponentRefMetaData(sref);
- pcrefMetaData.importStandardXml(pcrefElement);
- sref.addPortComponentRef(pcrefMetaData);
- }
-
- // Parse the handler elements
- iterator = DOMUtils.getChildElements(root, "handler");
- while (iterator.hasNext())
- {
- Element handlerElement = (Element)iterator.next();
- UnifiedHandlerMetaData handlerMetaData = new UnifiedHandlerMetaData();
- handlerMetaData.importStandardXml(handlerElement);
- sref.addHandler(handlerMetaData);
- }
- }
-
- public void importJBossXml(Element root, UnifiedServiceRefMetaData sref)
- {
- sref.setConfigName(getOptionalElementContent(root, "config-name"));
- sref.setConfigFile(getOptionalElementContent(root, "config-file"));
- sref.setWsdlOverride(getOptionalElementContent(root, "wsdl-override"));
-
- // Parse the port-component-ref elements
- Iterator iterator = DOMUtils.getChildElements(root,
"port-component-ref");
- while (iterator.hasNext())
- {
- Element pcrefElement = (Element)iterator.next();
- String seiName = getOptionalElementContent(pcrefElement,
"service-endpoint-interface");
- QName portName = getOptionalElementContentAsQName(pcrefElement,
"port-qname");
-
- UnifiedPortComponentRefMetaData pcref = sref.getPortComponentRef(seiName,
portName);
- if (pcref == null && seiName != null)
- {
- // Its ok to only have the <port-component-ref> in jboss.xml and not in
ejb-jar.xml
- // if it has at least a SEI declared
- pcref = new UnifiedPortComponentRefMetaData(sref);
- pcref.importStandardXml(pcrefElement);
- sref.addPortComponentRef(pcref);
- }
-
- if (pcref != null)
- pcref.importJBossXml(pcrefElement);
- }
-
- // Parse the call-property elements
- iterator = DOMUtils.getChildElements(root, "call-property");
- while (iterator.hasNext())
- {
- Element propElement = (Element)iterator.next();
- String name = getElementContent(propElement, "prop-name");
- String value = getElementContent(propElement, "prop-value");
- sref.addCallProperty(new UnifiedCallPropertyMetaData(name, value));
- }
- }
-
- public void importStandardXml(Element root, UnifiedPortComponentRefMetaData pcref)
- {
- pcref.setServiceEndpointInterface(getOptionalElementContent(root,
"service-endpoint-interface"));
- pcref.setPortComponentLink(getOptionalElementContent(root,
"port-component-link"));
- }
-
- public void importJBossXml(Element root, UnifiedPortComponentRefMetaData pcref)
- {
- // Look for call-property elements
- Iterator iterator = DOMUtils.getChildElements(root, "call-property");
- while (iterator.hasNext())
- {
- Element propElement = (Element)iterator.next();
- String name = getElementContent(propElement, "prop-name");
- String value = getElementContent(propElement, "prop-value");
- pcref.addCallProperty(new UnifiedCallPropertyMetaData(name, value));
- }
-
- // Look for stub-property elements
- iterator = DOMUtils.getChildElements(root, "stub-property");
- while (iterator.hasNext())
- {
- Element propElement = (Element)iterator.next();
- String name = getElementContent(propElement, "prop-name");
- String value = getElementContent(propElement, "prop-value");
- UnifiedStubPropertyMetaData propMetaData = new UnifiedStubPropertyMetaData();
- propMetaData.setPropName(name);
- propMetaData.setPropValue(value);
- pcref.addStubProperty(propMetaData);
- }
-
- // portQName
- QName portQName = getOptionalElementContentAsQName(root, "port-qname");
- if (portQName != null)
- pcref.setPortQName(portQName);
-
- // config
- Element configName = DOMUtils.getFirstChildElement(root, "config-name");
- if (configName != null)
- pcref.setConfigName(getTextContent(configName));
-
- Element configFile = DOMUtils.getFirstChildElement(root, "config-file");
- if (configFile != null)
- pcref.setConfigFile(getTextContent(configFile));
-
- // service-endpoint-interface
- Element sei = DOMUtils.getFirstChildElement(root,
"service-endpoint-interface");
- if (sei != null)
- pcref.setServiceEndpointInterface(getTextContent(sei));
-
- }
-
- public void importStandardXml(Element root, UnifiedHandlerMetaData href)
- {
- href.setHandlerName(getElementContent(root, "handler-name"));
- href.setHandlerClass(getElementContent(root, "handler-class"));
-
- // Parse the init-param elements
- Iterator iterator = DOMUtils.getChildElements(root, "init-param");
- while (iterator.hasNext())
- {
- Element paramElement = (Element)iterator.next();
- UnifiedInitParamMetaData param = new UnifiedInitParamMetaData();
- param.setParamName(getElementContent(paramElement, "param-name"));
- param.setParamValue(getElementContent(paramElement, "param-value"));
- href.addInitParam(param);
- }
-
- // Parse the soap-header elements
- iterator = DOMUtils.getChildElements(root, "soap-header");
- while (iterator.hasNext())
- {
- Element headerElement = (Element)iterator.next();
- String content = getTextContent(headerElement);
- QName qname = DOMUtils.resolveQName(headerElement, content);
- href.addSoapHeader(qname);
- }
-
- // Parse the soap-role elements
- iterator = DOMUtils.getChildElements(root, "soap-role");
- while (iterator.hasNext())
- {
- Element roleElement = (Element)iterator.next();
- String content = getTextContent(roleElement);
- href.addSoapRole(content);
- }
-
- // Parse the port-name elements
- iterator = DOMUtils.getChildElements(root, "port-name");
- while (iterator.hasNext())
- {
- Element portElement = (Element)iterator.next();
- String content = getTextContent(portElement);
- href.addPortName(content);
- }
- }
-
- private String getElementContent(Element element, String childName)
- {
- String childValue = getOptionalElementContent(element, childName);
- if (childValue == null || childValue.length() == 0)
- throw new IllegalStateException("Invalid null element content: " +
childName);
-
- return childValue;
- }
-
- private String getOptionalElementContent(Element element, String childName)
- {
- return getTextContent(DOMUtils.getFirstChildElement(element, childName));
- }
-
- private QName getOptionalElementContentAsQName(Element element, String childName)
- {
- QName qname = null;
- String value = getOptionalElementContent(element, childName);
- if (value != null)
- {
- qname = (value.startsWith("{") ? QName.valueOf(value) :
DOMUtils.resolveQName(element, value));
- }
- return qname;
- }
-
- private String getTextContent(Element element)
- {
- String content = null;
- if (element != null)
- {
- content = DOMUtils.getTextContent(element);
- if (content != null)
- content = content.trim();
- }
- return content;
- }
+ public void importStandardXml(Element root, UnifiedHandlerMetaData href);
}
Added:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/ServiceRefMetaDataParserFactory.java
===================================================================
---
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/ServiceRefMetaDataParserFactory.java
(rev 0)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/ServiceRefMetaDataParserFactory.java 2007-08-02
06:24:26 UTC (rev 4072)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.spi.metadata.j2ee.serviceref;
+
+// $Id: ServiceRefMetaDataParser.java 3959 2007-07-20 14:44:19Z heiko.braun(a)jboss.com $
+
+/**
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 02-Aug-2007
+ */
+public interface ServiceRefMetaDataParserFactory
+{
+ ServiceRefMetaDataParser getServiceRefMetaDataParser();
+}
Modified:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedHandlerMetaData.java
===================================================================
---
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedHandlerMetaData.java 2007-08-01
22:58:35 UTC (rev 4071)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedHandlerMetaData.java 2007-08-02
06:24:26 UTC (rev 4072)
@@ -30,6 +30,8 @@
import javax.xml.namespace.QName;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.serviceref.ServiceRefElement;
import org.w3c.dom.Element;
@@ -136,7 +138,9 @@
public void importStandardXml(Element root)
{
- new ServiceRefMetaDataParser().importStandardXml(root, this);
+ SPIProvider provider = SPIProviderResolver.getInstance().getProvider();
+ ServiceRefMetaDataParserFactory factory =
provider.getSPI(ServiceRefMetaDataParserFactory.class);
+ factory.getServiceRefMetaDataParser().importStandardXml(root, this);
}
public String toString()
Modified:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedPortComponentRefMetaData.java
===================================================================
---
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedPortComponentRefMetaData.java 2007-08-01
22:58:35 UTC (rev 4071)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedPortComponentRefMetaData.java 2007-08-02
06:24:26 UTC (rev 4072)
@@ -28,6 +28,8 @@
import javax.xml.namespace.QName;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.serviceref.ServiceRefElement;
import org.w3c.dom.Element;
@@ -179,12 +181,16 @@
public void importStandardXml(Element root)
{
- new ServiceRefMetaDataParser().importStandardXml(root, this);
+ SPIProvider provider = SPIProviderResolver.getInstance().getProvider();
+ ServiceRefMetaDataParserFactory factory =
provider.getSPI(ServiceRefMetaDataParserFactory.class);
+ factory.getServiceRefMetaDataParser().importStandardXml(root, this);
}
public void importJBossXml(Element root)
{
- new ServiceRefMetaDataParser().importJBossXml(root, this);
+ SPIProvider provider = SPIProviderResolver.getInstance().getProvider();
+ ServiceRefMetaDataParserFactory factory =
provider.getSPI(ServiceRefMetaDataParserFactory.class);
+ factory.getServiceRefMetaDataParser().importJBossXml(root, this);
}
public boolean matches(String seiName, QName portName)
Modified:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedServiceRefMetaData.java
===================================================================
---
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedServiceRefMetaData.java 2007-08-01
22:58:35 UTC (rev 4071)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedServiceRefMetaData.java 2007-08-02
06:24:26 UTC (rev 4072)
@@ -33,6 +33,8 @@
import javax.xml.ws.WebServiceException;
import org.jboss.logging.Logger;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
import org.jboss.wsf.spi.serviceref.ServiceRefMetaData;
import org.w3c.dom.Element;
@@ -393,13 +395,17 @@
@Override
public void importStandardXml(Element root)
{
- new ServiceRefMetaDataParser().importStandardXml(root, this);
+ SPIProvider provider = SPIProviderResolver.getInstance().getProvider();
+ ServiceRefMetaDataParserFactory factory =
provider.getSPI(ServiceRefMetaDataParserFactory.class);
+ factory.getServiceRefMetaDataParser().importStandardXml(root, this);
}
@Override
public void importJBossXml(Element root)
{
- new ServiceRefMetaDataParser().importJBossXml(root, this);
+ SPIProvider provider = SPIProviderResolver.getInstance().getProvider();
+ ServiceRefMetaDataParserFactory factory =
provider.getSPI(ServiceRefMetaDataParserFactory.class);
+ factory.getServiceRefMetaDataParser().importJBossXml(root, this);
}
public String toString()
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractConsumer.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractConsumer.java 2007-08-01
22:58:35 UTC (rev 4071)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractConsumer.java 2007-08-02
06:24:26 UTC (rev 4072)
@@ -27,7 +27,7 @@
import java.net.URL;
import java.util.List;
-import org.jboss.wsf.common.ServiceLoader;
+import org.jboss.wsf.spi.util.ServiceLoader;
/**
* WSContractConsumer is responsible for generating JAX-WS client and server
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractProvider.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractProvider.java 2007-08-01
22:58:35 UTC (rev 4071)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractProvider.java 2007-08-02
06:24:26 UTC (rev 4072)
@@ -3,7 +3,7 @@
import java.io.File;
import java.io.PrintStream;
-import org.jboss.wsf.common.ServiceLoader;
+import org.jboss.wsf.spi.util.ServiceLoader;
/**
* WSContractProvider is responsible for generating the required portable
Added: spi/trunk/src/main/java/org/jboss/wsf/spi/util/KernelLocator.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/util/KernelLocator.java
(rev 0)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/util/KernelLocator.java 2007-08-02 06:24:26
UTC (rev 4072)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.spi.util;
+
+//$Id: KernelLocator.java 3137 2007-05-18 13:41:57Z thomas.diesler(a)jboss.com $
+
+import org.jboss.kernel.Kernel;
+
+/**
+ * Locate the single instance of the kernel
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 12-May-2006
+ */
+public class KernelLocator
+{
+ private static Kernel kernel;
+
+ public static Kernel getKernel()
+ {
+ return KernelLocator.kernel;
+ }
+
+ public void setKernel(Kernel kernel)
+ {
+ KernelLocator.kernel = kernel;
+ }
+}
Added: spi/trunk/src/main/java/org/jboss/wsf/spi/util/ServiceLoader.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/util/ServiceLoader.java
(rev 0)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/util/ServiceLoader.java 2007-08-02 06:24:26
UTC (rev 4072)
@@ -0,0 +1,251 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.spi.util;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Properties;
+
+// $Id: ServiceLoader.java 3959 2007-07-20 14:44:19Z heiko.braun(a)jboss.com $
+
+/**
+ * Load a service class using this ordered lookup procedure
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 14-Dec-2006
+ */
+public abstract class ServiceLoader
+{
+ /**
+ * This method uses the algorithm below using the JAXWS Provider as an example.
+ *
+ * 1. If a resource with the name of META-INF/services/javax.xml.ws.spi.Provider
exists, then
+ * its first line, if present, is used as the UTF-8 encoded name of the implementation
class.
+ *
+ * 2. If the ${java.home}/lib/jaxws.properties file exists and it is readable by the
+ * java.util.Properties.load(InputStream) method and it contains an entry whose key is
+ * javax.xml.ws.spi.Provider, then the value of that entry is used as the name of the
implementation class.
+ *
+ * 3. If a system property with the name javax.xml.ws.spi.Provider is defined, then
its value is used
+ * as the name of the implementation class.
+ *
+ * 4. Finally, a default implementation class name is used.
+ */
+ public static Object loadService(String propertyName, String defaultFactory)
+ {
+ Object factory = loadFromServices(propertyName, null);
+ if (factory == null)
+ {
+ factory = loadFromPropertiesFile(propertyName, null);
+ }
+ if (factory == null)
+ {
+ factory = loadFromSystemProperty(propertyName, defaultFactory);
+ }
+ return factory;
+ }
+
+ /** Use the Services API (as detailed in the JAR specification), if available, to
determine the classname.
+ */
+ public static Object loadFromServices(String propertyName, String defaultFactory)
+ {
+ Object factory = null;
+ String factoryName = null;
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+ // Use the Services API (as detailed in the JAR specification), if available, to
determine the classname.
+ String filename = "META-INF/services/" + propertyName;
+ InputStream inStream = loader.getResourceAsStream(filename);
+ if (inStream != null)
+ {
+ try
+ {
+ BufferedReader br = new BufferedReader(new InputStreamReader(inStream,
"UTF-8"));
+ factoryName = br.readLine();
+ br.close();
+ if (factoryName != null)
+ {
+ Class factoryClass = loader.loadClass(factoryName);
+ factory = factoryClass.newInstance();
+ }
+ }
+ catch (Throwable t)
+ {
+ throw new IllegalStateException("Failed to load " + propertyName +
": " + factoryName, t);
+ }
+ }
+
+ // Use the default factory implementation class.
+ if (factory == null && defaultFactory != null)
+ {
+ factory = loadDefault(defaultFactory);
+ }
+
+ return factory;
+ }
+
+ /** Use the system property
+ */
+ public static Object loadFromSystemProperty(String propertyName, String
defaultFactory)
+ {
+ Object factory = null;
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+ PrivilegedAction action = new PropertyAccessAction(propertyName);
+ String factoryName = (String)AccessController.doPrivileged(action);
+ if (factoryName != null)
+ {
+ try
+ {
+ //if(log.isDebugEnabled()) log.debug("Load from system property: "
+ factoryName);
+ Class factoryClass = loader.loadClass(factoryName);
+ factory = factoryClass.newInstance();
+ }
+ catch (Throwable t)
+ {
+ throw new IllegalStateException("Failed to load " + propertyName +
": " + factoryName, t);
+ }
+ }
+
+ // Use the default factory implementation class.
+ if (factory == null && defaultFactory != null)
+ {
+ factory = loadDefault(defaultFactory);
+ }
+
+ return factory;
+ }
+
+ /**
+ * Use the properties file "${java.home}/lib/jaxws.properties" in the JRE
directory.
+ * This configuration file is in standard java.util.Properties format and contains the
+ * fully qualified name of the implementation class with the key being the system
property defined above.
+ */
+ public static Object loadFromPropertiesFile(String propertyName, String
defaultFactory)
+ {
+ Object factory = null;
+ String factoryName = null;
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+ // Use the properties file "lib/jaxm.properties" in the JRE directory.
+ // This configuration file is in standard java.util.Properties format and contains
the fully qualified name of the implementation class with the key being the system
property defined above.
+ PrivilegedAction action = new PropertyAccessAction("java.home");
+ String javaHome = (String)AccessController.doPrivileged(action);
+ File jaxmFile = new File(javaHome + "/lib/jaxws.properties");
+ if (jaxmFile.exists())
+ {
+ try
+ {
+ action = new PropertyFileAccessAction(jaxmFile.getCanonicalPath());
+ Properties jaxmProperties =
(Properties)AccessController.doPrivileged(action);
+ factoryName = jaxmProperties.getProperty(propertyName);
+ if (factoryName != null)
+ {
+ //if(log.isDebugEnabled()) log.debug("Load from " + jaxmFile +
": " + factoryName);
+ Class factoryClass = loader.loadClass(factoryName);
+ factory = factoryClass.newInstance();
+ }
+ }
+ catch (Throwable t)
+ {
+ throw new IllegalStateException("Failed to load " + propertyName +
": " + factoryName, t);
+ }
+ }
+
+ // Use the default factory implementation class.
+ if (factory == null && defaultFactory != null)
+ {
+ factory = loadDefault(defaultFactory);
+ }
+
+ return factory;
+ }
+
+ private static Object loadDefault(String defaultFactory)
+ {
+ Object factory = null;
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+ // Use the default factory implementation class.
+ if (defaultFactory != null)
+ {
+ try
+ {
+ //if(log.isDebugEnabled()) log.debug("Load from default: " +
factoryName);
+ Class factoryClass = loader.loadClass(defaultFactory);
+ factory = factoryClass.newInstance();
+ }
+ catch (Throwable t)
+ {
+ throw new IllegalStateException("Failed to load: " +
defaultFactory, t);
+ }
+ }
+
+ return factory;
+ }
+
+ private static class PropertyAccessAction implements PrivilegedAction
+ {
+ private String name;
+
+ PropertyAccessAction(String name)
+ {
+ this.name = name;
+ }
+
+ public Object run()
+ {
+ return System.getProperty(name);
+ }
+ }
+
+ private static class PropertyFileAccessAction implements PrivilegedAction
+ {
+ private String filename;
+
+ PropertyFileAccessAction(String filename)
+ {
+ this.filename = filename;
+ }
+
+ public Object run()
+ {
+ try
+ {
+ InputStream inStream = new FileInputStream(filename);
+ Properties props = new Properties();
+ props.load(inStream);
+ return props;
+ }
+ catch (IOException ex)
+ {
+ throw new SecurityException("Cannot load properties: " + filename,
ex);
+ }
+ }
+ }
+}