       1 /*
       2  * $Id$
       3  *
       4  * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
       5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       6  *
       7  * This code is free software; you can redistribute it and/or modify it
       8  * under the terms of the GNU General Public License version 2 only, as
       9  * published by the Free Software Foundation.  Oracle designates this
      10  * particular file as subject to the "Classpath" exception as provided
      11  * by Oracle in the LICENSE file that accompanied this code.
      12  *
      13  * This code is distributed in the hope that it will be useful, but WITHOUT
      14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      16  * version 2 for more details (a copy is included in the LICENSE file that
      17  * accompanied this code).
      18  *
      19  * You should have received a copy of the GNU General Public License version
      20  * 2 along with this work; if not, write to the Free Software Foundation,
      21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
      22  *
      23  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
      24  * or visit www.oracle.com if you need additional information or have any
      25  * questions.
      26  */
      27 package com.sun.javatest.cof;
      28
      29 import com.sun.javatest.InterviewParameters;
      30 import java.io.BufferedInputStream;
      31 import java.io.File;
      32 import java.io.FileInputStream;
      33 import java.io.IOException;
      34 import java.io.InputStream;
      35 import java.util.HashMap;
      36 import java.util.Map;
      37 import java.util.Properties;
      38 import java.util.Vector;
      39
      40 public class COFData
      41 {
      42     public COFData() {
      43     }
      44
      45     COFData(Vector data) throws IOException {
      46         for (int i = 0; i < data.size(); i++) {
      47             Object o = data.elementAt(i);
      48             if (o == null)
      49                 throw new NullPointerException();
      50             else if (o instanceof String) {
      51                 String s = (String) o;
      52                 int eq = s.indexOf("=");
      53                 if (eq < 1)
      54                     throw new IllegalArgumentException(s);
      55                 String name = s.substring(0, eq);
      56                 String value = s.substring(eq + 1);
      57                 put(name, value);
      58             }
      59             else if (o instanceof File) {
      60                 File f = (File) o;
      61                 InputStream in = new BufferedInputStream(new FileInputStream(f));
      62                 Properties p = new Properties();
      63                 try {
      64                     p.load(in);
      65                 }
      66                 finally {
      67                     in.close();
      68                 }
      69                 putAll(p);
      70             }
      71             else
      72                 throw new IllegalArgumentException(o.toString());
      73         }
      74     }
      75
      76     public String get(String name) {
      77         return (String) (data.get(name));
      78     }
      79
      80     public String get(String name, String defaultValue) {
      81         String value = (String) (data.get(name));
      82         return (value == null ? defaultValue : value);
      83     }
      84
      85     public void put(String name, String value) {
      86         data.put(name, value);
      87     }
      88
      89     public void putAll(Map map) {
      90         data.putAll(map);
      91     }
      92
      93     private Map data = new HashMap();
      94
      95     private CustomFilter filter = new CustomFilterAdapter();
      96
      97     void setCustomFilter(String filterClassName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
      98         Class c = Class.forName(filterClassName, true, ClassLoader.getSystemClassLoader());
      99         filter = (CustomFilter) c.newInstance();
     100     }
     101
     102     CustomFilter getCustomFilter() {
     103         return filter;
     104     }
     105
     106     private MTL mtl;
     107
     108     MTL getMtl() {
     109         return mtl;
     110     }
     111
     112     void setMtl(MTL mtl) {
     113         this.mtl = mtl;
     114     }
     115
     116     public void setInterviewParameters(InterviewParameters ip) {
     117         this.ip = ip;
     118     }
     119
     120     public InterviewParameters getInterviewParameters() {
     121         return ip;
     122     }
     123
     124     public boolean isInterviewParametersAvailable() {
     125         return ip != null;
     126     }
     127
     128     private InterviewParameters ip;
     129 }