cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject [3/11] Switch inject annotation to javax and let ComponentLocator to recognize both the new and original inject annotation
Date Fri, 02 Nov 2012 01:08:43 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3afbb0fc/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
index 2a25886..9752e30 100644
--- a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
@@ -21,6 +21,7 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 import javax.naming.NamingException;
 
@@ -74,7 +75,6 @@ import com.cloud.org.Grouping.AllocationState;
 import com.cloud.service.ServiceOfferingVO;
 import com.cloud.storage.DiskOfferingVO;
 import com.cloud.user.Account;
-import com.cloud.utils.component.Inject;
 import com.cloud.utils.component.Manager;
 import com.cloud.vm.VirtualMachine.Type;
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3afbb0fc/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
index dfd4f7e..b3c45ec 100644
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -23,6 +23,7 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
@@ -78,7 +79,6 @@ import com.cloud.user.Account;
 import com.cloud.user.User;
 import com.cloud.utils.Pair;
 import com.cloud.utils.component.Adapters;
-import com.cloud.utils.component.Inject;
 import com.cloud.utils.component.Manager;
 import com.cloud.vm.Nic;
 import com.cloud.vm.NicProfile;
@@ -95,7 +95,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager{
     NetworkServiceMapDao  _ntwkSrvcDao;
     @Inject
     NetworkOfferingServiceMapDao  _ntwkOfferingSrvcDao;
-    @Inject(adapter = NetworkElement.class)
+    @com.cloud.utils.component.Inject(adapter = NetworkElement.class)
     Adapters<NetworkElement> _networkElements;
     
     private static HashMap<String, String> s_providerToNetworkElementMap = new HashMap<String,
String>();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3afbb0fc/utils/src/com/cloud/utils/component/ComponentLocator.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/component/ComponentLocator.java b/utils/src/com/cloud/utils/component/ComponentLocator.java
index dea34d9..23c37ec 100755
--- a/utils/src/com/cloud/utils/component/ComponentLocator.java
+++ b/utils/src/com/cloud/utils/component/ComponentLocator.java
@@ -37,6 +37,7 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.MBeanRegistrationException;
 import javax.management.MalformedObjectNameException;
@@ -484,8 +485,28 @@ public class ComponentLocator implements ComponentLocatorMBean {
             for (Field field : fields) {
                 Inject inject = field.getAnnotation(Inject.class);
                 if (inject == null) {
+                	com.cloud.utils.component.Inject oldInject = field.getAnnotation(com.cloud.utils.component.Inject.class);
+                	if(inject != null) {
+                        Class<?> fc = field.getType();
+                        Object instance = null;
+                        if (Manager.class.isAssignableFrom(fc)) {
+                            s_logger.trace("Manager: " + fc.getName());
+                            instance = locator.getManager(fc);
+                        } else if (GenericDao.class.isAssignableFrom(fc)) {
+                            s_logger.trace("Dao:" + fc.getName());
+                            instance = locator.getDao((Class<? extends GenericDao<?,
? extends Serializable>>)fc);
+                        } else if (Adapters.class.isAssignableFrom(fc)) {
+                            s_logger.trace("Adapter" + fc.getName());
+                            instance = locator.getAdapters(oldInject.adapter());
+                        } else {
+                            s_logger.trace("Other:" + fc.getName());
+                            instance = locator.getManager(fc);
+                        }
+                	}
+                	
                     continue;
                 }
+                
                 Class<?> fc = field.getType();
                 Object instance = null;
                 if (Manager.class.isAssignableFrom(fc)) {
@@ -494,9 +515,6 @@ public class ComponentLocator implements ComponentLocatorMBean {
                 } else if (GenericDao.class.isAssignableFrom(fc)) {
                     s_logger.trace("Dao:" + fc.getName());
                     instance = locator.getDao((Class<? extends GenericDao<?, ? extends
Serializable>>)fc);
-                } else if (Adapters.class.isAssignableFrom(fc)) {
-                    s_logger.trace("Adapter" + fc.getName());
-                    instance = locator.getAdapters(inject.adapter());
                 } else {
                     s_logger.trace("Other:" + fc.getName());
                     instance = locator.getManager(fc);


Mime
View raw message