KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > Usage


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 package org.netbeans.modules.xml.refactoring;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.modules.xml.refactoring.impl.RefactoringUtil;
25 import org.netbeans.modules.xml.xam.Component;
26 import org.netbeans.modules.xml.xam.Reference;
27
28
29 public class Usage {
30     private Component component;
31     private Type type;
32     private UsageGroup container;
33     private boolean includedInRefactoring;
34     private String JavaDoc refactoringDescription;
35     
36     public Usage(Component component, UsageGroup container) {
37         this(component, Type.REFERENCE, container);
38     }
39     
40     public Usage(Component component, Type type, UsageGroup container) {
41         this.component = component;
42         this.type = type;
43         this.container = container;
44         includedInRefactoring = true;
45     }
46     
47     public enum Type {
48         REFERENCE, GENERALIZATION;
49         public String JavaDoc toString() {
50             return RefactoringUtil.getDescription(this);
51         }
52     }
53
54     /**
55      * Returns component having the usage.
56      */

57     public Component getComponent() {
58         return component;
59     }
60     
61     /**
62      * Returns type of the usage.
63      */

64     public Type getType() {
65         return type;
66     }
67     
68     public void setType(Type type) {
69         this.type = type;
70     }
71     
72     /**
73      * Return the containing group of this usage.
74      */

75     public UsageGroup getContainer() {
76         return container;
77     }
78     
79     /**
80      * Returns path from root to the usage host component.
81      */

82     public List JavaDoc<Component> getPathFromRoot() {
83         return getContainer().getEngine().getUIHelper().getRelevantPathFromRoot(this.getComponent());
84     }
85     
86     /**
87      * Whether this usage item should be included in refactoring.
88      */

89     public boolean isIncludedInRefactoring() {
90         return includedInRefactoring;
91     }
92     public void setIncludedInRefactoring(boolean included) {
93         includedInRefactoring = included;
94     }
95     
96     /**
97      * Returns short description of the change would be done on this usage item
98      * if the refactoring is applied. Return null if this usage item has not been
99      * associated with any refactoring request with a call to
100      * RefactoringManager.precheck().
101      */

102     public String JavaDoc getRefactoringDescription() {
103         return refactoringDescription;
104     }
105     public void setRefactoringDescription(String JavaDoc desc) {
106         this.refactoringDescription = desc;
107     }
108 }
Popular Tags