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.
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
6 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7 * Other names may be trademarks of their respective owners.
9 * The contents of this file are subject to the terms of either the GNU
10 * General Public License Version 2 only ("GPL") or the Common
11 * Development and Distribution License("CDDL") (collectively, the
12 * "License"). You may not use this file except in compliance with the
13 * License. You can obtain a copy of the License at
14 * http://www.netbeans.org/cddl-gplv2.html
15 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16 * specific language governing permissions and limitations under the
17 * License. When distributing the software, include this License Header
18 * Notice in each file and include the License file at
19 * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20 * particular file as subject to the "Classpath" exception as provided
21 * by Oracle in the GPL Version 2 section of the License file that
22 * accompanied this code. If applicable, add the following below the
23 * License Header, with the fields enclosed by brackets [] replaced by
24 * your own identifying information:
25 * "Portions Copyrighted [year] [name of copyright owner]"
29 * The Original Software is NetBeans. The Initial Developer of the Original
30 * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
32 * If you wish your version of this file to be governed by only the CDDL
33 * or only the GPL Version 2, indicate your decision by adding
34 * "[Contributor] elects to include this software in this distribution
35 * under the [CDDL or GPL Version 2] license." If you do not indicate a
36 * single choice of license, a recipient has the option to distribute
37 * your version of this file under either the CDDL, the GPL Version 2 or
38 * to extend the choice of license to its licensees as provided above.
39 * However, if you add GPL Version 2 code and therefore, elected the GPL
40 * Version 2 license, then the option applies only if the new code is
41 * made subject to such option by the copyright holder.
43 package org.netbeans.html.json.impl;
45 import java.lang.reflect.Array;
46 import java.util.ArrayList;
47 import java.util.Collection;
48 import java.util.Iterator;
49 import org.netbeans.html.json.spi.Proto;
53 * @author Jaroslav Tulach
55 public final class JSONList<T> extends ArrayList<T> {
56 private final Proto proto;
57 private final String name;
58 private final String[] deps;
59 private final int index;
61 public JSONList(Proto proto, String name, int changeIndex, String... deps) {
65 this.index = changeIndex;
68 public void init(Object values) {
70 if (values == null || (len = Array.getLength(values)) == 0) {
73 for (int i = 0; i < len; i++) {
74 Object data = Array.get(values, i);
78 public static <T> void init(Collection<T> to, Object values) {
80 if (values == null || (len = Array.getLength(values)) == 0) {
83 for (int i = 0; i < len; i++) {
84 Object data = Array.get(values, i);
90 public boolean add(T e) {
91 boolean ret = super.add(e);
97 public boolean addAll(Collection<? extends T> c) {
98 boolean ret = super.addAll(c);
104 public boolean addAll(int index, Collection<? extends T> c) {
105 boolean ret = super.addAll(index, c);
111 public boolean remove(Object o) {
112 boolean ret = super.remove(o);
118 public void clear() {
124 public boolean removeAll(Collection<?> c) {
125 boolean ret = super.removeAll(c);
131 public boolean retainAll(Collection<?> c) {
132 boolean ret = super.retainAll(c);
138 public T set(int index, T element) {
139 T ret = super.set(index, element);
145 public void add(int index, T element) {
146 super.add(index, element);
151 public T remove(int index) {
152 T ret = super.remove(index);
158 public String toString() {
159 Iterator<T> it = iterator();
164 StringBuilder sb = new StringBuilder();
166 while (it.hasNext()) {
169 sb.append(JSON.toJSON(t));
173 return sb.toString();
176 private void notifyChange() {
177 proto.getContext().execute(new Runnable() {
180 Bindings m = PropertyBindingAccessor.getBindings(proto, false);
182 m.valueHasMutated(name, null, null);
183 for (String dependant : deps) {
184 m.valueHasMutated(dependant, null, null);
187 PropertyBindingAccessor.notifyProtoChange(proto, index);
195 public JSONList clone() {
196 throw new UnsupportedOperationException();
199 static final Object koData(Collection<?> c, Bindings m) {
200 Object[] arr = c.toArray(new Object[c.size()]);
201 for (int i = 0; i < arr.length; i++) {
202 Object r = JSON.find(arr[i], m);
207 return m.wrapArray(arr);
210 final Object koData() {
211 return koData(this, PropertyBindingAccessor.getBindings(proto, true));