Search in sources :

Example 11 with MainInfo

use of com.predic8.membrane.annot.model.MainInfo in project service-proxy by membrane.

the class HelpReference method handle.

private void handle(Model m, MainInfo main) throws XMLStreamException {
    xew.writeStartElement("namespace");
    xew.writeAttribute("package", main.getAnnotation().outputPackage());
    xew.writeAttribute("targetNamespace", main.getAnnotation().targetNamespace());
    Collections.sort(main.getIis(), new Comparator<ElementInfo>() {

        @Override
        public int compare(ElementInfo o1, ElementInfo o2) {
            int res = o1.getAnnotation().name().compareTo(o2.getAnnotation().name());
            if (res == 0)
                res = o1.getElement().getQualifiedName().toString().compareTo(o2.getElement().getQualifiedName().toString());
            return res;
        }
    });
    for (ElementInfo ei : main.getIis()) handle(m, main, ei);
    xew.writeEndElement();
}
Also used : ElementInfo(com.predic8.membrane.annot.model.ElementInfo) ChildElementInfo(com.predic8.membrane.annot.model.ChildElementInfo)

Example 12 with MainInfo

use of com.predic8.membrane.annot.model.MainInfo in project service-proxy by membrane.

the class HelpReference method getFileName.

private String getFileName(Model m) {
    ArrayList<String> packages = new ArrayList<String>();
    for (MainInfo mi : m.getMains()) packages.add(mi.getAnnotation().outputPackage());
    Collections.sort(packages);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < packages.size(); i++) {
        if (i > 0)
            sb.append("-");
        sb.append(packages.get(i));
    }
    return sb.toString();
}
Also used : MainInfo(com.predic8.membrane.annot.model.MainInfo) ArrayList(java.util.ArrayList)

Example 13 with MainInfo

use of com.predic8.membrane.annot.model.MainInfo in project service-proxy by membrane.

the class Parsers method writeParserDefinitior.

public void writeParserDefinitior(Model m) throws IOException {
    for (MainInfo main : m.getMains()) {
        List<Element> sources = new ArrayList<Element>();
        sources.addAll(main.getInterceptorElements());
        sources.add(main.getElement());
        try {
            FileObject o = processingEnv.getFiler().createSourceFile(main.getAnnotation().outputPackage() + ".NamespaceHandlerAutoGenerated", sources.toArray(new Element[0]));
            BufferedWriter bw = new BufferedWriter(o.openWriter());
            try {
                bw.write("/* Copyright 2012,2013 predic8 GmbH, www.predic8.com\r\n" + "\r\n" + "   Licensed under the Apache License, Version 2.0 (the \"License\");\r\n" + "   you may not use this file except in compliance with the License.\r\n" + "   You may obtain a copy of the License at\r\n" + "\r\n" + "   http://www.apache.org/licenses/LICENSE-2.0\r\n" + "\r\n" + "   Unless required by applicable law or agreed to in writing, software\r\n" + "   distributed under the License is distributed on an \"AS IS\" BASIS,\r\n" + "   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n" + "   See the License for the specific language governing permissions and\r\n" + "   limitations under the License. */\r\n" + "\r\n" + "package " + main.getAnnotation().outputPackage() + ";\r\n" + "\r\n" + "/**\r\n" + "  * Automatically generated by " + Parsers.class.getName() + ".\r\n" + "  */\r\n" + "public class NamespaceHandlerAutoGenerated {\r\n" + "\r\n" + "	public static void registerBeanDefinitionParsers(NamespaceHandler nh) {\r\n");
                for (ElementInfo i : main.getIis()) {
                    if (i.getAnnotation().topLevel()) {
                        bw.write("		nh.registerGlobalBeanDefinitionParser(\"" + i.getAnnotation().name() + "\", new " + i.getParserClassSimpleName() + "());\r\n");
                    } else {
                        for (ChildElementDeclarationInfo cedi : i.getUsedBy()) {
                            for (ChildElementInfo cei : cedi.getUsedBy()) {
                                TypeElement element = cei.getEi().getElement();
                                String clazz = AnnotUtils.getRuntimeClassName(element);
                                bw.write("		nh.registerLocalBeanDefinitionParser(\"" + clazz + "\", \"" + i.getAnnotation().name() + "\", new " + i.getParserClassSimpleName() + "());\r\n");
                            }
                        }
                    }
                }
                bw.write("	}\r\n" + "}\r\n" + "");
            } finally {
                bw.close();
            }
        } catch (FilerException e) {
            if (e.getMessage().contains("Source file already created"))
                return;
            throw e;
        }
    }
}
Also used : ElementInfo(com.predic8.membrane.annot.model.ElementInfo) ChildElementInfo(com.predic8.membrane.annot.model.ChildElementInfo) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ArrayList(java.util.ArrayList) ChildElementInfo(com.predic8.membrane.annot.model.ChildElementInfo) BufferedWriter(java.io.BufferedWriter) MainInfo(com.predic8.membrane.annot.model.MainInfo) FileObject(javax.tools.FileObject) FilerException(javax.annotation.processing.FilerException) ChildElementDeclarationInfo(com.predic8.membrane.annot.model.ChildElementDeclarationInfo)

