tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From am...@apache.org
Subject svn commit: r619858 - in /incubator/tuscany/java/sdo: impl/src/main/java/org/apache/tuscany/sdo/helper/ impl/src/main/java/org/apache/tuscany/sdo/util/ impl/src/test/java/org/apache/tuscany/sdo/test/ impl/src/test/resources/ lib/src/main/java/org/apach...
Date Fri, 08 Feb 2008 12:20:32 GMT
Author: amita
Date: Fri Feb  8 04:20:31 2008
New Revision: 619858

URL: http://svn.apache.org/viewvc?rev=619858&view=rev
Log:
TUSCANY-1360 enumeration and pattern facet

Modified:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java
    incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/MetadataInstancePropertiesTestCase.java
    incubator/tuscany/java/sdo/impl/src/test/resources/TypePropertyMetadataInfo.xsd
    incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
    incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java?rev=619858&r1=619857&r2=619858&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java
Fri Feb  8 04:20:31 2008
@@ -129,6 +129,36 @@
         return ((EStructuralFeature)property).getLowerBound();
     }
     
+    public List getEnumerationFacet(Type type) {
+    	List instProps = type.getInstanceProperties();
+    	String propertyName = "enumeration";
+    	Property enumProperty = null;
+    	
+		for (int i = 0; i < instProps.size(); i++)
+		{
+		  Property prop = (Property)instProps.get(i);
+		  if (propertyName.equals(prop.getName()))
+			  enumProperty = prop;
+		}
+
+		return (List)DataObjectUtil.getMetaObjectInstanceProperty((EModelElement)type, enumProperty);
+    }
+    
+    public List getPatternFacet(Type type) {
+    	List instProps = type.getInstanceProperties();
+    	String propertyName = "pattern";
+    	Property patternProperty = null;
+    	
+		for (int i = 0; i < instProps.size(); i++)
+		{
+		  Property prop = (Property)instProps.get(i);
+		  if (propertyName.equals(prop.getName()))
+			  patternProperty = prop;
+		}
+
+		return (List)DataObjectUtil.getMetaObjectInstanceProperty((EModelElement)type, patternProperty);
+    }
+
     public boolean isMany(Property property, DataObject context) {
         return FeatureMapUtil.isMany((EObject)context, (EStructuralFeature)property);
     }

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java?rev=619858&r1=619857&r2=619858&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/DataObjectUtil.java
Fri Feb  8 04:20:31 2008
@@ -58,6 +58,7 @@
 import org.eclipse.emf.ecore.EReference;
 import org.eclipse.emf.ecore.EStructuralFeature;
 import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.impl.EDataTypeImpl;
 import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
 import org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl;
 import org.eclipse.emf.ecore.resource.Resource;
