KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > nls > AccessorDescription


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jdt.internal.ui.refactoring.nls;
12
13 import org.eclipse.core.runtime.IPath;
14
15 import org.eclipse.jface.dialogs.IDialogSettings;
16
17 import org.eclipse.jdt.core.IJavaElement;
18 import org.eclipse.jdt.core.IPackageFragment;
19 import org.eclipse.jdt.core.JavaCore;
20
21 import org.eclipse.jdt.ui.JavaElementLabels;
22
23
24 /**
25  *
26  */

27 public class AccessorDescription {
28     
29     private final static String JavaDoc KEY_ACCESSOR_NAME= "accessorName"; //$NON-NLS-1$
30
private final static String JavaDoc KEY_ACCESSOR_PACK= "accessorPackage"; //$NON-NLS-1$
31
private final static String JavaDoc KEY_RESOURCE_BUNDLE_NAME= "bundleName"; //$NON-NLS-1$
32
private final static String JavaDoc KEY_RESOURCE_BUNDLE_PACK= "bundlePackage"; //$NON-NLS-1$
33

34     
35     private final IPackageFragment fResourceBundlePackage;
36     private final String JavaDoc fAccessorClassName;
37     private final IPackageFragment fAccessorClassPackage;
38     private final String JavaDoc fResourceBundleName;
39
40     /**
41      *
42      */

43     public AccessorDescription(String JavaDoc accessorClassName, IPackageFragment accessorClassPackage, String JavaDoc propertyFileName, IPackageFragment propertyFilePackage) {
44         super();
45         fAccessorClassName= accessorClassName;
46         fAccessorClassPackage= accessorClassPackage;
47         fResourceBundleName= propertyFileName;
48         fResourceBundlePackage= propertyFilePackage;
49     }
50     
51     public String JavaDoc getLabel() {
52         StringBuffer JavaDoc buf= new StringBuffer JavaDoc();
53         buf.append(getAccessorClassPackage().getElementName());
54         if (buf.length() > 0) {
55             buf.append('.');
56         }
57         buf.append(getAccessorClassName());
58         buf.append(JavaElementLabels.CONCAT_STRING);
59         IPath propertyFilePath= getResourceBundlePackage().getPath().append(getResourceBundleName());
60         buf.append(propertyFilePath.makeRelative().toString());
61         return buf.toString();
62     }
63     
64     public void serialize(IDialogSettings settings) {
65         settings.put(KEY_ACCESSOR_NAME, getAccessorClassName());
66         settings.put(KEY_ACCESSOR_PACK, getAccessorClassPackage().getHandleIdentifier());
67         settings.put(KEY_RESOURCE_BUNDLE_NAME, getResourceBundleName());
68         settings.put(KEY_RESOURCE_BUNDLE_PACK, getResourceBundlePackage().getHandleIdentifier());
69     }
70
71     /**
72      * @return Returns the accessor class name.
73      */

74     public String JavaDoc getAccessorClassName() {
75         return fAccessorClassName;
76     }
77     /**
78      * @return Returns the accessor class package.
79      */

80     public IPackageFragment getAccessorClassPackage() {
81         return fAccessorClassPackage;
82     }
83     /**
84      * @return Returns the resource bundle name.
85      */

86     public String JavaDoc getResourceBundleName() {
87         return fResourceBundleName;
88     }
89     /**
90      * @return Returns the resource bundle package
91      */

92     public IPackageFragment getResourceBundlePackage() {
93         return fResourceBundlePackage;
94     }
95     
96     /* (non-Javadoc)
97      * @see java.lang.Object#equals(java.lang.Object)
98      */

99     public boolean equals(Object JavaDoc obj) {
100         if (obj != null && obj.getClass().equals(getClass())) {
101             AccessorDescription other= (AccessorDescription) obj;
102             return other == this ||
103               (other.fAccessorClassName.equals(fAccessorClassName)
104               && other.fAccessorClassPackage.equals(fAccessorClassPackage)
105               && other.fResourceBundleName.equals(fResourceBundleName)
106               && other.fResourceBundlePackage.equals(fResourceBundlePackage));
107         }
108         return false;
109     }
110     
111     /* (non-Javadoc)
112      * @see java.lang.Object#hashCode()
113      */

114     public int hashCode() {
115         return fAccessorClassName.hashCode() + fAccessorClassPackage.hashCode() + fResourceBundleName.hashCode() + fResourceBundlePackage.hashCode();
116     }
117     
118     public static AccessorDescription deserialize(IDialogSettings settings) {
119         String JavaDoc accessorName= settings.get(KEY_ACCESSOR_NAME);
120         if (accessorName == null) {
121             return null;
122         }
123         
124         String JavaDoc accessorPackHandle= settings.get(KEY_ACCESSOR_PACK);
125         if (accessorPackHandle == null) {
126             return null;
127         }
128         IJavaElement accessorPack= JavaCore.create(accessorPackHandle);
129         if (!(accessorPack instanceof IPackageFragment) || !accessorPack.exists()) {
130             return null;
131         }
132         
133         String JavaDoc bundleName= settings.get(KEY_RESOURCE_BUNDLE_NAME);
134         if (bundleName == null) {
135             return null;
136         }
137         
138         String JavaDoc bundlePackHandle= settings.get(KEY_RESOURCE_BUNDLE_PACK);
139         if (bundlePackHandle == null) {
140             return null;
141         }
142         IJavaElement bundlePack= JavaCore.create(bundlePackHandle);
143         if (!(bundlePack instanceof IPackageFragment) || !bundlePack.exists()) {
144             return null;
145         }
146         
147         return new AccessorDescription(accessorName, (IPackageFragment) accessorPack, bundleName, (IPackageFragment) bundlePack);
148     }
149 }
150
Popular Tags