View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3    Copyright (c) 2005, University of Innsbruck, Austria
4    This library is free software; you can redistribute it and/or modify it under
5    the terms of the GNU Lesser General Public License as published by the Free
6    Software Foundation; either version 2.1 of the License, or (at your option)
7    any later version.
8    This library is distributed in the hope that it will be useful, but WITHOUT
9    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11   details.
12   You should have received a copy of the GNU Lesser General Public License along
13   with this library; if not, write to the Free Software Foundation, Inc.,
14   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15   */
16  
17  package org.deri.wsmo4j.validator;
18  
19  
20  import org.wsmo.common.*;
21  import org.wsmo.validator.ValidationMessage;
22  
23  
24  /**
25   * Gives Structure to a validation message.
26   *
27   * <pre>
28   *  Created on Jul 28, 2005
29   *  Committed by $Author: nathaliest $
30   *  $Source$,
31   * </pre>
32   *
33   * @author Holger Lausen
34   * @author nathalie.steinmetz@deri.org
35   * @see org.wsmo.validator.ValidationError
36   * @see org.wsmo.validator.ValidationWarning
37   * @version $Revision: 1481 $ $Date: 2006-01-16 15:32:46 +0200 (Mon, 16 Jan 2006) $
38   */
39  public abstract class ValidationMessageImpl implements ValidationMessage{
40  
41      private Entity entity = null;
42  
43      private String reason = null;
44      
45      private String quickFix = null;
46  
47      public ValidationMessageImpl(Entity entity, String reason) {
48          this(entity, reason, null);
49      }
50  
51      public ValidationMessageImpl(Entity entity, String reason, String quickFix) {
52          this.entity = entity;
53          this.reason = reason;
54          this.quickFix = quickFix;
55      }
56      
57      /**
58       * 
59       * @see org.wsmo.validator.ValidationError#getEntity()
60       * @return the entity in which the violation occured
61       */
62      public Entity getEntity() {
63          return entity;
64      }
65  
66      /**
67       * @see org.wsmo.validator.ValidationError#getReason()
68       * @return String representation of error in Entity
69       */
70      public String getReason() {
71          return reason;
72      }
73  
74      /**
75       * @see org.wsmo.validator.ValidationError#getQuickFix()
76       * @see org.wsmo.validator.ValidationWarning#getQuickFix()
77       * @return String representation of a quick fix possibility
78       */
79      public String getQuickFix() {
80          if (quickFix == null) {
81              quickFix = "";
82          }
83          return quickFix;
84      }
85      
86      /**
87       * Formats the String representation of the ValidationError.
88       * 
89       * @see java.lang.Object#toString()
90       */
91      public String toString() {
92          String id = "<Identifier>";
93  
94          //short id if possible:
95          if (entity != null) {
96              id = entity.getIdentifier().toString();
97              if (entity.getIdentifier()instanceof IRI) {
98                  id = ((IRI)entity.getIdentifier()).getLocalName();
99              }
100         }
101         return id + ":\n" + reason;
102     }
103 }
104 /*
105  * $Log$
106  * Revision 1.1  2006/01/16 13:32:46  nathaliest
107  * added ValidationMessage to wsmo-api
108  *
109  * Revision 1.3  2006/01/09 16:12:58  nathaliest
110  * added quickFix method to validationError
111  *
112  * Revision 1.2  2005/11/22 16:19:32  nathaliest
113  * organized imports
114  *
115  * Revision 1.1  2005/11/21 13:08:47  holgerlausen
116  * added ValidationWarning
117  *
118  */