KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tutorial5 > AbstractUseCase


1 package org.apache.ojb.tutorial5;
2
3 /* Copyright 2002-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import javax.jdo.PersistenceManagerFactory;
19
20 import java.io.BufferedReader JavaDoc;
21 import java.io.InputStreamReader JavaDoc;
22
23 /**
24  * Base class for the use cases of tutorial 5.
25  */

26 public abstract class AbstractUseCase implements UseCase
27 {
28     /** The persistence manager factory used to acquire persistence managers
29         for database operations */

30     protected PersistenceManagerFactory factory;
31
32     /**
33      * Creates a new instance of the use case. Is intended to be called
34      * by sub classes.
35      *
36      * @param factory The factory for getting persistence managers
37      */

38     public AbstractUseCase(PersistenceManagerFactory factory)
39     {
40         this.factory = factory;
41     }
42
43     /**
44      * Reads a single line from stdin and returns it.
45      *
46      * @param message The message to print
47      * @return The text entered by the user
48      */

49     protected String JavaDoc readLineWithMessage(String JavaDoc message)
50     {
51         System.out.print(message + " ");
52
53         try
54         {
55             BufferedReader JavaDoc rin = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(System.in));
56
57             return rin.readLine();
58         }
59         catch (Exception JavaDoc e)
60         {
61             return "";
62         }
63     }
64 }
65
Popular Tags