1 11 package org.eclipse.core.expressions; 12 13 import org.w3c.dom.Element ; 14 import org.w3c.dom.Node ; 15 16 import org.eclipse.core.runtime.Assert; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IConfigurationElement; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Status; 21 22 import org.eclipse.core.internal.expressions.CompositeExpression; 23 import org.eclipse.core.internal.expressions.ExpressionMessages; 24 import org.eclipse.core.internal.expressions.ExpressionPlugin; 25 import org.eclipse.core.internal.expressions.Messages; 26 27 40 public final class ExpressionConverter { 41 42 private ElementHandler[] fHandlers; 43 private static final ExpressionConverter INSTANCE= new ExpressionConverter( 44 new ElementHandler[] { ElementHandler.getDefault() } ); 45 46 53 public static ExpressionConverter getDefault() { 54 return INSTANCE; 55 } 56 57 67 public ExpressionConverter(ElementHandler[] handlers) { 68 Assert.isNotNull(handlers); 69 fHandlers= handlers; 70 } 71 72 86 public Expression perform(IConfigurationElement root) throws CoreException { 87 for (int i= 0; i < fHandlers.length; i++) { 88 ElementHandler handler= fHandlers[i]; 89 Expression result= handler.create(this, root); 90 if (result != null) 91 return result; 92 } 93 return null; 94 } 95 96 111 public Expression perform(Element root) throws CoreException { 112 for (int i= 0; i < fHandlers.length; i++) { 113 ElementHandler handler= fHandlers[i]; 114 Expression result= handler.create(this, root); 115 if (result != null) 116 return result; 117 } 118 return null; 119 } 120 121 void processChildren(IConfigurationElement element, CompositeExpression result) throws CoreException { 122 IConfigurationElement[] children= element.getChildren(); 123 if (children != null) { 124 for (int i= 0; i < children.length; i++) { 125 Expression child= perform(children[i]); 126 if (child == null) 127 throw new CoreException(new Status(IStatus.ERROR, ExpressionPlugin.getPluginId(), 128 IStatus.ERROR, 129 Messages.format( 130 ExpressionMessages.Expression_unknown_element, 131 children[i].getName()), 132 null)); 133 result.add(child); 134 } 135 } 136 } 137 138 void processChildren(Element element, CompositeExpression result) throws CoreException { 139 Node child = element.getFirstChild(); 140 while (child != null) { 141 if (child.getNodeType() == Node.ELEMENT_NODE) { 142 Expression exp= perform((Element )child); 143 if (exp == null) 144 throw new CoreException(new Status(IStatus.ERROR, ExpressionPlugin.getPluginId(), 145 IStatus.ERROR, 146 Messages.format( 147 ExpressionMessages.Expression_unknown_element, 148 child.getNodeName()), 149 null)); 150 result.add(exp); 151 } 152 child = child.getNextSibling(); 153 } 154 } 155 } | Popular Tags |