Author: scabanovich
Date: 2008-04-08 10:24:36 -0400 (Tue, 08 Apr 2008)
New Revision: 7415
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/XModelEntity.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XModelEntityImpl.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/engines/impl/EnginesLoader.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/icons/impl/XStudioIcons.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/impl/XModelImpl.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/impl/XStudioDataLoaderImpl.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java
Log:
JBIDE-893
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/XModelEntity.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/XModelEntity.java 2008-04-08
14:24:18 UTC (rev 7414)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/XModelEntity.java 2008-04-08
14:24:36 UTC (rev 7415)
@@ -11,12 +11,24 @@
package org.jboss.tools.common.meta;
import org.jboss.tools.common.meta.action.XActionList;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.loaders.XObjectLoader;
public interface XModelEntity extends XMetaElement, XDependencies {
public XAttribute[] getAttributes();
public XAttribute getAttribute(String name);
+
+ /**
+ *
+ * @deprecated
+ * @return
+ */
public Class getImplementingClass();
- public Class getLoadingClass();
+
+ public boolean hasObjectImplementation();
+ public XModelObject getObjectImplementation();
+ public boolean hasObjectLoader();
+ public XObjectLoader getObjectLoader();
public String getGeneratorClassName();
public String getEditorClassName();
public XActionList getActionList();
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XModelEntityImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XModelEntityImpl.java 2008-04-08
14:24:18 UTC (rev 7414)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/meta/impl/XModelEntityImpl.java 2008-04-08
14:24:36 UTC (rev 7415)
@@ -29,11 +29,11 @@
protected XAttribute[] m_Attributes;
protected XActionListImpl actions = new XActionListImpl();
protected XEntityRenderer m_Renderer = null;
- protected ClassHolder implementation = null;
protected String implementationClassName = null;
+ protected String resolvedImplementationClassName = null;
protected String m_GeneratorClassName = null;
- protected ClassHolder loader = null;
protected String loaderClassName = null;
+ protected String resolvedLoaderClassName = null;
protected String m_EditorClassName = null;
protected XDependencies dependencies = new DefaultDependencies();
protected XAdoptManager adopt = null;
@@ -89,24 +89,69 @@
}
}
- public Class getImplementingClass(){
- return implementation.getHoldedClass();
+ public Class getImplementingClass() {
+ if(resolvedImplementationClassName == UNRESOLVED) {
+ resolvedImplementationClassName = expand(implementationClassName,
"Implementations");
+ }
+ if(resolvedImplementationClassName == null) return null;
+ Class cls =
ModelFeatureFactory.getInstance().getFeatureClass(resolvedImplementationClassName);
+ if(cls == null) {
+ resolvedImplementationClassName = null;
+ }
+ return cls;
}
+ public boolean hasObjectImplementation() {
+ return implementationClassName != null && implementationClassName.length()
> 0;
+ }
+
+ public XModelObject getObjectImplementation() {
+ if(resolvedImplementationClassName == UNRESOLVED) {
+ resolvedImplementationClassName = expand(implementationClassName,
"Implementations");
+ }
+ if(resolvedImplementationClassName == null) return null;
+ XModelObject o =
ModelFeatureFactory.getInstance().createXModelObjectInstance(resolvedImplementationClassName);
+ if(o == null) {
+ resolvedImplementationClassName = null;
+ }
+ return o;
+ }
+
public void setImplementingClassName(String className){
if(className != null && className.length() == 0) className = null;
- implementation = new ClassHolder(className, this, "Implementations");
implementationClassName = className;
+ if(className != null) {
+ resolvedImplementationClassName = UNRESOLVED;
+ }
}
- public Class getLoadingClass() {
- return (loader == null) ? null : loader.getHoldedClass();
+ public boolean hasObjectLoader() {
+ return loaderClassName != null && loaderClassName.length() > 0;
}
+ public XObjectLoader getObjectLoader() {
+ if(resolvedLoaderClassName == UNRESOLVED) {
+ resolvedLoaderClassName = expand(loaderClassName, "Loaders");
+ }
+ if(resolvedLoaderClassName == null) return null;
+ Object o =
ModelFeatureFactory.getInstance().createFeatureInstance(resolvedLoaderClassName);
+ if(o == null) {
+ return null;
+ }
+ if(!(o instanceof XObjectLoader)) {
+ ModelPlugin.getPluginLog().logError("Model object loader" +
resolvedLoaderClassName + " must implement " + XObjectLoader.class.getName());
+ resolvedLoaderClassName = null;
+ return null;
+ }
+ return (XObjectLoader)o;
+ }
+
+ static String UNRESOLVED = "UNRESOLVED";
+
public void setLoaderClassName(String className) {
if(className != null && className.length() > 0) {
- loader = new ClassHolder(className, this, "Loaders");
loaderClassName = className;
+ resolvedLoaderClassName = UNRESOLVED;
}
}
@@ -387,43 +432,6 @@
}
-class ClassHolder {
- private String name = null;
- private XMetaElementImpl element = null;
- private String map = null;
-
- public ClassHolder(String name, XMetaElementImpl element, String map) {
- this.name = name;
- this.element = element;
- this.map = map;
- }
-
- public Class getHoldedClass() {
- if(name == null) return null;
- validate();
- try {
- Class c = ModelFeatureFactory.getInstance().getFeatureClass(name);
- if(c == null) name = null;
- return c;
- } catch (Exception e) {
- name = null;
- return null;
- }
- }
-
- private void validate() {
- if(name == null) return;
- if(map != null && name.startsWith("%")) {
- name = element.expand(name, map);
- }
- map = null;
- }
-
- public String getProperty(String name) {
- return null;
- }
-}
-
class XAdoptWrapper implements XAdoptManager {
String adoptclass;
XModelEntityImpl entity;
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/engines/impl/EnginesLoader.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/engines/impl/EnginesLoader.java 2008-04-08
14:24:18 UTC (rev 7414)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/engines/impl/EnginesLoader.java 2008-04-08
14:24:36 UTC (rev 7415)
@@ -16,7 +16,6 @@
import org.jboss.tools.common.model.*;
import org.jboss.tools.common.model.impl.*;
import org.jboss.tools.common.model.loaders.impl.*;
-import org.jboss.tools.common.model.plugin.ModelPlugin;
import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
public class EnginesLoader extends URLRootLoader {
@@ -29,11 +28,8 @@
for (int i = 0; i < cs.length; i++) {
if(!cs[i].isRequired() || cs[i].getMaxCount() != 1) continue;
if(object.getChildren(cs[i].getName()).length > 0) continue;
- try {
- object.addChild(XModelObjectLoaderUtil.createValidObject(object.getModel(),
cs[i].getName()));
- } catch (Exception e) {
- ModelPlugin.getPluginLog().logError("EnginesLoader:load:" +
e.getMessage());
- }
+ //April 2008: catch removed. This call is proved to be safe.
+ object.addChild(XModelObjectLoaderUtil.createValidObject(object.getModel(),
cs[i].getName()));
}
if(isFilePath(getPath(object))) {
File f = file(object);
@@ -101,7 +97,7 @@
map.remove(c.getPathPart());
}
if(!map.isEmpty()) {
- Iterator it = map.values().iterator();
+ Iterator<XModelObject> it = map.values().iterator();
while(it.hasNext()) {
XModelObject o = (XModelObject)it.next();
XChild childEntity = object.getModelEntity().getChild(o.getModelEntity().getName());
@@ -135,11 +131,11 @@
return map;
}
- public static Set<String> getChildrenToRemove(Map save, XModelObject update) {
- Iterator it = save.keySet().iterator();
+ public static Set<String> getChildrenToRemove(Map<String,XModelObject> save,
XModelObject update) {
+ Iterator<String> it = save.keySet().iterator();
Set<String> set = new HashSet<String>();
while(it.hasNext()) {
- String p = it.next().toString();
+ String p = it.next();
if(update.getChildByPath(p) == null) set.add(p);
}
return set;
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/icons/impl/XStudioIcons.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/icons/impl/XStudioIcons.java 2008-04-08
14:24:18 UTC (rev 7414)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/icons/impl/XStudioIcons.java 2008-04-08
14:24:36 UTC (rev 7415)
@@ -11,6 +11,9 @@
package org.jboss.tools.common.model.icons.impl;
import java.io.*;
+
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.jboss.tools.common.model.*;
@@ -50,6 +53,7 @@
private byte[] getBytes(String filename) {
File f = new File(filename);
+ if(!f.isFile()) return new byte[0];
byte[] b = null;
try {
FileInputStream fr = new FileInputStream(f);
@@ -59,7 +63,7 @@
while(i < length) {
i += fr.read(b, i, length - i);
}
- } catch (Exception e) {
+ } catch (IOException e) {
b = new byte[0];
}
return b;
@@ -79,8 +83,10 @@
ImageData id = new ImageData(is);
Image i = new Image(null, id);
return i;
- } catch (Exception e) {
+ } catch (SWTException e) {
ModelPlugin.getPluginLog().logError(e);
+ } catch (SWTError e) {
+ ModelPlugin.getPluginLog().logError(e);
}
}
return
obj.getModelEntity().getMetaModel().getIconList().getImage("default.unknown");
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/impl/XModelImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/impl/XModelImpl.java 2008-04-08
14:24:18 UTC (rev 7414)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/impl/XModelImpl.java 2008-04-08
14:24:36 UTC (rev 7415)
@@ -221,21 +221,31 @@
return null;
}
- static Set<String> unknownEntities = new HashSet<String>();
+ static Set<String> unknownEntities = new HashSet<String>();
+
+ static void creationFailed(String entity, String cause) {
+ if(!unknownEntities.contains(entity)) {
+ unknownEntities.add(entity);
+ String message = XBundle.getInstance().getMessage("model", cause, new
Object[]{entity});
+ ModelPlugin.getPluginLog().logInfo(message);
+ }
+ }
public XModelObject createModelObject(String entity, Properties properties) {
+ if(unknownEntities.contains(entity)) {
+ return null;
+ }
XModelEntity ent = getMetaData().getEntity(entity);
if(ent == null) {
- if(!unknownEntities.contains(entity)) {
- unknownEntities.add(entity);
- String message = XBundle.getInstance().getMessage("model",
"UNKNOUN_ENTITY", new Object[]{entity});
- ModelPlugin.getPluginLog().logInfo(message);
- }
+ creationFailed(entity, "UNKNOUN_ENTITY");
return null;
}
+ XModelObjectImpl me = (XModelObjectImpl)ent.getObjectImplementation();
+ if(me == null) {
+ creationFailed(entity, "CREATION_ENTITY_FAILURE");
+ return null;
+ }
try {
- Class<?> c = ent.getImplementingClass();
- XModelObjectImpl me = (XModelObjectImpl)c.newInstance();
me.setModel(this);
me.setEntityName_0(entity);
XAttribute[] an = ent.getAttributes();
@@ -250,11 +260,7 @@
}
return me;
} catch (Exception e) {
- if(!unknownEntities.contains(entity)) {
- unknownEntities.add(entity);
- String message = XBundle.getInstance().getMessage("model",
"CREATION_ENTITY_FAILURE", new Object[]{entity});
- ModelPlugin.getPluginLog().logError(message, e);
- }
+ creationFailed(entity, "CREATION_ENTITY_FAILURE");
}
return null;
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/impl/XStudioDataLoaderImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/impl/XStudioDataLoaderImpl.java 2008-04-08
14:24:18 UTC (rev 7414)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/impl/XStudioDataLoaderImpl.java 2008-04-08
14:24:36 UTC (rev 7415)
@@ -159,7 +159,7 @@
URL u = b.getResource("meta/options_general.xml");
URLConnection c = u.openConnection();
return c.getInputStream();
- } catch (Exception e) {
+ } catch (IOException e) {
ModelPlugin.getPluginLog().logError(e);
return null;
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java 2008-04-08
14:24:18 UTC (rev 7414)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/XModelObjectLoaderUtil.java 2008-04-08
14:24:36 UTC (rev 7415)
@@ -646,11 +646,10 @@
}
public void load(File f, XModelObject o) {
- try {
- Element element = XMLUtil.getElement(f.getAbsolutePath());
- if(element != null) load(element, o);
- } catch (Exception e) {
-
ModelPlugin.getPluginLog().logError("XModelObjectLoaderUtil:load(f,o):" +
e.getMessage(), e);
+ if(f == null || !f.isFile()) return;
+ Element element = XMLUtil.getElement(f.getAbsolutePath());
+ if(element != null) {
+ load(element, o);
}
}
@@ -748,16 +747,8 @@
}
public static XObjectLoader getObjectLoader(XModelObject object) {
- try {
- Class<?> c = object.getModelEntity().getLoadingClass();
- if (c != null) {
- return (XObjectLoader)c.newInstance();
- }
- return null;
- } catch (Exception e) {
-
ModelPlugin.getPluginLog().logError("XModelObjectLoaderUtil:getObjectLoader(" +
object + "):" + e.getMessage(), e);
- return null;
- }
+ if(object == null) return null;
+ return object.getModelEntity().getObjectLoader();
}
public static void remove(File f) {