Author: richard.opalka(a)jboss.com
Date: 2010-10-19 08:46:34 -0400 (Tue, 19 Oct 2010)
New Revision: 13154
Added:
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/ServiceRefSerializer.java
Modified:
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceObjectFactoryJAXWS.java
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceRefBinder.java
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceRefBinderJAXRPC.java
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceReferenceableJAXWS.java
Log:
final refactoring
Modified:
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceObjectFactoryJAXWS.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceObjectFactoryJAXWS.java 2010-10-19
09:27:10 UTC (rev 13153)
+++
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceObjectFactoryJAXWS.java 2010-10-19
12:46:34 UTC (rev 13154)
@@ -21,9 +21,6 @@
*/
package org.jboss.wsf.common.serviceref;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -35,8 +32,6 @@
import javax.naming.Context;
import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
import javax.xml.namespace.QName;
@@ -54,7 +49,6 @@
* This ServiceObjectFactory reconstructs a javax.xml.ws.Service
* for a given WSDL when the webservice client does a JNDI lookup.
*
- * @author Thomas.Diesler(a)jboss.org
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public abstract class AbstractServiceObjectFactoryJAXWS implements ObjectFactory
@@ -80,14 +74,15 @@
* @see javax.naming.spi.NamingManager#getURLContext
*/
@SuppressWarnings("rawtypes")
- public Object getObjectInstance(final Object obj, final Name name, final Context
nameCtx, final Hashtable environment)
- throws Exception
+ public final Object getObjectInstance(final Object obj, final Name name, final Context
nameCtx,
+ final Hashtable environment) throws Exception
{
try
{
// references
final Reference ref = (Reference) obj;
- final UnifiedServiceRefMetaData serviceRef = unmarshallServiceRef(ref);
+ final byte[] binaryData = (byte[])
ref.get(ServiceRefSerializer.SERVICE_REF_META_DATA).getContent();
+ final UnifiedServiceRefMetaData serviceRef =
ServiceRefSerializer.unmarshall(binaryData);
// class names
final String serviceImplClass = this.getServiceClassName(ref, serviceRef);
final String targetClassName = this.getTargetClassName(ref, serviceRef,
serviceImplClass);
@@ -127,10 +122,28 @@
return null;
}
+ /**
+ * Lifecycle template method called before javax.xml.ws.Service object instantiation.
+ *
+ * @param serviceRefUMDM service reference meta data
+ */
protected abstract void init(final UnifiedServiceRefMetaData serviceRefUMDM);
+ /**
+ * Lifecycle template method called after javax.xml.ws.Service object was created
+ * and before port is instantiated. It allows stack to configure service before
+ * creating ports.
+ *
+ * @param serviceRefUMDM service reference meta data
+ * @param service service instance
+ */
protected abstract void configure(final UnifiedServiceRefMetaData serviceRefUMDM,
final Service service);
+ /**
+ * Lifecycle template method called after javax.xml.ws.Service object and after port
instantiation.
+ *
+ * @param serviceRefUMDM
+ */
protected abstract void destroy(final UnifiedServiceRefMetaData serviceRefUMDM);
private Class<?> getClass(final String className) throws ClassNotFoundException
@@ -147,7 +160,7 @@
{
String serviceClassName = serviceRefMD.getServiceImplClass();
if (serviceClassName == null)
- serviceClassName = (String)
ref.get(AbstractServiceReferenceableJAXWS.SERVICE_IMPL_CLASS).getContent();
+ serviceClassName = (String)
ref.get(ServiceRefSerializer.SERVICE_IMPL_CLASS).getContent();
return serviceClassName;
}
@@ -157,7 +170,7 @@
{
String targetClassName = serviceRefMD.getServiceRefType();
if (targetClassName == null)
- targetClassName = (String)
ref.get(AbstractServiceReferenceableJAXWS.TARGET_CLASS_NAME).getContent();
+ targetClassName = (String)
ref.get(ServiceRefSerializer.TARGET_CLASS_NAME).getContent();
if (Service.class.getName().equals(targetClassName))
targetClassName = serviceImplClass;
@@ -406,24 +419,4 @@
return features.size() == 0 ? null : features.toArray(new WebServiceFeature[]
{});
}
-
- private UnifiedServiceRefMetaData unmarshallServiceRef(final Reference ref) throws
ClassNotFoundException,
- NamingException
- {
- final UnifiedServiceRefMetaData sref;
- final RefAddr refAddr =
ref.get(AbstractServiceReferenceableJAXWS.SERVICE_REF_META_DATA);
- final ByteArrayInputStream bais = new ByteArrayInputStream((byte[])
refAddr.getContent());
- try
- {
- ObjectInputStream ois = new ObjectInputStream(bais);
- sref = (UnifiedServiceRefMetaData) ois.readObject();
- ois.close();
- }
- catch (IOException e)
- {
- throw new NamingException("Cannot unmarshall service ref meta data, cause:
" + e.toString());
- }
-
- return sref;
- }
}
Modified:
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceRefBinder.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceRefBinder.java 2010-10-19
09:27:10 UTC (rev 13153)
+++
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceRefBinder.java 2010-10-19
12:46:34 UTC (rev 13154)
@@ -58,7 +58,7 @@
{
final String jndiFullName = encCtx.getNameInNamespace() + "/" + encName;
- log.info("binding service reference to [jndi=" + jndiFullName +
"]");
+ log.info("Binding service reference to [jndi=" + jndiFullName +
"]");
Util.bind(encCtx, encName, jndiReferenceable);
}
}
Modified:
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceRefBinderJAXRPC.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceRefBinderJAXRPC.java 2010-10-19
09:27:10 UTC (rev 13153)
+++
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceRefBinderJAXRPC.java 2010-10-19
12:46:34 UTC (rev 13154)
@@ -39,7 +39,7 @@
/**
* Template method for creating stack specific JAXRPC referenceables.
- *
+ *
* @param serviceRef service reference UMDM
* @return stack specific JAXRPC JNDI referenceable
*/
Modified:
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceReferenceableJAXWS.java
===================================================================
---
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceReferenceableJAXWS.java 2010-10-19
09:27:10 UTC (rev 13153)
+++
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/AbstractServiceReferenceableJAXWS.java 2010-10-19
12:46:34 UTC (rev 13154)
@@ -21,10 +21,6 @@
*/
package org.jboss.wsf.common.serviceref;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-
import javax.naming.BinaryRefAddr;
import javax.naming.NamingException;
import javax.naming.Reference;
@@ -36,23 +32,16 @@
/**
* A JNDI reference to a javax.xml.ws.Service metadata.
- *
+ *
* It holds all the information necessary to reconstruct the javax.xml.ws.Service
* instances when client does a JNDI lookup.
*
* @param <T> JNDI object factory type
- *
- * @author Thomas.Diesler(a)jboss.org
+ *
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public abstract class AbstractServiceReferenceableJAXWS<T extends ObjectFactory>
implements Referenceable
{
- public static final String SERVICE_REF_META_DATA = "SERVICE_REF_META_DATA";
-
- public static final String SERVICE_IMPL_CLASS = "SERVICE_CLASS_NAME";
-
- public static final String TARGET_CLASS_NAME = "TARGET_CLASS_NAME";
-
private final String serviceImplClass;
private final String targetClassName;
@@ -67,39 +56,27 @@
this.serviceRef = serviceRef;
}
- public Reference getReference() throws NamingException
+ public final Reference getReference() throws NamingException
{
final Reference myRef = new Reference(getClass().getName(),
this.getObjectFactory().getName(), null);
- myRef.add(new StringRefAddr(SERVICE_IMPL_CLASS, this.serviceImplClass));
- myRef.add(new StringRefAddr(TARGET_CLASS_NAME, this.targetClassName));
- myRef.add(new BinaryRefAddr(SERVICE_REF_META_DATA,
this.marshall(this.serviceRef)));
+ myRef.add(new StringRefAddr(ServiceRefSerializer.SERVICE_IMPL_CLASS,
this.serviceImplClass));
+ myRef.add(new StringRefAddr(ServiceRefSerializer.TARGET_CLASS_NAME,
this.targetClassName));
+ myRef.add(new BinaryRefAddr(ServiceRefSerializer.SERVICE_REF_META_DATA,
ServiceRefSerializer
+ .marshall(this.serviceRef)));
return myRef;
}
+ /**
+ * Template method for providing stack specific JNDI object factory.
+ *
+ * @return JNDI object factory
+ */
protected abstract Class<T> getObjectFactory();
- private byte[] marshall(final Object obj) throws NamingException
+ public final String toString()
{
- final ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
-
- try
- {
- final ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(obj);
- oos.close();
- }
- catch (final IOException e)
- {
- throw new NamingException("Cannot marshall object, cause: " +
e.toString());
- }
-
- return baos.toByteArray();
- }
-
- public String toString()
- {
final StringBuilder sb = new StringBuilder();
sb.append("\n").append(getClass().getName());
Added:
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/ServiceRefSerializer.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/serviceref/ServiceRefSerializer.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/wsf/common/serviceref/ServiceRefSerializer.java 2010-10-19
12:46:34 UTC (rev 13154)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.serviceref;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.naming.NamingException;
+
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
+
+/**
+ * Provides utility methods and constants for web service reference de/serialization.
+ *
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
+ */
+final class ServiceRefSerializer
+{
+ public static final String SERVICE_REF_META_DATA = "SERVICE_REF_META_DATA";
+
+ public static final String SERVICE_IMPL_CLASS = "SERVICE_CLASS_NAME";
+
+ public static final String TARGET_CLASS_NAME = "TARGET_CLASS_NAME";
+
+ private ServiceRefSerializer()
+ {
+ // forbidden constructor
+ }
+
+ public static byte[] marshall(final UnifiedServiceRefMetaData obj) throws
NamingException
+ {
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
+
+ try
+ {
+ final ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(obj);
+ oos.close();
+ }
+ catch (final IOException e)
+ {
+ throw new NamingException("Cannot marshall service ref meta data, cause:
" + e.toString());
+ }
+
+ return baos.toByteArray();
+ }
+
+ public static UnifiedServiceRefMetaData unmarshall(final byte[] data) throws
NamingException
+ {
+ final UnifiedServiceRefMetaData sref;
+
+ try
+ {
+ final ByteArrayInputStream bais = new ByteArrayInputStream(data);
+ final ObjectInputStream ois = new ObjectInputStream(bais);
+ sref = (UnifiedServiceRefMetaData) ois.readObject();
+ ois.close();
+ }
+ catch (final IOException e)
+ {
+ throw new NamingException("Cannot unmarshall service ref meta data, cause:
" + e.toString());
+ }
+ catch (final ClassNotFoundException e)
+ {
+ throw new NamingException("Cannot unmarshall service ref meta data, cause:
" + e.toString());
+ }
+
+ return sref;
+ }
+}