You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sv...@apache.org on 2007/02/13 16:48:38 UTC
svn commit: r507067 - in
/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src:
main/java/org/apache/tuscany/core/databinding/javabeans/
main/java/org/apache/tuscany/core/implementation/processor/
main/java/org/apache/tuscany/core/loader...
Author: svkrish
Date: Tue Feb 13 07:48:36 2007
New Revision: 507067
URL: http://svn.apache.org/viewvc?view=rev&rev=507067
Log:
'Updates for supporting Complex Properties and to bring in sync with current specs'
Added:
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/DefaultPropertyValueLoaderException.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoaderException.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyLoaderTestCase.java
Modified:
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformer.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaBeanTransformer.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/PropertyProcessor.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoader.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformer.java?view=diff&rev=507067&r1=507066&r2=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformer.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformer.java Tue Feb 13 07:48:36 2007
@@ -34,6 +34,16 @@
public class DOMNode2JavaBeanTransformer extends XML2JavaBeanTransformer<Node> {
@Override
+ public Node getRootElement(Node element) throws XML2JavaMapperException {
+ if ( element instanceof Document ) {
+ return ((Document)element).getDocumentElement();
+ } else {
+ return element;
+ }
+
+ }
+
+ @Override
public List<Node> getChildElements(Node parent) throws XML2JavaMapperException {
NodeList nodeList = parent.getChildNodes();
List<Node> nodeArrayList = new ArrayList<Node>(nodeList.getLength());
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaBeanTransformer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaBeanTransformer.java?view=diff&rev=507067&r1=507066&r2=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaBeanTransformer.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaBeanTransformer.java Tue Feb 13 07:48:36 2007
@@ -61,7 +61,7 @@
xmlType = (TypeInfo) element.getType();
}
- return toJavaObject(xmlType, source, context);
+ return toJavaObject(xmlType, getRootElement(source), context);
}
public Object toJavaObject(TypeInfo xmlType, T xmlElement, TransformationContext context) {
@@ -291,6 +291,8 @@
public abstract String getElementName(T element) throws XML2JavaMapperException;
public abstract boolean isTextElement(T element) throws XML2JavaMapperException;
+
+ public abstract T getRootElement(T element) throws XML2JavaMapperException;
public Class getTargetType() {
return Object.class;
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java?view=diff&rev=507067&r1=507066&r2=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java Tue Feb 13 07:48:36 2007
@@ -442,7 +442,7 @@
JavaMappedProperty<T> property = new JavaMappedProperty<T>();
property.setName(name);
property.setMember(member);
- property.setOverride(OverrideOptions.MAY);
+ property.setNoDefault(false);
property.setJavaType(paramType);
TypeInfo xmlType = typeMapper.getXMLType(paramType);
if (xmlType != null) {
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java?view=diff&rev=507067&r1=507066&r2=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java Tue Feb 13 07:48:36 2007
@@ -312,7 +312,7 @@
throw new DuplicatePropertyException(name);
}
property.setName(name);
- property.setOverride(OverrideOptions.valueOf(propAnnot.override().toUpperCase()));
+ property.setNoDefault(Boolean.parseBoolean(propAnnot.required()));
String xmlType = propAnnot.xmlType();
if (xmlType != null && xmlType.length() != 0) {
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/PropertyProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/PropertyProcessor.java?view=diff&rev=507067&r1=507066&r2=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/PropertyProcessor.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/PropertyProcessor.java Tue Feb 13 07:48:36 2007
@@ -57,8 +57,7 @@
Property annotation,
CompositeComponent parent,
DeploymentContext context) {
- property.setOverride(OverrideOptions.valueOf(annotation.override().toUpperCase()));
- String xmlType = annotation.xmlType();
+ String xmlType = annotation.xmlType();
if (xmlType != null && xmlType.length() != 0) {
property.setXmlType(QName.valueOf(annotation.xmlType()));
} else {
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java?view=diff&rev=507067&r1=507066&r2=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java Tue Feb 13 07:48:36 2007
@@ -35,7 +35,6 @@
import org.apache.tuscany.core.binding.local.LocalBindingDefinition;
import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
-import org.apache.tuscany.core.property.SimplePropertyObjectFactory;
import org.apache.tuscany.spi.ObjectFactory;
import org.apache.tuscany.spi.annotation.Autowire;
import org.apache.tuscany.spi.component.CompositeComponent;
@@ -48,9 +47,8 @@
import org.apache.tuscany.spi.loader.LoaderRegistry;
import org.apache.tuscany.spi.loader.LoaderUtil;
import org.apache.tuscany.spi.loader.MissingImplementationException;
-import org.apache.tuscany.spi.loader.MissingMustOverridePropertyException;
+import org.apache.tuscany.spi.loader.MissingPropertyValueException;
import org.apache.tuscany.spi.loader.MissingReferenceException;
-import org.apache.tuscany.spi.loader.NotOverridablePropertyException;
import org.apache.tuscany.spi.loader.PropertyObjectFactory;
import org.apache.tuscany.spi.loader.ReferenceMultiplicityViolationException;
import org.apache.tuscany.spi.loader.UndefinedPropertyException;
@@ -63,7 +61,6 @@
import org.apache.tuscany.spi.model.Implementation;
import org.apache.tuscany.spi.model.ModelObject;
import org.apache.tuscany.spi.model.Multiplicity;
-import org.apache.tuscany.spi.model.OverrideOptions;
import org.apache.tuscany.spi.model.Property;
import org.apache.tuscany.spi.model.PropertyValue;
import org.apache.tuscany.spi.model.ReferenceDefinition;
@@ -192,9 +189,8 @@
Property<Type> property = (Property<Type>) componentType.getProperties().get(name);
if (property == null) {
throw new UndefinedPropertyException(name);
- } else if (OverrideOptions.NO.equals(property.getOverride())) {
- throw new NotOverridablePropertyException(name);
}
+
PropertyValue<Type> propertyValue;
String source = reader.getAttributeValue(null, PROPERTY_SOURCE_ATTR);
String file = reader.getAttributeValue(null, PROPERTY_FILE_ATTR);
@@ -273,7 +269,7 @@
@SuppressWarnings("unchecked")
protected void populatePropertyValues(ComponentDefinition<Implementation<?>> componentDefinition)
- throws MissingMustOverridePropertyException {
+ throws LoaderException, MissingPropertyValueException {
ComponentType componentType = componentDefinition.getImplementation().getComponentType();
if (componentType != null) {
Map<String, Property<?>> properties = componentType.getProperties();
@@ -281,14 +277,16 @@
for (Property<?> aProperty : properties.values()) {
if (propertyValues.get(aProperty.getName()) == null) {
- if (aProperty.getOverride() == OverrideOptions.MUST) {
- throw new MissingMustOverridePropertyException(aProperty.getName());
+ if (aProperty.isNoDefault()) {
+ throw new MissingPropertyValueException(aProperty.getName());
} else if (aProperty.getDefaultValue() != null) {
PropertyValue propertyValue = new PropertyValue();
propertyValue.setName(aProperty.getName());
propertyValue.setValue(aProperty.getDefaultValue());
- propertyValue.setValueFactory(new SimplePropertyObjectFactory(aProperty,
- propertyValue.getValue()));
+ propertyValue.setValueFactory(
+ propertyFactory.createObjectFactory(aProperty, propertyValue));
+ /*propertyValue.setValueFactory(new SimplePropertyObjectFactory(aProperty,
+ propertyValue.getValue()));*/
propertyValues.put(aProperty.getName(), propertyValue);
}
}
Added: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/DefaultPropertyValueLoaderException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/DefaultPropertyValueLoaderException.java?view=auto&rev=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/DefaultPropertyValueLoaderException.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/DefaultPropertyValueLoaderException.java Tue Feb 13 07:48:36 2007
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+
+/**
+ * Root unchecked exception for the injection package
+ *
+ * @version $Rev: 487057 $ $Date: 2006-12-14 12:50:44 +0530 (Thu, 14 Dec 2006) $
+ */
+public class DefaultPropertyValueLoaderException extends PropertyLoaderException {
+
+ public DefaultPropertyValueLoaderException() {
+ super("Default Property Value must be supplied only when 'noDefault' attribute is set to 'false'");
+ }
+}
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoader.java?view=diff&rev=507067&r1=507066&r2=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoader.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoader.java Tue Feb 13 07:48:36 2007
@@ -18,27 +18,26 @@
*/
package org.apache.tuscany.core.loader;
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
-import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
-import org.osoa.sca.annotations.Constructor;
-import org.w3c.dom.Document;
-
+import org.apache.tuscany.spi.annotation.Autowire;
import org.apache.tuscany.spi.component.CompositeComponent;
import org.apache.tuscany.spi.deployer.DeploymentContext;
import org.apache.tuscany.spi.extension.LoaderExtension;
-import org.apache.tuscany.spi.loader.LoaderException;
import org.apache.tuscany.spi.loader.LoaderRegistry;
-import org.apache.tuscany.spi.model.OverrideOptions;
-import org.apache.tuscany.spi.model.Property;
import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
import org.apache.tuscany.spi.util.stax.StaxUtil;
-import org.apache.tuscany.spi.annotation.Autowire;
+import org.osoa.sca.annotations.Constructor;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
/**
* Loads a property from an XML-based assembly file
@@ -48,8 +47,10 @@
public class PropertyLoader extends LoaderExtension<Property> {
public static final String PROPERTY_NAME_ATTR = "name";
public static final String PROPERTY_TYPE_ATTR = "type";
+ public static final String PROPERTY_ELEMENT_ATTR = "element";
public static final String PROPERTY_MANY_ATTR = "many";
- public static final String PROPERTY_OVERRIDE_ATTR = "override";
+ public static final String PROPERTY_NO_DEFAULT_ATTR = "noDefault";
+ public static final char COLON = ':';
public static final QName PROPERTY = new QName(XML_NAMESPACE_1_0, "property");
private final DocumentBuilder documentBuilder;
@@ -71,34 +72,78 @@
public Property<?> load(CompositeComponent parent, ModelObject object, XMLStreamReader reader,
DeploymentContext ctx)
- throws XMLStreamException, LoaderException {
+ throws XMLStreamException, PropertyLoaderException {
assert PROPERTY.equals(reader.getName());
String name = reader.getAttributeValue(null, PROPERTY_NAME_ATTR);
String typeName = reader.getAttributeValue(null, PROPERTY_TYPE_ATTR);
+ String elementName = reader.getAttributeValue(null, PROPERTY_ELEMENT_ATTR);
+
QName xmlType = null;
if (typeName != null) {
- int index = typeName.indexOf(':');
+ int index = typeName.indexOf(COLON);
if (index != -1) {
String prefix = typeName.substring(0, index);
String localName = typeName.substring(index + 1);
String ns = reader.getNamespaceURI(prefix);
xmlType = new QName(ns, localName, prefix);
}
+ } else if (elementName != null) {
+ QName xmlElement = null;
+ int index = typeName.indexOf(COLON);
+ if (index != -1) {
+ String prefix = typeName.substring(0, index);
+ String localName = typeName.substring(index + 1);
+ String ns = reader.getNamespaceURI(prefix);
+ xmlElement = new QName(ns, localName, prefix);
+ //FIXME :
+ //need to figure out how to determine the xmltype from this xmlelement
+ //this need access to the global xml element thro schemalocation or thro
+ //artifact repository
+ xmlType = null;
+ }
+ }
+
+
+ boolean many = false;
+ boolean noDefault = false;
+ String attrValue = null;
+ attrValue = reader.getAttributeValue(null, PROPERTY_MANY_ATTR);
+ if (attrValue != null) {
+ many = Boolean.parseBoolean(attrValue);
+ }
+
+ attrValue = reader.getAttributeValue(null, PROPERTY_NO_DEFAULT_ATTR);
+ if (attrValue != null) {
+ noDefault = Boolean.parseBoolean(attrValue);
}
- boolean many = Boolean.parseBoolean(reader.getAttributeValue(null, PROPERTY_MANY_ATTR));
- String override = reader.getAttributeValue(null, PROPERTY_OVERRIDE_ATTR);
Document value = StaxUtil.createPropertyValue(reader, xmlType, documentBuilder);
+
+ if (noDefault && isDefaultValueDefined(value) ) {
+ DefaultPropertyValueLoaderException ex = new DefaultPropertyValueLoaderException();
+ ex.setPropertyName(name);
+ ex.setLine(reader.getLocation().getLineNumber());
+ ex.setColumn(reader.getLocation().getColumnNumber());
+ throw ex;
+ }
Property<?> property = new Property();
property.setName(name);
property.setXmlType(xmlType);
property.setMany(many);
-
- if (override != null) {
- property.setOverride(OverrideOptions.valueOf(override.toUpperCase()));
- }
+ property.setNoDefault(noDefault);
property.setDefaultValue(value);
return property;
+ }
+
+ private boolean isDefaultValueDefined(Document value) {
+ if ( value.getFirstChild().hasChildNodes() ) {
+ Node childNode = value.getFirstChild().getFirstChild();
+ if ( childNode.getNodeType() == Document.ELEMENT_NODE ||
+ (childNode.getNodeType() == Document.TEXT_NODE &&
+ childNode.getTextContent().trim().length() > 0) )
+ return true;
+ }
+ return false;
}
}
Added: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoaderException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoaderException.java?view=auto&rev=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoaderException.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoaderException.java Tue Feb 13 07:48:36 2007
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import org.apache.tuscany.spi.loader.LoaderException;
+
+/**
+ * Root unchecked exception for the injection package
+ *
+ * @version $Rev: 487057 $ $Date: 2006-12-14 12:50:44 +0530 (Thu, 14 Dec 2006) $
+ */
+public class PropertyLoaderException extends LoaderException {
+
+ private String propertyName;
+
+ public PropertyLoaderException() {
+ super();
+ }
+
+ public PropertyLoaderException(String message) {
+ super(message);
+ }
+
+
+ protected PropertyLoaderException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public PropertyLoaderException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ protected PropertyLoaderException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public PropertyLoaderException(Throwable cause) {
+ super(cause);
+ }
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ public void setPropertyName(String propertyName) {
+ this.propertyName = propertyName;
+ }
+
+}
Added: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java?view=auto&rev=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java Tue Feb 13 07:48:36 2007
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.javabeans;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.javabeans.DOMNode2JavaBeanTransformer;
+import org.apache.tuscany.core.databinding.javabeans.JavaBean2DOMNodeTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.apache.tuscany.spi.idl.ElementInfo;
+import org.apache.tuscany.spi.idl.TypeInfo;
+import org.apache.tuscany.spi.model.DataType;
+import org.easymock.EasyMock;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+/**
+ * Testcase to test the XMLTypeMapperExtension which is the back bone for all transformations supported by the JavaBeans
+ * Databinding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DOMNode2JavaBeanTransformerTestCase extends TestCase {
+
+ private DOMNode2JavaBeanTransformer dom2JavaTransformer = new DOMNode2JavaBeanTransformer();
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testFieldSettings() throws Exception {
+ String samplePropertyXML =
+ "<property name=\"prop2\" >" + "<integerNumber>27</integerNumber>"
+ + "<floatNumber>79.34</floatNumber>"
+ + "<doubleNumber>184.52</doubleNumber>" + "<innerProperty>"
+ + "<integerNumber>54</integerNumber>" + "<floatNumber>158.68</floatNumber>"
+ + "<doubleNumber>369.04</doubleNumber>" + "</innerProperty>"
+ + "<stringArray>TestString_1</stringArray>"
+ + "<stringArray>TestString_2</stringArray>" + "<boolArray>true</boolArray>"
+ + "<boolArray>false</boolArray>" + "</property>";
+
+ DocumentBuilder builder = DOMHelper.newDocumentBuilder();
+ InputSource inputSource = new InputSource(new StringReader(samplePropertyXML));
+ Node samplePropertyNode = builder.parse(inputSource);
+ TypeInfo typeInfo = new TypeInfo(null, false, null);
+
+ TransformationContext context = EasyMock.createMock(TransformationContext.class);
+ DataType<Class> targetDataType = new DataType<Class>(null, SamplePropertyBean.class);
+ EasyMock.expect(context.getTargetDataType()).andReturn(targetDataType).anyTimes();
+
+ DataType<Class> sourceDataType = new DataType<Class>(null, null);
+ ElementInfo eleInfo = new ElementInfo(null, typeInfo);
+ sourceDataType.setMetadata(ElementInfo.class.getName(), eleInfo);
+ EasyMock.expect(context.getSourceDataType()).andReturn(sourceDataType).anyTimes();
+ EasyMock.replay(context);
+
+ Object javaObject =
+ dom2JavaTransformer.transform(((Document) samplePropertyNode).getDocumentElement(), context);
+
+ assertTrue(javaObject instanceof SamplePropertyBean);
+ SamplePropertyBean samplePropBean = (SamplePropertyBean) javaObject;
+ assertEquals(samplePropBean.getIntegerNumber(), 27);
+ assertEquals((float) 79.34, samplePropBean.getFloatNumber());
+ assertEquals(samplePropBean.getInnerProperty().getDoubleNumber(), 369.04);
+
+ assertEquals(samplePropBean.getStringArray()[0], "TestString_1");
+ assertEquals(samplePropBean.boolArray[0], true);
+
+ /** testing for object to node * */
+ javax.xml.transform.Transformer transformer =
+ TransformerFactory.newInstance().newTransformer();
+ JavaBean2DOMNodeTransformer java2DomTransformer = new JavaBean2DOMNodeTransformer();
+ Node aNode = java2DomTransformer.transform(javaObject, context);
+ StringWriter sw = new StringWriter();
+ transformer.transform(new DOMSource(aNode), new StreamResult(sw));
+ String nodeString = sw.toString();
+ //System.out.println(nodeString);
+
+ // testing the case when field and getter method do not have public access
+ assertTrue(nodeString.indexOf("<doubleNumber>184.52</doubleNumber>") == -1);
+ // test the case for fields that are of array type
+ assertTrue(nodeString.indexOf("<stringArray>TestString_1</stringArray>"
+ + "<stringArray>TestString_2</stringArray>") != -1);
+ // testing the case for non-public field with public getter method
+ assertTrue(nodeString.indexOf("<integerNumber>27</integerNumber>") != -1);
+ // test the case for public field that is a another java bean .i.e. embeded javabean
+ int startIndex = nodeString.indexOf("<innerProperty>");
+ int endIndex = nodeString.indexOf("</innerProperty>");
+ String fragment = nodeString.substring(startIndex, endIndex);
+ assertTrue(fragment.indexOf("<integerNumber>54</integerNumber>") != -1);
+
+ // System.out.println(sw.toString());
+
+ }
+
+
+ public static class SamplePropertyBean {
+
+ private float floatNumber = 50;
+ private SamplePropertyBean innerProperty;
+ public boolean[] boolArray;
+ private double doubleNumber = 75;
+ private int integerNumber = 25;
+ private String[] stringArray;
+
+ public SamplePropertyBean() {
+
+ }
+
+ double getDoubleNumber() {
+ return doubleNumber;
+ }
+
+ public void setDoubleNumber(double doubleNumber) {
+ this.doubleNumber = doubleNumber;
+ }
+
+ public float getFloatNumber() {
+ return floatNumber;
+ }
+
+ public void setFloatNumber(float floatNumber) {
+ this.floatNumber = floatNumber;
+ }
+
+ public int getIntegerNumber() {
+ return integerNumber;
+ }
+
+ public void setIntegerNumber(int integerNumber) {
+ this.integerNumber = integerNumber;
+ }
+
+ public SamplePropertyBean getInnerProperty() {
+ return innerProperty;
+ }
+
+ public void setInnerProperty(SamplePropertyBean prop) {
+ this.innerProperty = prop;
+ }
+
+ public String toString() {
+ return Double.toString(integerNumber + floatNumber + doubleNumber) + " & "
+ + ((innerProperty == null) ? "" : innerProperty.toString());
+ }
+
+ public String[] getStringArray() {
+ return stringArray;
+ }
+
+ public void setStringArray(String[] stringArray) {
+ this.stringArray = stringArray;
+ }
+
+ }
+}
Added: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java?view=auto&rev=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java Tue Feb 13 07:48:36 2007
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.javabeans;
+
+import java.io.StringWriter;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Node;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.model.DataType;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Testcase to test the XMLTypeMapperExtension which is the back bone for all transformations supported by the JavaBeans
+ * Databinding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaBean2DOMNodeTransformerTestCase extends TestCase {
+ private JavaBean2DOMNodeTransformer aTransformer = new JavaBean2DOMNodeTransformer();
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testTranformation() throws Exception {
+ TransformationContext context = EasyMock.createMock(TransformationContext.class);
+ DataType<Class> dataType = new DataType<Class>(null, SamplePropertyBean.class);
+ EasyMock.expect(context.getTargetDataType()).andReturn(dataType).anyTimes();
+ EasyMock.replay(context);
+
+ javax.xml.transform.Transformer transformer =
+ TransformerFactory.newInstance().newTransformer();
+ Object data = new int[]{10, 20, 30, 40};
+ Node aNode = aTransformer.transform(data, context);
+ StringWriter sw = new StringWriter();
+ transformer.transform(new DOMSource(aNode), new StreamResult(sw));
+
+ System.out.println(sw.toString());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><int_collection><int>10</int><int>20</int>"
+ + "<int>30</int><int>40</int></int_collection>",
+ sw.toString());
+ }
+
+ public static class SamplePropertyBean {
+ private float floatNumber = 50;
+ private SamplePropertyBean innerProperty;
+ private double doubleNumber = 75;
+ private int integerNumber = 25;
+ private String[] stringArray;
+
+ public SamplePropertyBean() {
+
+ }
+
+ double getDoubleNumber() {
+ return doubleNumber;
+ }
+
+ public void setDoubleNumber(double doubleNumber) {
+ this.doubleNumber = doubleNumber;
+ }
+
+ public float getFloatNumber() {
+ return floatNumber;
+ }
+
+ public void setFloatNumber(float floatNumber) {
+ this.floatNumber = floatNumber;
+ }
+
+ public int getIntegerNumber() {
+ return integerNumber;
+ }
+
+ public void setIntegerNumber(int integerNumber) {
+ this.integerNumber = integerNumber;
+ }
+
+ public SamplePropertyBean getInnerProperty() {
+ return innerProperty;
+ }
+
+ public void setInnerProperty(SamplePropertyBean prop) {
+ this.innerProperty = prop;
+ }
+
+ public String toString() {
+ return Double.toString(integerNumber + floatNumber + doubleNumber) + " & "
+ + ((innerProperty == null) ? "" : innerProperty.toString());
+ }
+
+ public String[] getStringArray() {
+ return stringArray;
+ }
+
+ public void setStringArray(String[] stringArray) {
+ this.stringArray = stringArray;
+ }
+
+ }
+}
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java?view=diff&rev=507067&r1=507066&r2=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java Tue Feb 13 07:48:36 2007
@@ -21,17 +21,15 @@
import java.lang.reflect.Constructor;
import java.util.List;
-import org.osoa.sca.annotations.Property;
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
import org.apache.tuscany.spi.implementation.java.DuplicatePropertyException;
import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
import org.apache.tuscany.spi.implementation.java.JavaMappedService;
import org.apache.tuscany.spi.implementation.java.PojoComponentType;
-import org.apache.tuscany.spi.model.OverrideOptions;
-
-import junit.framework.TestCase;
-import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.osoa.sca.annotations.Property;
/**
* @version $Rev$ $Date$
@@ -47,8 +45,7 @@
Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
processor.visitConstructor(null, ctor, type, null);
JavaMappedProperty<?> property = type.getProperties().get("myProp");
- //assertTrue(property.isRequired());
- assertEquals(property.getOverride(), OverrideOptions.MAY);
+ assertEquals(property.isNoDefault(), true);
assertEquals("myProp", property.getName());
}
@@ -124,7 +121,7 @@
private static class Foo {
@org.osoa.sca.annotations.Constructor()
- public Foo(@Property(name = "myProp", override = "may") String prop) {
+ public Foo(@Property(name = "myProp", required = "true") String prop) {
}
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java?view=diff&rev=507067&r1=507066&r2=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java Tue Feb 13 07:48:36 2007
@@ -21,26 +21,23 @@
import java.util.Collection;
import java.util.List;
-import org.osoa.sca.annotations.Property;
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
import org.apache.tuscany.spi.implementation.java.DuplicatePropertyException;
import org.apache.tuscany.spi.implementation.java.IllegalPropertyException;
import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
import org.apache.tuscany.spi.implementation.java.JavaMappedService;
import org.apache.tuscany.spi.implementation.java.PojoComponentType;
-import org.apache.tuscany.spi.model.OverrideOptions;
-import static org.apache.tuscany.spi.model.OverrideOptions.MUST;
-
-import junit.framework.TestCase;
-import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.osoa.sca.annotations.Property;
/**
* @version $Rev$ $Date$
*/
public class PropertyProcessorTestCase extends TestCase {
- PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
PropertyProcessor processor;
public void testMethodAnnotation() throws Exception {
@@ -52,7 +49,6 @@
processor.visitMethod(null, Foo.class.getMethod("setFooRequired", String.class), type, null);
JavaMappedProperty prop = type.getProperties().get("fooRequired");
assertNotNull(prop);
- assertEquals(prop.getOverride(), MUST);
}
public void testMethodName() throws Exception {
@@ -69,7 +65,6 @@
processor.visitField(null, Foo.class.getDeclaredField("bazRequired"), type, null);
JavaMappedProperty prop = type.getProperties().get("bazRequired");
assertNotNull(prop);
- assertEquals(prop.getOverride(), OverrideOptions.MUST);
}
public void testFieldName() throws Exception {
@@ -117,7 +112,7 @@
@Property
protected String baz;
- @Property(override = "must")
+ @Property(required = "true")
protected String bazRequired;
@Property(name = "theBaz")
protected String bazField;
@@ -126,7 +121,7 @@
public void setFoo(String string) {
}
- @Property(override = "must")
+ @Property(required = "true")
public void setFooRequired(String string) {
}
@@ -206,5 +201,4 @@
assertSame(String.class, prop.getJavaType());
assertTrue(prop.isMany());
}
-
}
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java?view=diff&rev=507067&r1=507066&r2=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java Tue Feb 13 07:48:36 2007
@@ -20,20 +20,19 @@
import javax.xml.stream.XMLStreamException;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
import org.apache.tuscany.spi.implementation.java.PojoComponentType;
import org.apache.tuscany.spi.loader.LoaderException;
import org.apache.tuscany.spi.loader.LoaderRegistry;
-import org.apache.tuscany.spi.loader.MissingMustOverridePropertyException;
+import org.apache.tuscany.spi.loader.MissingPropertyValueException;
import org.apache.tuscany.spi.loader.PropertyObjectFactory;
import org.apache.tuscany.spi.model.ComponentDefinition;
import org.apache.tuscany.spi.model.Implementation;
-import org.apache.tuscany.spi.model.OverrideOptions;
import org.apache.tuscany.spi.model.Property;
import org.apache.tuscany.spi.model.ReferenceDefinition;
import org.apache.tuscany.spi.model.ServiceDefinition;
-
-import junit.framework.TestCase;
-import org.apache.tuscany.core.implementation.java.JavaImplementation;
import org.easymock.EasyMock;
/**
@@ -47,18 +46,25 @@
* Verifies that an optional property not cofigured in an assembly will avoid having a PropertyValue created for it
* so that the runtime does not erroneously inject null values
*/
- public void testOptionalPropertyNotConfigured() throws LoaderException, XMLStreamException {
+ public void testMissingPropertyValueException() throws LoaderException, XMLStreamException {
PojoComponentType<?, ?, Property<?>> type =
new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
Property property = new Property();
property.setName("name");
- property.setOverride(OverrideOptions.MAY);
+ property.setNoDefault(true);
type.add(property);
+
JavaImplementation impl = new JavaImplementation(null, type);
impl.setComponentType(type);
ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl);
- loader.populatePropertyValues(defn);
assertTrue(defn.getPropertyValues().isEmpty());
+ try {
+ loader.populatePropertyValues(defn);
+ fail();
+ } catch (Exception e) {
+ assertTrue(e instanceof MissingPropertyValueException);
+ }
+
}
protected void setUp() throws Exception {
@@ -76,7 +82,7 @@
@Override
public void populatePropertyValues(ComponentDefinition<Implementation<?>> componentDefinition)
- throws MissingMustOverridePropertyException {
+ throws MissingPropertyValueException, LoaderException {
super.populatePropertyValues(componentDefinition);
}
}
Added: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyLoaderTestCase.java?view=auto&rev=507067
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyLoaderTestCase.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyLoaderTestCase.java Tue Feb 13 07:48:36 2007
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.io.StringReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.util.stax.StaxUtil;
+import org.easymock.EasyMock;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * @version $Rev: 502055 $ $Date: 2007-02-01 05:37:32 +0530 (Thu, 01 Feb 2007) $
+ */
+public class PropertyLoaderTestCase extends TestCase {
+ private PropertyLoader propertyLoader;
+ private XMLInputFactory xmlFactory;
+
+ public void testPropertyLoading() throws Exception {
+ String xml = "<tus:property xmlns:foo='http://foo.com' "
+ + "xmlns:tus='http://www.osoa.org/xmlns/sca/1.0'"
+ + " name='TestProperty' many='true' type='foo:TestType'>"
+ + "<foo:a>aValue</foo:a>"
+ + "<foo:b>InterestingURI</foo:b>"
+ + "</tus:property>";
+
+ XMLStreamReader reader = getReader(xml);
+ Property<?> aProperty = propertyLoader.load(null, null, reader, null);
+
+ assertEquals("TestProperty", aProperty.getName());
+ assertEquals(new QName("http://foo.com", "TestType", "foo"), aProperty.getXmlType());
+ assertEquals(false, aProperty.isNoDefault());
+ assertEquals(true, aProperty.isMany());
+
+ Element root = aProperty.getDefaultValue().getDocumentElement();
+ NodeList childNodes = root.getChildNodes();
+ assertEquals(2, childNodes.getLength());
+
+ Element e = (Element) childNodes.item(0);
+ assertEquals("http://foo.com", e.getNamespaceURI());
+ assertEquals("a", e.getLocalName());
+ assertEquals("aValue", e.getTextContent());
+ e = (Element) childNodes.item(1);
+ assertEquals("http://foo.com", e.getNamespaceURI());
+ assertEquals("b", e.getLocalName());
+ assertEquals("InterestingURI", e.getTextContent());
+ }
+
+ public void testPropertyLoadingNoDefault() throws Exception {
+ String xml = "<tus:property xmlns:foo='http://foo.com' "
+ + "xmlns:tus='http://www.osoa.org/xmlns/sca/1.0'"
+ + " name='TestProperty' many='true' type='foo:TestType' noDefault='true'>"
+ + "<foo:a>aValue</foo:a>"
+ + "<foo:b>InterestingURI</foo:b>"
+ + "</tus:property>";
+
+ XMLStreamReader reader = getReader(xml);
+
+ try {
+ propertyLoader.load(null, null, reader, null);
+ } catch (Exception e) {
+ assertTrue(e instanceof DefaultPropertyValueLoaderException);
+ }
+ }
+
+ public XMLStreamReader getReader(String xml) throws XMLStreamException {
+ XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml));
+ reader.next();
+ return reader;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ xmlFactory = XMLInputFactory.newInstance();
+ propertyLoader = new PropertyLoader(EasyMock.createMock(LoaderRegistry.class));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org