| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>AbstractSimpleValidator.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">jUDDI Core - OpenJPA</a> > <a href="index.source.html" class="el_package">org.apache.juddi.validation.vsv</a> > <span class="el_source">AbstractSimpleValidator.java</span></div><h1>AbstractSimpleValidator.java</h1><pre class="source lang-java linenums">/* |
| * Copyright 2014 The Apache Software Foundation. |
| * |
| * 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 org.apache.juddi.validation.vsv; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| import org.apache.juddi.v3.error.ErrorMessage; |
| import org.apache.juddi.v3.error.InvalidValueException; |
| import org.uddi.api_v3.BindingTemplate; |
| import org.uddi.api_v3.BusinessEntity; |
| import org.uddi.api_v3.BusinessService; |
| import org.uddi.api_v3.KeyedReference; |
| import org.uddi.api_v3.KeyedReferenceGroup; |
| import org.uddi.api_v3.PublisherAssertion; |
| import org.uddi.api_v3.TModel; |
| import org.uddi.api_v3.TModelInstanceInfo; |
| import org.uddi.v3_service.DispositionReportFaultMessage; |
| |
| /** |
| * A simple base class for the validator interface that lets you define a simple |
| * set of allowed values. All other values will be rejected. Valid values apply |
| * to all UDDI elements |
| * |
| * @author Alex O'Ree |
| * @since 3.2.1 |
| * |
| */ |
| <span class="fc" id="L41">public abstract class AbstractSimpleValidator implements ValueSetValidator {</span> |
| |
| public abstract String getMyKey(); |
| |
| @Override |
| public void validateValuesBindingTemplate(List<BindingTemplate> items, String xpath) throws DispositionReportFaultMessage { |
| <span class="pc bpc" id="L47" title="1 of 2 branches missed."> if (items == null) {</span> |
| <span class="nc" id="L48"> return;</span> |
| } |
| <span class="pc bpc" id="L50" title="1 of 2 branches missed."> for (int i = 0; i < items.size(); i++) {</span> |
| <span class="nc bnc" id="L51" title="All 2 branches missed."> if (items.get(i).getCategoryBag() != null) {</span> |
| <span class="nc" id="L52"> validatedValuesKeyRef(items.get(i).getCategoryBag().getKeyedReference(), xpath + "bindingTemplate(" + i + ").categoryBag.");</span> |
| <span class="nc" id="L53"> validatedValuesKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), xpath + "bindingTemplate(" + i + ").categoryBag.");</span> |
| } |
| <span class="nc bnc" id="L55" title="All 2 branches missed."> if (items.get(i).getTModelInstanceDetails() != null) {</span> |
| |
| <span class="nc" id="L57"> validateTmodelInstanceDetails(items.get(i).getTModelInstanceDetails().getTModelInstanceInfo(), xpath + "bindingTemplate(" + i + ").tModelInstanceDetails.");</span> |
| } |
| } |
| <span class="fc" id="L60"> }</span> |
| |
| @Override |
| public void validateValuesBusinessEntity(List<BusinessEntity> items) throws DispositionReportFaultMessage { |
| <span class="pc bpc" id="L64" title="1 of 2 branches missed."> if (items == null) {</span> |
| <span class="nc" id="L65"> return;</span> |
| } |
| <span class="pc bfc" id="L67" title="All 2 branches covered."> for (int i = 0; i < items.size(); i++) {</span> |
| <span class="pc bpc" id="L68" title="1 of 2 branches missed."> if (items.get(i).getCategoryBag() != null) {</span> |
| <span class="nc" id="L69"> validatedValuesKeyRef(items.get(i).getCategoryBag().getKeyedReference(), "businessEntity(" + i + ").categoryBag.");</span> |
| <span class="nc" id="L70"> validatedValuesKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), "businessEntity(" + i + ").categoryBagGroup.");</span> |
| } |
| <span class="nc bnc" id="L72" title="All 2 branches missed."> if (items.get(i).getIdentifierBag() != null) {</span> |
| <span class="nc" id="L73"> validatedValuesKeyRef(items.get(i).getIdentifierBag().getKeyedReference(), "businessEntity(" + i + ").identifierBag.");</span> |
| } |
| <span class="nc bnc" id="L75" title="All 2 branches missed."> if (items.get(i).getBusinessServices() != null) {</span> |
| <span class="nc" id="L76"> validateValuesBusinessService(items.get(i).getBusinessServices().getBusinessService(), "businessEntity(" + i + ").");</span> |
| } |
| } |
| <span class="fc" id="L79"> }</span> |
| |
| @Override |
| public void validateValuesBusinessService(List<BusinessService> items, String xpath) throws DispositionReportFaultMessage { |
| <span class="pc bpc" id="L83" title="1 of 2 branches missed."> if (items == null) {</span> |
| <span class="nc" id="L84"> return;</span> |
| } |
| <span class="pc bpc" id="L86" title="1 of 2 branches missed."> for (int i = 0; i < items.size(); i++) {</span> |
| <span class="nc bnc" id="L87" title="All 2 branches missed."> if (items.get(i).getCategoryBag() != null) {</span> |
| <span class="nc" id="L88"> validatedValuesKeyRef(items.get(i).getCategoryBag().getKeyedReference(), xpath + "businessService(" + i + ").categoryBag.");</span> |
| <span class="nc" id="L89"> validatedValuesKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), xpath + "businessService(" + i + ").categoryBag.");</span> |
| } |
| <span class="nc bnc" id="L91" title="All 2 branches missed."> if (items.get(i).getBindingTemplates() != null) {</span> |
| <span class="nc" id="L92"> validateValuesBindingTemplate(items.get(i).getBindingTemplates().getBindingTemplate(), xpath + xpath + "businessService(" + i + ").");</span> |
| } |
| } |
| <span class="fc" id="L95"> }</span> |
| |
| @Override |
| public void validateValuesPublisherAssertion(List<PublisherAssertion> items) throws DispositionReportFaultMessage { |
| <span class="pc bpc" id="L99" title="1 of 2 branches missed."> if (items == null) {</span> |
| <span class="nc" id="L100"> return;</span> |
| } |
| <span class="pc bpc" id="L102" title="1 of 2 branches missed."> for (int i = 0; i < items.size(); i++) {</span> |
| <span class="nc bnc" id="L103" title="All 2 branches missed."> if (items.get(i).getKeyedReference() != null) {</span> |
| <span class="nc" id="L104"> List<KeyedReference> temp = new ArrayList<KeyedReference>();</span> |
| <span class="nc" id="L105"> temp.add(items.get(i).getKeyedReference());</span> |
| <span class="nc" id="L106"> validatedValuesKeyRef(temp, "publisherAssertion(" + i + ").");</span> |
| } |
| } |
| <span class="fc" id="L109"> }</span> |
| |
| private void validatedValuesKeyRef(List<KeyedReference> items, String xpath) throws DispositionReportFaultMessage { |
| <span class="pc bpc" id="L112" title="1 of 2 branches missed."> if (items == null) {</span> |
| <span class="nc" id="L113"> return;</span> |
| } |
| //StringBuilder badvalues=new StringBuilder(); |
| <span class="fc" id="L116"> StringBuilder err = new StringBuilder();</span> |
| <span class="fc bfc" id="L117" title="All 2 branches covered."> for (int i = 0; i < items.size(); i++) {</span> |
| <span class="pc bpc" id="L118" title="1 of 2 branches missed."> if (items.get(i).getTModelKey().equalsIgnoreCase(getMyKey())) {</span> |
| <span class="fc" id="L119"> List<String> validValues = getValidValues();</span> |
| <span class="pc bpc" id="L120" title="1 of 2 branches missed."> if (validValues != null) {</span> |
| //ok we have some work to do |
| //boolean valid = false; |
| <span class="fc" id="L123"> boolean localfound = false;</span> |
| <span class="fc bfc" id="L124" title="All 2 branches covered."> for (int k = 0; k < validValues.size(); k++) {</span> |
| <span class="fc bfc" id="L125" title="All 2 branches covered."> if (validValues.get(k).equals(items.get(i).getKeyValue())) {</span> |
| // valid = true; |
| <span class="fc" id="L127"> localfound = true;</span> |
| } |
| } |
| <span class="fc bfc" id="L130" title="All 2 branches covered."> if (!localfound) {</span> |
| //badvalues.append(items.get(i).getKeyValue()).append(" "); |
| <span class="fc" id="L132"> err.append(xpath).append("keyedReference(").append(i).append(")=").append(items.get(i).getKeyValue()).append(" ");</span> |
| } |
| } |
| } |
| } |
| <span class="fc bfc" id="L137" title="All 2 branches covered."> if (err.length() > 0) {</span> |
| <span class="fc" id="L138"> throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", err.toString() + getPrintableValidValues()));</span> |
| } |
| <span class="fc" id="L140"> }</span> |
| |
| private void validatedValuesKeyRefGrp(List<KeyedReferenceGroup> items, String xpath) throws DispositionReportFaultMessage { |
| <span class="pc bpc" id="L143" title="1 of 2 branches missed."> if (items == null) {</span> |
| <span class="nc" id="L144"> return;</span> |
| } |
| <span class="pc bpc" id="L146" title="1 of 2 branches missed."> for (int i = 0; i < items.size(); i++) {</span> |
| <span class="nc" id="L147"> validatedValuesKeyRef(items.get(i).getKeyedReference(), xpath + "keyReferenceGroup(" + i + ").");</span> |
| } |
| <span class="fc" id="L149"> }</span> |
| |
| @Override |
| public void validateTmodelInstanceDetails(List<TModelInstanceInfo> tModelInstanceInfo, String xpath) throws DispositionReportFaultMessage { |
| |
| <span class="nc" id="L154"> }</span> |
| |
| @Override |
| public abstract List<String> getValidValues(); |
| |
| @Override |
| public void validateValuesTModel(List<TModel> items) throws DispositionReportFaultMessage { |
| <span class="pc bpc" id="L161" title="1 of 2 branches missed."> if (items == null) {</span> |
| <span class="nc" id="L162"> return;</span> |
| } |
| <span class="fc bfc" id="L164" title="All 2 branches covered."> for (int i = 0; i < items.size(); i++) {</span> |
| <span class="pc bpc" id="L165" title="1 of 2 branches missed."> if (items.get(i).getCategoryBag() != null) {</span> |
| <span class="fc" id="L166"> validatedValuesKeyRef(items.get(i).getCategoryBag().getKeyedReference(), "tModel(" + i + ").categoryBag.");</span> |
| <span class="fc" id="L167"> validatedValuesKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), "tModel(" + i + ").categoryBag.");</span> |
| } |
| <span class="pc bpc" id="L169" title="1 of 2 branches missed."> if (items.get(i).getIdentifierBag() != null) {</span> |
| <span class="nc" id="L170"> validatedValuesKeyRef(items.get(i).getIdentifierBag().getKeyedReference(), "tModel(" + i + ").identifierBag.");</span> |
| } |
| } |
| <span class="fc" id="L173"> }</span> |
| |
| public static void validateKeyNotPresentKeyRef(List<KeyedReference> items, String key, String itemtype) throws DispositionReportFaultMessage { |
| <span class="pc bpc" id="L176" title="1 of 2 branches missed."> if (items == null) {</span> |
| <span class="nc" id="L177"> return;</span> |
| } |
| <span class="pc bpc" id="L179" title="1 of 2 branches missed."> for (int i = 0; i < items.size(); i++) {</span> |
| <span class="nc" id="L180"> validateKeyNotPresentKeyRef(items.get(i), key, itemtype);</span> |
| } |
| <span class="nc" id="L182"> }</span> |
| |
| public static void validateKeyNotPresentKeyRef(KeyedReference item, String key, String itemtype) throws DispositionReportFaultMessage { |
| <span class="pc bpc" id="L185" title="1 of 2 branches missed."> if (item == null) {</span> |
| <span class="nc" id="L186"> return;</span> |
| } |
| <span class="pc bpc" id="L188" title="1 of 2 branches missed."> if (key.equalsIgnoreCase(item.getTModelKey())) {</span> |
| <span class="fc" id="L189"> throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "key " + key + " not allowed on " + itemtype));</span> |
| } |
| <span class="nc" id="L191"> }</span> |
| |
| public static void validateKeyNotPresentKeyRefGrp(List<KeyedReferenceGroup> items, String key, String itemtype) throws DispositionReportFaultMessage { |
| <span class="nc bnc" id="L194" title="All 2 branches missed."> if (items == null) {</span> |
| <span class="nc" id="L195"> return;</span> |
| } |
| <span class="nc bnc" id="L197" title="All 2 branches missed."> for (int i = 0; i < items.size(); i++) {</span> |
| <span class="nc bnc" id="L198" title="All 2 branches missed."> if (key.equalsIgnoreCase(items.get(i).getTModelKey())) {</span> |
| <span class="nc" id="L199"> throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "key " + key + " not allowed on " + itemtype));</span> |
| } |
| <span class="nc" id="L201"> validateKeyNotPresentKeyRef(items.get(i).getKeyedReference(), key, itemtype);</span> |
| } |
| <span class="nc" id="L203"> }</span> |
| |
| private String getPrintableValidValues() { |
| <span class="fc" id="L206"> StringBuilder sb = new StringBuilder();</span> |
| <span class="fc" id="L207"> sb.append(" Valid Values:[");</span> |
| <span class="fc" id="L208"> List<String> validValues = getValidValues();</span> |
| <span class="fc bfc" id="L209" title="All 2 branches covered."> for (int i = 0; i < validValues.size(); i++) {</span> |
| <span class="fc" id="L210"> sb.append(validValues.get(i));</span> |
| <span class="fc bfc" id="L211" title="All 2 branches covered."> if (i + 1 < validValues.size()) {</span> |
| <span class="fc" id="L212"> sb.append(",");</span> |
| } |
| } |
| <span class="fc" id="L215"> sb.append("]");</span> |
| <span class="fc" id="L216"> return sb.toString();</span> |
| } |
| |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html> |