扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
图1 |
图2 dependencies标签 |
图3 |
public boolean supports(IAdaptable context) { return context.getAdapter(IStructuredDocumentContext.class) != null; } |
protected ISymbol internalCreate(String symbolName, int scope, IAdaptable context, List problems) { //得到上下文 final IStructuredDocumentContext sContext =(IStructuredDocumentContext) context.getAdapter(IstructuredDocumentContext.class); // 为上下文建立一个DOM上下文 final IDOMContextResolver domResolver = IStructuredDocumentContextResolverFactory.INSTANCE.getDOMContextResolver(sContext); if (domResolver != null) { final Node curNode = domResolver.getNode(); // node必须是XML属性 if (curNode instanceof Attr) { final Attr attr = (Attr) curNode; final Node owningElement = attr.getOwnerElement(); if (owningElement != null) { IProject iProject = workspaceResolver.getProject(); if (iProject != null) { return handleSymbolCreation(symbolName, sContext, attr, owningElement, iProject); } } } } return null; } |
private ISymbol handleSymbolCreation(final String symbolName, final IStructuredDocumentContext context, final Attr attr, final Node owningElement, final IProject project) { // 建立Tab库 final ITaglibContextResolver resolver =IStructuredDocumentContextResolverFactory.INSTANCE .getTaglibContextResolver(context); if (resolver == null || !resolver.canResolveContext(context)) { return null; } final String uri = resolver.getTagURIForNodeName(owningElement); IBeanInstanceSymbol beanSymbol = null; // 处理核心标签库 if ("http://oracle.com/tutorial/fake/taglib".equals(uri)) { final String elementName = owningElement.getLocalName(); final String attrName = attr.getName(); if ("locallyDeclaredBean".equals(elementName)) { if ("var".equals(attrName)) { final NamedNodeMap attrMap = owningElement.getAttributes(); final Node baseNameNode = attrMap.getNamedItem("classname"); if (baseNameNode instanceof Attr) { // 得到bean的名字 final String className = ((Attr)baseNameNode).getValue(); // 建立一个新的空Bean实例符号 beanSymbol = SymbolFactory.eINSTANCE.createIBeanInstanceSymbol(); beanSymbol.setName(attr.getValue()); try { IJavaProject javaProject = JavaCore.create(project); IType type = javaProject.findType(className); if (type != null) { IJavaTypeDescriptor2 javaTypeDescriptor = SymbolFactory.eINSTANCE.createIJavaTypeDescriptor2(); javaTypeDescriptor.setType(type); beanSymbol.setJavaTypeDescriptor(javaTypeDescriptor); } } catch (JavaModelException jme) { } } } } } return beanSymbol; } |
<t:locallyDeclaredBean var="x" classname="beans.MyBean"/> |
图4 |
<?xml version="1.0" encoding="UTF-8"?> <grammar-annotation xmlns="http://org.eclipse.jsf.core/grammarAnnotationSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://org.eclipse.jsf.core/grammarAnnotationSchema D:\\EclipseWTPLatest\\WTPWorkspace\\org.eclipse.jst.jsf.core\\schema\\grammar-annotations.xsd "> <cm-element name="locallyDeclaredBean"> <cm-attribute name="var"> <property name="contributes-value-binding"> < value>true</value> </property> <property name="value-binding-scope"> <value>request</value> </property> <property name="value-binding-symbol-factory"> <value>tutorial.locallyDeclaredBean</value> </property> </cm-attribute> </cm-element> </grammar-annotation> |
<?xml version="1.0" encoding="GB2312" ?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"> <taglib> <tlib-version>1.0</tlib-version> <jsp-version>1.2</jsp-version> <short-name>tutorial</short-name> <uri>http://oracle.com/tutorial/fake/taglib</uri> <tag> <name>locallyDeclaredBean</name> <tag-class>foo</tag-class> <tei-class>foo</tei-class> <body-content>empty</body-content> <attribute> <name>var</name> <required>true</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <name>classname</name> <required>true</required> <rtexprvalue>false</rtexprvalue> </attribute> </tag> </taglib> |
package beans;public class MyBean { public String getFooProperty() { return "foo!"; } } |
<%@page contentType="text/html"%> <%@page pageEncoding="GB2312"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@taglib uri="http://oracle.com/tutorial/fake/taglib" prefix="t" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB2312"> <title>JSP 页</title> </head> <body> <f:view> <h1>JSP 页</h1> <t:locallyDeclaredBean var="x" classname="beans.MyBean"/> <h:outputText value="#{}"/> </f:view> </body> </html> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。