blob: 7376d4ee46e2e5b723dc21440663cbb5b8bd9827 [file] [log] [blame]
david_williams96213482004-11-11 09:07:12 +00001/*******************************************************************************
amywuecebb042007-04-10 20:07:35 +00002 * Copyright (c) 2001, 2005 IBM Corporation and others.
david_williams96213482004-11-11 09:07:12 +00003 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
amywuecebb042007-04-10 20:07:35 +00007 *
david_williams96213482004-11-11 09:07:12 +00008 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Jens Lukowski/Innoopract - initial renaming/restructuring
11 *
12 *******************************************************************************/
13package org.eclipse.wst.xml.core.internal.propagate;
14
15
16import java.util.ArrayList;
17import java.util.Iterator;
18import java.util.List;
19
david_williams68bf9b32005-03-26 04:29:10 +000020import org.eclipse.wst.sse.core.internal.PropagatingAdapter;
21import org.eclipse.wst.sse.core.internal.PropagatingAdapterFactory;
david_williams4ad020f2005-04-18 08:00:30 +000022import org.eclipse.wst.sse.core.internal.provisional.AbstractAdapterFactory;
23import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
24import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
25import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
david_williams96213482004-11-11 09:07:12 +000026
27
28/**
29 * The PropagatingAdapterFactory is part of the "adapt on create" mechanism. A
30 * PropagatingAdapter, once added to a node, will cause proagating adapters to
31 * be created for all child nodes. A side effect of creating a
32 * PropagatingAdapter for a node is that is is also creates adapters for and
33 * adapts the Node for all other registered 'create on adapt' Adapters. This
34 * other adapters are registered by registering their factories via plugin
35 * extension point.
36 */
37public class PropagatingAdapterFactoryImpl extends AbstractAdapterFactory implements PropagatingAdapterFactory {
38
david_williams6f9dcdd2005-10-09 05:14:55 +000039 private PropagatingAdapter fAdapterInstance;
40 private List fContributedFactories = null;
david_williams96213482004-11-11 09:07:12 +000041
42 /**
43 * PropagatingAdapterFactory constructor comment.
44 */
45 public PropagatingAdapterFactoryImpl() {
46 this(PropagatingAdapter.class, true);
47 }
48
david_williams6f9dcdd2005-10-09 05:14:55 +000049 protected PropagatingAdapterFactoryImpl(Object adapterKey, boolean registerAdapters) { // ,
david_williams96213482004-11-11 09:07:12 +000050 super(adapterKey, registerAdapters);
51 }
52
david_williams285ee2d2005-04-10 18:21:21 +000053 public void addContributedFactories(INodeAdapterFactory factory) {
david_williams6f9dcdd2005-10-09 05:14:55 +000054 if (fContributedFactories != null) {
55 fContributedFactories.add(factory);
david_williams96213482004-11-11 09:07:12 +000056 }
57
58 }
59
david_williams96213482004-11-11 09:07:12 +000060 /**
61 * createAdapter method comment.
62 */
63 protected INodeAdapter createAdapter(INodeNotifier target) {
64 // every notifier get's one of these
65 // (and the same instance of it)
66 return getAdapterInstance();
67 }
68
69 /**
70 * Gets the adapterInstance.
71 *
72 * @return Returns a PropagatingAdapter
73 */
david_williams6f9dcdd2005-10-09 05:14:55 +000074 private PropagatingAdapter getAdapterInstance() {
75 if (fAdapterInstance == null) {
76 fAdapterInstance = new PropagatingAdapterImpl();
77 if (fContributedFactories != null) {
78 for (int i = 0; i < fContributedFactories.size(); i++)
79 fAdapterInstance.addAdaptOnCreateFactory((PropagatingAdapterFactory) fContributedFactories.get(i));
david_williams96213482004-11-11 09:07:12 +000080 }
81 }
david_williams6f9dcdd2005-10-09 05:14:55 +000082 return fAdapterInstance;
david_williams96213482004-11-11 09:07:12 +000083 }
84
85 public void release() {
86 // give the adapter instance a chance to release its factories
87 getAdapterInstance().release();
88
89 }
90
91 public void setContributedFactories(ArrayList list) {
david_williams6f9dcdd2005-10-09 05:14:55 +000092 fContributedFactories = list;
david_williams96213482004-11-11 09:07:12 +000093
94 }
95
david_williams6f9dcdd2005-10-09 05:14:55 +000096 public INodeAdapterFactory copy() {
97 PropagatingAdapterFactory clonedInstance = new PropagatingAdapterFactoryImpl(getAdapterKey(), isShouldRegisterAdapter());
98 // clone this adapters specific list of adapter factories too
99 if (fContributedFactories != null) {
100
101 Iterator iterator = fContributedFactories.iterator();
102 clonedInstance.setContributedFactories(new ArrayList());
103 while (iterator.hasNext()) {
104 INodeAdapterFactory existingFactory = (INodeAdapterFactory) iterator.next();
105 clonedInstance.addContributedFactories(existingFactory.copy());
106 }
107 }
108 return clonedInstance;
109 }
110
111
112
david_williams96213482004-11-11 09:07:12 +0000113}