Author: michiel
Date: 2010-05-18 18:30:52 +0200 (Tue, 18 May 2010)
New Revision: 42231
Modified:
mmbase/trunk/bridge/src/main/java/org/mmbase/datatypes/DataTypes.java
mmbase/trunk/bridge/src/main/java/org/mmbase/datatypes/util/xml/resources/datatypes.xsd
Log:
MMB-1959
Modified: mmbase/trunk/bridge/src/main/java/org/mmbase/datatypes/DataTypes.java
===================================================================
--- mmbase/trunk/bridge/src/main/java/org/mmbase/datatypes/DataTypes.java
2010-05-18 16:30:03 UTC (rev 42230)
+++ mmbase/trunk/bridge/src/main/java/org/mmbase/datatypes/DataTypes.java
2010-05-18 16:30:52 UTC (rev 42231)
@@ -16,7 +16,7 @@
import org.xml.sax.InputSource;
import org.w3c.dom.*;
-import org.mmbase.bridge.Field;
+import org.mmbase.bridge.*;
import org.mmbase.bridge.Fields;
import org.mmbase.datatypes.util.xml.*;
import org.mmbase.util.*;
@@ -255,7 +255,47 @@
return dataTypeCollector.getDataType(name);
}
+ public static class FieldNotFoundException extends Exception {
+ public FieldNotFoundException(Exception e) {
+ super(e);
+ }
+ public FieldNotFoundException(String message) {
+ super(message);
+ }
+ }
+
/**
+ * Get the datatype a defined for a certain field of a certain node
manager, of a certain cloud context.
+ * It does this by parsing a string with this format:
[[<uri>|]<cloud name>|]<nodemanager>|<field>
+ * The point is that the string can be used as the value for an XML
attribute of the datatype tag.
+ * @param fieldAttribute The string describing the datatype
+ * @throws FieldNotFoundException If the specified field could not be
found (yet).
+ * @since MMBase-1.9.4
+ */
+ public static BasicDataType getDataTypeForFieldAttribute(String
fieldAttribute) throws FieldNotFoundException {
+
+ List<String> elements = Arrays.asList(fieldAttribute.split("\\|", 4));
+ Collections.reverse(elements);
+ String uri = elements.size() == 4 ? elements.get(3) :
ContextProvider.getDefaultCloudContext().getUri();
+ CloudContext cloudContext = ContextProvider.getCloudContext(uri);
+ if (cloudContext == null) {
+ throw new FieldNotFoundException("No cloud context for uri '" +
uri + "'");
+ }
+ try {
+ String cloudName = elements.size() >= 3 ? elements.get(2)
: cloudContext.getCloudNames().get(0);
+ String nodeManagerName = elements.get(1);
+ String baseFieldName = elements.get(0);
+
+ Cloud cloud = cloudContext.getCloud(cloudName);
+ NodeManager nodeManager = cloud.getNodeManager(nodeManagerName);
+ return (BasicDataType)
nodeManager.getField(baseFieldName).getDataType();
+ } catch (NotFoundException nfe) {
+ throw new FieldNotFoundException(nfe);
+ }
+ }
+
+
+ /**
* Returns a DataType instance.
* The system first tries to obtain a data type from the available set of
datatypes
* accessible throughout the application. If a DataType of the passed name
exists, a clone of that DataType is returned.
Modified:
mmbase/trunk/bridge/src/main/java/org/mmbase/datatypes/util/xml/resources/datatypes.xsd
===================================================================
---
mmbase/trunk/bridge/src/main/java/org/mmbase/datatypes/util/xml/resources/datatypes.xsd
2010-05-18 16:30:03 UTC (rev 42230)
+++
mmbase/trunk/bridge/src/main/java/org/mmbase/datatypes/util/xml/resources/datatypes.xsd
2010-05-18 16:30:52 UTC (rev 42231)
@@ -127,6 +127,7 @@
</xsd:sequence>
<xsd:attribute name="id" type="xsd:token" use="optional" /> <!--
optinal, because in builder xml exist 'anonymous' datatypes -->
<xsd:attribute name="base" type="xsd:token" use="optional" />
+ <xsd:attribute name="field" type="xsd:string" use="optional" />
</xsd:complexType>
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs