📄 framedresource.java
字号:
* @param cls The class of frames we are looking for. * @param identifier the frame identifier * @return a ResourceFrame instance of <strong>null</strong> */ ResourceFrame unsafeGetFrame(Class c, String identifier) { ResourceFrame frames[] = collectFrames(c); if (frames != null) { for (int i = 0 ; i < frames.length ; i++) { ResourceFrame fr = frames[i]; if (fr.getIdentifier().equals(identifier)) return fr; } } return null; } /** * Get the frame of the given class. * @param classname the class name * @return a ResourceFrame instance of null. */ public synchronized ResourceFrame getFrame(String classname) { try { Class c = Class.forName(classname); return getFrame(c); } catch (Exception ex) { return null; } } /** * (AWT Like), dspatch the Event to all our listeners. * @param evt The resourceEvent to dispatch. */ public void processEvent(ResourceEvent evt) { if (evt instanceof StructureChangedEvent) { fireStructureChangedEvent((StructureChangedEvent)evt); } else if (evt instanceof AttributeChangedEvent) { fireAttributeChangeEvent((AttributeChangedEvent)evt); } } /** * Post an Event in the Event Queue. * @param evt The Event to post. */ public void postEvent(ResourceEvent evt) { if (eventDisabled()) return; ResourceSpace space = getSpace(); if (space != null) space.getEventQueue().sendEvent(evt); } /** * Add an attribute change listener. * @param l The new attribute change listener. */ public void addAttributeChangedListener(AttributeChangedListener l) { attrListener = ResourceEventMulticaster.add(attrListener, l); } /** * Remove an attribute change listener. * @param l The listener to remove. */ public void removeAttributeChangedListener(AttributeChangedListener l) { attrListener = ResourceEventMulticaster.remove(attrListener, l); } /** * post an attribute change event. Actually this kind of event should * not be posted. So fire them! * @param idx The index of the attribute that has changed. * @param newvalue The new value for that attribute. */ protected void postAttributeChangeEvent(int idx, Object newvalue) { if (eventDisabled()) return; if (( attrListener != null ) && (getResourceReference() != null)) { AttributeChangedEvent evt = new AttributeChangedEvent(getResourceReference(), attributes[idx], newvalue); fireAttributeChangeEvent(evt); } } /** * Fire an attribute change event. * @param evt the AttributeChangedEvent to fire. */ protected void fireAttributeChangeEvent(AttributeChangedEvent evt) { if ( attrListener != null ) attrListener.attributeChanged(evt); } /** * Add a structure change listener. * @param l The new structure change listener. */ public void addStructureChangedListener(StructureChangedListener l) { structListener = ResourceEventMulticaster.add(structListener, l); } /** * Remove a structure change listener. * @param l The listener to remove. */ public void removeStructureChangedListener(StructureChangedListener l) { structListener = ResourceEventMulticaster.remove(structListener, l); } /** * post an structure change event. * @param rr the ResourceReference of the source. * @param type The type of the event. */ protected void postStructureChangedEvent(ResourceReference rr, int type) { if ((structListener != null) && (rr != null)) { StructureChangedEvent evt = new StructureChangedEvent(rr, type); postEvent(evt); } } /** * post an structure change event. * @param type The type of the event. */ protected void postStructureChangedEvent(int type) { if ((structListener != null) && (getResourceReference() != null)) { StructureChangedEvent evt = new StructureChangedEvent(getResourceReference(), type); postEvent(evt); } } /** * Fire an structure change event. * @param type The type of the event. */ protected void fireStructureChangedEvent(int type) { if ((structListener != null) && (getResourceReference() != null)) { StructureChangedEvent evt = new StructureChangedEvent(getResourceReference(), type); fireStructureChangedEvent(evt); } } /** * Fire an structure change event. * @param evt the StructureChangedEvent to fire. */ protected void fireStructureChangedEvent(StructureChangedEvent evt) { if (structListener != null) { int type = evt.getID(); switch (type) { case Events.RESOURCE_MODIFIED : structListener.resourceModified(evt); break; case Events.RESOURCE_CREATED : structListener.resourceCreated(evt); break; case Events.RESOURCE_REMOVED : structListener.resourceRemoved(evt); break; case Events.RESOURCE_UNLOADED : structListener.resourceUnloaded(evt); break; } } } /** * This resource is being unloaded. * The resource is being unloaded from memory, perform any additional * cleanup required. */ public void notifyUnload() { // // direct notification // ResourceFrame frames[] = getFrames(); if ( frames != null ) { for (int i = 0 ; i < frames.length ; i++) { if ( frames[i] == null ) continue; frames[i].notifyUnload(); } } fireStructureChangedEvent(Events.RESOURCE_UNLOADED); super.notifyUnload(); } /** * Delete this Resource instance, and remove it from its store. * This method will erase definitely this resource, for ever, by removing * it from its resource store (when doable). * @exception MultipleLockException if someone has locked this resource. */ public synchronized void delete() throws MultipleLockException { disableEvent(); // fire and not post because we don't want this resource // to be locked() during the delete. fireStructureChangedEvent(Events.RESOURCE_REMOVED); ResourceFrame frames[] = getFrames(); if ( frames != null ) { for (int i = 0 ; i < frames.length ; i++) { if ( frames[i] == null ) continue; frames[i].removeFrameEventListener(this); this.removeAttributeChangedListener(frames[i]); frames[i].unregisterResource(this); } } try { super.delete(); } catch (MultipleLockException ex) { enableEvent(); throw ex; } } /** * Mark this resource as having been modified. */ public void markModified() { super.markModified(); postStructureChangedEvent(Events.RESOURCE_MODIFIED); } /** * Set some of this resource attribute. We overide setValue to post * events. */ public synchronized void setValue(int idx, Object value) { super.setValue(idx, value) ; if (idx != ATTR_LAST_MODIFIED) { postAttributeChangeEvent(idx, value); postStructureChangedEvent(Events.RESOURCE_MODIFIED); } } /** * Set a value, without posting event. * @param idx The attribute index, in the list of attributes advertized by * the resource. * @param value The new value for this attribute. */ public synchronized void setSilentValue(int idx, Object value) { disableEvent(); super.setValue(idx, value); enableEvent(); } /** * Set a value, without posting event. * @param name The attribute name. * @param value The new value for the attribute. */ public synchronized void setSilentValue(String name, Object value) { disableEvent(); super.setValue(name, value); enableEvent(); } /** * Lookup the target resource. * @param ls The current lookup state * @param lr The result * @return true if lookup is done. * @exception ProtocolException If an error relative to the protocol occurs */ public boolean lookup(LookupState ls, LookupResult lr) throws ProtocolException { ResourceFrame frames[] = getFrames(); if (frames != null) { for (int i = 0 ; i < frames.length ; i++) { if (frames[i] == null) continue; if (frames[i].lookup(ls,lr)) return true; } } if ( ls.hasMoreComponents() ) { // We are not a container resource, and we don't have children: lr.setTarget(null); return false; } else { //we are done! lr.setTarget(getResourceReference()); return true; } } /** * Perform the request on all the frames of that resource. The * Reply returned is the first non-null reply. * @param request A RequestInterface instance. * @return A ReplyInterface instance. * @exception ProtocolException If an error relative to the protocol occurs * @exception ResourceException If an error not relative to the * protocol occurs */ protected ReplyInterface performFrames(RequestInterface request) throws ProtocolException, ResourceException { ResourceFrame frames[] = getFrames(); if (frames != null) { for (int i = 0 ; i < frames.length ; i++) { if (frames[i] == null) continue; ReplyInterface reply = frames[i].perform(request); if (reply != null) return reply; } } return null; } /** * Perform the request. * @return a ReplyInterface instance * @exception ProtocolException If an error relative to the protocol occurs * @exception ResourceException If an error not relative to the * protocol occurs */ public ReplyInterface perform(RequestInterface request) throws ProtocolException, ResourceException { return performFrames(request); } /** * Initialize the frames of that framed resource. * @param values Default attribute values. */ public void initialize(Object values[]) { this.attrListener = null; this.structListener = null; disableEvent(); super.initialize(values); // Initialize the frames if any. ResourceFrame frames[] = getFrames(); if ( frames != null ) { this.framesRef = new Hashtable(Math.max(frames.length, 1)); Hashtable defs = new Hashtable(3); for (int i = 0 ; i < frames.length ; i++) { if ( frames[i] == null ) continue; frames[i].registerResource(this); frames[i].initialize(defs); frames[i].addFrameEventListener(this); this.addAttributeChangedListener(frames[i]); } } else { this.framesRef = new Hashtable(3); } enableEvent(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -