01: /*
02: (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: All rights reserved - see end of file.
04: $Id: Mode.java,v 1.7 2008/01/02 12:05:51 andy_seaborne Exp $
05: */
06:
07: package com.hp.hpl.jena.assembler;
08:
09: import com.hp.hpl.jena.rdf.model.Resource;
10:
11: /**
12: A Mode object controls whether persistent objects can be created or reused
13: by an assembler. Their methods are expected to be called when an
14: assembler is about to create a new object (because no object with the given
15: name exists) or reuse an existing one (because one does).
16:
17: <p>The default behaviour of the methods is dictated by booleans bound into
18: the mode object. Subclasses of mode may exploit the ability to inspect the
19: name of the object or its other RDF properties.
20:
21: @author kers
22: */
23: public class Mode {
24: /**
25: Mode that demands a new object be created and no existing object
26: should exist.
27: */
28: public static final Mode CREATE = new Mode(true, false);
29:
30: /**
31: Default mode; existing objects are reused, new objects are not created
32: */
33: public static final Mode DEFAULT = new Mode(false, true);
34:
35: /**
36: Mode that requires that objects should already exist; new objects cannot
37: be created.
38: */
39: public static final Mode REUSE = new Mode(false, true);
40:
41: /**
42: Mode that permits existing objects to be reused and new objects to
43: be created.
44: */
45: public static final Mode ANY = new Mode(true, true);
46:
47: protected final boolean mayCreate;
48: protected final boolean mayReuse;
49:
50: public Mode(boolean mayCreate, boolean mayReuse) {
51: this .mayCreate = mayCreate;
52: this .mayReuse = mayReuse;
53: }
54:
55: /**
56: Answer true if the object <code>root</code> with the given <code>name</code>
57: can be created if it does not already exist.
58: */
59: public boolean permitCreateNew(Resource root, String name) {
60: return mayCreate;
61: }
62:
63: /**
64: Answer true if the existing object <code>root</code> with the given
65: <code>name</code> can be reused.
66: */
67: public boolean permitUseExisting(Resource root, String name) {
68: return mayReuse;
69: }
70: }
71:
72: /*
73: * (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
74: * All rights reserved.
75: *
76: * Redistribution and use in source and binary forms, with or without
77: * modification, are permitted provided that the following conditions
78: * are met:
79: * 1. Redistributions of source code must retain the above copyright
80: * notice, this list of conditions and the following disclaimer.
81: * 2. Redistributions in binary form must reproduce the above copyright
82: * notice, this list of conditions and the following disclaimer in the
83: * documentation and/or other materials provided with the distribution.
84: * 3. The name of the author may not be used to endorse or promote products
85: * derived from this software without specific prior written permission.
86: *
87: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
88: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
90: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
91: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
92: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
93: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
94: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
95: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
96: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97: */
|