tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fra...@apache.org
Subject svn commit: r374126 - /incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java
Date Wed, 01 Feb 2006 17:57:29 GMT
Author: frankb
Date: Wed Feb  1 09:57:26 2006
New Revision: 374126

URL: http://svn.apache.org/viewcvs?rev=374126&view=rev
Log:
This is partial fix for TUSCANY-20. I added support for some
of the sdo XSD annotaions (e.g., sdoXML:propertyType
and sdoJava:instanceClass)

Modified:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java?rev=374126&r1=374125&r2=374126&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java
Wed Feb  1 09:57:26 2006
@@ -34,13 +34,17 @@
 import org.eclipse.emf.ecore.EModelElement;
 import org.eclipse.emf.ecore.EPackage;
 import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.resource.ResourceSet;
 import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.emf.ecore.util.ExtendedMetaData;
+import org.eclipse.xsd.XSDConcreteComponent;
 import org.eclipse.xsd.XSDSchema;
+import org.eclipse.xsd.XSDTypeDefinition;
 import org.eclipse.xsd.ecore.XSDEcoreBuilder;
 import org.eclipse.xsd.util.XSDResourceImpl;
+import org.w3c.dom.Element;
 import org.xml.sax.InputSource;
 
 import commonj.sdo.Property;
@@ -64,7 +68,7 @@
   public XSDHelperImpl(ExtendedMetaData extendedMetaData)
   {
     this.extendedMetaData = extendedMetaData;
-    ecoreBuilder = new XSDEcoreBuilder(extendedMetaData);
+    ecoreBuilder = new SDOXSDEcoreBuilder(extendedMetaData);
   }
 
   public XSDHelperImpl(TypeHelper typeHelper)
@@ -202,6 +206,65 @@
   public String generate(List /*Type*/types, Map /*String, String*/namespaceToSchemaLocation)
   {
     throw new UnsupportedOperationException(); //TODO
+  }
+  
+  protected static class SDOXSDEcoreBuilder extends XSDEcoreBuilder
+  {
+    public SDOXSDEcoreBuilder(ExtendedMetaData extendedMetaData)
+    {
+      super(extendedMetaData);
+    }
+
+    protected String getEcoreAttribute(Element element, String attribute)
+    {
+      String sdoAttribute = null;
+      
+      if ("name".equals(attribute))
+        sdoAttribute = "name";
+      else if ("opposite".equals(attribute))
+        sdoAttribute = "oppositeProperty";
+      else if ("mixed".equals(attribute))
+        sdoAttribute = "sequence";
+      
+      if (sdoAttribute != null)
+      {
+        return 
+          element != null && element.hasAttributeNS("commonj.sdo/xml", sdoAttribute)
? 
+            element.getAttributeNS("commonj.sdo/xml", sdoAttribute) : 
+            null;
+      }
+      
+      if ("package".equals(attribute))
+        sdoAttribute = "package";
+      else if ("instanceClass".equals(attribute))
+        sdoAttribute = "instanceClass";
+
+      if (sdoAttribute != null)
+      {
+        return 
+          element != null && element.hasAttributeNS("commonj.sdo/java", sdoAttribute)
? 
+            element.getAttributeNS("commonj.sdo/java", sdoAttribute) : 
+            null;
+      }
+
+      return super.getEcoreAttribute(element, attribute);
+    }
+
+    protected XSDTypeDefinition getEcoreTypeQNameAttribute(XSDConcreteComponent xsdConcreteComponent,
String attribute)
+    {
+      String sdoAttribute = null;
+      
+      if ("reference".equals(attribute)) sdoAttribute = "propertyType";
+      
+      if (sdoAttribute != null)
+      {
+        Element element = xsdConcreteComponent.getElement();
+        return  element == null ? null : getEcoreTypeQNameAttribute(xsdConcreteComponent,
element, "commonj.sdo/xml", sdoAttribute);
+      }
+
+      return super.getEcoreTypeQNameAttribute(xsdConcreteComponent, attribute);
+    }
+     
   }
 
 }



Mime
View raw message