001/*
002 * Copyright (c) 2004-2010, Kohsuke Kawaguchi
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification, are permitted provided
006 * that the following conditions are met:
007 *
008 *     * Redistributions of source code must retain the above copyright notice, this list of
009 *       conditions and the following disclaimer.
010 *     * Redistributions in binary form must reproduce the above copyright notice, this list of
011 *       conditions and the following disclaimer in the documentation and/or other materials
012 *       provided with the distribution.
013 *
014 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
015 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
016 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
017 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
018 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
019 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
020 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
021 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
022 */
023
024package org.kohsuke.stapler.export;
025
026import com.sun.xml.txw2.TypedXmlWriter;
027import com.sun.xml.txw2.annotation.XmlAttribute;
028import com.sun.xml.txw2.annotation.XmlElement;
029
030import javax.xml.namespace.QName;
031
032/**
033 * TXW interfaces to generate schema.
034 *
035 * @author Kohsuke Kawaguchi
036 */
037public interface XSD {
038    public static final String URI = "http://www.w3.org/2001/XMLSchema";
039
040    @XmlElement("schema")
041    public interface Schema extends TypedXmlWriter {
042        Element element();
043        ComplexType complexType();
044        SimpleType simpleType();
045    }
046
047    public interface Element extends Annotated {
048        @XmlAttribute
049        Element name(String v);
050        @XmlAttribute
051        Element type(QName t);
052
053        @XmlAttribute
054        Element minOccurs(int i);
055        @XmlAttribute
056        Element maxOccurs(String v);
057    }
058
059    public interface Attribute extends Annotated {
060        @XmlAttribute
061        Attribute name(String v);
062        @XmlAttribute
063        Attribute type(QName v);
064        @XmlAttribute
065        Attribute use(String v);
066    }
067
068    public interface ComplexType extends TypedXmlWriter {
069        @XmlAttribute
070        ComplexType name(String v);
071        ContentModel sequence();
072        ComplexContent complexContent();
073        Attribute attribute();
074    }
075
076    public interface ComplexContent extends TypedXmlWriter {
077        Restriction extension();
078    }
079
080    public interface ContentModel extends TypedXmlWriter {
081        Element element();
082    }
083
084    public interface SimpleType extends TypedXmlWriter {
085        @XmlAttribute
086        SimpleType name(String v);
087        Restriction restriction();
088    }
089
090    public interface Restriction extends TypedXmlWriter {
091        @XmlAttribute
092        Restriction base(QName t);
093        // for simple type
094        Enumeration enumeration();
095        // for complex type
096        ContentModel sequence();
097    }
098
099    public interface Enumeration extends TypedXmlWriter {
100        @XmlAttribute
101        void value(String v);
102    }
103
104    public interface Annotated extends TypedXmlWriter {
105        Annotation annotation();
106    }
107
108    public interface Annotation extends TypedXmlWriter {
109        void documentation(String value);
110    }
111
112    public abstract class Types {
113        public static final QName STRING = t("string");
114        public static final QName BOOLEAN = t("boolean");
115        public static final QName INT = t("int");
116        public static final QName LONG = t("long");
117        public static final QName ANYTYPE = t("anyType");
118
119        private static QName t(String name) {
120            return new QName(XSD.URI, name);
121        }
122    }
123}