📄 component.java
字号:
* User u = (User)getModelObject(); * u.setName("got you there!"); * </pre> * * can't be prevented. Indeed it can be argued that any model protection is best dealt with in * your model objects to be completely secured. Wicket will catch all normal framework-directed * use though. */ public static final Action ENABLE = new Action(Action.ENABLE); /** Separator for component paths */ public static final char PATH_SEPARATOR = ':'; /** * Action used with IAuthorizationStrategy to determine whether a component and its children are * allowed to be rendered. * <p> * There are two uses for this method: * <ul> * <li>The 'normal' use is for controlling whether a component is rendered without having any * effect on the rest of the processing. If a strategy lets this method return 'false', then the * target component and its children will not be rendered, in the same fashion as if that * component had visibility property 'false'.</li> * <li>The other use is when a component should block the rendering of the whole page. So * instead of 'hiding' a component, what we generally want to achieve here is that we force the * user to logon/give-credentials for a higher level of authorization. For this functionality, * the strategy implementation should throw a {@link AuthorizationException}, which will then * be handled further by the framework.</li> * </ul> * </p> */ public static final Action RENDER = new Action(Action.RENDER); /** meta data key for missing body tags logging. */ private static final MetaDataKey BORDER_KEY = new MetaDataKey(IComponentBorder.class) { private static final long serialVersionUID = 1L; }; /* meta data for user specified markup id */ private static final MetaDataKey MARKUP_ID_KEY = new MetaDataKey(String.class) { private static final long serialVersionUID = 1L; }; /** Basic model IModelComparator implementation for normal object models */ private static final IModelComparator defaultModelComparator = new IModelComparator() { private static final long serialVersionUID = 1L; public boolean compare(Component component, Object b) { final Object a = component.getModelObject(); if (a == null && b == null) { return true; } if (a == null || b == null) { return false; } return a.equals(b); } }; /** True when a component is being auto-added */ private static final int FLAG_AUTO = 0x0001; /** Flag for escaping HTML in model strings */ private static final int FLAG_ESCAPE_MODEL_STRINGS = 0x0002; /** * Boolean whether this component's model is inheritable. */ static final int FLAG_INHERITABLE_MODEL = 0x0004; /** Versioning boolean */ private static final int FLAG_VERSIONED = 0x0008; /** Visibility boolean */ private static final int FLAG_VISIBLE = 0x0010; /** Render tag boolean */ private static final int FLAG_RENDER_BODY_ONLY = 0x0020; /** Ignore attribute modifiers */ private static final int FLAG_IGNORE_ATTRIBUTE_MODIFIER = 0x0040; /** True when a component is enabled for model updates and is reachable. */ private static final int FLAG_ENABLED = 0x0080; /** Reserved subclass-definable flag bit */ protected static final int FLAG_RESERVED1 = 0x0100; /** Reserved subclass-definable flag bit */ protected static final int FLAG_RESERVED2 = 0x0200; /** Reserved subclass-definable flag bit */ protected static final int FLAG_RESERVED3 = 0x0400; /** Reserved subclass-definable flag bit */ protected static final int FLAG_RESERVED4 = 0x0800; /** * Boolean whether this component was rendered at least once for tracking changes. */ private static final int FLAG_HAS_BEEN_RENDERED = 0x1000; /** * Internal indicator of whether this component may be rendered given the current context's * authorization. It overrides the visible flag in case this is false. Authorization is done * before trying to render any component (otherwise we would end up with a half rendered page in * the buffer) */ private static final int FLAG_IS_RENDER_ALLOWED = 0x2000; /** * Whether or not the component should print out its markup id into the id attribute */ private static final int FLAG_OUTPUT_MARKUP_ID = 0x4000; /** * Output a placeholder tag if the component is not visible. This is useful in ajax mode to go * to visible(false) to visible(true) without the overhead of repainting a visible parent * container */ private static final int FLAG_PLACEHOLDER = 0x8000; /** Reserved subclass-definable flag bit */ protected static final int FLAG_RESERVED5 = 0x10000; /** Reserved subclass-definable flag bit */ protected static final int FLAG_RESERVED6 = 0x20000; /** Reserved subclass-definable flag bit */ protected static final int FLAG_RESERVED7 = 0x40000; /** Reserved subclass-definable flag bit */ protected static final int FLAG_RESERVED8 = 0x80000; /** * Flag that determines whether the model is set. This is necessary because of the way we * represent component state ({@link #data}). We can't distinguish between model and behavior * using instanceof, because one object can implement both interfaces. Thus we need this flag - * when the flag is set, first object in {@link #data} is always model. */ private static final int FLAG_MODEL_SET = 0x100000; private static final int FLAG_BEFORE_RENDERING_SUPER_CALL_VERIFIED = 0x1000000; /** * Flag that makes we are in before-render callback phase Set after component.onBeforeRender is * invoked (right before invoking beforeRender on children) */ private static final int FLAG_PREPARED_FOR_RENDER = 0x4000000; private static final int FLAG_RENDERING = 0x2000000; private static final int FLAG_AFTER_RENDERING = 0x8000000; private static final int FLAG_ATTACHED = 0x20000000; private static final int FLAG_DETACHING = 0x80000000; /** Log. */ private static final Logger log = LoggerFactory.getLogger(Component.class); /** * The name of attribute that will hold markup id */ private static final String MARKUP_ID_ATTR_NAME = "id"; private static final long serialVersionUID = 1L; /** * Meta data key for line precise error logging for the moment of addition. Made package private * for access in {@link MarkupContainer} and {@link Page} */ static final MetaDataKey ADDED_AT_KEY = new MetaDataKey(String.class) { private static final long serialVersionUID = 1L; }; /** * meta data key for line precise error logging for the moment of construction. Made package * private for access in {@link Page} */ static final MetaDataKey CONSTRUCTED_AT_KEY = new MetaDataKey(String.class) { private static final long serialVersionUID = 1L; }; /** Component flags. See FLAG_* for possible non-exclusive flag values. */ private int flags = FLAG_VISIBLE | FLAG_ESCAPE_MODEL_STRINGS | FLAG_VERSIONED | FLAG_ENABLED | FLAG_IS_RENDER_ALLOWED; /** Component id. */ private String id; /** Any parent container. */ private MarkupContainer parent; /** * I really dislike it, but for now we need it. Reason: due to transparent containers and * IComponentResolver there is guaranteed 1:1 mapping between component and markup */ int markupIndex = -1; /** * Instead of remembering the whole markupId, we just remember the number for this component so * we can "reconstruct" the markupId on demand. While this could be part of {@link #data}, * profiling showed that having it as separate property consumes less memory. */ int generatedMarkupId = -1; /** * MetaDataEntry array. */// private MetaDataEntry[] metaData;//// /** List of behaviors to be applied for this Component */// private Object behaviors;//// /** The model for this component. */// IModel model; /** * The object that holds the component state. * <p> * What's stored here depends on what attributes are set on component. Data can contains * combination of following attributes: * <ul> * <li>Model (indicated by {@link #FLAG_MODEL_SET}) * <li>MetaDataEntry (optionally {@link MetaDataEntry}[] if more metadata entries are present) * * <li>{@link IBehavior}(s) added to component. The behaviors are not stored in separate * array, they are part of the {@link #data} array * </ul> * If there is only one attribute set (i.e. model or MetaDataEntry([]) or one behavior), the * #data object points directly to value of that attribute. Otherwise the data is of type * Object[] where the attributes are ordered as specified above. * <p> */ Object data = null; private final int data_length() { if (data == null) { return 0; } else if (data instanceof Object[] && !(data instanceof MetaDataEntry[])) { return ((Object[])data).length; } else { return 1; } } private final Object data_get(int index) { if (data == null) { return null; } else if (data instanceof Object[] && !(data instanceof MetaDataEntry[])) { Object[] array = (Object[])data; return index < array.length ? array[index] : null; } else if (index == 0) { return data; } else { return null; } } private final Object data_set(int index, Object object) { if (index > data_length() - 1) { throw new IndexOutOfBoundsException(); } else if (index == 0 && !(data instanceof Object[] && !(data instanceof MetaDataEntry[]))) { Object old = data; data = object; return old; } else { Object[] array = (Object[])data; Object old = array[index]; array[index] = object; return old; } } private final void data_add(Object object) { data_insert(-1, object); } private final void data_insert(int position, Object object) { int currentLength = data_length(); if (position == -1) { position = currentLength; } if (position > currentLength) { throw new IndexOutOfBoundsException(); } if (currentLength == 0) { data = object; } else if (currentLength == 1) { Object[] array = new Object[2]; if (position == 0) { array[0] = object; array[1] = data; } else { array[0] = data; array[1] = object; } data = array; } else { Object[] array = new Object[currentLength + 1]; Object[] current = (Object[])data; int before = position; int after = currentLength - position; if (before > 0) { System.arraycopy(current, 0, array, 0, before); } array[position] = object; if (after > 0) { System.arraycopy(current, position, array, position + 1, after); } data = array; } } private Object data_remove(int position) { int currentLength = data_length(); if (position > currentLength - 1) { throw new IndexOutOfBoundsException(); } else if (currentLength == 1) { Object old = data; data = null; return old; } else if (currentLength == 2) { Object[] current = (Object[])data; if (position == 0) { data = current[1]; return current[0]; } else { data = current[0]; return current[1]; } } else { Object[] current = (Object[])data; data = new Object[currentLength - 1]; if (position > 0) { System.arraycopy(current, 0, data, 0, position); } if (position != currentLength - 1) { final int left = currentLength - position - 1; System.arraycopy(current, position + 1, data, position, left); } return current[position]; } } /** * Constructor. All components have names. A component's id cannot be null. This is the minimal * constructor of component. It does not register a model. * * @param id * The non-null id of this component * @throws WicketRuntimeException * Thrown if the component has been given a null id. */ public Component(final String id) { setId(id); getApplication().notifyComponentInstantiationListeners(this); final IDebugSettings debugSettings = Application.get().getDebugSettings(); if (debugSettings.isLinePreciseReportingOnNewComponentEnabled()) { setMetaData(CONSTRUCTED_AT_KEY, Strings.toString(this, new MarkupException( "constructed"))); } } /** * Constructor. All components have names. A component's id cannot be null. This constructor * includes a model. * * @param id * The non-null id of this component * @param model * The component's model * * @throws WicketRuntimeException * Thrown if the component has been given a null id. */ public Component(final String id, final IModel model) { this(id); setModelImpl(wrap(model)); } /** * Adds an behavior modifier to the component. * * <p> * Note: this method is override to enable users to do things like discussed in <a * href="http://www.nabble.com/Why-add%28IBehavior%29-is-final--tf2598263.html#a7248198">this * thread</a>. * </p> * * @param behavior * The behavior modifier to be added * @return this (to allow method call chaining) */ public Component add(final IBehavior behavior) { if (behavior == null) { throw new IllegalArgumentException("Argument may not be null"); } addBehavior(behavior);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -