languagedefinition.java
来自「非常接近C/S操作方式的Java Ajax框架-ZK 用ZK框架使你的B/S应」· Java 代码 · 共 626 行 · 第 1/2 页
JAVA
626 行
* * <p>Note: anonymous component definition won't be returned by * this method. * * @param name the name of the component definition. * @exception DefinitionNotFoundException is thrown if the definition * is not found */ public ComponentDefinition getComponentDefinition(String name) { if (isCaseInsensitive()) name = name.toLowerCase(); synchronized (_compdefs) { final ComponentDefinition compdef = (ComponentDefinition)_compdefs.get(name); if (compdef == null) throw new DefinitionNotFoundException("Component definition not found: "+name); return compdef; } } /** Returns whether the component of the specified name exists. */ public boolean hasComponentDefinition(String name) { if (isCaseInsensitive()) name = name.toLowerCase(); synchronized (_compdefs) { return _compdefs.containsKey(name); } } /** Returns {@link ComponentDefinition} of the specified class. * * <p>Note: anonymous component definition won't be returned by * this method. * * @param klass the class that implements the component. * @exception DefinitionNotFoundException is thrown if the definition * is not found */ public ComponentDefinition getComponentDefinition(Class klass) { synchronized (_compdefsByClass) { for (Class cls = klass; cls != null; cls = cls.getSuperclass()) { final ComponentDefinition compdef = (ComponentDefinition)_compdefsByClass.get(cls.getName()); if (compdef != null) return compdef; } } throw new DefinitionNotFoundException("Component definition not found: "+klass); } /** Adds a {@link ComponentDefinition}. * @return the previous component definition, or null if it isn't defined yet. */ /*package*/ ComponentDefinition addComponentDefinition(ComponentDefinition compdef) { final Object implcls = compdef.getImplementationClass(); ComponentDefinition old; synchronized (_compdefsByClass) { old = (ComponentDefinition)_compdefsByClass.put( implcls instanceof Class ? ((Class)implcls).getName(): implcls, compdef); } if (old != null) log.info(old+" is overwriten by "+compdef+" because they use the same class: "+implcls); final String nm = compdef.getName(); synchronized (_compdefs) { old = (ComponentDefinition)_compdefs.put( isCaseInsensitive() ? nm.toLowerCase(): nm, compdef); } if (old != null) log.info(old+" is overwriten by "+compdef+" because they use the same name: "+compdef.getName()); return old; } /** Adds a script for BeanShell. */ public void addScript(String script) { if (script != null && script.length() > 0) { synchronized (_scripts) { _scripts.add(script); } } } /** Returns all scripts. */ /*package*/ List getScripts() { return _scripts; } /** Adds a {@link JavaScript} required by this language. */ public void addJavaScript(JavaScript js) { if (js == null) throw new IllegalArgumentException("null js"); synchronized (_js) { _js.add(js); } } /** Returns a readonly list of all {@link JavaScript} required * by this language. */ public List getJavaScripts() { return _rojs; } /** Adds the definition of a JavaScript module to this language. * <p>A JavaScript module represents a JavaScript file. This definition * is mainly used to define its version, such that ZK could encode * its URL such that browsers know when to reload it. */ public void addJavaScriptModule(String name, String version) { if (name == null || name.length() == 0 || version == null || version.length() == 0) throw new IllegalArgumentException(); _jsmods.put(name, version); } /** Returns a map of definitions of JavaScript modules, * (String name, String version). */ public Map getJavaScriptModules() { return _rojsmods; } /** Adds a {@link StyleSheet} required by this language. */ public void addStyleSheet(StyleSheet ss) { if (ss == null) throw new IllegalArgumentException("null ss"); synchronized (_ss) { _ss.add(ss); } } /** Returns a readonly list of all {@link StyleSheet} required * by this language. */ public List getStyleSheets() { return _ross; } /** Returns whether the element names are case-insensitive. */ public boolean isCaseInsensitive() { return _ignoreCase; } /** Sets whether the element names are case-insensitive. */ /*package*/ void setCaseInsensitive(boolean caseInsensitive) { _ignoreCase = caseInsensitive; } /** Return the URI to render a full page (which might be an expression). */ public String getDesktopURI() { return _desktopURI; } /** Return the URI to render a included page (which might be an expression). */ public String getPageURI() { return _pageURI; } /** Initializes the specified definition of a macro component * based on {@link #setMacroTemplate}. */ public void initMacroDefinition(ComponentDefinition compdef) { if (_macrotmpl == null) throw new UiException("No macro component is supported by "+this); if (!compdef.isMacro()) throw new UiException("Not macro component: "+compdef); compdef.addMold("default", _macrotmpl.moldURI); compdef.setImplementationClass(_macrotmpl.klass); } /** Sets the macro template. */ public void setMacroTemplate(Class klass, String moldURI) { _macrotmpl = klass != null ? new MacroTemplate(klass, moldURI): null; } /** Sets the component and attribute names used to represent a label. * Since label is used a lot in a page, there is a simple way to create * an {@link InstanceDefinition} by calling {@link #newLabelDefinition}. * * <p>To be able to call {@link #newLabelDefinition}, this method must * be called to define the component and attribute names used to create * an {@link InstanceDefinition} for a label. */ public void setLabelTemplate(String compName, String propName, boolean raw) { _labeltmpl = compName != null ? new LabelTemplate(compName, propName, raw): null; } /** Constructs and returns an {@link InstanceDefinition} for * the specified parent and text, */ public InstanceDefinition newLabelDefinition(InstanceDefinition parent, String text) { if (_labeltmpl == null) throw new UiException("No default label component is supported by "+this); return _labeltmpl.newDefinition(parent, text); } /** Returns whether the raw label is required. * If true, the parser won't trim the text, and the text is generated * directly to the output without any wrapping. */ public boolean isRawLabel() { return _labeltmpl != null && _labeltmpl.raw; } /** Adds the definition for the dynamic tag. * * @param compnm the component name used to represent any of dynamic * tags for this language. If null, it means this language definition * doesn't support the dynamic tag. * @param reservedAttrs a set of reserved attributes that * the dynamic tag support. The reserved attributes are the if, unless * and use attributes. */ public void setDynamicTagInfo(String compnm, Set reservedAttrs) { if (compnm != null && _dyntagnm != null) log.warning("Overwriting the definition of dynamic tag. Previous="+_dyntagnm+" New="+compnm+" for "+this); _dyntagnm = compnm; _dyntagDefn = null; _dyntagRvAttrs = compnm == null || reservedAttrs.isEmpty() ? null: Collections.unmodifiableSet(new HashSet(reservedAttrs)); } /** Returns the component defintion of the dynamic tag, or null if * this language doesn't support the dynamic tag. * @exception DefinitionNotFoundException is thrown if the definition * is not found */ public ComponentDefinition getDynamicTagDefinition() { if (_dyntagDefn == null) { //no sync since racing is OK if (_dyntagnm == null) return null; _dyntagDefn = getComponentDefinition(_dyntagnm); } return _dyntagDefn; } /** Returns whether a reserved attribute is used by the dynamic tag * ({@link #getDynamicTagDefinition}). */ public boolean isDynamicReservedAttributes(String attr) { return _dyntagRvAttrs != null && _dyntagRvAttrs.contains(attr); } /** Adds a tag lib. */ public void addTaglib(Taglib taglib) { synchronized (_taglibs) { _taglibs.add(taglib); _mapper = null; //ask for re-parse } } /** Returns the function mapper. */ private FunctionMapper getFunctionMapper() { if (_mapper == null) { synchronized (this) { _mapper = FunctionMappers.getFunctionMapper(_taglibs, _locator); } } return _mapper; } /** Returns the evaluator associated with this definition. */ public Evaluator getEvaluator() { return _evalor; } //Object// public String toString() { return "[LanguageDefinition: "+_name+']'; } private static class MacroTemplate { private final Class klass; private final String moldURI; private MacroTemplate(Class klass, String moldURI) { if (klass == null || !Component.class.isAssignableFrom(klass) || moldURI == null || moldURI.length() == 0) throw new IllegalArgumentException("class="+klass+", mold="+moldURI); this.klass = klass; this.moldURI = moldURI; } } private class LabelTemplate { /** The component definition. */ private ComponentDefinition _compdef; /** The component name used for contructing a label. */ private final String _name; /** The component property used for contructing a label. */ private final String _prop; /** Whether the raw label is required. */ private final boolean raw; private LabelTemplate(String name, String prop, boolean raw) { if (name == null || name.length() == 0 || prop == null || prop.length() == 0) throw new IllegalArgumentException(); _name = name; _prop = prop; this.raw = raw; } private InstanceDefinition newDefinition( InstanceDefinition parent, String text) { if (_compdef == null) //no sync since racing is OK _compdef = getComponentDefinition(_name); final InstanceDefinition instdef = new InstanceDefinition(parent, _compdef); instdef.addProperty(_prop, text, null); return instdef; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?