
net.customware.license.support.ValidatingLicenseManager Maven / Gradle / Ivy
The newest version!
package net.customware.license.support;
import java.util.Collection;
import de.schlichtherle.license.LicenseContent;
import de.schlichtherle.license.LicenseContentException;
import de.schlichtherle.license.LicenseNotary;
import de.schlichtherle.license.LicenseParam;
public class ValidatingLicenseManager extends BundledLicenseManager {
public ValidatingLicenseManager() {
super();
}
public ValidatingLicenseManager( ValidatingLicenseParam licenseParam ) {
super( licenseParam );
}
public ValidatingLicenseManager( ClassLoader classLoader ) {
super( classLoader );
}
public ValidatingLicenseManager( ValidatingLicenseParam licenseParam, ClassLoader classLoader ) {
super( licenseParam, classLoader );
}
@Override protected synchronized LicenseContent verify( LicenseNotary notary ) throws Exception {
Collection exemptions = getValidatingLicenseParam().getExemptions();
Object context = getValidatingLicenseParam().getContext();
for ( Exemption e : exemptions )
if ( e.isExempt( context ) )
return null;
return super.verify( notary );
}
@Override protected synchronized void validate( LicenseContent content ) throws LicenseContentException {
super.validate( content );
ValidatingLicenseParam licenseParam = getValidatingLicenseParam();
if ( licenseParam != null ) {
Object context = licenseParam.getContext();
Collection restrictions = licenseParam.getRestrictions();
for ( Restriction r : restrictions ) {
r.checkRestriction( context, content );
}
}
}
private ValidatingLicenseParam getValidatingLicenseParam() {
LicenseParam lp = getLicenseParam();
if ( lp instanceof ValidatingLicenseParam ) {
return ( ValidatingLicenseParam ) lp;
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy