Author: richard.opalka(a)jboss.com
Date: 2011-10-10 09:14:02 -0400 (Mon, 10 Oct 2011)
New Revision: 15065
Added:
common/trunk/src/main/java/org/jboss/ws/common/deployment/ReferenceFactory.java
Modified:
common/trunk/src/main/java/org/jboss/ws/common/invocation/InvocationHandlerJAXWS.java
Log:
adding Reference abstraction
Added: common/trunk/src/main/java/org/jboss/ws/common/deployment/ReferenceFactory.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/deployment/ReferenceFactory.java
(rev 0)
+++
common/trunk/src/main/java/org/jboss/ws/common/deployment/ReferenceFactory.java 2011-10-10
13:14:02 UTC (rev 15065)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., 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.ws.common.deployment;
+
+import org.jboss.wsf.spi.deployment.Reference;
+
+/**
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
+ */
+public final class ReferenceFactory {
+
+ private ReferenceFactory() {
+ // forbidden instantiation
+ }
+
+ public static Reference newInitializedReference(final Reference reference) {
+ if (reference == null) throw new IllegalArgumentException();
+ return newInitializedReference(reference.getValue());
+ }
+
+ public static Reference newInitializedReference(final Object reference) {
+ if (reference == null) throw new IllegalArgumentException();
+ return newReference(reference, true);
+ }
+
+ public static Reference newUninitializedReference(final Reference reference) {
+ if (reference == null) throw new IllegalArgumentException();
+ return newUninitializedReference(reference.getValue());
+ }
+
+ public static Reference newUninitializedReference(final Object reference) {
+ if (reference == null) throw new IllegalArgumentException();
+ return newReference(reference, false);
+ }
+
+ private static Reference newReference(final Object reference, final boolean
initialized) {
+ return new ReferenceImpl(reference, initialized);
+ }
+
+ private static final class ReferenceImpl implements Reference {
+
+ private final Object reference;
+ private final boolean initialized;
+
+ private ReferenceImpl(final Object reference, final boolean initialized) {
+ this.reference = reference;
+ this.initialized = initialized;
+ }
+
+ @Override
+ public Object getValue() {
+ return reference;
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ }
+
+}
Modified:
common/trunk/src/main/java/org/jboss/ws/common/invocation/InvocationHandlerJAXWS.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/common/invocation/InvocationHandlerJAXWS.java 2011-10-10
13:10:46 UTC (rev 15064)
+++
common/trunk/src/main/java/org/jboss/ws/common/invocation/InvocationHandlerJAXWS.java 2011-10-10
13:14:02 UTC (rev 15065)
@@ -27,6 +27,7 @@
import org.jboss.ws.common.injection.PreDestroyHolder;
import org.jboss.ws.common.injection.ThreadLocalAwareWebServiceContext;
import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.deployment.Reference;
import org.jboss.wsf.spi.invocation.Invocation;
import org.jboss.wsf.spi.invocation.InvocationContext;
import org.jboss.wsf.spi.metadata.injection.InjectionsMetaData;
@@ -61,16 +62,22 @@
final InjectionsMetaData injectionsMD =
endpoint.getAttachment(InjectionsMetaData.class);
final Object _targetBean = this.getTargetBean(invocation);
// TODO: refactor injection to AS IL
- final Object targetBean =
endpoint.getInstanceProvider().getInstance(_targetBean.getClass().getName());
+ final Reference reference =
endpoint.getInstanceProvider().getInstance(_targetBean.getClass().getName());
+ final Object targetBean = reference.getValue();
- this.log.debug("Injecting resources on JAXWS JSE endpoint: " +
targetBean);
- if (injectionsMD != null)
+ if (!reference.isInitialized() && injectionsMD != null)
+ {
+ this.log.debug("Injecting resources on JAXWS JSE endpoint: " +
targetBean);
InjectionHelper.injectResources(targetBean, injectionsMD,
endpoint.getJNDIContext());
+ }
- InjectionHelper.injectWebServiceContext(targetBean,
ThreadLocalAwareWebServiceContext.getInstance());
+ if (!reference.isInitialized())
+ {
+ InjectionHelper.injectWebServiceContext(targetBean,
ThreadLocalAwareWebServiceContext.getInstance());
- this.log.debug("Calling postConstruct method on JAXWS JSE endpoint: " +
targetBean);
- InjectionHelper.callPostConstructMethod(targetBean);
+ this.log.debug("Calling postConstruct method on JAXWS JSE endpoint: "
+ targetBean);
+ InjectionHelper.callPostConstructMethod(targetBean);
+ }
endpoint.addAttachment(PreDestroyHolder.class, new PreDestroyHolder(targetBean));
}