Author: bimargulies Date: Wed Jan 7 04:30:39 2009 New Revision: 732319 URL: http://svn.apache.org/viewvc?rev=732319&view=rev Log: Rethink previous commit to recognize role of naming in the XmlSchema scheme of things.
Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamed.java (with props) webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java (with props) Removed: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaNamed.java Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.java webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java?rev=732319&r1=732318&r2=732319&view=diff ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java (original) +++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java Wed Jan 7 04:30:39 2009 @@ -1178,20 +1178,20 @@ if (attrEl.hasAttribute("type")) { String name = attrEl.getAttribute("type"); - attr.schemaTypeName = getRefQName(name, attrEl); + attr.setSchemaTypeName(getRefQName(name, attrEl)); } if (attrEl.hasAttribute("default")) { - attr.defaultValue = attrEl.getAttribute("default"); + attr.setDefaultValue(attrEl.getAttribute("default")); } if (attrEl.hasAttribute("fixed")) { - attr.fixedValue = attrEl.getAttribute("fixed"); + attr.setFixedValue(attrEl.getAttribute("fixed")); } if (attrEl.hasAttribute("form")) { String formValue = getEnumString(attrEl, "form"); - attr.form = XmlSchemaForm.schemaValueOf(formValue); + attr.setForm(XmlSchemaForm.schemaValueOf(formValue)); } if (attrEl.hasAttribute("id")) { @@ -1200,18 +1200,18 @@ if (attrEl.hasAttribute("use")) { String useType = getEnumString(attrEl, "use"); - attr.use = XmlSchemaUse.schemaValueOf(useType); + attr.setUse(XmlSchemaUse.schemaValueOf(useType)); } if (attrEl.hasAttribute("ref")) { String name = attrEl.getAttribute("ref"); - attr.refName = getRefQName(name, attrEl); + attr.setRefName(getRefQName(name, attrEl)); attr.setName(name); } Element simpleTypeEl = XDOMUtil.getFirstChildElementNS(attrEl, XmlSchema.SCHEMA_NS, "simpleType"); if (simpleTypeEl != null) { - attr.schemaType = handleSimpleType(schema, simpleTypeEl, schemaEl); + attr.setSchemaType(handleSimpleType(schema, simpleTypeEl, schemaEl)); } Element annotationEl = XDOMUtil.getFirstChildElementNS(attrEl, XmlSchema.SCHEMA_NS, "annotation"); Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.java?rev=732319&r1=732318&r2=732319&view=diff ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.java (original) +++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.java Wed Jan 7 04:30:39 2009 @@ -21,37 +21,36 @@ import javax.xml.namespace.QName; +import org.apache.ws.commons.schema.utils.XmlSchemaNamed; +import org.apache.ws.commons.schema.utils.XmlSchemaNamedImpl; + /** * Class for attribute types. Represents the World Wide Web Consortium (W3C) attribute element. */ // October 15th - momo - initial implementation -public class XmlSchemaAttribute extends XmlSchemaNamed { - - Object attributeType; - String defaultValue; - String fixedValue; - XmlSchemaForm form; - XmlSchemaSimpleType schemaType; - QName schemaTypeName; - QName refName; - XmlSchemaUse use; +public class XmlSchemaAttribute extends XmlSchemaAnnotated implements XmlSchemaNamed { + private String defaultValue; + private String fixedValue; + private XmlSchemaForm form; + private XmlSchemaSimpleType schemaType; + private QName schemaTypeName; + private QName refName; + private XmlSchemaUse use; + private XmlSchemaNamed namedDelegate; + /** * Create a new attribute. * @param schema containing scheme. * @param topLevel true if a global attribute. */ public XmlSchemaAttribute(XmlSchema schema, boolean topLevel) { - super(schema, topLevel); + namedDelegate = new XmlSchemaNamedImpl(schema, topLevel); form = XmlSchemaForm.NONE; use = XmlSchemaUse.NONE; } - public Object getAttributeType() { - return attributeType; - } - public String getDefaultValue() { return defaultValue; } @@ -125,4 +124,38 @@ return xml; } + + + public String getName() { + return namedDelegate.getName(); + } + + + public XmlSchema getParent() { + return namedDelegate.getParent(); + } + + + public QName getQName() { + return namedDelegate.getQName(); + } + + + public boolean isAnonymous() { + return namedDelegate.isAnonymous(); + } + + + public boolean isTopLevel() { + return namedDelegate.isTopLevel(); + } + + + public void setName(String name) { + namedDelegate.setName(name); + } + + public void setForm(XmlSchemaForm form) { + this.form = form; + } } Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java?rev=732319&r1=732318&r2=732319&view=diff ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java (original) +++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java Wed Jan 7 04:30:39 2009 @@ -365,35 +365,35 @@ Element attribute = createNewElement(doc, "attribute", schema.schemaNamespacePrefix, XmlSchema.SCHEMA_NS); - if (attributeObj.refName != null) { - String refName = resolveQName(attributeObj.refName, schema); + if (attributeObj.getRefName() != null) { + String refName = resolveQName(attributeObj.getRefName(), schema); attribute.setAttribute("ref", refName); } else if (!attributeObj.isAnonymous()) { attribute.setAttribute("name", attributeObj.getName()); } - if (attributeObj.schemaTypeName != null) { - String typeName = resolveQName(attributeObj.schemaTypeName, schema); + if (attributeObj.getSchemaTypeName() != null) { + String typeName = resolveQName(attributeObj.getSchemaTypeName(), schema); attribute.setAttribute("type", typeName); } - if (attributeObj.defaultValue != null) { - attribute.setAttribute("default", attributeObj.defaultValue); + if (attributeObj.getDefaultValue() != null) { + attribute.setAttribute("default", attributeObj.getDefaultValue()); } - if (attributeObj.fixedValue != null) { - attribute.setAttribute("fixed", attributeObj.fixedValue); + if (attributeObj.getFixedValue() != null) { + attribute.setAttribute("fixed", attributeObj.getFixedValue()); } - if (attributeObj.form != XmlSchemaForm.NONE) { - attribute.setAttribute("form", attributeObj.form.toString()); + if (attributeObj.getForm() != XmlSchemaForm.NONE) { + attribute.setAttribute("form", attributeObj.getForm().toString()); } if (attributeObj.getId() != null) { attribute.setAttribute("id", attributeObj.getId()); } - if (attributeObj.use != null && attributeObj.use != XmlSchemaUse.NONE) { - attribute.setAttribute("use", attributeObj.use.toString()); + if (attributeObj.getUse() != null && attributeObj.getUse() != XmlSchemaUse.NONE) { + attribute.setAttribute("use", attributeObj.getUse().toString()); } if (attributeObj.getAnnotation() != null) { @@ -401,9 +401,9 @@ attribute.appendChild(annotation); } - if (attributeObj.schemaType != null) { + if (attributeObj.getSchemaType() != null) { try { - XmlSchemaSimpleType simpleType = attributeObj.schemaType; + XmlSchemaSimpleType simpleType = attributeObj.getSchemaType(); Element simpleTypeEl = serializeSimpleType(doc, simpleType, schema); attribute.appendChild(simpleTypeEl); } catch (ClassCastException e) { Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamed.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamed.java?rev=732319&view=auto ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamed.java (added) +++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamed.java Wed Jan 7 04:30:39 2009 @@ -0,0 +1,51 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.ws.commons.schema.utils; + +import javax.xml.namespace.QName; + +import org.apache.ws.commons.schema.XmlSchema; + +public interface XmlSchemaNamed { + + /** + * Retrieve the name. + * @return + */ + String getName(); + + boolean isAnonymous(); + + /** + * Set the name. Set to null to render the object anonymous. + * @param name + */ + void setName(String name); + + /** + * Retrieve the parent schema. + * @return + */ + XmlSchema getParent(); + + QName getQName(); + + boolean isTopLevel(); + +} Propchange: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamed.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamed.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java?rev=732319&view=auto ============================================================================== --- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java (added) +++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java Wed Jan 7 04:30:39 2009 @@ -0,0 +1,94 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.ws.commons.schema.utils; + +import javax.xml.namespace.QName; + +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaException; + +/** + * Common class of all of the named objects in the XML Schema model. + * Because 'being named' is not part of the XML Schema logical + * object hierarchy, this is used as a delegate, not as a base class. + * + * By definition, all of these objects live in some particular (parent) + * schema. + * + * The parent is intentionally immutable; there's no good reason to move + * an object from one schema to another, and this simplifies some of the + * book-keeping. + * + */ +public class XmlSchemaNamedImpl implements XmlSchemaNamed { + + protected XmlSchema parentSchema; + // Store the name as a QName for the convenience of QName fans. + private QName qname; + private boolean topLevel; + + /** + * Create a new named object. + * @param parent the parent schema. + */ + public XmlSchemaNamedImpl(XmlSchema parent, boolean topLevel) { + this.parentSchema = parent; + this.topLevel = topLevel; + } + + /** {...@inheritdoc}*/ + public String getName() { + if (qname == null) { + return null; + } else { + return qname.getLocalPart(); + } + } + + /** {...@inheritdoc}*/ + public boolean isAnonymous() { + return qname == null; + } + + /** {...@inheritdoc}*/ + public void setName(String name) { + if ("".equals(name)) { + throw new XmlSchemaException("Attempt to set empty name."); + } + // even non-top-level named items have a full qname. After all, + // if form='qualified', we need to serialize it. + qname = new QName(parentSchema.getLogicalTargetNamespace(), name); + } + + /** {...@inheritdoc}*/ + public XmlSchema getParent() { + return parentSchema; + } + + /** {...@inheritdoc}*/ + public QName getQName() { + return qname; + } + + /** {...@inheritdoc}*/ + public boolean isTopLevel() { + return topLevel; + } +} Propchange: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XmlSchemaNamedImpl.java ------------------------------------------------------------------------------ svn:keywords = Rev Date