View Javadoc

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.PropertyType;
27  import javax.jcr.Value;
28  import org.modeshape.graph.ExecutionContext;
29  import org.modeshape.graph.property.ValueFactories;
30  import org.modeshape.jcr.nodetype.PropertyDefinitionTemplate;
31  
32  /**
33   * ModeShape implementation of the JCR 2 PropertyDefinitionTemplate interface.
34   */
35  class JcrPropertyDefinitionTemplate extends JcrItemDefinitionTemplate implements PropertyDefinitionTemplate {
36  
37      private boolean multiple = false;
38      private Value[] defaultValues = null;
39      private int requiredType = PropertyType.STRING;
40      private String[] valueConstraints = null;
41      private boolean fullTextSearchable = true;
42      private boolean queryOrderable = true;
43      private String[] availableQueryOperators;
44  
45      JcrPropertyDefinitionTemplate( ExecutionContext context ) {
46          super(context);
47      }
48  
49      /**
50       * {@inheritDoc}
51       * 
52       * @see org.modeshape.jcr.nodetype.PropertyDefinitionTemplate#setDefaultValues(java.lang.String[])
53       */
54      public void setDefaultValues( String[] defaultValues ) {
55          if (defaultValues == null) {
56              this.defaultValues = null;
57              return;
58          }
59  
60          this.defaultValues = new Value[defaultValues.length];
61          ValueFactories factories = getExecutionContext().getValueFactories();
62          for (int i = 0; i < defaultValues.length; i++) {
63              this.defaultValues[i] = new JcrValue(factories, null, PropertyType.STRING, defaultValues[i]);
64          }
65      }
66  
67      /**
68       * {@inheritDoc}
69       * 
70       * @see org.modeshape.jcr.nodetype.PropertyDefinitionTemplate#setDefaultValues(Value[])
71       */
72      public void setDefaultValues( Value[] defaultValues ) {
73          this.defaultValues = defaultValues;
74      }
75  
76      /**
77       * {@inheritDoc}
78       * 
79       * @see org.modeshape.jcr.nodetype.PropertyDefinitionTemplate#setMultiple(boolean)
80       */
81      public void setMultiple( boolean multiple ) {
82          this.multiple = multiple;
83      }
84  
85      /**
86       * {@inheritDoc}
87       * 
88       * @see org.modeshape.jcr.nodetype.PropertyDefinitionTemplate#setRequiredType(int)
89       */
90      public void setRequiredType( int requiredType ) {
91          assert requiredType == PropertyType.BINARY || requiredType == PropertyType.BOOLEAN || requiredType == PropertyType.DATE
92                 || requiredType == PropertyType.DOUBLE || requiredType == PropertyType.DECIMAL
93                 || requiredType == PropertyType.LONG || requiredType == PropertyType.NAME || requiredType == PropertyType.PATH
94                 || requiredType == PropertyType.REFERENCE || requiredType == PropertyType.WEAKREFERENCE
95                 || requiredType == PropertyType.URI
96                 || requiredType == PropertyType.STRING || requiredType == PropertyType.UNDEFINED;
97          this.requiredType = requiredType;
98      }
99  
100     /**
101      * {@inheritDoc}
102      * 
103      * @see org.modeshape.jcr.nodetype.PropertyDefinitionTemplate#setValueConstraints(java.lang.String[])
104      */
105     public void setValueConstraints( String[] constraints ) {
106         this.valueConstraints = constraints;
107     }
108 
109     /**
110      * {@inheritDoc}
111      * 
112      * @see javax.jcr.nodetype.PropertyDefinition#getDefaultValues()
113      */
114     public Value[] getDefaultValues() {
115         return this.defaultValues;
116     }
117 
118     /**
119      * {@inheritDoc}
120      * 
121      * @see javax.jcr.nodetype.PropertyDefinition#getRequiredType()
122      */
123     public int getRequiredType() {
124         return requiredType;
125     }
126 
127     /**
128      * {@inheritDoc}
129      * 
130      * @see javax.jcr.nodetype.PropertyDefinition#getValueConstraints()
131      */
132     public String[] getValueConstraints() {
133         return valueConstraints;
134     }
135 
136     /**
137      * {@inheritDoc}
138      * 
139      * @see javax.jcr.nodetype.PropertyDefinition#isMultiple()
140      */
141     public boolean isMultiple() {
142         return multiple;
143     }
144 
145     public boolean isFullTextSearchable() {
146         return this.fullTextSearchable;
147     }
148 
149     /**
150      * {@inheritDoc}
151      * 
152      * @see PropertyDefinitionTemplate#setFullTextSearchable(boolean)
153      */
154     public void setFullTextSearchable( boolean fullTextSearchable ) {
155         this.fullTextSearchable = fullTextSearchable;
156     }
157 
158     public String[] getAvailableQueryOperators() {
159         return this.availableQueryOperators;
160     }
161 
162     /**
163      * {@inheritDoc}
164      * 
165      * @see PropertyDefinitionTemplate#setAvailableQueryOperators(String[])
166      */
167     public void setAvailableQueryOperators( String[] queryOperators ) {
168         this.availableQueryOperators = queryOperators;
169     }
170 
171     public boolean isQueryOrderable() {
172         return this.queryOrderable;
173     }
174 
175     /**
176      * {@inheritDoc}
177      * 
178      * @see PropertyDefinitionTemplate#setQueryOrderable(boolean)
179      */
180     public void setQueryOrderable( boolean queryOrderable ) {
181         this.queryOrderable = queryOrderable;
182     }
183 }