KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdr > storagemodel > AttrImmutUList


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.mdr.storagemodel;
20
21 import java.util.*;
22 import javax.jmi.reflect.*;
23
24 import org.netbeans.mdr.persistence.StorageException;
25
26 /**
27  *
28  * @author Martin Matula
29  */

30 public class AttrImmutUList extends AttrImmutList {
31
32     public AttrImmutUList() {
33     }
34
35     AttrImmutUList(StorableFeatured mdrObject, StorableClass.AttributeDescriptor desc) throws StorageException {
36         this(mdrObject, desc, null);
37     }
38
39     AttrImmutUList(StorableFeatured mdrObject, StorableClass.AttributeDescriptor desc, Collection values) throws StorageException {
40         Class JavaDoc type = desc.getType();
41         if (values == null) {
42             data = new Object JavaDoc[0];
43         } else {
44             data = values.toArray();
45             Set helperSet = new HashSet(data.length, 1);
46             for (int i = 0; i < data.length; i++) {
47                 if (data[i] == null) {
48                     throw new NullPointerException JavaDoc();
49                 }
50                 if (!type.isInstance(data[i])) {
51                     throw new TypeMismatchException(type, data[i], getMetaElement(mdrObject.getMdrStorage(), desc.getMofId()));
52                 }
53                 if (!helperSet.add(data[i])) {
54                     throw new DuplicateException(data[i], getMetaElement(mdrObject.getMdrStorage(), desc.getMofId()));
55                 }
56             }
57         }
58
59         if ((data.length < desc.getMinSize()) || ((desc.getMaxSize() > -1) && (data.length > desc.getMaxSize()))) {
60             throw new WrongSizeException(getMetaElement(mdrObject.getMdrStorage(), desc.getMofId()));
61         }
62
63         if (type.isInstance(RefObject.class)) {
64             setAttribComposite(mdrObject.getMofId(), values, desc.getMofId());
65         }
66     }
67 }
68
Popular Tags