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.ConfigurableApplicationContext;
28  import org.springframework.context.support.ClassPathXmlApplicationContext;
29  import org.springframework.util.StringUtils;
30  
31  @WebService(endpointInterface = "org.kuali.student.r1.common.dictionary.service.old.DictionaryService", serviceName = "DictionaryService", portName = "DictionaryService", targetNamespace = "http://student.kuali.org/wsdl/dictionary")
32  @Deprecated
33  public class DictionaryServiceSpringImpl implements DictionaryService {
34  
35  	private String[] dictionaryContext;
36  	private Map<String, ObjectStructure> objectStructures;
37  
38  	public DictionaryServiceSpringImpl() {
39  		super();
40  	}
41  
42  	public DictionaryServiceSpringImpl(String dictionaryContext) {
43  		super();
44  		String[] locations = StringUtils.tokenizeToStringArray(dictionaryContext, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
45  		this.dictionaryContext = locations;
46  		init();
47  	}
48  	
49  	public DictionaryServiceSpringImpl(String[] dictionaryContext) {
50  		super();
51          this.dictionaryContext = new String[dictionaryContext.length];
52          System.arraycopy(dictionaryContext, 0, this.dictionaryContext, 0, dictionaryContext.length);
53  //		this.dictionaryContext = dictionaryContext;
54  		init();
55  	}
56  
57  	@SuppressWarnings("unchecked")
58  	public void init() {
59  		ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext(dictionaryContext);
60  		Map<String, ObjectStructure> beansOfType = ac.getBeansOfType(ObjectStructure.class);
61          ac.close();
62  		objectStructures = new HashMap<String, ObjectStructure>();
63  		for (ObjectStructure objStr : beansOfType.values()){
64  			//Only add top level structures
65  			if(objStr.getId()!=null){
66  				if(objStr.getId().startsWith("object.")){
67  					if(!objStr.getId().startsWith("object.field.")){
68  						objectStructures.put(objStr.getKey(), objStr);
69  					}
70  				}else{
71  					objectStructures.put(objStr.getKey(), objStr);
72  				}
73  			}else{
74  				objectStructures.put(objStr.getKey(), objStr);
75  			}
76  		}
77  	}
78  
79  	@Override
80  	public ObjectStructure getObjectStructure(String objectTypeKey) {
81  		return objectStructures.get(objectTypeKey);
82  	}
83  
84  	@Override
85  	public List<String> getObjectTypes() {
86  		return new ArrayList<String>(objectStructures.keySet());
87  	}
88  
89  	public String[] getDictionaryContext() {
90  		return dictionaryContext;
91  	}
92  
93  	public void setDictionaryContext(String[] dictionaryContext) {
94          this.dictionaryContext = new String[dictionaryContext.length];
95          System.arraycopy(dictionaryContext, 0, this.dictionaryContext, 0, dictionaryContext.length);
96  //        this.dictionaryContext = dictionaryContext;
97  	}
98  
99  }