@@ -2851,7 +2852,7 @@
   public static List getMetaObjectInstanceProperties(EModelElement metaObject) 
   {
     // Use the default helper context for now
-//    TypeHelper typeHelper = HelperProvider.getDefaultContext().getTypeHelper();
+	// TypeHelper typeHelper = HelperProvider.getDefaultContext().getTypeHelper();
       HelperContext hc = HelperProvider.getDefaultContext();
       
     List result = new UniqueEList();
@@ -2884,12 +2885,32 @@
    * @param property - The instance property to retrieve
    * @return The value of the instance property
    */
-  public static Object getMetaObjectInstanceProperty(EModelElement metaObject, Property property)
+  /*public static Object getMetaObjectInstanceProperty(EModelElement metaObject, Property
property)
   {
     String value = EcoreUtil.getAnnotation(metaObject, property.getContainingType().getURI(),
property.getName());
     //TODO if (property.isMany()) ... // create list of values from from string
     return SDOUtil.createFromString(property.getType(), value);
-  }
+  }*/
+  
+	 public static Object getMetaObjectInstanceProperty(EModelElement metaObject, Property property)
+	 {
+	  if(metaObject instanceof EDataTypeImpl){
+		  if(property.getName().equals("enumeration")) {
+				  List enumVals = ((EDataTypeImpl)metaObject).getExtendedMetaData().getEnumerationFacet();
+				  return enumVals;
+			  }
+	 
+			  if(property.getName().equals("pattern")) {
+			  List patternVals = ((EDataTypeImpl)metaObject).getExtendedMetaData().getPatternFacet();
+			  return patternVals;
+		  }
+	  }
+	  String value = EcoreUtil.getAnnotation(metaObject, property.getContainingType().getURI(),
property.getName());
+	  //TODO if (property.isMany()) ... // create list of values from from string
+	  return SDOUtil.createFromString(property.getType(), value);
+	 }
+  
+  
 /*
   protected static Property getGlobalProperty(TypeHelper typeHelper, String uri, String name)
   {

Modified: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/MetadataInstancePropertiesTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/MetadataInstancePropertiesTestCase.java?rev=619858&r1=619857&r2=619858&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/MetadataInstancePropertiesTestCase.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/MetadataInstancePropertiesTestCase.java
Fri Feb  8 04:20:31 2008
@@ -138,6 +138,29 @@
     assertTrue(getInstanceProperty(property, "foo") == null);
   }
   
+  //Amita
+  public void testEnumProperty()
+  {
+	    Type type = typeHelper.getType(TEST_NAMESPACE, "ExampleRating");
+	    assertTrue(getInstanceProperty(type, "enumeration") != null);
+	    List enumFacet = SDOUtil.getEnumerationFacet(type);
+	    assertEquals(3, enumFacet.size());
+	    assertEquals("", enumFacet.get(0));
+	    assertEquals("Good", enumFacet.get(1));
+	    assertEquals("Bad", enumFacet.get(2));	    
+  }
+  
+  //Amita
+  public void testPatternProperty()
+  {
+	    Type type = typeHelper.getType(TEST_NAMESPACE, "PhoneNumber");
+	    assertTrue(getInstanceProperty(type, "pattern") != null);
+	    List patternFacet = SDOUtil.getPatternFacet(type);
+	    assertEquals(2, patternFacet.size());
+	    assertEquals("\\d{3}-\\d{4}", patternFacet.get(0));
+	    assertEquals("\\d{6}-\\d{8}", patternFacet.get(1));
+  }
+  
   public void setUp() throws Exception
   {
     super.setUp();

Modified: incubator/tuscany/java/sdo/impl/src/test/resources/TypePropertyMetadataInfo.xsd
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/resources/TypePropertyMetadataInfo.xsd?rev=619858&r1=619857&r2=619858&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/resources/TypePropertyMetadataInfo.xsd (original)
+++ incubator/tuscany/java/sdo/impl/src/test/resources/TypePropertyMetadataInfo.xsd Fri Feb
 8 04:20:31 2008
@@ -82,6 +82,7 @@
 	<restriction base="string">
 		<length value="8"/>
 		<pattern value="\d{3}-\d{4}"/>
+		<pattern value="\d{6}-\d{8}"/>
 	</restriction>
 </simpleType>
 
@@ -93,4 +94,4 @@
 	</restriction>
 </simpleType>
    
-</schema>
\ No newline at end of file
+</schema>

Modified: incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java?rev=619858&r1=619857&r2=619858&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
(original)
+++ incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
Fri Feb  8 04:20:31 2008
@@ -154,6 +154,20 @@
   public int getLowerBound(Property property);
   
   /**
+   * Return Enumeration facet 
+   * @param type
+   * @return List of enum facets in a Type
+   *///Amita
+  public List getEnumerationFacet(Type type);
+  
+  /**
+   * Return Pattern facet 
+   * @param type
+   * @return List of pattern facets in a Type
+   *///Amita
+  public List getPatternFacet(Type type);
+
+  /**
    * Returns whether the Property is many-valued given the specified context.
    * @param property The Property in question
    * @param context The context to check whether the specified Property is many-valued

Modified: incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java?rev=619858&r1=619857&r2=619858&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java (original)
+++ incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java Fri
Feb  8 04:20:31 2008
@@ -119,6 +119,14 @@
     return defaultSDOHelper.getLowerBound(property);
   }
   
+  public static List getEnumerationFacet(Type type) {
+	  return defaultSDOHelper.getEnumerationFacet(type);
+  }
+
+  public static List getPatternFacet(Type type) {
+	  return defaultSDOHelper.getPatternFacet(type);
+  }
+	     
   /**
    * @see {@link org.apache.tuscany.sdo.api.SDOHelper#isMany(Property, DataObject)}.
    */



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message