json/src/main/java/org/netbeans/html/json/impl/PropertyBindingAccessor.java
author Jaroslav Tulach <jtulach@netbeans.org>
Tue, 26 Aug 2014 18:13:30 +0200
changeset 838 bdc3d696dd4a
parent 790 30f20d9c0986
child 940 bdec4103bdb2
permissions -rw-r--r--
During the API review process (bug 246133) the reviewers decided that in order to include html4j to NetBeans Platform, we need to stop using org.apidesign namespace and switch to NetBeans one. Repackaging all SPI packages into org.netbeans.html.smthng.spi.
jaroslav@9
     1
/**
jaroslav@358
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
jaroslav@9
     3
 *
jaroslav@551
     4
 * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
jaroslav@9
     5
 *
jaroslav@358
     6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
jaroslav@358
     7
 * Other names may be trademarks of their respective owners.
jaroslav@9
     8
 *
jaroslav@358
     9
 * The contents of this file are subject to the terms of either the GNU
jaroslav@358
    10
 * General Public License Version 2 only ("GPL") or the Common
jaroslav@358
    11
 * Development and Distribution License("CDDL") (collectively, the
jaroslav@358
    12
 * "License"). You may not use this file except in compliance with the
jaroslav@358
    13
 * License. You can obtain a copy of the License at
jaroslav@358
    14
 * http://www.netbeans.org/cddl-gplv2.html
jaroslav@358
    15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
jaroslav@358
    16
 * specific language governing permissions and limitations under the
jaroslav@358
    17
 * License.  When distributing the software, include this License Header
jaroslav@358
    18
 * Notice in each file and include the License file at
jaroslav@358
    19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
jaroslav@358
    20
 * particular file as subject to the "Classpath" exception as provided
jaroslav@358
    21
 * by Oracle in the GPL Version 2 section of the License file that
jaroslav@358
    22
 * accompanied this code. If applicable, add the following below the
jaroslav@358
    23
 * License Header, with the fields enclosed by brackets [] replaced by
jaroslav@358
    24
 * your own identifying information:
jaroslav@358
    25
 * "Portions Copyrighted [year] [name of copyright owner]"
jaroslav@358
    26
 *
jaroslav@358
    27
 * Contributor(s):
jaroslav@358
    28
 *
jaroslav@358
    29
 * The Original Software is NetBeans. The Initial Developer of the Original
jaroslav@551
    30
 * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
jaroslav@358
    31
 *
jaroslav@358
    32
 * If you wish your version of this file to be governed by only the CDDL
jaroslav@358
    33
 * or only the GPL Version 2, indicate your decision by adding
jaroslav@358
    34
 * "[Contributor] elects to include this software in this distribution
jaroslav@358
    35
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
jaroslav@358
    36
 * single choice of license, a recipient has the option to distribute
jaroslav@358
    37
 * your version of this file under either the CDDL, the GPL Version 2 or
jaroslav@358
    38
 * to extend the choice of license to its licensees as provided above.
jaroslav@358
    39
 * However, if you add GPL Version 2 code and therefore, elected the GPL
jaroslav@358
    40
 * Version 2 license, then the option applies only if the new code is
jaroslav@358
    41
 * made subject to such option by the copyright holder.
jaroslav@9
    42
 */
jaroslav@362
    43
package org.netbeans.html.json.impl;
jaroslav@9
    44
jaroslav@262
    45
import net.java.html.BrwsrCtx;
jtulach@838
    46
import org.netbeans.html.json.spi.FunctionBinding;
jtulach@838
    47
import org.netbeans.html.json.spi.JSONCall;
jtulach@838
    48
import org.netbeans.html.json.spi.PropertyBinding;
jtulach@838
    49
import org.netbeans.html.json.spi.Proto;
jaroslav@9
    50
jaroslav@9
    51
/**
jaroslav@9
    52
 *
jtulach@790
    53
 * @author Jaroslav Tulach
jaroslav@9
    54
 */
jaroslav@9
    55
public abstract class PropertyBindingAccessor {
jaroslav@9
    56
    private static PropertyBindingAccessor DEFAULT;
jaroslav@9
    57
jaroslav@9
    58
    protected PropertyBindingAccessor() {
jaroslav@9
    59
        if (DEFAULT != null) throw new IllegalStateException();
jaroslav@9
    60
        DEFAULT = this;
jaroslav@9
    61
    }
jaroslav@9
    62
    
jaroslav@9
    63
    static {
jaroslav@30
    64
        JSON.initClass(PropertyBinding.class);
jaroslav@9
    65
    }
jaroslav@9
    66
jaroslav@415
    67
    protected abstract <M> PropertyBinding newBinding(
jaroslav@415
    68
        Proto.Type<M> access, Bindings<?> bindings, String name, int index, M model, boolean readOnly
jaroslav@415
    69
    );
jaroslav@24
    70
    protected abstract JSONCall newCall(
jaroslav@262
    71
        BrwsrCtx ctx, RcvrJSON callback, String urlBefore, String urlAfter,
jaroslav@262
    72
        String method, Object data
jaroslav@262
    73
    );
jaroslav@404
    74
    
jaroslav@404
    75
    protected abstract Bindings bindings(Proto proto, boolean initialize);
jaroslav@406
    76
    protected abstract void notifyChange(Proto proto, int propIndex);
jaroslav@412
    77
    protected abstract Proto findProto(Proto.Type<?> type, Object object);
jaroslav@412
    78
    protected abstract <Model> Model cloneTo(Proto.Type<Model> type, Model model, BrwsrCtx c);
jaroslav@412
    79
    protected abstract Object read(Proto.Type<?> from, BrwsrCtx c, Object data);
jaroslav@404
    80
    
jaroslav@404
    81
    static Bindings getBindings(Proto proto, boolean initialize) {
jaroslav@404
    82
        return DEFAULT.bindings(proto, initialize);
jaroslav@404
    83
    }
jaroslav@9
    84
    
jaroslav@406
    85
    static void notifyProtoChange(Proto proto, int propIndex) {
jaroslav@406
    86
        DEFAULT.notifyChange(proto, propIndex);
jaroslav@406
    87
    }
jaroslav@406
    88
    
jaroslav@415
    89
    static <M> PropertyBinding create(
jaroslav@415
    90
        Proto.Type<M> access, Bindings<?> bindings, String name, int index, M model , boolean readOnly
jaroslav@415
    91
    ) {
jaroslav@415
    92
        return DEFAULT.newBinding(access, bindings, name, index, model, readOnly);
jaroslav@9
    93
    }
jaroslav@24
    94
    static JSONCall createCall(
jaroslav@262
    95
        BrwsrCtx ctx, RcvrJSON callback, String urlBefore, String urlAfter, 
jaroslav@262
    96
        String method, Object data
jaroslav@262
    97
    ) {
jaroslav@262
    98
        return DEFAULT.newCall(ctx, callback, urlBefore, urlAfter, method, data);
jaroslav@24
    99
    }
jaroslav@412
   100
    static Proto protoFor(Proto.Type<?> type, Object object) {
jaroslav@412
   101
        return DEFAULT.findProto(type, object);
jaroslav@412
   102
    }
jaroslav@412
   103
    static <Model> Model clone(Proto.Type<Model> type, Model model, BrwsrCtx c) {
jaroslav@412
   104
        return DEFAULT.cloneTo(type, model, c);
jaroslav@412
   105
    }
jaroslav@412
   106
    static Object readFrom(Proto.Type<?> from, BrwsrCtx c, Object data) {
jaroslav@412
   107
        return DEFAULT.read(from, c, data);
jaroslav@412
   108
    }
jaroslav@9
   109
}