stefan      2004/07/07 09:04:29

  Added:       proposals/jcrri/src/org/apache/slide/jcr/core/nodetype
                        NodeDefId.java PropDefId.java
  Log:
  jcrri
  
  Revision  Changes    Path
  1.1                  
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype/NodeDefId.java
  
  Index: NodeDefId.java
  ===================================================================
  /*
   * $Id: NodeDefId.java,v 1.1 2004/07/07 16:04:29 stefan Exp $
   *
   * Copyright 2002-2004 Day Management AG, Switzerland.
   *
   * Licensed under the Day RI License, Version 2.0 (the "License"),
   * as a reference implementation of the following specification:
   *
   *   Content Repository API for Java Technology, revision 0.13
   *        <http://www.jcp.org/en/jsr/detail?id=170>
   *
   * You may not use this file except in compliance with the License.
   * You may obtain a copy of the License files at
   *
   *     http://www.day.com/content/en/licenses/day-ri-license-2.0
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.slide.jcr.core.nodetype;
  
  import org.apache.slide.jcr.core.QName;
  
  import java.io.Serializable;
  import java.util.TreeSet;
  
  /**
   * <code>NodeDefId</code> uniquely identifies a <code>ChildNodeDef</code> in the
   * node type registry.
   *
   * @author Stefan Guggisberg
   * @version $Revision: 1.1 $
   */
  public class NodeDefId implements Serializable {
  
      static final long serialVersionUID = 7020286139887664713L;
  
      private final int id;
  
      public NodeDefId(ChildNodeDef def) {
        if (def == null) {
            throw new IllegalArgumentException("ChildNodeDef argument can not be 
null");
        }
        // build key (format: <declaring node type>/<name>/<default node 
type>/<required node types>)
        StringBuffer sb = new StringBuffer();
  
        sb.append(def.getDeclaringNodeType().toString());
        sb.append('/');
        if (def.getName() == null) {
            sb.append('*');
        } else {
            sb.append(def.getName().toString());
        }
        sb.append('/');
        if (def.getDefaultPrimaryType() != null) {
            sb.append(def.getDefaultPrimaryType());
        }
        sb.append('/');
        // set of required node type names, sorted in ascending order
        TreeSet set = new TreeSet();
        QName[] names = def.getRequiredPrimaryTypes();
        for (int i = 0; i < names.length; i++) {
            set.add(names[i]);
        }
        sb.append(set.toString());
  
        id = sb.toString().hashCode();
      }
  
      private NodeDefId(int id) {
        this.id = id;
      }
  
      /**
       * Returns a <code>NodeDefId</code> holding the value of the specified
       * string. The string must be in the format returned by the
       * <code>NodeDefId.toString()</code> method.
       *
       * @param s a <code>String</code> containing the <code>NodeDefId</code>
       *          representation to be parsed.
       * @return the <code>NodeDefId</code> represented by the argument
       * @throws IllegalArgumentException if the specified string can not be parsed
       *                                  as a <code>NodeDefId</code>.
       * @see #toString()
       */
      public static NodeDefId valueOf(String s) {
        if (s == null) {
            throw new IllegalArgumentException("invalid NodeDefId literal");
        }
        return new NodeDefId(Integer.parseInt(s));
      }
  
      public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof NodeDefId) {
            NodeDefId other = (NodeDefId) obj;
            return id == other.id;
        }
        return false;
      }
  
      public String toString() {
        return Integer.toString(id);
      }
  
      public int hashCode() {
        return id;
      }
  }
  
  
  
  1.1                  
jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/nodetype/PropDefId.java
  
  Index: PropDefId.java
  ===================================================================
  /*
   * $Id: PropDefId.java,v 1.1 2004/07/07 16:04:29 stefan Exp $
   *
   * Copyright 2002-2004 Day Management AG, Switzerland.
   *
   * Licensed under the Day RI License, Version 2.0 (the "License"),
   * as a reference implementation of the following specification:
   *
   *   Content Repository API for Java Technology, revision 0.13
   *        <http://www.jcp.org/en/jsr/detail?id=170>
   *
   * You may not use this file except in compliance with the License.
   * You may obtain a copy of the License files at
   *
   *     http://www.day.com/content/en/licenses/day-ri-license-2.0
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.slide.jcr.core.nodetype;
  
  import java.io.Serializable;
  
  /**
   * <code>PropDefId</code> uniquely identifies a <code>PropDef</code> in the
   * node type registry.
   *
   * @author Stefan Guggisberg
   * @version $Revision: 1.1 $
   */
  public class PropDefId implements Serializable {
  
      static final long serialVersionUID = 3675238890036653593L;
  
      private final int id;
  
      public PropDefId(PropDef def) {
        if (def == null) {
            throw new IllegalArgumentException("PropDef argument can not be null");
        }
        // build key (format: <declaring node type>/<name>/<type>/<multiple flag>)
        StringBuffer sb = new StringBuffer();
  
        sb.append(def.getDeclaringNodeType().toString());
        sb.append('/');
        if (def.getName() == null) {
            sb.append('*');
        } else {
            sb.append(def.getName().toString());
        }
        sb.append('/');
        sb.append(def.getRequiredType());
        sb.append('/');
        sb.append(def.isMultiple() ? 1 : 0);
  
        id = sb.toString().hashCode();
      }
  
      private PropDefId(int id) {
        this.id = id;
      }
  
      /**
       * Returns a <code>PropDefId</code> holding the value of the specified
       * string. The string must be in the format returned by the
       * <code>PropDefId.toString()</code> method.
       *
       * @param s a <code>String</code> containing the <code>PropDefId</code>
       *          representation to be parsed.
       * @return the <code>PropDefId</code> represented by the argument
       * @throws IllegalArgumentException if the specified string can not be parsed
       *                                  as a <code>PropDefId</code>.
       * @see #toString()
       */
      public static PropDefId valueOf(String s) {
        if (s == null) {
            throw new IllegalArgumentException("invalid PropDefId literal");
        }
        return new PropDefId(Integer.parseInt(s));
      }
  
      public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof PropDefId) {
            PropDefId other = (PropDefId) obj;
            return id == other.id;
        }
        return false;
      }
  
      public String toString() {
        return Integer.toString(id);
      }
  
      public int hashCode() {
        return id;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to