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/11/01 10:07:05 UTC
svn commit: r469831 - in
/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav:
QNodeTypeDefinitionImpl.java RepositoryServiceImpl.java
Author: angela
Date: Wed Nov 1 01:07:04 2006
New Revision: 469831
URL: http://svn.apache.org/viewvc?view=rev&rev=469831
Log:
work in progress
- adjust nodetypedef according to API
- rs: retrieve descriptors once.
- rs: cache client by sessionInfo
Modified:
jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java
jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Modified: 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?view=diff&rev=469831&r1=469830&r2=469831
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java Wed Nov 1 01:07:04 2006
@@ -120,106 +120,63 @@
}
}
- 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;
- }
-
+ //------------------------------------------------< QNodeTypeDefinition >---
/**
- * 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.
+ * @see QNodeTypeDefinition#getQName()
*/
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.
+ * @see QNodeTypeDefinition#getSupertypes()
*/
public QName[] getSupertypes() {
- return supertypes;
+ if (supertypes.length > 0
+ || isMixin() || QName.NT_BASE.equals(getQName())) {
+ return supertypes;
+ } else {
+ return new QName[] { QName.NT_BASE };
+ }
}
/**
- * Returns the value of the mixin flag.
- *
- * @return true if this is a mixin node type; false otherwise.
+ * @see QNodeTypeDefinition#isMixin()
*/
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.
+ * @see QNodeTypeDefinition#hasOrderableChildNodes()
*/
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.
+ * @see QNodeTypeDefinition#getPrimaryItemName()
*/
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.
+ * @see QNodeTypeDefinition#getPropertyDefs()
*/
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.
+ * @see QNodeTypeDefinition#getChildNodeDefs()
*/
public QNodeDefinition[] getChildNodeDefs() {
return nodeDefs;
}
/**
- * @inheritDoc
+ * @see QNodeTypeDefinition#getDependencies()
*/
public Collection getDependencies() {
if (dependencies == null) {
@@ -260,5 +217,36 @@
}
}
return dependencies;
+ }
+
+ //-------------------------------------------------------------< Object >---
+ /**
+ * @see Object#equals(Object)
+ */
+ 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;
}
}
Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?view=diff&rev=469831&r1=469830&r2=469831
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java Wed Nov 1 01:07:04 2006
@@ -186,6 +186,8 @@
private final HostConfiguration hostConfig;
private final HashMap clients = new HashMap();
+ private Map descriptors;
+
public RepositoryServiceImpl(String uri, IdFactory idFactory, ValueFactory valueFactory) throws RepositoryException {
if (uri == null || "".equals(uri)) {
throw new RepositoryException("Invalid repository uri '" + uri + "'.");
@@ -245,9 +247,9 @@
return requestURI.equals(href);
}
- private HttpClient getClient(org.apache.commons.httpclient.Credentials credentials) {
- if (clients.containsKey(credentials)) {
- return (HttpClient) clients.get(credentials);
+ HttpClient getClient(SessionInfo sessionInfo) throws RepositoryException {
+ if (clients.containsKey(sessionInfo)) {
+ return (HttpClient) clients.get(sessionInfo);
} else {
HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager());
client.setHostConfiguration(hostConfig);
@@ -255,18 +257,18 @@
client.getParams().setAuthenticationPreemptive(true);
// NOTE: null credentials only work if 'missing-auth-mapping' param is
// set on the server
- client.getState().setCredentials(AuthScope.ANY, credentials);
+ org.apache.commons.httpclient.Credentials creds = null;
+ if (sessionInfo != null) {
+ checkSessionInfo(sessionInfo);
+ creds = ((SessionInfoImpl) sessionInfo).getCredentials().getCredentials();
+ }
+ client.getState().setCredentials(AuthScope.ANY, creds);
- clients.put(credentials, client);
+ clients.put(sessionInfo, client);
return client;
}
}
- HttpClient getClient(SessionInfo sessionInfo) throws RepositoryException {
- checkSessionInfo(sessionInfo);
- return getClient(((SessionInfoImpl) sessionInfo).getCredentials().getCredentials());
- }
-
private String getItemUri(ItemId itemId, SessionInfo sessionInfo) throws RepositoryException {
return uriResolver.getItemUri(itemId, sessionInfo.getWorkspaceName(), sessionInfo);
}
@@ -349,39 +351,41 @@
* @see RepositoryService#getRepositoryDescriptors()
*/
public Map getRepositoryDescriptors() throws RepositoryException {
- ReportInfo info = new ReportInfo(RepositoryDescriptorsReport.REPOSITORY_DESCRIPTORS_REPORT, DavConstants.DEPTH_0);
- ReportMethod method = null;
- try {
- method = new ReportMethod(uriResolver.getRepositoryUri(), info);
-
- getClient((org.apache.commons.httpclient.Credentials) null).executeMethod(method);
- method.checkSuccess();
- Document doc = method.getResponseBodyAsDocument();
- Map descriptors = new HashMap();
- if (doc != null) {
- Element rootElement = doc.getDocumentElement();
- ElementIterator nsElems = DomUtil.getChildren(rootElement, ItemResourceConstants.XML_DESCRIPTOR, ItemResourceConstants.NAMESPACE);
- while (nsElems.hasNext()) {
- Element elem = nsElems.nextElement();
- String key = DomUtil.getChildText(elem, ItemResourceConstants.XML_DESCRIPTORKEY, ItemResourceConstants.NAMESPACE);
- String descriptor = DomUtil.getChildText(elem, ItemResourceConstants.XML_DESCRIPTORVALUE, ItemResourceConstants.NAMESPACE);
- if (key != null && descriptor != null) {
- descriptors.put(key, descriptor);
- } else {
- log.error("Invalid descriptor key / value pair: " + key + " -> " + descriptor);
+ if (descriptors == null) {
+ ReportInfo info = new ReportInfo(RepositoryDescriptorsReport.REPOSITORY_DESCRIPTORS_REPORT, DavConstants.DEPTH_0);
+ ReportMethod method = null;
+ try {
+ method = new ReportMethod(uriResolver.getRepositoryUri(), info);
+ getClient(null).executeMethod(method);
+ method.checkSuccess();
+ Document doc = method.getResponseBodyAsDocument();
+
+ descriptors = new HashMap();
+ if (doc != null) {
+ Element rootElement = doc.getDocumentElement();
+ ElementIterator nsElems = DomUtil.getChildren(rootElement, ItemResourceConstants.XML_DESCRIPTOR, ItemResourceConstants.NAMESPACE);
+ while (nsElems.hasNext()) {
+ Element elem = nsElems.nextElement();
+ String key = DomUtil.getChildText(elem, ItemResourceConstants.XML_DESCRIPTORKEY, ItemResourceConstants.NAMESPACE);
+ String descriptor = DomUtil.getChildText(elem, ItemResourceConstants.XML_DESCRIPTORVALUE, ItemResourceConstants.NAMESPACE);
+ if (key != null && descriptor != null) {
+ descriptors.put(key, descriptor);
+ } else {
+ log.error("Invalid descriptor key / value pair: " + key + " -> " + descriptor);
+ }
}
}
- }
- return descriptors;
- } catch (IOException e) {
- throw new RepositoryException(e);
- } catch (DavException e) {
- throw ExceptionConverter.generate(e);
- } finally {
- if (method != null) {
- method.releaseConnection();
+ } catch (IOException e) {
+ throw new RepositoryException(e);
+ } catch (DavException e) {
+ throw ExceptionConverter.generate(e);
+ } finally {
+ if (method != null) {
+ method.releaseConnection();
+ }
}
}
+ return descriptors;
}
/**
@@ -406,10 +410,12 @@
// check if the workspace with the given name is accessible
PropFindMethod method = null;
try {
+ SessionInfo sessionInfo = new SessionInfoImpl(credentials, workspaceName);
+
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(DeltaVConstants.WORKSPACE);
method = new PropFindMethod(uriResolver.getWorkspaceUri(workspaceName), nameSet, DavConstants.DEPTH_0);
- getClient(credentials.getCredentials()).executeMethod(method);
+ getClient(sessionInfo).executeMethod(method);
MultiStatusResponse[] responses = method.getResponseBodyAsMultiStatus().getResponses();
if (responses.length != 1) {
@@ -423,7 +429,7 @@
if (!wspName.equals(workspaceName)) {
throw new LoginException("Login failed: Invalid workspace name " + workspaceName);
}
- return new SessionInfoImpl(credentials, workspaceName);
+ return sessionInfo;
} else {
throw new LoginException("Login failed: Unknown workspace '" + workspaceName+ " '.");
}
@@ -877,7 +883,6 @@
try {
String uri = getItemUri(nodeId, sessionInfo);
method = new PropFindMethod(uri, nameSet, DEPTH_0);
- initMethod(method, sessionInfo, true);
getClient(sessionInfo).executeMethod(method);
method.checkSuccess();