Author: scabanovich
Date: 2009-12-17 10:50:22 -0500 (Thu, 17 Dec 2009)
New Revision: 19423
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/EntityRecognizerExtension.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XModel.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarFolderImpl.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/loaders/impl/ModelEntityRecognizer.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseJavaUtil.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4943
Added opportunity to recognize entity by file name even if xml doctype/schema is missing.
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XModel.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XModel.java 2009-12-17
14:40:21 UTC (rev 19422)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XModel.java 2009-12-17
15:50:22 UTC (rev 19423)
@@ -16,6 +16,7 @@
import org.jboss.tools.common.model.event.*;
import org.jboss.tools.common.model.undo.XUndoManager;
import org.jboss.tools.common.model.loaders.EntityRecognizer;
+import org.jboss.tools.common.model.loaders.EntityRecognizerExtension;
import org.jboss.tools.common.model.filesystems.impl.FileSystemPeer;
/**
@@ -179,7 +180,7 @@
* Returns a singleton used to resolve entity of a file object.
* @return
*/
- public EntityRecognizer getEntityRecognizer();
+ public EntityRecognizerExtension getEntityRecognizer();
/**
* Returns registry keeping time stamps of loaded file objects.
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java 2009-12-17
14:40:21 UTC (rev 19422)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/AbstractExtendedXMLFileImpl.java 2009-12-17
15:50:22 UTC (rev 19423)
@@ -163,7 +163,7 @@
if(body == null) return;
if(!isForceLoadOn() && body.equals(getAsText())) return;
- String entity =
getModel().getEntityRecognizer().getEntityName(getAttributeValue(XModelObjectConstants.ATTR_NAME_EXTENSION),
body);
+ String entity = getModel().getEntityRecognizer().getEntityName(toFileName(this),
getAttributeValue(XModelObjectConstants.ATTR_NAME_EXTENSION), body);
if(entity == null || !entity.equals(getModelEntity().getName())) {
String[] errors = (body.length() == 0) ? null : XMLUtil.getXMLErrors(new
java.io.StringReader(body), false);
if(errors == null || errors.length == 0) errors = new String[]{"Doctype has been
changed. Please save file for the change to take effect in object model. :0:0"};
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java 2009-12-17
14:40:21 UTC (rev 19422)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FolderImpl.java 2009-12-17
15:50:22 UTC (rev 19423)
@@ -205,14 +205,14 @@
parseFileName(p, f.getName());
String ext = p.getProperty(XModelObjectConstants.ATTR_NAME_EXTENSION);
String body = null;
- String entity = getModel().getEntityRecognizer().getEntityName(ext, body);
+ String entity = getModel().getEntityRecognizer().getEntityName(f.getName(), ext,
body);
if("FileAny".equals(entity)) { //$NON-NLS-1$
boolean isText = XModelObjectLoaderUtil.isTextFile(f, 100);
if(f.length() > 100000 || !isText) entity =
XModelObjectConstants.ENT_FILE_ANY_LONG;
else if(isText) entity = "FileTXT"; //$NON-NLS-1$
} else /*if(entity == null)*/ {
body = getBodySource(f).get();
- entity = getModel().getEntityRecognizer().getEntityName(ext, body);
+ entity = getModel().getEntityRecognizer().getEntityName(f.getName(), ext,
body);
}
if(entity == null || getModel().getMetaData().getEntity(entity) == null) entity =
"FileAny"; //$NON-NLS-1$
p.setProperty(XMetaDataConstants.ENTITY, entity);
@@ -707,6 +707,9 @@
}
private static int question(XModelObject o) {
+ if(Display.getCurrent() == null) {
+ //TODO we cannot display dialog. What should we do?
+ }
return o.getModel().getService().showDialog("Update",
MessageFormat
.format(
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarFolderImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarFolderImpl.java 2009-12-17
14:40:21 UTC (rev 19422)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarFolderImpl.java 2009-12-17
15:50:22 UTC (rev 19423)
@@ -84,13 +84,13 @@
FolderImpl.parseFileName(p, name);
String ext = p.getProperty(XModelObjectConstants.ATTR_NAME_EXTENSION);
String body = null;
- String entity = getModel().getEntityRecognizer().getEntityName(ext, body);
+ String entity = getModel().getEntityRecognizer().getEntityName(name, ext, body);
if("FileAny".equals(entity)) { //$NON-NLS-1$
if(jar.getSize(cpath) > 100000) entity =
XModelObjectConstants.ENT_FILE_ANY_LONG;
else if(jar.isTextEntry(cpath, 100)) entity = "FileTXT";
//$NON-NLS-1$
} else /*if(entity == null)*/ {
body = jar.getContent(cpath);
- entity = getModel().getEntityRecognizer().getEntityName(ext, body);
+ entity = getModel().getEntityRecognizer().getEntityName(name, ext, body);
}
if(entity == null || getModel().getMetaData().getEntity(entity) == null) entity =
"FileAny"; //$NON-NLS-1$
XModelObject c = getModel().createModelObject(entity, p);
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 2009-12-17
14:40:21 UTC (rev 19422)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/impl/XModelImpl.java 2009-12-17
15:50:22 UTC (rev 19423)
@@ -48,6 +48,7 @@
import org.jboss.tools.common.model.filesystems.impl.FileSystemImpl;
import org.jboss.tools.common.model.filesystems.impl.FileSystemPeer;
import org.jboss.tools.common.model.loaders.EntityRecognizer;
+import org.jboss.tools.common.model.loaders.EntityRecognizerExtension;
import org.jboss.tools.common.model.loaders.XObjectLoader;
import org.jboss.tools.common.model.loaders.impl.ModelEntityRecognizer;
import org.jboss.tools.common.model.plugin.ModelMessages;
@@ -120,7 +121,7 @@
return buffer;
}
- public EntityRecognizer getEntityRecognizer() {
+ public EntityRecognizerExtension getEntityRecognizer() {
return recognizer;
}
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/EntityRecognizerExtension.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/EntityRecognizerExtension.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/EntityRecognizerExtension.java 2009-12-17
15:50:22 UTC (rev 19423)
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.loaders;
+
+/**
+ *
+ * Interface is used for cases when file name is sufficient to define entity of file
model object.
+ * @author Viacheslav Kabanovich
+ *
+ */
+public interface EntityRecognizerExtension extends EntityRecognizer {
+
+ public String getEntityName(String fileName, String ext, String body);
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/EntityRecognizerExtension.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/ModelEntityRecognizer.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/ModelEntityRecognizer.java 2009-12-17
14:40:21 UTC (rev 19422)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/loaders/impl/ModelEntityRecognizer.java 2009-12-17
15:50:22 UTC (rev 19423)
@@ -16,7 +16,7 @@
import org.jboss.tools.common.model.plugin.ModelPlugin;
import org.jboss.tools.common.model.util.ModelFeatureFactory;
-public class ModelEntityRecognizer implements EntityRecognizer {
+public class ModelEntityRecognizer implements EntityRecognizerExtension {
private XModelMetaData meta = null;
private HashMap<String,EntityRecognizer[]> recognizers = new
HashMap<String,EntityRecognizer[]>();
@@ -30,6 +30,22 @@
load();
}
+ public String getEntityName(String fileName, String ext, String body) {
+ if(ext != null) ext = ext.toLowerCase();
+ EntityRecognizer[] list = recognizers.get(ext);
+ if(list == null || list.length == 0) return "FileAny"; //$NON-NLS-1$
+ for (EntityRecognizer r: list) {
+ String n = null;
+ if(r instanceof EntityRecognizerExtension) {
+ n = ((EntityRecognizerExtension)r).getEntityName(fileName, ext, body);
+ } else {
+ n = r.getEntityName(ext, body);
+ }
+ if(n != null) return n;
+ }
+ return null;
+ }
+
public String getEntityName(String ext, String body) {
if(ext != null) ext = ext.toLowerCase();
EntityRecognizer[] list = recognizers.get(ext);
@@ -142,21 +158,34 @@
}
}
- private class EntityRecognizerWrapper implements EntityRecognizer {
+ private class EntityRecognizerWrapper implements EntityRecognizerExtension {
String clsname;
EntityRecognizer resolved;
public EntityRecognizerWrapper(String clsname) {
this.clsname = clsname;
}
-
- public String getEntityName(String ext, String body) {
+
+ boolean checkResolved() {
if(resolved == null && clsname != null) {
resolved = find(clsname);
clsname = null;
}
- return (resolved != null) ? resolved.getEntityName(ext, body) : null;
+ return resolved != null;
+ }
+
+ public String getEntityName(String ext, String body) {
+ return checkResolved() ? resolved.getEntityName(ext, body) : null;
}
+
+ public String getEntityName(String fileName, String ext, String body) {
+ if(!checkResolved()) return null;
+ if(resolved instanceof EntityRecognizerExtension) {
+ return ((EntityRecognizerExtension)resolved).getEntityName(fileName, ext, body);
+ } else {
+ return resolved.getEntityName(ext, body);
+ }
+ }
}
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseJavaUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseJavaUtil.java 2009-12-17
14:40:21 UTC (rev 19422)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseJavaUtil.java 2009-12-17
15:50:22 UTC (rev 19423)
@@ -79,6 +79,13 @@
public static String resolveType(IType type, String typeName) {
if(type == null) return null;
if(type.isBinary() || typeName == null) return typeName;
+ int i = typeName.indexOf("<");
+ if(i >= 0) {
+ int j = typeName.lastIndexOf(">");
+ if(j >= i) {
+// typeName = typeName.substring(0, i);
+ }
+ }
String n = getKey(type);
Resolved r = resolved.get(n);
@@ -123,6 +130,8 @@
return typeName;
} catch (JavaModelException e) {
ModelPlugin.getPluginLog().logError(e);
+ } catch (IllegalArgumentException ee) {
+ System.out.println("Illegal " + typeName);
}
return null;
}