Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » openwire » tool » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.activemq.openwire.tool;
   18   
   19   import java.io.PrintWriter;
   20   import java.util.Iterator;
   21   import java.util.List;
   22   
   23   import org.codehaus.jam.JClass;
   24   import org.codehaus.jam.JProperty;
   25   
   26   /**
   27    * @version $Revision: 379734 $
   28    */
   29   public class CppHeadersGenerator extends CppClassesGenerator {
   30   
   31       protected String getFilePostFix() {
   32           return ".hpp";
   33       }
   34   
   35       protected void generateFile(PrintWriter out) {
   36           generateLicence(out);
   37   
   38           out.println("#ifndef ActiveMQ_" + className + "_hpp_");
   39           out.println("#define ActiveMQ_" + className + "_hpp_");
   40           out.println("");
   41           out.println("// Turn off warning message for ignored exception specification");
   42           out.println("#ifdef _MSC_VER");
   43           out.println("#pragma warning( disable : 4290 )");
   44           out.println("#endif");
   45           out.println("");
   46           out.println("#include <string>");
   47           out.println("#include \"activemq/command/" + baseClass + ".hpp\"");
   48   
   49           List properties = getProperties();
   50           for (Iterator iter = properties.iterator(); iter.hasNext();) {
   51               JProperty property = (JProperty)iter.next();
   52               if (!property.getType().isPrimitiveType() && !property.getType().getSimpleName().equals("String") && !property.getType().getSimpleName().equals("ByteSequence")) {
   53                   String includeName = toCppType(property.getType());
   54                   if (property.getType().isArrayType()) {
   55                       JClass arrayType = property.getType().getArrayComponentType();
   56                       if (arrayType.isPrimitiveType()) {
   57                           continue;
   58                       }
   59                   }
   60                   if (includeName.startsWith("array<")) {
   61                       includeName = includeName.substring(6, includeName.length() - 1);
   62                   } else if (includeName.startsWith("p<")) {
   63                       includeName = includeName.substring(2, includeName.length() - 1);
   64                   }
   65                   if (includeName.equals("IDataStructure")) {
   66                       out.println("#include \"activemq/" + includeName + ".hpp\"");
   67                   } else {
   68                       out.println("#include \"activemq/command/" + includeName + ".hpp\"");
   69                   }
   70               }
   71           }
   72           out.println("");
   73           out.println("#include \"activemq/protocol/IMarshaller.hpp\"");
   74           out.println("#include \"ppr/io/IOutputStream.hpp\"");
   75           out.println("#include \"ppr/io/IInputStream.hpp\"");
   76           out.println("#include \"ppr/io/IOException.hpp\"");
   77           out.println("#include \"ppr/util/ifr/array\"");
   78           out.println("#include \"ppr/util/ifr/p\"");
   79           out.println("");
   80           out.println("namespace apache");
   81           out.println("{");
   82           out.println("  namespace activemq");
   83           out.println("  {");
   84           out.println("    namespace command");
   85           out.println("    {");
   86           out.println("      using namespace ifr;");
   87           out.println("      using namespace std;");
   88           out.println("      using namespace apache::activemq;");
   89           out.println("      using namespace apache::activemq::protocol;");
   90           out.println("      using namespace apache::ppr::io;");
   91           out.println("");
   92           out.println("/*");
   93           out.println(" *");
   94           out.println(" *  Command and marshalling code for OpenWire format for " + className + "");
   95           out.println(" *");
   96           out.println(" *");
   97           out.println(" *  NOTE!: This file is autogenerated - do not modify!");
   98           out.println(" *         if you need to make a change, please see the Groovy scripts in the");
   99           out.println(" *         activemq-core module");
  100           out.println(" *");
  101           out.println(" */");
  102           out.println("class " + className + " : public " + baseClass + "");
  103           out.println("{");
  104           out.println("protected:");
  105   
  106           for (Iterator iter = properties.iterator(); iter.hasNext();) {
  107               JProperty property = (JProperty)iter.next();
  108               String type = toCppType(property.getType());
  109               String name = decapitalize(property.getSimpleName());
  110               out.println("    " + type + " " + name + " ;");
  111           }
  112           out.println("");
  113           out.println("public:");
  114           out.println("    const static unsigned char TYPE = " + getOpenWireOpCode(jclass) + ";");
  115           out.println("");
  116           out.println("public:");
  117           out.println("    " + className + "() ;");
  118           out.println("    virtual ~" + className + "() ;");
  119           out.println("");
  120           out.println("    virtual unsigned char getDataStructureType() ;");
  121   
  122           for (Iterator iter = properties.iterator(); iter.hasNext();) {
  123               JProperty property = (JProperty)iter.next();
  124               String type = toCppType(property.getType());
  125               String propertyName = property.getSimpleName();
  126               String parameterName = decapitalize(propertyName);
  127               out.println("");
  128               out.println("    virtual " + type + " get" + propertyName + "() ;");
  129               out.println("    virtual void set" + propertyName + "(" + type + " " + parameterName + ") ;");
  130           }
  131           out.println("");
  132           out.println("    virtual int marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException) ;");
  133           out.println("    virtual void unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException) ;");
  134           out.println("} ;");
  135           out.println("");
  136           out.println("/* namespace */");
  137           out.println("    }");
  138           out.println("  }");
  139           out.println("}");
  140           out.println("");
  141           out.println("#endif /*ActiveMQ_" + className + "_hpp_*/");
  142       }
  143   
  144   }

Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » openwire » tool » [javadoc | source]