KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > target > EnvironmentInfo


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.target;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.eclipse.core.runtime.Platform;
16 import org.eclipse.pde.internal.core.itarget.IEnvironmentInfo;
17 import org.eclipse.pde.internal.core.itarget.ITargetModel;
18 import org.w3c.dom.Node JavaDoc;
19 import org.w3c.dom.NodeList JavaDoc;
20
21 public class EnvironmentInfo extends TargetObject implements IEnvironmentInfo {
22
23     private static final long serialVersionUID = 1L;
24     
25     private String JavaDoc fOS;
26     private String JavaDoc fWS;
27     private String JavaDoc fArch;
28     private String JavaDoc fNL;
29     
30     public EnvironmentInfo(ITargetModel model) {
31         super(model);
32     }
33
34     public String JavaDoc getOS() {
35         return fOS;
36     }
37
38     public String JavaDoc getWS() {
39         return fWS;
40     }
41
42     public String JavaDoc getArch() {
43         return fArch;
44     }
45
46     public String JavaDoc getNL() {
47         return fNL;
48     }
49
50     public void setOS(String JavaDoc os) {
51         String JavaDoc oldValue = fOS;
52         fOS = os;
53         firePropertyChanged(P_OS, oldValue, fOS);
54     }
55
56     public void setWS(String JavaDoc ws) {
57         String JavaDoc oldValue = fWS;
58         fWS = ws;
59         firePropertyChanged(P_WS, oldValue, fWS);
60     }
61
62     public void setArch(String JavaDoc arch) {
63         String JavaDoc oldValue = fArch;
64         fArch = arch;
65         firePropertyChanged(P_ARCH, oldValue, fArch);
66     }
67
68     public void setNL(String JavaDoc nl) {
69         String JavaDoc oldValue = fNL;
70         fNL = nl;
71         firePropertyChanged(P_NL, oldValue, fNL);
72     }
73
74     public void parse(Node JavaDoc node) {
75         NodeList JavaDoc list = node.getChildNodes();
76         for (int i = 0; i < list.getLength(); i++) {
77             Node JavaDoc child = list.item(i);
78             if (child.getNodeType() == Node.ELEMENT_NODE) {
79                 if (child.getNodeName().equals(P_OS)) {
80                     fOS = getText(child);
81                 } else if (child.getNodeName().equals(P_WS)) {
82                     fWS = getText(child);
83                 } else if (child.getNodeName().equals(P_ARCH)) {
84                     fArch = getText(child);
85                 } else if (child.getNodeName().equals(P_NL)) {
86                     fNL = getText(child);
87                 }
88             }
89         }
90     }
91         
92     private String JavaDoc getText(Node JavaDoc node) {
93         node.normalize();
94         Node JavaDoc text = node.getFirstChild();
95         if (text != null && text.getNodeType() == Node.TEXT_NODE) {
96             return text.getNodeValue();
97         }
98         return ""; //$NON-NLS-1$
99
}
100     
101     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
102         // if no elements set, then don't write anything
103
if ((fOS == null || fOS.length() == 0) && (fWS == null || fWS.length() == 0) &&
104                 (fArch == null || fArch.length() == 0) && (fNL == null || fNL.length() == 0))
105             return;
106         writer.println();
107         writer.println(indent + "<environment>"); //$NON-NLS-1$
108
if (fOS != null && fOS.length() > 0)
109             writer.println(indent + " <" + P_OS + ">" + getWritableString(fOS) + "</" + P_OS + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
110
if (fWS != null && fWS.length() > 0)
111             writer.println(indent + " <" + P_WS + ">" + getWritableString(fWS) + "</" + P_WS + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
112
if (fArch != null && fArch.length() > 0)
113             writer.println(indent + " <" + P_ARCH + ">" + getWritableString(fArch) + "</" + P_ARCH + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
114
if (fNL != null && fNL.length() > 0)
115             writer.println(indent + " <" + P_NL + ">" + getWritableString(fNL) + "</" + P_NL + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
116
writer.println(indent + "</environment>"); //$NON-NLS-1$
117
}
118
119     public String JavaDoc getDisplayOS() {
120         if (fOS == null || fOS.trim().length() == 0)
121             return Platform.getOS();
122         return fOS.trim();
123     }
124
125     public String JavaDoc getDisplayWS() {
126         if (fWS == null || fWS.trim().length() == 0)
127             return Platform.getWS();
128         return fWS.trim();
129     }
130
131     public String JavaDoc getDisplayArch() {
132         if (fArch == null || fArch.trim().length() == 0)
133             return Platform.getOSArch();
134         return fArch.trim();
135     }
136
137     public String JavaDoc getDisplayNL() {
138         if (fNL == null || fNL.trim().length() == 0)
139             return Platform.getNL();
140         return fNL.trim();
141     }
142
143 }
144
Popular Tags