Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbvosburgh2011-05-11 15:27:34 +0000
committerbvosburgh2011-05-11 15:27:34 +0000
commit8a54688d33fdd37a7c0e6a70c8014cb239fa978a (patch)
tree75e421c8aec71045a341403236a8756e6cd23d90
parent7ad44dd68ee96a7d83031c1cc7677cfd35571ae2 (diff)
downloadwebtools.dali-8a54688d33fdd37a7c0e6a70c8014cb239fa978a.tar.gz
webtools.dali-8a54688d33fdd37a7c0e6a70c8014cb239fa978a.tar.xz
webtools.dali-8a54688d33fdd37a7c0e6a70c8014cb239fa978a.zip
[345441] close jaxb.properties file
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbprops/JaxbPropertiesResourceImpl.java107
1 files changed, 56 insertions, 51 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbprops/JaxbPropertiesResourceImpl.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbprops/JaxbPropertiesResourceImpl.java
index 40efcc14e0..67a308902b 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbprops/JaxbPropertiesResourceImpl.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbprops/JaxbPropertiesResourceImpl.java
@@ -1,19 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2011 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.core.internal.resource.jaxbprops;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaCore;
@@ -25,87 +24,93 @@ import org.eclipse.jpt.jaxb.core.resource.jaxbprops.JaxbPropertiesResource;
public class JaxbPropertiesResourceImpl
- implements JaxbPropertiesResource {
-
+ implements JaxbPropertiesResource
+{
+ protected final IFile file;
+
+ protected final String packageName;
+
+ protected final Properties properties = new Properties();
+
protected final ListenerList<JptResourceModelListener> resourceModelListenerList =
new ListenerList<JptResourceModelListener>(JptResourceModelListener.class);
-
- protected IFile file;
-
- protected String packageName;
-
- protected final Properties properties = new Properties();
-
-
+
+
public JaxbPropertiesResourceImpl(IFile file) {
super();
if (file == null) {
- throw new IllegalArgumentException("file cannot be null");
+ throw new NullPointerException();
}
this.file = file;
- this.packageName = buildPackageName();
- buildProperties();
+ this.packageName = this.buildPackageName();
+ this.loadProperties();
}
-
-
+
protected String buildPackageName() {
IJavaElement javaElement = JavaCore.create(this.file.getParent());
- if (javaElement != null && javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
+ if ((javaElement != null) && (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT)) {
return ((IPackageFragment) javaElement).getElementName();
}
return null;
}
-
- private void buildProperties() {
+
+ protected void reloadProperties() {
+ this.properties.clear();
+ this.loadProperties();
+ }
+
+ protected void loadProperties() {
InputStream stream = null;
-
try {
- stream = file.getContents();
- }
- catch (CoreException ce) {
- JptJaxbCorePlugin.log(ce);
- return;
- }
-
- if (stream != null) {
- try {
+ stream = this.file.getContents();
+ if (stream != null) {
this.properties.load(stream);
}
- catch (IOException ioe) {
- JptJaxbCorePlugin.log(ioe);
+ } catch (Exception ex) {
+ JptJaxbCorePlugin.log(ex);
+ } finally {
+ this.closeStream(stream);
+ }
+ }
+
+ protected void closeStream(InputStream stream) {
+ try {
+ if (stream != null) {
+ stream.close();
}
+ } catch (IOException ex) {
+ JptJaxbCorePlugin.log(ex);
}
}
-
+
void update() {
- this.properties.clear();
- buildProperties();
- resourceModelChanged();
+ this.reloadProperties();
+ this.resourceModelChanged();
}
-
+
public String getPackageName() {
return this.packageName;
}
-
+
public String getProperty(String propertyName) {
return this.properties.getProperty(propertyName);
}
-
-
+
+
// ********** JptResourceModel implementation **********
-
+
public JptResourceType getResourceType() {
return JptJaxbCorePlugin.JAXB_PROPERTIES_RESOURCE_TYPE;
}
-
+
public void addResourceModelListener(JptResourceModelListener listener) {
this.resourceModelListenerList.add(listener);
}
-
+
public void removeResourceModelListener(JptResourceModelListener listener) {
this.resourceModelListenerList.remove(listener);
}
-
+
protected void resourceModelChanged() {
for (JptResourceModelListener listener : this.resourceModelListenerList.getListeners()) {
listener.resourceModelChanged(this);

Back to the top