KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > openwire > tool > CppHeadersGenerator


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * 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, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.openwire.tool;
19
20 import java.io.PrintWriter JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23
24 import org.codehaus.jam.JClass;
25 import org.codehaus.jam.JProperty;
26
27
28 /**
29  *
30  * @version $Revision: 379734 $
31  */

32 public class CppHeadersGenerator extends CppClassesGenerator {
33
34     protected String JavaDoc getFilePostFix() {
35         return ".hpp";
36     }
37     
38     protected void generateFile(PrintWriter JavaDoc out) {
39         generateLicence(out);
40         
41 out.println("#ifndef ActiveMQ_"+className+"_hpp_");
42 out.println("#define ActiveMQ_"+className+"_hpp_");
43 out.println("");
44 out.println("// Turn off warning message for ignored exception specification");
45 out.println("#ifdef _MSC_VER");
46 out.println("#pragma warning( disable : 4290 )");
47 out.println("#endif");
48 out.println("");
49 out.println("#include <string>");
50 out.println("#include \"activemq/command/"+baseClass+".hpp\"");
51
52         List JavaDoc properties = getProperties();
53         for (Iterator JavaDoc iter = properties.iterator(); iter.hasNext();) {
54             JProperty property = (JProperty) iter.next();
55             if( !property.getType().isPrimitiveType() &&
56                 !property.getType().getSimpleName().equals("String") &&
57                 !property.getType().getSimpleName().equals("ByteSequence") )
58             {
59                 String JavaDoc includeName = toCppType(property.getType());
60                 if( property.getType().isArrayType() )
61                 {
62                     JClass arrayType = property.getType().getArrayComponentType();
63                     if( arrayType.isPrimitiveType() )
64                         continue ;
65                 }
66                 if( includeName.startsWith("array<") )
67                     includeName = includeName.substring(6, includeName.length()-1);
68                 else if( includeName.startsWith("p<") )
69                     includeName = includeName.substring(2, includeName.length()-1);
70         
71                 if( includeName.equals("IDataStructure") ) {
72 out.println("#include \"activemq/"+includeName+".hpp\"");
73                 } else {
74 out.println("#include \"activemq/command/"+includeName+".hpp\"");
75                 }
76             }
77         }
78 out.println("");
79 out.println("#include \"activemq/protocol/IMarshaller.hpp\"");
80 out.println("#include \"ppr/io/IOutputStream.hpp\"");
81 out.println("#include \"ppr/io/IInputStream.hpp\"");
82 out.println("#include \"ppr/io/IOException.hpp\"");
83 out.println("#include \"ppr/util/ifr/array\"");
84 out.println("#include \"ppr/util/ifr/p\"");
85 out.println("");
86 out.println("namespace apache");
87 out.println("{");
88 out.println(" namespace activemq");
89 out.println(" {");
90 out.println(" namespace command");
91 out.println(" {");
92 out.println(" using namespace ifr;");
93 out.println(" using namespace std;");
94 out.println(" using namespace apache::activemq;");
95 out.println(" using namespace apache::activemq::protocol;");
96 out.println(" using namespace apache::ppr::io;");
97 out.println("");
98 out.println("/*");
99 out.println(" *");
100 out.println(" * Command and marshalling code for OpenWire format for "+className+"");
101 out.println(" *");
102 out.println(" *");
103 out.println(" * NOTE!: This file is autogenerated - do not modify!");
104 out.println(" * if you need to make a change, please see the Groovy scripts in the");
105 out.println(" * activemq-core module");
106 out.println(" *");
107 out.println(" */");
108 out.println("class "+className+" : public "+baseClass+"");
109 out.println("{");
110 out.println("protected:");
111
112         for (Iterator JavaDoc iter = properties.iterator(); iter.hasNext();) {
113             JProperty property = (JProperty) iter.next();
114             String JavaDoc type = toCppType(property.getType());
115             String JavaDoc name = decapitalize(property.getSimpleName());
116 out.println(" "+type+" "+name+" ;");
117         }
118 out.println("");
119 out.println("public:");
120 out.println(" const static unsigned char TYPE = "+getOpenWireOpCode(jclass)+";");
121 out.println("");
122 out.println("public:");
123 out.println(" "+className+"() ;");
124 out.println(" virtual ~"+className+"() ;");
125 out.println("");
126 out.println(" virtual unsigned char getDataStructureType() ;");
127
128         for (Iterator JavaDoc iter = properties.iterator(); iter.hasNext();) {
129             JProperty property = (JProperty) iter.next();
130             String JavaDoc type = toCppType(property.getType());
131             String JavaDoc propertyName = property.getSimpleName();
132             String JavaDoc parameterName = decapitalize(propertyName);
133 out.println("");
134 out.println(" virtual "+type+" get"+propertyName+"() ;");
135 out.println(" virtual void set"+propertyName+"("+type+" "+parameterName+") ;");
136         }
137 out.println("");
138 out.println(" virtual int marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException) ;");
139 out.println(" virtual void unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException) ;");
140 out.println("} ;");
141 out.println("");
142 out.println("/* namespace */");
143 out.println(" }");
144 out.println(" }");
145 out.println("}");
146 out.println("");
147 out.println("#endif /*ActiveMQ_"+className+"_hpp_*/");
148 }
149
150 }
151
Popular Tags