From: Alex L. <al...@jb...> - 2005-05-28 17:05:14
|
User: aloubyansky Date: 05/05/28 13:04:45 Modified: src/main/org/jboss/xml/binding/metadata JaxbBaseType.java JaxbClass.java JaxbJavaType.java JaxbPackage.java JaxbProperty.java JaxbSchemaBindings.java XsdAnnotation.java XsdAppInfo.java XsdElement.java Added: src/main/org/jboss/xml/binding/metadata CharactersMetaData.java ClassMetaData.java PackageMetaData.java PropertyMetaData.java SchemaMetaData.java ValueMetaData.java Removed: src/main/org/jboss/xml/binding/metadata BindingElement.java Log: use more general/abstract metadata model than the one from jaxb Revision Changes Path 1.2 +2 -2 jboss-common/src/main/org/jboss/xml/binding/metadata/JaxbBaseType.java (In the diff below, changes in quantity of whitespace are not shown.) Index: JaxbBaseType.java =================================================================== RCS file: /cvsroot/jboss/jboss-common/src/main/org/jboss/xml/binding/metadata/JaxbBaseType.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- JaxbBaseType.java 13 May 2005 13:23:51 -0000 1.1 +++ JaxbBaseType.java 28 May 2005 17:04:45 -0000 1.2 @@ -11,10 +11,10 @@ /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.1 $</tt> + * @version <tt>$Revision: 1.2 $</tt> */ public class JaxbBaseType - extends BindingElement + extends XsdElement { static final QName QNAME = new QName(Constants.NS_JAXB, "baseType"); 1.3 +2 -2 jboss-common/src/main/org/jboss/xml/binding/metadata/JaxbClass.java (In the diff below, changes in quantity of whitespace are not shown.) Index: JaxbClass.java =================================================================== RCS file: /cvsroot/jboss/jboss-common/src/main/org/jboss/xml/binding/metadata/JaxbClass.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- JaxbClass.java 25 May 2005 12:55:56 -0000 1.2 +++ JaxbClass.java 28 May 2005 17:04:45 -0000 1.3 @@ -11,10 +11,10 @@ /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.2 $</tt> + * @version <tt>$Revision: 1.3 $</tt> */ public class JaxbClass - extends BindingElement + extends XsdElement { static final QName QNAME = new QName(Constants.NS_JAXB, "class"); private static final QName QNAME_IMPL_CLASS = new QName("implClass"); 1.2 +2 -2 jboss-common/src/main/org/jboss/xml/binding/metadata/JaxbJavaType.java (In the diff below, changes in quantity of whitespace are not shown.) Index: JaxbJavaType.java =================================================================== RCS file: /cvsroot/jboss/jboss-common/src/main/org/jboss/xml/binding/metadata/JaxbJavaType.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- JaxbJavaType.java 13 May 2005 13:23:51 -0000 1.1 +++ JaxbJavaType.java 28 May 2005 17:04:45 -0000 1.2 @@ -11,10 +11,10 @@ /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.1 $</tt> + * @version <tt>$Revision: 1.2 $</tt> */ public class JaxbJavaType - extends BindingElement + extends XsdElement { public static final QName QNAME = new QName(Constants.NS_JAXB, "javaType"); private static final QName QNAME_XML_TYPE = new QName("xmlType"); 1.3 +2 -2 jboss-common/src/main/org/jboss/xml/binding/metadata/JaxbPackage.java (In the diff below, changes in quantity of whitespace are not shown.) Index: JaxbPackage.java =================================================================== RCS file: /cvsroot/jboss/jboss-common/src/main/org/jboss/xml/binding/metadata/JaxbPackage.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- JaxbPackage.java 25 May 2005 12:55:56 -0000 1.2 +++ JaxbPackage.java 28 May 2005 17:04:45 -0000 1.3 @@ -11,10 +11,10 @@ /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.2 $</tt> + * @version <tt>$Revision: 1.3 $</tt> */ public class JaxbPackage - extends BindingElement + extends XsdElement { static final QName QNAME = new QName(Constants.NS_JAXB, "package"); 1.3 +2 -2 jboss-common/src/main/org/jboss/xml/binding/metadata/JaxbProperty.java (In the diff below, changes in quantity of whitespace are not shown.) Index: JaxbProperty.java =================================================================== RCS file: /cvsroot/jboss/jboss-common/src/main/org/jboss/xml/binding/metadata/JaxbProperty.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- JaxbProperty.java 13 May 2005 13:23:51 -0000 1.2 +++ JaxbProperty.java 28 May 2005 17:04:45 -0000 1.3 @@ -11,10 +11,10 @@ /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.2 $</tt> + * @version <tt>$Revision: 1.3 $</tt> */ public class JaxbProperty - extends BindingElement + extends XsdElement { static final QName QNAME = new QName(Constants.NS_JAXB, "property"); static final QName QNAME_COLLECTION_TYPE = new QName("collectionType"); 1.2 +2 -2 jboss-common/src/main/org/jboss/xml/binding/metadata/JaxbSchemaBindings.java (In the diff below, changes in quantity of whitespace are not shown.) Index: JaxbSchemaBindings.java =================================================================== RCS file: /cvsroot/jboss/jboss-common/src/main/org/jboss/xml/binding/metadata/JaxbSchemaBindings.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- JaxbSchemaBindings.java 12 May 2005 10:00:09 -0000 1.1 +++ JaxbSchemaBindings.java 28 May 2005 17:04:45 -0000 1.2 @@ -11,10 +11,10 @@ /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.1 $</tt> + * @version <tt>$Revision: 1.2 $</tt> */ public class JaxbSchemaBindings - extends BindingElement + extends XsdElement { static final QName QNAME = new QName(Constants.NS_JAXB, "schemaBindings"); 1.4 +174 -21 jboss-common/src/main/org/jboss/xml/binding/metadata/XsdAnnotation.java (In the diff below, changes in quantity of whitespace are not shown.) Index: XsdAnnotation.java =================================================================== RCS file: /cvsroot/jboss/jboss-common/src/main/org/jboss/xml/binding/metadata/XsdAnnotation.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -b -r1.3 -r1.4 --- XsdAnnotation.java 19 May 2005 12:10:58 -0000 1.3 +++ XsdAnnotation.java 28 May 2005 17:04:45 -0000 1.4 @@ -19,10 +19,10 @@ /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.3 $</tt> + * @version <tt>$Revision: 1.4 $</tt> */ public class XsdAnnotation - extends BindingElement + extends XsdElement { public XsdAnnotation(QName qName) { @@ -90,7 +90,7 @@ return root; } - protected void setAttributes(BindingElement element, Attributes attrs) + protected void setAttributes(XsdElement element, Attributes attrs) { if(element != null) { @@ -113,7 +113,7 @@ String localName, Attributes attrs) { - BindingElement element = null; + XsdElement element = null; if("appinfo".equals(localName)) { element = new XsdAppInfo(); @@ -124,6 +124,38 @@ return element; } + public void addChild(Object parent, + Object child, + UnmarshallingContext ctx, + String namespaceURI, + String localName) + { + if(parent instanceof XsdAppInfo) + { + XsdAppInfo appInfo = (XsdAppInfo)parent; + if(child instanceof ClassMetaData) + { + appInfo.setClassMetaData((ClassMetaData)child); + } + else if(child instanceof PropertyMetaData) + { + appInfo.setPropertyMetaData((PropertyMetaData)child); + } + else if(child instanceof SchemaMetaData) + { + appInfo.setSchemaMetaData((SchemaMetaData)child); + } + else if(child instanceof ValueMetaData) + { + appInfo.setValueMetaData((ValueMetaData)child); + } + } + else + { + super.addChild(parent, child, ctx, namespaceURI, localName); + } + } + public Object newRoot(Object root, UnmarshallingContext ctx, String namespaceURI, @@ -135,7 +167,7 @@ } private static final class JaxbObjectModelFactory - extends AbstractGOMF + implements GenericObjectModelFactory { public static final GenericObjectModelFactory INSTANCE = new JaxbObjectModelFactory(); @@ -145,52 +177,173 @@ String localName, Attributes attrs) { - BindingElement element = null; + Object element = null; if("package".equals(localName)) { - element = new JaxbPackage(); - } - else if("baseType".equals(localName)) + element = new PackageMetaData(); + setAttributes(element, attrs, new AttributeSetter() { - element = new JaxbBaseType(); + public void setAttribute(Object o, String nsUri, String localName, String value) + { + if("name".equals(localName)) + { + ((PackageMetaData)o).setName(value); + } + } + } + ); } else if("javaType".equals(localName)) { - element = new JaxbJavaType(); + ValueMetaData valueMetaData = new ValueMetaData(); + setAttributes(valueMetaData, attrs, new AttributeSetter() + { + public void setAttribute(Object o, String nsUri, String localName, String value) + { + if("parseMethod".equals(localName)) + { + ((ValueMetaData)o).setUnmarshalMethod(value); } + else if("printMethod".equals(localName)) + { + ((ValueMetaData)o).setMarshalMethod(value); + } + } + } + ); - setAttributes(element, attrs); + // todo review this... + XsdAppInfo appInfo = (XsdAppInfo)parent; + appInfo.setValueMetaData(valueMetaData); + } return element; } + public void addChild(Object parent, + Object child, + UnmarshallingContext ctx, + String namespaceURI, + String localName) + { + if(parent instanceof CharactersMetaData) + { + CharactersMetaData charMetaData = (CharactersMetaData)parent; + if(child instanceof PropertyMetaData) + { + charMetaData.setProperty((PropertyMetaData)child); + } + else + { + charMetaData.setValue((ValueMetaData)child); + } + } + else if(parent instanceof SchemaMetaData) + { + SchemaMetaData schemaMetaData = (SchemaMetaData)parent; + if(child instanceof PackageMetaData) + { + schemaMetaData.setPackage((PackageMetaData)child); + } + else + { + schemaMetaData.addValue((ValueMetaData)child); + } + } + } + + public void setValue(Object o, UnmarshallingContext ctx, String namespaceURI, String localName, String value) + { + } + public Object newRoot(Object root, UnmarshallingContext ctx, String namespaceURI, String localName, Attributes attrs) { - BindingElement element = null; + Object element = null; if("schemaBindings".equals(localName)) { - element = new JaxbSchemaBindings(); + element = new SchemaMetaData(); } else if("property".equals(localName)) { - element = new JaxbProperty(); + PropertyMetaData property = new PropertyMetaData(); + setAttributes(property, attrs, new AttributeSetter() + { + public void setAttribute(Object o, String nsUri, String localName, String value) + { + if("name".equals(localName)) + { + ((PropertyMetaData)o).setName(value); + } + else if("collectionType".equals(localName)) + { + ((PropertyMetaData)o).setCollectionType(value); + } + } + } + ); + //element = property; + XsdAppInfo appInfo = (XsdAppInfo)root; + appInfo.setPropertyMetaData(property); + // return null; } else if("class".equals(localName)) { - element = new JaxbClass(); + element = new ClassMetaData(); + setAttributes(element, attrs, new AttributeSetter() + { + public void setAttribute(Object o, String nsUri, String localName, String value) + { + if("implClass".equals(localName)) + { + ((ClassMetaData)o).setImpl(value); + } + } + } + ); } else if("javaType".equals(localName)) { - element = new JaxbJavaType(); + element = new ValueMetaData(); + setAttributes(element, attrs, new AttributeSetter(){ + public void setAttribute(Object o, String nsUri, String localName, String value) + { + if("printMethod".equals(localName)) + { + ((ValueMetaData)o).setMarshalMethod(value); + } + else if("parseMethod".equals(localName)) + { + ((ValueMetaData)o).setUnmarshalMethod(value); + } + } + }); } - - setAttributes(element, attrs); return element; } + + public Object completeRoot(Object root, UnmarshallingContext ctx, String namespaceURI, String localName) + { + return root; + } + + private void setAttributes(Object o, Attributes attrs, AttributeSetter attrSetter) + { + for(int i = 0; i < attrs.getLength(); ++i) + { + attrSetter.setAttribute(o, attrs.getURI(i), attrs.getLocalName(i), attrs.getValue(i)); + } + } + + // Inner + + interface AttributeSetter + { + void setAttribute(Object o, String nsUri, String localName, String value); + } } } 1.3 +38 -8 jboss-common/src/main/org/jboss/xml/binding/metadata/XsdAppInfo.java (In the diff below, changes in quantity of whitespace are not shown.) Index: XsdAppInfo.java =================================================================== RCS file: /cvsroot/jboss/jboss-common/src/main/org/jboss/xml/binding/metadata/XsdAppInfo.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- XsdAppInfo.java 19 May 2005 12:10:58 -0000 1.2 +++ XsdAppInfo.java 28 May 2005 17:04:45 -0000 1.3 @@ -11,30 +11,60 @@ /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.2 $</tt> + * @version <tt>$Revision: 1.3 $</tt> */ public class XsdAppInfo - extends BindingElement + extends XsdElement { static final QName QNAME = new QName(Constants.NS_XML_SCHEMA, "appinfo"); + private SchemaMetaData schemaMetaData; + private ClassMetaData classMetaData; + private PropertyMetaData propertyMetaData; + private ValueMetaData valueMetaData; + public XsdAppInfo() { super(QNAME); } - public JaxbClass getJaxbClass() + public SchemaMetaData getSchemaMetaData() + { + return schemaMetaData; + } + + public void setSchemaMetaData(SchemaMetaData schema) + { + this.schemaMetaData = schema; + } + + public ClassMetaData getClassMetaData() + { + return classMetaData; + } + + public void setClassMetaData(ClassMetaData classMetaData) + { + this.classMetaData = classMetaData; + } + + public PropertyMetaData getPropertyMetaData() + { + return propertyMetaData; + } + + public void setPropertyMetaData(PropertyMetaData propertyMetaData) { - return (JaxbClass)getChild(JaxbClass.QNAME); + this.propertyMetaData = propertyMetaData; } - public JaxbProperty getJaxbProperty() + public ValueMetaData getValueMetaData() { - return (JaxbProperty)getChild(JaxbProperty.QNAME); + return valueMetaData; } - public JaxbJavaType getJaxbJavaType() + public void setValueMetaData(ValueMetaData valueMetaData) { - return (JaxbJavaType)getChild(JaxbJavaType.QNAME); + this.valueMetaData = valueMetaData; } } 1.2 +13 -1 jboss-common/src/main/org/jboss/xml/binding/metadata/XsdElement.java (In the diff below, changes in quantity of whitespace are not shown.) Index: XsdElement.java =================================================================== RCS file: /cvsroot/jboss/jboss-common/src/main/org/jboss/xml/binding/metadata/XsdElement.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- XsdElement.java 12 May 2005 10:00:09 -0000 1.1 +++ XsdElement.java 28 May 2005 17:04:45 -0000 1.2 @@ -13,10 +13,12 @@ /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.1 $</tt> + * @version <tt>$Revision: 1.2 $</tt> */ public class XsdElement { + public static final QName QNAME_NAME = new QName("name"); + private final QName qName; private Map attributes = Collections.EMPTY_MAP; private Map children = Collections.EMPTY_MAP; @@ -80,6 +82,16 @@ return qName; } + public String getNameAttribute() + { + return getAttribute(QNAME_NAME); + } + + public void setNameAttribute(String name) + { + addAttribute(QNAME_NAME, name); + } + public boolean equals(Object o) { if(this == o) 1.1 date: 2005/05/28 17:04:45; author: aloubyansky; state: Exp;jboss-common/src/main/org/jboss/xml/binding/metadata/CharactersMetaData.java Index: CharactersMetaData.java =================================================================== /* * JBoss, the OpenSource webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.xml.binding.metadata; /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> * @version <tt>$Revision: 1.1 $</tt> */ public class CharactersMetaData { private PropertyMetaData property; private ValueMetaData value; public PropertyMetaData getProperty() { return property; } public void setProperty(PropertyMetaData property) { this.property = property; } public ValueMetaData getValue() { return value; } public void setValue(ValueMetaData value) { this.value = value; } public boolean equals(Object o) { if(this == o) { return true; } if(!(o instanceof CharactersMetaData)) { return false; } final CharactersMetaData charactersMetaData = (CharactersMetaData)o; if(property != null ? !property.equals(charactersMetaData.property) : charactersMetaData.property != null) { return false; } if(value != null ? !value.equals(charactersMetaData.value) : charactersMetaData.value != null) { return false; } return true; } public int hashCode() { int result; result = (property != null ? property.hashCode() : 0); result = 29 * result + (value != null ? value.hashCode() : 0); return result; } } 1.1 date: 2005/05/28 17:04:45; author: aloubyansky; state: Exp;jboss-common/src/main/org/jboss/xml/binding/metadata/ClassMetaData.java Index: ClassMetaData.java =================================================================== /* * JBoss, the OpenSource webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.xml.binding.metadata; /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> * @version <tt>$Revision: 1.1 $</tt> */ public class ClassMetaData { private String impl; public String getImpl() { return impl; } public void setImpl(String impl) { this.impl = impl; } public boolean equals(Object o) { if(this == o) { return true; } if(!(o instanceof ClassMetaData)) { return false; } final ClassMetaData classMetaData = (ClassMetaData)o; if(impl != null ? !impl.equals(classMetaData.impl) : classMetaData.impl != null) { return false; } return true; } public int hashCode() { return (impl != null ? impl.hashCode() : 0); } } 1.1 date: 2005/05/28 17:04:45; author: aloubyansky; state: Exp;jboss-common/src/main/org/jboss/xml/binding/metadata/PackageMetaData.java Index: PackageMetaData.java =================================================================== /* * JBoss, the OpenSource webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.xml.binding.metadata; /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> * @version <tt>$Revision: 1.1 $</tt> */ public class PackageMetaData { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public boolean equals(Object o) { if(this == o) { return true; } if(!(o instanceof PackageMetaData)) { return false; } final PackageMetaData packageMetaData = (PackageMetaData)o; if(name != null ? !name.equals(packageMetaData.name) : packageMetaData.name != null) { return false; } return true; } public int hashCode() { return (name != null ? name.hashCode() : 0); } } 1.1 date: 2005/05/28 17:04:45; author: aloubyansky; state: Exp;jboss-common/src/main/org/jboss/xml/binding/metadata/PropertyMetaData.java Index: PropertyMetaData.java =================================================================== /* * JBoss, the OpenSource webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.xml.binding.metadata; /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> * @version <tt>$Revision: 1.1 $</tt> */ public class PropertyMetaData { private String name; private String collectionType; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCollectionType() { return collectionType; } public void setCollectionType(String collectionType) { this.collectionType = collectionType; } } 1.1 date: 2005/05/28 17:04:45; author: aloubyansky; state: Exp;jboss-common/src/main/org/jboss/xml/binding/metadata/SchemaMetaData.java Index: SchemaMetaData.java =================================================================== /* * JBoss, the OpenSource webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.xml.binding.metadata; import java.util.Map; import java.util.Collections; import java.util.HashMap; /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> * @version <tt>$Revision: 1.1 $</tt> */ public class SchemaMetaData { private PackageMetaData packageMetaData; private Map values = Collections.EMPTY_MAP; public PackageMetaData getPackage() { return packageMetaData; } public void setPackage(PackageMetaData pkg) { this.packageMetaData = pkg; } public ValueMetaData getValue(String id) { return (ValueMetaData)values.get(id); } public void addValue(ValueMetaData value) { if(value.getId() == null) { throw new IllegalArgumentException("ValueMetaData must have a non-null id."); } switch(values.size()) { case 0: values = Collections.singletonMap(value.getId(), value); break; case 1: values = new HashMap(values); default: values.put(value.getId(), value); } } } 1.1 date: 2005/05/28 17:04:45; author: aloubyansky; state: Exp;jboss-common/src/main/org/jboss/xml/binding/metadata/ValueMetaData.java Index: ValueMetaData.java =================================================================== /* * JBoss, the OpenSource webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.xml.binding.metadata; /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> * @version <tt>$Revision: 1.1 $</tt> */ public class ValueMetaData { private String id; private String ref; private String unmarshalMethod; private String marshalMethod; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getRef() { return ref; } public void setRef(String ref) { this.ref = ref; } public String getUnmarshalMethod() { return unmarshalMethod; } public void setUnmarshalMethod(String unmarshalMethod) { this.unmarshalMethod = unmarshalMethod; } public String getMarshalMethod() { return marshalMethod; } public void setMarshalMethod(String marshalMethod) { this.marshalMethod = marshalMethod; } public boolean equals(Object o) { if(this == o) { return true; } if(!(o instanceof ValueMetaData)) { return false; } final ValueMetaData valueMetaData = (ValueMetaData)o; if(id != null ? !id.equals(valueMetaData.id) : valueMetaData.id != null) { return false; } if(marshalMethod != null ? !marshalMethod.equals(valueMetaData.marshalMethod) : valueMetaData.marshalMethod != null) { return false; } if(ref != null ? !ref.equals(valueMetaData.ref) : valueMetaData.ref != null) { return false; } if(unmarshalMethod != null ? !unmarshalMethod.equals(valueMetaData.unmarshalMethod) : valueMetaData.unmarshalMethod != null) { return false; } return true; } public int hashCode() { int result; result = (id != null ? id.hashCode() : 0); result = 29 * result + (ref != null ? ref.hashCode() : 0); result = 29 * result + (unmarshalMethod != null ? unmarshalMethod.hashCode() : 0); result = 29 * result + (marshalMethod != null ? marshalMethod.hashCode() : 0); return result; } } |