001: /*****************************************************************************
002: * Source code information
003: * -----------------------
004: * Original author Ian Dickinson, HP Labs Bristol
005: * Author email Ian.Dickinson@hp.com
006: * Package Jena 2
007: * Web http://sourceforge.net/projects/jena/
008: * Created July 19th 2003
009: * Filename $RCSfile: DIGQueryRoleParentsTranslator.java,v $
010: * Revision $Revision: 1.8 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:07:09 $
014: * by $Author: andy_seaborne $
015: *
016: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017: * [See end of file]
018: * ****************************************************************************/package com.hp.hpl.jena.reasoner.dig;
019:
020: // Imports
021: ///////////////
022: import org.w3c.dom.Element;
023: import org.w3c.dom.Document;
024:
025: import com.hp.hpl.jena.reasoner.TriplePattern;
026:
027: /**
028: * <p>
029: * Translator that generates DIG parents/childre queries in response to a find queries:
030: * <pre>
031: * :X direct-subClassOf *
032: * * direct-subClassOf :X
033: * </pre>
034: * or similar.
035: * </p>
036: *
037: * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
038: * @version Release @release@ ($Id: DIGQueryRoleParentsTranslator.java,v 1.8 2008/01/02 12:07:09 andy_seaborne Exp $)
039: */
040: public class DIGQueryRoleParentsTranslator extends
041: DIGQueryRoleAncestorsTranslator {
042:
043: // Constants
044: //////////////////////////////////
045:
046: // Static variables
047: //////////////////////////////////
048:
049: // Instance variables
050: //////////////////////////////////
051:
052: // Constructors
053: //////////////////////////////////
054:
055: /**
056: * <p>Construct a translator for the DIG query 'rparents'.</p>
057: * @param predicate The predicate URI to trigger on
058: * @param parents If true, we are searching for parents of the role; if false, the children
059: */
060: public DIGQueryRoleParentsTranslator(String predicate,
061: boolean parents) {
062: super (predicate, parents);
063: }
064:
065: // External signature methods
066: //////////////////////////////////
067:
068: /**
069: * <p>Answer a query that will generate the direct class hierarchy (one level up or down) for a node</p>
070: */
071: public Document translatePattern(TriplePattern pattern,
072: DIGAdapter da) {
073: DIGConnection dc = da.getConnection();
074: Document query = dc.createDigVerb(DIGProfile.ASKS, da
075: .getProfile());
076:
077: if (m_ancestors) {
078: Element parents = da.createQueryElement(query,
079: DIGProfile.RPARENTS);
080: da.addNamedElement(parents, DIGProfile.RATOM, pattern
081: .getSubject().getURI());
082: } else {
083: Element descendants = da.createQueryElement(query,
084: DIGProfile.RCHILDREN);
085: da.addNamedElement(descendants, DIGProfile.RATOM, pattern
086: .getObject().getURI());
087: }
088:
089: return query;
090: }
091:
092: // Internal implementation methods
093: //////////////////////////////////
094:
095: //==============================================================================
096: // Inner class definitions
097: //==============================================================================
098:
099: }
100:
101: /*
102: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
103: * All rights reserved.
104: *
105: * Redistribution and use in source and binary forms, with or without
106: * modification, are permitted provided that the following conditions
107: * are met:
108: * 1. Redistributions of source code must retain the above copyright
109: * notice, this list of conditions and the following disclaimer.
110: * 2. Redistributions in binary form must reproduce the above copyright
111: * notice, this list of conditions and the following disclaimer in the
112: * documentation and/or other materials provided with the distribution.
113: * 3. The name of the author may not be used to endorse or promote products
114: * derived from this software without specific prior written permission.
115: *
116: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
117: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
118: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
119: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
120: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
121: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
122: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
123: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
124: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
125: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
126: */
|