01: /**
02: *
03: */package org.ontoware.rdfreactor.generator.java;
04:
05: import org.ontoware.rdf2go.model.node.URI;
06:
07: /**
08: * <b>JMapped</b> is used as the superclass of Objects in a JModel which can be mapped to
09: * an URI.
10: *
11: * Every JMapped instance has a name, a comment and an URI to which it can be mapped in the
12: * representation of the JModel.
13: *
14: * @author $Author: xamde $
15: * @version $Id: JMapped.java,v 1.4 2006/09/11 10:07:57 xamde Exp $
16: */
17:
18: public class JMapped {
19:
20: /** name of the JMapped instance */
21: private String name;
22:
23: /** comment of this JMapped instance */
24: private String comment;
25:
26: /** the URI to which this JMapped instance is mapped */
27: private URI mappedTo;
28:
29: /**
30: * the constructor:
31: * @param name of the JMapped instance
32: * @param mappedTo is the URI to which to map this JMapped instance
33: */
34: public JMapped(String name, URI mappedTo) {
35: assert mappedTo != null;
36: this .name = name;
37: this .mappedTo = mappedTo;
38: }
39:
40: public String getComment() {
41: return comment;
42: }
43:
44: public void setComment(String comment) {
45: this .comment = comment;
46: }
47:
48: public URI getMappedTo() {
49: return mappedTo;
50: }
51:
52: public String getName() {
53: return name;
54: }
55:
56: public String getPlainName() {
57: String plain = getName();
58: plain = plain.replaceAll("\\W", "_");
59: return plain;
60: }
61:
62: /**
63: * @return the last part of the name (starting after the last dot in the name)
64: */
65: public String getN3Name() {
66: if (getName().contains(".")) {
67: return getName().substring(getName().lastIndexOf(".") + 1);
68: } else
69: return getName();
70: }
71:
72: public String toDebug() {
73: return this .getName();
74: }
75:
76: /**
77: * Two JMapped are equal, if they are mapped to the same URI OR have the
78: * same name
79: */
80: public boolean equals(Object other) {
81: return other instanceof JMapped && (
82: // same URI
83: ((JMapped) other).getMappedTo().equals(getMappedTo()) || // same
84: // name
85: ((JMapped) other).getName().equals(this.getName()));
86: }
87:
88: }
|