Example 14 with MainInfo

use of com.predic8.membrane.annot.model.MainInfo in project service-proxy by membrane.

the class Schemas method assembleElementInfo.

private void assembleElementInfo(Writer w, Model m, MainInfo main, ElementInfo i) throws IOException {
    w.append("<xsd:sequence>\r\n");
    for (ChildElementInfo cei : i.getCeis()) {
        w.append("<xsd:choice" + (cei.isRequired() ? " minOccurs=\"1\"" : " minOccurs=\"0\"") + (cei.isList() ? " maxOccurs=\"unbounded\"" : "") + ">\r\n");
        assembleDocumentation(w, i);
        for (ElementInfo ei : main.getChildElementDeclarations().get(cei.getTypeDeclaration()).getElementInfo()) {
            if (ei.getAnnotation().topLevel())
                w.append("<xsd:element ref=\"" + ei.getAnnotation().name() + "\">\r\n");
            else
                w.append("<xsd:element name=\"" + ei.getAnnotation().name() + "\" type=\"" + ei.getXSDTypeName(m) + "\">\r\n");
            assembleDocumentation(w, ei);
            w.append("</xsd:element>\r\n");
        }
        if (cei.getAnnotation().allowForeign())
            w.append("<xsd:any namespace=\"##other\" processContents=\"strict\" />\r\n");
        w.append("</xsd:choice>\r\n");
    }
    w.append("</xsd:sequence>\r\n");
    for (AttributeInfo ai : i.getAis()) if (!ai.getXMLName().equals("id"))
        assembleAttributeDeclaration(w, ai);
    if (i.getOai() != null) {
        w.append("<xsd:anyAttribute processContents=\"skip\">\r\n");
        assembleDocumentation(w, i.getOai());
        w.append("</xsd:anyAttribute>\r\n");
    }
}
Also used : AttributeInfo(com.predic8.membrane.annot.model.AttributeInfo) ElementInfo(com.predic8.membrane.annot.model.ElementInfo) ChildElementInfo(com.predic8.membrane.annot.model.ChildElementInfo) ChildElementInfo(com.predic8.membrane.annot.model.ChildElementInfo)

Example 15 with MainInfo

use of com.predic8.membrane.annot.model.MainInfo in project service-proxy by membrane.

the class Schemas method writeXSD.

public void writeXSD(Model m) throws IOException {
    try {
        for (MainInfo main : m.getMains()) {
            List<Element> sources = new ArrayList<Element>();
            sources.add(main.getElement());
            sources.addAll(main.getInterceptorElements());
            FileObject o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, main.getAnnotation().outputPackage(), main.getAnnotation().outputName(), sources.toArray(new Element[0]));
            BufferedWriter bw = new BufferedWriter(o.openWriter());
            try {
                assembleXSD(bw, m, main);
            } finally {
                bw.close();
            }
        }
    } catch (FilerException e) {
        if (e.getMessage().contains("Source file already created"))
            return;
        throw e;
    }
}
Also used : MainInfo(com.predic8.membrane.annot.model.MainInfo) Element(javax.lang.model.element.Element) ArrayList(java.util.ArrayList) FileObject(javax.tools.FileObject) FilerException(javax.annotation.processing.FilerException) BufferedWriter(java.io.BufferedWriter)

Aggregations

ChildElementInfo (com.predic8.membrane.annot.model.ChildElementInfo)11 ElementInfo (com.predic8.membrane.annot.model.ElementInfo)9 MainInfo (com.predic8.membrane.annot.model.MainInfo)9 ArrayList (java.util.ArrayList)6 FileObject (javax.tools.FileObject)6 AttributeInfo (com.predic8.membrane.annot.model.AttributeInfo)5 ChildElementDeclarationInfo (com.predic8.membrane.annot.model.ChildElementDeclarationInfo)5 BufferedWriter (java.io.BufferedWriter)5 FilerException (javax.annotation.processing.FilerException)5 Element (javax.lang.model.element.Element)5 TypeElement (javax.lang.model.element.TypeElement)5 OtherAttributesInfo (com.predic8.membrane.annot.model.OtherAttributesInfo)2 IOException (java.io.IOException)2 Model (com.predic8.membrane.annot.model.Model)1 TextContentInfo (com.predic8.membrane.annot.model.TextContentInfo)1 BufferedOutputStream (java.io.BufferedOutputStream)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Properties (java.util.Properties)1