001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.hadoop.record.compiler;
020
021import java.io.IOException;
022import java.util.ArrayList;
023
024import org.apache.hadoop.classification.InterfaceAudience;
025import org.apache.hadoop.classification.InterfaceStability;
026
027/**
028 * Container for the Hadoop Record DDL.
029 * The main components of the file are filename, list of included files,
030 * and records defined in that file.
031 * 
032 * @deprecated Replaced by <a href="http://hadoop.apache.org/avro/">Avro</a>.
033 */
034@Deprecated
035@InterfaceAudience.Public
036@InterfaceStability.Stable
037public class JFile {
038  /** Possibly full name of the file */
039  private String mName;
040  /** Ordered list of included files */
041  private ArrayList<JFile> mInclFiles;
042  /** Ordered list of records declared in this file */
043  private ArrayList<JRecord> mRecords;
044    
045  /** Creates a new instance of JFile
046   *
047   * @param name possibly full pathname to the file
048   * @param inclFiles included files (as JFile)
049   * @param recList List of records defined within this file
050   */
051  public JFile(String name, ArrayList<JFile> inclFiles,
052               ArrayList<JRecord> recList) {
053    mName = name;
054    mInclFiles = inclFiles;
055    mRecords = recList;
056  }
057    
058  /** Strip the other pathname components and return the basename */
059  String getName() {
060    int idx = mName.lastIndexOf('/');
061    return (idx > 0) ? mName.substring(idx) : mName; 
062  }
063    
064  /** Generate record code in given language. Language should be all
065   *  lowercase.
066   */
067  public int genCode(String language, String destDir, ArrayList<String> options)
068    throws IOException {
069    CodeGenerator gen = CodeGenerator.get(language);
070    if (gen != null) {
071      gen.genCode(mName, mInclFiles, mRecords, destDir, options);
072    } else {
073      System.err.println("Cannnot recognize language:"+language);
074      return 1;
075    }
076    return 0;
077  }
078}