KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > importer > view > ParentContext


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.importer.view;
18
19 import java.util.HashSet JavaDoc;
20 import java.util.Map JavaDoc;
21 import java.util.Set JavaDoc;
22
23 import org.alfresco.repo.importer.ImportParent;
24 import org.alfresco.repo.importer.Importer;
25 import org.alfresco.service.cmr.dictionary.AspectDefinition;
26 import org.alfresco.service.cmr.dictionary.AssociationDefinition;
27 import org.alfresco.service.cmr.dictionary.DictionaryService;
28 import org.alfresco.service.cmr.dictionary.TypeDefinition;
29 import org.alfresco.service.cmr.repository.NodeRef;
30 import org.alfresco.service.cmr.view.ImporterException;
31 import org.alfresco.service.namespace.QName;
32
33
34 /**
35  * Maintains state about the parent context of the node being imported.
36  *
37  * @author David Caruana
38  *
39  */

40 public class ParentContext extends ElementContext
41     implements ImportParent
42 {
43     private NodeRef parentRef;
44     private QName assocType;
45
46
47     /**
48      * Construct
49      *
50      * @param dictionary
51      * @param configuration
52      * @param progress
53      * @param elementName
54      * @param parentRef
55      * @param assocType
56      */

57     public ParentContext(QName elementName, DictionaryService dictionary, Importer importer)
58     {
59         super(elementName, dictionary, importer);
60         parentRef = importer.getRootRef();
61         assocType = importer.getRootAssocType();
62     }
63     
64     /**
65      * Construct (with unknown child association)
66      *
67      * @param elementName
68      * @param parent
69      */

70     public ParentContext(QName elementName, NodeContext parent)
71     {
72         super(elementName, parent.getDictionaryService(), parent.getImporter());
73         parentRef = parent.getNodeRef();
74     }
75     
76     /**
77      * Construct
78      *
79      * @param elementName
80      * @param parent
81      * @param childDef
82      */

83     public ParentContext(QName elementName, NodeContext parent, AssociationDefinition assocDef)
84     {
85         this(elementName, parent);
86         
87         TypeDefinition typeDef = parent.getTypeDefinition();
88         if (typeDef != null)
89         {
90             //
91
// Ensure association type is valid for node parent
92
//
93

94             // Build complete Type Definition
95
Set JavaDoc<QName> allAspects = new HashSet JavaDoc<QName>();
96             for (AspectDefinition typeAspect : parent.getTypeDefinition().getDefaultAspects())
97             {
98                 allAspects.add(typeAspect.getName());
99             }
100             allAspects.addAll(parent.getNodeAspects());
101             TypeDefinition anonymousType = getDictionaryService().getAnonymousType(parent.getTypeDefinition().getName(), allAspects);
102             
103             // Determine if Association is valid for Type Definition
104
Map JavaDoc<QName, AssociationDefinition> nodeAssociations = anonymousType.getAssociations();
105             if (nodeAssociations.containsKey(assocDef.getName()) == false)
106             {
107                 throw new ImporterException("Association " + assocDef.getName() + " is not valid for node " + parent.getTypeDefinition().getName());
108             }
109         }
110         
111         parentRef = parent.getNodeRef();
112         assocType = assocDef.getName();
113     }
114     
115     /* (non-Javadoc)
116      * @see org.alfresco.repo.importer.ImportParent#getParentRef()
117      */

118     public NodeRef getParentRef()
119     {
120         return parentRef;
121     }
122     
123     /**
124      * Set Parent Reference
125      *
126      * @param parentRef parent reference
127      */

128     public void setParentRef(NodeRef parentRef)
129     {
130         this.parentRef = parentRef;
131     }
132     
133     /* (non-Javadoc)
134      * @see org.alfresco.repo.importer.ImportParent#getAssocType()
135      */

136     public QName getAssocType()
137     {
138         return assocType;
139     }
140
141     /**
142      * Set Parent / Child Assoc Type
143      *
144      * @param assocType association type
145      */

146     public void setAssocType(QName assocType)
147     {
148         this.assocType = assocType;
149     }
150     
151     /* (non-Javadoc)
152      * @see java.lang.Object#toString()
153      */

154     @Override JavaDoc
155     public String JavaDoc toString()
156     {
157         return "ParentContext[parent=" + parentRef + ",assocType=" + getAssocType() + "]";
158     }
159     
160 }
161
Popular Tags