jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r792142 [31/35] - in /jackrabbit/sandbox/JCR-1456: ./ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/ jackrabbit-core/ jackrabbit-core/src/main/java/org/apache/jackrab...
Date Wed, 08 Jul 2009 13:57:46 GMT
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefReader.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefReader.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefReader.java Wed Jul  8 13:57:13 2009
@@ -16,121 +16,135 @@
  */
 package org.apache.jackrabbit.spi.commons.nodetype.compact;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.Reader;
-import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Set;
 
 import javax.jcr.NamespaceException;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.NodeTypeDefinition;
+import javax.jcr.query.qom.QueryObjectModelConstants;
 import javax.jcr.version.OnParentVersionAction;
 
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueConstraint;
 import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping;
 import org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException;
+import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefinitionFactory;
 import org.apache.jackrabbit.spi.commons.nodetype.compact.QNodeTypeDefinitionsBuilder.QNodeDefinitionBuilder;
 import org.apache.jackrabbit.spi.commons.nodetype.compact.QNodeTypeDefinitionsBuilder.QNodeTypeDefinitionBuilder;
 import org.apache.jackrabbit.spi.commons.nodetype.compact.QNodeTypeDefinitionsBuilder.QPropertyDefinitionBuilder;
+import org.apache.jackrabbit.spi.commons.query.qom.Operator;
 import org.apache.jackrabbit.util.ISO9075;
 
 /**
  * CompactNodeTypeDefReader. Parses node type definitions written in the compact
- * node type definition format and returns a list of QNodeTypeDefinition objects that
- * can then be used to register node types.
+ * node type definition format and provides a list of QNodeTypeDefinition
+ * objects that can then be used to register node types.
+ *
  * <p/>
  * The EBNF grammar of the compact node type definition:<br>
  * <pre>
- * cnd ::= ns_mapping* node_type_def+
- *
- * ns_mapping ::= "&lt;" prefix "=" namespace "&gt;"
- *
- * prefix ::= string
- *
- * namespace ::= string
- *
- * node_type_def ::= node_type_name [super_types] [options] {property_def | node_def}
- *
- * node_type_name ::= "[" string "]"
- *
- * super_types ::= "&gt;" string_list
- *
- * options ::= orderable_opt | mixin_opt | orderable_opt mixin_opt | mixin_opt orderable_opt
- *
- * orderable_opt ::= "orderable" | "ord" | "o"
- *
- * mixin_opt ::= "mixin" | "mix" | "m"
- *
- * property_def ::= "-" property_name [property_type_decl] [default_values] [attributes] [value_constraints]
- *
- * property_name ::= string
- *
- * property_type_decl ::= "(" property_type ")"
- *
- * property_type ::= "STRING" | "String |"string" |
- *                   "BINARY" | "Binary" | "binary" |
- *                   "LONG" | "Long" | "long" |
- *                   "DOUBLE" | "Double" | "double" |
- *                   "BOOLEAN" | "Boolean" | "boolean" |
- *                   "DATE" | "Date" | "date" |
- *                   "NAME | "Name | "name |
- *                   "PATH" | "Path" | "path" |
- *                   "REFERENCE" | "Reference" | "reference" |
- *                   "UNDEFINED" | "Undefined" | "undefined" | "*"
- *
- *
- * default_values ::= "=" string_list
- *
- * value_constraints ::= "&lt;" string_list
- *
- * node_def ::= "+" node_name [required_types] [default_type] [attributes]
- *
- * node_name ::= string
- *
- * required_types ::= "(" string_list ")"
- *
- * default_type ::= "=" string
- *
- * attributes ::= "primary" | "pri" | "!" |
- *                "autocreated" | "aut" | "a" |
- *                "mandatory" | "man" | "m" |
- *                "protected" | "pro" | "p" |
- *                "multiple" | "mul" | "*" |
- *                "COPY" | "Copy" | "copy" |
- *                "VERSION" | "Version" | "version" |
- *                "INITIALIZE" | "Initialize" | "initialize" |
- *                "COMPUTE" | "Compute" | "compute" |
- *                "IGNORE" | "Ignore" | "ignore" |
- *                "ABORT" | "Abort" | "abort"
- *
- * string_list ::= string {"," string}
- *
- * string ::= quoted_string | unquoted_string
- *
- * quoted_string :: = "'" unquoted_string "'"
- *
- * unquoted_string ::= [A-Za-z0-9:_]+
+ * Cnd ::= {NamespaceMapping | NodeTypeDef}
+ * NamespaceMapping ::= '<' Prefix '=' Uri '>'
+ * Prefix ::= String
+ * Uri ::= String
+ * NodeTypeDef ::= NodeTypeName [Supertypes]
+ *                 [NodeTypeAttribute {NodeTypeAttribute}]
+ *                 {PropertyDef | ChildNodeDef}
+ * NodeTypeName ::= '[' String ']'
+ * Supertypes ::= '>' (StringList | '?')
+ * NodeTypeAttribute ::= Orderable | Mixin | Abstract | Query |
+ *                       PrimaryItem
+ * Orderable ::= ('orderable' | 'ord' | 'o') ['?']
+ * Mixin ::= ('mixin' | 'mix' | 'm') ['?']
+ * Abstract ::= ('abstract' | 'abs' | 'a') ['?']
+ * Query ::= ('noquery' | 'nq') | ('query' | 'q' )
+ * PrimaryItem ::= ('primaryitem'| '!')(String | '?')
+ * PropertyDef ::= PropertyName [PropertyType] [DefaultValues]
+ *                 [PropertyAttribute {PropertyAttribute}]
+ *                 [ValueConstraints]
+ * PropertyName ::= '-' String
+ * PropertyType ::= '(' ('STRING' | 'BINARY' | 'LONG' | 'DOUBLE' |
+ *                       'BOOLEAN' | 'DATE' | 'NAME' | 'PATH' |
+ *                       'REFERENCE' | 'WEAKREFERENCE' |
+ *                       'DECIMAL' | 'URI' | 'UNDEFINED' | '*' |
+ *                       '?') ')'
+ * DefaultValues ::= '=' (StringList | '?')
+ * ValueConstraints ::= '<' (StringList | '?')
+ * ChildNodeDef ::= NodeName [RequiredTypes] [DefaultType]
+ *                  [NodeAttribute {NodeAttribute}]
+ * NodeName ::= '+' String
+ * RequiredTypes ::= '(' (StringList | '?') ')'
+ * DefaultType ::= '=' (String | '?')
+ * PropertyAttribute ::= Autocreated | Mandatory | Protected |
+ *                       Opv | Multiple | QueryOps | NoFullText |
+ *                       NoQueryOrder
+ * NodeAttribute ::= Autocreated | Mandatory | Protected |
+ *                   Opv | Sns
+ * Autocreated ::= ('autocreated' | 'aut' | 'a' )['?']
+ * Mandatory ::= ('mandatory' | 'man' | 'm') ['?']
+ * Protected ::= ('protected' | 'pro' | 'p') ['?']
+ * Opv ::= 'COPY' | 'VERSION' | 'INITIALIZE' | 'COMPUTE' |
+ *         'IGNORE' | 'ABORT' | ('OPV' '?')
+ * Multiple ::= ('multiple' | 'mul' | '*') ['?']
+ * QueryOps ::= ('queryops' | 'qop')
+ *              (('''Operator {','Operator}''') | '?')
+ * Operator ::= '=' | '<>' | '<' | '<=' | '>' | '>=' | 'LIKE'
+ * NoFullText ::= ('nofulltext' | 'nof') ['?']
+ * NoQueryOrder ::= ('noqueryorder' | 'nqord') ['?']
+ * Sns ::= ('sns' | '*') ['?']
+ * StringList ::= String {',' String}
+ * String ::= QuotedString | UnquotedString
+ * QuotedString ::= SingleQuotedString | DoubleQuotedString
+ * SingleQuotedString ::= ''' UnquotedString '''
+ * DoubleQuotedString ::= '"' UnquotedString '"'
+ * UnquotedString ::= XmlChar {XmlChar}
+ * XmlChar ::= see ยค3.2.2 Local Names
  * </pre>
  */
 public class CompactNodeTypeDefReader {
 
     /**
-     * Empty array of value constraints
+     * Default namespace mappings
      */
-    private final static String[] EMPTY_VALUE_CONSTRAINTS = new String[0];
-
+    public static final NamespaceMapping NS_DEFAULTS;
+    static {
+        try {
+            NS_DEFAULTS = new NamespaceMapping();
+            NS_DEFAULTS.setMapping(Name.NS_EMPTY_PREFIX, Name.NS_DEFAULT_URI);
+            NS_DEFAULTS.setMapping(Name.NS_JCR_PREFIX, Name.NS_JCR_URI);
+            NS_DEFAULTS.setMapping(Name.NS_MIX_PREFIX, Name.NS_MIX_URI);
+            NS_DEFAULTS.setMapping(Name.NS_NT_PREFIX, Name.NS_NT_URI);
+            NS_DEFAULTS.setMapping(Name.NS_REP_PREFIX, Name.NS_REP_URI);
+        } catch (NamespaceException e) {
+            throw new InternalError(e.toString());
+        }
+    }
+    
     /**
      * the list of parsed QNodeTypeDefinition
      */
-    private final List nodeTypeDefs = new LinkedList();
+    private final List<QNodeTypeDefinition> nodeTypeDefs
+            = new LinkedList<QNodeTypeDefinition>();
 
     /**
      * the current namespace mapping
@@ -158,44 +172,140 @@
     private final QNodeTypeDefinitionsBuilder builder;
 
     /**
-     * Creates a new CND reader.
-     * @param r
-     * @param systemId
-     * @param builder
-     * @throws ParseException
+     * Convenience method that creates a new CND reader and parses the given
+     * file directly.
+     *
+     * @param file A CND file
+     * @return a new 'parsed' reader object
+     * @throws ParseException if an error occurs
+     * @throws IOException if an I/O error occurs.
+     */
+    public static CompactNodeTypeDefReader read(File file)
+            throws ParseException, IOException {
+        InputStream in = null;
+        Reader r = null;
+        try {
+            in = new FileInputStream(file);
+            r = new InputStreamReader(in, "utf8");
+            return new CompactNodeTypeDefReader(r, file.getPath());
+        } finally {
+            if (r != null) {
+                try {
+                    r.close();
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Creates a new CND reader and parses the given stream directly.
+     *
+     * @param r a reader to the CND
+     * @param systemId a informative id of the given stream
+     * @throws ParseException if an error occurs
+     */
+    public CompactNodeTypeDefReader(Reader r, String systemId)
+            throws ParseException {
+        this(r, systemId, null, null);
+    }
+
+    /**
+     * Creates a new CND reader and parses the given stream it directly.
+     * If <code>builder</code> is <code>null</code> the reader uses the
+     * default {@link QNodeTypeDefinitionsBuilderImpl}.
+     *
+     * @param r a reader to the CND
+     * @param systemId a informative id of the given stream
+     * @param builder build for creating new definitions or <code>null</code>
+     * @throws ParseException if an error occurs
      */
-    public CompactNodeTypeDefReader(Reader r, String systemId, QNodeTypeDefinitionsBuilder builder) throws ParseException {
-        this(r, systemId, new NamespaceMapping(), builder);
+    public CompactNodeTypeDefReader(Reader r, String systemId,
+                                    QNodeTypeDefinitionsBuilder builder)
+            throws ParseException {
+        this(r, systemId, null, builder);
     }
 
+    /**
+     * Creates a new CND reader and parses the given stream it directly.
+     *
+     * @param r a reader to the CND
+     * @param systemId a informative id of the given stream
+     * @param mapping default namespace mapping to use
+     * @throws ParseException if an error occurs
+     */
+    public CompactNodeTypeDefReader(Reader r, String systemId, NamespaceMapping mapping)
+            throws ParseException {
+        this(r, systemId, mapping, null);
+    }
 
     /**
-     * Creates a new CND reader.
-     * @param r
-     * @param builder
-     * @throws ParseException
+     * Creates a new CND reader and parses the given stream it directly.
+     * If <code>builder</code> is <code>null</code> the reader uses the
+     * default {@link QNodeTypeDefinitionsBuilderImpl}.
+     *
+     * @param r a reader to the CND
+     * @param systemId a informative id of the given stream
+     * @param mapping default namespace mapping to use
+     * @param builder build for creating new definitions
+     * @throws ParseException if an error occurs
      */
     public CompactNodeTypeDefReader(Reader r, String systemId, NamespaceMapping mapping,
             QNodeTypeDefinitionsBuilder builder) throws ParseException {
 
-        this.builder = builder;
+        this.builder = builder == null
+                ? new QNodeTypeDefinitionsBuilderImpl()
+                : builder;
         lexer = new Lexer(r, systemId);
-        this.nsMapping = mapping;
+        this.nsMapping = mapping == null
+                ? new NamespaceMapping(NS_DEFAULTS)
+                : mapping;
         this.resolver = new DefaultNamePathResolver(nsMapping);
         nextToken();
         parse();
     }
 
     /**
+     * Returns the previously assigned system id
+     * @return the system id
+     */
+    public String getSystemId() {
+        return lexer.getSystemId();
+    }
+
+    /**
      * Returns the list of parsed QNodeTypeDefinition definitions.
      *
-     * @return a List of QNodeTypeDefinition objects
+     * @return a collection of QNodeTypeDefinition objects
      */
-    public List getNodeTypeDefs() {
+    public List<QNodeTypeDefinition> getNodeTypeDefinitions() {
         return nodeTypeDefs;
     }
 
     /**
+     * Convenience methdo that returns the list of parsed NodeTypeDefinition
+     * definitions, using the {@link NodeTypeDefinitionFactory}.
+     *
+     * @param session repository session used for converting the definitions.
+     * @return a collection of NodeTypeDefinition objects
+     * @throws RepositoryException if an error occurs
+     */
+    public List<NodeTypeDefinition> getNodeTypeDefinitions(Session session)
+            throws RepositoryException {
+        NodeTypeDefinitionFactory fac = new NodeTypeDefinitionFactory(session);
+        return fac.create(nodeTypeDefs);
+    }
+
+    /**
      * Returns the namespace mapping.
      *
      * @return a NamespaceMapping object.
@@ -207,7 +317,7 @@
     /**
      * Parses the definition
      *
-     * @throws ParseException
+     * @throws ParseException if an error during parsing occurs
      */
     private void parse() throws ParseException {
         while (!currentTokenEquals(Lexer.EOF)) {
@@ -219,6 +329,8 @@
             QNodeTypeDefinitionBuilder ntd = builder.newQNodeTypeDefinition();
             ntd.setOrderableChildNodes(false);
             ntd.setMixin(false);
+            ntd.setAbstract(false);
+            ntd.setQueryable(true);
             ntd.setPrimaryItemName(null);
             doNodeTypeName(ntd);
             doSuperTypes(ntd);
@@ -233,8 +345,8 @@
     /**
      * processes the namespace declaration
      *
-     * @return
-     * @throws ParseException
+     * @return <code>true</code> if a namespace was parsed
+     * @throws ParseException if an error during parsing occurs
      */
     private boolean doNameSpace() throws ParseException {
         if (!currentTokenEquals('<')) {
@@ -264,8 +376,8 @@
     /**
      * processes the nodetype name
      *
-     * @param ntd
-     * @throws ParseException
+     * @param ntd nodetype definition builder
+     * @throws ParseException if an error during parsing occurs
      */
     private void doNodeTypeName(QNodeTypeDefinitionBuilder ntd) throws ParseException {
         if (!currentTokenEquals(Lexer.BEGIN_NODE_TYPE_NAME)) {
@@ -284,14 +396,11 @@
     /**
      * processes the superclasses
      *
-     * @param ntd
-     * @throws ParseException
+     * @param ntd nodetype definition builder
+     * @throws ParseException if an error during parsing occurs
      */
     private void doSuperTypes(QNodeTypeDefinitionBuilder ntd) throws ParseException {
-        // a set would be nicer here, in case someone defines a supertype twice.
-        // but due to issue [JCR-333], the resulting node type definition is
-        // not symmetric anymore and the tests will fail.
-        ArrayList supertypes = new ArrayList();
+        Set<Name> supertypes = new HashSet<Name>();
         if (currentTokenEquals(Lexer.EXTENDS))
             do {
                 nextToken();
@@ -299,29 +408,39 @@
                 nextToken();
             } while (currentTokenEquals(Lexer.LIST_DELIMITER));
 
-        ntd.setSupertypes((Name[]) supertypes.toArray(new Name[0]));
+        ntd.setSupertypes(supertypes.toArray(new Name[supertypes.size()]));
     }
 
     /**
      * processes the options
      *
-     * @param ntd
-     * @throws ParseException
+     * @param ntd nodetype definition builder
+     * @throws ParseException if an error during parsing occurs
      */
     private void doOptions(QNodeTypeDefinitionBuilder ntd) throws ParseException {
-        if (currentTokenEquals(Lexer.ORDERABLE)) {
-            ntd.setOrderableChildNodes(true);
-            nextToken();
-            if (currentTokenEquals(Lexer.MIXIN)) {
-                ntd.setMixin(true);
-                nextToken();
-            }
-        } else if (currentTokenEquals(Lexer.MIXIN)) {
-            ntd.setMixin(true);
-            nextToken();
+        boolean hasOption = true;
+        while (hasOption) {
             if (currentTokenEquals(Lexer.ORDERABLE)) {
+                nextToken();
                 ntd.setOrderableChildNodes(true);
+            } else if (currentTokenEquals(Lexer.MIXIN)) {
+                nextToken();
+                ntd.setMixin(true);
+            } else if (currentTokenEquals(Lexer.ABSTRACT)) {
+                nextToken();
+                ntd.setAbstract(true);
+            } else if (currentTokenEquals(Lexer.NOQUERY)) {
+                nextToken();
+                ntd.setQueryable(false);
+            } else if (currentTokenEquals(Lexer.QUERY)) {
                 nextToken();
+                ntd.setQueryable(true);
+            } else if (currentTokenEquals(Lexer.PRIMARYITEM)) {
+                nextToken();
+                ntd.setPrimaryItemName(toName(currentToken));
+                nextToken();
+            } else {
+                hasOption = false;
             }
         }
     }
@@ -329,12 +448,12 @@
     /**
      * processes the item definitions
      *
-     * @param ntd
-     * @throws ParseException
+     * @param ntd nodetype definition builder
+     * @throws ParseException if an error during parsing occurs
      */
     private void doItemDefs(QNodeTypeDefinitionBuilder ntd) throws ParseException {
-        List propertyDefinitions = new ArrayList();
-        List nodeDefinitions = new ArrayList();
+        List<QPropertyDefinition> propertyDefinitions = new LinkedList<QPropertyDefinition>();
+        List<QNodeDefinition> nodeDefinitions = new LinkedList<QNodeDefinition>();
         while (currentTokenEquals(Lexer.PROPERTY_DEFINITION) || currentTokenEquals(Lexer.CHILD_NODE_DEFINITION)) {
             if (currentTokenEquals(Lexer.PROPERTY_DEFINITION)) {
                 QPropertyDefinitionBuilder pd = ntd.newQPropertyDefinition();
@@ -347,7 +466,10 @@
                 pd.setOnParentVersion(OnParentVersionAction.COPY);
                 pd.setProtected(false);
                 pd.setRequiredType(PropertyType.STRING);
-                pd.setValueConstraints(EMPTY_VALUE_CONSTRAINTS);
+                pd.setValueConstraints(QValueConstraint.EMPTY_ARRAY);
+                pd.setFullTextSearchable(true);
+                pd.setQueryOrderable(true);
+                pd.setAvailableQueryOperators(Operator.getAllQueryOperators());
 
                 nextToken();
                 doPropertyDefinition(pd, ntd);
@@ -370,19 +492,16 @@
                 nodeDefinitions.add(nd.build());
             }
         }
-
-        ntd.setPropertyDefs((QPropertyDefinition[]) propertyDefinitions
-                .toArray(new QPropertyDefinition[0]));
-
-        ntd.setChildNodeDefs((QNodeDefinition[]) nodeDefinitions.toArray(new QNodeDefinition[0]));
+        ntd.setPropertyDefs(propertyDefinitions.toArray(new QPropertyDefinition[propertyDefinitions.size()]));
+        ntd.setChildNodeDefs(nodeDefinitions.toArray(new QNodeDefinition[nodeDefinitions.size()]));
     }
 
     /**
      * processes the property definition
      *
-     * @param pd
-     * @param ntd
-     * @throws ParseException
+     * @param pd property definition builder
+     * @param ntd declaring nodetype definition builder
+     * @throws ParseException if an error during parsing occurs
      */
     private void doPropertyDefinition(QPropertyDefinitionBuilder pd, QNodeTypeDefinitionBuilder ntd)
             throws ParseException {
@@ -401,8 +520,8 @@
     /**
      * processes the property type
      *
-     * @param pd
-     * @throws ParseException
+     * @param pd property definition builder
+     * @throws ParseException if an error during parsing occurs
      */
     private void doPropertyType(QPropertyDefinitionBuilder pd) throws ParseException {
         if (!currentTokenEquals(Lexer.BEGIN_TYPE)) {
@@ -415,6 +534,8 @@
             pd.setRequiredType(PropertyType.BINARY);
         } else if (currentTokenEquals(Lexer.LONG)) {
             pd.setRequiredType(PropertyType.LONG);
+        } else if (currentTokenEquals(Lexer.DECIMAL)) {
+            pd.setRequiredType(PropertyType.DECIMAL);
         } else if (currentTokenEquals(Lexer.DOUBLE)) {
             pd.setRequiredType(PropertyType.DOUBLE);
         } else if (currentTokenEquals(Lexer.BOOLEAN)) {
@@ -425,8 +546,12 @@
             pd.setRequiredType(PropertyType.NAME);
         } else if (currentTokenEquals(Lexer.PATH)) {
             pd.setRequiredType(PropertyType.PATH);
+        } else if (currentTokenEquals(Lexer.URI)) {
+            pd.setRequiredType(PropertyType.URI);
         } else if (currentTokenEquals(Lexer.REFERENCE)) {
             pd.setRequiredType(PropertyType.REFERENCE);
+        } else if (currentTokenEquals(Lexer.WEAKREFERENCE)) {
+            pd.setRequiredType(PropertyType.WEAKREFERENCE);
         } else if (currentTokenEquals(Lexer.UNDEFINED)) {
             pd.setRequiredType(PropertyType.UNDEFINED);
         } else {
@@ -442,12 +567,14 @@
     /**
      * processes the property attributes
      *
-     * @param pd
-     * @param ntd
-     * @throws ParseException
+     * @param pd property definition builder
+     * @param ntd declaring nodetype definition builder
+     * @throws ParseException if an error during parsing occurs
      */
-    private void doPropertyAttributes(QPropertyDefinitionBuilder pd, QNodeTypeDefinitionBuilder ntd) throws ParseException {
-        while (currentTokenEquals(Lexer.ATTRIBUTE)) {
+    private void doPropertyAttributes(QPropertyDefinitionBuilder pd,
+                                      QNodeTypeDefinitionBuilder ntd)
+            throws ParseException {
+        while (currentTokenEquals(Lexer.PROP_ATTRIBUTE)) {
             if (currentTokenEquals(Lexer.PRIMARY)) {
                 if (ntd.getPrimaryItemName() != null) {
                     String name = null;
@@ -479,71 +606,114 @@
                 pd.setOnParentVersion(OnParentVersionAction.IGNORE);
             } else if (currentTokenEquals(Lexer.ABORT)) {
                 pd.setOnParentVersion(OnParentVersionAction.ABORT);
+            } else if (currentTokenEquals(Lexer.NOFULLTEXT)) {
+                pd.setFullTextSearchable(false);
+            } else if (currentTokenEquals(Lexer.NOQUERYORDER)) {
+                pd.setQueryOrderable(false);
+            } else if (currentTokenEquals(Lexer.QUERYOPS)) {
+                doPropertyQueryOperators(pd);
             }
             nextToken();
         }
     }
 
     /**
+     * processes the property query operators
+     *
+     * @param pd the property definition builder
+     * @throws ParseException if an error occurs
+     */
+    private void doPropertyQueryOperators(QPropertyDefinitionBuilder pd)
+            throws ParseException {
+        if (!currentTokenEquals(Lexer.QUERYOPS)) {
+            return;
+        }
+        nextToken();
+
+        String[] ops = currentToken.split(",");
+        List<String> queryOps = new LinkedList<String>();
+        for (String op : ops) {
+            String s = op.trim();
+            if (s.equals(Lexer.QUEROPS_EQUAL)) {
+                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO);
+            } else if (s.equals(Lexer.QUEROPS_NOTEQUAL)) {
+                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO);
+            } else if (s.equals(Lexer.QUEROPS_LESSTHAN)) {
+                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN);
+            } else if (s.equals(Lexer.QUEROPS_LESSTHANOREQUAL)) {
+                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO);
+            } else if (s.equals(Lexer.QUEROPS_GREATERTHAN)) {
+                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN);
+            } else if (s.equals(Lexer.QUEROPS_GREATERTHANOREQUAL)) {
+                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO);
+            } else if (s.equals(Lexer.QUEROPS_LIKE)) {
+                queryOps.add(QueryObjectModelConstants.JCR_OPERATOR_LIKE);
+            } else {
+                lexer.fail("'" + s + "' is not a valid query operator");
+            }
+        }
+        pd.setAvailableQueryOperators(queryOps.toArray(new String[queryOps.size()]));
+    }
+
+    /**
      * processes the property default values
      *
-     * @param pd
-     * @throws ParseException
+     * @param pd property definition builder
+     * @throws ParseException if an error during parsing occurs
      */
-    private void doPropertyDefaultValue(QPropertyDefinitionBuilder pd) throws ParseException {
+    private void doPropertyDefaultValue(QPropertyDefinitionBuilder pd)
+            throws ParseException {
         if (!currentTokenEquals(Lexer.DEFAULT)) {
             return;
         }
-        List defaultValues = new ArrayList();
+        List<QValue> defaultValues = new LinkedList<QValue>();
         do {
             nextToken();
-            QValue value = null;
             try {
-                value = pd.createValue(currentToken, resolver);
+                defaultValues.add(pd.createValue(currentToken, resolver));
             } catch (ValueFormatException e) {
                 lexer.fail("'" + currentToken + "' is not a valid string representation of a value of type " + pd.getRequiredType());
             } catch (RepositoryException e) {
                 lexer.fail("An error occured during value conversion of '" + currentToken + "'");
             }
-            defaultValues.add(value);
             nextToken();
         } while (currentTokenEquals(Lexer.LIST_DELIMITER));
-        pd.setDefaultValues((QValue[]) defaultValues.toArray(new QValue[0]));
+        pd.setDefaultValues(defaultValues.toArray(new QValue[defaultValues.size()]));
     }
 
     /**
      * processes the property value constraints
      *
-     * @param pd
-     * @throws ParseException
+     * @param pd property definition builder
+     * @throws ParseException if an error during parsing occurs
      */
-    private void doPropertyValueConstraints(QPropertyDefinitionBuilder pd) throws ParseException {
+    private void doPropertyValueConstraints(QPropertyDefinitionBuilder pd)
+            throws ParseException {
         if (!currentTokenEquals(Lexer.CONSTRAINT)) {
             return;
         }
-        List constraints = new ArrayList();
+        List<QValueConstraint> constraints = new LinkedList<QValueConstraint>();
         do {
             nextToken();
-            String constraint = null;
             try {
-                constraint = pd.createValueConstraint(currentToken, resolver);
+                constraints.add(pd.createValueConstraint(currentToken, resolver));
             } catch (InvalidConstraintException e) {
                 lexer.fail("'" + currentToken + "' is not a valid constraint expression for a value of type " + pd.getRequiredType());
             }
-            constraints.add(constraint);
             nextToken();
         } while (currentTokenEquals(Lexer.LIST_DELIMITER));
-        pd.setValueConstraints((String[]) constraints.toArray(new String[0]));
+        pd.setValueConstraints(constraints.toArray(new QValueConstraint[constraints.size()]));
     }
 
     /**
      * processes the childnode definition
      *
-     * @param nd
-     * @param ntd
-     * @throws ParseException
+     * @param nd node definition builder
+     * @param ntd declaring nodetype definition builder
+     * @throws ParseException if an error during parsing occurs
      */
-    private void doChildNodeDefinition(QNodeDefinitionBuilder nd, QNodeTypeDefinitionBuilder ntd)
+    private void doChildNodeDefinition(QNodeDefinitionBuilder nd,
+                                       QNodeTypeDefinitionBuilder ntd)
             throws ParseException {
         if (currentTokenEquals('*')) {
             nd.setName(NameConstants.ANY_NAME);
@@ -559,30 +729,32 @@
     /**
      * processes the childnode required types
      *
-     * @param nd
-     * @throws ParseException
+     * @param nd node definition builder
+     * @throws ParseException if an error during parsing occurs
      */
-    private void doChildNodeRequiredTypes(QNodeDefinitionBuilder nd) throws ParseException {
+    private void doChildNodeRequiredTypes(QNodeDefinitionBuilder nd)
+            throws ParseException {
         if (!currentTokenEquals(Lexer.BEGIN_TYPE)) {
             return;
         }
-        List types = new ArrayList();
+        List<Name> types = new LinkedList<Name>();
         do {
             nextToken();
             types.add(toName(currentToken));
             nextToken();
         } while (currentTokenEquals(Lexer.LIST_DELIMITER));
-        nd.setRequiredPrimaryTypes((Name[]) types.toArray(new Name[0]));
+        nd.setRequiredPrimaryTypes(types.toArray(new Name[types.size()]));
         nextToken();
     }
 
     /**
      * processes the childnode default types
      *
-     * @param nd
-     * @throws ParseException
+     * @param nd node definition builder
+     * @throws ParseException if an error during parsing occurs
      */
-    private void doChildNodeDefaultType(QNodeDefinitionBuilder nd) throws ParseException {
+    private void doChildNodeDefaultType(QNodeDefinitionBuilder nd)
+            throws ParseException {
         if (!currentTokenEquals(Lexer.DEFAULT)) {
             return;
         }
@@ -594,12 +766,14 @@
     /**
      * processes the childnode attributes
      *
-     * @param nd
-     * @param ntd
-     * @throws ParseException
+     * @param nd node definition builder
+     * @param ntd declaring nodetype definition builder
+     * @throws ParseException if an error during parsing occurs
      */
-    private void doChildNodeAttributes(QNodeDefinitionBuilder nd, QNodeTypeDefinitionBuilder ntd) throws ParseException {
-        while (currentTokenEquals(Lexer.ATTRIBUTE)) {
+    private void doChildNodeAttributes(QNodeDefinitionBuilder nd,
+                                       QNodeTypeDefinitionBuilder ntd)
+            throws ParseException {
+        while (currentTokenEquals(Lexer.NODE_ATTRIBUTE)) {
             if (currentTokenEquals(Lexer.PRIMARY)) {
                 if (ntd.getPrimaryItemName() != null) {
                     String name = null;
@@ -617,7 +791,7 @@
                 nd.setMandatory(true);
             } else if (currentTokenEquals(Lexer.PROTECTED)) {
                 nd.setProtected(true);
-            } else if (currentTokenEquals(Lexer.MULTIPLE)) {
+            } else if (currentTokenEquals(Lexer.SNS)) {
                 nd.setAllowsSameNameSiblings(true);
             } else if (currentTokenEquals(Lexer.COPY)) {
                 nd.setOnParentVersion(OnParentVersionAction.COPY);
@@ -637,11 +811,11 @@
     }
 
     /**
-     * Converts the given string into a qualified name using the current
+     * Converts the given string into a <code>Name</code> using the current
      * namespace mapping.
      *
-     * @param stringName
-     * @return the qualified name
+     * @param stringName jcr name
+     * @return A <code>Name</code> object.
      * @throws ParseException if the conversion fails
      */
     private Name toName(String stringName) throws ParseException {
@@ -670,14 +844,14 @@
 
     /**
      * Checks if the {@link #currentToken} is semantically equal to the given
-     * argument.
+     * argument ignoring the case.
      *
      * @param s the tokens to compare with
      * @return <code>true</code> if equals; <code>false</code> otherwise.
      */
     private boolean currentTokenEquals(String[] s) {
-        for (int i = 0; i < s.length; i++) {
-            if (currentToken.equals(s[i])) {
+        for (String value : s) {
+            if (currentToken.equalsIgnoreCase(value)) {
                 return true;
             }
         }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefWriter.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefWriter.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefWriter.java Wed Jul  8 13:57:13 2009
@@ -19,15 +19,21 @@
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashSet;
-import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
 
 import javax.jcr.NamespaceException;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NodeTypeDefinition;
+import javax.jcr.query.qom.QueryObjectModelConstants;
 import javax.jcr.version.OnParentVersionAction;
 
 import org.apache.jackrabbit.spi.Name;
@@ -35,9 +41,16 @@
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueConstraint;
+import org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
+import org.apache.jackrabbit.spi.commons.namespace.SessionNamespaceResolver;
+import org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException;
+import org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint;
+import org.apache.jackrabbit.spi.commons.query.qom.Operator;
 import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
 import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 import org.apache.jackrabbit.util.ISO9075;
@@ -72,11 +85,6 @@
     private final NamePathResolver npResolver;
 
     /**
-     * the current value factory
-     */
-    private final ValueFactory valueFactory;
-
-    /**
      * the underlying writer
      */
     private Writer out;
@@ -89,19 +97,43 @@
     /**
      * namespaces(prefixes) that are used
      */
-    private final HashSet usedNamespaces = new HashSet();
+    private final Set<String> usedNamespaces = new HashSet<String>();
 
     /**
-     * Creates a new nodetype writer
+     * Creates a new nodetype writer based on a session
+     *
+     * @param out the underlaying writer
+     * @param s repository session
+     * @param includeNS if <code>true</code> all used namespace decl. are also
+     *                  written to the writer
+     */
+    public CompactNodeTypeDefWriter(Writer out, Session s, boolean includeNS) {
+        this(out, new SessionNamespaceResolver(s), new DefaultNamePathResolver(s), includeNS);
+    }
+
+    /**
+     * Creates a new nodetype writer based on a namespace resolver
+     *
+     * @param out the underlaying writer
+     * @param r the naespace resolver
+     * @param includeNS if <code>true</code> all used namespace decl. are also
+     *                  written to the writer
+     */
+    public CompactNodeTypeDefWriter(Writer out, NamespaceResolver r, boolean includeNS) {
+        this(out, r, new DefaultNamePathResolver(r), includeNS);
+    }
+
+    /**
+     * Creates a new nodetype writer that does not include namepsaces.
      *
-     * @param out the underlying writer
-     * @param r the namespace resolver
-     * @param npResolver
-     * @param valueFactory
-     */
-    public CompactNodeTypeDefWriter(Writer out, NamespaceResolver r, NamePathResolver npResolver,
-            ValueFactory valueFactory) {
-        this(out, r, npResolver, valueFactory, false);
+     * @param out the underlaying writer
+     * @param r the naespace resolver
+     * @param npResolver name-path resolver
+     */
+    public CompactNodeTypeDefWriter(Writer out,
+                                    NamespaceResolver r,
+                                    NamePathResolver npResolver) {
+        this(out, r, npResolver, false);
     }
 
     /**
@@ -109,15 +141,16 @@
      *
      * @param out the underlaying writer
      * @param r the naespace resolver
-     * @param npResolver
-     * @param valueFactory
+     * @param npResolver name-path resolver
      * @param includeNS if <code>true</code> all used namespace decl. are also
+     *                  written to the writer
      */
-    public CompactNodeTypeDefWriter(Writer out, NamespaceResolver r, NamePathResolver npResolver,
-            ValueFactory valueFactory, boolean includeNS) {
+    public CompactNodeTypeDefWriter(Writer out,
+                                    NamespaceResolver r,
+                                    NamePathResolver npResolver,
+                                    boolean includeNS) {
         this.resolver = r;
         this.npResolver = npResolver;
-        this.valueFactory = valueFactory;
         if (includeNS) {
             this.out = new StringWriter();
             this.nsWriter = out;
@@ -131,20 +164,19 @@
      * Writes the given list of QNodeTypeDefinition to the output writer including the
      * used namespaces.
      *
-     * @param l
-     * @param r
-     * @param npResolver
-     * @param valueFactory
-     * @param out
-     * @throws IOException
-     */
-    public static void write(List l, NamespaceResolver r, NamePathResolver npResolver,
-            ValueFactory valueFactory, Writer out)
+     * @param defs collection of definitions
+     * @param r namespace resolver
+     * @param npResolver name-path resolver
+     * @param out output writer
+     * @throws IOException if an I/O error occurs
+     */
+    public static void write(Collection<QNodeTypeDefinition> defs,
+                             NamespaceResolver r,
+                             NamePathResolver npResolver,
+                             Writer out)
             throws IOException {
-        CompactNodeTypeDefWriter w = new CompactNodeTypeDefWriter(out, r, npResolver, valueFactory, true);
-        Iterator iter = l.iterator();
-        while (iter.hasNext()) {
-            QNodeTypeDefinition def = (QNodeTypeDefinition) iter.next();
+        CompactNodeTypeDefWriter w = new CompactNodeTypeDefWriter(out, r, npResolver, true);
+        for (QNodeTypeDefinition def : defs) {
             w.write(def);
         }
         w.close();
@@ -153,8 +185,8 @@
     /**
      * Write one QNodeTypeDefinition to this writer
      *
-     * @param ntd
-     * @throws IOException
+     * @param ntd node type definition
+     * @throws IOException if an I/O error occurs
      */
     public void write(QNodeTypeDefinition ntd) throws IOException {
         writeName(ntd);
@@ -166,10 +198,36 @@
     }
 
     /**
+     * Write a collection of QNodeTypeDefinitions to this writer
+     *
+     * @param defs node type definitions
+     * @throws IOException if an I/O error occurs
+     */
+    public void write(Collection<QNodeTypeDefinition> defs) throws IOException {
+        for (QNodeTypeDefinition def : defs) {
+            write(def);
+        }
+    }
+
+    /**
+     * Write one NodeTypeDefinition to this writer
+     *
+     * @param nt node type definition
+     * @throws IOException if an I/O error occurs
+     */
+    public void write(NodeTypeDefinition nt) throws IOException {
+        try {
+            write(new QNodeTypeDefinitionImpl(nt, npResolver, QValueFactoryImpl.getInstance()));
+        } catch (RepositoryException e) {
+            throw new IOException("Error during internal conversion of nodetype definition:" + e.toString());
+        }
+    }
+
+    /**
      * Flushes all pending write operations and Closes this writer. please note,
      * that the underlying writer remains open.
      *
-     * @throws IOException
+     * @throws IOException if an I/O error occurs
      */
     public void close() throws IOException {
         if (nsWriter != null) {
@@ -185,6 +243,8 @@
 
     /**
      * write name
+     * @param ntd node type definition
+     * @throws IOException if an I/O error occurs
      */
     private void writeName(QNodeTypeDefinition ntd) throws IOException {
         out.write("[");
@@ -194,60 +254,88 @@
 
     /**
      * write supertypes
+     * @param ntd node type definition
+     * @throws IOException if an I/O error occurs
      */
     private void writeSupertypes(QNodeTypeDefinition ntd) throws IOException {
-        Name[] sta = ntd.getSupertypes();
-        String delim = " > ";
-        for (int i = 0; i < sta.length; i++) {
-            out.write(delim);
-            out.write(resolve(sta[i]));
-            delim = ", ";
+        // get ordered list of supertypes, omitting nt:Base
+        TreeSet<Name> supertypes = new TreeSet<Name>();
+        for (Name name : ntd.getSupertypes()) {
+            if (!name.equals(NameConstants.NT_BASE)) {
+                supertypes.add(name);
+            }
+        }
+        if (!supertypes.isEmpty()) {
+            String delim = " > ";
+            for (Name name : supertypes) {
+                out.write(delim);
+                out.write(resolve(name));
+                delim = ", ";
+            }
         }
     }
 
     /**
      * write options
+     * @param ntd node type definition
+     * @throws IOException if an I/O error occurs
      */
     private void writeOptions(QNodeTypeDefinition ntd) throws IOException {
+        List<String> options = new LinkedList<String>();
+        if (ntd.isAbstract()) {
+            options.add(Lexer.ABSTRACT[0]);
+        }
         if (ntd.hasOrderableChildNodes()) {
-            out.write("\n" + INDENT);
-            out.write("orderable");
-            if (ntd.isMixin()) {
-                out.write(" mixin");
+            options.add(Lexer.ORDERABLE[0]);
+        }
+        if (ntd.isMixin()) {
+            options.add(Lexer.MIXIN[0]);
+        }
+        if (!ntd.isQueryable()) {
+            options.add(Lexer.NOQUERY[0]);
+        }
+        if (ntd.getPrimaryItemName() != null) {
+            options.add(Lexer.PRIMARYITEM[0]);
+            options.add(resolve(ntd.getPrimaryItemName()));
+        }
+        for (int i = 0; i < options.size(); i++) {
+            if (i == 0) {
+                out.write("\n" + INDENT);
+            } else {
+                out.write(" ");
             }
-        } else if (ntd.isMixin()) {
-            out.write("\n" + INDENT);
-            out.write("mixin");
+            out.write(options.get(i));
         }
     }
 
     /**
      * write prop defs
+     * @param ntd node type definition
+     * @throws IOException if an I/O error occurs
      */
     private void writePropDefs(QNodeTypeDefinition ntd) throws IOException {
-        QPropertyDefinition[] pda = ntd.getPropertyDefs();
-        for (int i = 0; i < pda.length; i++) {
-            QPropertyDefinition pd = pda[i];
-            writePropDef(ntd, pd);
+        for (QPropertyDefinition pd : ntd.getPropertyDefs()) {
+            writePropDef(pd);
         }
     }
 
     /**
      * write node defs
+     * @param ntd node type definition
+     * @throws IOException if an I/O error occurs
      */
     private void writeNodeDefs(QNodeTypeDefinition ntd) throws IOException {
-        QNodeDefinition[] nda = ntd.getChildNodeDefs();
-        for (int i = 0; i < nda.length; i++) {
-            QNodeDefinition nd = nda[i];
-            writeNodeDef(ntd, nd);
+        for (QNodeDefinition nd : ntd.getChildNodeDefs()) {
+            writeNodeDef(nd);
         }
     }
 
     /**
      * write prop def
-     * @param pd
+     * @param pd property definition
+     * @throws IOException if an I/O error occurs
      */
-    private void writePropDef(QNodeTypeDefinition ntd, QPropertyDefinition pd) throws IOException {
+    private void writePropDef(QPropertyDefinition pd) throws IOException {
         out.write("\n" + INDENT + "- ");
 
         Name name = pd.getName();
@@ -261,7 +349,6 @@
         out.write(PropertyType.nameFromValue(pd.getRequiredType()).toLowerCase());
         out.write(")");
         writeDefaultValues(pd.getDefaultValues());
-        out.write(ntd.getPrimaryItemName() != null && ntd.getPrimaryItemName().equals(pd.getName()) ? " primary" : "");
         if (pd.isMandatory()) {
             out.write(" mandatory");
         }
@@ -278,23 +365,59 @@
             out.write(" ");
             out.write(OnParentVersionAction.nameFromValue(pd.getOnParentVersion()).toLowerCase());
         }
+        if (!pd.isFullTextSearchable()) {
+            out.write(" nofulltext");
+        }
+        if (!pd.isQueryOrderable()) {
+            out.write(" noqueryorder");
+        }
+        String[] qops = pd.getAvailableQueryOperators();
+        if (qops != null && qops.length > 0) {
+            List<String> opts = new ArrayList<String>(Arrays.asList(qops));
+            List<String> defaultOps = Arrays.asList(Operator.getAllQueryOperators());
+            if (!opts.containsAll(defaultOps)) {
+                out.write(" queryops '");
+                String delim = "";
+                for (String opt: opts) {
+                    out.write(delim);
+                    delim= ", ";
+                    if (opt.equals(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO)) {
+                        out.write(Lexer.QUEROPS_EQUAL);
+                    } else if (opt.equals(QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO)) {
+                        out.write(Lexer.QUEROPS_NOTEQUAL);
+                    } else if (opt.equals(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN)) {
+                        out.write(Lexer.QUEROPS_GREATERTHAN);
+                    } else if (opt.equals(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO)) {
+                        out.write(Lexer.QUEROPS_GREATERTHANOREQUAL);
+                    } else if (opt.equals(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN)) {
+                        out.write(Lexer.QUEROPS_LESSTHAN);
+                    } else if (opt.equals(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO)) {
+                        out.write(Lexer.QUEROPS_LESSTHANOREQUAL);
+                    } else if (opt.equals(QueryObjectModelConstants.JCR_OPERATOR_LIKE)) {
+                        out.write(Lexer.QUEROPS_LIKE);
+                    }
+                }
+                out.write("'");
+            }
+        }
         writeValueConstraints(pd.getValueConstraints(), pd.getRequiredType());
     }
 
     /**
      * write default values
-     * @param dva
+     * @param dva default value
+     * @throws IOException if an I/O error occurs
      */
     private void writeDefaultValues(QValue[] dva) throws IOException {
         if (dva != null && dva.length > 0) {
             String delim = " = '";
-            for (int i = 0; i < dva.length; i++) {
+            for (QValue value : dva) {
                 out.write(delim);
                 try {
-                    Value v = ValueFormat.getJCRValue(dva[i], npResolver, valueFactory);
-                    out.write(escape(v.getString()));
+                    String str = ValueFormat.getJCRString(value, npResolver);
+                    out.write(escape(str));
                 } catch (RepositoryException e) {
-                    out.write(escape(dva[i].toString()));
+                    out.write(escape(value.toString()));
                 }
                 out.write("'");
                 delim = ", '";
@@ -304,9 +427,11 @@
 
     /**
      * write value constraints
-     * @param vca
+     * @param vca value constraint
+     * @param type value type
+     * @throws IOException if an I/O error occurs
      */
-    private void writeValueConstraints(String[] vca, int type) throws IOException {
+    private void writeValueConstraints(QValueConstraint[] vca, int type) throws IOException {
         if (vca != null && vca.length > 0) {
             String vc = convertConstraint(vca[0], type);
             out.write(" < '");
@@ -321,29 +446,29 @@
         }
     }
 
-    private String convertConstraint(String vc, int type) {
-        if (type == PropertyType.REFERENCE || type == PropertyType.NAME || type == PropertyType.PATH) {
-            if (type == PropertyType.REFERENCE)
-                type = PropertyType.NAME;
-
-            try {
-                QValue qv = QValueFactoryImpl.getInstance().create(vc, type);
-                vc = ValueFormat.getJCRValue(qv, npResolver, valueFactory).getString();
-            }
-            catch (RepositoryException e) {
-                // ignore -> return unconverted constraint
-            }
+    /**
+     * Converts the constraint to a jcr value
+     * @param vc value constraint string
+     * @param type value type
+     * @return converted value
+     */
+    private String convertConstraint(QValueConstraint vc, int type) {
+        try {
+            ValueConstraint c = ValueConstraint.create(type, vc.getString());
+            return c.getDefinition(npResolver);
+        } catch (InvalidConstraintException e) {
+            // ignore -> return unconverted constraint
+            return vc.getString();
         }
-
-        return vc;
     }
 
     /**
      * write node def
      *
-     * @param nd
+     * @param nd node definition
+     * @throws IOException if an I/O error occurs
      */
-    private void writeNodeDef(QNodeTypeDefinition ntd, QNodeDefinition nd) throws IOException {
+    private void writeNodeDef(QNodeDefinition nd) throws IOException {
         out.write("\n" + INDENT + "+ ");
 
         Name name = nd.getName();
@@ -354,7 +479,6 @@
         }
         writeRequiredTypes(nd.getRequiredPrimaryTypes());
         writeDefaultType(nd.getDefaultPrimaryType());
-        out.write(ntd.getPrimaryItemName() != null && ntd.getPrimaryItemName().equals(nd.getName()) ? " primary" : "");
         if (nd.isMandatory()) {
             out.write(" mandatory");
         }
@@ -375,22 +499,23 @@
 
     /**
      * Write item def name
-     * @param name
-     * @throws IOException
+     * @param name name
+     * @throws IOException if an I/O error occurs
      */
     private void writeItemDefName(Name name) throws IOException {
         out.write(resolve(name));
     }
     /**
      * write required types
-     * @param reqTypes
+     * @param reqTypes required type names
+     * @throws IOException if an I/O error occurs
      */
     private void writeRequiredTypes(Name[] reqTypes) throws IOException {
         if (reqTypes != null && reqTypes.length > 0) {
             String delim = " (";
-            for (int i = 0; i < reqTypes.length; i++) {
+            for (Name reqType : reqTypes) {
                 out.write(delim);
-                out.write(resolve(reqTypes[i]));
+                out.write(resolve(reqType));
                 delim = ", ";
             }
             out.write(")");
@@ -399,7 +524,8 @@
 
     /**
      * write default types
-     * @param defType
+     * @param defType default type name
+     * @throws IOException if an I/O error occurs
      */
     private void writeDefaultType(Name defType) throws IOException {
         if (defType != null && !defType.getLocalName().equals("*")) {
@@ -410,8 +536,9 @@
 
     /**
      * resolve
-     * @param name
+     * @param name name to resolve
      * @return the resolved name
+     * @throws IOException if an I/O error occurs
      */
     private String resolve(Name name) throws IOException {
         if (name == null) {
@@ -451,7 +578,7 @@
 
     /**
      * escape
-     * @param s
+     * @param s string
      * @return the escaped string
      */
     private String escape(String s) {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/Lexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/Lexer.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/Lexer.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/Lexer.java Wed Jul  8 13:57:13 2009
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.spi.commons.nodetype.compact;
 
-import javax.jcr.query.qom.QueryObjectModelConstants;
 import java.io.StreamTokenizer;
 import java.io.Reader;
 import java.io.IOException;
@@ -24,7 +23,7 @@
 import java.util.Arrays;
 
 /**
- * Lexer
+ * Lexer of the CND definition.
  */
 public class Lexer {
     public static final char SINGLE_QUOTE = '\'';
@@ -44,6 +43,7 @@
     public static final String[] MIXIN = new String[]{"mixin", "mix", "m"};
     public static final String[] ABSTRACT = new String[]{"abstract", "abs", "a"};
     public static final String[] NOQUERY = new String[]{"noquery", "nq"};
+    public static final String[] QUERY = new String[]{"query", "q"};
     public static final String[] PRIMARYITEM = new String[]{"primaryitem", "!"};
 
     public static final String[] PRIMARY = new String[]{"primary", "pri", "!"};
@@ -51,18 +51,20 @@
     public static final String[] MANDATORY = new String[]{"mandatory", "man", "m"};
     public static final String[] PROTECTED = new String[]{"protected", "pro", "p"};
     public static final String[] MULTIPLE = new String[]{"multiple", "mul", "*"};
+    public static final String[] SNS = new String[]{"sns", "*", "multiple"};
     public static final String[] QUERYOPS = new String[]{"queryops", "qop"};
     public static final String[] NOFULLTEXT = new String[]{"nofulltext", "nof"};
     public static final String[] NOQUERYORDER = new String[]{"noqueryorder", "nqord"};
 
-    public static final String[] COPY = new String[]{"copy", "Copy", "COPY"};
-    public static final String[] VERSION = new String[]{"version", "Version", "VERSION"};
-    public static final String[] INITIALIZE = new String[]{"initialize", "Initialize", "INITIALIZE"};
-    public static final String[] COMPUTE = new String[]{"compute", "Compute", "COMPUTE"};
-    public static final String[] IGNORE = new String[]{"ignore", "Ignore", "IGNORE"};
-    public static final String[] ABORT = new String[]{"abort", "Abort", "ABORT"};
+    public static final String[] COPY = new String[]{"COPY"};
+    public static final String[] VERSION = new String[]{"VERSION"};
+    public static final String[] INITIALIZE = new String[]{"INITIALIZE"};
+    public static final String[] COMPUTE = new String[]{"COMPUTE"};
+    public static final String[] IGNORE = new String[]{"IGNORE"};
+    public static final String[] ABORT = new String[]{"ABORT"};
 
-    public static final String[] ATTRIBUTE;
+    public static final String[] PROP_ATTRIBUTE;
+    public static final String[] NODE_ATTRIBUTE;
     static {
         ArrayList<String> attr = new ArrayList<String>();
         attr.addAll(Arrays.asList(PRIMARY));
@@ -79,7 +81,20 @@
         attr.addAll(Arrays.asList(COMPUTE));
         attr.addAll(Arrays.asList(IGNORE));
         attr.addAll(Arrays.asList(ABORT));
-        ATTRIBUTE = attr.toArray(new String[attr.size()]);
+        PROP_ATTRIBUTE = attr.toArray(new String[attr.size()]);
+        attr = new ArrayList<String>();
+        attr.addAll(Arrays.asList(PRIMARY));
+        attr.addAll(Arrays.asList(AUTOCREATED));
+        attr.addAll(Arrays.asList(MANDATORY));
+        attr.addAll(Arrays.asList(PROTECTED));
+        attr.addAll(Arrays.asList(SNS));
+        attr.addAll(Arrays.asList(COPY));
+        attr.addAll(Arrays.asList(VERSION));
+        attr.addAll(Arrays.asList(INITIALIZE));
+        attr.addAll(Arrays.asList(COMPUTE));
+        attr.addAll(Arrays.asList(IGNORE));
+        attr.addAll(Arrays.asList(ABORT));
+        NODE_ATTRIBUTE = attr.toArray(new String[attr.size()]);
     }
 
     public static final String QUEROPS_EQUAL = "=";
@@ -90,20 +105,20 @@
     public static final String QUEROPS_GREATERTHANOREQUAL = ">=";
     public static final String QUEROPS_LIKE = "LIKE";
 
-    public static final String[] STRING = {"string", "String", "STRING"};
-    public static final String[] BINARY = {"binary", "Binary", "BINARY"};
-    public static final String[] LONG = {"long", "Long", "LONG"};
-    public static final String[] DOUBLE = {"double", "Double", "DOUBLE"};
-    public static final String[] BOOLEAN = {"boolean", "Boolean", "BOOLEAN"};
-    public static final String[] DATE = {"date", "Date", "DATE"};
-    public static final String[] NAME = {"name", "Name", "NAME"};
-    public static final String[] PATH = {"path", "Path", "PATH"};
-    public static final String[] REFERENCE = {"reference", "Reference", "REFERENCE"};
-    public static final String[] WEAKREFERENCE = {"weakreference", "WeakReference", "WEAKREFERENCE"};
-    public static final String[] URI = {"uri", "Uri", "URI"};
-    public static final String[] DECIMAL = {"decimal", "Decimal", "DECIMAL"};
+    public static final String[] STRING = {"STRING"};
+    public static final String[] BINARY = {"BINARY"};
+    public static final String[] LONG = {"LONG"};
+    public static final String[] DOUBLE = {"DOUBLE"};
+    public static final String[] BOOLEAN = {"BOOLEAN"};
+    public static final String[] DATE = {"DATE"};
+    public static final String[] NAME = {"NAME"};
+    public static final String[] PATH = {"PATH"};
+    public static final String[] REFERENCE = {"REFERENCE"};
+    public static final String[] WEAKREFERENCE = {"WEAKREFERENCE"};
+    public static final String[] URI = {"URI"};
+    public static final String[] DECIMAL = {"DECIMAL"};
 
-    public static final String[] UNDEFINED = new String[]{"undefined", "Undefined", "UNDEFINED", "*"};
+    public static final String[] UNDEFINED = new String[]{"UNDEFINED", "*"};
 
     public static final String EOF = "eof";
 
@@ -112,8 +127,9 @@
     private final String systemId;
 
     /**
-     * Constructor
-     * @param r
+     * Creates an unitialized lexer on top of the given reader.
+     * @param r the reader
+     * @param systemId informational systemid of the given stream
      */
     public Lexer(Reader r, String systemId) {
         this.systemId = systemId;
@@ -149,8 +165,8 @@
     /**
      * getNextToken
      *
-     * @return
-     * @throws ParseException
+     * @return the next token
+     * @throws ParseException if an error during parsing occurs
      */
     public String getNextToken() throws ParseException {
         try {
@@ -172,14 +188,38 @@
         }
     }
 
+    /**
+     * Returns the system id
+     * @return the system id
+     */
+    public String getSystemId() {
+        return systemId;
+    }
+
+    /**
+     * Creates a failure exception including the current line number and systemid.
+     * @param message message
+     * @throws ParseException the created exception
+     */
     public void fail(String message) throws ParseException {
         throw new ParseException(message, st.lineno(), -1, systemId);
     }
 
+    /**
+     * Creates a failure exception including the current line number and systemid.
+     * @param message message
+     * @param e root cause
+     * @throws ParseException the created exception
+     */
     public void fail(String message, Throwable e) throws ParseException {
         throw new ParseException(message, e, st.lineno(), -1, systemId);
     }
 
+    /**
+     * Creates a failure exception including the current line number and systemid.
+     * @param e root cause
+     * @throws ParseException the created exception
+     */
     public void fail(Throwable e) throws ParseException {
         throw new ParseException(e, st.lineno(), -1, systemId);
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/ParseException.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/ParseException.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/ParseException.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/ParseException.java Wed Jul  8 13:57:13 2009
@@ -40,6 +40,9 @@
     /**
      * Constructs a new instance of this class with <code>null</code> as its
      * detail message.
+     * @param lineNumber line number
+     * @param colNumber columns number
+     * @param systemId system id
      */
     public ParseException(int lineNumber, int colNumber, String systemId) {
         super();
@@ -54,6 +57,9 @@
      *
      * @param message the detail message. The detail message is saved for
      *                later retrieval by the {@link #getMessage()} method.
+     * @param lineNumber line number
+     * @param colNumber columns number
+     * @param systemId system id
      */
     public ParseException(String message, int lineNumber, int colNumber, String systemId) {
         super(message);
@@ -68,6 +74,9 @@
      *
      * @param message   the detail message. The detail message is saved for
      *                  later retrieval by the {@link #getMessage()} method.
+     * @param lineNumber line number
+     * @param colNumber columns number
+     * @param systemId system id
      * @param rootCause root failure cause
      */
     public ParseException(String message, Throwable rootCause, int lineNumber, int colNumber, String systemId) {
@@ -80,6 +89,9 @@
     /**
      * Constructs a new instance of this class with the specified root cause.
      *
+     * @param lineNumber line number
+     * @param colNumber columns number
+     * @param systemId system id
      * @param rootCause root failure cause
      */
     public ParseException(Throwable rootCause, int lineNumber, int colNumber, String systemId) {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilder.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilder.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilder.java Wed Jul  8 13:57:13 2009
@@ -18,6 +18,9 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.nodetype.ItemDefinition;
+import javax.jcr.nodetype.NodeTypeDefinition;
 
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QItemDefinition;
@@ -25,8 +28,10 @@
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueConstraint;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException;
+import org.apache.jackrabbit.spi.commons.query.qom.Operator;
 
 /**
  * A builder for {@link QNodeTypeDefinition}s
@@ -44,10 +49,12 @@
      *
      * @param namespaceURI namespace uri
      * @param localName local part
+     * @return the created name
      * @throws IllegalArgumentException if <code>namespaceURI</code> or
      * <code>localName</code> is invalid.
      */
-    public abstract Name createName(String namespaceURI, String localName) throws IllegalArgumentException;
+    public abstract Name createName(String namespaceURI, String localName)
+            throws IllegalArgumentException;
 
     /**
      * A builder for a {@link QNodeTypeDefinition}
@@ -60,17 +67,22 @@
         private Name primaryItemName;
         private QPropertyDefinition[] propertyDefinitions;
         private QNodeDefinition[] childNodeDefinitions;
+        private boolean isAbstract;
+        private boolean isQueryable = true;
 
         /**
          * Set the name of the node type definition being built
-         * @param name
+         * @param name the name
+         * @see NodeTypeDefinition#getName()
          */
         public void setName(Name name) {
             this.name = name;
         }
 
         /**
-         * @return the name of the node type definition being built or <code>null</code> if not set.
+         * @return the name of the node type definition being built or
+         * <code>null</code> if not set.
+         * @see NodeTypeDefinition#getName()
          */
         public Name getName() {
             return name;
@@ -78,53 +90,64 @@
 
         /**
          * Specifies the supertypes of the node type definition being built
-         * @param supertypes
+         * @param supertypes the supertypes
+         * @see NodeTypeDefinition#getDeclaredSupertypeNames()
          */
         public void setSupertypes(Name[] supertypes) {
             this.supertypes = supertypes;
         }
 
         /**
-         * Returns an array containing the names of the supertypes of the node type definition being
-         * built.
+         * Returns an array containing the names of the supertypes of the node
+         * type definition being built.
          *
          * @return an array of supertype names
+         * @see NodeTypeDefinition#getDeclaredSupertypeNames()
          */
         public Name[] getSuperTypes() {
             return supertypes;
         }
 
         /**
-         * @param isMixin true if building a mixin node type definition; false otherwise.
+         * @param isMixin <code>true</code> if building a mixin node type
+         * definition; <code>false</code> otherwise.
+         * @see NodeTypeDefinition#isMixin()
          */
         public void setMixin(boolean isMixin) {
             this.isMixin = isMixin;
         }
 
         /**
-         * @return true if building a mixin node type definition; false otherwise.
+         * @return <code>true</code> if building a mixin node type definition;
+         * <code>false</code> otherwise.
+         * @see NodeTypeDefinition#isMixin()
          */
         public boolean getMixin() {
             return isMixin;
         }
 
         /**
-         * @param isOrderable true if building a node type having orderable child nodes; false
-         *                otherwise.
+         * @param isOrderable <code>true</code> if building a node type having
+         * orderable child nodes; <code>false</code> otherwise.
+         * @see NodeTypeDefinition#hasOrderableChildNodes()
          */
         public void setOrderableChildNodes(boolean isOrderable) {
             this.isOrderable = isOrderable;
         }
 
         /**
-         * @return true if building a node type having orderable child nodes; false otherwise.
+         * @return <code>true</code> if building a node type having orderable
+         * child nodes; <code>false</code> otherwise.
+         * @see NodeTypeDefinition#hasOrderableChildNodes()
          */
         public boolean getOrderableChildNodes() {
             return isOrderable;
         }
 
         /**
-         * @param primaryItemName  the name of the primary item or <code>null</code> if not set.
+         * @param primaryItemName the name of the primary item or
+         * <code>null</code> if not set.
+         * @see NodeTypeDefinition#getPrimaryItemName()
          */
         public void setPrimaryItemName(Name primaryItemName) {
             this.primaryItemName = primaryItemName;
@@ -132,14 +155,48 @@
 
         /**
          * @return the name of the primary item or <code>null</code> if not set.
+         * @see NodeTypeDefinition#getPrimaryItemName()
          */
         public Name getPrimaryItemName() {
             return primaryItemName;
         }
 
         /**
+         * @return <code>true</code> if the node type is abstract.
+         * @see NodeTypeDefinition#isAbstract()
+         */
+        public boolean getAbstract() {
+            return isAbstract;
+        }
+
+        /**
+         * @param isAbstract <code>true</code> if building a node type that is abstract.
+         * @see NodeTypeDefinition#isAbstract()
+         */
+        public void setAbstract(boolean isAbstract) {
+            this.isAbstract = isAbstract;
+        }
+
+        /**
+         * @return <code>true</code> if the node type is queryable
+         * @see NodeTypeDefinition#isQueryable()
+         */
+        public boolean getQueryable() {
+            return isQueryable;
+        }
+
+        /**
+         * @param queryable <code>true</code> if building a node type that is queryable
+         * @see NodeTypeDefinition#isQueryable()
+         */
+        public void setQueryable(boolean queryable) {
+            isQueryable = queryable;
+        }
+
+        /**
          * @param propDefs an array containing the property definitions of the node type definition
          *                being built.
+         * @see NodeTypeDefinition#getDeclaredPropertyDefinitions()
          */
         public void setPropertyDefs(QPropertyDefinition[] propDefs) {
             propertyDefinitions = propDefs;
@@ -148,6 +205,7 @@
         /**
          * @return an array containing the property definitions of the node type definition being
          *         built or <code>null</code> if not set.
+         * @see NodeTypeDefinition#getDeclaredPropertyDefinitions()
          */
         public QPropertyDefinition[] getPropertyDefs() {
             return propertyDefinitions;
@@ -156,6 +214,7 @@
         /**
          * @param childDefs an array containing the child node definitions of the node type
          *                definition being.
+         * @see NodeTypeDefinition#getDeclaredChildNodeDefinitions()
          */
         public void setChildNodeDefs(QNodeDefinition[] childDefs) {
             childNodeDefinitions = childDefs;
@@ -164,6 +223,7 @@
         /**
          * @return an array containing the child node definitions of the node type definition being
          *         built or <code>null</code> if not set.
+         * @see NodeTypeDefinition#getDeclaredChildNodeDefinitions()
          */
         public QNodeDefinition[] getChildNodeDefs() {
             return childNodeDefinitions;
@@ -202,6 +262,7 @@
 
         /**
          * @param name  the name of the child item definition being build
+         * @see ItemDefinition#getName()
          */
         public void setName(Name name) {
             this.name = name;
@@ -209,6 +270,7 @@
 
         /**
          * @return the name of the child item definition being build.
+         * @see ItemDefinition#getName()
          */
         public Name getName() {
             return name;
@@ -216,6 +278,7 @@
 
         /**
          * @param type  the name of the declaring node type.
+         * @see ItemDefinition#getDeclaringNodeType()
          */
         public void setDeclaringNodeType(Name type) {
             declaringType = type;
@@ -223,20 +286,25 @@
 
         /**
          * @return the name of the declaring node type.
+         * @see ItemDefinition#getDeclaringNodeType()
          */
         public Name getDeclaringNodeType() {
             return declaringType;
         }
 
         /**
-         * @param autocreate  true if building a 'autocreate' child item definition, false otherwise.
+         * @param autocreate <code>true</code> if building a 'autocreate' child item 
+         * definition, false otherwise.
+         * @see ItemDefinition#isAutoCreated()
          */
         public void setAutoCreated(boolean autocreate) {
             isAutocreated = autocreate;
         }
 
         /**
-         * @return true if building a 'autocreate' child item definition, false otherwise.
+         * @return <code>true</code> if building a 'autocreate' child item
+         * definition, false otherwise.
+         * @see ItemDefinition#isAutoCreated()
          */
         public boolean getAutoCreated() {
             return isAutocreated;
@@ -244,6 +312,7 @@
 
         /**
          * @param onParent the 'onParentVersion' attribute of the child item definition being built
+         * @see ItemDefinition#getOnParentVersion()
          */
         public void setOnParentVersion(int onParent) {
             onParentVersion = onParent;
@@ -251,34 +320,43 @@
 
         /**
          * @return the 'onParentVersion' attribute of the child item definition being built
+         * @see ItemDefinition#getOnParentVersion()
          */
         public int getOnParentVersion() {
             return onParentVersion;
         }
 
         /**
-         * @param isProtected true if building a 'protected' child item definition, false otherwise.
+         * @param isProtected <code>true</code> if building a 'protected' child
+         * item definition, false otherwise.
+         * @see ItemDefinition#isProtected()
          */
         public void setProtected(boolean isProtected) {
             this.isProtected = isProtected;
         }
 
         /**
-         * @return  true if building a 'protected' child item definition, false otherwise.
+         * @return <code>true</code> if building a 'protected' child item
+         * definition, false otherwise.
+         * @see ItemDefinition#isProtected()
          */
         public boolean getProtected() {
             return isProtected;
         }
 
         /**
-         * @param isMandatory true if building a 'mandatory' child item definition, false otherwise.
+         * @param isMandatory <code>true</code> if building a 'mandatory' child
+         * item definition, false otherwise.
+         * @see ItemDefinition#isMandatory()
          */
         public void setMandatory(boolean isMandatory) {
             this.isMandatory = isMandatory;
         }
 
         /**
-         * @return  true if building a 'mandatory' child item definition, false otherwise.
+         * @return <code>true</code> if building a 'mandatory' child item
+         * definition, false otherwise.
+         * @see ItemDefinition#isMandatory()
          */
         public boolean getMandatory() {
             return isMandatory;
@@ -286,16 +364,22 @@
     }
 
     /**
-     * A builder for a {@link QNodeDefinition}
+     * A builder for a {@link QPropertyDefinition}
+     * @see PropertyDefinition
      */
     public abstract class QPropertyDefinitionBuilder extends QItemDefinitionBuilder {
+
         private int requiredType;
-        private String[] valueConstraints;
+        private QValueConstraint[] valueConstraints;
         private QValue[] defaultValues;
         private boolean isMultiple;
+        private boolean fullTextSearchable = true;
+        private boolean queryOrderable = true;
+        private String[] queryOperators = Operator.getAllQueryOperators();
 
         /**
          * @param type the required type of the property definition being built.
+         * @see PropertyDefinition#getRequiredType()
          */
         public void setRequiredType(int type) {
             requiredType = type;
@@ -303,6 +387,7 @@
 
         /**
          * @return the required type of the property definition being built.
+         * @see PropertyDefinition#getRequiredType()
          */
         public int getRequiredType() {
             return requiredType;
@@ -310,20 +395,23 @@
 
         /**
          * @param constraints array of value constraints of the property definition being built.
+         * @see PropertyDefinition#getValueConstraints()
          */
-        public void setValueConstraints(String[] constraints) {
+        public void setValueConstraints(QValueConstraint[] constraints) {
             valueConstraints = constraints;
         }
 
         /**
          * @return array of value constraints of the property definition being built.
+         * @see PropertyDefinition#getValueConstraints()
          */
-        public String[] getValueConstraints() {
+        public QValueConstraint[] getValueConstraints() {
             return valueConstraints;
         }
 
         /**
          * @param values array of default values of the property definition being built.
+         * @see PropertyDefinition#getDefaultValues()
          */
         public void setDefaultValues(QValue[] values) {
             defaultValues = values;
@@ -332,6 +420,7 @@
         /**
          * @return array of default values of the property definition being built or
          *         <code>null</code> if no default values are defined.
+         * @see PropertyDefinition#getDefaultValues()
          */
         public QValue[] getDefaultValues() {
             return defaultValues;
@@ -339,6 +428,7 @@
 
         /**
          * @param isMultiple true if building a 'multiple' property definition.
+         * @see PropertyDefinition#isMultiple()
          */
         public void setMultiple(boolean isMultiple) {
             this.isMultiple = isMultiple;
@@ -346,30 +436,81 @@
 
         /**
          * @return true if building a 'multiple' property definition.
+         * @see PropertyDefinition#isMultiple()
          */
         public boolean getMultiple() {
             return isMultiple;
         }
 
         /**
+         * @return <code>true</code> if the property is fulltext searchable
+         * @see PropertyDefinition#isFullTextSearchable()
+         */
+        public boolean getFullTextSearchable() {
+            return fullTextSearchable;
+        }
+
+        /**
+         * @param fullTextSearchable <code>true</code> if building a
+         * 'fulltext searchable' property definition
+         * @see PropertyDefinition#isFullTextSearchable()
+         */
+        public void setFullTextSearchable(boolean fullTextSearchable) {
+            this.fullTextSearchable = fullTextSearchable;
+        }
+
+        /**
+         * @return <code>true</code> if the property is orderable in a query
+         * @see PropertyDefinition#isQueryOrderable()
+         */
+        public boolean getQueryOrderable() {
+            return queryOrderable;
+        }
+
+        /**
+         * @param queryOrderable <code>true</code> if the property is orderable
+         *        in a query
+         * @see PropertyDefinition#isQueryOrderable()
+         */
+        public void setQueryOrderable(boolean queryOrderable) {
+            this.queryOrderable = queryOrderable;
+        }
+
+        /**
+         * @return the query operators of the property
+         * @see PropertyDefinition#getAvailableQueryOperators()
+         */
+        public String[] getAvailableQueryOperators() {
+            return queryOperators;
+        }
+
+        /**
+         * @param queryOperators the query operators of the property
+         * @see PropertyDefinition#getAvailableQueryOperators()
+         */
+        public void setAvailableQueryOperators(String[] queryOperators) {
+            this.queryOperators = queryOperators;
+        }
+
+        /**
          * Validate the given <code>constraint</code> and resolve any prefixes.
          *
-         * @param constraint
-         * @param resolver
-         * @return A syntactically valid value constrained which refers to fully qualified names and
-         *         paths only.
-         * @throws InvalidConstraintException if <code>constraint</code> cannot be converted to a
-         *                 valid value constrained.
+         * @param constraint the contraint
+         * @param resolver the resolver
+         * @return A syntactically valid value constrained which refers to
+         * internal names and paths representations only.
+         * @throws InvalidConstraintException if <code>constraint</code> cannot
+         * be converted to a valid value constrained.
          */
-        public abstract String createValueConstraint(String constraint, NamePathResolver resolver)
+        public abstract QValueConstraint createValueConstraint(String constraint, NamePathResolver resolver)
                 throws InvalidConstraintException;
 
         /**
          * Create a new <code>QValue</code> for <code>value</code> of the type this instance
          * represents using the given <code>resolver</code>.
          *
-         * @param value
-         * @param resolver
+         * @param value the value
+         * @param resolver the resolver
          * @return a new <code>QValue</code>.
          * @throws ValueFormatException If the given <code>value</code> cannot be converted to the
          *                 specified <code>type</code>.

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilderImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilderImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/compact/QNodeTypeDefinitionsBuilderImpl.java Wed Jul  8 13:57:13 2009
@@ -25,13 +25,14 @@
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueConstraint;
 import org.apache.jackrabbit.spi.commons.QNodeDefinitionImpl;
 import org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl;
 import org.apache.jackrabbit.spi.commons.QPropertyDefinitionImpl;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 import org.apache.jackrabbit.spi.commons.nodetype.InvalidConstraintException;
-import org.apache.jackrabbit.spi.commons.nodetype.ValueConstraint;
+import org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint;
 import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
 import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 
@@ -72,7 +73,10 @@
             return new QNodeTypeDefinitionImpl(
                     this.getName(),
                     this.getSuperTypes(),
+                    null,
                     this.getMixin(),
+                    this.getAbstract(),
+                    this.getQueryable(),
                     this.getOrderableChildNodes(),
                     this.getPrimaryItemName(),
                     this.getPropertyDefs(),
@@ -93,10 +97,10 @@
                     .getInstance());
         }
 
-        public String createValueConstraint(String constraint, NamePathResolver resolver)
+        public QValueConstraint createValueConstraint(String constraint, NamePathResolver resolver)
                 throws InvalidConstraintException {
 
-            return ValueConstraint.create(getRequiredType(), constraint, resolver).getQualifiedDefinition();
+            return ValueConstraint.create(getRequiredType(), constraint, resolver);
         }
 
         public QPropertyDefinition build() {
@@ -110,7 +114,10 @@
                     this.getDefaultValues(),
                     this.getMultiple(),
                     this.getRequiredType(),
-                    this.getValueConstraints());
+                    this.getValueConstraints(),
+                    this.getAvailableQueryOperators(),
+                    this.getFullTextSearchable(),
+                    this.getQueryOrderable());
         }
 
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/AndQueryNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/AndQueryNode.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/AndQueryNode.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/AndQueryNode.java Wed Jul  8 13:57:13 2009
@@ -22,7 +22,7 @@
  * Implements a query node that defines an AND operation between arbitrary
  * other {@link QueryNode}s.
  */
-public class AndQueryNode extends NAryQueryNode {
+public class AndQueryNode extends NAryQueryNode<QueryNode> {
 
     /**
      * Creates a new <code>AndQueryNode</code> with a <code>parent</code>

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/DefaultQueryNodeFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/DefaultQueryNodeFactory.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/DefaultQueryNodeFactory.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/DefaultQueryNodeFactory.java Wed Jul  8 13:57:13 2009
@@ -16,26 +16,26 @@
  */
 package org.apache.jackrabbit.spi.commons.query;
 
-import java.util.List;
+import java.util.Collection;
 
 import org.apache.jackrabbit.spi.Name;
 
 /**
- * Default implementetation of a {@link QueryNodeFactory}.
+ * Default implementation of a {@link QueryNodeFactory}.
  */
 public class DefaultQueryNodeFactory implements QueryNodeFactory {
 
     /**
-     * List of valid node type names under /jcr:system
+     * Valid node type names under /jcr:system
      */
-    private final List validJcrSystemNodeTypeNames;
+    private final Collection<Name> validJcrSystemNodeTypeNames;
 
     /**
      * Creates a DefaultQueryNodeFactory with the given node types under
      * /jcr:system .
      */
-    public DefaultQueryNodeFactory(List validJcrSystemNodeTypeNames) {
-        super();
+    public DefaultQueryNodeFactory(
+            Collection<Name> validJcrSystemNodeTypeNames) {
         this.validJcrSystemNodeTypeNames = validJcrSystemNodeTypeNames;
     }
 
@@ -89,7 +89,7 @@
      */
     public RelationQueryNode createRelationQueryNode(QueryNode parent,
                                                      int operation) {
-        return new RelationQueryNode(parent, operation);
+        return new RelationQueryNode(parent, operation, this);
     }
 
     /**



Mime
View raw message