001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.web.jsf.impl.facesmodel;
043:
044: import org.netbeans.modules.web.jsf.api.facesmodel.*;
045: import org.netbeans.modules.xml.xam.ComponentUpdater;
046: import org.netbeans.modules.xml.xam.ComponentUpdater.Operation;
047:
048: /**
049: *
050: * @author Petr Pisl
051: */
052: public class SyncUpdateVisitor extends JSFConfigVisitor.Default
053: implements ComponentUpdater<JSFConfigComponent> {
054:
055: private JSFConfigComponent target;
056: private Operation operation;
057: private int index;
058:
059: /** Creates a new instance of SyncUpdateVisitor */
060: public SyncUpdateVisitor() {
061: }
062:
063: public void update(JSFConfigComponent target,
064: JSFConfigComponent child, Operation operation) {
065: update(target, child, -1, operation);
066: }
067:
068: public void update(JSFConfigComponent target,
069: JSFConfigComponent child, int index, Operation operation) {
070: assert target != null;
071: assert child != null;
072: this .target = target;
073: this .index = index;
074: this .operation = operation;
075: child.accept(this );
076: }
077:
078: private void insert(String propertyName,
079: JSFConfigComponent component) {
080: ((JSFConfigComponentImpl) target).insertAtIndex(propertyName,
081: component, index);
082: }
083:
084: private void remove(String propertyName,
085: JSFConfigComponent component) {
086: ((JSFConfigComponentImpl) target).removeChild(propertyName,
087: component);
088: }
089:
090: @Override
091: public void visit(ManagedBean component) {
092: if (target instanceof FacesConfig) {
093: if (operation == Operation.ADD) {
094: insert(FacesConfig.MANAGED_BEAN, component);
095: } else {
096: remove(FacesConfig.MANAGED_BEAN, component);
097: }
098: }
099: }
100:
101: @Override
102: public void visit(NavigationRule component) {
103: if (target instanceof FacesConfig) {
104: if (operation == Operation.ADD) {
105: insert(FacesConfig.NAVIGATION_RULE, component);
106: } else {
107: remove(FacesConfig.NAVIGATION_RULE, component);
108: }
109: }
110: }
111:
112: @Override
113: public void visit(NavigationCase component) {
114: if (target instanceof NavigationRule) {
115: if (operation == Operation.ADD) {
116: insert(NavigationRule.NAVIGATION_CASE, component);
117: } else {
118: remove(NavigationRule.NAVIGATION_CASE, component);
119: }
120: }
121: }
122:
123: @Override
124: public void visit(Converter component) {
125: if (target instanceof FacesConfig) {
126: if (operation == Operation.ADD) {
127: insert(FacesConfig.CONVERTER, component);
128: } else {
129: remove(FacesConfig.CONVERTER, component);
130: }
131: }
132: }
133:
134: @Override
135: public void visit(Application component) {
136: if (target instanceof FacesConfig) {
137: if (operation == Operation.ADD) {
138: insert(FacesConfig.APPLICATION, component);
139: } else {
140: remove(FacesConfig.APPLICATION, component);
141: }
142: }
143: }
144:
145: @Override
146: public void visit(ViewHandler component) {
147: if (target instanceof Application) {
148: if (operation == Operation.ADD) {
149: insert(Application.VIEW_HANDLER, component);
150: } else {
151: remove(Application.VIEW_HANDLER, component);
152: }
153: }
154: }
155:
156: @Override
157: public void visit(LocaleConfig component) {
158: if (target instanceof Application) {
159: if (operation == Operation.ADD) {
160: insert(Application.LOCALE_CONFIG, component);
161: } else {
162: remove(Application.LOCALE_CONFIG, component);
163: }
164: }
165: }
166:
167: @Override
168: public void visit(DefaultLocale component) {
169: if (target instanceof LocaleConfig) {
170: if (operation == Operation.ADD) {
171: insert(LocaleConfig.DEFAULT_LOCALE, component);
172: } else {
173: remove(LocaleConfig.DEFAULT_LOCALE, component);
174: }
175: }
176: }
177:
178: @Override
179: public void visit(SupportedLocale component) {
180: if (target instanceof LocaleConfig) {
181: if (operation == Operation.ADD) {
182: insert(LocaleConfig.SUPPORTED_LOCALE, component);
183: } else {
184: remove(LocaleConfig.SUPPORTED_LOCALE, component);
185: }
186: }
187: }
188:
189: @Override
190: public void visit(ResourceBundle component) {
191: if (target instanceof Application) {
192: if (operation == Operation.ADD) {
193: insert(Application.RESOURCE_BUNDLE, component);
194: } else {
195: remove(Application.RESOURCE_BUNDLE, component);
196: }
197: }
198: }
199: }
|