Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2406CF2EF for ; Thu, 28 Mar 2013 09:06:44 +0000 (UTC) Received: (qmail 55006 invoked by uid 500); 28 Mar 2013 09:06:42 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 54901 invoked by uid 500); 28 Mar 2013 09:06:41 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 54872 invoked by uid 99); 28 Mar 2013 09:06:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Mar 2013 09:06:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Mar 2013 09:06:38 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0357C238890D; Thu, 28 Mar 2013 09:06:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1461998 - in /cxf/xjc-utils/trunk: boolean-test/ boolean-test/src/test/java/org/apache/cxf/xjc/bgi/ boolean-test/src/test/resources/schemas/configuration/ boolean/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bgi/ boolean/src/main/java/... Date: Thu, 28 Mar 2013 09:06:17 -0000 To: commits@cxf.apache.org From: ffang@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130328090618.0357C238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ffang Date: Thu Mar 28 09:06:17 2013 New Revision: 1461998 URL: http://svn.apache.org/r1461998 Log: [CXF-4899]add -Xbgi xjc plugin which can match both getXXX and isXXX method for boolean in xsd Added: cxf/xjc-utils/trunk/boolean-test/src/test/java/org/apache/cxf/xjc/bgi/ cxf/xjc-utils/trunk/boolean-test/src/test/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPluginTest.java cxf/xjc-utils/trunk/boolean-test/src/test/resources/schemas/configuration/foo1.xsd cxf/xjc-utils/trunk/boolean/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bgi/ cxf/xjc-utils/trunk/boolean/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bgi/BooleanGetAndIsPlugin.java cxf/xjc-utils/trunk/boolean/src/main/java/org/apache/cxf/xjc/bgi/ cxf/xjc-utils/trunk/boolean/src/main/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPlugin.java Modified: cxf/xjc-utils/trunk/boolean-test/pom.xml cxf/xjc-utils/trunk/boolean/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin Modified: cxf/xjc-utils/trunk/boolean-test/pom.xml URL: http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/boolean-test/pom.xml?rev=1461998&r1=1461997&r2=1461998&view=diff ============================================================================== --- cxf/xjc-utils/trunk/boolean-test/pom.xml (original) +++ cxf/xjc-utils/trunk/boolean-test/pom.xml Thu Mar 28 09:06:17 2013 @@ -82,6 +82,14 @@ -Xbg + + true + ${basedir}/src/test/resources/schemas/configuration/foo1.xsd + + -Xbgi + + + org.apache.cxf.xjcplugins:cxf-xjc-boolean:${project.version} Added: cxf/xjc-utils/trunk/boolean-test/src/test/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPluginTest.java URL: http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/boolean-test/src/test/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPluginTest.java?rev=1461998&view=auto ============================================================================== --- cxf/xjc-utils/trunk/boolean-test/src/test/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPluginTest.java (added) +++ cxf/xjc-utils/trunk/boolean-test/src/test/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPluginTest.java Thu Mar 28 09:06:17 2013 @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.xjc.bgi; + +import javax.xml.bind.DatatypeConverter; + +import org.apache.cxf.configuration.foo1.Foo; +import org.apache.ws.jaxme.impl.DatatypeConverterImpl; + +import org.junit.Test; + +public class BooleanGetAndIsPluginTest { + + @Test + public void testBooleanGetAndIs() throws Exception { + + DatatypeConverter.setDatatypeConverter(new DatatypeConverterImpl()); + + Foo foo = new org.apache.cxf.configuration.foo1.ObjectFactory().createFoo(); + + foo.getBooleanAttr(); + foo.isBooleanAttr(); + } + +} Added: cxf/xjc-utils/trunk/boolean-test/src/test/resources/schemas/configuration/foo1.xsd URL: http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/boolean-test/src/test/resources/schemas/configuration/foo1.xsd?rev=1461998&view=auto ============================================================================== --- cxf/xjc-utils/trunk/boolean-test/src/test/resources/schemas/configuration/foo1.xsd (added) +++ cxf/xjc-utils/trunk/boolean-test/src/test/resources/schemas/configuration/foo1.xsd Thu Mar 28 09:06:17 2013 @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: cxf/xjc-utils/trunk/boolean/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bgi/BooleanGetAndIsPlugin.java URL: http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/boolean/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bgi/BooleanGetAndIsPlugin.java?rev=1461998&view=auto ============================================================================== --- cxf/xjc-utils/trunk/boolean/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bgi/BooleanGetAndIsPlugin.java (added) +++ cxf/xjc-utils/trunk/boolean/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bgi/BooleanGetAndIsPlugin.java Thu Mar 28 09:06:17 2013 @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.sun.tools.xjc.addon.apache_cxf.bgi; + +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXException; + +import com.sun.tools.xjc.Options; +import com.sun.tools.xjc.Plugin; +import com.sun.tools.xjc.outline.Outline; + +/** + * Thin wrapper around the BooleanGetAndIsPlugin. This must be in the com.sun.tools.xjc.addon package for it to + * work with Java 6. See https://issues.apache.org/jira/browse/CXF-1880. + */ +public class BooleanGetAndIsPlugin extends Plugin { + + org.apache.cxf.xjc.bgi.BooleanGetAndIsPlugin impl = + new org.apache.cxf.xjc.bgi.BooleanGetAndIsPlugin(); + + /* + * (non-Javadoc) + * + * @see com.sun.tools.xjc.Plugin#getOptionName() + */ + @Override + public String getOptionName() { + return impl.getOptionName(); + } + + /* + * (non-Javadoc) + * + * @see com.sun.tools.xjc.Plugin#getUsage() + */ + @Override + public String getUsage() { + return impl.getUsage(); + } + + /* + * (non-Javadoc) + * + * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline, com.sun.tools.xjc.Options, + * org.xml.sax.ErrorHandler) + */ + @Override + public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { + return impl.run(outline, opt, errorHandler); + } +} Added: cxf/xjc-utils/trunk/boolean/src/main/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPlugin.java URL: http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/boolean/src/main/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPlugin.java?rev=1461998&view=auto ============================================================================== --- cxf/xjc-utils/trunk/boolean/src/main/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPlugin.java (added) +++ cxf/xjc-utils/trunk/boolean/src/main/java/org/apache/cxf/xjc/bgi/BooleanGetAndIsPlugin.java Thu Mar 28 09:06:17 2013 @@ -0,0 +1,94 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.xjc.bgi; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.logging.Logger; + +import org.xml.sax.ErrorHandler; + +import com.sun.codemodel.JBlock; +import com.sun.codemodel.JMethod; +import com.sun.codemodel.JMod; +import com.sun.codemodel.JType; +import com.sun.tools.xjc.Options; +import com.sun.tools.xjc.outline.ClassOutline; +import com.sun.tools.xjc.outline.Outline; + +/** + * Generate getters named getXXX() and isXXX(). + */ +public class BooleanGetAndIsPlugin { + + private static final Logger LOG = Logger.getLogger(BooleanGetAndIsPlugin.class.getName()); //NOPMD + private static final String IS_PREFIX = "is"; + + public BooleanGetAndIsPlugin() { + } + + public String getOptionName() { + return "Xbgi"; + } + + public String getUsage() { + return " -Xbgi : Generate getXXX and isXXX methods for Booleans"; + } + + public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) { + for (ClassOutline classOutline : outline.getClasses()) { + processClass(classOutline); + } + return true; + } + + private void processClass(ClassOutline clazz) { + Collection methods = clazz.implClass.methods(); + Map methodsToAdd = new HashMap(); + for (JMethod method : methods) { + if (method.name().startsWith(IS_PREFIX) && requiresGetter(methods, method)) { + methodsToAdd.put(method.name(), method.type()); + } + } + + Iterator> todo = methodsToAdd.entrySet().iterator(); + while (todo.hasNext()) { + Entry entry = todo.next(); + String newName = "get" + entry.getKey().substring(2); + LOG.info("Adding method " + newName); + JMethod newMethod = clazz.implClass.method(JMod.PUBLIC, entry.getValue(), newName); + JBlock body = newMethod.body(); + body.directStatement("return " + entry.getKey() + "();"); + } + } + + private boolean requiresGetter(Collection methods, JMethod method) { + String newName = "get" + method.name().substring(2); + // Check if already exists. + for (JMethod cursor : methods) { + if (newName.equals(cursor.name())) { + return false; + } + } + return true; + } +} Modified: cxf/xjc-utils/trunk/boolean/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin URL: http://svn.apache.org/viewvc/cxf/xjc-utils/trunk/boolean/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin?rev=1461998&r1=1461997&r2=1461998&view=diff ============================================================================== --- cxf/xjc-utils/trunk/boolean/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin (original) +++ cxf/xjc-utils/trunk/boolean/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin Thu Mar 28 09:06:17 2013 @@ -1 +1,2 @@ -com.sun.tools.xjc.addon.apache_cxf.bg.BooleanGetterPlugin \ No newline at end of file +com.sun.tools.xjc.addon.apache_cxf.bg.BooleanGetterPlugin +com.sun.tools.xjc.addon.apache_cxf.bgi.BooleanGetAndIsPlugin