Cross Reference: BaseExpressionWriter.java
xref
: /
owl-s
/
src
/
org
/
mindswap
/
owls
/
io
/
BaseExpressionWriter.java
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
2
ronwalf
/*
2
ronwalf
* Created on May 7, 2005
2
ronwalf
*/
2
ronwalf
package
org
.
mindswap
.
owls
.
io
;
2
ronwalf
2
ronwalf
import
java
.
io
.
OutputStream
;
2
ronwalf
import
java
.
io
.
PrintWriter
;
2
ronwalf
import
java
.
io
.
Writer
;
2
ronwalf
import
java
.
net
.
URI
;
2
ronwalf
2
ronwalf
import
org
.
mindswap
.
owl
.
OWLClass
;
2
ronwalf
import
org
.
mindswap
.
owl
.
OWLIndividual
;
2
ronwalf
import
org
.
mindswap
.
owl
.
OWLProperty
;
2
ronwalf
import
org
.
mindswap
.
owl
.
OWLValue
;
2
ronwalf
import
org
.
mindswap
.
owls
.
generic
.
expression
.
Expression
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
Atom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
AtomList
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
BuiltinAtom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
ClassAtom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
DataPropertyAtom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
DifferentIndividualsAtom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
IndividualPropertyAtom
;
2
ronwalf
import
org
.
mindswap
.
swrl
.
SameIndividualAtom
;
2
ronwalf
import
org
.
mindswap
.
utils
.
QNameProvider
;
2
ronwalf
2
ronwalf
/**
2
ronwalf
*
@author
Evren Sirin
2
ronwalf
*
2
ronwalf
*/
2
ronwalf
public
abstract
class
BaseExpressionWriter
implements
ExpressionWriter
{
2
ronwalf
protected
QNameProvider
qnames
;
2
ronwalf
protected
PrintWriter
out
;
2
ronwalf
protected
String
indent
;
2
ronwalf
protected
boolean
firstLineIndent
;
2
ronwalf
2
ronwalf
public
BaseExpressionWriter
() {
2
ronwalf
firstLineIndent
=
false
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
setWriter
(
Writer
out
) {
2
ronwalf
if
(
out
instanceof
PrintWriter
)
2
ronwalf
this
.
out
= (
PrintWriter
)
out
;
2
ronwalf
else
2
ronwalf
this
.
out
=
new
PrintWriter
(
out
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
Writer
getWriter
() {
2
ronwalf
return
out
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
setWriter
(
OutputStream
out
) {
2
ronwalf
setWriter
(
new
PrintWriter
(
out
) );
2
ronwalf
}
2
ronwalf
2
ronwalf
public
String
getIndent
() {
2
ronwalf
return
indent
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
setIndent
(
String
indent
) {
2
ronwalf
this
.
indent
=
indent
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
boolean
getFirstLineIndent
() {
2
ronwalf
return
firstLineIndent
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
setFirstLineIndent
(
boolean
indent
) {
2
ronwalf
firstLineIndent
=
indent
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
setQNames
(
QNameProvider
qnames
) {
2
ronwalf
this
.
qnames
=
qnames
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
QNameProvider
getQNames
() {
2
ronwalf
return
qnames
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
write
(
Expression
expr
,
Writer
out
) {
2
ronwalf
if
(
out
instanceof
PrintWriter
)
2
ronwalf
this
.
out
= (
PrintWriter
)
out
;
2
ronwalf
else
2
ronwalf
this
.
out
=
new
PrintWriter
(
out
);
2
ronwalf
2
ronwalf
boolean
noQNameProvider
= (
qnames
==
null
);
2
ronwalf
if
(
noQNameProvider
)
2
ronwalf
qnames
=
expr
.
getKB
().
getQNames
();
2
ronwalf
2
ronwalf
write
(
expr
);
2
ronwalf
2
ronwalf
if
(
noQNameProvider
)
2
ronwalf
qnames
=
null
;
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
write
(
Expression
expr
,
OutputStream
out
) {
2
ronwalf
write
(
expr
,
new
PrintWriter
(
out
) );
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
write
(
Expression
expr
) {
2
ronwalf
write
(
expr
.
getBody
() );
2
ronwalf
}
2
ronwalf
2
ronwalf
public
abstract
void
write
(
AtomList
atoms
);
2
ronwalf
2
ronwalf
public
void
write
(
Atom
atom
) {
2
ronwalf
if
(
atom
instanceof
ClassAtom
)
2
ronwalf
write
( (
ClassAtom
)
atom
);
2
ronwalf
else
if
(
atom
instanceof
IndividualPropertyAtom
)
2
ronwalf
write
( (
IndividualPropertyAtom
)
atom
);
2
ronwalf
else
if
(
atom
instanceof
DataPropertyAtom
)
2
ronwalf
write
( (
DataPropertyAtom
)
atom
);
2
ronwalf
else
if
(
atom
instanceof
SameIndividualAtom
)
2
ronwalf
write
( (
SameIndividualAtom
)
atom
);
2
ronwalf
else
if
(
atom
instanceof
DifferentIndividualsAtom
)
2
ronwalf
write
( (
DifferentIndividualsAtom
)
atom
);
2
ronwalf
else
if
(
atom
instanceof
BuiltinAtom
)
2
ronwalf
write
( (
BuiltinAtom
)
atom
);
2
ronwalf
}
2
ronwalf
2
ronwalf
public
abstract
void
write
(
ClassAtom
atom
);
2
ronwalf
2
ronwalf
public
abstract
void
write
(
IndividualPropertyAtom
atom
);
2
ronwalf
2
ronwalf
public
abstract
void
write
(
DataPropertyAtom
atom
);
2
ronwalf
2
ronwalf
public
abstract
void
write
(
SameIndividualAtom
atom
);
2
ronwalf
2
ronwalf
public
abstract
void
write
(
DifferentIndividualsAtom
atom
);
2
ronwalf
2
ronwalf
public
abstract
void
write
(
BuiltinAtom
atom
);
2
ronwalf
2
ronwalf
public
void
print
(
OWLValue
value
) {
2
ronwalf
try
{
2
ronwalf
if
(
value
instanceof
OWLIndividual
) {
2
ronwalf
OWLIndividual
ind
= (
OWLIndividual
)
value
;
2
ronwalf
if
(
ind
.
isAnon
() )
2
ronwalf
out
.
print
(
"<< Anonymous Individual >>"
);
2
ronwalf
else
2
ronwalf
print
(
ind
.
getURI
() );
2
ronwalf
}
2
ronwalf
else
2
ronwalf
out
.
print
(
value
);
2
ronwalf
}
2
ronwalf
catch
(
RuntimeException
e ) {
2
ronwalf
out
.
print
(
"<< Invalid URI >>"
);
2
ronwalf
}
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
print
(
OWLClass
cls
) {
2
ronwalf
if
(
cls
.
isAnon
() )
2
ronwalf
out
.
print
(
"<< Anonymous Class >>"
);
2
ronwalf
else
2
ronwalf
print
(
cls
.
getURI
() );
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
print
(
OWLProperty
prop
) {
2
ronwalf
print
(
prop
.
getURI
() );
2
ronwalf
}
2
ronwalf
2
ronwalf
public
void
print
(
URI
uri
) {
2
ronwalf
out
.
print
(
qnames
.
shortForm
(
uri
) );
2
ronwalf
}
2
ronwalf
2
ronwalf
}