01: /*
02: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: [See end of file]
04: $Id: UnsupportedPolymorphismException.java,v 1.9 2008/01/02 12:09:12 andy_seaborne Exp $
05: */
06:
07: package com.hp.hpl.jena.enhanced;
08:
09: import com.hp.hpl.jena.shared.JenaException;
10:
11: /**
12: Exception to throw if an enhanced graph does not support polymorphism
13: to a specific class. The exception records the "bad" class and node for
14: later reporting.
15: */
16: public class UnsupportedPolymorphismException extends JenaException {
17: private final Class type;
18: private final EnhNode node;
19:
20: /**
21: Initialise this exception with the node that couldn't be polymorphed and
22: the class it couldn't be polymorphed to.
23: */
24: public UnsupportedPolymorphismException(EnhNode node, Class type) {
25: super (constructMessage(node, type));
26: this .node = node;
27: this .type = type;
28: }
29:
30: private static String constructMessage(EnhNode node, Class type) {
31: String mainMessage = "cannot convert " + node + " to " + type;
32: return node.getGraph() == null ? mainMessage : mainMessage
33: + " -- it has no model";
34: }
35:
36: /**
37: Answer the (enhanced) Graph of the node that couldn't be polymorphed;
38: may be null if that node had no attached model.
39: */
40: public EnhGraph getBadGraph() {
41: return node.getGraph();
42: }
43:
44: /**
45: Answer the class that the node couldn't be polymorphed to
46: */
47: public Class getBadClass() {
48: return type;
49: }
50:
51: /**
52: Answer the node that couldn't be polymorphed.
53: */
54: public Object getBadNode() {
55: return node;
56: }
57: }
58:
59: /*
60: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
61: All rights reserved.
62:
63: Redistribution and use in source and binary forms, with or without
64: modification, are permitted provided that the following conditions
65: are met:
66:
67: 1. Redistributions of source code must retain the above copyright
68: notice, this list of conditions and the following disclaimer.
69:
70: 2. Redistributions in binary form must reproduce the above copyright
71: notice, this list of conditions and the following disclaimer in the
72: documentation and/or other materials provided with the distribution.
73:
74: 3. The name of the author may not be used to endorse or promote products
75: derived from this software without specific prior written permission.
76:
77: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
78: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
79: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
80: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
81: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
82: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
83: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
84: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
85: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
86: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
87: */
|