KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > mps > PropertySet


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.components.mps;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 import javax.jbi.JBIException;
23 import javax.jbi.messaging.NormalizedMessage;
24
25 import org.w3c.dom.Element JavaDoc;
26 import org.w3c.dom.NodeList JavaDoc;
27
28 public class PropertySet {
29
30     
31     public final static String JavaDoc XML_ELEMENT_NAME = "property-set";
32     
33     public final static String JavaDoc XML_ATTR_NAME_NAME = "name";
34     
35     /**
36      * Our name
37      */

38     private String JavaDoc propertySetName;
39
40     /**
41      * Our list of property value resolvers
42      */

43     private ArrayList JavaDoc pvrs = new ArrayList JavaDoc();
44     
45     /**
46      * Create a propertySet with a particular name
47      * Element self is //property-set
48      *
49      * @param name
50      */

51     public PropertySet(String JavaDoc name, Element JavaDoc self) throws ConfigNotSupportedException{
52         this.propertySetName = name;
53         NodeList JavaDoc properties = self.getElementsByTagName(PropertyValueResolver.XML_ELEMENT_NAME);
54         for (int i=0; i < properties.getLength();i++) {
55             Element JavaDoc property = (Element JavaDoc)properties.item(i);
56             this.pvrs.add((new PropertyValueResolver(property.getAttribute(XML_ATTR_NAME_NAME),property)));
57         }
58     }
59     
60     /**
61      * Apply all the property values for this in/out pair
62      *
63      * @param in
64      * @param out
65      */

66     public void applyProperties(NormalizedMessage in, NormalizedMessage out) throws JBIException {
67         
68         // for every property, set the value on the message
69
for (Iterator JavaDoc iter = pvrs.iterator(); iter.hasNext();) {
70             ((PropertyValueResolver)iter.next()).setProperty(in,out);
71         }
72     }
73
74     public String JavaDoc getName() {
75         return propertySetName;
76     }
77 }
78
Popular Tags