KickJava   Java API By Example, From Geeks To Geeks.

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


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.File JavaDoc;
21 import java.io.PrintWriter JavaDoc;
22
23 /**
24  *
25  * @version $Revision: 381410 $
26  */

27 public class CppMarshallingHeadersGenerator extends JavaMarshallingGenerator {
28
29     protected String JavaDoc targetDir="./src";
30
31     public Object JavaDoc run() {
32         filePostFix = getFilePostFix();
33         if (destDir == null) {
34             destDir = new File JavaDoc(targetDir+"/marshal");
35         }
36         return super.run();
37     }
38     
39     protected String JavaDoc getFilePostFix() {
40         return ".hpp";
41     }
42     
43     
44     protected void generateLicence(PrintWriter JavaDoc out) {
45 out.println("/*");
46 out.println(" *");
47 out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
48 out.println(" * contributor license agreements. See the NOTICE file distributed with");
49 out.println(" * this work for additional information regarding copyright ownership.");
50 out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
51 out.println(" * (the \"License\"); you may not use this file except in compliance with");
52 out.println(" * the License. You may obtain a copy of the License at");
53 out.println(" *");
54 out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
55 out.println(" *");
56 out.println(" * Unless required by applicable law or agreed to in writing, software");
57 out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
58 out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
59 out.println(" * See the License for the specific language governing permissions and");
60 out.println(" * limitations under the License.");
61 out.println(" */");
62     }
63
64     protected void generateFile(PrintWriter JavaDoc out) throws Exception JavaDoc {
65         generateLicence(out);
66         
67 out.println("#ifndef "+className+"_hpp_");
68 out.println("#define "+className+"_hpp_");
69 out.println("");
70 out.println("#include <string>");
71 out.println("");
72 out.println("#include \"command/IDataStructure.hpp\"");
73 out.println("");
74 out.println("/* we could cut this down - for now include all possible headers */");
75 out.println("#include \"command/BrokerId.hpp\"");
76 out.println("#include \"command/ConnectionId.hpp\"");
77 out.println("#include \"command/ConsumerId.hpp\"");
78 out.println("#include \"command/ProducerId.hpp\"");
79 out.println("#include \"command/SessionId.hpp\"");
80 out.println("");
81 out.println("#include \"io/BinaryReader.hpp\"");
82 out.println("#include \"io/BinaryWriter.hpp\"");
83 out.println("");
84 out.println("#include \"command/"+baseClass+".hpp\"");
85 out.println("#include \"util/ifr/p.hpp\"");
86 out.println("");
87 out.println("#include \"protocol/ProtocolFormat.hpp\"");
88 out.println("");
89 out.println("namespace apache");
90 out.println("{");
91 out.println(" namespace activemq");
92 out.println(" {");
93 out.println(" namespace client");
94 out.println(" {");
95 out.println(" namespace marshal");
96 out.println(" {");
97 out.println(" using namespace ifr ;");
98 out.println(" using namespace apache::activemq::client::command;");
99 out.println(" using namespace apache::activemq::client::io;");
100 out.println(" using namespace apache::activemq::client::protocol;");
101 out.println("");
102 out.println("/*");
103 out.println(" *");
104 out.println(" */");
105 out.println("class "+className+" : public "+baseClass+"");
106 out.println("{");
107 out.println("public:");
108 out.println(" "+className+"() ;");
109 out.println(" virtual ~"+className+"() ;");
110 out.println("");
111 out.println(" virtual IDataStructure* createCommand() ;");
112 out.println(" virtual char getDataStructureType() ;");
113 out.println(" ");
114 out.println(" virtual void unmarshal(ProtocolFormat& wireFormat, Object o, BinaryReader& dataIn, BooleanStream& bs) ;");
115 out.println(" virtual int marshal1(ProtocolFormat& wireFormat, Object& o, BooleanStream& bs) ;");
116 out.println(" virtual void marshal2(ProtocolFormat& wireFormat, Object& o, BinaryWriter& dataOut, BooleanStream& bs) ;");
117 out.println("} ;");
118 out.println("");
119 out.println("/* namespace */");
120 out.println(" }");
121 out.println(" }");
122 out.println(" }");
123 out.println("}");
124 out.println("#endif /*"+className+"_hpp_*/");
125         }
126     
127     public void generateFactory(PrintWriter JavaDoc out) {
128         generateLicence(out);
129 out.println("");
130 out.println("// Marshalling code for Open Wire Format ");
131 out.println("//");
132 out.println("//");
133 out.println("// NOTE!: This file is autogenerated - do not modify!");
134 out.println("// if you need to make a change, please see the Groovy scripts in the");
135 out.println("// activemq-openwire module");
136 out.println("//");
137 out.println("");
138 out.println("#ifndef MarshallerFactory_hpp_");
139 out.println("#define MarshallerFactory_hpp_");
140 out.println("");
141 out.println("");
142 out.println("namespace apache");
143 out.println("{");
144 out.println(" namespace activemq");
145 out.println(" {");
146 out.println(" namespace client");
147 out.println(" {");
148 out.println(" namespace marshal");
149 out.println(" {");
150 out.println(" using namespace ifr ;");
151 out.println(" using namespace std ;");
152 out.println(" using namespace apache::activemq::client;");
153 out.println(" using namespace apache::activemq::client::command;");
154 out.println(" using namespace apache::activemq::client::io;");
155 out.println("");
156 out.println("/*");
157 out.println(" * ");
158 out.println(" */");
159 out.println("class MarshallerFactory");
160 out.println("{");
161 out.println("public:");
162 out.println(" MarshallerFactory() ;");
163 out.println(" virtual ~MarshallerFactory() ;");
164 out.println("");
165 out.println(" virtual void configure(ProtocolFormat& format) ;");
166 out.println("} ;");
167 out.println("");
168 out.println("/* namespace */");
169 out.println(" }");
170 out.println(" }");
171 out.println(" }");
172 out.println("}");
173 out.println("");
174 out.println("#endif /*MarshallerFactory_hpp_*/");
175 out.println("");
176     }
177
178     public String JavaDoc getTargetDir() {
179         return targetDir;
180     }
181
182     public void setTargetDir(String JavaDoc targetDir) {
183         this.targetDir = targetDir;
184     }
185 }
186
Popular Tags