You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fg...@apache.org on 2010/01/14 17:17:09 UTC
svn commit: r899267 - in /incubator/chemistry/trunk/chemistry:
chemistry-api/src/main/java/org/apache/chemistry/
chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/
chemistry-atompub-client/src/main/java/org/apache/chemistry/ato...
Author: fguillaume
Date: Thu Jan 14 16:17:08 2010
New Revision: 899267
URL: http://svn.apache.org/viewvc?rev=899267&view=rev
Log:
Simplify property reading by using the fact that property defs ids are unique across types (2.1.3.3.2). Added TypeManager.getPropertyDefinition
Modified:
incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/CMIS.java
incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/TypeManager.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryReader.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepository.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ReadContext.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/resources/types-feed.xml
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseRepository.java
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java
incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
Modified: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/CMIS.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/CMIS.java?rev=899267&r1=899266&r2=899267&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/CMIS.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/CMIS.java Thu Jan 14 16:17:08 2010
@@ -225,6 +225,8 @@
public static final QName LOCAL_NAME_NONS = new QName("localName");
+ public static final QName QUERY_NAME_NONS = new QName("queryName");
+
public static final QName DISPLAY_NAME_NONS = new QName("displayName");
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/TypeManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/TypeManager.java?rev=899267&r1=899266&r2=899267&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/TypeManager.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/TypeManager.java Thu Jan 14 16:17:08 2010
@@ -42,6 +42,14 @@
Type getType(String typeId);
/**
+ * Gets the specified property definition.
+ *
+ * @param id the property ID
+ * @return the property definition, or {@code null} if not found
+ */
+ PropertyDefinition getPropertyDefinition(String id);
+
+ /**
* Gets all the types.
*
* @return all the types
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryReader.java?rev=899267&r1=899266&r2=899267&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPObjectEntryReader.java Thu Jan 14 16:17:08 2010
@@ -24,7 +24,6 @@
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
-import org.apache.chemistry.Type;
import org.apache.chemistry.atompub.AtomPub;
import org.apache.chemistry.atompub.client.stax.AbstractObjectReader;
import org.apache.chemistry.atompub.client.stax.ReadContext;
@@ -44,14 +43,9 @@
@Override
protected APPObjectEntry createObject(ReadContext ctx) {
- Type type = ctx.getType();
APPConnection connection = (APPConnection) ctx.getConnection();
- if (type == null) {
- return new APPObjectEntry(connection,
- new HashMap<String, XmlProperty>(), null);
- } else {
- return connection.newObjectEntry(type.getId());
- }
+ return new APPObjectEntry(connection,
+ new HashMap<String, XmlProperty>(), null);
}
@Override
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepository.java?rev=899267&r1=899266&r2=899267&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepository.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPRepository.java Thu Jan 14 16:17:08 2010
@@ -28,6 +28,7 @@
import org.apache.chemistry.Connection;
import org.apache.chemistry.ListPage;
import org.apache.chemistry.Paging;
+import org.apache.chemistry.PropertyDefinition;
import org.apache.chemistry.Repository;
import org.apache.chemistry.RepositoryInfo;
import org.apache.chemistry.SPI;
@@ -126,6 +127,11 @@
return typeManager.getType(typeId);
}
+ public PropertyDefinition getPropertyDefinition(String id) {
+ loadTypes();
+ return typeManager.getPropertyDefinition(id);
+ }
+
public Collection<Type> getTypes() {
loadTypes();
return typeManager.getTypes();
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java?rev=899267&r1=899266&r2=899267&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/AbstractObjectReader.java Thu Jan 14 16:17:08 2010
@@ -18,18 +18,14 @@
*/
package org.apache.chemistry.atompub.client.stax;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import org.apache.chemistry.CMIS;
-import org.apache.chemistry.Property;
import org.apache.chemistry.PropertyDefinition;
-import org.apache.chemistry.Type;
import org.apache.chemistry.atompub.AtomPubCMIS;
import org.apache.chemistry.xml.stax.ChildrenNavigator;
import org.apache.chemistry.xml.stax.ParseException;
@@ -80,59 +76,20 @@
}
}
- /*
- * Reads the properties. Because the ObjectTypeId may not be known
- * initially, the properties' types cannot be computed on the fly. So the
- * properties are held until the type is found.
- */
protected void readProperties(ReadContext ctx, StaxReader reader, T object)
throws XMLStreamException {
- PropertyIterator it = new PropertyIterator(reader);
- List<XmlProperty> incomplete = null;
- Type entryType = ctx.getType();
- // find the type
- if (entryType == null) {
- incomplete = new ArrayList<XmlProperty>();
- while (it.hasNext()) {
- XmlProperty p = it.next();
- if (Property.TYPE_ID.equals(p.getId())) {
- // type has been found
- String v = (String) p.getXmlValue();
- entryType = ctx.getRepository().getType(v);
- if (entryType == null) {
- throw new ParseException("No such type: " + v);
- }
- incomplete.add(p);
- // stop looking for type
- break;
- } else {
- incomplete.add(p);
- }
- }
- if (entryType == null) {
- throw new IllegalStateException("Type not known");
- }
- }
- // fill in the type for incomplete properties
- if (incomplete != null) {
- for (XmlProperty p : incomplete) {
- readPropertyWithType(ctx, reader, object, p, entryType);
- }
- }
- // consume the rest of the stream
- while (it.hasNext()) {
+ for (PropertyIterator it = new PropertyIterator(reader); it.hasNext();) {
XmlProperty p = it.next();
- readPropertyWithType(ctx, reader, object, p, entryType);
+ readPropertyWithType(ctx, reader, object, p);
}
}
protected void readPropertyWithType(ReadContext ctx, StaxReader reader,
- T object, XmlProperty p, Type entryType) {
+ T object, XmlProperty p) {
String id = p.getId();
- PropertyDefinition def = entryType.getPropertyDefinition(id);
+ PropertyDefinition def = ctx.getRepository().getPropertyDefinition(id);
if (def == null) {
- throw new ParseException("No such property definition: " + id
- + " in type: " + entryType);
+ throw new ParseException("No such property definition: " + id);
}
p.setDefinition(def);
readProperty(ctx, reader, object, p);
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ReadContext.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ReadContext.java?rev=899267&r1=899266&r2=899267&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ReadContext.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/stax/ReadContext.java Thu Jan 14 16:17:08 2010
@@ -19,7 +19,6 @@
import org.apache.chemistry.Connection;
import org.apache.chemistry.Repository;
-import org.apache.chemistry.Type;
import org.apache.chemistry.atompub.client.ContentManager;
/**
@@ -27,41 +26,25 @@
*/
public class ReadContext {
- protected Type type;
-
protected Repository repository;
protected Connection connection;
protected ContentManager contentManager;
- public ReadContext() {
-
- }
-
public ReadContext(Connection connection) {
- this(connection, null);
+ this.connection = connection;
+ this.repository = connection.getRepository();
}
public ReadContext(Repository repository) {
- this(repository, null);
+ this.repository = repository;
}
public ReadContext(ContentManager contentManager) {
this.contentManager = contentManager;
}
- public ReadContext(Repository repository, Type type) {
- this.type = type;
- this.repository = repository;
- }
-
- public ReadContext(Connection connection, Type type) {
- this.connection = connection;
- this.type = type;
- this.repository = connection.getRepository();
- }
-
public Repository getRepository() {
return repository;
}
@@ -74,8 +57,4 @@
return contentManager;
}
- public Type getType() {
- return type;
- }
-
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/resources/types-feed.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/resources/types-feed.xml?rev=899267&r1=899266&r2=899267&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/resources/types-feed.xml (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/test/resources/types-feed.xml Thu Jan 14 16:17:08 2010
@@ -32,6 +32,21 @@
<cmis:fulltextIndexed>true</cmis:fulltextIndexed>
<cmis:includedInSupertypeQuery>true
</cmis:includedInSupertypeQuery>
+ <cmis:propertyIdDefinition>
+ <cmis:id>cmis:baseTypeId</cmis:id>
+ <cmis:localName>rep-cmis:baseTypeId</cmis:localName>
+ <cmis:displayName>cmis:baseTypeId</cmis:displayName>
+ <cmis:description>Description for cmis:baseTypeId
+ </cmis:description>
+ <cmis:propertyType>id</cmis:propertyType>
+ <cmis:cardinality>single</cmis:cardinality>
+ <cmis:updatability>readonly</cmis:updatability>
+ <cmis:inherited>true</cmis:inherited>
+ <cmis:required>false</cmis:required>
+ <cmis:queryable>true</cmis:queryable>
+ <cmis:orderable>true</cmis:orderable>
+ <cmis:openChoice>false</cmis:openChoice>
+ </cmis:propertyIdDefinition>
</cmisra:type>
</entry>
<entry>
@@ -59,6 +74,21 @@
<cmis:fulltextIndexed>true</cmis:fulltextIndexed>
<cmis:includedInSupertypeQuery>true
</cmis:includedInSupertypeQuery>
+ <cmis:propertyIdDefinition>
+ <cmis:id>cmis:baseTypeId</cmis:id>
+ <cmis:localName>rep-cmis:baseTypeId</cmis:localName>
+ <cmis:displayName>cmis:baseTypeId</cmis:displayName>
+ <cmis:description>Description for cmis:baseTypeId
+ </cmis:description>
+ <cmis:propertyType>id</cmis:propertyType>
+ <cmis:cardinality>single</cmis:cardinality>
+ <cmis:updatability>readonly</cmis:updatability>
+ <cmis:inherited>true</cmis:inherited>
+ <cmis:required>false</cmis:required>
+ <cmis:queryable>true</cmis:queryable>
+ <cmis:orderable>true</cmis:orderable>
+ <cmis:openChoice>false</cmis:openChoice>
+ </cmis:propertyIdDefinition>
</cmisra:type>
</entry>
<entry>
@@ -86,6 +116,21 @@
<cmis:fulltextIndexed>false</cmis:fulltextIndexed>
<cmis:includedInSupertypeQuery>true
</cmis:includedInSupertypeQuery>
+ <cmis:propertyIdDefinition>
+ <cmis:id>cmis:baseTypeId</cmis:id>
+ <cmis:localName>rep-cmis:baseTypeId</cmis:localName>
+ <cmis:displayName>cmis:baseTypeId</cmis:displayName>
+ <cmis:description>Description for cmis:baseTypeId
+ </cmis:description>
+ <cmis:propertyType>id</cmis:propertyType>
+ <cmis:cardinality>single</cmis:cardinality>
+ <cmis:updatability>readonly</cmis:updatability>
+ <cmis:inherited>true</cmis:inherited>
+ <cmis:required>false</cmis:required>
+ <cmis:queryable>true</cmis:queryable>
+ <cmis:orderable>true</cmis:orderable>
+ <cmis:openChoice>false</cmis:openChoice>
+ </cmis:propertyIdDefinition>
</cmisra:type>
</entry>
<entry>
@@ -113,6 +158,21 @@
<cmis:fulltextIndexed>false</cmis:fulltextIndexed>
<cmis:includedInSupertypeQuery>true
</cmis:includedInSupertypeQuery>
+ <cmis:propertyIdDefinition>
+ <cmis:id>cmis:baseTypeId</cmis:id>
+ <cmis:localName>rep-cmis:baseTypeId</cmis:localName>
+ <cmis:displayName>cmis:baseTypeId</cmis:displayName>
+ <cmis:description>Description for cmis:baseTypeId
+ </cmis:description>
+ <cmis:propertyType>id</cmis:propertyType>
+ <cmis:cardinality>single</cmis:cardinality>
+ <cmis:updatability>readonly</cmis:updatability>
+ <cmis:inherited>true</cmis:inherited>
+ <cmis:required>false</cmis:required>
+ <cmis:queryable>true</cmis:queryable>
+ <cmis:orderable>true</cmis:orderable>
+ <cmis:openChoice>false</cmis:openChoice>
+ </cmis:propertyIdDefinition>
</cmisra:type>
</entry>
<entry>
@@ -140,6 +200,21 @@
<cmis:fulltextIndexed>false</cmis:fulltextIndexed>
<cmis:includedInSupertypeQuery>false
</cmis:includedInSupertypeQuery>
+ <cmis:propertyIdDefinition>
+ <cmis:id>cmis:baseTypeId</cmis:id>
+ <cmis:localName>rep-cmis:baseTypeId</cmis:localName>
+ <cmis:displayName>cmis:baseTypeId</cmis:displayName>
+ <cmis:description>Description for cmis:baseTypeId
+ </cmis:description>
+ <cmis:propertyType>id</cmis:propertyType>
+ <cmis:cardinality>single</cmis:cardinality>
+ <cmis:updatability>readonly</cmis:updatability>
+ <cmis:inherited>true</cmis:inherited>
+ <cmis:required>false</cmis:required>
+ <cmis:queryable>true</cmis:queryable>
+ <cmis:orderable>true</cmis:orderable>
+ <cmis:openChoice>false</cmis:openChoice>
+ </cmis:propertyIdDefinition>
</cmisra:type>
</entry>
</feed>
Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseRepository.java?rev=899267&r1=899266&r2=899267&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseRepository.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/base/BaseRepository.java Thu Jan 14 16:17:08 2010
@@ -160,6 +160,10 @@
return typeManager.getType(typeId);
}
+ public PropertyDefinition getPropertyDefinition(String id) {
+ return typeManager.getPropertyDefinition(id);
+ }
+
public Collection<Type> getTypes() {
return typeManager.getTypes();
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java?rev=899267&r1=899266&r2=899267&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleTypeManager.java Thu Jan 14 16:17:08 2010
@@ -29,14 +29,21 @@
import org.apache.chemistry.BaseType;
import org.apache.chemistry.ListPage;
import org.apache.chemistry.Paging;
+import org.apache.chemistry.PropertyDefinition;
import org.apache.chemistry.Type;
import org.apache.chemistry.TypeManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
public class SimpleTypeManager implements TypeManager {
+ private static final Log log = LogFactory.getLog(SimpleTypeManager.class);
+
// linked so that values() returns things in a parent-before-children order
protected final Map<String, Type> types = new LinkedHashMap<String, Type>();
+ protected final Map<String, PropertyDefinition> propertyDefinitions = new HashMap<String, PropertyDefinition>();
+
protected final Map<String, Collection<Type>> typesChildren;
public SimpleTypeManager() {
@@ -53,6 +60,9 @@
throw new RuntimeException("Type already defined: " + typeId);
}
types.put(typeId, type);
+ for (PropertyDefinition pdef : type.getPropertyDefinitions()) {
+ addPropertyDefinition(pdef);
+ }
typesChildren.put(typeId, new LinkedList<Type>());
String parentId = type.getParentId();
if (parentId == null) {
@@ -74,10 +84,34 @@
}
}
+ protected void addPropertyDefinition(PropertyDefinition pdef) {
+ PropertyDefinition old = propertyDefinitions.get(pdef.getId());
+ if (old != null) {
+ // some sanity checks
+ if (!eq(old.getLocalName(), pdef.getLocalName())
+ || !eq(old.getDisplayName(), pdef.getDisplayName())
+ || !eq(old.getQueryName(), pdef.getQueryName())
+ || !old.getType().equals(pdef.getType())) {
+ log.error("Property definition redefined differently: "
+ + pdef.getId());
+ }
+ return;
+ }
+ propertyDefinitions.put(pdef.getId(), pdef);
+ }
+
+ protected static boolean eq(String a, String b) {
+ return a == null ? b == null : a.equals(b);
+ }
+
public Type getType(String typeId) {
return types.get(typeId);
}
+ public PropertyDefinition getPropertyDefinition(String id) {
+ return propertyDefinitions.get(id);
+ }
+
public Collection<Type> getTypes() {
return new ArrayList<Type>(types.values());
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java?rev=899267&r1=899266&r2=899267&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrRepository.java Thu Jan 14 16:17:08 2010
@@ -49,6 +49,7 @@
import org.apache.chemistry.ListPage;
import org.apache.chemistry.ObjectId;
import org.apache.chemistry.Paging;
+import org.apache.chemistry.PropertyDefinition;
import org.apache.chemistry.Repository;
import org.apache.chemistry.RepositoryCapabilities;
import org.apache.chemistry.RepositoryEntry;
@@ -137,6 +138,17 @@
return null;
}
+ public PropertyDefinition getPropertyDefinition(String id) {
+ // TODO improve by caching
+ for (Type type : getTypes()) {
+ PropertyDefinition pdef = type.getPropertyDefinition(id);
+ if (pdef != null) {
+ return pdef;
+ }
+ }
+ return null;
+ }
+
public Collection<Type> getTypes() {
return getTypeDescendants(null, -1, true);
}