KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > nodes > NewTypesFactory


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * NewTypesFactory.java
22  *
23  * Created on May 2, 2006, 5:08 PM
24  *
25  */

26
27 package org.netbeans.modules.xml.schema.ui.nodes;
28
29 import java.util.ArrayList JavaDoc;
30 import org.netbeans.modules.xml.schema.model.Annotation;
31 import org.netbeans.modules.xml.schema.model.SchemaComponent;
32 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
33 import org.netbeans.modules.xml.schema.model.visitor.DeepSchemaVisitor;
34 import org.netbeans.modules.xml.schema.ui.nodes.categorized.newtype.AdvancedSchemaComponentNewType;
35 import org.openide.util.datatransfer.NewType;
36
37 /**
38  *
39  * @author Ajit Bhate
40  */

41 public class NewTypesFactory extends DeepSchemaVisitor
42 {
43     private ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>> childTypes;
44     /**
45      * Creates a new instance of NewTypesFactory
46      */

47     public NewTypesFactory()
48     {
49         childTypes = new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>();
50     }
51     
52     public NewType[] getNewTypes(
53             SchemaComponentReference<? extends SchemaComponent> reference,
54             Class JavaDoc<? extends SchemaComponent> filterClass)
55     {
56         childTypes.clear();
57         reference.get().accept(this);
58         ArrayList JavaDoc<NewType> result = new ArrayList JavaDoc<NewType>();
59         for(Class JavaDoc<? extends SchemaComponent>childType:childTypes)
60         {
61             if(filterClass==null|| filterClass.isAssignableFrom(childType))
62             {
63                 AdvancedSchemaComponentNewType newType =
64                         new AdvancedSchemaComponentNewType(reference,childType);
65                 if (newType.canCreate())
66                 {
67                     result.add(newType);
68                 }
69             }
70         }
71         childTypes.clear();
72         return result.toArray(new NewType[result.size()]);
73     }
74     
75     protected void visitChildren(SchemaComponent sc)
76     {
77         addChildType(Annotation.class);
78     }
79
80     protected void addChildType(Class JavaDoc<? extends SchemaComponent> childType)
81     {
82         childTypes.add(childType);
83     }
84     
85 }
86
Popular Tags