KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > AbstractNLModel


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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;
12
13 import org.eclipse.core.resources.IResource;
14
15 public abstract class AbstractNLModel extends AbstractModel {
16     protected transient NLResourceHelper fNLHelper;
17
18     public NLResourceHelper getNLResourceHelper() {
19         if (fNLHelper == null)
20             fNLHelper = createNLResourceHelper();
21         return fNLHelper;
22     }
23
24     public void resetNLResourceHelper() {
25         fNLHelper = null;
26     }
27
28     public void dispose() {
29         if (fNLHelper != null) {
30             fNLHelper.dispose();
31             fNLHelper = null;
32         }
33         super.dispose();
34     }
35
36     public String JavaDoc getResourceString(String JavaDoc key) {
37         if (key == null)
38             return ""; //$NON-NLS-1$
39

40         if (fNLHelper == null)
41             fNLHelper = createNLResourceHelper();
42         
43         return fNLHelper != null ? fNLHelper.getResourceString(key) : key;
44     }
45     
46     protected abstract NLResourceHelper createNLResourceHelper();
47     
48     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
49         if(adapter == IResource.class) {
50             IResource resource = getUnderlyingResource();
51             return resource == null ? null : resource.getProject();
52         }
53         return super.getAdapter(adapter);
54     }
55
56 }
57
Popular Tags