View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.r1.common.dictionary.service.impl.old;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  import javax.jws.WebService;
24  
25  import org.kuali.student.r1.common.dictionary.old.dto.ObjectStructure;
26  import org.kuali.student.r1.common.dictionary.service.old.DictionaryService;
27  import org.springframework.context.ApplicationContext;
28  import org.springframework.context.ConfigurableApplicationContext;
29  import org.springframework.context.support.ClassPathXmlApplicationContext;
30  import org.springframework.util.StringUtils;
31  
32  @WebService(endpointInterface = "org.kuali.student.r1.common.dictionary.service.old.DictionaryService", serviceName = "DictionaryService", portName = "DictionaryService", targetNamespace = "http://student.kuali.org/wsdl/dictionary")
33  @Deprecated
34  public class DictionaryServiceSpringImpl implements DictionaryService {
35  
36  	private String[] dictionaryContext;
37  	private Map<String, ObjectStructure> objectStructures;
38  
39  	public DictionaryServiceSpringImpl() {
40  		super();
41  	}
42  
43  	public DictionaryServiceSpringImpl(String dictionaryContext) {
44  		super();
45  		String[] locations = StringUtils.tokenizeToStringArray(dictionaryContext, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
46  		this.dictionaryContext = locations;
47  		init();
48  	}
49  	
50  	public DictionaryServiceSpringImpl(String[] dictionaryContext) {
51  		super();
52  		this.dictionaryContext = dictionaryContext;
53  		init();
54  	}
55  
56  	@SuppressWarnings("unchecked")
57  	public void init() {
58  		ApplicationContext ac = new ClassPathXmlApplicationContext(dictionaryContext);
59  
60  		Map<String, ObjectStructure> beansOfType = (Map<String, ObjectStructure>) ac.getBeansOfType(ObjectStructure.class);
61  		objectStructures = new HashMap<String, ObjectStructure>();
62  		for (ObjectStructure objStr : beansOfType.values()){
63  			//Only add top level structures
64  			if(objStr.getId()!=null){
65  				if(objStr.getId().startsWith("object.")){
66  					if(!objStr.getId().startsWith("object.field.")){
67  						objectStructures.put(objStr.getKey(), objStr);
68  					}
69  				}else{
70  					objectStructures.put(objStr.getKey(), objStr);
71  				}
72  			}else{
73  				objectStructures.put(objStr.getKey(), objStr);
74  			}
75  		}
76  	}
77  
78  	@Override
79  	public ObjectStructure getObjectStructure(String objectTypeKey) {
80  		return objectStructures.get(objectTypeKey);
81  	}
82  
83  	@Override
84  	public List<String> getObjectTypes() {
85  		return new ArrayList<String>(objectStructures.keySet());
86  	}
87  
88  	public String[] getDictionaryContext() {
89  		return dictionaryContext;
90  	}
91  
92  	public void setDictionaryContext(String[] dictionaryContext) {
93  		this.dictionaryContext = dictionaryContext;
94  	}
95  
96  }