├── .github ├── dependabot.yml └── workflows │ ├── codeql.yml │ └── pull-request-build.yml ├── .gitignore ├── boolean-test ├── pom.xml └── src │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ ├── bg │ │ └── BooleanGetterPluginTest.java │ │ └── bgi │ │ └── BooleanGetAndIsPluginTest.java │ └── resources │ └── schemas │ └── configuration │ ├── foo.xsd │ └── foo1.xsd ├── boolean ├── pom.xml └── src │ └── main │ ├── java │ ├── com │ │ └── sun │ │ │ └── tools │ │ │ └── xjc │ │ │ └── addon │ │ │ └── apache_cxf │ │ │ ├── bg │ │ │ └── BooleanGetterPlugin.java │ │ │ └── bgi │ │ │ └── BooleanGetAndIsPlugin.java │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ ├── bg │ │ └── BooleanGetterPlugin.java │ │ └── bgi │ │ └── BooleanGetAndIsPlugin.java │ └── resources │ └── META-INF │ └── services │ └── com.sun.tools.xjc.Plugin ├── bug671 ├── pom.xml └── src │ └── main │ ├── java │ ├── com │ │ └── sun │ │ │ └── tools │ │ │ └── xjc │ │ │ └── addon │ │ │ └── apache_cxf │ │ │ └── bug671 │ │ │ └── Bug671Plugin.java │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ └── bug671 │ │ └── Bug671Plugin.java │ └── resources │ └── META-INF │ └── services │ └── com.sun.tools.xjc.Plugin ├── bug986 ├── pom.xml └── src │ └── main │ ├── java │ ├── com │ │ └── sun │ │ │ └── tools │ │ │ └── xjc │ │ │ └── addon │ │ │ └── apache_cxf │ │ │ └── bug986 │ │ │ └── Bug986Plugin.java │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ └── bug986 │ │ └── Bug986Plugin.java │ └── resources │ └── META-INF │ └── services │ └── com.sun.tools.xjc.Plugin ├── cxf-xjc-plugin ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── cxf │ │ │ └── maven_plugin │ │ │ ├── AbstractXSDToJavaMojo.java │ │ │ ├── TestXSDToJavaMojo.java │ │ │ ├── XJCBuildContext.java │ │ │ ├── XJCErrorListener.java │ │ │ ├── XSDToJavaMojo.java │ │ │ ├── XSDToJavaRunner.java │ │ │ └── XsdOption.java │ └── resources │ │ └── META-INF │ │ └── m2e │ │ └── lifecycle-mapping-metadata.xml │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── cxf │ │ └── maven_plugin │ │ └── XSDToJavaRunnerTest.java │ └── resources │ └── schemas │ ├── configuration │ ├── catalog.cat │ └── wsdl.xsd │ └── wsdl │ ├── test.xjb │ └── test.xsd ├── dv-test ├── empty-elements.xml ├── pom.xml └── src │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ └── dv │ │ └── DefaultValueTest.java │ └── resources │ ├── foo-simple.xjb │ └── schemas │ └── configuration │ ├── foo-simple.xsd │ └── foo.xsd ├── dv ├── pom.xml └── src │ └── main │ ├── java │ ├── com │ │ └── sun │ │ │ └── tools │ │ │ └── xjc │ │ │ └── addon │ │ │ └── apache_cxf │ │ │ └── dv │ │ │ └── DefaultValuePlugin.java │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ └── dv │ │ ├── DefaultValuePlugin.java │ │ └── Messages.properties │ └── resources │ └── META-INF │ └── services │ └── com.sun.tools.xjc.Plugin ├── javadoc ├── pom.xml └── src │ ├── main │ ├── java │ │ ├── com │ │ │ └── sun │ │ │ │ └── tools │ │ │ │ └── xjc │ │ │ │ └── addon │ │ │ │ └── dpytel │ │ │ │ └── javadoc │ │ │ │ └── JavadocPlugin.java │ │ └── org │ │ │ └── apache │ │ │ └── cxf │ │ │ └── xjc │ │ │ └── javadoc │ │ │ ├── JavadocInserter.java │ │ │ ├── JavadocPlugin.java │ │ │ ├── MethodHelper.java │ │ │ ├── PropertyJavadoc.java │ │ │ └── XSComponentHelper.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── com.sun.tools.xjc.Plugin │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ └── javadoc │ │ ├── JavadocPluginTest.java │ │ └── JavadocTestHelper.java │ └── resources │ ├── anonymousEnum-javadoc-bindings.xjb │ ├── anonymousEnum.xsd │ ├── complexTypeWithDocumentedAttribute.xsd │ ├── complexTypeWithDocumentedProperties-javadoc-bindings.xjb │ ├── complexTypeWithDocumentedProperties.xsd │ ├── complexTypeWithoutProperties.xsd │ ├── enumDocumented-javadoc-bindings.xjb │ └── enumDocumented.xsd ├── pom.xml ├── property-listener ├── pom.xml └── src │ └── main │ ├── java │ ├── com │ │ └── sun │ │ │ └── tools │ │ │ └── xjc │ │ │ └── addon │ │ │ └── apache_cxf │ │ │ └── property_listener │ │ │ └── PropertyListenerPlugin.java │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ └── property_listener │ │ ├── Messages.properties │ │ └── PropertyListenerPlugin.java │ └── resources │ └── META-INF │ └── services │ └── com.sun.tools.xjc.Plugin ├── runtime ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ └── runtime │ │ ├── DataTypeAdapter.java │ │ ├── JAXBToStringBuilder.java │ │ └── JAXBToStringStyle.java │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ └── runtime │ │ ├── JAXBElementToStringStyleTest.java │ │ └── JAXBToStringBuilderTest.java │ └── resources │ └── binding.xml ├── ts-test ├── pom.xml └── src │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ └── ts │ │ └── ToStringTest.java │ └── resources │ └── schemas │ └── configuration │ └── foo.xsd ├── ts ├── pom.xml └── src │ └── main │ ├── java │ ├── com │ │ └── sun │ │ │ └── tools │ │ │ └── xjc │ │ │ └── addon │ │ │ └── apache_cxf │ │ │ └── ts │ │ │ └── ToStringPlugin.java │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ └── ts │ │ ├── Messages.properties │ │ └── ToStringPlugin.java │ └── resources │ └── META-INF │ └── services │ └── com.sun.tools.xjc.Plugin ├── wsdlextension-test ├── pom.xml └── src │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── cxf │ │ └── xjc │ │ └── wsdlextension │ │ └── WSDLExtensionTest.java │ └── resources │ └── schemas │ └── configuration │ └── foo.xsd └── wsdlextension ├── pom.xml └── src └── main ├── java ├── com │ └── sun │ │ └── tools │ │ └── xjc │ │ └── addon │ │ └── apache_cxf │ │ └── wsdlextension │ │ └── WSDLExtensionPlugin.java └── org │ └── apache │ └── cxf │ └── xjc │ └── wsdlextension │ ├── Messages.properties │ └── WSDLExtension.java └── resources └── META-INF └── services └── com.sun.tools.xjc.Plugin /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | version: 2 16 | updates: 17 | - package-ecosystem: "maven" 18 | directory: "/" 19 | schedule: 20 | interval: "daily" 21 | 22 | - package-ecosystem: github-actions 23 | directory: / 24 | schedule: 25 | interval: weekly 26 | 27 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ "main" ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ "main" ] 20 | schedule: 21 | - cron: '28 12 * * 5' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | # Runner size impacts CodeQL analysis time. To learn more, please see: 27 | # - https://gh.io/recommended-hardware-resources-for-running-codeql 28 | # - https://gh.io/supported-runners-and-hardware-resources 29 | # - https://gh.io/using-larger-runners 30 | # Consider using larger runners for possible analysis time improvements. 31 | runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} 32 | timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} 33 | permissions: 34 | actions: read 35 | contents: read 36 | security-events: write 37 | 38 | strategy: 39 | fail-fast: false 40 | matrix: 41 | language: [ 'java' ] 42 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] 43 | # Use only 'java' to analyze code written in Java, Kotlin or both 44 | # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both 45 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 46 | 47 | steps: 48 | - name: Checkout repository 49 | uses: actions/checkout@v4 50 | 51 | - name: Setup JDK 17 52 | uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 53 | with: 54 | distribution: 'temurin' 55 | java-version: '17' 56 | 57 | # Initializes the CodeQL tools for scanning. 58 | - name: Initialize CodeQL 59 | uses: github/codeql-action/init@v3 60 | with: 61 | languages: ${{ matrix.language }} 62 | # If you wish to specify custom queries, you can do so here or in a config file. 63 | # By default, queries listed here will override any specified in a config file. 64 | # Prefix the list here with "+" to use these queries and those in the config file. 65 | 66 | # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 67 | # queries: security-extended,security-and-quality 68 | 69 | 70 | # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). 71 | # If this step fails, then you should remove it and run the build manually (see below) 72 | - name: Autobuild 73 | uses: github/codeql-action/autobuild@v3 74 | 75 | # ℹ️ Command-line programs to run using the OS shell. 76 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 77 | 78 | # If the Autobuild fails above, remove it and uncomment the following three lines. 79 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 80 | 81 | # - run: | 82 | # echo "Run, Build Application using script" 83 | # ./location_of_script_within_repo/buildscript.sh 84 | 85 | - name: Perform CodeQL Analysis 86 | uses: github/codeql-action/analyze@v3 87 | with: 88 | category: "/language:${{matrix.language}}" 89 | -------------------------------------------------------------------------------- /.github/workflows/pull-request-build.yml: -------------------------------------------------------------------------------- 1 | name: "Build and Test" 2 | 3 | on: 4 | pull_request: 5 | branches: ['main'] 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | permissions: 14 | contents: read 15 | pull-requests: read 16 | timeout-minutes: 130 17 | steps: 18 | - uses: actions/checkout@v4 19 | - name: Set up JDK 17 20 | uses: actions/setup-java@v4 21 | with: 22 | java-version: '17' 23 | distribution: 'temurin' 24 | cache: maven 25 | - name: Build with Apache Maven 26 | run: mvn -U clean install -Djava.awt.headless=true -fae -B 27 | env: 28 | MAVEN_OPTS: "-Xmx1024M" 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | *.ipr 4 | *.iws 5 | .DS_Store 6 | .checkstyle 7 | .classpath 8 | .pmd 9 | .pmdruleset 10 | .project 11 | .ruleset 12 | .settings/ 13 | target/ 14 | velocity.log 15 | bin/ 16 | -------------------------------------------------------------------------------- /boolean-test/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf.xjcplugins.tests 22 | cxf-xjc-boolean-test 23 | jar 24 | Apache CXF XJC Boolean Getter Plugin Tests 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | jakarta.xml.bind 36 | jakarta.xml.bind-api 37 | 38 | 39 | org.glassfish.jaxb 40 | jaxb-runtime 41 | 42 | 43 | org.glassfish.jaxb 44 | jaxb-xjc 45 | 46 | 47 | 48 | junit 49 | junit 50 | test 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.apache.cxf 58 | cxf-xjc-plugin 59 | ${project.version} 60 | 61 | 62 | 63 | xsdtojava-tests 64 | 65 | 66 | 67 | 68 | 69 | 70 | true 71 | ${basedir}/src/test/resources/schemas/configuration/foo.xsd 72 | 73 | -Xbg 74 | 75 | 76 | 77 | true 78 | ${basedir}/src/test/resources/schemas/configuration/foo1.xsd 79 | 80 | -Xbgi 81 | 82 | 83 | 84 | 85 | 86 | org.apache.cxf.xjcplugins:cxf-xjc-boolean:${project.version} 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /boolean-test/src/test/java/org/apache/cxf/xjc/bg/BooleanGetterPluginTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.xjc.bg; 20 | 21 | import org.apache.cxf.configuration.foo.Foo; 22 | 23 | import org.junit.Test; 24 | 25 | public class BooleanGetterPluginTest { 26 | 27 | @Test 28 | public void testBooleanGetter() throws Exception { 29 | 30 | Foo foo = new org.apache.cxf.configuration.foo.ObjectFactory().createFoo(); 31 | 32 | foo.getBooleanAttr(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /boolean-test/src/test/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPluginTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.xjc.bgi; 20 | 21 | import org.apache.cxf.configuration.foo1.Foo; 22 | 23 | import org.junit.Test; 24 | 25 | public class BooleanGetAndIsPluginTest { 26 | 27 | @Test 28 | public void testBooleanGetAndIs() throws Exception { 29 | 30 | Foo foo = new org.apache.cxf.configuration.foo1.ObjectFactory().createFoo(); 31 | 32 | foo.getBooleanAttr(); 33 | foo.isBooleanAttr(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /boolean-test/src/test/resources/schemas/configuration/foo.xsd: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | This is a test documentation with strange UTF chars: Ã, Ã, ¢, â‚ €, für 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /boolean-test/src/test/resources/schemas/configuration/foo1.xsd: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /boolean/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf.xjcplugins 22 | cxf-xjc-boolean 23 | jar 24 | Apache CXF XJC Boolean Getter Plugin 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | true 36 | 37 | 38 | 39 | 40 | org.glassfish.jaxb 41 | jaxb-xjc 42 | provided 43 | 44 | 45 | org.glassfish.jaxb 46 | jaxb-runtime 47 | provided 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /boolean/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bg/BooleanGetterPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.sun.tools.xjc.addon.apache_cxf.bg; 21 | 22 | import org.xml.sax.ErrorHandler; 23 | import org.xml.sax.SAXException; 24 | 25 | import com.sun.tools.xjc.Options; 26 | import com.sun.tools.xjc.Plugin; 27 | import com.sun.tools.xjc.outline.Outline; 28 | 29 | /** 30 | * Thin wrapper around the BooleanGetterPlugin. This must be in the com.sun.tools.xjc.addon package for it to 31 | * work with Java 6. See https://issues.apache.org/jira/browse/CXF-1880. 32 | */ 33 | public class BooleanGetterPlugin extends Plugin { 34 | 35 | org.apache.cxf.xjc.bg.BooleanGetterPlugin impl = 36 | new org.apache.cxf.xjc.bg.BooleanGetterPlugin(); 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see com.sun.tools.xjc.Plugin#getOptionName() 42 | */ 43 | @Override 44 | public String getOptionName() { 45 | return impl.getOptionName(); 46 | } 47 | 48 | /* 49 | * (non-Javadoc) 50 | * 51 | * @see com.sun.tools.xjc.Plugin#getUsage() 52 | */ 53 | @Override 54 | public String getUsage() { 55 | return impl.getUsage(); 56 | } 57 | 58 | /* 59 | * (non-Javadoc) 60 | * 61 | * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline, com.sun.tools.xjc.Options, 62 | * org.xml.sax.ErrorHandler) 63 | */ 64 | @Override 65 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { 66 | return impl.run(outline, opt, errorHandler); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /boolean/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bgi/BooleanGetAndIsPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.sun.tools.xjc.addon.apache_cxf.bgi; 21 | 22 | import org.xml.sax.ErrorHandler; 23 | import org.xml.sax.SAXException; 24 | 25 | import com.sun.tools.xjc.Options; 26 | import com.sun.tools.xjc.Plugin; 27 | import com.sun.tools.xjc.outline.Outline; 28 | 29 | /** 30 | * Thin wrapper around the BooleanGetAndIsPlugin. This must be in the com.sun.tools.xjc.addon package for it to 31 | * work with Java 6. See https://issues.apache.org/jira/browse/CXF-1880. 32 | */ 33 | public class BooleanGetAndIsPlugin extends Plugin { 34 | 35 | org.apache.cxf.xjc.bgi.BooleanGetAndIsPlugin impl = 36 | new org.apache.cxf.xjc.bgi.BooleanGetAndIsPlugin(); 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see com.sun.tools.xjc.Plugin#getOptionName() 42 | */ 43 | @Override 44 | public String getOptionName() { 45 | return impl.getOptionName(); 46 | } 47 | 48 | /* 49 | * (non-Javadoc) 50 | * 51 | * @see com.sun.tools.xjc.Plugin#getUsage() 52 | */ 53 | @Override 54 | public String getUsage() { 55 | return impl.getUsage(); 56 | } 57 | 58 | /* 59 | * (non-Javadoc) 60 | * 61 | * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline, com.sun.tools.xjc.Options, 62 | * org.xml.sax.ErrorHandler) 63 | */ 64 | @Override 65 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { 66 | return impl.run(outline, opt, errorHandler); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /boolean/src/main/java/org/apache/cxf/xjc/bg/BooleanGetterPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.xjc.bg; 20 | 21 | import java.util.Collection; 22 | import java.util.logging.Logger; 23 | 24 | import org.xml.sax.ErrorHandler; 25 | 26 | import com.sun.codemodel.JMethod; 27 | import com.sun.tools.xjc.Options; 28 | import com.sun.tools.xjc.outline.ClassOutline; 29 | import com.sun.tools.xjc.outline.Outline; 30 | 31 | 32 | /** 33 | * Generate getters named getXXX() for Booleans instead of isXXX(). Useful to use generated beans with tools 34 | * that needs introspections, like dozer. 35 | */ 36 | public class BooleanGetterPlugin { 37 | 38 | private static final Logger LOG = Logger.getLogger(BooleanGetterPlugin.class.getName()); //NOPMD 39 | 40 | public BooleanGetterPlugin() { 41 | } 42 | 43 | public String getOptionName() { 44 | return "Xbg"; 45 | } 46 | 47 | public String getUsage() { 48 | return " -Xbg : Generate getters methods for Booleans"; 49 | } 50 | 51 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) { 52 | LOG.info("Running boolean getter plugin."); 53 | for (ClassOutline classOutline : outline.getClasses()) { 54 | Collection methods = classOutline.implClass.methods(); 55 | for (JMethod method : methods) { 56 | if (method.name().startsWith("is")) { 57 | String newName = "get" + method.name().substring(2); 58 | LOG.info("Changing method name from " + method.name() + " to " + newName); 59 | method.javadoc().add( 60 | "\nThis getter has been renamed from " + method.name() + "() to " 61 | + newName + "() by cxf-xjc-boolean plugin."); 62 | method.name(newName); 63 | } 64 | } 65 | } 66 | return true; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /boolean/src/main/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.xjc.bgi; 20 | 21 | import java.util.Collection; 22 | import java.util.HashMap; 23 | import java.util.Iterator; 24 | import java.util.Map; 25 | import java.util.Map.Entry; 26 | import java.util.logging.Logger; 27 | 28 | import org.xml.sax.ErrorHandler; 29 | 30 | import com.sun.codemodel.JBlock; 31 | import com.sun.codemodel.JMethod; 32 | import com.sun.codemodel.JMod; 33 | import com.sun.codemodel.JType; 34 | import com.sun.tools.xjc.Options; 35 | import com.sun.tools.xjc.outline.ClassOutline; 36 | import com.sun.tools.xjc.outline.Outline; 37 | 38 | /** 39 | * Generate getters named getXXX() and isXXX(). 40 | */ 41 | public class BooleanGetAndIsPlugin { 42 | 43 | private static final Logger LOG = Logger.getLogger(BooleanGetAndIsPlugin.class.getName()); //NOPMD 44 | private static final String IS_PREFIX = "is"; 45 | 46 | public BooleanGetAndIsPlugin() { 47 | } 48 | 49 | public String getOptionName() { 50 | return "Xbgi"; 51 | } 52 | 53 | public String getUsage() { 54 | return " -Xbgi : Generate getXXX and isXXX methods for Booleans"; 55 | } 56 | 57 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) { 58 | for (ClassOutline classOutline : outline.getClasses()) { 59 | processClass(classOutline); 60 | } 61 | return true; 62 | } 63 | 64 | private void processClass(ClassOutline clazz) { 65 | Collection methods = clazz.implClass.methods(); 66 | Map methodsToAdd = new HashMap(); 67 | for (JMethod method : methods) { 68 | if (method.name().startsWith(IS_PREFIX) && requiresGetter(methods, method)) { 69 | methodsToAdd.put(method.name(), method.type()); 70 | } 71 | } 72 | 73 | Iterator> todo = methodsToAdd.entrySet().iterator(); 74 | while (todo.hasNext()) { 75 | Entry entry = todo.next(); 76 | String newName = "get" + entry.getKey().substring(2); 77 | LOG.info("Adding method " + newName); 78 | JMethod newMethod = clazz.implClass.method(JMod.PUBLIC, entry.getValue(), newName); 79 | JBlock body = newMethod.body(); 80 | body.directStatement("return " + entry.getKey() + "();"); 81 | } 82 | } 83 | 84 | private boolean requiresGetter(Collection methods, JMethod method) { 85 | String newName = "get" + method.name().substring(2); 86 | // Check if already exists. 87 | for (JMethod cursor : methods) { 88 | if (newName.equals(cursor.name())) { 89 | return false; 90 | } 91 | } 92 | return true; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /boolean/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin: -------------------------------------------------------------------------------- 1 | com.sun.tools.xjc.addon.apache_cxf.bg.BooleanGetterPlugin 2 | com.sun.tools.xjc.addon.apache_cxf.bgi.BooleanGetAndIsPlugin 3 | -------------------------------------------------------------------------------- /bug671/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf.xjcplugins 22 | cxf-xjc-bug671 23 | jar 24 | Apache CXF XJC Plugin To Workaround JAXB Bug 671 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | org.glassfish.jaxb 36 | jaxb-xjc 37 | provided 38 | 39 | 40 | org.glassfish.jaxb 41 | jaxb-runtime 42 | provided 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /bug671/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bug671/Bug671Plugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.sun.tools.xjc.addon.apache_cxf.bug671; 21 | 22 | import org.xml.sax.ErrorHandler; 23 | import org.xml.sax.SAXException; 24 | 25 | import com.sun.tools.xjc.BadCommandLineException; 26 | import com.sun.tools.xjc.Options; 27 | import com.sun.tools.xjc.Plugin; 28 | import com.sun.tools.xjc.outline.Outline; 29 | 30 | /** 31 | * Thin wrapper around the Bug671Plugin. This must be in the com.sun.tools.xjc.addon package 32 | * for it to work with Java 6. See https://issues.apache.org/jira/browse/CXF-1880. 33 | */ 34 | public class Bug671Plugin extends Plugin { 35 | 36 | org.apache.cxf.xjc.bug671.Bug671Plugin impl = new org.apache.cxf.xjc.bug671.Bug671Plugin(this); 37 | 38 | /* (non-Javadoc) 39 | * @see com.sun.tools.xjc.Plugin#getOptionName() 40 | */ 41 | @Override 42 | public String getOptionName() { 43 | return impl.getOptionName(); 44 | } 45 | 46 | /* (non-Javadoc) 47 | * @see com.sun.tools.xjc.Plugin#getUsage() 48 | */ 49 | @Override 50 | public String getUsage() { 51 | return impl.getUsage(); 52 | } 53 | public void onActivated(Options opts) throws BadCommandLineException { 54 | impl.onActivated(opts); 55 | } 56 | /* (non-Javadoc) 57 | * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline, 58 | * com.sun.tools.xjc.Options, org.xml.sax.ErrorHandler) 59 | */ 60 | @Override 61 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { 62 | return true; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /bug671/src/main/java/org/apache/cxf/xjc/bug671/Bug671Plugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.xjc.bug671; 21 | 22 | import com.sun.codemodel.JJavaName; 23 | import com.sun.tools.xjc.BadCommandLineException; 24 | import com.sun.tools.xjc.Options; 25 | import com.sun.tools.xjc.Plugin; 26 | 27 | import org.glassfish.jaxb.core.api.impl.NameConverter; 28 | 29 | /** 30 | * Modifies the JAXB code model to handle package naming that run into: 31 | * https://jaxb.dev.java.net/issues/show_bug.cgi?id=671 32 | */ 33 | public class Bug671Plugin { 34 | private Plugin plugin; 35 | 36 | public Bug671Plugin(Plugin p) { 37 | plugin = p; 38 | } 39 | 40 | 41 | public String getOptionName() { 42 | return "Xbug671"; 43 | } 44 | 45 | public String getUsage() { 46 | return " -Xbug671 : Activate plugin to map package names that contain keywords"; 47 | } 48 | 49 | public void onActivated(Options opt) throws BadCommandLineException { 50 | // kind of a bogus thing to have to do to workaround bug: 51 | // https://jaxb.dev.java.net/issues/show_bug.cgi?id=671 52 | opt.setNameConverter(new NameConverter.Standard() { 53 | @Override 54 | public String toPackageName(String nsUri) { 55 | String s = super.toPackageName(nsUri); 56 | int idx = s.indexOf('.'); 57 | while (idx != -1) { 58 | ++idx; 59 | int idx2 = s.indexOf('.', idx); 60 | if (idx2 == -1) { 61 | idx2 = s.length(); 62 | } 63 | if (!JJavaName.isJavaIdentifier(s.substring(idx, idx2))) { 64 | s = s.substring(0, idx) + "_" + s.substring(idx); 65 | } 66 | idx = s.indexOf('.', idx); 67 | } 68 | return s; 69 | } 70 | 71 | }, plugin); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /bug671/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin: -------------------------------------------------------------------------------- 1 | com.sun.tools.xjc.addon.apache_cxf.bug671.Bug671Plugin -------------------------------------------------------------------------------- /bug986/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf.xjcplugins 22 | cxf-xjc-bug986 23 | jar 24 | Apache CXF XJC Plugin To Workaround JAXB Bug 986 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | org.glassfish.jaxb 36 | jaxb-xjc 37 | provided 38 | 39 | 40 | org.glassfish.jaxb 41 | jaxb-runtime 42 | provided 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /bug986/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bug986/Bug986Plugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.sun.tools.xjc.addon.apache_cxf.bug986; 21 | 22 | import org.xml.sax.ErrorHandler; 23 | import org.xml.sax.SAXException; 24 | 25 | import com.sun.tools.xjc.BadCommandLineException; 26 | import com.sun.tools.xjc.Options; 27 | import com.sun.tools.xjc.Plugin; 28 | import com.sun.tools.xjc.outline.Outline; 29 | 30 | /** 31 | * Thin wrapper around the Bug986Plugin. This must be in the com.sun.tools.xjc.addon package 32 | * for it to work with Java 6. See https://issues.apache.org/jira/browse/CXF-1880. 33 | */ 34 | public class Bug986Plugin extends Plugin { 35 | 36 | org.apache.cxf.xjc.bug986.Bug986Plugin impl = new org.apache.cxf.xjc.bug986.Bug986Plugin(this); 37 | 38 | /* (non-Javadoc) 39 | * @see com.sun.tools.xjc.Plugin#getOptionName() 40 | */ 41 | @Override 42 | public String getOptionName() { 43 | return impl.getOptionName(); 44 | } 45 | 46 | /* (non-Javadoc) 47 | * @see com.sun.tools.xjc.Plugin#getUsage() 48 | */ 49 | @Override 50 | public String getUsage() { 51 | return impl.getUsage(); 52 | } 53 | public void onActivated(Options opts) throws BadCommandLineException { 54 | 55 | } 56 | /* (non-Javadoc) 57 | * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline, 58 | * com.sun.tools.xjc.Options, org.xml.sax.ErrorHandler) 59 | */ 60 | @Override 61 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { 62 | return impl.run(outline, opt, errorHandler); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /bug986/src/main/java/org/apache/cxf/xjc/bug986/Bug986Plugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.xjc.bug986; 21 | 22 | 23 | import java.io.StringWriter; 24 | import java.lang.reflect.Field; 25 | import java.util.ArrayList; 26 | import java.util.Collection; 27 | import java.util.Collections; 28 | import java.util.List; 29 | import java.util.Map; 30 | import java.util.logging.Logger; 31 | 32 | 33 | import org.xml.sax.ErrorHandler; 34 | 35 | import com.sun.codemodel.JAnnotationUse; 36 | import com.sun.codemodel.JAnnotationValue; 37 | import com.sun.codemodel.JClass; 38 | import com.sun.codemodel.JFieldVar; 39 | import com.sun.codemodel.JFormatter; 40 | import com.sun.codemodel.JVar; 41 | import com.sun.tools.xjc.Options; 42 | import com.sun.tools.xjc.Plugin; 43 | import com.sun.tools.xjc.outline.ClassOutline; 44 | import com.sun.tools.xjc.outline.Outline; 45 | 46 | import jakarta.xml.bind.annotation.XmlSchemaType; 47 | 48 | /** 49 | * Modifies the JAXB code model to handle package naming that run into: 50 | * https://jaxb.dev.java.net/issues/show_bug.cgi?id=671 51 | */ 52 | public class Bug986Plugin { 53 | private static final Logger LOG = Logger.getLogger(Bug986Plugin.class.getName()); //NOPMD 54 | 55 | final Plugin plugin; 56 | 57 | public Bug986Plugin(Plugin p) { 58 | plugin = p; 59 | } 60 | 61 | 62 | public String getOptionName() { 63 | return "Xbug986"; 64 | } 65 | 66 | public String getUsage() { 67 | return " -Xbug986 : Activate plugin remove XmlSchemaType(anySimpleType)" 68 | + " from fields that shouldn't have it."; 69 | } 70 | 71 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) { 72 | // kind of a bogus thing to have to do to workaround bug: 73 | // https://java.net/jira/browse/JAXB-986 74 | LOG.fine("Running Bug986Plugin plugin."); 75 | for (ClassOutline classOutline : outline.getClasses()) { 76 | Map fields = classOutline.implClass.fields(); 77 | for (JFieldVar field : fields.values()) { 78 | Collection annotations = getAnnotations(field); 79 | List toRemove = new ArrayList(); 80 | for (JAnnotationUse j : annotations) { 81 | if (XmlSchemaType.class.getName().equals(getAnnotationClass(j).fullName())) { 82 | JAnnotationValue st = getAnnotationMember(j, "name"); 83 | StringWriter sw = new StringWriter(); 84 | st.generate(new JFormatter(sw)); 85 | if ("\"anySimpleType\"".equals(sw.toString())) { 86 | if (field.type().fullName().startsWith("java.util.List")) { 87 | //if it's a list of non-string types, we have to remove 88 | if (!field.type().fullName().contains("")) { 89 | toRemove.add(j); 90 | } 91 | } else if (!"java.lang.String".equals(field.type().fullName())) { 92 | //if it's not a list and it's not a string, we have to remove 93 | toRemove.add(j); 94 | } 95 | } 96 | } 97 | } 98 | for (JAnnotationUse j : toRemove) { 99 | annotations.remove(j); 100 | } 101 | } 102 | } 103 | return true; 104 | } 105 | 106 | private JAnnotationValue getAnnotationMember(JAnnotationUse ju, String name) { 107 | try { 108 | Field f = JAnnotationUse.class.getDeclaredField("memberValues"); 109 | f.setAccessible(true); 110 | @SuppressWarnings("unchecked") 111 | Map memberValues = (Map)f.get(ju); 112 | if (memberValues == null) { 113 | return null; 114 | } 115 | return memberValues.get(name); 116 | } catch (Throwable t) { 117 | //ignore for now 118 | t.printStackTrace(); 119 | } 120 | return null; 121 | } 122 | 123 | private JClass getAnnotationClass(JAnnotationUse ju) { 124 | try { 125 | Field f = JAnnotationUse.class.getDeclaredField("clazz"); 126 | f.setAccessible(true); 127 | return (JClass)f.get(ju); 128 | } catch (Throwable t) { 129 | //ignore for now 130 | t.printStackTrace(); 131 | } 132 | return null; 133 | } 134 | 135 | @SuppressWarnings("unchecked") 136 | private List getAnnotations(JFieldVar field) { 137 | try { 138 | Field f = JVar.class.getDeclaredField("annotations"); 139 | f.setAccessible(true); 140 | List anns = (List)f.get(field); 141 | if (anns == null) { 142 | anns = Collections.emptyList(); 143 | } 144 | return (List)anns; 145 | } catch (Throwable t) { 146 | //ignore for now 147 | t.printStackTrace(); 148 | } 149 | return Collections.emptyList(); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /bug986/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin: -------------------------------------------------------------------------------- 1 | com.sun.tools.xjc.addon.apache_cxf.bug986.Bug986Plugin -------------------------------------------------------------------------------- /cxf-xjc-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf 22 | cxf-xjc-plugin 23 | maven-plugin 24 | Apache CXF XSD2Java Plugin 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 3.0 35 | 36 | 37 | 38 | 39 | junit 40 | junit 41 | test 42 | 43 | 44 | org.sonatype.plexus 45 | plexus-build-api 46 | 0.0.7 47 | 48 | 49 | org.codehaus.plexus 50 | plexus-archiver 51 | 4.10.0 52 | 53 | 54 | org.apache.maven 55 | maven-plugin-api 56 | provided 57 | 58 | 59 | org.apache.maven 60 | maven-core 61 | provided 62 | 63 | 64 | org.apache.maven 65 | maven-compat 66 | provided 67 | 68 | 69 | org.apache.maven.plugin-tools 70 | maven-plugin-annotations 71 | 3.15.1 72 | provided 73 | 74 | 75 | jakarta.xml.bind 76 | jakarta.xml.bind-api 77 | 78 | 79 | org.glassfish.jaxb 80 | jaxb-xjc 81 | 82 | 83 | org.glassfish.jaxb 84 | jaxb-runtime 85 | 86 | 87 | xml-resolver 88 | xml-resolver 89 | 1.2 90 | 91 | 92 | org.javassist 93 | javassist 94 | 3.30.2-GA 95 | 96 | 97 | 98 | 99 | 100 | 101 | maven-plugin-plugin 102 | 103 | true 104 | true 105 | cxf-xjc 106 | 107 | 108 | 109 | generate-descriptor 110 | 111 | descriptor 112 | 113 | 114 | 115 | generate-helpmojo 116 | 117 | helpmojo 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | org.eclipse.m2e 128 | lifecycle-mapping 129 | 1.0.0 130 | 131 | 132 | 133 | 134 | 135 | 136 | org.apache.maven.plugins 137 | 138 | 139 | maven-plugin-plugin 140 | 141 | 142 | [3.2,) 143 | 144 | 145 | descriptor 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/TestXSDToJavaMojo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.maven_plugin; 21 | 22 | import java.util.List; 23 | 24 | import org.apache.maven.artifact.DependencyResolutionRequiredException; 25 | import org.apache.maven.plugin.MojoExecutionException; 26 | import org.apache.maven.plugins.annotations.LifecyclePhase; 27 | import org.apache.maven.plugins.annotations.Mojo; 28 | import org.apache.maven.plugins.annotations.Parameter; 29 | import org.apache.maven.plugins.annotations.ResolutionScope; 30 | 31 | @Mojo(name = "xsdtojava-tests", 32 | defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, 33 | threadSafe = true, 34 | requiresDependencyResolution = ResolutionScope.TEST 35 | ) 36 | public class TestXSDToJavaMojo extends AbstractXSDToJavaMojo { 37 | 38 | @Parameter(required = true, defaultValue = "${project.build.directory}/generated/src/test/java") 39 | String testSourceRoot; 40 | 41 | 42 | public void execute() throws MojoExecutionException { 43 | if (project != null && testSourceRoot != null) { 44 | project.addTestCompileSourceRoot(testSourceRoot); 45 | } 46 | super.execute(); 47 | } 48 | 49 | 50 | @Override 51 | String getOutputDir() { 52 | return testSourceRoot; 53 | } 54 | 55 | protected List getClasspathElements() throws DependencyResolutionRequiredException { 56 | return project.getTestClasspathElements(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/XJCBuildContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.maven_plugin; 20 | 21 | import java.io.File; 22 | import java.io.IOException; 23 | import java.io.OutputStream; 24 | import java.util.List; 25 | 26 | import org.codehaus.plexus.util.Scanner; 27 | import org.sonatype.plexus.build.incremental.BuildContext; 28 | 29 | public class XJCBuildContext implements BuildContext { 30 | public boolean hasDelta(String relpath) { 31 | return false; 32 | } 33 | public boolean hasDelta(File file) { 34 | return false; 35 | } 36 | public boolean hasDelta(@SuppressWarnings("rawtypes") List relpaths) { 37 | return false; 38 | } 39 | public void refresh(File file) { 40 | } 41 | 42 | public OutputStream newFileOutputStream(File file) throws IOException { 43 | return null; 44 | } 45 | public Scanner newScanner(File basedir) { 46 | return null; 47 | } 48 | public Scanner newDeleteScanner(File basedir) { 49 | return null; 50 | } 51 | public Scanner newScanner(File basedir, boolean ignoreDelta) { 52 | return null; 53 | } 54 | public boolean isIncremental() { 55 | return false; 56 | } 57 | public void setValue(String key, Object value) { 58 | } 59 | public Object getValue(String key) { 60 | return null; 61 | } 62 | public void addWarning(File file, int line, int column, String message, Throwable cause) { 63 | System.out.println("WARNING: " + file.getAbsolutePath()); 64 | System.out.println("Line: " + line); 65 | System.out.println("Col: " + column); 66 | System.out.println(message); 67 | if (cause != null) { 68 | cause.printStackTrace(System.out); 69 | } 70 | System.out.println(); 71 | System.out.println("DONE"); 72 | } 73 | 74 | @Override 75 | public void addError(File file, int line, int column, String message, Throwable cause) { 76 | System.err.println("ERROR: " + file.getAbsolutePath()); 77 | System.err.println("Line: " + line); 78 | System.err.println("Col: " + column); 79 | System.err.println(message); 80 | if (cause != null) { 81 | cause.printStackTrace(System.err); 82 | } 83 | System.err.println(); 84 | System.err.println("DONE"); 85 | } 86 | public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) { 87 | System.out.println("MSG: " + file.getAbsolutePath()); 88 | System.out.println("Severity: " + severity); 89 | System.out.println("Line: " + line); 90 | System.out.println("Col: " + column); 91 | System.out.println(message); 92 | if (cause != null) { 93 | cause.printStackTrace(System.out); 94 | } 95 | System.out.println(); 96 | System.out.println("DONE"); 97 | } 98 | public void removeMessages(File file) { 99 | } 100 | public boolean isUptodate(File target, File source) { 101 | return false; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/XJCErrorListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.maven_plugin; 20 | 21 | import java.io.File; 22 | import java.net.URI; 23 | import java.net.URISyntaxException; 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | import org.xml.sax.SAXParseException; 28 | 29 | import com.sun.tools.xjc.ErrorReceiver; 30 | 31 | import org.sonatype.plexus.build.incremental.BuildContext; 32 | 33 | public class XJCErrorListener extends ErrorReceiver { 34 | private BuildContext buildContext; 35 | private final List errorfiles = new ArrayList(); 36 | private Exception firstError; 37 | 38 | public XJCErrorListener(BuildContext context) { 39 | this.buildContext = context; 40 | } 41 | public Exception getFirstError() { 42 | return firstError; 43 | } 44 | 45 | public void error(Exception exception) { 46 | if (firstError == null) { 47 | firstError = exception; 48 | firstError.fillInStackTrace(); 49 | } 50 | } 51 | public void error(SAXParseException exception) { 52 | final String sysId = exception.getSystemId(); 53 | File file = mapFile(sysId); 54 | if (file != null && !errorfiles.contains(file)) { 55 | buildContext.removeMessages(file); 56 | errorfiles.add(file); 57 | } 58 | 59 | buildContext.addMessage(file, exception.getLineNumber(), exception.getColumnNumber(), 60 | mapMessage(exception.getLocalizedMessage()), 61 | BuildContext.SEVERITY_ERROR, exception); 62 | if (firstError == null) { 63 | firstError = exception; 64 | firstError.fillInStackTrace(); 65 | } 66 | } 67 | 68 | private String mapMessage(String localizedMessage) { 69 | return localizedMessage; 70 | } 71 | 72 | private File mapFile(String s) { 73 | File file = null; 74 | if (s != null && s.startsWith("file:")) { 75 | if (s.contains("#")) { 76 | s = s.substring(0, s.indexOf('#')); 77 | } 78 | try { 79 | URI uri = new URI(s); 80 | file = new File(uri); 81 | } catch (URISyntaxException e) { 82 | //ignore 83 | } 84 | } 85 | if (file == null) { 86 | //Cannot pass a null into buildContext.addMessage. Create a pointless 87 | //File object that maps to the systemId 88 | if (s == null) { 89 | file = new File("null"); 90 | } else { 91 | final String s2 = s; 92 | file = new File(s2) { 93 | private static final long serialVersionUID = 1L; 94 | public String getAbsolutePath() { 95 | return s2; 96 | } 97 | }; 98 | } 99 | } 100 | return file; 101 | } 102 | 103 | public void fatalError(SAXParseException exception) { 104 | error(exception); 105 | if (firstError == null) { 106 | firstError = exception; 107 | firstError.fillInStackTrace(); 108 | } 109 | } 110 | 111 | public void warning(SAXParseException exception) { 112 | File file = mapFile(exception.getSystemId()); 113 | if (file != null && !errorfiles.contains(file)) { 114 | buildContext.removeMessages(file); 115 | errorfiles.add(file); 116 | } 117 | buildContext.addMessage(file, exception.getLineNumber(), exception.getColumnNumber(), 118 | mapMessage(exception.getLocalizedMessage()), 119 | BuildContext.SEVERITY_WARNING, exception); 120 | } 121 | 122 | public void info(SAXParseException exception) { 123 | //System.out.println(mapFile(exception.getSystemId())); 124 | } 125 | public void message(File file, String string) { 126 | buildContext.addMessage(file, 0, 0, 127 | mapMessage(string), 128 | BuildContext.SEVERITY_ERROR, null); 129 | } 130 | public void warning(File file, Exception e) { 131 | buildContext.addMessage(file, 0, 0, 132 | mapMessage(e.getLocalizedMessage()), 133 | BuildContext.SEVERITY_WARNING, e); 134 | } 135 | } -------------------------------------------------------------------------------- /cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/XSDToJavaMojo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.maven_plugin; 21 | 22 | import org.apache.maven.plugin.MojoExecutionException; 23 | import org.apache.maven.plugins.annotations.LifecyclePhase; 24 | import org.apache.maven.plugins.annotations.Mojo; 25 | import org.apache.maven.plugins.annotations.Parameter; 26 | import org.apache.maven.plugins.annotations.ResolutionScope; 27 | 28 | @Mojo(name = "xsdtojava", 29 | defaultPhase = LifecyclePhase.GENERATE_SOURCES, 30 | threadSafe = true, 31 | requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME 32 | ) 33 | public class XSDToJavaMojo extends AbstractXSDToJavaMojo { 34 | @Parameter(required = true, defaultValue = "${project.build.directory}/generated/src/main/java") 35 | String sourceRoot; 36 | 37 | public void execute() throws MojoExecutionException { 38 | if (project != null && sourceRoot != null) { 39 | project.addCompileSourceRoot(sourceRoot); 40 | } 41 | super.execute(); 42 | } 43 | 44 | 45 | @Override 46 | String getOutputDir() { 47 | return sourceRoot; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/XsdOption.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.maven_plugin; 21 | 22 | import java.io.File; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | public class XsdOption { 27 | String xsd; 28 | String xsdDir; 29 | String packagename; 30 | File[] dependencies; 31 | File[] redundantDirs; 32 | boolean extension; 33 | List extensionArgs; 34 | List bindingFiles; 35 | String catalog; 36 | 37 | public String getPackagename() { 38 | return packagename; 39 | } 40 | public void setPackagename(String pn) { 41 | this.packagename = pn; 42 | } 43 | public String getXsd() { 44 | return xsd; 45 | } 46 | public void setXsd(String x) { 47 | this.xsd = x; 48 | } 49 | public String getXsdDir() { 50 | return xsdDir; 51 | } 52 | public void setXsdDir(String x) { 53 | this.xsdDir = x; 54 | } 55 | public String getBindingFile() { 56 | if (bindingFiles != null && !bindingFiles.isEmpty()) { 57 | return bindingFiles.get(0); 58 | } 59 | return null; 60 | } 61 | public void setBindingFile(String bf) { 62 | if (bindingFiles == null) { 63 | bindingFiles = new ArrayList<>(); 64 | bindingFiles.add(bf); 65 | } else { 66 | bindingFiles.clear(); 67 | bindingFiles.add(bf); 68 | } 69 | } 70 | public List getBindingFiles() { 71 | return bindingFiles; 72 | } 73 | public void setBindingFiles(List bindingFiles) { 74 | this.bindingFiles = bindingFiles; 75 | } 76 | public void setDependencies(File[] files) { 77 | dependencies = files; 78 | } 79 | public File[] getDependencies() { 80 | return dependencies; 81 | } 82 | 83 | public void setDeleteDirs(File[] files) { 84 | redundantDirs = files; 85 | } 86 | public File[] getDeleteDirs() { 87 | return redundantDirs; 88 | } 89 | public List getExtensionArgs() { 90 | return extensionArgs; 91 | } 92 | public void setExtensionArgs(List extensionArgs) { 93 | this.extensionArgs = extensionArgs; 94 | } 95 | public boolean isExtension() { 96 | return extension; 97 | } 98 | public void setExtension(boolean extension) { 99 | this.extension = extension; 100 | } 101 | public String getCatalog() { 102 | return catalog; 103 | } 104 | public void setCatalogFile(String c) { 105 | catalog = c; 106 | } 107 | 108 | 109 | } 110 | -------------------------------------------------------------------------------- /cxf-xjc-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | xsdtojava 7 | 8 | 9 | 10 | 11 | true 12 | true 13 | 14 | 15 | 16 | 17 | 18 | 19 | xsdtojava-tests 20 | 21 | 22 | 23 | 24 | true 25 | true 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /cxf-xjc-plugin/src/test/java/org/apache/cxf/maven_plugin/XSDToJavaRunnerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.maven_plugin; 21 | 22 | import java.io.File; 23 | import java.util.Collections; 24 | 25 | import org.sonatype.plexus.build.incremental.BuildContext; 26 | 27 | import org.junit.Rule; 28 | import org.junit.Test; 29 | import org.junit.rules.TemporaryFolder; 30 | 31 | import static org.hamcrest.CoreMatchers.is; 32 | import static org.hamcrest.CoreMatchers.nullValue; 33 | import static org.junit.Assert.assertThat; 34 | 35 | public class XSDToJavaRunnerTest { 36 | @Rule public TemporaryFolder outputFolder = new TemporaryFolder(); 37 | 38 | @Test 39 | public void testCatalogAndBindings() throws Exception { 40 | final BuildContext context = new XJCBuildContext(); 41 | final XJCErrorListener listener = new XJCErrorListener(context); 42 | 43 | final File outputFile = outputFolder.newFile(); 44 | final String xjb = getClass().getResource("/schemas/wsdl/test.xjb").toExternalForm(); 45 | final String xsd = getClass().getResource("/schemas/wsdl/test.xsd").toExternalForm(); 46 | final String catalog = getClass().getResource("/schemas/configuration/catalog.cat").toExternalForm(); 47 | 48 | new XSDToJavaRunner( 49 | new String [] { 50 | "-catalog", catalog, 51 | "-b", xjb, 52 | xsd 53 | }, 54 | listener, 55 | outputFile, 56 | Collections.emptyList()).run(); 57 | 58 | assertThat(listener.getFirstError(), is(nullValue())); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /cxf-xjc-plugin/src/test/resources/schemas/configuration/catalog.cat: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /cxf-xjc-plugin/src/test/resources/schemas/configuration/wsdl.xsd: -------------------------------------------------------------------------------- 1 | 2 | 32 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /cxf-xjc-plugin/src/test/resources/schemas/wsdl/test.xjb: -------------------------------------------------------------------------------- 1 | 2 | 20 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /cxf-xjc-plugin/src/test/resources/schemas/wsdl/test.xsd: -------------------------------------------------------------------------------- 1 | 2 | 20 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /dv-test/empty-elements.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 76 22 | 23 | -------------------------------------------------------------------------------- /dv-test/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf.xjcplugins.tests 22 | cxf-xjc-dv-test 23 | jar 24 | Apache CXF XJC Default Value Plugin Tests 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | jakarta.xml.bind 39 | jakarta.xml.bind-api 40 | 41 | 42 | org.glassfish.jaxb 43 | jaxb-runtime 44 | 45 | 46 | org.glassfish.jaxb 47 | jaxb-xjc 48 | 49 | 50 | 51 | junit 52 | junit 53 | test 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.apache.cxf 61 | cxf-xjc-plugin 62 | ${project.version} 63 | 64 | 65 | foo 66 | 67 | xsdtojava-tests 68 | 69 | 70 | 71 | 72 | true 73 | ${basedir}/src/test/resources/schemas/configuration/foo.xsd 74 | 75 | -Xdv 76 | 77 | 78 | 79 | 80 | org.apache.cxf.xjcplugins:cxf-xjc-dv:${project.version} 81 | 82 | 83 | 84 | 85 | foo-simple 86 | 87 | xsdtojava-tests 88 | 89 | 90 | 91 | 92 | true 93 | ${basedir}/src/test/resources/schemas/configuration/foo-simple.xsd 94 | ${basedir}/src/test/resources/foo-simple.xjb 95 | 96 | -Xdv 97 | 98 | 99 | 100 | 101 | org.apache.cxf.xjcplugins:cxf-xjc-dv:${project.version} 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /dv-test/src/test/resources/foo-simple.xjb: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /dv-test/src/test/resources/schemas/configuration/foo-simple.xsd: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /dv/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf.xjcplugins 22 | cxf-xjc-dv 23 | jar 24 | Apache CXF XJC Default Value Plugin 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | org.glassfish.jaxb 36 | jaxb-xjc 37 | provided 38 | 39 | 40 | org.glassfish.jaxb 41 | jaxb-runtime 42 | provided 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /dv/src/main/java/com/sun/tools/xjc/addon/apache_cxf/dv/DefaultValuePlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.sun.tools.xjc.addon.apache_cxf.dv; 21 | 22 | import java.io.IOException; 23 | 24 | import org.xml.sax.ErrorHandler; 25 | import org.xml.sax.SAXException; 26 | 27 | import com.sun.tools.xjc.BadCommandLineException; 28 | import com.sun.tools.xjc.Options; 29 | import com.sun.tools.xjc.Plugin; 30 | import com.sun.tools.xjc.outline.Outline; 31 | 32 | /** 33 | * Thin wrapper around the DefaultValuePlugin. This must be in the com.sun.tools.xjc.addon package 34 | * for it to work with Java 6. See https://issues.apache.org/jira/browse/CXF-1880. 35 | */ 36 | public class DefaultValuePlugin extends Plugin { 37 | 38 | org.apache.cxf.xjc.dv.DefaultValuePlugin impl = new org.apache.cxf.xjc.dv.DefaultValuePlugin(); 39 | 40 | /* (non-Javadoc) 41 | * @see com.sun.tools.xjc.Plugin#getOptionName() 42 | */ 43 | @Override 44 | public String getOptionName() { 45 | return impl.getOptionName(); 46 | } 47 | 48 | /* (non-Javadoc) 49 | * @see com.sun.tools.xjc.Plugin#getUsage() 50 | */ 51 | @Override 52 | public String getUsage() { 53 | return impl.getUsage(); 54 | } 55 | 56 | /* (non-Javadoc) 57 | * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline, 58 | * com.sun.tools.xjc.Options, org.xml.sax.ErrorHandler) 59 | */ 60 | @Override 61 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { 62 | return impl.run(outline, opt, errorHandler); 63 | } 64 | 65 | public void onActivated(Options opts) throws BadCommandLineException { 66 | impl.onActivated(opts); 67 | } 68 | 69 | 70 | /* (non-Javadoc) 71 | * @see com.sun.tools.xjc.Plugin#parseArgument(com.sun.tools.xjc.Options, java.lang.String[], int) 72 | */ 73 | @Override 74 | public int parseArgument(Options opt, String[] args, int index) 75 | throws BadCommandLineException, IOException { 76 | 77 | return impl.parseArgument(opt, args, index, this); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /dv/src/main/java/org/apache/cxf/xjc/dv/Messages.properties: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | # 21 | -------------------------------------------------------------------------------- /dv/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin: -------------------------------------------------------------------------------- 1 | com.sun.tools.xjc.addon.apache_cxf.dv.DefaultValuePlugin -------------------------------------------------------------------------------- /javadoc/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf.xjcplugins 22 | cxf-xjc-javadoc 23 | jar 24 | Apache CXF XJC JavaDoc Plugin 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | 36 | org.glassfish.jaxb 37 | jaxb-xjc 38 | 39 | 40 | org.glassfish.jaxb 41 | jaxb-runtime 42 | 43 | 44 | junit 45 | junit 46 | test 47 | 48 | 49 | org.eclipse.platform 50 | org.eclipse.equinox.app 51 | 1.7.0 52 | test 53 | 54 | 55 | org.eclipse.jdt 56 | org.eclipse.jdt.core 57 | 3.37.0 58 | test 59 | 60 | 61 | com.cedarsoft.commons 62 | io 63 | 8.9.2 64 | test 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /javadoc/src/main/java/com/sun/tools/xjc/addon/dpytel/javadoc/JavadocPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.sun.tools.xjc.addon.dpytel.javadoc; 20 | 21 | import org.xml.sax.ErrorHandler; 22 | import org.xml.sax.SAXException; 23 | 24 | import com.sun.tools.xjc.Options; 25 | import com.sun.tools.xjc.Plugin; 26 | import com.sun.tools.xjc.outline.Outline; 27 | 28 | /** 29 | * Thin wrapper around the DefaultValuePlugin. This must be in the com.sun.tools.xjc.addon package for it to 30 | * work with Java 6. See https://issues.apache.org/jira/browse/CXF-1880. 31 | */ 32 | public class JavadocPlugin extends Plugin { 33 | 34 | private org.apache.cxf.xjc.javadoc.JavadocPlugin impl = new org.apache.cxf.xjc.javadoc.JavadocPlugin(); 35 | 36 | /* 37 | * (non-Javadoc) 38 | * @see com.sun.tools.xjc.Plugin#getOptionName() 39 | */ 40 | @Override 41 | public String getOptionName() { 42 | return impl.getOptionName(); 43 | } 44 | 45 | /* 46 | * (non-Javadoc) 47 | * @see com.sun.tools.xjc.Plugin#getUsage() 48 | */ 49 | @Override 50 | public String getUsage() { 51 | return impl.getUsage(); 52 | } 53 | 54 | /* 55 | * (non-Javadoc) 56 | * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline, com.sun.tools.xjc.Options, 57 | * org.xml.sax.ErrorHandler) 58 | */ 59 | @Override 60 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { 61 | return impl.run(outline, opt, errorHandler); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /javadoc/src/main/java/org/apache/cxf/xjc/javadoc/JavadocInserter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.xjc.javadoc; 20 | 21 | import java.util.Collection; 22 | 23 | import javax.xml.namespace.QName; 24 | 25 | import org.xml.sax.ErrorHandler; 26 | 27 | import com.sun.tools.xjc.Options; 28 | import com.sun.tools.xjc.model.CEnumLeafInfo; 29 | import com.sun.tools.xjc.outline.ClassOutline; 30 | import com.sun.tools.xjc.outline.EnumOutline; 31 | import com.sun.tools.xjc.outline.FieldOutline; 32 | import com.sun.tools.xjc.outline.Outline; 33 | import com.sun.tools.xjc.reader.xmlschema.Messages; 34 | import com.sun.xml.xsom.XSComponent; 35 | 36 | /** 37 | * @author Dawid Pytel 38 | */ 39 | public class JavadocInserter { 40 | 41 | private Outline outline; 42 | private Options options; 43 | 44 | public JavadocInserter(Outline outline, Options opt, ErrorHandler errorHandler) { 45 | this.outline = outline; 46 | this.options = opt; 47 | } 48 | 49 | /** 50 | * @return true if successful 51 | */ 52 | public boolean addJavadocs() { 53 | addJavadocsToClasses(); 54 | addJavadocsToEnums(); 55 | return false; 56 | } 57 | 58 | private void addJavadocsToClasses() { 59 | for (ClassOutline classOutline : outline.getClasses()) { 60 | addJavadocs(classOutline); 61 | } 62 | } 63 | 64 | private void addJavadocs(ClassOutline classOutline) { 65 | FieldOutline[] declaredFields = classOutline.getDeclaredFields(); 66 | for (FieldOutline fieldOutline : declaredFields) { 67 | PropertyJavadoc propertyJavadoc = new PropertyJavadoc(outline.getCodeModel(), options, 68 | classOutline, fieldOutline); 69 | propertyJavadoc.addJavadocs(); 70 | } 71 | } 72 | 73 | private void addJavadocsToEnums() { 74 | Collection enums = outline.getEnums(); 75 | for (EnumOutline enumOutline : enums) { 76 | addJavadoc(enumOutline); 77 | } 78 | } 79 | 80 | private void addJavadoc(EnumOutline enumOutline) { 81 | if (isCustomBindingApplied(enumOutline)) { 82 | return; // JAXB binding customization overwrites xsd:documentation 83 | } 84 | XSComponent schemaComponent = enumOutline.target.getSchemaComponent(); 85 | String documentation = XSComponentHelper.getDocumentation(schemaComponent); 86 | if (documentation == null || "".equals(documentation)) { 87 | return; 88 | } 89 | enumOutline.clazz.javadoc().add(0, documentation + "\n\n"); 90 | } 91 | 92 | private boolean isCustomBindingApplied(EnumOutline enumOutline) { 93 | CEnumLeafInfo target = enumOutline.target; 94 | QName typeName = target.getTypeName(); 95 | // typeName may be null on anonymous simple types 96 | if (typeName == null) { 97 | return false; 98 | } 99 | String defaultComment = Messages.format("ClassSelector.JavadocHeading", 100 | typeName.getLocalPart()); 101 | // not very clean but the only way of determining whether Javadoc 102 | // customization has been applied 103 | return !target.javadoc.startsWith(defaultComment); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /javadoc/src/main/java/org/apache/cxf/xjc/javadoc/JavadocPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.xjc.javadoc; 20 | 21 | import org.xml.sax.ErrorHandler; 22 | import org.xml.sax.SAXException; 23 | 24 | import com.sun.tools.xjc.Options; 25 | import com.sun.tools.xjc.Plugin; 26 | import com.sun.tools.xjc.outline.Outline; 27 | 28 | /** 29 | * Generates Javadocs based on xsd:documentation. 30 | * 31 | * @author Dawid Pytel 32 | */ 33 | public class JavadocPlugin extends Plugin { 34 | 35 | /* 36 | * (non-Javadoc) 37 | * @see com.sun.tools.xjc.Plugin#getOptionName() 38 | */ 39 | @Override 40 | public String getOptionName() { 41 | return "Xjavadoc"; 42 | } 43 | 44 | /* 45 | * (non-Javadoc) 46 | * @see com.sun.tools.xjc.Plugin#getUsage() 47 | */ 48 | @Override 49 | public String getUsage() { 50 | return " -Xjavadoc : Generates Javadocs based on xsd:documentation."; 51 | } 52 | 53 | /* 54 | * (non-Javadoc) 55 | * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline, com.sun.tools.xjc.Options, 56 | * org.xml.sax.ErrorHandler) 57 | */ 58 | @Override 59 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { 60 | JavadocInserter javadocInserter = new JavadocInserter(outline, opt, errorHandler); 61 | return javadocInserter.addJavadocs(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /javadoc/src/main/java/org/apache/cxf/xjc/javadoc/MethodHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.xjc.javadoc; 20 | 21 | import java.util.Collection; 22 | 23 | import com.sun.codemodel.JMethod; 24 | import com.sun.tools.xjc.outline.ClassOutline; 25 | 26 | public final class MethodHelper { 27 | 28 | private MethodHelper() { 29 | // no constructor for helper class 30 | } 31 | 32 | /** 33 | * Find method in given class with given method name 34 | * 35 | * @param classOutline 36 | * @param methodName 37 | * @return method in given class with given method name 38 | */ 39 | public static JMethod findMethod(ClassOutline classOutline, String methodName) { 40 | Collection methods = classOutline.implClass.methods(); 41 | for (JMethod method : methods) { 42 | if (method.name().equals(methodName)) { 43 | return method; 44 | } 45 | } 46 | return null; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /javadoc/src/main/java/org/apache/cxf/xjc/javadoc/PropertyJavadoc.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.xjc.javadoc; 20 | 21 | import com.sun.codemodel.JCodeModel; 22 | import com.sun.codemodel.JDocComment; 23 | import com.sun.codemodel.JFieldVar; 24 | import com.sun.codemodel.JMethod; 25 | import com.sun.codemodel.JType; 26 | import com.sun.tools.xjc.Options; 27 | import com.sun.tools.xjc.model.CPropertyInfo; 28 | import com.sun.tools.xjc.outline.ClassOutline; 29 | import com.sun.tools.xjc.outline.FieldOutline; 30 | import com.sun.xml.xsom.XSAttributeUse; 31 | import com.sun.xml.xsom.XSComponent; 32 | import com.sun.xml.xsom.XSParticle; 33 | 34 | public class PropertyJavadoc { 35 | 36 | private JCodeModel codeModel; 37 | 38 | private Options options; 39 | 40 | private ClassOutline classOutline; 41 | 42 | private FieldOutline fieldOutline; 43 | 44 | public PropertyJavadoc(JCodeModel codeModel, Options options, ClassOutline classOutline, 45 | FieldOutline fieldOutline) { 46 | this.codeModel = codeModel; 47 | this.options = options; 48 | this.classOutline = classOutline; 49 | this.fieldOutline = fieldOutline; 50 | } 51 | 52 | public void addJavadocs() { 53 | CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo(); 54 | if (propertyInfo == null) { 55 | return; 56 | } 57 | if (propertyInfo.javadoc.length() > 0) { 58 | return; // JAXB binding customization overwrites xsd:documentation 59 | } 60 | XSComponent component = getDocumentedComponent(propertyInfo); 61 | 62 | String documentation = XSComponentHelper.getDocumentation(component); 63 | if (documentation == null || "".equals(documentation.trim())) { 64 | return; 65 | } 66 | setJavadoc(documentation.trim()); 67 | } 68 | 69 | private XSComponent getDocumentedComponent(CPropertyInfo propertyInfo) { 70 | XSComponent schemaComponent = propertyInfo.getSchemaComponent(); 71 | if (schemaComponent instanceof XSParticle) { 72 | return ((XSParticle)schemaComponent).getTerm(); 73 | } else if (schemaComponent instanceof XSAttributeUse) { 74 | return ((XSAttributeUse)schemaComponent).getDecl(); 75 | } else { 76 | return null; 77 | } 78 | } 79 | 80 | private void setJavadoc(String documentation) { 81 | setJavadocToField(documentation); 82 | setJavadocToGetter(documentation); 83 | setSeeTagToSetter(); 84 | } 85 | 86 | private void setJavadocToField(String documentation) { 87 | JFieldVar fieldVar = classOutline.implClass.fields().get(fieldOutline.getPropertyInfo() 88 | .getName(false)); 89 | if (fieldVar == null) { 90 | return; 91 | } 92 | fieldVar.javadoc().append(documentation); 93 | } 94 | 95 | private void setJavadocToGetter(String documentation) { 96 | String getterMethod = getGetterMethod(); 97 | JMethod getter = MethodHelper.findMethod(classOutline, getterMethod); 98 | JDocComment javadoc = getter.javadoc(); 99 | if (javadoc.size() != 0) { 100 | documentation = "\n

\n" + documentation; 101 | } 102 | javadoc.add(javadoc.size(), documentation); // add comment as last 103 | // non-tag element 104 | } 105 | 106 | private void setSeeTagToSetter() { 107 | JMethod setterMethod = MethodHelper.findMethod(classOutline, "set" 108 | + fieldOutline.getPropertyInfo() 109 | .getName(true)); 110 | if (setterMethod == null) { 111 | return; 112 | } 113 | setterMethod.javadoc().addXdoclet("see #" + getGetterMethod() + "()"); 114 | } 115 | 116 | private String getGetterMethod() { 117 | JType type = fieldOutline.getRawType(); 118 | if (options.enableIntrospection) { 119 | return ((type.isPrimitive() && type.boxify().getPrimitiveType() == codeModel.BOOLEAN) 120 | ? "is" : "get") + fieldOutline.getPropertyInfo().getName(true); 121 | } 122 | return (type.boxify().getPrimitiveType() == codeModel.BOOLEAN ? "is" : "get") 123 | + fieldOutline.getPropertyInfo().getName(true); 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /javadoc/src/main/java/org/apache/cxf/xjc/javadoc/XSComponentHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.xjc.javadoc; 20 | 21 | import com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo; 22 | import com.sun.xml.xsom.XSAnnotation; 23 | import com.sun.xml.xsom.XSComponent; 24 | 25 | public final class XSComponentHelper { 26 | 27 | private XSComponentHelper() { 28 | // no constructor for utility class 29 | } 30 | 31 | public static String getDocumentation(XSComponent schemaComponent) { 32 | if (schemaComponent == null) { 33 | return null; 34 | } 35 | XSAnnotation xsAnnotation = schemaComponent.getAnnotation(); 36 | if (xsAnnotation == null) { 37 | return null; 38 | } 39 | BindInfo annotation = (BindInfo)xsAnnotation.getAnnotation(); 40 | if (annotation == null) { 41 | return null; 42 | } 43 | return annotation.getDocumentation(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /javadoc/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin: -------------------------------------------------------------------------------- 1 | org.apache.cxf.xjc.javadoc.JavadocPlugin -------------------------------------------------------------------------------- /javadoc/src/test/java/org/apache/cxf/xjc/javadoc/JavadocTestHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.xjc.javadoc; 20 | 21 | import java.util.List; 22 | 23 | import org.eclipse.jdt.core.dom.Javadoc; 24 | import org.eclipse.jdt.core.dom.TagElement; 25 | import org.hamcrest.Description; 26 | import org.hamcrest.Matcher; 27 | import org.hamcrest.TypeSafeMatcher; 28 | 29 | /** 30 | * Utility methods for tests 31 | * 32 | * @author Dawid Pytel 33 | */ 34 | public final class JavadocTestHelper { 35 | private JavadocTestHelper() { 36 | //utility class 37 | } 38 | 39 | public static Matcher javadocContains(final String comment) { 40 | return new TypeSafeMatcher(Javadoc.class) { 41 | 42 | @Override 43 | protected boolean matchesSafely(Javadoc javadoc) { 44 | if (!javadoc.tags().isEmpty()) { 45 | TagElement tagElement = (TagElement)javadoc.tags().get(0); 46 | List fragments = tagElement.fragments(); 47 | for (Object fragment : fragments) { 48 | if (fragment != null && fragment.toString().contains(comment)) { 49 | return true; 50 | } 51 | } 52 | } 53 | return false; 54 | } 55 | 56 | public void describeTo(Description description) { 57 | description.appendText("javadoc contains given comment: " + comment); 58 | } 59 | }; 60 | } 61 | 62 | public static Matcher containsTag(final String tagName, final String tagValue) { 63 | return new TypeSafeMatcher(Javadoc.class) { 64 | 65 | @Override 66 | protected boolean matchesSafely(Javadoc javadoc) { 67 | @SuppressWarnings("unchecked") 68 | List tags = javadoc.tags(); 69 | for (TagElement tagElement : tags) { 70 | if (tagName.equals(tagElement.getTagName())) { 71 | return tagValue.equals(tagElement.fragments().get(0).toString()); 72 | } 73 | } 74 | 75 | return false; 76 | } 77 | 78 | public void describeTo(Description description) { 79 | description.appendText("javadoc contains tag " + tagName + " " + tagValue); 80 | } 81 | }; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /javadoc/src/test/resources/anonymousEnum-javadoc-bindings.xjb: -------------------------------------------------------------------------------- 1 | 19 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /javadoc/src/test/resources/anonymousEnum.xsd: -------------------------------------------------------------------------------- 1 | 2 | 20 | 22 | 23 | 24 | 25 | 26 | Documentation of anonymous enum simpleType 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /javadoc/src/test/resources/complexTypeWithDocumentedAttribute.xsd: -------------------------------------------------------------------------------- 1 | 2 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | Documentation of attribute 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /javadoc/src/test/resources/complexTypeWithDocumentedProperties-javadoc-bindings.xjb: -------------------------------------------------------------------------------- 1 | 19 | 25 | 26 | 27 | Documentation from JAXB binding customization 28 | 29 | 30 | -------------------------------------------------------------------------------- /javadoc/src/test/resources/complexTypeWithDocumentedProperties.xsd: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | Some documentation of element 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /javadoc/src/test/resources/complexTypeWithoutProperties.xsd: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /javadoc/src/test/resources/enumDocumented-javadoc-bindings.xjb: -------------------------------------------------------------------------------- 1 | 19 | 25 | 26 | 27 | Documentation from JAXB binding customization 28 | 29 | 30 | -------------------------------------------------------------------------------- /javadoc/src/test/resources/enumDocumented.xsd: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | Documentation of enumDocumented 24 | 25 | 26 | 27 | 28 | Documentation of ONE 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /property-listener/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf.xjcplugins 22 | cxf-xjc-pl 23 | jar 24 | Apache CXF XJC Property Listener Plugin 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | org.glassfish.jaxb 36 | jaxb-xjc 37 | provided 38 | 39 | 40 | org.glassfish.jaxb 41 | jaxb-runtime 42 | provided 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /property-listener/src/main/java/com/sun/tools/xjc/addon/apache_cxf/property_listener/PropertyListenerPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.sun.tools.xjc.addon.apache_cxf.property_listener; 21 | 22 | import org.xml.sax.ErrorHandler; 23 | import org.xml.sax.SAXException; 24 | 25 | import com.sun.tools.xjc.Options; 26 | import com.sun.tools.xjc.Plugin; 27 | import com.sun.tools.xjc.outline.Outline; 28 | 29 | /** 30 | * Thin wrapper around the DefaultValuePlugin. This must be in the com.sun.tools.xjc.addon package 31 | * for it to work with Java 6. See https://issues.apache.org/jira/browse/CXF-1880. 32 | */ 33 | public class PropertyListenerPlugin extends Plugin { 34 | 35 | org.apache.cxf.xjc.property_listener.PropertyListenerPlugin impl 36 | = new org.apache.cxf.xjc.property_listener.PropertyListenerPlugin(); 37 | 38 | /* (non-Javadoc) 39 | * @see com.sun.tools.xjc.Plugin#getOptionName() 40 | */ 41 | @Override 42 | public String getOptionName() { 43 | return impl.getOptionName(); 44 | } 45 | 46 | /* (non-Javadoc) 47 | * @see com.sun.tools.xjc.Plugin#getUsage() 48 | */ 49 | @Override 50 | public String getUsage() { 51 | return impl.getUsage(); 52 | } 53 | 54 | /* (non-Javadoc) 55 | * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline, 56 | * com.sun.tools.xjc.Options, org.xml.sax.ErrorHandler) 57 | */ 58 | @Override 59 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { 60 | return impl.run(outline, opt, errorHandler); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /property-listener/src/main/java/org/apache/cxf/xjc/property_listener/Messages.properties: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | # 21 | -------------------------------------------------------------------------------- /property-listener/src/main/java/org/apache/cxf/xjc/property_listener/PropertyListenerPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.xjc.property_listener; 21 | 22 | import java.beans.PropertyChangeListener; 23 | import java.beans.PropertyChangeSupport; 24 | import java.lang.reflect.Field; 25 | import java.lang.reflect.Modifier; 26 | import java.util.List; 27 | import java.util.logging.Logger; 28 | 29 | 30 | import org.xml.sax.ErrorHandler; 31 | 32 | import com.sun.codemodel.JAssignment; 33 | import com.sun.codemodel.JExpr; 34 | import com.sun.codemodel.JExpression; 35 | import com.sun.codemodel.JFieldRef; 36 | import com.sun.codemodel.JFieldVar; 37 | import com.sun.codemodel.JMethod; 38 | import com.sun.codemodel.JType; 39 | import com.sun.codemodel.JVar; 40 | import com.sun.tools.xjc.Options; 41 | import com.sun.tools.xjc.outline.ClassOutline; 42 | import com.sun.tools.xjc.outline.Outline; 43 | 44 | import jakarta.xml.bind.annotation.XmlTransient; 45 | 46 | /** 47 | * Modifies the JAXB code model to add a PropertyChangeListener to the 48 | * setter methods 49 | */ 50 | public class PropertyListenerPlugin { 51 | 52 | private static final Logger LOG = Logger.getLogger(PropertyListenerPlugin.class.getName()); //NOPMD 53 | 54 | public PropertyListenerPlugin() { 55 | } 56 | 57 | public String getOptionName() { 58 | return "Xproperty-listener"; 59 | } 60 | 61 | public String getUsage() { 62 | return " -Xproperty-listener : Adds a PropertyChangeListener to all the set methods"; 63 | } 64 | 65 | 66 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) { 67 | LOG.fine("Running property-listener plugin."); 68 | for (ClassOutline co : outline.getClasses()) { 69 | if (co.getDeclaredFields().length == 0) { 70 | continue; 71 | } 72 | 73 | //add listener support 74 | JType listenerType = co.parent().getCodeModel()._ref(PropertyChangeSupport.class); 75 | JFieldVar newVar = co.implClass.field(Modifier.PRIVATE, 76 | listenerType, 77 | "propertyListener", 78 | JExpr._new(listenerType).arg(JExpr._this())); 79 | newVar.annotate(XmlTransient.class); 80 | 81 | JMethod method = co.implClass.method(Modifier.PUBLIC, Void.TYPE, "addPropertyChangeListener"); 82 | JVar listener = method.param(PropertyChangeListener.class, "listener"); 83 | method.body().invoke(newVar, "addPropertyChangeListener").arg(listener); 84 | 85 | method = co.implClass.method(Modifier.PUBLIC, Void.TYPE, "removePropertyChangeListener"); 86 | listener = method.param(PropertyChangeListener.class, "listener"); 87 | method.body().invoke(newVar, "removePropertyChangeListener").arg(listener); 88 | 89 | //add firePropertyChange to set methods 90 | List methods = (List)co.implClass.methods(); 91 | for (int x = 0; x < methods.size(); x++) { 92 | JMethod m = methods.get(x); 93 | if (m.name().startsWith("set")) { 94 | m.body().pos(0); 95 | List contents = m.body().getContents(); 96 | JFieldRef target = null; 97 | JExpression value = null; 98 | for (Object o : contents) { 99 | if (o instanceof JAssignment) { 100 | JAssignment jass = (JAssignment)o; 101 | try { 102 | Field f = jass.getClass().getDeclaredField("lhs"); 103 | f.setAccessible(true); 104 | Object t = f.get(jass); 105 | if (t instanceof JFieldRef) { 106 | f = jass.getClass().getDeclaredField("rhs"); 107 | f.setAccessible(true); 108 | value = (JExpression)f.get(jass); 109 | target = (JFieldRef)t; 110 | } 111 | } catch (Throwable t) { 112 | //ignore 113 | } 114 | } 115 | } 116 | if (target != null) { 117 | try { 118 | String targetName = getName(target); 119 | 120 | JFieldVar field = co.implClass.fields().get(targetName); 121 | 122 | if (value instanceof JVar) { 123 | JVar var = (JVar)value; 124 | JType t = var.type(); 125 | if ("int".equals(t.fullName()) 126 | && !"int".equals(field.type().fullName())) { 127 | value = JExpr.cast(co.parent().getCodeModel()._ref(Integer.class), 128 | value); 129 | } else if ("boolean".equals(t.fullName()) 130 | && !"boolean".equals(field.type().fullName())) { 131 | value = JExpr.cast(co.parent().getCodeModel()._ref(Boolean.class), 132 | value); 133 | } 134 | } 135 | 136 | m.body().invoke(newVar, "firePropertyChange").arg(targetName) 137 | .arg(target).arg(value); 138 | } catch (Throwable t) { 139 | //ignore 140 | t.printStackTrace(); 141 | } 142 | } 143 | } 144 | 145 | } 146 | 147 | } 148 | return true; 149 | } 150 | 151 | String getName(JFieldRef ref) { 152 | try { 153 | Field f = ref.getClass().getDeclaredField("name"); 154 | f.setAccessible(true); 155 | String targetName = (String)f.get(ref); 156 | if (targetName == null) { 157 | f = ref.getClass().getDeclaredField("var"); 158 | f.setAccessible(true); 159 | JVar v = (JVar)f.get(ref); 160 | targetName = v.name(); 161 | } 162 | return targetName; 163 | } catch (Throwable t) { 164 | //ignore 165 | } 166 | return null; 167 | } 168 | 169 | } 170 | -------------------------------------------------------------------------------- /property-listener/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin: -------------------------------------------------------------------------------- 1 | com.sun.tools.xjc.addon.apache_cxf.property_listener.PropertyListenerPlugin -------------------------------------------------------------------------------- /runtime/pom.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 4.0.0 10 | cxf-xjc-runtime 11 | bundle 12 | Apache CXF XJC Runtime 13 | https://cxf.apache.org 14 | 15 | 16 | org.apache.cxf.xjc-utils 17 | xjc-utils 18 | 4.1.1-SNAPSHOT 19 | 20 | 21 | 22 | 23 | 24 | org.apache.felix 25 | maven-bundle-plugin 26 | 6.0.0 27 | true 28 | 29 | 30 | ${project.groupId}.${project.artifactId} 31 | ${project.decription} 32 | 33 | jakarta.xml.bind*;version="[3,4)", 34 | * 35 | 36 | 37 | 38 | 39 | 40 | org.apache.maven.plugins 41 | maven-surefire-plugin 42 | 43 | --add-opens java.base/java.util=ALL-UNNAMED 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.apache.commons 52 | commons-lang3 53 | true 54 | 55 | 56 | junit 57 | junit 58 | test 59 | 60 | 61 | jakarta.xml.bind 62 | jakarta.xml.bind-api 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /runtime/src/main/java/org/apache/cxf/xjc/runtime/DataTypeAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.cxf.xjc.runtime; 20 | 21 | import java.util.Calendar; 22 | import java.util.Date; 23 | 24 | import jakarta.xml.bind.DatatypeConverter; 25 | 26 | public final class DataTypeAdapter { 27 | 28 | private DataTypeAdapter() { 29 | } 30 | 31 | public static Date parseDate(String s) { 32 | if (s == null) { 33 | return null; 34 | } 35 | return DatatypeConverter.parseDate(s).getTime(); 36 | } 37 | public static String printDate(Date dt) { 38 | if (dt == null) { 39 | return null; 40 | } 41 | Calendar c = Calendar.getInstance(); 42 | c.setTime(dt); 43 | return DatatypeConverter.printDate(c); 44 | } 45 | 46 | public static Date parseTime(String s) { 47 | if (s == null) { 48 | return null; 49 | } 50 | return DatatypeConverter.parseTime(s).getTime(); 51 | } 52 | public static String printTime(Date dt) { 53 | if (dt == null) { 54 | return null; 55 | } 56 | Calendar c = Calendar.getInstance(); 57 | c.setTime(dt); 58 | return DatatypeConverter.printTime(c); 59 | } 60 | 61 | public static Date parseDateTime(String s) { 62 | if (s == null) { 63 | return null; 64 | } 65 | return DatatypeConverter.parseDateTime(s).getTime(); 66 | } 67 | public static String printDateTime(Date dt) { 68 | if (dt == null) { 69 | return null; 70 | } 71 | Calendar c = Calendar.getInstance(); 72 | c.setTime(dt); 73 | return DatatypeConverter.printDateTime(c); 74 | } 75 | } -------------------------------------------------------------------------------- /runtime/src/main/java/org/apache/cxf/xjc/runtime/JAXBToStringBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.xjc.runtime; 21 | 22 | import java.util.Collection; 23 | 24 | import org.apache.commons.lang3.builder.ToStringBuilder; 25 | import org.apache.commons.lang3.builder.ToStringStyle; 26 | 27 | public final class JAXBToStringBuilder { 28 | private JAXBToStringBuilder() { 29 | } 30 | 31 | public static String valueOf(Object object) { 32 | return valueOf(object, JAXBToStringStyle.DEFAULT_STYLE); 33 | } 34 | 35 | public static String valueOf(Object object, ToStringStyle style) { 36 | if (object instanceof String) { 37 | return (String)object; 38 | } 39 | if (object instanceof Collection) { 40 | object = ((Collection) object).toArray(); 41 | } 42 | return ToStringBuilder.reflectionToString(object, style); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /runtime/src/main/java/org/apache/cxf/xjc/runtime/JAXBToStringStyle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.xjc.runtime; 21 | 22 | import jakarta.xml.bind.JAXBElement; 23 | import org.apache.commons.lang3.builder.ToStringBuilder; 24 | import org.apache.commons.lang3.builder.ToStringStyle; 25 | 26 | 27 | /* 28 | * Override default styles to recognise JAXBElement as needing introspection 29 | */ 30 | public final class JAXBToStringStyle { 31 | 32 | public static final ToStringStyle MULTI_LINE_STYLE = 33 | new JAXBToStringStyleImpl(true); 34 | 35 | public static final ToStringStyle SIMPLE_STYLE = 36 | new JAXBToStringStyleImpl(false); 37 | 38 | public static final ToStringStyle DEFAULT_STYLE = 39 | new JAXBToStringStyleImpl(); 40 | 41 | private JAXBToStringStyle() { 42 | //utility class 43 | } 44 | } 45 | 46 | class JAXBToStringStyleImpl extends ToStringStyle { 47 | private static final long serialVersionUID = -584903238590491314L; 48 | 49 | JAXBToStringStyleImpl() { 50 | super(); 51 | } 52 | 53 | JAXBToStringStyleImpl(boolean multiLine) { 54 | super(); 55 | if (multiLine) { 56 | this.setContentStart("["); 57 | this.setFieldSeparator(System.lineSeparator() + " "); 58 | this.setFieldSeparatorAtStart(true); 59 | this.setContentEnd(System.lineSeparator() + "]"); 60 | } else { 61 | // simple 62 | this.setUseClassName(false); 63 | this.setUseIdentityHashCode(false); 64 | this.setUseFieldNames(false); 65 | this.setContentStart(""); 66 | this.setContentEnd(""); 67 | } 68 | } 69 | 70 | /* 71 | * Introspect into JAXBElement as a special case as it does not have a 72 | * toString() and we loose the content 73 | * 74 | * @see org.apache.commons.lang3.builder.ToStringStyle 75 | */ 76 | @Override 77 | protected void appendDetail(StringBuffer buffer, String fieldName, Object value) { 78 | if (value instanceof JAXBElement) { 79 | buffer.append(ToStringBuilder.reflectionToString(value, this)); 80 | } else { 81 | buffer.append(value); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /runtime/src/test/java/org/apache/cxf/xjc/runtime/JAXBElementToStringStyleTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.xjc.runtime; 21 | 22 | 23 | import javax.xml.namespace.QName; 24 | 25 | import jakarta.xml.bind.JAXBElement; 26 | import org.apache.commons.lang3.builder.ToStringBuilder; 27 | 28 | import org.junit.Assert; 29 | import org.junit.Test; 30 | 31 | public class JAXBElementToStringStyleTest { 32 | 33 | class Holder { 34 | String name = "HolderName"; 35 | Object obj; 36 | Holder(Object o) { 37 | this.obj = o; 38 | } 39 | } 40 | 41 | JAXBElement nel = 42 | new JAXBElement( 43 | new QName("ab", "bv"), 44 | String.class, "SomeText"); 45 | 46 | Holder h = new Holder(nel); 47 | 48 | @Test 49 | public void testToStringDefault() throws Exception { 50 | 51 | String ts = ToStringBuilder.reflectionToString(h); 52 | 53 | validateHolderString(ts); 54 | 55 | // JAXBElement contents not present 56 | Assert.assertTrue("has no value", ts.indexOf("value") == -1); 57 | Assert.assertTrue("has no bv", ts.indexOf("bv") == -1); 58 | 59 | } 60 | 61 | @Test 62 | public void testToStringMultiLineStyle() throws Exception { 63 | String ts = 64 | ToStringBuilder.reflectionToString(h, JAXBToStringStyle.MULTI_LINE_STYLE); 65 | 66 | validateHolderString(ts); 67 | validateElementString(ts); 68 | } 69 | 70 | @Test 71 | public void testToStringSimpleStyle() throws Exception { 72 | String ts = 73 | ToStringBuilder.reflectionToString(h, JAXBToStringStyle.SIMPLE_STYLE); 74 | 75 | // field names are missing 76 | Assert.assertTrue("has no obj field", ts.indexOf("obj") == -1); 77 | Assert.assertTrue("has HolderName", ts.indexOf("HolderName") != -1); 78 | Assert.assertTrue("has SomeText", ts.indexOf("SomeText") != -1); 79 | } 80 | 81 | private void validateHolderString(String ts) { 82 | Assert.assertTrue("has HolderName", ts.indexOf("HolderName") != -1); 83 | Assert.assertTrue("has JAXBElement", ts.indexOf("JAXBElement") != -1); 84 | Assert.assertTrue("has obj", ts.indexOf("obj") != -1); 85 | } 86 | 87 | private void validateElementString(String ts) { 88 | Assert.assertTrue("has value", ts.indexOf("value") != -1); 89 | Assert.assertTrue("has scope", ts.indexOf("scope") != -1); 90 | Assert.assertTrue("has bv", ts.indexOf("bv") != -1); 91 | 92 | 93 | } 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /runtime/src/test/java/org/apache/cxf/xjc/runtime/JAXBToStringBuilderTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.xjc.runtime; 21 | 22 | import java.util.ArrayList; 23 | import java.util.HashMap; 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | import org.junit.Assert; 28 | import org.junit.Test; 29 | 30 | 31 | public class JAXBToStringBuilderTest { 32 | 33 | private static final String DATA = "someData"; 34 | 35 | @Test 36 | public void testToString() throws Exception { 37 | String res = JAXBToStringBuilder.valueOf(DATA); 38 | Assert.assertEquals(res, DATA); 39 | } 40 | 41 | @Test 42 | public void testToStringArray() throws Exception { 43 | String[] data = new String[]{DATA}; 44 | String res = JAXBToStringBuilder.valueOf(data); 45 | Assert.assertTrue(res.indexOf(DATA) != -1); 46 | } 47 | 48 | @Test 49 | public void testToStringCollection() throws Exception { 50 | List data = new ArrayList(); 51 | data.add(DATA); 52 | String res = JAXBToStringBuilder.valueOf(data); 53 | Assert.assertTrue(res.indexOf(DATA) != -1); 54 | } 55 | 56 | 57 | @Test 58 | public void testToStringMap() throws Exception { 59 | Map data = new HashMap(); 60 | data.put(DATA, DATA); 61 | 62 | // no content as it is not a Collection 63 | String res = JAXBToStringBuilder.valueOf(data); 64 | Assert.assertTrue(res.indexOf(DATA) == -1); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /runtime/src/test/resources/binding.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 25 | 30 | 31 | 32 | 33 | 34 | 37 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ts-test/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf.xjcplugins.tests 22 | cxf-xjc-ts-test 23 | jar 24 | Apache CXF XJC toString Plugin Tests 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | 36 | jakarta.xml.bind 37 | jakarta.xml.bind-api 38 | 39 | 40 | org.glassfish.jaxb 41 | jaxb-runtime 42 | 43 | 44 | org.glassfish.jaxb 45 | jaxb-xjc 46 | 47 | 48 | junit 49 | junit 50 | test 51 | 52 | 53 | org.apache.commons 54 | commons-lang3 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.apache.cxf 62 | cxf-xjc-plugin 63 | ${project.version} 64 | 65 | 66 | 67 | xsdtojava-tests 68 | 69 | 70 | 71 | 72 | true 73 | 74 | 75 | true 76 | ${basedir}/src/test/resources/schemas/configuration/foo.xsd 77 | 78 | -Xts:style:org.apache.commons.lang3.builder.ToStringStyle.DEFAULT_STYLE 79 | 80 | 81 | 82 | 83 | org.apache.cxf.xjcplugins:cxf-xjc-ts:${project.version} 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /ts-test/src/test/java/org/apache/cxf/xjc/ts/ToStringTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.xjc.ts; 21 | 22 | import java.lang.reflect.Method; 23 | 24 | 25 | import org.apache.cxf.configuration.foo.Foo; 26 | import org.apache.cxf.configuration.foo.TpAddress; 27 | import org.apache.cxf.configuration.foo.TpAddressPresentation; 28 | 29 | import org.junit.Assert; 30 | import org.junit.Test; 31 | 32 | 33 | 34 | public class ToStringTest extends Assert { 35 | 36 | @Test 37 | public void testFooToStringOverride() throws Exception { 38 | 39 | Foo foo = new org.apache.cxf.configuration.foo.ObjectFactory().createFoo(); 40 | 41 | Method method = foo.getClass().getMethod("toString"); 42 | assertEquals("toString is overridden", foo.getClass(), 43 | method.getDeclaringClass()); 44 | 45 | String fooS = foo.toString(); 46 | assertTrue("contains null", fooS.indexOf("null") != -1); 47 | } 48 | 49 | 50 | @Test 51 | public void testAddressToStringOverride() throws Exception { 52 | 53 | TpAddress foo = new org.apache.cxf.configuration.foo.ObjectFactory().createTpAddress(); 54 | 55 | Method method = foo.getClass().getMethod("toString"); 56 | assertEquals("toString is overridden", foo.getClass(), 57 | method.getDeclaringClass()); 58 | 59 | TpAddressPresentation value = TpAddressPresentation.P_ADDRESS_PRESENTATION_ALLOWED; 60 | foo.setPresentation(value); 61 | String fooS = foo.toString(); 62 | assertTrue("contains null", fooS.indexOf("null") != -1); 63 | assertTrue("contains P_ADDRESS_PRESENTATION_ALLOWED", 64 | fooS.indexOf("P_ADDRESS_PRESENTATION_ALLOWED") != -1); 65 | 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /ts-test/src/test/resources/schemas/configuration/foo.xsd: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /ts/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf.xjcplugins 22 | cxf-xjc-ts 23 | jar 24 | Apache CXF XJC toString Plugin 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | org.glassfish.jaxb 36 | jaxb-xjc 37 | provided 38 | 39 | 40 | org.glassfish.jaxb 41 | jaxb-runtime 42 | provided 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /ts/src/main/java/com/sun/tools/xjc/addon/apache_cxf/ts/ToStringPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.sun.tools.xjc.addon.apache_cxf.ts; 21 | 22 | import java.io.IOException; 23 | 24 | import org.xml.sax.ErrorHandler; 25 | import org.xml.sax.SAXException; 26 | 27 | import com.sun.tools.xjc.BadCommandLineException; 28 | import com.sun.tools.xjc.Options; 29 | import com.sun.tools.xjc.Plugin; 30 | import com.sun.tools.xjc.outline.Outline; 31 | 32 | /** 33 | * Thin wrapper around the ToStringPlugin. This must be in the com.sun.tools.xjc.addon package 34 | * for it to work with Java 6. See https://issues.apache.org/jira/browse/CXF-1880. 35 | */ 36 | public class ToStringPlugin extends Plugin { 37 | 38 | org.apache.cxf.xjc.ts.ToStringPlugin impl = new org.apache.cxf.xjc.ts.ToStringPlugin(); 39 | 40 | /* (non-Javadoc) 41 | * @see com.sun.tools.xjc.Plugin#getOptionName() 42 | */ 43 | @Override 44 | public String getOptionName() { 45 | return impl.getOptionName(); 46 | } 47 | 48 | /* (non-Javadoc) 49 | * @see com.sun.tools.xjc.Plugin#getUsage() 50 | */ 51 | @Override 52 | public String getUsage() { 53 | return impl.getUsage(); 54 | } 55 | 56 | /* (non-Javadoc) 57 | * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline, 58 | * com.sun.tools.xjc.Options, org.xml.sax.ErrorHandler) 59 | */ 60 | @Override 61 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { 62 | return impl.run(outline, opt, errorHandler); 63 | } 64 | 65 | public void onActivated(Options opts) throws BadCommandLineException { 66 | impl.onActivated(opts); 67 | } 68 | 69 | 70 | /* (non-Javadoc) 71 | * @see com.sun.tools.xjc.Plugin#parseArgument(com.sun.tools.xjc.Options, java.lang.String[], int) 72 | */ 73 | @Override 74 | public int parseArgument(Options opt, String[] args, int index) 75 | throws BadCommandLineException, IOException { 76 | 77 | return impl.parseArgument(opt, args, index, this); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /ts/src/main/java/org/apache/cxf/xjc/ts/Messages.properties: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | # 21 | -------------------------------------------------------------------------------- /ts/src/main/java/org/apache/cxf/xjc/ts/ToStringPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.xjc.ts; 21 | 22 | import java.io.IOException; 23 | import java.util.logging.Logger; 24 | 25 | import org.xml.sax.ErrorHandler; 26 | 27 | import com.sun.codemodel.JClass; 28 | import com.sun.codemodel.JDefinedClass; 29 | import com.sun.codemodel.JDocComment; 30 | import com.sun.codemodel.JExpr; 31 | import com.sun.codemodel.JFieldRef; 32 | import com.sun.codemodel.JInvocation; 33 | import com.sun.codemodel.JMethod; 34 | import com.sun.codemodel.JMod; 35 | import com.sun.tools.xjc.BadCommandLineException; 36 | import com.sun.tools.xjc.Options; 37 | import com.sun.tools.xjc.outline.ClassOutline; 38 | import com.sun.tools.xjc.outline.Outline; 39 | 40 | /** 41 | * Modifies the JAXB code model to override the Object.toString() method with an 42 | * implementation that provides a String representation of the xml content. 43 | */ 44 | public class ToStringPlugin { 45 | 46 | private static final Logger LOG = Logger.getLogger(ToStringPlugin.class.getName()); //NOPMD 47 | 48 | private String styleFieldName = "DEFAULT_STYLE"; 49 | private String styleClassName = "org.apache.cxf.xjc.runtime.JAXBToStringStyle"; 50 | private boolean active; 51 | 52 | public String getOptionName() { 53 | return "Xts"; 54 | } 55 | 56 | public String getUsage() { 57 | return " -Xts : Activate plugin to add a toString() method to generated classes\n" 58 | + " equivalent to: " 59 | + "-Xts:style:org.apache.cxf.xjc.runtime.JAXBToStringStyle.DEFAULT_STYLE\n" 60 | + " -Xts:style:multiline : Have toString produce multi line output\n" 61 | + " equivalent to: " 62 | + "-Xts:style:org.apache.cxf.xjc.runtime.JAXBToStringStyle.MULTI_LINE_STYLE\n" 63 | + " -Xts:style:simple : Have toString produce single line terse output\n" 64 | + " equivalent to: " 65 | + "-Xts:style:org.apache.cxf.xjc.runtime.JAXBToStringStyle.SIMPLE_STYLE\n" 66 | + " -Xts:style:org.apache.commons.lang3.builder.ToStringStyle.FIELD : The full class+field\n" 67 | + " name of the ToStringStyle to use."; 68 | } 69 | 70 | public int parseArgument(Options opt, String[] args, int index, com.sun.tools.xjc.Plugin plugin) 71 | throws BadCommandLineException, IOException { 72 | int ret = 0; 73 | 74 | if (args[index].startsWith("-Xts")) { 75 | ret = 1; 76 | if (args[index].startsWith("-Xts:style:")) { 77 | String v = args[index].substring("-Xts:style:".length()); 78 | if ("multiline".equals(v)) { 79 | styleFieldName = "MULTI_LINE_STYLE"; 80 | } else if ("simple".equals(v)) { 81 | styleFieldName = "SIMPLE_STYLE"; 82 | } else { 83 | int idx = v.lastIndexOf('.'); 84 | styleFieldName = v.substring(idx + 1); 85 | styleClassName = v.substring(0, idx); 86 | } 87 | } 88 | if (!opt.activePlugins.contains(plugin)) { 89 | opt.activePlugins.add(plugin); 90 | } 91 | active = true; 92 | } 93 | return ret; 94 | } 95 | 96 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) { 97 | LOG.fine("Running toString() plugin."); 98 | if (!active) { 99 | return true; 100 | } 101 | 102 | final JClass toStringDelegateImpl = outline.getCodeModel() 103 | .ref("org.apache.commons.lang3.builder.ToStringBuilder"); 104 | final JClass styleClass = outline.getCodeModel().ref(styleClassName); 105 | final JFieldRef toStringDelegateStyleParam = styleClass.staticRef(styleFieldName); 106 | 107 | for (ClassOutline co : outline.getClasses()) { 108 | addToStringMethod(co, toStringDelegateImpl, toStringDelegateStyleParam); 109 | } 110 | 111 | return true; 112 | } 113 | 114 | private void addToStringMethod(ClassOutline co, 115 | JClass delegateImpl, 116 | JFieldRef toStringDelegateStyleParam) { 117 | final JDefinedClass implementation = co.implClass; 118 | 119 | final JMethod toStringMethod = implementation.method(JMod.PUBLIC, String.class, "toString"); 120 | final JInvocation invoke = delegateImpl.staticInvoke("reflectionToString"); 121 | invoke.arg(JExpr._this()); 122 | invoke.arg(toStringDelegateStyleParam); 123 | toStringMethod.body()._return(invoke); 124 | 125 | JDocComment doc = toStringMethod.javadoc(); 126 | doc.add("Generates a String representation of the contents of this type."); 127 | doc.add("\nThis is an extension method, produced by the 'ts' xjc plugin"); 128 | toStringMethod.annotate(Override.class); 129 | } 130 | 131 | public void onActivated(Options opts) { 132 | active = true; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /ts/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin: -------------------------------------------------------------------------------- 1 | com.sun.tools.xjc.addon.apache_cxf.ts.ToStringPlugin -------------------------------------------------------------------------------- /wsdlextension-test/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf.xjcplugins.tests 22 | cxf-xjc-wsdlextension-test 23 | jar 24 | Apache CXF XJC WSDL Extension Plugin Tests 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | 36 | jakarta.xml.bind 37 | jakarta.xml.bind-api 38 | 39 | 40 | org.glassfish.jaxb 41 | jaxb-runtime 42 | 43 | 44 | org.glassfish.jaxb 45 | jaxb-xjc 46 | 47 | 48 | junit 49 | junit 50 | test 51 | 52 | 53 | wsdl4j 54 | wsdl4j 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.apache.cxf 62 | cxf-xjc-plugin 63 | ${project.version} 64 | 65 | 66 | 67 | xsdtojava-tests 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | ${basedir}/src/test/resources/schemas/configuration/foo.xsd 76 | 77 | -Xwsdlextension 78 | 79 | 80 | 81 | 82 | org.apache.cxf.xjcplugins:cxf-xjc-wsdlextension:${project.version} 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /wsdlextension-test/src/test/java/org/apache/cxf/xjc/wsdlextension/WSDLExtensionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.xjc.wsdlextension; 21 | 22 | import org.apache.cxf.configuration.foo.Foo; 23 | 24 | import org.junit.Assert; 25 | import org.junit.Test; 26 | 27 | public class WSDLExtensionTest extends Assert { 28 | 29 | @Test 30 | public void testFooToStringOverride() throws Exception { 31 | 32 | Foo foo = new org.apache.cxf.configuration.foo.ObjectFactory().createFoo(); 33 | 34 | assertTrue("The interface ExtensibilityElement should be used.", 35 | foo instanceof javax.wsdl.extensions.ExtensibilityElement); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /wsdlextension/pom.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 4.0.0 21 | org.apache.cxf.xjcplugins 22 | cxf-xjc-wsdlextension 23 | jar 24 | Apache CXF XJC WSDL Extension Plugin 25 | https://cxf.apache.org 26 | 27 | 28 | org.apache.cxf.xjc-utils 29 | xjc-utils 30 | 4.1.1-SNAPSHOT 31 | 32 | 33 | 34 | 35 | org.glassfish.jaxb 36 | jaxb-xjc 37 | provided 38 | 39 | 40 | org.glassfish.jaxb 41 | jaxb-runtime 42 | provided 43 | 44 | 45 | wsdl4j 46 | wsdl4j 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /wsdlextension/src/main/java/com/sun/tools/xjc/addon/apache_cxf/wsdlextension/WSDLExtensionPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.sun.tools.xjc.addon.apache_cxf.wsdlextension; 21 | 22 | import java.io.IOException; 23 | 24 | import org.xml.sax.ErrorHandler; 25 | import org.xml.sax.SAXException; 26 | 27 | import com.sun.tools.xjc.BadCommandLineException; 28 | import com.sun.tools.xjc.Options; 29 | import com.sun.tools.xjc.Plugin; 30 | import com.sun.tools.xjc.outline.Outline; 31 | 32 | import org.apache.cxf.xjc.wsdlextension.WSDLExtension; 33 | 34 | public class WSDLExtensionPlugin extends Plugin { 35 | 36 | WSDLExtension impl = new WSDLExtension(); 37 | 38 | /* (non-Javadoc) 39 | * @see com.sun.tools.xjc.Plugin#getOptionName() 40 | */ 41 | @Override 42 | public String getOptionName() { 43 | return impl.getOptionName(); 44 | } 45 | 46 | /* (non-Javadoc) 47 | * @see com.sun.tools.xjc.Plugin#getUsage() 48 | */ 49 | @Override 50 | public String getUsage() { 51 | return impl.getUsage(); 52 | } 53 | 54 | /* (non-Javadoc) 55 | * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline, 56 | * com.sun.tools.xjc.Options, org.xml.sax.ErrorHandler) 57 | */ 58 | @Override 59 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { 60 | return impl.run(outline, opt, errorHandler); 61 | } 62 | 63 | /* (non-Javadoc) 64 | * @see com.sun.tools.xjc.Plugin#parseArgument(com.sun.tools.xjc.Options, java.lang.String[], int) 65 | */ 66 | @Override 67 | public int parseArgument(Options opt, String[] args, int index) 68 | throws BadCommandLineException, IOException { 69 | 70 | return impl.parseArgument(opt, args, index); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /wsdlextension/src/main/java/org/apache/cxf/xjc/wsdlextension/Messages.properties: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | # 21 | -------------------------------------------------------------------------------- /wsdlextension/src/main/java/org/apache/cxf/xjc/wsdlextension/WSDLExtension.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.cxf.xjc.wsdlextension; 21 | 22 | import java.io.IOException; 23 | import java.util.logging.Logger; 24 | 25 | import javax.wsdl.extensions.ExtensibilityElement; 26 | import javax.xml.namespace.QName; 27 | 28 | import org.xml.sax.ErrorHandler; 29 | 30 | import com.sun.codemodel.JAnnotationUse; 31 | import com.sun.codemodel.JDefinedClass; 32 | import com.sun.codemodel.JExpr; 33 | import com.sun.codemodel.JFieldVar; 34 | import com.sun.codemodel.JMethod; 35 | import com.sun.codemodel.JMod; 36 | import com.sun.codemodel.JType; 37 | import com.sun.tools.xjc.BadCommandLineException; 38 | import com.sun.tools.xjc.Options; 39 | import com.sun.tools.xjc.outline.ClassOutline; 40 | import com.sun.tools.xjc.outline.Outline; 41 | 42 | import jakarta.xml.bind.annotation.XmlAttribute; 43 | import jakarta.xml.bind.annotation.XmlTransient; 44 | 45 | public class WSDLExtension { 46 | 47 | private static final Logger LOG = Logger.getLogger(WSDLExtension.class.getName()); //NOPMD 48 | 49 | public String getOptionName() { 50 | return "Xwsdlextension"; 51 | } 52 | 53 | public String getUsage() { 54 | return " -Xwsdlextension " 55 | + ":Activate plugin to add wsdl extension methods to generated root classes\n"; 56 | } 57 | 58 | public int parseArgument(Options opt, String[] args, int index) throws BadCommandLineException, 59 | IOException { 60 | int ret = 0; 61 | if ("-Xwsdlextension".equals(args[index])) { 62 | ret = 1; 63 | } 64 | return ret; 65 | } 66 | 67 | public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) { 68 | LOG.fine("Running WSDLExtension plugin."); 69 | 70 | for (ClassOutline co : outline.getClasses()) { 71 | addWSDLExtension(co); 72 | } 73 | return true; 74 | } 75 | 76 | private void addWSDLExtension(ClassOutline co) { 77 | final JDefinedClass implementation = co.implClass; 78 | implementation._implements(ExtensibilityElement.class); 79 | 80 | JFieldVar elementTypeVar = implementation.field(JMod.PROTECTED, QName.class, "elementType"); 81 | elementTypeVar.annotate(XmlTransient.class); 82 | 83 | JFieldVar requiredVar = implementation.field(JMod.PROTECTED, Boolean.class, "required"); 84 | JAnnotationUse requiredAnnotation = requiredVar.annotate(XmlAttribute.class); 85 | requiredAnnotation.param("namespace", "http://schemas.xmlsoap.org/wsdl/"); 86 | 87 | JMethod getElementTypeMethod = implementation.method(JMod.PUBLIC, QName.class, 88 | "getElementType"); 89 | getElementTypeMethod.body()._return(JExpr.direct("elementType")); 90 | 91 | JMethod setElementTypeMethod = implementation.method(JMod.PUBLIC, JType.parse(co 92 | .parent().getCodeModel(), "void"), "setElementType"); 93 | setElementTypeMethod.param(QName.class, "type"); 94 | setElementTypeMethod.body().directStatement("this.elementType = type;"); 95 | 96 | JMethod getRequiredMethod = implementation.method(JMod.PUBLIC, Boolean.class, 97 | "getRequired"); 98 | getRequiredMethod.body()._return(JExpr.direct("required == null ? false : required")); 99 | 100 | JMethod setRequiredMethod = implementation.method(JMod.PUBLIC, JType.parse(co 101 | .parent().getCodeModel(), "void"), "setRequired"); 102 | setRequiredMethod.param(Boolean.class, "required"); 103 | setRequiredMethod.body().directStatement("this.required = required;"); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /wsdlextension/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin: -------------------------------------------------------------------------------- 1 | com.sun.tools.xjc.addon.apache_cxf.wsdlextension.WSDLExtensionPlugin --------------------------------------------------------------------------------