JFile.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with 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 com.yahoo.jute.compiler;
  19. import java.io.IOException;
  20. import java.util.ArrayList;
  21. /**
  22. * Container for the Hadoop Record DDL.
  23. * The main components of the file are filename, list of included files,
  24. * and records defined in that file.
  25. *
  26. * @author Milind Bhandarkar
  27. */
  28. public class JFile {
  29. private String mName;
  30. private ArrayList mInclFiles;
  31. private ArrayList mRecords;
  32. /** Creates a new instance of JFile
  33. *
  34. * @param name possibly full pathname to the file
  35. * @param inclFiles included files (as JFile)
  36. * @param recList List of records defined within this file
  37. */
  38. public JFile(String name, ArrayList inclFiles, ArrayList recList) {
  39. mName = name;
  40. mInclFiles = inclFiles;
  41. mRecords = recList;
  42. }
  43. /** Strip the other pathname components and return the basename */
  44. String getName() {
  45. int idx = mName.lastIndexOf('/');
  46. return (idx > 0) ? mName.substring(idx) : mName;
  47. }
  48. /** Generate record code in given language. Language should be all
  49. * lowercase.
  50. */
  51. public void genCode(String language) throws IOException {
  52. if ("c++".equals(language)) {
  53. CppGenerator gen = new CppGenerator(mName, mInclFiles, mRecords);
  54. gen.genCode();
  55. } else if ("java".equals(language)) {
  56. JavaGenerator gen = new JavaGenerator(mName, mInclFiles, mRecords);
  57. gen.genCode();
  58. } else if ("c".equals(language)) {
  59. CGenerator gen = new CGenerator(mName, mInclFiles, mRecords);
  60. gen.genCode();
  61. } else {
  62. System.out.println("Cannnot recognize language:"+language);
  63. System.exit(1);
  64. }
  65. }
  66. }