Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* 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.
*/
package com.labs64.netlicensing.domain;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.labs64.netlicensing.domain.entity.Country;
import com.labs64.netlicensing.domain.entity.License;
import com.labs64.netlicensing.domain.entity.LicenseTemplate;
import com.labs64.netlicensing.domain.entity.Licensee;
import com.labs64.netlicensing.domain.entity.PaymentMethod;
import com.labs64.netlicensing.domain.entity.Product;
import com.labs64.netlicensing.domain.entity.ProductModule;
import com.labs64.netlicensing.domain.entity.Token;
import com.labs64.netlicensing.domain.entity.Transaction;
import com.labs64.netlicensing.domain.vo.LicenseTypeProperties;
import com.labs64.netlicensing.domain.vo.LicensingModelProperties;
import com.labs64.netlicensing.domain.vo.Page;
import com.labs64.netlicensing.domain.vo.PageImpl;
import com.labs64.netlicensing.domain.vo.ValidationResult;
import com.labs64.netlicensing.exception.ConversionException;
import com.labs64.netlicensing.exception.NetLicensingException;
import com.labs64.netlicensing.exception.WrongResponseFormatException;
import com.labs64.netlicensing.schema.context.Item;
import com.labs64.netlicensing.schema.context.Netlicensing;
import com.labs64.netlicensing.schema.converter.Converter;
import com.labs64.netlicensing.schema.converter.ItemToCountryConverter;
import com.labs64.netlicensing.schema.converter.ItemToLicenseConverter;
import com.labs64.netlicensing.schema.converter.ItemToLicenseTemplateConverter;
import com.labs64.netlicensing.schema.converter.ItemToLicenseTypePropertiesConverter;
import com.labs64.netlicensing.schema.converter.ItemToLicenseeConverter;
import com.labs64.netlicensing.schema.converter.ItemToLicensingModelPropertiesConverter;
import com.labs64.netlicensing.schema.converter.ItemToPaymentMethodConverter;
import com.labs64.netlicensing.schema.converter.ItemToProductConverter;
import com.labs64.netlicensing.schema.converter.ItemToProductModuleConverter;
import com.labs64.netlicensing.schema.converter.ItemToTokenConverter;
import com.labs64.netlicensing.schema.converter.ItemToTransactionConverter;
import com.labs64.netlicensing.schema.converter.ItemsToValidationResultConverter;
import com.labs64.netlicensing.util.Visitable;
import com.labs64.netlicensing.util.Visitor;
/**
* Factory that contains static methods for creating entities
*/
public class EntityFactory {
private static final Map, Class>> entityToConverterMap = new HashMap<>();
static {
entityToConverterMap.put(License.class, ItemToLicenseConverter.class);
entityToConverterMap.put(Licensee.class, ItemToLicenseeConverter.class);
entityToConverterMap.put(LicenseTemplate.class, ItemToLicenseTemplateConverter.class);
entityToConverterMap.put(PaymentMethod.class, ItemToPaymentMethodConverter.class);
entityToConverterMap.put(Product.class, ItemToProductConverter.class);
entityToConverterMap.put(ProductModule.class, ItemToProductModuleConverter.class);
entityToConverterMap.put(Token.class, ItemToTokenConverter.class);
entityToConverterMap.put(Transaction.class, ItemToTransactionConverter.class);
entityToConverterMap.put(Country.class, ItemToCountryConverter.class);
entityToConverterMap.put(LicensingModelProperties.class, ItemToLicensingModelPropertiesConverter.class);
entityToConverterMap.put(LicenseTypeProperties.class, ItemToLicenseTypePropertiesConverter.class);
}
private Map, Converter> convertersCache;
private Map, Converter> getConvertersCache() {
if (convertersCache == null) {
convertersCache = new HashMap<>();
}
return convertersCache;
}
/**
* Creates entity of specific class from service response
*
* @param netlicensing
* service XML response
* @param entityClass
* entity class
* @return entity class instance created from service response
* @throws com.labs64.netlicensing.exception.NetLicensingException
*/
@SuppressWarnings("unchecked")
public T create(final Netlicensing netlicensing, final Class entityClass)
throws NetLicensingException {
if (entityClass == ValidationResult.class) {
return (T) new ItemsToValidationResultConverter().convert(netlicensing);
} else {
final Item item = findSuitableItemOfType(netlicensing, entityClass);
return converterFor(entityClass).convert(item);
}
}
public class LinkedEntitiesPopulator extends Visitor {
private final List