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  package org.deri.wsmo4j.validator;
17  
18  import org.omwg.ontology.Attribute;
19  import org.wsmo.common.*;
20  import org.wsmo.validator.AttributeError;
21  
22  public class AttributeErrorImpl extends ValidationErrorImpl implements AttributeError {
23  
24      private Attribute attribute = null;
25  
26      
27      public AttributeErrorImpl(Entity entity, Attribute attribute, String reason, String variant) {
28          super(entity, reason, variant);
29          this.attribute = attribute;
30      }
31      
32      /**
33       * 
34       * @see org.wsmo.validator.AttributeError#getAttribute()
35       * @return String representation of the attribute in which the violation occured
36       */
37      public Attribute getAttribute() {
38          return attribute;
39      }
40      
41      /**
42       * Formats the String representation of the ValidationError.
43       * 
44       * @see java.lang.Object#toString()
45       */
46      public String toString() {
47          String id = "<Identifier>";
48          
49          //short id if possible:
50          if (getEntity() != null) {
51              id = getEntity().getIdentifier().toString();
52              if (getEntity().getIdentifier()instanceof IRI) {
53                  id = ((IRI)getEntity().getIdentifier()).getLocalName();
54              }
55          }
56          //short for variant if possible
57          String shortVariant = getViolatesVariant();
58          if (getViolatesVariant().lastIndexOf('/') != -1) {
59              shortVariant = getViolatesVariant().substring(getViolatesVariant().lastIndexOf('/') + 1);
60          }
61          return id + ":\n" + getReason() + "\n(violated variant: " +
62                  shortVariant + ")";
63      }
64  
65  }