All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.page.Page Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

// @(#) $Id: Page.java 3240 2009-03-03 16:10:56Z gub $
package at.spardat.xma.page;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import at.spardat.enterprise.exc.SysException;
import at.spardat.xma.mdl.IWModelClient;
import at.spardat.xma.mdl.NewModelEvent;
import at.spardat.xma.mdl.NewModelEventFactory;
import at.spardat.xma.mdl.NewModelEventParams;
import at.spardat.xma.mdl.Synchronization;
import at.spardat.xma.mdl.Transactional;
import at.spardat.xma.mdl.WModel;
import at.spardat.xma.mdl.util.DNode;
import at.spardat.xma.mdl.util.Descriptive;
import at.spardat.xma.serializer.XmaInput;
import at.spardat.xma.serializer.XmaOutput;
import at.spardat.xma.session.XMASession;


/**
 * Base class for server and client side PageModels. A Page is a set of
 * WidgetModels.
 */
public abstract class Page implements Transactional, Synchronization, Descriptive {

    /**
     * Constructs a Page.
     *
     * @param stateless indicates if this is a server stateless Page.
     * @param atServer indicates if the created instance is living at the server side.
     */
    public Page (boolean stateless, boolean atServer) {
        isStateless_ = stateless;
        isAtServer_ = atServer;
    }


    /**
     * Indicates whether this Page is stateless. This property specifies
     * that the state of the page is dropped at the server side after a
     * server side event.
     *
     * @return true if stateless
     */
    public boolean isStateless() {
        return isStateless_;
    }

    /**
     * Yields true if any of this PageModels WidgetModels has changed since the
     * last server side event (or since creation if isNew).
     *
     * @return true if changed.
     */
    public boolean changed() {
        if(newModelEvents_!=null&&newModelEvents_.size()>0) return true;
        WModel[]        wModels = getWModels();
        for (int i=wModels.length-1; i>=0; i--) if (wModels[i].changed()) return true;
        return false;
    }

    /**
     * Restores all WidgetModels of this PageModels to the state immediately
     * after the last server side event (or at creation time if isNew()).
     */
    public void rollback() {
        WModel[]        wModels = getWModels();
        for (int i=wModels.length-1; i>=0; i--) wModels[i].rollback();
    }

    /**
     * This method discards the change history in every WidgetModel.
     */
    public void commit() {
        WModel[]        wModels = getWModels();
        for (int i=wModels.length-1; i>=0; i--) wModels[i].commit();
        newModelEvents_=null;
    }

    /**
     * This method writes either all widget models if forceFull or just the changed ones.
     *
     * @see at.spardat.xma.mdl.Synchronization#externalize(at.spardat.xma.serializer.XmaOutput, boolean)
     */
    public void externalize (XmaOutput xo, boolean forceFull) throws IOException {
        List newModelList;
        if(forceFull) newModelList=handledNewModelEvents_;
        else newModelList=newModelEvents_;
        // write model creations
        if(newModelList==null) {
            xo.writeShort("numNewModels",0);
        } else {
            xo.writeShort("numNewModels",newModelList.size());
            for(Iterator it=newModelList.iterator();it.hasNext();) {
                NewModelEvent event = (NewModelEvent) it.next();
                xo.writeByte("type",event.getType());
                event.serialize(xo);
            }
        }
        // write models
        WModel[]            wModels = getWModels();
        int                 numToWrite = wModels.length;  // number of models if forceFull
        if (!forceFull) {
            numToWrite = 0;
            for (int i=0; i0) {
            XMASession session = getSession();
            NewModelEventFactory eventFactory; // session is only null in unit tests
            if(session!=null) { eventFactory = getSession().getNewModelEventFactory(); }
            else { eventFactory = new NewModelEventFactory(); }
            for(int i=0;iidModel less then zero or
     *             greater than getNumWModels()-1.
     */
    public  WModel getWModel (short idWModel) {
        return getWModels()[idWModel];
    }

    /**
     * Returns an array of all WidgetModels of this page.
     * @return array of WidgetModels. The returned array is not a copy, therefore
     *          it must not be modified.
     */
    public abstract WModel[] getWModels();

    /**
     * Modifies the widget model array generated by guidesigner.
     * May only be called by the runtime. Do not call this method!
     * @since 2.1.0
     */
    protected void setWModels(WModel[] wModels) {
        throw new SysException("not supported");
    }

    /**
     * Appends a new widget model to WModel.
     * @since 2.1.0
     */
    private void appendWModel(WModel widgetModel) {
        WModel[] oldWModels = getWModels();
        if(widgetModel.getId()!=oldWModels.length) {
            throw new IllegalArgumentException("new widget model has invalid ID: "+widgetModel.getId());
        }
        WModel[] newWModels = new WModel[oldWModels.length+1];
        for(int i=0;in random changes to each widget model of this page
     */
    public void randomlyChange (int n) {
       WModel [] wModels = getWModels();
        for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy