001/**
002 *   GRANITE DATA SERVICES
003 *   Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S.
004 *
005 *   This file is part of the Granite Data Services Platform.
006 *
007 *   Granite Data Services is free software; you can redistribute it and/or
008 *   modify it under the terms of the GNU Lesser General Public
009 *   License as published by the Free Software Foundation; either
010 *   version 2.1 of the License, or (at your option) any later version.
011 *
012 *   Granite Data Services is distributed in the hope that it will be useful,
013 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
014 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
015 *   General Public License for more details.
016 *
017 *   You should have received a copy of the GNU Lesser General Public
018 *   License along with this library; if not, write to the Free Software
019 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
020 *   USA, or see <http://www.gnu.org/licenses/>.
021 */
022
023package org.granite.generator.ant;
024
025import java.lang.reflect.Field;
026
027import org.granite.generator.Transformer;
028import org.granite.generator.as3.As3TypeFactory;
029import org.granite.generator.as3.DefaultAs3TypeFactory;
030import org.granite.generator.as3.JavaAs3GroovyTransformer;
031import org.granite.generator.template.StandardTemplateUris;
032
033/**
034 * @author Franck WOLFF
035 */
036public class AntJavaAs3Task extends AbstractAntJavaGenTask {
037
038    ///////////////////////////////////////////////////////////////////////////
039    // Configurable fields (xml attributes).
040
041    private boolean externalizelong = false;
042    private boolean externalizebiginteger = false;
043    private boolean externalizebigdecimal = false;
044    
045    ///////////////////////////////////////////////////////////////////////////
046    // Task attributes.
047
048    public void setExternalizelong(boolean externalizelong) {
049                this.externalizelong = externalizelong;
050        }
051
052    public void setExternalizebiginteger(boolean externalizebiginteger) {
053                this.externalizebiginteger = externalizebiginteger;
054        }
055
056        public void setExternalizebigdecimal(boolean externalizebigdecimal) {
057                this.externalizebigdecimal = externalizebigdecimal;
058        }
059
060    ///////////////////////////////////////////////////////////////////////////
061    // Task execution.
062
063    @Override
064        protected As3TypeFactory initDefaultClientTypeFactory() {
065        As3TypeFactory clientTypeFactoryImpl = new DefaultAs3TypeFactory();
066        clientTypeFactoryImpl.configure(externalizelong, externalizebiginteger, externalizebigdecimal);
067        return clientTypeFactoryImpl;
068    }
069    
070    @Override
071    protected Transformer<?, ?, ?> initDefaultTransformer() {
072        return new JavaAs3GroovyTransformer();
073    }
074    
075    @Override
076    protected String defaultTemplateUri(String type) {
077        try {
078                Field field = StandardTemplateUris.class.getField(type);
079                return (String)field.get(null);
080        }
081        catch (Exception e) {
082                throw new RuntimeException("Default template not found for type " + type);
083        }
084    }
085}