Coverage Report - org.openpermis.editor.policy.presenter.PolicyProblemReporter
 
Classes in this File Line Coverage Branch Coverage Complexity
PolicyProblemReporter
0%
0/23
0%
0/8
1.5
PolicyProblemReporter$PartProblem
0%
0/8
N/A
1.5
 
 1  
 /*
 2  
  * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport
 3  
  *                     (http://www.vbs.admin.ch)
 4  
  * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch)
 5  
  * All rights reserved.
 6  
  *
 7  
  * Licensed under the Open Permis License which accompanies this distribution,
 8  
  * and is available at http://www.openpermis.org/BSDlicenceKent.txt
 9  
  */
 10  
 package org.openpermis.editor.policy.presenter;
 11  
 
 12  
 
 13  
 import java.util.ArrayList;
 14  
 
 15  
 import org.jdesktop.application.ResourceMap;
 16  
 import org.jdesktop.observablecollections.ObservableCollections;
 17  
 import org.jdesktop.observablecollections.ObservableList;
 18  
 
 19  
 import org.openpermis.policy.Part;
 20  
 import org.openpermis.policy.PartProblemReporter;
 21  
 import org.openpermis.policy.bean.PartBean;
 22  
 
 23  
 /**
 24  
  * ProblemReporter Handling for a policy presenter.
 25  
  * @since 0.1.0
 26  
  */
 27  
 public class PolicyProblemReporter implements PartProblemReporter
 28  
 {
 29  
         private class PartProblem {
 30  
 
 31  
                 private Part part;
 32  
                 private ProblemMessage message;
 33  
                 private Object[] parameters;
 34  
 
 35  0
                 public PartProblem (Part part, ProblemMessage message, Object...parameters) {
 36  0
                         this.part = part;
 37  0
                         this.message = message;
 38  0
                         this.parameters = parameters;
 39  0
                 }
 40  
 
 41  
                 /**
 42  
                  * @return the part.
 43  
                  * @since 0.1.0
 44  
                  */
 45  
                 public Part getPart () {
 46  0
                         return this.part;
 47  
                 }
 48  
 
 49  
                 /**
 50  
                  * @return the message.
 51  
                  * @since 0.1.0
 52  
                  */
 53  
                 public ProblemMessage getMessage () {
 54  0
                         return this.message;
 55  
                 }
 56  
 
 57  
 
 58  
                 /**
 59  
                  * @return the parameters.
 60  
                  * @since 0.1.0
 61  
                  */
 62  
                 public Object[] getParameters () {
 63  0
                         return this.parameters;
 64  
                 }
 65  
 
 66  
         }
 67  
 
 68  
         //---- State
 69  
 
 70  
         ObservableList<PartProblem> reports;
 71  
 
 72  
         //---- Constructors
 73  
 
 74  
         /**
 75  
          * @since 0.1.0
 76  
          */
 77  
         public PolicyProblemReporter () {
 78  0
                 super();
 79  0
                 this.reports = ObservableCollections.observableList(new ArrayList<PartProblem>());
 80  0
         }
 81  
 
 82  
         //---- Methods
 83  
 
 84  
         /**
 85  
          * @since 0.1.0
 86  
          */
 87  
         public void clear () {
 88  0
                 this.reports.clear();
 89  0
         }
 90  
 
 91  
         /**
 92  
          * Returns a textual description of the reported problems.
 93  
          * @since 0.1.0
 94  
          */
 95  
         public String renderString (ResourceMap resourceMap) {
 96  
                 String classname;
 97  
                 String message;
 98  
                 String messageMapped;
 99  
 
 100  0
                 StringBuffer sb = new StringBuffer();
 101  0
                 for (PartProblem problem : this.reports) {
 102  0
                         if (sb.length() > 0) {
 103  0
                                 sb.append("\n");
 104  
                         }
 105  0
                         classname = problem.getPart().getClass().getName();
 106  0
                         classname = classname.substring(classname.lastIndexOf(".") + 1);
 107  0
                         sb.append(classname);
 108  0
                         if (problem.getPart() instanceof PartBean) {
 109  0
                                 sb.append("[");
 110  0
                                 sb.append(((PartBean) problem.getPart()).getSerialNumber().toString());
 111  0
                                 sb.append("]");
 112  
                         }
 113  0
                         sb.append(": ");
 114  0
                         message = problem.getMessage().name();
 115  0
                         messageMapped = resourceMap.getString(message);
 116  0
                         sb.append((messageMapped == null) ? message : messageMapped );
 117  
                 }
 118  0
                 return sb.toString();
 119  
         }
 120  
 
 121  
         //---- PartProblemReporter
 122  
 
 123  
         /**
 124  
          * Reports an integrity violation of a part.
 125  
          * @param part the part affected.
 126  
          * @param message the message describing the type of violation.
 127  
          * @param parameters additional details about the type of violation.
 128  
          * @since 0.1.0
 129  
          */
 130  
         public void reportProblem (Part part, ProblemMessage message, Object... parameters) {
 131  0
                 this.reports.add(new PartProblem(part, message, parameters));
 132  0
         }
 133  
 
 134  
 }