aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java2
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java9
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tenant/TenantAdapterRest.java2
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/BuildingBlockTestDataSetup.java149
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/SerializableChecker.java163
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/SerializationTest.java4
-rw-r--r--bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/SerializableChecker.java163
7 files changed, 5 insertions, 487 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java
index 3eb3fe188d..c648cc2137 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java
@@ -525,7 +525,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin {
private StackInfo getStackStatus(String cloudSiteId, String cloudOwner, String tenantId, String instanceId,
boolean pollForCompletion, int timeoutMinutes, boolean backout) throws MsoException {
- StackInfo stackInfo = new StackInfo();
+ StackInfo stackInfo;
// If client has requested a final response, poll for stack completion
if (pollForCompletion) {
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java
index 52b97da61a..5641186eca 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java
@@ -310,7 +310,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
// First, look up to see if the Network already exists (by name).
// For HEAT orchestration of networks, the stack name will always match the network name
StackInfo heatStack = null;
- long queryNetworkStarttime = System.currentTimeMillis();
try {
heatStack = heat.queryStack(cloudSiteId, CLOUD_OWNER, tenantId, networkName);
} catch (MsoException me) {
@@ -564,7 +563,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
// Verify that the Network exists
// For Neutron-based orchestration, the networkId is the Neutron Network UUID.
NetworkInfo netInfo = null;
- long queryNetworkStarttime = System.currentTimeMillis();
try {
netInfo = neutron.queryNetwork(networkId, tenantId, cloudSiteId);
} catch (MsoException me) {
@@ -608,7 +606,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
// First, look up to see that the Network already exists.
// For Heat-based orchestration, the networkId is the network Stack ID.
StackInfo heatStack = null;
- long queryStackStarttime = System.currentTimeMillis();
try {
heatStack = heat.queryStack(cloudSiteId, CLOUD_OWNER, tenantId, networkName);
} catch (MsoException me) {
@@ -728,7 +725,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
// Update the network stack
// Ignore MsoStackNotFound exception because we already checked.
- long updateStackStarttime = System.currentTimeMillis();
try {
heatStack = heatWithUpdate.updateStack(cloudSiteId, CLOUD_OWNER, tenantId, networkId, template,
stackParams, true, heatTemplate.getTimeoutMinutes());
@@ -892,9 +888,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
logger.debug("*** QUERY Network with Network: {} in {}/{}", networkNameOrId, cloudSiteId, tenantId);
- // Will capture execution time for metrics
- long startTime = System.currentTimeMillis();
-
if (commonUtils.isNullOrEmpty(cloudSiteId) || commonUtils.isNullOrEmpty(tenantId)
|| commonUtils.isNullOrEmpty(networkNameOrId)) {
@@ -919,7 +912,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
String neutronId = null;
// Try Heat first, since networks may be named the same as the Heat stack
StackInfo heatStack = null;
- long queryStackStarttime = System.currentTimeMillis();
try {
heatStack = heat.queryStack(cloudSiteId, CLOUD_OWNER, tenantId, networkNameOrId);
} catch (MsoException me) {
@@ -961,7 +953,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
// Query directly against the Neutron Network for the details
// no RouteTargets available for ContrailV2 in neutron net-show
// networkId is heatStackId
- long queryNetworkStarttime = System.currentTimeMillis();
try {
NetworkInfo netInfo = neutron.queryNetwork(neutronId, tenantId, cloudSiteId);
if (netInfo != null) {
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tenant/TenantAdapterRest.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tenant/TenantAdapterRest.java
index 6a38cc60e6..c782adec64 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tenant/TenantAdapterRest.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tenant/TenantAdapterRest.java
@@ -100,7 +100,7 @@ public class TenantAdapterRest {
logger.debug("createTenant enter: {}", req.toJsonString());
String newTenantId = null;
- TenantRollback tenantRollback = new TenantRollback();
+ TenantRollback tenantRollback;
try {
Holder<String> htenant = new Holder<>();
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/BuildingBlockTestDataSetup.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/BuildingBlockTestDataSetup.java
index e9d8a5dee9..c421a67e7b 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/BuildingBlockTestDataSetup.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/BuildingBlockTestDataSetup.java
@@ -26,7 +26,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import org.assertj.core.util.Arrays;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.impl.pvm.runtime.ExecutionImpl;
import org.junit.Before;
@@ -65,9 +64,6 @@ import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule;
import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
import org.onap.so.client.exception.BBObjectNotFoundException;
-import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource;
-import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoAllottedResource;
-import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceProxy;
public class BuildingBlockTestDataSetup {
private int collectionCounter;
@@ -80,7 +76,6 @@ public class BuildingBlockTestDataSetup {
private int pnfCounter;
private int projectCounter;
private int serviceInstanceCounter;
- private int serviceProxyCounter;
private int serviceSubscriptionCounter;
private int vfModuleCounter;
private int volumeGroupCounter;
@@ -112,7 +107,6 @@ public class BuildingBlockTestDataSetup {
pnfCounter = 0;
projectCounter = 0;
serviceInstanceCounter = 0;
- serviceProxyCounter = 0;
serviceSubscriptionCounter = 0;
vfModuleCounter = 0;
volumeGroupCounter = 0;
@@ -145,14 +139,6 @@ public class BuildingBlockTestDataSetup {
return userInput;
}
- public Map<String, String> setUserInput() {
- Map<String, String> userInput = buildUserInput();
-
- gBBInput.setUserInput(userInput);
-
- return userInput;
- }
-
public RequestContext buildRequestContext() {
RequestContext requestContext = new RequestContext();
requestContext.setMsoRequestId(UUID.randomUUID().toString());
@@ -216,14 +202,6 @@ public class BuildingBlockTestDataSetup {
return orchestrationContext;
}
- public OrchestrationContext setOrchestrationContext() {
- OrchestrationContext orchestrationContext = buildOrchestrationContext();
-
- gBBInput.setOrchContext(orchestrationContext);
-
- return orchestrationContext;
- }
-
public Collection buildCollection() {
collectionCounter++;
@@ -350,7 +328,7 @@ public class BuildingBlockTestDataSetup {
Collection collection = new Collection();
collection.setId("testId");
- ServiceInstance serviceInstance = null;
+ ServiceInstance serviceInstance;
try {
serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
@@ -363,30 +341,6 @@ public class BuildingBlockTestDataSetup {
return collection;
}
- public InstanceGroup setInstanceGroup() {
- InstanceGroup instanceGroup = new InstanceGroup();
- instanceGroup.setId("testId");
- instanceGroup.setInstanceGroupFunction("testInstanceGroupFunction");
-
- Collection collection = null;
-
- try {
- ServiceInstance serviceInstance =
- extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
- collection = serviceInstance.getCollection();
-
- if (collection == null) {
- collection = setCollection();
- }
- } catch (BBObjectNotFoundException e) {
- collection = setCollection();
- }
-
- collection.setInstanceGroup(instanceGroup);
-
- return instanceGroup;
- }
-
public VpnBinding buildVpnBinding() {
vpnBindingCounter++;
@@ -398,21 +352,6 @@ public class BuildingBlockTestDataSetup {
return vpnBinding;
}
- public VpnBinding setVpnBinding() {
- VpnBinding vpnBinding = buildVpnBinding();
-
- Customer customer = gBBInput.getCustomer();
-
- if (customer == null) {
- customer = buildCustomer();
- }
-
- customer.getVpnBindings().add(vpnBinding);
- lookupKeyMap.put(ResourceKey.VPN_ID, vpnBinding.getVpnId());
-
- return vpnBinding;
- }
-
public InstanceGroup buildInstanceGroup() {
instanceGroupCounter++;
@@ -529,7 +468,7 @@ public class BuildingBlockTestDataSetup {
public VfModule setVfModule() {
VfModule vfModule = buildVfModule();
- GenericVnf genericVnf = null;
+ GenericVnf genericVnf;
try {
genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
@@ -582,8 +521,6 @@ public class BuildingBlockTestDataSetup {
}
public ServiceProxy buildServiceProxy() {
- serviceProxyCounter++;
-
ServiceProxy serviceProxy = new ServiceProxy();
serviceProxy.setServiceInstance(buildServiceInstance());
serviceProxy.getServiceInstance().getVnfs().add(buildGenericVnf());
@@ -617,86 +554,4 @@ public class BuildingBlockTestDataSetup {
return vpnBondingLink;
}
-
- public VpnBondingLink setVpnBondingLink() {
- VpnBondingLink vpnBondingLink = buildVpnBondingLink();
-
- ServiceInstance serviceInstance = null;
-
- try {
- serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
- } catch (BBObjectNotFoundException e) {
- serviceInstance = setServiceInstance();
- }
-
- serviceInstance.getVpnBondingLinks().add(vpnBondingLink);
- lookupKeyMap.put(ResourceKey.VPN_BONDING_LINK_ID, vpnBondingLink.getVpnBondingLinkId());
-
-
- return vpnBondingLink;
- }
-
- public Customer setAvpnCustomer() {
- Customer customer = buildCustomer();
-
- gBBInput.setCustomer(customer);
-
- return customer;
- }
-
- public ServiceProxy setServiceProxy(String uniqueIdentifier, String type) {
- ServiceProxy serviceProxy = new ServiceProxy();
- serviceProxy.setId("testProxyId" + uniqueIdentifier);
- serviceProxy.setType(type);
-
- ModelInfoServiceProxy modelInfo = new ModelInfoServiceProxy();
- modelInfo.setModelInvariantUuid("testProxyModelInvariantUuid" + uniqueIdentifier);
- modelInfo.setModelName("testProxyModelName" + uniqueIdentifier);
- modelInfo.setModelUuid("testProxyModelUuid" + uniqueIdentifier);
- modelInfo.setModelVersion("testProxyModelVersion" + uniqueIdentifier);
- modelInfo.setModelInstanceName("testProxyInstanceName" + uniqueIdentifier);
-
- serviceProxy.setModelInfoServiceProxy(modelInfo);
-
- return serviceProxy;
- }
-
- public AllottedResource setAllottedResource(String uniqueIdentifier) {
- AllottedResource ar = new AllottedResource();
- ar.setId("testAllottedResourceId" + uniqueIdentifier);
-
- ModelInfoAllottedResource modelInfo = new ModelInfoAllottedResource();
- modelInfo.setModelInvariantUuid("testAllottedModelInvariantUuid" + uniqueIdentifier);
- modelInfo.setModelName("testAllottedModelName" + uniqueIdentifier);
- modelInfo.setModelUuid("testAllottedModelUuid" + uniqueIdentifier);
- modelInfo.setModelVersion("testAllottedModelVersion" + uniqueIdentifier);
- modelInfo.setModelInstanceName("testAllottedInstanceName" + uniqueIdentifier);
-
- ar.setModelInfoAllottedResource(modelInfo);
-
- return ar;
- }
-
- public Configuration setConfiguration() {
- Configuration config = new Configuration();
- config.setConfigurationId("testConfigurationId");
- ModelInfoConfiguration modelInfoConfig = new ModelInfoConfiguration();
- modelInfoConfig.setModelCustomizationId("modelCustomizationId");
- modelInfoConfig.setModelVersionId("modelVersionId");
- modelInfoConfig.setModelInvariantId("modelInvariantId");
- modelInfoConfig.setPolicyName("policyName");
- config.setModelInfoConfiguration(modelInfoConfig);
-
- List<Configuration> configurations = new ArrayList<>();
- configurations.add(config);
- ServiceInstance serviceInstance = new ServiceInstance();
- try {
- serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
- } catch (BBObjectNotFoundException e) {
- serviceInstance = setServiceInstance();
- }
- lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, "testConfigurationId");
- serviceInstance.setConfigurations(configurations);
- return config;
- }
}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/SerializableChecker.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/SerializableChecker.java
deleted file mode 100644
index 47ddea1b4f..0000000000
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/SerializableChecker.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.so;
-
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public final class SerializableChecker {
- public static class SerializationFailure {
- private final String mContainingClass;
- private final String mMemberName;
-
- public SerializationFailure(String inNonSerializableClass, String inMemberName) {
- mContainingClass = inNonSerializableClass;
- mMemberName = inMemberName;
- }
-
- public String getContainingClass() {
- return mContainingClass;
- }
-
- public String getMemberName() {
- return mMemberName;
- }
-
- public String getBadMemberString() {
- if (mMemberName == null)
- return mContainingClass;
- return mContainingClass + "." + mMemberName;
- }
-
- @Override
- public String toString() {
- return "SerializationFailure [mNonSerializableClass=" + mContainingClass + ", mMemberName=" + mMemberName
- + "]";
- }
- }
-
- private static class SerializationCheckerData {
- private Set<Class<?>> mSerializableClasses;
-
- SerializationCheckerData() {
- mSerializableClasses = new HashSet<Class<?>>();
- }
-
- boolean isAlreadyChecked(Class<?> inClass) {
- return mSerializableClasses.contains(inClass);
- }
-
- void addSerializableClass(Class<?> inClass) {
- mSerializableClasses.add(inClass);
- }
- }
-
- private SerializableChecker() {}
-
- public static SerializationFailure isFullySerializable(Class<?> inClass) {
- if (!isSerializable(inClass))
- return new SerializationFailure(inClass.getName(), null);
-
- return isFullySerializable(inClass, new SerializationCheckerData());
- }
-
- private static SerializationFailure isFullySerializable(Class<?> inClass,
- SerializationCheckerData inSerializationCheckerData) {
- for (Field field : declaredFields(inClass)) {
- Class<?> fieldDeclaringClass = field.getType();
-
- if (field.getType() == Object.class)
- continue;
-
- if (Modifier.isStatic(field.getModifiers()))
- continue;
-
- if (field.isSynthetic())
- continue;
-
- if (fieldDeclaringClass.isInterface() || fieldDeclaringClass.isPrimitive())
- continue;
-
- if (Modifier.isAbstract(field.getType().getModifiers()))
- continue;
-
- if (inSerializationCheckerData.isAlreadyChecked(fieldDeclaringClass))
- continue;
-
- if (isSerializable(fieldDeclaringClass)) {
- inSerializationCheckerData.addSerializableClass(inClass);
-
- SerializationFailure failure = isFullySerializable(field.getType(), inSerializationCheckerData);
- if (failure != null)
- return failure;
- else
- continue;
- }
-
- if (Modifier.isTransient(field.getModifiers()))
- continue;
-
- return new SerializationFailure(field.getDeclaringClass().getName(), field.getName());
- }
- return null;
- }
-
- private static boolean isSerializable(Class<?> inClass) {
- Set<Class<?>> interfaces = getInterfaces(inClass);
- if (interfaces == null)
- return false;
- boolean isSerializable = interfaces.contains(Serializable.class);
- if (isSerializable)
- return true;
-
- for (Class<?> classInterface : interfaces) {
- if (isSerializable(classInterface))
- return true;
- }
-
- if (inClass.getSuperclass() != null && isSerializable(inClass.getSuperclass()))
- return true;
-
- return false;
- }
-
- private static Set<Class<?>> getInterfaces(Class<?> inFieldDeclaringClass) {
- return new HashSet<Class<?>>(Arrays.asList(inFieldDeclaringClass.getInterfaces()));
- }
-
- private static List<Field> declaredFields(Class<?> inClass) {
- List<Field> fields = new ArrayList<Field>(Arrays.asList(inClass.getDeclaredFields()));
-
- Class<?> parentClasses = inClass.getSuperclass();
-
- if (parentClasses == null)
- return fields;
- fields.addAll(declaredFields(parentClasses));
-
- return fields;
- }
-}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/SerializationTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/SerializationTest.java
index b970b95b97..e9e83a59ae 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/SerializationTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/SerializationTest.java
@@ -20,7 +20,6 @@
package org.onap.so.bpmn.servicedecomposition;
-import static org.junit.Assert.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.Externalizable;
import java.io.File;
@@ -33,8 +32,7 @@ import java.util.Map;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.impl.pvm.runtime.ExecutionImpl;
import org.junit.Test;
-import org.onap.so.SerializableChecker;
-import org.onap.so.SerializableChecker.SerializationFailure;
+import static org.junit.Assert.assertEquals;
import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.bpmn.common.DelegateExecutionImpl;
import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/SerializableChecker.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/SerializableChecker.java
deleted file mode 100644
index 47ddea1b4f..0000000000
--- a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/SerializableChecker.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.so;
-
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public final class SerializableChecker {
- public static class SerializationFailure {
- private final String mContainingClass;
- private final String mMemberName;
-
- public SerializationFailure(String inNonSerializableClass, String inMemberName) {
- mContainingClass = inNonSerializableClass;
- mMemberName = inMemberName;
- }
-
- public String getContainingClass() {
- return mContainingClass;
- }
-
- public String getMemberName() {
- return mMemberName;
- }
-
- public String getBadMemberString() {
- if (mMemberName == null)
- return mContainingClass;
- return mContainingClass + "." + mMemberName;
- }
-
- @Override
- public String toString() {
- return "SerializationFailure [mNonSerializableClass=" + mContainingClass + ", mMemberName=" + mMemberName
- + "]";
- }
- }
-
- private static class SerializationCheckerData {
- private Set<Class<?>> mSerializableClasses;
-
- SerializationCheckerData() {
- mSerializableClasses = new HashSet<Class<?>>();
- }
-
- boolean isAlreadyChecked(Class<?> inClass) {
- return mSerializableClasses.contains(inClass);
- }
-
- void addSerializableClass(Class<?> inClass) {
- mSerializableClasses.add(inClass);
- }
- }
-
- private SerializableChecker() {}
-
- public static SerializationFailure isFullySerializable(Class<?> inClass) {
- if (!isSerializable(inClass))
- return new SerializationFailure(inClass.getName(), null);
-
- return isFullySerializable(inClass, new SerializationCheckerData());
- }
-
- private static SerializationFailure isFullySerializable(Class<?> inClass,
- SerializationCheckerData inSerializationCheckerData) {
- for (Field field : declaredFields(inClass)) {
- Class<?> fieldDeclaringClass = field.getType();
-
- if (field.getType() == Object.class)
- continue;
-
- if (Modifier.isStatic(field.getModifiers()))
- continue;
-
- if (field.isSynthetic())
- continue;
-
- if (fieldDeclaringClass.isInterface() || fieldDeclaringClass.isPrimitive())
- continue;
-
- if (Modifier.isAbstract(field.getType().getModifiers()))
- continue;
-
- if (inSerializationCheckerData.isAlreadyChecked(fieldDeclaringClass))
- continue;
-
- if (isSerializable(fieldDeclaringClass)) {
- inSerializationCheckerData.addSerializableClass(inClass);
-
- SerializationFailure failure = isFullySerializable(field.getType(), inSerializationCheckerData);
- if (failure != null)
- return failure;
- else
- continue;
- }
-
- if (Modifier.isTransient(field.getModifiers()))
- continue;
-
- return new SerializationFailure(field.getDeclaringClass().getName(), field.getName());
- }
- return null;
- }
-
- private static boolean isSerializable(Class<?> inClass) {
- Set<Class<?>> interfaces = getInterfaces(inClass);
- if (interfaces == null)
- return false;
- boolean isSerializable = interfaces.contains(Serializable.class);
- if (isSerializable)
- return true;
-
- for (Class<?> classInterface : interfaces) {
- if (isSerializable(classInterface))
- return true;
- }
-
- if (inClass.getSuperclass() != null && isSerializable(inClass.getSuperclass()))
- return true;
-
- return false;
- }
-
- private static Set<Class<?>> getInterfaces(Class<?> inFieldDeclaringClass) {
- return new HashSet<Class<?>>(Arrays.asList(inFieldDeclaringClass.getInterfaces()));
- }
-
- private static List<Field> declaredFields(Class<?> inClass) {
- List<Field> fields = new ArrayList<Field>(Arrays.asList(inClass.getDeclaredFields()));
-
- Class<?> parentClasses = inClass.getSuperclass();
-
- if (parentClasses == null)
- return fields;
- fields.addAll(declaredFields(parentClasses));
-
- return fields;
- }
-}