You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2006/07/12 15:33:27 UTC
svn commit: r421270 [21/23] - in /jackrabbit/trunk/contrib/spi: ./ commons/
commons/src/ commons/src/main/ commons/src/main/java/
commons/src/main/java/org/ commons/src/main/java/org/apache/
commons/src/main/java/org/apache/jackrabbit/ commons/src/main...
Added: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QItemDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QItemDefinitionImpl.java?rev=421270&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QItemDefinitionImpl.java (added)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QItemDefinitionImpl.java Wed Jul 12 06:33:19 2006
@@ -0,0 +1,238 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * 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.jackrabbit.spi2dav;
+
+import org.w3c.dom.Element;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.NameException;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.QItemDefinition;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.webdav.jcr.nodetype.NodeTypeConstants;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+
+import javax.jcr.version.OnParentVersionAction;
+import javax.jcr.RepositoryException;
+
+/**
+ * This abstract class implements the <code>QItemDefinition</code>
+ * interface and additionally provides setter methods for the
+ * various item definition attributes.
+ */
+public abstract class QItemDefinitionImpl implements QItemDefinition, NodeTypeConstants {
+
+ /**
+ * The special wildcard name used as the name of residual item definitions.
+ */
+ public static final QName ANY_NAME = new QName("", "*");
+
+ /**
+ * The name of the child item.
+ */
+ private final QName name;
+
+ /**
+ * The name of the declaring node type.
+ */
+ private final QName declaringNodeType;
+
+ /**
+ * The 'autoCreated' flag.
+ */
+ private final boolean autoCreated;
+
+ /**
+ * The 'onParentVersion' attribute.
+ */
+ private final int onParentVersion;
+
+ /**
+ * The 'protected' flag.
+ */
+ private final boolean writeProtected;
+
+ /**
+ * The 'mandatory' flag.
+ */
+ private final boolean mandatory;
+
+ /**
+ * HashCode of this object
+ */
+ protected int hashCode = 0;
+
+ /**
+ *
+ * @param itemDefElement
+ * @param nsResolver
+ * @throws RepositoryException
+ */
+ QItemDefinitionImpl(Element itemDefElement, NamespaceResolver nsResolver) throws RepositoryException {
+ this(null, itemDefElement, nsResolver);
+ }
+
+ /**
+ *
+ * @param declaringNodeType
+ * @param itemDefElement
+ * @param nsResolver
+ * @throws RepositoryException
+ */
+ QItemDefinitionImpl(QName declaringNodeType, Element itemDefElement, NamespaceResolver nsResolver)
+ throws RepositoryException {
+ try {
+ // TODO: webdav server sends jcr names -> nsResolver required. improve this.
+ if (DomUtil.hasChildElement(itemDefElement, DECLARINGNODETYPE_ATTRIBUTE, null)) {
+ QName dnt = nsResolver.getQName(itemDefElement.getAttribute(DECLARINGNODETYPE_ATTRIBUTE));
+ if (declaringNodeType != null && !declaringNodeType.equals(dnt)) {
+ throw new RepositoryException("Declaring nodetype mismatch: In element = '" + dnt + "', Declaring nodetype = '" + declaringNodeType + "'");
+ }
+ this.declaringNodeType = dnt;
+ } else {
+ this.declaringNodeType = declaringNodeType;
+ }
+
+ if (itemDefElement.hasAttribute(NAME_ATTRIBUTE)) {
+ String nAttr = itemDefElement.getAttribute(NAME_ATTRIBUTE);
+ if (nAttr.length() > 0) {
+ name = (isAnyName(nAttr)) ? ANY_NAME : nsResolver.getQName(nAttr);
+ } else {
+ name = QName.ROOT;
+ }
+ } else {
+ // TODO: check if correct..
+ name = ANY_NAME;
+ }
+ } catch (NameException e) {
+ throw new RepositoryException(e);
+ }
+
+ if (itemDefElement.hasAttribute(AUTOCREATED_ATTRIBUTE)) {
+ autoCreated = Boolean.valueOf(itemDefElement.getAttribute(AUTOCREATED_ATTRIBUTE)).booleanValue();
+ } else {
+ autoCreated = false;
+ }
+ if (itemDefElement.hasAttribute(MANDATORY_ATTRIBUTE)) {
+ mandatory = Boolean.valueOf(itemDefElement.getAttribute(MANDATORY_ATTRIBUTE)).booleanValue();
+ } else {
+ mandatory = false;
+ }
+ if (itemDefElement.hasAttribute(PROTECTED_ATTRIBUTE)) {
+ writeProtected = Boolean.valueOf(itemDefElement.getAttribute(PROTECTED_ATTRIBUTE)).booleanValue();
+ } else {
+ writeProtected = false;
+ }
+
+ if (itemDefElement.hasAttribute(ONPARENTVERSION_ATTRIBUTE)) {
+ onParentVersion = OnParentVersionAction.valueFromName(itemDefElement.getAttribute(ONPARENTVERSION_ATTRIBUTE));
+ } else {
+ onParentVersion = OnParentVersionAction.COPY;
+ }
+ }
+
+ //--------------------------------------------------------------< QItemDefinition >
+ /**
+ * {@inheritDoc}
+ */
+ public QName getDeclaringNodeType() {
+ return declaringNodeType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public QName getQName() {
+ return name;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isAutoCreated() {
+ return autoCreated;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getOnParentVersion() {
+ return onParentVersion;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isProtected() {
+ return writeProtected;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isMandatory() {
+ return mandatory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean definesResidual() {
+ return name.equals(ANY_NAME);
+ }
+
+ //-------------------------------------------< java.lang.Object overrides >
+ /**
+ * Compares two item definitions for equality. Returns <code>true</code>
+ * if the given object is an item defintion and has the same attributes
+ * as this item definition.
+ *
+ * @param obj the object to compare this item definition with
+ * @return <code>true</code> if the object is equal to this item definition,
+ * <code>false</code> otherwise
+ * @see Object#equals(Object)
+ */
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof QItemDefinition) {
+ QItemDefinition other = (QItemDefinition) obj;
+ return (declaringNodeType == null
+ ? other.getDeclaringNodeType() == null
+ : declaringNodeType.equals(other.getDeclaringNodeType()))
+ && (name == null ? other.getQName() == null : name.equals(other.getQName()))
+ && autoCreated == other.isAutoCreated()
+ && onParentVersion == other.getOnParentVersion()
+ && writeProtected == other.isProtected()
+ && mandatory == other.isMandatory();
+ }
+ return false;
+ }
+
+ /**
+ * See {@link QNodeDefinition#hashCode()} and {@link QPropertyDefinition#hashCode()}.
+ *
+ * @return
+ */
+ public abstract int hashCode();
+
+ //--------------------------------------------------------------------------
+ private boolean isAnyName(String nameAttribute) {
+ return ANY_NAME.getLocalName().equals(nameAttribute);
+ }
+}
Propchange: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QItemDefinitionImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QItemDefinitionImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url
Added: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeDefinitionImpl.java?rev=421270&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeDefinitionImpl.java (added)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeDefinitionImpl.java Wed Jul 12 06:33:19 2006
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * 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.jackrabbit.spi2dav;
+
+import org.w3c.dom.Element;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.NameException;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.apache.jackrabbit.webdav.xml.ElementIterator;
+
+import javax.jcr.RepositoryException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.TreeSet;
+
+/**
+ * This class implements the <code>QNodeDefinition</code> interface and additionally
+ * provides setter methods for the various node definition attributes.
+ */
+public class QNodeDefinitionImpl extends QItemDefinitionImpl implements QNodeDefinition {
+
+ /**
+ * The name of the default primary type.
+ */
+ private final QName defaultPrimaryType;
+
+ /**
+ * The names of the required primary types.
+ */
+ private final QName[] requiredPrimaryTypes;
+
+ /**
+ * The 'allowsSameNameSiblings' flag.
+ */
+ private final boolean allowsSameNameSiblings;
+
+ /**
+ * Create a new <code>QNodeDefinitionImpl</code>
+ *
+ * @param declaringNodeType
+ * @param ndefElement
+ * @param nsResolver
+ * @throws RepositoryException
+ */
+ QNodeDefinitionImpl(QName declaringNodeType, Element ndefElement, NamespaceResolver nsResolver)
+ throws RepositoryException {
+ super(declaringNodeType, ndefElement, nsResolver);
+ // TODO: webdav server sends jcr names -> nsResolver required. improve this.
+ // NOTE: the server should send the namespace-mappings as addition ns-defininitions
+ try {
+
+ if (ndefElement.hasAttribute(DEFAULTPRIMARYTYPE_ATTRIBUTE)) {
+ defaultPrimaryType = nsResolver.getQName(ndefElement.getAttribute(DEFAULTPRIMARYTYPE_ATTRIBUTE));
+ } else {
+ defaultPrimaryType = null;
+ }
+
+ Element reqPrimaryTypes = DomUtil.getChildElement(ndefElement, REQUIREDPRIMARYTYPES_ELEMENT, null);
+ if (reqPrimaryTypes != null) {
+ List qNames = new ArrayList();
+ ElementIterator it = DomUtil.getChildren(reqPrimaryTypes, REQUIREDPRIMARYTYPE_ELEMENT, null);
+ while (it.hasNext()) {
+ qNames.add(nsResolver.getQName(DomUtil.getTextTrim(it.nextElement())));
+ }
+ requiredPrimaryTypes = (QName[]) qNames.toArray(new QName[qNames.size()]);
+ } else {
+ requiredPrimaryTypes = new QName[] { QName.NT_BASE };
+ }
+
+ if (ndefElement.hasAttribute(SAMENAMESIBLINGS_ATTRIBUTE)) {
+ allowsSameNameSiblings = Boolean.valueOf(ndefElement.getAttribute(SAMENAMESIBLINGS_ATTRIBUTE)).booleanValue();
+ } else {
+ allowsSameNameSiblings = false;
+ }
+ } catch (NameException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ //--------------------------------------------------------------< QNodeDefinition >
+ /**
+ * {@inheritDoc}
+ */
+ public QName getDefaultPrimaryType() {
+ return defaultPrimaryType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public QName[] getRequiredPrimaryTypes() {
+ return requiredPrimaryTypes;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean allowsSameNameSiblings() {
+ return allowsSameNameSiblings;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return always <code>true</code>
+ */
+ public boolean definesNode() {
+ return true;
+ }
+
+ //-------------------------------------------< java.lang.Object overrides >
+ /**
+ * Compares two node definitions for equality. Returns <code>true</code>
+ * if the given object is a node defintion and has the same attributes
+ * as this node definition.
+ *
+ * @param obj the object to compare this node definition with
+ * @return <code>true</code> if the object is equal to this node definition,
+ * <code>false</code> otherwise
+ * @see Object#equals(Object)
+ */
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof QNodeDefinition) {
+ QNodeDefinition other = (QNodeDefinition) obj;
+ return super.equals(obj)
+ && Arrays.equals(requiredPrimaryTypes, other.getRequiredPrimaryTypes())
+ && (defaultPrimaryType == null
+ ? other.getDefaultPrimaryType() == null
+ : defaultPrimaryType.equals(other.getDefaultPrimaryType()))
+ && allowsSameNameSiblings == other.allowsSameNameSiblings();
+ }
+ return false;
+ }
+
+ /**
+ * Overwrites {@link QItemDefinitionImpl#hashCode()}.
+ *
+ * @return
+ */
+ public int hashCode() {
+ if (hashCode == 0) {
+ // build hashCode (format: <declaringNodeType>/<name>/<requiredPrimaryTypes>)
+ StringBuffer sb = new StringBuffer();
+
+ if (getDeclaringNodeType() != null) {
+ sb.append(getDeclaringNodeType().toString());
+ sb.append('/');
+ }
+ if (definesResidual()) {
+ sb.append('*');
+ } else {
+ sb.append(getQName().toString());
+ }
+ sb.append('/');
+ // set of required node type names, sorted in ascending order
+ TreeSet set = new TreeSet();
+ QName[] names = getRequiredPrimaryTypes();
+ for (int i = 0; i < names.length; i++) {
+ set.add(names[i]);
+ }
+ sb.append(set.toString());
+
+ hashCode = sb.toString().hashCode();
+ }
+ return hashCode;
+ }
+}
Propchange: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeDefinitionImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeDefinitionImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url
Added: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java?rev=421270&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java (added)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java Wed Jul 12 06:33:19 2006
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * 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.jackrabbit.spi2dav;
+
+import org.w3c.dom.Element;
+import org.apache.jackrabbit.webdav.jcr.nodetype.NodeTypeConstants;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.apache.jackrabbit.webdav.xml.ElementIterator;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.NameException;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.PropertyType;
+import java.util.Arrays;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A <code>QNodeTypeDefinitionImpl</code> holds the definition of a node type.
+ */
+public class QNodeTypeDefinitionImpl implements QNodeTypeDefinition, NodeTypeConstants {
+
+ private static Logger log = LoggerFactory.getLogger(QNodeTypeDefinitionImpl.class);
+
+ private final QName name;
+ private final QName[] supertypes;
+ private final boolean mixin;
+ private final boolean orderableChildNodes;
+ private final QName primaryItemName;
+ private final QPropertyDefinition[] propDefs;
+ private final QNodeDefinition[] nodeDefs;
+ private Set dependencies;
+
+ /**
+ * Default constructor.
+ */
+ public QNodeTypeDefinitionImpl(Element ntdElement, NamespaceResolver nsResolver)
+ throws RepositoryException {
+ // TODO: webdav-server currently sends jcr-names -> conversion needed
+ // NOTE: the server should send the namespace-mappings as addition ns-defininitions
+ try {
+ if (ntdElement.hasAttribute(NAME_ATTRIBUTE)) {
+ name = nsResolver.getQName(ntdElement.getAttribute(NAME_ATTRIBUTE));
+ } else {
+ name = null;
+ }
+
+ if (ntdElement.hasAttribute(PRIMARYITEMNAME_ATTRIBUTE)) {
+ primaryItemName = nsResolver.getQName(ntdElement.getAttribute(PRIMARYITEMNAME_ATTRIBUTE));
+ } else {
+ primaryItemName = null;
+ }
+
+ Element child = DomUtil.getChildElement(ntdElement, SUPERTYPES_ELEMENT, null);
+ if (child != null) {
+ ElementIterator stIter = DomUtil.getChildren(child, SUPERTYPE_ELEMENT, null);
+ List qNames = new ArrayList();
+ while (stIter.hasNext()) {
+ QName st = nsResolver.getQName(DomUtil.getTextTrim(stIter.nextElement()));
+ qNames.add(st);
+ }
+ supertypes = (QName[]) qNames.toArray(new QName[qNames.size()]);
+ } else {
+ supertypes = QName.EMPTY_ARRAY;
+ }
+ if (ntdElement.hasAttribute(ISMIXIN_ATTRIBUTE)) {
+ mixin = Boolean.valueOf(ntdElement.getAttribute(ISMIXIN_ATTRIBUTE)).booleanValue();
+ } else {
+ mixin = false;
+ }
+ if (ntdElement.hasAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)) {
+ orderableChildNodes = Boolean.valueOf(ntdElement.getAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)).booleanValue();
+ } else {
+ orderableChildNodes = false;
+ }
+
+ // nodeDefinitions
+ ElementIterator it = DomUtil.getChildren(ntdElement, CHILDNODEDEFINITION_ELEMENT, null);
+ List itemDefs = new ArrayList();
+ while (it.hasNext()) {
+ itemDefs.add(new QNodeDefinitionImpl(name, it.nextElement(), nsResolver));
+ }
+ nodeDefs = (QNodeDefinition[]) itemDefs.toArray(new QNodeDefinition[itemDefs.size()]);
+
+
+ // propertyDefinitions
+ it = DomUtil.getChildren(ntdElement, PROPERTYDEFINITION_ELEMENT, null);
+ itemDefs = new ArrayList();
+ while (it.hasNext()) {
+ itemDefs.add(new QPropertyDefinitionImpl(name, it.nextElement(), nsResolver));
+ }
+ propDefs = (QPropertyDefinition[]) itemDefs.toArray(new QPropertyDefinition[itemDefs.size()]);
+ } catch (NameException e) {
+ log.error(e.getMessage());
+ throw new RepositoryException(e);
+ }
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof QNodeTypeDefinition) {
+ QNodeTypeDefinition other = (QNodeTypeDefinition) obj;
+ return (name == null ? other.getQName() == null : name.equals(other.getQName()))
+ && (primaryItemName == null ? other.getPrimaryItemName() == null : primaryItemName.equals(other.getPrimaryItemName()))
+ && Arrays.equals(supertypes, other.getSupertypes())
+ && mixin == other.isMixin()
+ && orderableChildNodes == other.hasOrderableChildNodes()
+ && Arrays.equals(propDefs, other.getPropertyDefs())
+ && Arrays.equals(nodeDefs, other.getChildNodeDefs());
+ }
+ return false;
+ }
+
+ /**
+ * Always returns 0
+ *
+ * @see Object#hashCode()
+ */
+ public int hashCode() {
+ // TODO: can be calculated for the definition is immutable
+ return 0;
+ }
+
+ /**
+ * Returns the name of the node type being defined or
+ * <code>null</code> if not set.
+ *
+ * @return the name of the node type or <code>null</code> if not set.
+ */
+ public QName getQName() {
+ return name;
+ }
+
+ /**
+ * Returns an array containing the names of the supertypes or
+ * <code>null</code> if not set.
+ *
+ * @return an array listing the names of the supertypes or
+ * <code>null</code> if not set.
+ */
+ public QName[] getSupertypes() {
+ return supertypes;
+ }
+
+ /**
+ * Returns the value of the mixin flag.
+ *
+ * @return true if this is a mixin node type; false otherwise.
+ */
+ public boolean isMixin() {
+ return mixin;
+ }
+
+ /**
+ * Returns the value of the orderableChildNodes flag.
+ *
+ * @return true if nodes of this node type can have orderable child nodes; false otherwise.
+ */
+ public boolean hasOrderableChildNodes() {
+ return orderableChildNodes;
+ }
+
+ /**
+ * Returns the name of the primary item (one of the child items of the
+ * node's of this node type) or <code>null</code> if not set.
+ *
+ * @return the name of the primary item or <code>null</code> if not set.
+ */
+ public QName getPrimaryItemName() {
+ return primaryItemName;
+ }
+
+ /**
+ * Returns an array containing the property definitions or
+ * <code>null</code> if not set.
+ *
+ * @return an array containing the property definitions or
+ * <code>null</code> if not set.
+ */
+ public QPropertyDefinition[] getPropertyDefs() {
+ return propDefs;
+ }
+
+ /**
+ * Returns an array containing the child node definitions or
+ * <code>null</code> if not set.
+ *
+ * @return an array containing the child node definitions or
+ * <code>null</code> if not set.
+ */
+ public QNodeDefinition[] getChildNodeDefs() {
+ return nodeDefs;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public Collection getDependencies() {
+ if (dependencies == null) {
+ dependencies = new HashSet();
+ // supertypes
+ for (int i = 0; i < supertypes.length; i++) {
+ dependencies.add(supertypes[i]);
+ }
+ // child node definitions
+ for (int i = 0; i < nodeDefs.length; i++) {
+ // default primary type
+ QName ntName = nodeDefs[i].getDefaultPrimaryType();
+ if (ntName != null && !name.equals(ntName)) {
+ dependencies.add(ntName);
+ }
+ // required primary type
+ QName[] ntNames = nodeDefs[i].getRequiredPrimaryTypes();
+ for (int j = 0; j < ntNames.length; j++) {
+ if (ntNames[j] != null && !name.equals(ntNames[j])) {
+ dependencies.add(ntNames[j]);
+ }
+ }
+ }
+ // property definitions
+ for (int i = 0; i < propDefs.length; i++) {
+ // REFERENCE value constraints
+ if (propDefs[i].getRequiredType() == PropertyType.REFERENCE) {
+ String[] ca = propDefs[i].getValueConstraints();
+ if (ca != null) {
+ for (int j = 0; j < ca.length; j++) {
+ QName ntName = QName.valueOf(ca[j]);
+ if (!name.equals(ntName)) {
+ dependencies.add(ntName);
+ }
+ }
+ }
+ }
+ }
+ }
+ return dependencies;
+ }
+}
Propchange: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url
Added: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QPropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QPropertyDefinitionImpl.java?rev=421270&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QPropertyDefinitionImpl.java (added)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QPropertyDefinitionImpl.java Wed Jul 12 06:33:19 2006
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * 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.jackrabbit.spi2dav;
+
+import org.w3c.dom.Element;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.apache.jackrabbit.webdav.xml.ElementIterator;
+import org.apache.jackrabbit.value.ValueFormat;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.ArrayList;
+import java.io.InputStream;
+
+/**
+ * This class implements the <code>QPropertyDefinition</code> interface and additionally
+ * provides setter methods for the various property definition attributes.
+ */
+public class QPropertyDefinitionImpl extends QItemDefinitionImpl implements QPropertyDefinition {
+
+ /**
+ * The required type.
+ */
+ private final int requiredType;
+
+ /**
+ * The value constraints.
+ */
+ private final String[] valueConstraints;
+
+ /**
+ * The default values.
+ */
+ private final String[] defaultValues;
+
+ /**
+ * The 'multiple' flag
+ */
+ private final boolean multiple;
+
+ /**
+ * Default constructor.
+ */
+ QPropertyDefinitionImpl(QName declaringNodeType, Element pdefElement, NamespaceResolver nsResolver)
+ throws RepositoryException {
+ // TODO: webdav server sends jcr names -> nsResolver required. improve this.
+ // NOTE: the server should send the namespace-mappings as addition ns-defininitions
+ super(declaringNodeType, pdefElement, nsResolver);
+
+ if (pdefElement.hasAttribute(REQUIREDTYPE_ATTRIBUTE)) {
+ requiredType = PropertyType.valueFromName(pdefElement.getAttribute(REQUIREDTYPE_ATTRIBUTE));
+ } else {
+ requiredType = PropertyType.UNDEFINED;
+ }
+
+ if (pdefElement.hasAttribute(MULTIPLE_ATTRIBUTE)) {
+ multiple = Boolean.valueOf(pdefElement.getAttribute(MULTIPLE_ATTRIBUTE)).booleanValue();
+ } else {
+ multiple = false;
+ }
+
+ Element child = DomUtil.getChildElement(pdefElement, DEFAULTVALUES_ELEMENT, null);
+ if (child == null) {
+ defaultValues = new String[0];
+ } else {
+ List vs = new ArrayList();
+ ElementIterator it = DomUtil.getChildren(child, DEFAULTVALUE_ELEMENT, null);
+ while (it.hasNext()) {
+ String qValue = ValueFormat.getQValue(DomUtil.getText(it.nextElement()), requiredType, nsResolver).getString();
+ vs.add(qValue);
+ }
+ defaultValues = (String[]) vs.toArray(new String[vs.size()]);
+ }
+
+ child = DomUtil.getChildElement(pdefElement, VALUECONSTRAINTS_ELEMENT, null);
+ if (child == null) {
+ valueConstraints = new String[0];
+ } else {
+ List vc = new ArrayList();
+ ElementIterator it = DomUtil.getChildren(child, VALUECONSTRAINT_ELEMENT, null);
+ while (it.hasNext()) {
+ int constType = (requiredType == PropertyType.REFERENCE) ? PropertyType.NAME : requiredType;
+ String qValue = ValueFormat.getQValue(DomUtil.getText(it.nextElement()), constType, nsResolver).getString();
+ vc.add(qValue);
+ }
+ valueConstraints = (String[]) vc.toArray(new String[vc.size()]);
+ }
+ }
+
+ //------------------------------------------------< QPropertyDefinition >---
+ /**
+ * {@inheritDoc}
+ */
+ public int getRequiredType() {
+ return requiredType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String[] getValueConstraints() {
+ return valueConstraints;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String[] getDefaultValues() {
+ return defaultValues;
+ }
+
+ public InputStream[] getDefaultValuesAsStream() {
+ // todo: implementation missing
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isMultiple() {
+ return multiple;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return always <code>false</code>
+ */
+ public boolean definesNode() {
+ return false;
+ }
+
+ //-------------------------------------------< java.lang.Object overrides >
+ /**
+ * Compares two property definitions for equality. Returns <code>true</code>
+ * if the given object is a property defintion and has the same attributes
+ * as this property definition.
+ *
+ * @param obj the object to compare this property definition with
+ * @return <code>true</code> if the object is equal to this property definition,
+ * <code>false</code> otherwise
+ * @see Object#equals(Object)
+ */
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof QPropertyDefinition) {
+ QPropertyDefinition other = (QPropertyDefinition) obj;
+ return super.equals(obj)
+ && requiredType == other.getRequiredType()
+ && Arrays.equals(valueConstraints, other.getValueConstraints())
+ && Arrays.equals(defaultValues, other.getDefaultValues())
+ && multiple == other.isMultiple();
+ }
+ return false;
+ }
+
+ /**
+ * Overwrites {@link QItemDefinitionImpl#hashCode()}.
+ *
+ * @return
+ */
+ public int hashCode() {
+ if (hashCode == 0) {
+ // build hashCode (format: <declaringNodeType>/<name>/<requiredType>/<multiple>)
+ StringBuffer sb = new StringBuffer();
+
+ sb.append(getDeclaringNodeType().toString());
+ sb.append('/');
+ if (definesResidual()) {
+ sb.append('*');
+ } else {
+ sb.append(getQName().toString());
+ }
+ sb.append('/');
+ sb.append(getRequiredType());
+ sb.append('/');
+ sb.append(isMultiple() ? 1 : 0);
+
+ hashCode = sb.toString().hashCode();
+ }
+ return hashCode;
+ }
+}
Propchange: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QPropertyDefinitionImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QPropertyDefinitionImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url
Added: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java?rev=421270&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java (added)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java Wed Jul 12 06:33:19 2006
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.jackrabbit.spi2dav;
+
+import org.apache.jackrabbit.webdav.property.DavPropertySet;
+import org.apache.jackrabbit.webdav.property.DavProperty;
+import org.apache.jackrabbit.webdav.jcr.search.SearchResultProperty;
+import org.apache.jackrabbit.webdav.MultiStatusResponse;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.MultiStatus;
+import org.apache.jackrabbit.util.ISO9075;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.NameFormat;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.NameException;
+import org.apache.jackrabbit.spi.QueryInfo;
+import org.apache.jackrabbit.spi.IdIterator;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.SessionInfo;
+import org.apache.jackrabbit.value.ValueFormat;
+import org.apache.jackrabbit.value.QValue;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.PropertyType;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.AbstractCollection;
+import java.util.NoSuchElementException;
+import java.util.Map;
+import java.util.LinkedHashMap;
+
+/**
+ * <code>QueryInfoImpl</code>...
+ */
+public class QueryInfoImpl implements QueryInfo {
+
+ /**
+ * Logger instance for this class.
+ */
+ private static final Logger log = LoggerFactory.getLogger(QueryInfoImpl.class);
+
+ private final Map results = new LinkedHashMap();
+
+ private final QName[] columnNames;
+ private final NamespaceResolver nsResolver;
+
+ public QueryInfoImpl(MultiStatus ms, SessionInfo sessionInfo, URIResolver uriResolver, NamespaceResolver nsResolver) throws RepositoryException {
+ this.nsResolver = nsResolver;
+
+ String responseDescription = ms.getResponseDescription();
+ if (responseDescription != null) {
+ String[] cn = responseDescription.split(" ");
+ this.columnNames = new QName[cn.length];
+ for (int i = 0; i < cn.length; i++) {
+ String jcrColumnNames = ISO9075.decode(cn[i]);
+ try {
+ columnNames[i] = NameFormat.parse(jcrColumnNames, nsResolver);
+ } catch (NameException e) {
+ throw new RepositoryException(e);
+ }
+ }
+ } else {
+ throw new RepositoryException("Missing column infos: Unable to build QueryInfo object.");
+ }
+
+ MultiStatusResponse[] responses = ms.getResponses();
+ for (int i = 0; i < responses.length; i++) {
+ MultiStatusResponse response = responses[i];
+ String href = response.getHref();
+ DavPropertySet okSet = response.getProperties(DavServletResponse.SC_OK);
+
+ DavProperty davProp = okSet.get(SearchResultProperty.SEARCH_RESULT_PROPERTY);
+ SearchResultProperty resultProp = new SearchResultProperty(davProp);
+
+ NodeId nodeId = uriResolver.getNodeId(href, sessionInfo);
+ this.results.put(nodeId, resultProp);
+ }
+ }
+
+ public IdIterator getNodeIds() {
+ return new IteratorHelper(new AbstractCollection() {
+ public int size() {
+ return results.size();
+ }
+
+ public Iterator iterator() {
+ return results.keySet().iterator();
+ }
+ });
+ }
+
+ public QName[] getColumnNames() {
+ return columnNames;
+ }
+
+ public String[] getValues(NodeId nodeId) {
+ SearchResultProperty prop = (SearchResultProperty) results.get(nodeId);
+ if (prop == null) {
+ throw new NoSuchElementException();
+ } else {
+ Value[] values = prop.getValues();
+ String[] ret = new String[values.length];
+ for (int i = 0; i < values.length; i++) {
+ try {
+ QValue qValue = (values[i] == null) ? null : ValueFormat.getQValue(values[i], nsResolver);
+ ret[i] = qValue.getString();
+ } catch (RepositoryException e) {
+ // should not occur
+ log.error("malformed value: " + values[i].toString());
+ }
+ }
+ return ret;
+ }
+ }
+
+ public InputStream[] getValuesAsStream(NodeId nodeId) {
+ SearchResultProperty prop = (SearchResultProperty) results.get(nodeId);
+ if (prop == null) {
+ throw new NoSuchElementException();
+ } else {
+ Value[] values = prop.getValues();
+ InputStream[] ret = new InputStream[values.length];
+ for (int i = 0; i < ret.length; i++) {
+ try {
+ // make sure we return the qualified value if the type is
+ // name or path.
+ if (values[i].getType() == PropertyType.NAME || values[i].getType() == PropertyType.PATH) {
+ ret[i] = ValueFormat.getQValue(values[i], nsResolver).getStream();
+ } else {
+ ret[i] = values[i].getStream();
+ }
+ } catch (RepositoryException e) {
+ // ignore this value
+ log.warn("unable to get stream value: " + values[i].toString());
+ }
+ }
+ return ret;
+ }
+ }
+
+}
Propchange: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url