You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xbean-scm@geronimo.apache.org by dj...@apache.org on 2010/02/06 09:01:44 UTC
svn commit: r907189 - in /geronimo/xbean/trunk/xbean-blueprint: ./
src/main/java/org/apache/xbean/blueprint/cm/
src/main/java/org/apache/xbean/blueprint/context/impl/
src/main/java/org/apache/xbean/blueprint/generator/
src/main/resources/META-INF/ src/...
Author: djencks
Date: Sat Feb 6 08:01:43 2010
New Revision: 907189
URL: http://svn.apache.org/viewvc?rev=907189&view=rev
Log:
XBEAN-142 Allow for non-loadable managed classes in properties files. Implement a proeprty-placeholder using jexl to evaluate expressions
Added:
geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/
geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/CmNamespaceHandler.java (with props)
geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlExpressionParser.java (with props)
geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlPropertyPlaceholder.java (with props)
geronimo/xbean/trunk/xbean-blueprint/src/main/resources/OSGI-INF/
geronimo/xbean/trunk/xbean-blueprint/src/main/resources/OSGI-INF/blueprint/
geronimo/xbean/trunk/xbean-blueprint/src/main/resources/OSGI-INF/blueprint/xbean-cm.xml (with props)
geronimo/xbean/trunk/xbean-blueprint/src/main/resources/org/apache/xbean/blueprint/
geronimo/xbean/trunk/xbean-blueprint/src/main/resources/org/apache/xbean/blueprint/cm/
geronimo/xbean/trunk/xbean-blueprint/src/main/resources/org/apache/xbean/blueprint/cm/xbean-cm.xsd (with props)
geronimo/xbean/trunk/xbean-blueprint/src/test/java/org/apache/xbean/blueprint/context/impl/JexlTest.java (with props)
Removed:
geronimo/xbean/trunk/xbean-blueprint/src/main/resources/META-INF/
geronimo/xbean/trunk/xbean-blueprint/src/main/resources/org/apache/xbean/spring/
Modified:
geronimo/xbean/trunk/xbean-blueprint/pom.xml
geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/XBeanNamespaceHandler.java
geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/generator/Type.java
Modified: geronimo/xbean/trunk/xbean-blueprint/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-blueprint/pom.xml?rev=907189&r1=907188&r2=907189&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-blueprint/pom.xml (original)
+++ geronimo/xbean/trunk/xbean-blueprint/pom.xml Sat Feb 6 08:01:43 2010
@@ -53,8 +53,26 @@
<version>1.0.0-incubating-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint.cm</artifactId>
+ <version>1.0.0-incubating-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jexl</artifactId>
+ <version>2.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</artifactId>
<version>${pax.logging.version}</version>
@@ -68,6 +86,13 @@
</dependency>
<dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>4.2.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-service</artifactId>
<version>${pax.logging.version}</version>
Added: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/CmNamespaceHandler.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/CmNamespaceHandler.java?rev=907189&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/CmNamespaceHandler.java (added)
+++ geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/CmNamespaceHandler.java Sat Feb 6 08:01:43 2010
@@ -0,0 +1,535 @@
+/*
+ * 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.xbean.blueprint.cm;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.aries.blueprint.ComponentDefinitionRegistry;
+import org.apache.aries.blueprint.NamespaceHandler;
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.aries.blueprint.ext.ExtNamespaceHandler;
+import org.apache.aries.blueprint.ext.PlaceholdersUtils;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.aries.blueprint.mutable.MutableCollectionMetadata;
+import org.apache.aries.blueprint.mutable.MutableComponentMetadata;
+import org.apache.aries.blueprint.mutable.MutableIdRefMetadata;
+import org.apache.aries.blueprint.mutable.MutableMapMetadata;
+import org.apache.aries.blueprint.mutable.MutableRefMetadata;
+import org.apache.aries.blueprint.mutable.MutableReferenceMetadata;
+import org.apache.aries.blueprint.mutable.MutableValueMetadata;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.BeanProperty;
+import org.osgi.service.blueprint.reflect.CollectionMetadata;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.IdRefMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.RefMetadata;
+import org.osgi.service.blueprint.reflect.ReferenceMetadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Modified from aries CmNamespaceHandler
+ *
+ * @version $Rev$ $Date$
+ */
+public class CmNamespaceHandler implements NamespaceHandler {
+
+ public static final String BLUEPRINT_NAMESPACE = "http://www.osgi.org/xmlns/blueprint/v1.0.0";
+ public static final String XBEAN_CM_NAMESPACE = "http://xbean.apache.org/blueprint/xmlns/xbean-cm/v1.0.0";
+
+ public static final String PROPERTY_PLACEHOLDER_ELEMENT = "property-placeholder";
+// public static final String MANAGED_PROPERTIES_ELEMENT = "managed-properties";
+// public static final String MANAGED_SERVICE_FACTORY_ELEMENT = "managed-service-factory";
+ public static final String CM_PROPERTIES_ELEMENT = "cm-properties";
+ public static final String DEFAULT_PROPERTIES_ELEMENT = "default-properties";
+ public static final String PROPERTY_ELEMENT = "property";
+ public static final String INTERFACES_ELEMENT = "interfaces";
+ public static final String VALUE_ELEMENT = "value";
+ public static final String MANAGED_COMPONENT_ELEMENT = "managed-component";
+
+ public static final String ID_ATTRIBUTE = "id";
+ public static final String PERSISTENT_ID_ATTRIBUTE = "persistent-id";
+ public static final String PLACEHOLDER_PREFIX_ATTRIBUTE = "placeholder-prefix";
+ public static final String PLACEHOLDER_SUFFIX_ATTRIBUTE = "placeholder-suffix";
+ public static final String DEFAULTS_REF_ATTRIBUTE = "defaults-ref";
+ public static final String UPDATE_STRATEGY_ATTRIBUTE = "update-strategy";
+ public static final String UPDATE_METHOD_ATTRIBUTE = "update-method";
+ public static final String FACTORY_PID_ATTRIBUTE = "factory-pid";
+ public static final String AUTO_EXPORT_ATTRIBUTE = "auto-export";
+ public static final String RANKING_ATTRIBUTE = "ranking";
+ public static final String INTERFACE_ATTRIBUTE = "interface";
+ public static final String UPDATE_ATTRIBUTE = "update";
+
+ public static final String AUTO_EXPORT_DISABLED = "disabled";
+ public static final String AUTO_EXPORT_INTERFACES = "interfaces";
+ public static final String AUTO_EXPORT_CLASS_HIERARCHY = "class-hierarchy";
+ public static final String AUTO_EXPORT_ALL = "all-classes";
+ public static final String AUTO_EXPORT_DEFAULT = AUTO_EXPORT_DISABLED;
+ public static final String RANKING_DEFAULT = "0";
+
+ private static final String MANAGED_OBJECT_MANAGER_NAME = "org.apache.aries.managedObjectManager";
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CmNamespaceHandler.class);
+
+// private final ConfigurationAdmin configAdmin;
+
+ private int idCounter;
+
+// public CmNamespaceHandler(ConfigurationAdmin configAdmin) {
+// this.configAdmin = configAdmin;
+// }
+
+ public URL getSchemaLocation(String namespace) {
+ return getClass().getResource("xbean-cm.xsd");
+ }
+
+ public Set<Class> getManagedClasses() {
+ return new HashSet<Class>(Arrays.asList(
+ JexlPropertyPlaceholder.class
+ ));
+ }
+
+ public Metadata parse(Element element, ParserContext context) {
+ LOGGER.debug("Parsing element {{}}{}", element.getNamespaceURI(), element.getLocalName());
+ ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
+// registerManagedObjectManager(context, registry);
+ if (nodeNameEquals(element, PROPERTY_PLACEHOLDER_ELEMENT)) {
+ return parsePropertyPlaceholder(context, element);
+// } else if (nodeNameEquals(element, MANAGED_SERVICE_FACTORY_ELEMENT)) {
+// return parseManagedServiceFactory(context, element);
+ } else {
+ throw new ComponentDefinitionException("Unsupported element: " + element.getNodeName());
+ }
+ }
+
+ public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
+ LOGGER.debug("Decorating node {{}}{}", node.getNamespaceURI(), node.getLocalName());
+ ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
+// registerManagedObjectManager(context, registry);
+ if (node instanceof Element) {
+// if (nodeNameEquals(node, MANAGED_PROPERTIES_ELEMENT)) {
+// return decorateManagedProperties(context, (Element) node, component);
+// } else
+// if (nodeNameEquals(node, CM_PROPERTIES_ELEMENT)) {
+// return decorateCmProperties(context, (Element) node, component);
+// } else {
+ throw new ComponentDefinitionException("Unsupported element: " + node.getNodeName());
+// }
+ } else {
+ throw new ComponentDefinitionException("Illegal use of blueprint cm namespace");
+ }
+ }
+
+ private ComponentMetadata parsePropertyPlaceholder(ParserContext context, Element element) {
+ MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
+ metadata.setProcessor(true);
+ metadata.setId(getId(context, element));
+ metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+ metadata.setRuntimeClass(JexlPropertyPlaceholder.class);
+ metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
+// metadata.addProperty("configAdmin", createConfigAdminProxy(context));
+ metadata.addProperty("configAdmin", createReference(context, ConfigurationAdmin.class.getName()));
+ metadata.addProperty("persistentId", createValue(context, element.getAttribute(PERSISTENT_ID_ATTRIBUTE)));
+// metadata.addArgument(createRef(context, "blueprintContainer"), BlueprintContainer.class.getName(), 0);
+// metadata.addArgument(createReference(context, ConfigurationAdmin.class.getName()), ConfigurationAdmin.class.getName(), 1);
+// metadata.addArgument(createValue(context, element.getAttribute(PERSISTENT_ID_ATTRIBUTE)), String.class.getName(), 2);
+ String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
+ ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
+ : "${";
+ metadata.addProperty("placeholderPrefix", createValue(context, prefix));
+ String suffix = element.hasAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE)
+ ? element.getAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE)
+ : "}";
+ metadata.addProperty("placeholderSuffix", createValue(context, suffix));
+ String defaultsRef = element.hasAttribute(DEFAULTS_REF_ATTRIBUTE) ? element.getAttribute(DEFAULTS_REF_ATTRIBUTE) : null;
+ if (defaultsRef != null) {
+ metadata.addProperty("defaultProperties", createRef(context, defaultsRef));
+ }
+ String ignoreMissingLocations = element.hasAttributeNS(ExtNamespaceHandler.BLUEPRINT_EXT_NAMESPACE, ExtNamespaceHandler.IGNORE_MISSING_LOCATIONS_ATTRIBUTE)
+ ? element.getAttributeNS(ExtNamespaceHandler.BLUEPRINT_EXT_NAMESPACE, ExtNamespaceHandler.IGNORE_MISSING_LOCATIONS_ATTRIBUTE) : null;
+ if (ignoreMissingLocations != null) {
+ metadata.addProperty("ignoreMissingLocations", createValue(context, ignoreMissingLocations));
+ }
+ String systemProperties = element.hasAttributeNS(ExtNamespaceHandler.BLUEPRINT_EXT_NAMESPACE, ExtNamespaceHandler.SYSTEM_PROPERTIES_ATTRIBUTE)
+ ? element.getAttributeNS(ExtNamespaceHandler.BLUEPRINT_EXT_NAMESPACE, ExtNamespaceHandler.SYSTEM_PROPERTIES_ATTRIBUTE) : null;
+ if (systemProperties == null) {
+ systemProperties = ExtNamespaceHandler.SYSTEM_PROPERTIES_NEVER;
+ }
+ metadata.addProperty("systemProperties", createValue(context, systemProperties));
+ // Parse elements
+ List<String> locations = new ArrayList<String>();
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node node = nl.item(i);
+ if (node instanceof Element) {
+ Element e = (Element) node;
+ if (XBEAN_CM_NAMESPACE.equals(e.getNamespaceURI())) {
+ if (nodeNameEquals(e, DEFAULT_PROPERTIES_ELEMENT)) {
+ if (defaultsRef != null) {
+ throw new ComponentDefinitionException("Only one of " + DEFAULTS_REF_ATTRIBUTE + " attribute or " + DEFAULT_PROPERTIES_ELEMENT + " element is allowed");
+ }
+ Metadata props = parseDefaultProperties(context, metadata, e);
+ metadata.addProperty("defaultProperties", props);
+ }
+ } else if (ExtNamespaceHandler.BLUEPRINT_EXT_NAMESPACE.equals(e.getNamespaceURI())) {
+ if (nodeNameEquals(e, ExtNamespaceHandler.LOCATION_ELEMENT)) {
+ locations.add(getTextValue(e));
+ }
+ }
+ }
+ }
+ if (!locations.isEmpty()) {
+ metadata.addProperty("locations", createList(context, locations));
+ }
+
+// PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
+
+ return metadata;
+ }
+
+ private Metadata parseDefaultProperties(ParserContext context, MutableBeanMetadata enclosingComponent, Element element) {
+ MutableMapMetadata props = context.createMetadata(MutableMapMetadata.class);
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node node = nl.item(i);
+ if (node instanceof Element) {
+ Element e = (Element) node;
+ if (XBEAN_CM_NAMESPACE.equals(e.getNamespaceURI())) {
+ if (nodeNameEquals(e, PROPERTY_ELEMENT)) {
+ BeanProperty prop = context.parseElement(BeanProperty.class, enclosingComponent, e);
+ props.addEntry(createValue(context, prop.getName(), String.class.getName()), prop.getValue());
+ }
+ }
+ }
+ }
+ return props;
+ }
+
+// private ComponentMetadata parseManagedServiceFactory(ParserContext context, Element element) {
+// String id = getId(context, element);
+//
+// MutableBeanMetadata factoryMetadata = context.createMetadata(MutableBeanMetadata.class);
+// generateIdIfNeeded(context, factoryMetadata);
+// factoryMetadata.addProperty("id", createValue(context, factoryMetadata.getId()));
+// factoryMetadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+// factoryMetadata.setRuntimeClass(CmManagedServiceFactory.class);
+// factoryMetadata.setInitMethod("init");
+// factoryMetadata.setDestroyMethod("destroy");
+// factoryMetadata.addProperty("configAdmin", createConfigAdminProxy(context));
+// factoryMetadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
+// factoryMetadata.addProperty("factoryPid", createValue(context, element.getAttribute(FACTORY_PID_ATTRIBUTE)));
+// String autoExport = element.hasAttribute(AUTO_EXPORT_ATTRIBUTE) ? element.getAttribute(AUTO_EXPORT_ATTRIBUTE) : AUTO_EXPORT_DEFAULT;
+// if (AUTO_EXPORT_DISABLED.equals(autoExport)) {
+// autoExport = Integer.toString(ServiceMetadata.AUTO_EXPORT_DISABLED);
+// } else if (AUTO_EXPORT_INTERFACES.equals(autoExport)) {
+// autoExport = Integer.toString(ServiceMetadata.AUTO_EXPORT_INTERFACES);
+// } else if (AUTO_EXPORT_CLASS_HIERARCHY.equals(autoExport)) {
+// autoExport = Integer.toString(ServiceMetadata.AUTO_EXPORT_CLASS_HIERARCHY);
+// } else if (AUTO_EXPORT_ALL.equals(autoExport)) {
+// autoExport = Integer.toString(ServiceMetadata.AUTO_EXPORT_ALL_CLASSES);
+// } else {
+// throw new ComponentDefinitionException("Illegal value (" + autoExport + ") for " + AUTO_EXPORT_ATTRIBUTE + " attribute");
+// }
+// factoryMetadata.addProperty("autoExport", createValue(context, autoExport));
+// String ranking = element.hasAttribute(RANKING_ATTRIBUTE) ? element.getAttribute(RANKING_ATTRIBUTE) : RANKING_DEFAULT;
+// factoryMetadata.addProperty("ranking", createValue(context, ranking));
+//
+// List<String> interfaces = null;
+// if (element.hasAttribute(INTERFACE_ATTRIBUTE)) {
+// interfaces = Collections.singletonList(element.getAttribute(INTERFACE_ATTRIBUTE));
+// factoryMetadata.addProperty("interfaces", createList(context, interfaces));
+// }
+//
+// Parser parser = getParser(context);
+//
+// // Parse elements
+// List<RegistrationListener> listeners = new ArrayList<RegistrationListener>();
+// NodeList nl = element.getChildNodes();
+// for (int i = 0; i < nl.getLength(); i++) {
+// Node node = nl.item(i);
+// if (node instanceof Element) {
+// Element e = (Element) node;
+// if (isBlueprintNamespace(e.getNamespaceURI())) {
+// if (nodeNameEquals(e, INTERFACES_ELEMENT)) {
+// if (interfaces != null) {
+// throw new ComponentDefinitionException("Only one of " + Parser.INTERFACE_ATTRIBUTE + " attribute or " + INTERFACES_ELEMENT + " element must be used");
+// }
+// interfaces = parseInterfaceNames(e);
+// factoryMetadata.addProperty("interfaces", createList(context, interfaces));
+// } else if (nodeNameEquals(e, Parser.SERVICE_PROPERTIES_ELEMENT)) {
+// MapMetadata map = parser.parseServiceProperties(e, factoryMetadata);
+// factoryMetadata.addProperty("serviceProperties", map);
+// } else if (nodeNameEquals(e, Parser.REGISTRATION_LISTENER_ELEMENT)) {
+// listeners.add(parser.parseRegistrationListener(e, factoryMetadata));
+// }
+// } else if (XBEAN_CM_NAMESPACE.equals(e.getNamespaceURI())) {
+// if (nodeNameEquals(e, MANAGED_COMPONENT_ELEMENT)) {
+// MutableBeanMetadata managedComponent = context.parseElement(MutableBeanMetadata.class, null, e);
+// generateIdIfNeeded(context, managedComponent);
+// managedComponent.setScope(BeanMetadata.SCOPE_PROTOTYPE);
+// // destroy-method on managed-component has different signature than on regular beans
+// // so we'll handle it differently
+// String destroyMethod = managedComponent.getDestroyMethod();
+// if (destroyMethod != null) {
+// factoryMetadata.addProperty("componentDestroyMethod", createValue(context, destroyMethod));
+// managedComponent.setDestroyMethod(null);
+// }
+// context.getComponentDefinitionRegistry().registerComponentDefinition(managedComponent);
+// factoryMetadata.addProperty("managedComponentName", createIdRef(context, managedComponent.getId()));
+// }
+// }
+// }
+// }
+//
+// MutableCollectionMetadata listenerCollection = context.createMetadata(MutableCollectionMetadata.class);
+// listenerCollection.setCollectionClass(List.class);
+// for (RegistrationListener listener : listeners) {
+// MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
+// bean.setRuntimeClass(ServiceListener.class);
+// bean.addProperty("listener", listener.getListenerComponent());
+// bean.addProperty("registerMethod", createValue(context, listener.getRegistrationMethod()));
+// bean.addProperty("unregisterMethod", createValue(context, listener.getUnregistrationMethod()));
+// listenerCollection.addValue(bean);
+// }
+// factoryMetadata.addProperty("listeners", listenerCollection);
+//
+// context.getComponentDefinitionRegistry().registerComponentDefinition(factoryMetadata);
+//
+// MutableBeanMetadata mapMetadata = context.createMetadata(MutableBeanMetadata.class);
+// mapMetadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+// mapMetadata.setId(id);
+// mapMetadata.setFactoryComponent(createRef(context, factoryMetadata.getId()));
+// mapMetadata.setFactoryMethod("getServiceMap");
+// return mapMetadata;
+// }
+
+// private ComponentMetadata decorateCmProperties(ParserContext context, Element element, ComponentMetadata component) {
+// generateIdIfNeeded(context, ((MutableComponentMetadata) component));
+// MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
+// metadata.setProcessor(true);
+// metadata.setId(getId(context, element));
+// metadata.setRuntimeClass(CmProperties.class);
+// String persistentId = element.getAttribute(PERSISTENT_ID_ATTRIBUTE);
+// // if persistentId is "" the cm-properties element in nested in managed-service-factory
+// // and the configuration object will come from the factory. So we only really need to register
+// // ManagedService if the persistentId is not an empty string.
+// if (persistentId.length() > 0) {
+// metadata.setInitMethod("init");
+// metadata.setDestroyMethod("destroy");
+// }
+// metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
+// metadata.addProperty("configAdmin", createConfigAdminProxy(context));
+// metadata.addProperty("managedObjectManager", createRef(context, MANAGED_OBJECT_MANAGER_NAME));
+// metadata.addProperty("persistentId", createValue(context, persistentId));
+// if (element.hasAttribute(UPDATE_ATTRIBUTE)) {
+// metadata.addProperty("update", createValue(context, element.getAttribute(UPDATE_ATTRIBUTE)));
+// }
+// metadata.addProperty("serviceId", createIdRef(context, component.getId()));
+// context.getComponentDefinitionRegistry().registerComponentDefinition(metadata);
+// return component;
+// }
+
+// private ComponentMetadata decorateManagedProperties(ParserContext context, Element element, ComponentMetadata component) {
+// if (!(component instanceof MutableBeanMetadata)) {
+// throw new ComponentDefinitionException("Element " + MANAGED_PROPERTIES_ELEMENT + " must be used inside a <bp:bean> element");
+// }
+// generateIdIfNeeded(context, ((MutableBeanMetadata) component));
+// MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
+// metadata.setProcessor(true);
+// metadata.setId(getId(context, element));
+// metadata.setRuntimeClass(CmManagedProperties.class);
+// String persistentId = element.getAttribute(PERSISTENT_ID_ATTRIBUTE);
+// // if persistentId is "" the managed properties element in nested in managed-service-factory
+// // and the configuration object will come from the factory. So we only really need to register
+// // ManagedService if the persistentId is not an empty string.
+// if (persistentId.length() > 0) {
+// metadata.setInitMethod("init");
+// metadata.setDestroyMethod("destroy");
+// }
+// metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
+// metadata.addProperty("configAdmin", createConfigAdminProxy(context));
+// metadata.addProperty("managedObjectManager", createRef(context, MANAGED_OBJECT_MANAGER_NAME));
+// metadata.addProperty("persistentId", createValue(context, persistentId));
+// String updateStrategy = element.getAttribute(UPDATE_STRATEGY_ATTRIBUTE);
+// if (updateStrategy != null) {
+// metadata.addProperty("updateStrategy", createValue(context, updateStrategy));
+// }
+// if (element.hasAttribute(UPDATE_METHOD_ATTRIBUTE)) {
+// metadata.addProperty("updateMethod", createValue(context, element.getAttribute(UPDATE_METHOD_ATTRIBUTE)));
+// } else if ("component-managed".equals(updateStrategy)) {
+// throw new ComponentDefinitionException(UPDATE_METHOD_ATTRIBUTE + " attribute must be set when " + UPDATE_STRATEGY_ATTRIBUTE + " is set to 'component-managed'");
+// }
+// metadata.addProperty("beanName", createIdRef(context, component.getId()));
+// context.getComponentDefinitionRegistry().registerComponentDefinition(metadata);
+// return component;
+// }
+
+ /**
+ * Create a reference to the ConfigurationAdmin service if not already done
+ * and add it to the registry.
+ *
+ * @param context the parser context
+ * @return a metadata pointing to the config admin
+ */
+ private Metadata createConfigAdminProxy(ParserContext context) {
+ MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
+ bean.setRuntimeClass(CmNamespaceHandler.class);
+ bean.setFactoryMethod("getConfigAdmin");
+ bean.setActivation(MutableBeanMetadata.ACTIVATION_LAZY);
+ bean.setScope(MutableBeanMetadata.SCOPE_PROTOTYPE);
+ return bean;
+ }
+
+// private void registerManagedObjectManager(ParserContext context, ComponentDefinitionRegistry registry) {
+// if (registry.getComponentDefinition(MANAGED_OBJECT_MANAGER_NAME) == null) {
+// MutableBeanMetadata beanMetadata = context.createMetadata(MutableBeanMetadata.class);
+// beanMetadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+// beanMetadata.setId(MANAGED_OBJECT_MANAGER_NAME);
+// beanMetadata.setRuntimeClass(ManagedObjectManager.class);
+// registry.registerComponentDefinition(beanMetadata);
+// }
+// }
+
+ private static ValueMetadata createValue(ParserContext context, String value) {
+ return createValue(context, value, null);
+ }
+
+ private static ValueMetadata createValue(ParserContext context, String value, String type) {
+ MutableValueMetadata m = context.createMetadata(MutableValueMetadata.class);
+ m.setStringValue(value);
+ m.setType(type);
+ return m;
+ }
+
+ private static RefMetadata createRef(ParserContext context, String value) {
+ MutableRefMetadata m = context.createMetadata(MutableRefMetadata.class);
+ m.setComponentId(value);
+ return m;
+ }
+ private static ReferenceMetadata createReference(ParserContext context, String interfaceName) {
+ MutableReferenceMetadata m = context.createMetadata(MutableReferenceMetadata.class);
+ m.setInterface(interfaceName);
+ return m;
+ }
+
+ private static IdRefMetadata createIdRef(ParserContext context, String value) {
+ MutableIdRefMetadata m = context.createMetadata(MutableIdRefMetadata.class);
+ m.setComponentId(value);
+ return m;
+ }
+
+ private static CollectionMetadata createList(ParserContext context, List<String> list) {
+ MutableCollectionMetadata m = context.createMetadata(MutableCollectionMetadata.class);
+ m.setCollectionClass(List.class);
+ m.setValueType(String.class.getName());
+ for (String v : list) {
+ m.addValue(createValue(context, v, String.class.getName()));
+ }
+ return m;
+ }
+
+ private static String getTextValue(Element element) {
+ StringBuffer value = new StringBuffer();
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node item = nl.item(i);
+ if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
+ value.append(item.getNodeValue());
+ }
+ }
+ return value.toString();
+ }
+
+ private static boolean nodeNameEquals(Node node, String name) {
+ return (name.equals(node.getNodeName()) || name.equals(node.getLocalName()));
+ }
+
+ public static boolean isBlueprintNamespace(String ns) {
+ return BLUEPRINT_NAMESPACE.equals(ns);
+ }
+
+ public String getId(ParserContext context, Element element) {
+ if (element.hasAttribute(ID_ATTRIBUTE)) {
+ return element.getAttribute(ID_ATTRIBUTE);
+ } else {
+ return generateId(context);
+ }
+ }
+
+ public void generateIdIfNeeded(ParserContext context, MutableComponentMetadata metadata) {
+ if (metadata.getId() == null) {
+ metadata.setId(generateId(context));
+ }
+ }
+
+ private String generateId(ParserContext context) {
+ String id;
+ do {
+ id = ".cm-" + ++idCounter;
+ } while (context.getComponentDefinitionRegistry().containsComponentDefinition(id));
+ return id;
+ }
+
+// private Parser getParser(ParserContext ctx) {
+// if (ctx instanceof ParserContextImpl) {
+// return ((ParserContextImpl) ctx).getParser();
+// }
+// throw new RuntimeException("Unable to get parser");
+// }
+
+ public List<String> parseInterfaceNames(Element element) {
+ List<String> interfaceNames = new ArrayList<String>();
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node node = nl.item(i);
+ if (node instanceof Element) {
+ Element e = (Element) node;
+ if (nodeNameEquals(e, VALUE_ELEMENT)) {
+ String v = getTextValue(e).trim();
+ if (interfaceNames.contains(v)) {
+ throw new ComponentDefinitionException("The element " + INTERFACES_ELEMENT + " should not contain the same interface twice");
+ }
+ interfaceNames.add(getTextValue(e));
+ } else {
+ throw new ComponentDefinitionException("Unsupported element " + e.getNodeName() + " inside an " + INTERFACES_ELEMENT + " element");
+ }
+ }
+ }
+ return interfaceNames;
+ }
+
+}
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/CmNamespaceHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/CmNamespaceHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/CmNamespaceHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlExpressionParser.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlExpressionParser.java?rev=907189&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlExpressionParser.java (added)
+++ geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlExpressionParser.java Sat Feb 6 08:01:43 2010
@@ -0,0 +1,149 @@
+/*
+ * 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.xbean.blueprint.cm;
+
+import java.util.Map;
+
+import org.apache.commons.jexl2.JexlContext;
+import org.apache.commons.jexl2.JexlEngine;
+import org.apache.commons.jexl2.MapContext;
+import org.apache.commons.jexl2.UnifiedJEXL;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JexlExpressionParser {
+ private static final Logger log = LoggerFactory.getLogger(JexlExpressionParser.class);
+
+ private final JexlEngine engine;
+ private final UnifiedJEXL jexl;
+ protected final JexlContext context;
+
+ public JexlExpressionParser(final Map<String, Object> vars) {
+ if (vars == null) {
+ throw new IllegalArgumentException("vars");
+ }
+ engine = new JexlEngine();
+ jexl = new UnifiedJEXL(engine);
+ context = new MapContext(vars);
+
+ log.trace("Using variables: {}", vars);
+ }
+
+// private FlatResolver resolver = new FlatResolver(true);
+//
+// protected Expression createExpression(final String expression) throws Exception {
+// // assert expression != null;
+//
+// Expression expr = engine.createExpression(expression);
+// expr.addPreResolver(resolver);
+//
+// return expr;
+// }
+
+ public Object evaluate(final String expression) throws Exception {
+ if (expression == null) {
+ throw new IllegalArgumentException("expression");
+ }
+
+ log.trace("Evaluating expression: {}", expression);
+ return jexl.parse(expression).evaluate(context);
+// Expression expr = createExpression(expression);
+// Object obj = expr.evaluate(context);
+// log.trace("Result: {}", obj);
+//
+// return obj;
+ }
+
+// public String parse(final String input) {
+// if (input == null) {
+// throw new IllegalArgumentException("input");
+// }
+//
+// log.trace("Parsing input: {}", input);
+//
+// StringBuilder buff = new StringBuilder();
+//
+// int cur = 0;
+// int prefixLoc;
+// int suffixLoc;
+//
+// while (cur < input.length()) {
+// prefixLoc = input.indexOf("${", cur);
+//
+// if (prefixLoc < 0) {
+// break;
+// }
+//
+// suffixLoc = findBlockEnd(prefixLoc + 2, input);
+// if (suffixLoc < 0) {
+// throw new RuntimeException("Missing '}': " + input);
+// }
+//
+// String expr = input.substring(prefixLoc + 2, suffixLoc);
+// buff.append(input.substring(cur, prefixLoc));
+//
+// try {
+// buff.append(evaluate(expr));
+// }
+// catch (Exception e) {
+// throw new RuntimeException("Failed to evaluate: " + expr, e);
+// }
+//
+// cur = suffixLoc + 1;
+// }
+//
+// buff.append(input.substring(cur));
+//
+// log.trace("Parsed result: {}", buff);
+//
+// return buff.toString();
+// }
+
+// private int findBlockEnd(int pos, String input) {
+// int nested = 0;
+// while (pos < input.length()) {
+// char ch = input.charAt(pos);
+// if (ch == '{') {
+// nested++;
+// } else if (ch == '}') {
+// if (nested == 0) {
+// return pos;
+// } else {
+// nested--;
+// }
+// }
+// pos++;
+// }
+// return -1;
+// }
+
+// public String parse(final String input, final boolean trim) {
+// String output = parse(input);
+// if (trim && output != null) {
+// output = output.trim();
+// }
+//
+// return output;
+// }
+}
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlExpressionParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlExpressionParser.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlExpressionParser.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlPropertyPlaceholder.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlPropertyPlaceholder.java?rev=907189&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlPropertyPlaceholder.java (added)
+++ geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlPropertyPlaceholder.java Sat Feb 6 08:01:43 2010
@@ -0,0 +1,138 @@
+/*
+ * 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.xbean.blueprint.cm;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.aries.blueprint.compendium.cm.CmPropertyPlaceholder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JexlPropertyPlaceholder extends CmPropertyPlaceholder {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(JexlPropertyPlaceholder.class);
+
+ private transient JexlExpressionParser parser;
+
+ @Override
+ protected String processString(String str) {
+ LOGGER.debug("Processing {} from configuration with pid {}", str, getPersistentId());
+ JexlExpressionParser parser = getParser();
+ try {
+ return parser.evaluate(str).toString();
+ } catch (Exception e) {
+ LOGGER.info("Could not evaluate expressions {} for {}", str, getPersistentId());
+ LOGGER.info("Exception:", e);
+ }
+ return str;
+ }
+
+ protected synchronized JexlExpressionParser getParser() {
+ if (parser == null) {
+// try {
+ parser = new JexlExpressionParser(toMap());
+// } catch (IOException e) {
+ // ignore
+// }
+ }
+ return parser;
+ }
+
+ private Map<String, Object> toMap() {
+ return new ConfigMap();
+// Map<String, Object> map = new HashMap<String, Object>();
+// if (config != null) {
+// Dictionary<String, Object> properties = config.getProperties();
+// for (Enumeration<String> e = properties.keys(); e.hasMoreElements(); ) {
+// String key = e.nextElement();
+// Object value = properties.get(key);
+// map.put(key, value);
+// }
+// }
+// return map;
+ }
+
+ private class ConfigMap implements Map<String, Object> {
+
+ @Override
+ public int size() {
+ return 0;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return false;
+ }
+
+ @Override
+ public boolean containsKey(Object o) {
+ return getProperty((String) o) != null;
+ }
+
+ @Override
+ public boolean containsValue(Object o) {
+ return false;
+ }
+
+ @Override
+ public Object get(Object o) {
+ return getProperty((String) o);
+ }
+
+ @Override
+ public Object put(String s, Object o) {
+ return null;
+ }
+
+ @Override
+ public Object remove(Object o) {
+ return null;
+ }
+
+ @Override
+ public void putAll(Map<? extends String, ? extends Object> map) {
+ }
+
+ @Override
+ public void clear() {
+ }
+
+ @Override
+ public Set<String> keySet() {
+ return null;
+ }
+
+ @Override
+ public Collection<Object> values() {
+ return null;
+ }
+
+ @Override
+ public Set<Entry<String, Object>> entrySet() {
+ return null;
+ }
+ }
+}
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlPropertyPlaceholder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlPropertyPlaceholder.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/cm/JexlPropertyPlaceholder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/XBeanNamespaceHandler.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/XBeanNamespaceHandler.java?rev=907189&r1=907188&r2=907189&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/XBeanNamespaceHandler.java (original)
+++ geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/XBeanNamespaceHandler.java Sat Feb 6 08:01:43 2010
@@ -53,6 +53,8 @@
import org.osgi.service.blueprint.reflect.Metadata;
import org.osgi.service.blueprint.reflect.NonNullMetadata;
import org.osgi.service.blueprint.reflect.NullMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -64,6 +66,8 @@
*/
public class XBeanNamespaceHandler implements NamespaceHandler {
+ private static final Logger LOGGER = LoggerFactory.getLogger(XBeanNamespaceHandler.class);
+
public static final String BLUEPRINT_NAMESPACE = "http://www.osgi.org/xmlns/blueprint/v1.0.0";
private static final String BEAN_REFERENCE_PREFIX = "#";
private static final String NULL_REFERENCE = "#null";
@@ -123,27 +127,37 @@
this.mappingMetaData = new MappingMetaData(properties);
}
- private static Set<Class> managedClassesFromProperties(ClassLoader cl, Properties properties) throws ClassNotFoundException {
+ private static Set<Class> managedClassesFromProperties(ClassLoader cl, Properties properties) {
Set<Class> managedClasses = new HashSet<Class>();
for (Map.Entry entry : properties.entrySet()) {
String key = (String) entry.getKey();
if (key.indexOf(".") < 0) {
String className = (String) entry.getValue();
- Class clazz = cl.loadClass(className);
- managedClasses.add(clazz);
+ try {
+ managedClasses.add(cl.loadClass(className));
+ } catch (NoClassDefFoundError e) {
+ LOGGER.warn("Could not load class: {} due to {}",className, e.getMessage());
+ } catch (ClassNotFoundException e) {
+ LOGGER.warn("Could not load class: {}", className);
+ }
}
}
return managedClasses;
}
- private static Set<Class> managedClassesFromProperties(Bundle bundle, Properties properties) throws ClassNotFoundException {
+ private static Set<Class> managedClassesFromProperties(Bundle bundle, Properties properties) {
Set<Class> managedClasses = new HashSet<Class>();
for (Map.Entry entry : properties.entrySet()) {
String key = (String) entry.getKey();
if (key.indexOf(".") < 0) {
String className = (String) entry.getValue();
- Class clazz = bundle.loadClass(className);
- managedClasses.add(clazz);
+ try {
+ managedClasses.add(bundle.loadClass(className));
+ } catch (NoClassDefFoundError e) {
+ LOGGER.warn("Could not load class: {} due to {}",className, e.getMessage());
+ } catch (ClassNotFoundException e) {
+ LOGGER.warn("Could not load class: {}", className);
+ }
}
}
return managedClasses;
@@ -205,6 +219,8 @@
private Metadata parseInternal(Element element, ParserContext parserContext, String beanTypeName, String className) {
MutableBeanMetadata beanMetaData = parserContext.createMetadata(MutableBeanMetadata.class);
beanMetaData.setClassName(className);
+ beanMetaData.setScope(BeanMetadata.SCOPE_SINGLETON);
+ beanMetaData.setActivation(BeanMetadata.ACTIVATION_EAGER);
beanMetaData.setRuntimeClass(managedClassesByName.get(className));
if (beanMetaData.getRuntimeClass() == null) {
throw new ComponentDefinitionException("Unknown bean class: " + className);
Modified: geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/generator/Type.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/generator/Type.java?rev=907189&r1=907188&r2=907189&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/generator/Type.java (original)
+++ geronimo/xbean/trunk/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/generator/Type.java Sat Feb 6 08:01:43 2010
@@ -40,7 +40,7 @@
public static Type newArrayType(String type, int dimensions) {
if (type == null) throw new NullPointerException("type");
- if (dimensions < 1) throw new IllegalArgumentException("dimensions must be atleast one");
+ if (dimensions < 1) throw new IllegalArgumentException("dimensions must be at least one");
StringBuffer buf = new StringBuffer(type.length() + (dimensions * 2));
buf.append(type);
for (int i = 0; i < dimensions; i ++) {
@@ -85,10 +85,10 @@
return super.equals(obj);
}
- private static final Set primitives;
+ private static final Set<String> primitives;
static {
- Set set = new HashSet();
+ Set<String> set = new HashSet<String>();
set.add("boolean");
set.add("byte");
set.add("char");
Added: geronimo/xbean/trunk/xbean-blueprint/src/main/resources/OSGI-INF/blueprint/xbean-cm.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-blueprint/src/main/resources/OSGI-INF/blueprint/xbean-cm.xml?rev=907189&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-blueprint/src/main/resources/OSGI-INF/blueprint/xbean-cm.xml (added)
+++ geronimo/xbean/trunk/xbean-blueprint/src/main/resources/OSGI-INF/blueprint/xbean-cm.xml Sat Feb 6 08:01:43 2010
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<!--
+
+ blueprint configuration for xbean ncm jexl amespace handler
+
+-->
+
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <service interface="org.apache.aries.blueprint.NamespaceHandler">
+ <service-properties>
+ <entry key="osgi.service.blueprint.namespace" value="http://xbean.apache.org/blueprint/xmlns/xbean-cm/v1.0.0"/>
+ </service-properties>
+ <bean class="org.apache.xbean.blueprint.cm.CmNamespaceHandler">
+ </bean>
+ </service>
+
+</blueprint>
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/resources/OSGI-INF/blueprint/xbean-cm.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/resources/OSGI-INF/blueprint/xbean-cm.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/resources/OSGI-INF/blueprint/xbean-cm.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: geronimo/xbean/trunk/xbean-blueprint/src/main/resources/org/apache/xbean/blueprint/cm/xbean-cm.xsd
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-blueprint/src/main/resources/org/apache/xbean/blueprint/cm/xbean-cm.xsd?rev=907189&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-blueprint/src/main/resources/org/apache/xbean/blueprint/cm/xbean-cm.xsd (added)
+++ geronimo/xbean/trunk/xbean-blueprint/src/main/resources/org/apache/xbean/blueprint/cm/xbean-cm.xsd Sat Feb 6 08:01:43 2010
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ /*
+ * $Revision$
+ *
+ * Copyright (c) OSGi Alliance (2008, 2009). All Rights Reserved.
+ *
+ * Licensed 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.
+ */
+ -->
+
+ <!-- copied from aries. Most of this is unimplemented in xbean -->
+<xsd:schema xmlns="http://xbean.apache.org/blueprint/xmlns/xbean-cm/v1.0.0"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ targetNamespace="http://xbean.apache.org/blueprint/xmlns/xbean-cm/v1.0.0"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified"
+ version="1.0.0">
+
+ <xsd:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0" />
+
+ <!-- property placeholder -->
+
+ <xsd:element name="property-placeholder" type="TpropertyPlaceholder"/>
+
+ <xsd:complexType name="TpropertyPlaceholder">
+ <xsd:complexContent>
+ <xsd:extension base="bp:Tcomponent">
+ <xsd:sequence>
+ <!-- nested properties declaration -->
+ <xsd:element name="default-properties" type="TdefaultProperties" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="location" minOccurs="0" maxOccurs="unbounded" type="xsd:string"/>
+ </xsd:sequence>
+
+ <!-- #### What should be the type for a persistent id? I think we need to define one like class and method -->
+ <xsd:attribute name="persistent-id" type="xsd:string" use="required"/>
+ <xsd:attribute name="placeholder-prefix" type="xsd:string" use="optional" default="${"/>
+ <xsd:attribute name="placeholder-suffix" type="xsd:string" use="optional" default="}"/>
+ <xsd:attribute name="defaults-ref" type="bp:Tidref" use="optional"/>
+ <xsd:attribute name="ignore-missing-locations" type="xsd:boolean" use="optional" default="false"/>
+ <xsd:attribute name="system-properties" use="optional" default="fallback">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:NMTOKEN">
+ <xsd:enumeration value="never"/>
+ <xsd:enumeration value="fallback"/>
+ <xsd:enumeration value="override"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:attribute>
+ </xsd:extension>
+ </xsd:complexContent>
+ </xsd:complexType>
+
+
+ <!-- #### is this the correct type here? This is defining placeholder properties,
+ so should this be a restricted set of value types or should this be expanded to
+ all of the elements you can inject into a bean property? -->
+ <xsd:complexType name="TdefaultProperties">
+ <xsd:sequence minOccurs="0" maxOccurs="unbounded">
+ <xsd:element name="property" type="bp:Tproperty"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+
+ <!-- managed-properties -->
+
+ <xsd:element name="managed-properties" type="TmanagedProperties"/>
+
+ <xsd:complexType name="TmanagedProperties">
+ <xsd:attribute name="persistent-id" type="xsd:string" use="required"/>
+ <xsd:attribute name="update-strategy" type="TupdateStrategyType" use="optional"/>
+ <xsd:attribute name="update-method" type="xsd:string" use="optional"/>
+ </xsd:complexType>
+
+ <xsd:simpleType name="TupdateStrategyType">
+ <xsd:restriction base="xsd:NMTOKEN">
+ <xsd:enumeration value="none"/>
+ <xsd:enumeration value="component-managed"/>
+ <xsd:enumeration value="container-managed"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <!-- managed-service-factory -->
+
+ <xsd:element name="managed-service-factory" type="TmanagedServiceFactory"/>
+
+ <xsd:complexType name="TmanagedServiceFactory">
+ <xsd:complexContent>
+ <xsd:extension base="bp:Tcomponent">
+ <xsd:sequence>
+ <xsd:group ref="bp:GbaseServiceElements"/>
+ <xsd:element name="managed-component" type="TmanagedComponent" minOccurs="1" maxOccurs="1"/>
+ </xsd:sequence>
+ <xsd:attribute name="interface" type="bp:Tclass" use="optional" />
+ <xsd:attribute name="ref" type="bp:Tidref" use="optional" />
+ <xsd:attribute name="auto-export" type="bp:TautoExportModes" default="disabled" />
+ <xsd:attribute name="ranking" type="xsd:int" default="0"/>
+ <xsd:attribute name="factory-pid" type="xsd:string" use="required"/>
+ <xsd:anyAttribute namespace="##other" processContents="strict"/>
+ </xsd:extension>
+ </xsd:complexContent>
+ </xsd:complexType>
+
+ <xsd:complexType name="TmanagedComponent">
+ <xsd:group ref="bp:GbeanElements"/>
+ <xsd:attribute name="class" type="bp:Tclass"/>
+ <xsd:attribute name="init-method" type="bp:Tmethod"/>
+ <xsd:attribute name="destroy-method" type="bp:Tmethod"/>
+ <xsd:attribute name="factory-method" type="bp:Tmethod"/>
+ <xsd:attribute name="factory-component" type="bp:Tidref"/>
+ <xsd:anyAttribute namespace="##other" processContents="strict"/>
+ </xsd:complexType>
+
+
+ <!-- cm-properties -->
+
+ <xsd:element name="cm-properties" type="TcmProperties"/>
+
+ <xsd:complexType name="TcmProperties">
+ <xsd:attribute name="persistent-id" type="xsd:string" use="required"/>
+ <xsd:attribute name="update" type="xsd:boolean" use="optional" default="false"/>
+ </xsd:complexType>
+
+</xsd:schema>
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/resources/org/apache/xbean/blueprint/cm/xbean-cm.xsd
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/resources/org/apache/xbean/blueprint/cm/xbean-cm.xsd
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/main/resources/org/apache/xbean/blueprint/cm/xbean-cm.xsd
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: geronimo/xbean/trunk/xbean-blueprint/src/test/java/org/apache/xbean/blueprint/context/impl/JexlTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-blueprint/src/test/java/org/apache/xbean/blueprint/context/impl/JexlTest.java?rev=907189&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-blueprint/src/test/java/org/apache/xbean/blueprint/context/impl/JexlTest.java (added)
+++ geronimo/xbean/trunk/xbean-blueprint/src/test/java/org/apache/xbean/blueprint/context/impl/JexlTest.java Sat Feb 6 08:01:43 2010
@@ -0,0 +1,46 @@
+/*
+ * 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.xbean.blueprint.context.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+import org.apache.xbean.blueprint.cm.JexlExpressionParser;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JexlTest extends TestCase {
+
+ public void testJexl() throws Exception {
+ Map<String, Object> vars = new HashMap<String, Object> ();
+ vars.put("foo", 1);
+ vars.put("bar", 2);
+ JexlExpressionParser parser = new JexlExpressionParser(vars);
+ assertEquals(3, parser.evaluate("${foo + bar}"));
+
+ vars.put("ServerHostname", "localhost");
+ vars.put("ActiveMQPort", 63636);
+ vars.put("PortOffset", 10);
+ assertEquals("tcp://localhost:63646", parser.evaluate("tcp://${ServerHostname}:${ActiveMQPort + PortOffset}"));
+ }
+}
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/test/java/org/apache/xbean/blueprint/context/impl/JexlTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/test/java/org/apache/xbean/blueprint/context/impl/JexlTest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/xbean/trunk/xbean-blueprint/src/test/java/org/apache/xbean/blueprint/context/impl/JexlTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain