001/*
002 * (C) Copyright 2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id: ProtectedEditableModelImpl.java 21685 2007-06-30 21:02:58Z sfermigier $
020 */
021
022package org.nuxeo.ecm.platform.ui.web.model.impl;
023
024import javax.el.ValueExpression;
025
026import org.apache.commons.logging.Log;
027import org.apache.commons.logging.LogFactory;
028import org.nuxeo.ecm.platform.ui.web.model.EditableModel;
029import org.nuxeo.ecm.platform.ui.web.model.ProtectedEditableModel;
030
031/**
032 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
033 */
034public class ProtectedEditableModelImpl implements ProtectedEditableModel {
035
036    private static final Log log = LogFactory.getLog(ProtectedEditableModelImpl.class);
037
038    protected final String componentId;
039
040    protected final EditableModel delegate;
041
042    protected final ProtectedEditableModel parent;
043
044    protected final ValueExpression binding;
045
046    public ProtectedEditableModelImpl(String compId, EditableModel delegate, ProtectedEditableModel parent,
047            ValueExpression binding) {
048        this.componentId = compId;
049        this.delegate = delegate;
050        this.parent = parent;
051        this.binding = binding;
052    }
053
054    @Override
055    public String getComponentId() {
056        return componentId;
057    }
058
059    @Override
060    public int getRowCount() {
061        return delegate.getRowCount();
062    }
063
064    @Override
065    public Object getRowData() {
066        Object data = delegate.getRowData();
067        if (log.isDebugEnabled()) {
068            log.debug("getRowData " + getComponentId() + " -> " + data);
069        }
070        return data;
071    }
072
073    @Override
074    public int getRowIndex() {
075        return delegate.getRowIndex();
076    }
077
078    @Override
079    public void setRowData(Object rowData) {
080        delegate.setRowData(rowData);
081    }
082
083    @Override
084    public boolean isRowNew() {
085        return delegate.isRowNew();
086    }
087
088    @Override
089    public ValueExpression getBinding() {
090        return binding;
091    }
092
093    @Override
094    public ProtectedEditableModel getParent() {
095        return parent;
096    }
097
098    @Override
099    public String toString() {
100        final StringBuilder buf = new StringBuilder();
101        buf.append(ProtectedEditableModelImpl.class.getSimpleName());
102        buf.append(" {");
103        buf.append(" component id=");
104        buf.append(componentId);
105        buf.append(", binding=");
106        buf.append(binding);
107        buf.append(", delegate=");
108        buf.append(delegate);
109        buf.append(", parent=");
110        buf.append(parent);
111        buf.append('}');
112        return buf.toString();
113    }
114
115}