commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r240123 - in /jakarta/commons/proper/betwixt/trunk: src/java/org/apache/commons/betwixt/schema/ src/java/org/apache/commons/betwixt/schema/strategy/ src/java/org/apache/commons/betwixt/schema/strategy/impl/ xdocs/
Date Thu, 25 Aug 2005 19:26:21 GMT
Author: rdonkin
Date: Thu Aug 25 12:26:08 2005
New Revision: 240123

URL: http://svn.apache.org/viewcvs?rev=240123&view=rev
Log:
Added strategy for schema type naming.

Added:
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/SchemaTypeNamingStrategy.java
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/ClassNameSchemaNamingStrategy.java
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/ElementSchemaNamingStrategy.java
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/QualifiedPropertyTypeSchemaNamingStrategy.java
Modified:
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/ComplexType.java
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/GlobalComplexType.java
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/Schema.java
    jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/TranscriptionConfiguration.java
    jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/ComplexType.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/ComplexType.java?rev=240123&r1=240122&r2=240123&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/ComplexType.java
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/ComplexType.java
Thu Aug 25 12:26:08 2005
@@ -65,8 +65,15 @@
             if (type == null) {
                 type = elementDescriptor.getPropertyType();
             }
-            XMLBeanInfo filledBeanInfo = schema.introspect(type);
-            elementDescriptor = filledBeanInfo.getElementDescriptor();
+            if (type == null) {
+               // no type!
+               // TODO: handle this
+               // TODO: add support for logging
+               // TODO: maybe should try singular type?
+            } else {
+                XMLBeanInfo filledBeanInfo = schema.introspect(type);
+                elementDescriptor = filledBeanInfo.getElementDescriptor();
+            }
         }
         return elementDescriptor;
     }

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/GlobalComplexType.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/GlobalComplexType.java?rev=240123&r1=240122&r2=240123&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/GlobalComplexType.java
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/GlobalComplexType.java
Thu Aug 25 12:26:08 2005
@@ -31,7 +31,8 @@
 public class GlobalComplexType extends ComplexType {
 	
 	private String name;
-	
+    private TranscriptionConfiguration configuration;
+    
 	public GlobalComplexType() {}
     
     /**
@@ -39,10 +40,11 @@
      * @param elementDescriptor
      */
     public GlobalComplexType(TranscriptionConfiguration configuration, ElementDescriptor
elementDescriptor, Schema schema) throws IntrospectionException {
-        super(configuration, elementDescriptor, schema);    
+        super(configuration, elementDescriptor, schema); 
     }
 
     protected void init(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor,
Schema schema) throws IntrospectionException {
+        this.configuration = configuration;
         setName(nameFromDescriptor( elementDescriptor ));
     }
 
@@ -61,7 +63,7 @@
     }
     
     private String nameFromDescriptor( ElementDescriptor elementDescriptor ) {
-        return elementDescriptor.getPropertyType().getName();
+        return configuration.getSchemaTypeNamingStrategy().nameSchemaType(elementDescriptor);
     }
     
     /**

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/Schema.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/Schema.java?rev=240123&r1=240122&r2=240123&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/Schema.java
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/Schema.java
Thu Aug 25 12:26:08 2005
@@ -118,7 +118,7 @@
         // use the fully qualified class name as the type name
         GlobalElement element = new GlobalElement(
                             elementDescriptor.getLocalName(), 
-                            elementDescriptor.getPropertyType().getName());
+                            configuration.getSchemaTypeNamingStrategy().nameSchemaType(elementDescriptor));
         addElement(element);
         addGlobalComplexType(configuration, elementDescriptor);
     }	

Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/TranscriptionConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/TranscriptionConfiguration.java?rev=240123&r1=240122&r2=240123&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/TranscriptionConfiguration.java
(original)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/TranscriptionConfiguration.java
Thu Aug 25 12:26:08 2005
@@ -17,6 +17,9 @@
 
 package org.apache.commons.betwixt.schema;
 
+import org.apache.commons.betwixt.schema.strategy.SchemaTypeNamingStrategy;
+import org.apache.commons.betwixt.schema.strategy.impl.QualifiedPropertyTypeSchemaNamingStrategy;
+
 /**
  * Configuration for XMLBeanInfo to XML schema transcription.
  * All settings are gathered into this one class for convenience.
@@ -28,6 +31,7 @@
     
     private DataTypeMapper dataTypeMapper = new DefaultDataTypeMapper();
     
+    private SchemaTypeNamingStrategy schemaTypeNamingStrategy = new QualifiedPropertyTypeSchemaNamingStrategy();
     
     /**
      * Gets the <code>DataTypeMapper</code> to be used during the transcription.
@@ -44,5 +48,23 @@
     public void setDataTypeMapper(DataTypeMapper mapper) {
         dataTypeMapper = mapper;
     }
+
+    /**
+     * Gets the stategy to be used for naming types.
+     * @return <code>SchemaTypeNamingStrategy</code>, not null
+     */
+    public SchemaTypeNamingStrategy getSchemaTypeNamingStrategy() {
+        return schemaTypeNamingStrategy;
+    }
+
+    /**
+     * Sets the strategy to be used for naming types.
+     * @param schemaTypeNamingStrategy <code>SchemaTypeNamingStrategy</code>,
not null
+     */
+    public void setSchemaTypeNamingStrategy( SchemaTypeNamingStrategy schemaTypeNamingStrategy)
{
+        this.schemaTypeNamingStrategy = schemaTypeNamingStrategy;
+    }
+    
+    
 
 }

Added: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/SchemaTypeNamingStrategy.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/SchemaTypeNamingStrategy.java?rev=240123&view=auto
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/SchemaTypeNamingStrategy.java
(added)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/SchemaTypeNamingStrategy.java
Thu Aug 25 12:26:08 2005
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package org.apache.commons.betwixt.schema.strategy;
+
+import org.apache.commons.betwixt.ElementDescriptor;
+
+/**
+ * Pluggable strategy for naming schema types. 
+ * Logical interface.
+ * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>
of the <a href='http://www.apache.org'>Apache Software Foundation</a>
+ */
+abstract public class SchemaTypeNamingStrategy {
+
+    /**
+     * Names the schema type described.
+     * @param descriptor <code>ElementDescriptor</code> describing the element
+     * @return
+     */
+    public abstract String nameSchemaType(ElementDescriptor descriptor);
+}

Added: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/ClassNameSchemaNamingStrategy.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/ClassNameSchemaNamingStrategy.java?rev=240123&view=auto
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/ClassNameSchemaNamingStrategy.java
(added)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/ClassNameSchemaNamingStrategy.java
Thu Aug 25 12:26:08 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package org.apache.commons.betwixt.schema.strategy.impl;
+
+import org.apache.commons.betwixt.ElementDescriptor;
+import org.apache.commons.betwixt.schema.strategy.SchemaTypeNamingStrategy;
+
+/**
+ * Names schema types from the property type of the descriptor
+ * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>
of the <a href='http://www.apache.org'>Apache Software Foundation</a>
+ */
+public class ClassNameSchemaNamingStrategy  extends SchemaTypeNamingStrategy {
+    
+    /**
+     * Names the schema type from the type of the property.
+     * @see SchemaTypeNamingStrategy#nameSchemaType(ElementDescriptor)
+     */
+    public String nameSchemaType(ElementDescriptor elementDescriptor) {
+        // TODO: this is probably wrong. needs more thought but this stuff is still experiemental
+        String result="xsd:anyType";
+        Class type = elementDescriptor.getPropertyType();
+        if (type != null)
+        {
+            String fullName = elementDescriptor.getPropertyType().getName();
+            int lastIndexOf = fullName.lastIndexOf('.');
+            result = fullName.substring(++lastIndexOf);
+        }
+        return result;
+    }
+    
+    /**
+     * Outputs brief description.
+     */
+    public String toString() {
+        return "Simple Class Name";
+    }
+}

Added: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/ElementSchemaNamingStrategy.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/ElementSchemaNamingStrategy.java?rev=240123&view=auto
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/ElementSchemaNamingStrategy.java
(added)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/ElementSchemaNamingStrategy.java
Thu Aug 25 12:26:08 2005
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package org.apache.commons.betwixt.schema.strategy.impl;
+
+import org.apache.commons.betwixt.ElementDescriptor;
+import org.apache.commons.betwixt.schema.strategy.SchemaTypeNamingStrategy;
+
+/**
+ * Strategy uses the name of the element for the complex type
+ * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>
of the <a href='http://www.apache.org'>Apache Software Foundation</a>
+ */
+public class ElementSchemaNamingStrategy extends SchemaTypeNamingStrategy{
+
+    /**
+     * Names the schema from the element
+     * @see SchemaTypeNamingStrategy#nameSchemaType(ElementDescriptor)
+     * 
+     */
+    public String nameSchemaType(ElementDescriptor descriptor) {
+        return descriptor.getLocalName();
+    }
+
+    public String toString() {
+        return "Element Schema Type Naming Strategy";
+    }
+}

Added: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/QualifiedPropertyTypeSchemaNamingStrategy.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/QualifiedPropertyTypeSchemaNamingStrategy.java?rev=240123&view=auto
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/QualifiedPropertyTypeSchemaNamingStrategy.java
(added)
+++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/schema/strategy/impl/QualifiedPropertyTypeSchemaNamingStrategy.java
Thu Aug 25 12:26:08 2005
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+package org.apache.commons.betwixt.schema.strategy.impl;
+
+import org.apache.commons.betwixt.ElementDescriptor;
+import org.apache.commons.betwixt.schema.strategy.SchemaTypeNamingStrategy;
+
+/**
+ * Names schema types from the fully qualified property type of the descriptor
+ * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>
of the <a href='http://www.apache.org'>Apache Software Foundation</a>
+ */
+public class QualifiedPropertyTypeSchemaNamingStrategy  extends SchemaTypeNamingStrategy
{
+    
+    /**
+     * Names the schema type from the type of the property.
+     * @see SchemaTypeNamingStrategy#nameSchemaType(ElementDescriptor)
+     */
+    public String nameSchemaType(ElementDescriptor elementDescriptor) {
+        // TODO: this is probably wrong. needs more thought but this stuff is still experiemental
+        String result="xsd:anyType";
+        Class type = elementDescriptor.getPropertyType();
+        if (type != null)
+        {
+            result = type.getName();
+        }
+        return result;
+    }
+    
+    /**
+     * Outputs brief description.
+     */
+    public String toString() {
+        return "Fully Qualified Type";
+    }
+}

Modified: jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml?rev=240123&r1=240122&r2=240123&view=diff
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml (original)
+++ jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml Thu Aug 25 12:26:08 2005
@@ -200,6 +200,9 @@
     <subsection name='Since 0.7'>            
         <ul>
             <li>
+Added transcription strategy to allow flexbility for schema type names.
+            </li>
+            <li>
 Added package name property suppression strategy and make default property suppression strategy
public
 nest so that it can be subclassed.
             </li>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message