1 /*
2 * ModeShape (http://www.modeshape.org)
3 * See the COPYRIGHT.txt file distributed with this work for information
4 * regarding copyright ownership. Some portions may be licensed
5 * to Red Hat, Inc. under one or more contributor license agreements.
6 * See the AUTHORS.txt file in the distribution for a full listing of
7 * individual contributors.
8 *
9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10 * is licensed to you under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * ModeShape is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23 */
24 package org.modeshape.jcr;
25
26 import javax.jcr.nodetype.ItemDefinition;
27 import javax.jcr.nodetype.NodeType;
28 import net.jcip.annotations.Immutable;
29 import org.modeshape.graph.ExecutionContext;
30 import org.modeshape.graph.property.Name;
31
32 /**
33 * ModeShape implementation of the {@link ItemDefinition} interface. This implementation is immutable and has all fields initialized
34 * through its constructor.
35 */
36 @Immutable
37 class JcrItemDefinition implements ItemDefinition {
38
39 protected final ExecutionContext context;
40
41 protected final JcrNodeType declaringNodeType;
42 protected final Name name;
43 private final int onParentVersion;
44 private final boolean autoCreated;
45 private final boolean mandatory;
46 private final boolean protectedItem;
47
48 JcrItemDefinition( ExecutionContext context,
49 JcrNodeType declaringNodeType,
50 Name name,
51 int onParentVersion,
52 boolean autoCreated,
53 boolean mandatory,
54 boolean protectedItem ) {
55 super();
56 this.context = context;
57 this.declaringNodeType = declaringNodeType;
58 this.name = name != null ? name : context.getValueFactories().getNameFactory().create(JcrNodeType.RESIDUAL_ITEM_NAME);
59 this.onParentVersion = onParentVersion;
60 this.autoCreated = autoCreated;
61 this.mandatory = mandatory;
62 this.protectedItem = protectedItem;
63 }
64
65 final Name getInternalName() {
66 return name;
67 }
68
69 /**
70 * Determine whether this is a residual item. Section 6.7.15 in the JSR 1.0 specification defines a residual item as one
71 * having a name equal to "*".
72 *
73 * @return true if this item is residual, or false otherwise
74 */
75 public boolean isResidual() {
76 return name.getLocalName().equals("*");
77 }
78
79 /**
80 * {@inheritDoc}
81 *
82 * @see javax.jcr.nodetype.ItemDefinition#getDeclaringNodeType()
83 */
84 public NodeType getDeclaringNodeType() {
85 return declaringNodeType;
86 }
87
88 /**
89 * {@inheritDoc}
90 *
91 * @see javax.jcr.nodetype.ItemDefinition#getName()
92 */
93 public String getName() {
94 if (name == null) {
95 return JcrNodeType.RESIDUAL_ITEM_NAME;
96 }
97
98 return name.getString(context.getNamespaceRegistry());
99 }
100
101 /**
102 * {@inheritDoc}
103 *
104 * @see javax.jcr.nodetype.ItemDefinition#getOnParentVersion()
105 */
106 public int getOnParentVersion() {
107 return onParentVersion;
108 }
109
110 /**
111 * {@inheritDoc}
112 *
113 * @see javax.jcr.nodetype.ItemDefinition#isAutoCreated()
114 */
115 public boolean isAutoCreated() {
116 return autoCreated;
117 }
118
119 /**
120 * {@inheritDoc}
121 *
122 * @see javax.jcr.nodetype.ItemDefinition#isMandatory()
123 */
124 public boolean isMandatory() {
125 return mandatory;
126 }
127
128 /**
129 * {@inheritDoc}
130 *
131 * @see javax.jcr.nodetype.ItemDefinition#isProtected()
132 */
133 public boolean isProtected() {
134 return protectedItem;
135 }
136
137 }