KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ungoverned > oscar > installer > artifact > AbstractFileArtifact


1 /*
2  * Oscar - An implementation of the OSGi framework.
3  * Copyright (c) 2004, Richard S. Hall
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of the ungoverned.org nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * Contact: Richard S. Hall (heavy@ungoverned.org)
33  * Contributor(s):
34  *
35 **/

36 package org.ungoverned.oscar.installer.artifact;
37
38 import java.io.*;
39 import java.util.Map JavaDoc;
40
41 import org.ungoverned.oscar.installer.Install;
42 import org.ungoverned.oscar.installer.Status;
43 import org.ungoverned.oscar.installer.StringProperty;
44
45 public abstract class AbstractFileArtifact extends AbstractArtifact
46 {
47     private StringProperty m_destName = null;
48
49     public AbstractFileArtifact(StringProperty sourceName)
50     {
51         this(sourceName, sourceName);
52     }
53
54     public AbstractFileArtifact(StringProperty sourceName, StringProperty destName)
55     {
56         this(sourceName, destName, null);
57     }
58
59     public AbstractFileArtifact(
60         StringProperty sourceName, StringProperty destName, StringProperty destDir)
61     {
62         this(sourceName, destName, destDir, false);
63     }
64
65     public AbstractFileArtifact(
66         StringProperty sourceName, StringProperty destName,
67         StringProperty destDir, boolean localize)
68     {
69         super(sourceName, destDir, localize);
70         m_destName = destName;
71     }
72
73     public StringProperty getDestinationName()
74     {
75         return m_destName;
76     }
77
78     public boolean process(Status status, Map JavaDoc propMap)
79     {
80         String JavaDoc installDir =
81             ((StringProperty) propMap.get(Install.INSTALL_DIR)).getStringValue();
82
83         try
84         {
85             InputStream is = getInputStream(status);
86
87             if (is == null)
88             {
89                 return true;
90             }
91
92             if (localize())
93             {
94                 status.setText("Copying and configuring "
95                     + getSourceName().getStringValue());
96                 copyAndLocalize(
97                     is,
98                     installDir,
99                     getDestinationName().getStringValue(),
100                     getDestinationDirectory().getStringValue(),
101                     propMap);
102             }
103             else
104             {
105                 status.setText("Copying " + getSourceName().getStringValue());
106                 copy(
107                     is,
108                     installDir,
109                     getDestinationName().getStringValue(),
110                     getDestinationDirectory().getStringValue());
111             }
112
113             is.close();
114
115         }
116         catch (Exception JavaDoc ex)
117         {
118             System.err.println(ex);
119             return false;
120         }
121
122         return true;
123     }
124 }
Popular Tags