[jboss-cvs] JBossAS SVN: r108425 - projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 4 12:15:44 EDT 2010
Author: bstansberry at jboss.com
Date: 2010-10-04 12:15:44 -0400 (Mon, 04 Oct 2010)
New Revision: 108425
Modified:
projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl/StringReplacementServiceBindingValueSourceImpl.java
projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl/XSLTServiceBindingValueSourceImpl.java
Log:
Remove use of deprecated methods
Modified: projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl/StringReplacementServiceBindingValueSourceImpl.java
===================================================================
--- projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl/StringReplacementServiceBindingValueSourceImpl.java 2010-10-04 15:56:05 UTC (rev 108424)
+++ projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl/StringReplacementServiceBindingValueSourceImpl.java 2010-10-04 16:15:44 UTC (rev 108425)
@@ -36,37 +36,37 @@
/**
* A {@link ServiceBindingValueSource} implementation that uses
* string replacement to perform any needed transformations.
- *
+ *
* @author Brian Stansberry
* @version $Revision$
*/
-public class StringReplacementServiceBindingValueSourceImpl
+public class StringReplacementServiceBindingValueSourceImpl
implements StringServiceBindingValueSource, ElementServiceBindingValueSource, URLServiceBindingValueSource
{
-
+
public String getStringServiceBindingValue(ServiceBinding binding, String input)
{
if (input == null)
{
return binding.getHostName();
}
-
+
StringReplacementServiceBindingValueSourceConfig config = getConfig(binding);
return replaceHostAndPort(input, binding.getHostName(), binding.getPort(), config.getHostMarker(), config.getHostforurlMarker(), config.getPortMarker());
- }
-
+ }
+
public Element getElementServiceBindingValue(ServiceBinding binding, Element input)
{
if (input == null)
throw new IllegalArgumentException("input cannot be null");
-
+
PropertyEditor editor = PropertyEditorManager.findEditor(Element.class);
if (editor == null)
throw new IllegalStateException("Cannot find PropertyEditor for type Element");
-
+
StringReplacementServiceBindingValueSourceConfig config = getConfig(binding);
-
+
editor.setValue(input);
String text = editor.getAsText();
text = replaceHostAndPort(text, binding.getHostName(), binding.getPort(), config.getHostMarker(), config.getHostforurlMarker(), config.getPortMarker());
@@ -78,9 +78,9 @@
{
if (input == null)
throw new IllegalArgumentException("input cannot be null");
-
- StringReplacementServiceBindingValueSourceConfig config = getConfig(binding);
-
+
+ StringReplacementServiceBindingValueSourceConfig config = getConfig(binding);
+
try
{
String content = Util.getContentAsString(input);
@@ -98,14 +98,14 @@
{
if (input == null)
throw new IllegalArgumentException("input cannot be null");
-
- StringReplacementServiceBindingValueSourceConfig config = getConfig(binding);
-
+
+ StringReplacementServiceBindingValueSourceConfig config = getConfig(binding);
+
try
{
String content = Util.getContentAsString(input);
String transformed = replaceHostAndPort(content, binding.getHostName(), binding.getPort(), config.getHostMarker(), config.getHostforurlMarker(), config.getPortMarker());
- return Util.writeToTempFile(transformed).toURL();
+ return Util.writeToTempFile(transformed).toURI().toURL();
}
catch (IOException e)
{
@@ -119,30 +119,30 @@
{
return getStringServiceBindingValue(binding, null);
}
-
+
if (params.length != 1)
{
throw new IllegalArgumentException(getClass().getSimpleName() + ".getServiceBindingValue() requires a single-value 'params'");
}
-
+
if (params[0] instanceof String)
- {
+ {
return getStringServiceBindingValue(binding, (String) params[0]);
}
else if (params[0] instanceof Element)
- {
+ {
return getElementServiceBindingValue(binding, (Element) params[0]);
}
else if (params[0] instanceof URL)
- {
+ {
return getURLServiceBindingValue(binding, (URL) params[0]);
}
-
+
throw new IllegalArgumentException(getClass().getSimpleName() + ".getServiceBindingValue() requires a single-value 'params' of type String, Element or URL");
}
-
-
-
+
+
+
// ---------------------------------------------------------------- Private
@@ -158,12 +158,12 @@
return new StringReplacementServiceBindingValueSourceConfig();
}
}
-
+
private String replaceHostAndPort(String text, String host, int port, String hostMarker, String hostforurlMarker, String portMarker)
{
if( text == null )
return null;
-
+
if( host == null )
host = "localhost";
String portStr = String.valueOf(port);
Modified: projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl/XSLTServiceBindingValueSourceImpl.java
===================================================================
--- projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl/XSLTServiceBindingValueSourceImpl.java 2010-10-04 15:56:05 UTC (rev 108424)
+++ projects/service-binding/trunk/core/src/main/java/org/jboss/services/binding/impl/XSLTServiceBindingValueSourceImpl.java 2010-10-04 16:15:44 UTC (rev 108425)
@@ -57,29 +57,29 @@
/**
* A {@link ServiceBindingValueSource} implementation that uses
* XSLT to perform any needed transformations.
- *
- *
+ *
+ *
* @author Brian Stansberry
* @version $Revision$
*/
public class XSLTServiceBindingValueSourceImpl implements URLServiceBindingValueSource, ElementServiceBindingValueSource
{
private static final Logger log = Logger.getLogger(XSLTServiceBindingValueSourceImpl.class);
-
+
public String getResourceServiceBindingValue(ServiceBinding binding, final String input)
{
if (input == null)
throw new IllegalArgumentException("input cannot be null");
-
+
XSLTServiceBindingValueSourceConfig config = getConfig(binding);
-
+
Reader reader = null;
try
{
reader = AccessController.doPrivileged(new PrivilegedExceptionAction<Reader>()
{
public Reader run() throws IOException
- {
+ {
return Util.getInputStreamReader(input);
}
});
@@ -88,7 +88,7 @@
{
throw new RuntimeException("Caught IOException during transformation", e);
}
-
+
return doFileTransform(input, reader, binding, config).getAbsolutePath();
}
@@ -96,9 +96,9 @@
{
if (input == null)
throw new IllegalArgumentException("input cannot be null");
-
+
XSLTServiceBindingValueSourceConfig config = getConfig(binding);
-
+
Reader reader = null;
try
{
@@ -108,10 +108,10 @@
{
throw new RuntimeException("Caught IOException during transformation", e);
}
-
+
try
{
- return doFileTransform(input, reader, binding, config).toURL();
+ return doFileTransform(input, reader, binding, config).toURI().toURL();
}
catch (MalformedURLException e)
{
@@ -123,17 +123,17 @@
{
if (input == null)
throw new IllegalArgumentException("input cannot be null");
-
+
PropertyEditor editor = PropertyEditorManager.findEditor(Element.class);
if (editor == null)
throw new IllegalStateException("Cannot find PropertyEditor for type Element");
-
- editor.setValue(input);
+
+ editor.setValue(input);
Reader reader = new StringReader(editor.getAsText());
Writer writer = new StringWriter();
-
+
doXslTransform(binding, getConfig(binding), reader, writer);
-
+
editor.setAsText(writer.toString());
return (Element) editor.getValue();
}
@@ -144,24 +144,24 @@
{
throw new IllegalArgumentException(getClass().getSimpleName() + ".getServiceBindingValue() requires a single-value 'params'");
}
-
+
if (params[0] instanceof String)
- {
+ {
return getResourceServiceBindingValue(binding, (String) params[0]);
}
else if (params[0] instanceof Element)
- {
+ {
return getElementServiceBindingValue(binding, (Element) params[0]);
}
else if (params[0] instanceof URL)
- {
+ {
return getURLServiceBindingValue(binding, (URL) params[0]);
}
-
+
throw new IllegalArgumentException(getClass().getSimpleName() + ".getServiceBindingValue() requires a single-value 'params' of type String, Element or URL");
}
-
- private File doFileTransform(Object input, Reader reader, ServiceBinding binding,
+
+ private File doFileTransform(Object input, Reader reader, ServiceBinding binding,
XSLTServiceBindingValueSourceConfig config)
{
Writer writer = null;
@@ -176,7 +176,7 @@
}
});
writer = new OutputStreamWriter(new FileOutputStream(targetFile));
-
+
doXslTransform(binding, config, reader, writer);
return targetFile;
@@ -215,7 +215,7 @@
}
}
}
-
+
private XSLTServiceBindingValueSourceConfig getConfig(ServiceBinding binding)
{
Object config = binding.getServiceBindingValueSourceConfig();
@@ -227,29 +227,29 @@
{
throw new IllegalStateException("No config object bound to " + binding);
}
- throw new IllegalStateException("Incompatible config object of type " +
+ throw new IllegalStateException("Incompatible config object of type " +
config.getClass() + " bound to " + binding +
" -- must use " + XSLTServiceBindingValueSourceConfig.class.getName());
}
- private void doXslTransform(ServiceBinding binding, XSLTServiceBindingValueSourceConfig config,
+ private void doXslTransform(ServiceBinding binding, XSLTServiceBindingValueSourceConfig config,
Reader reader, Writer writer)
{
Source xmlSource = new StreamSource(reader);
- Result xmlResult = new StreamResult(writer);
+ Result xmlResult = new StreamResult(writer);
Source xslSource = new StreamSource(new StringReader(config.getXslt()));
-
+
TransformerFactory factory = TransformerFactory.newInstance();
try
{
Transformer transformer = factory.newTransformer(xslSource);
-
+
transformer.setParameter("port", Integer.valueOf(binding.getPort()));
String host = binding.getHostName();
if (host != null)
{
transformer.setParameter("host", host);
-
+
String hostforurl = null ;
if (host.contains(":")) // check if IPv6 address
hostforurl = "[" + host + "]";
@@ -257,7 +257,7 @@
hostforurl = host;
transformer.setParameter("hostforurl", hostforurl);
}
-
+
// Check for any arbitrary attributes
Map<String, String> attributes = config.getAdditionalAttributes();
for(Map.Entry<String, String> entry : attributes.entrySet())
@@ -266,7 +266,7 @@
String attrValue = entry.getValue();
transformer.setParameter(entry.getKey(), attrValue);
}
-
+
transformer.transform(xmlSource, xmlResult);
}
catch (TransformerException e)
More information about the jboss-cvs-commits
mailing list