You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ga...@apache.org on 2010/06/16 02:52:47 UTC
svn commit: r955102 [7/10] - in /incubator/aries/trunk/jpa: ./ jpa-api/
jpa-api/src/main/java/org/apache/aries/jpa/container/
jpa-api/src/main/java/org/apache/aries/jpa/container/context/
jpa-api/src/main/java/org/apache/aries/jpa/container/parsing/ jp...
Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/PersistenceUnitImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/PersistenceUnitImpl.java?rev=955102&r1=955101&r2=955102&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/PersistenceUnitImpl.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/PersistenceUnitImpl.java Wed Jun 16 00:52:45 2010
@@ -1,208 +1,208 @@
-/*
- * 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 WARRANTIESOR 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.aries.jpa.container.parsing.impl;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceReference;
-
-/**
- * An implementation of PersistenceUnit for parsed persistence unit metadata
- *
- */
-@SuppressWarnings("unchecked")
-public class PersistenceUnitImpl implements ParsedPersistenceUnit
-{
- /** A map to hold the metadata from the xml */
- private final Map<String,Object> metadata = new HashMap<String, Object>();
- /** The bundle defining this persistence unit */
- private final Bundle bundle;
-
- /**
- * The Service Reference for the provider to which this persistence
- * unit is tied
- */
- private ServiceReference provider;
-
-
- /**
- * Create a new persistence unit with the given name, transaction type, location and
- * defining bundle
- *
- * @param name may be null
- * @param transactionType may be null
- * @param location
- * @param version The version of the JPA schema used in persistence.xml
- */
- public PersistenceUnitImpl(Bundle b, String name, String transactionType, String version)
- {
- this.bundle = b;
- metadata.put(SCHEMA_VERSION, version);
-
- if (name == null)
- name = "";
-
- metadata.put(UNIT_NAME, name);
- if (transactionType != null) metadata.put(TRANSACTION_TYPE, transactionType);
-
- }
-
-
- public Bundle getDefiningBundle()
- {
- return bundle;
- }
-
- public Map<String, Object> getPersistenceXmlMetadata()
- {
- Map<String, Object> data = new HashMap<String, Object>(metadata);
- if(data.containsKey(MAPPING_FILES))
- data.put(MAPPING_FILES, ((ArrayList) metadata.get(MAPPING_FILES)).clone());
- if(data.containsKey(JAR_FILES))
- data.put(JAR_FILES, ((ArrayList) metadata.get(JAR_FILES)).clone());
- if(data.containsKey(MANAGED_CLASSES))
- data.put(MANAGED_CLASSES, ((ArrayList) metadata.get(MANAGED_CLASSES)).clone());
- if(data.containsKey(PROPERTIES))
- data.put(PROPERTIES, ((Properties)metadata.get(PROPERTIES)).clone());
-
- return data;
- }
-
- /**
- * @param provider
- */
- public void setProviderClassName(String provider)
- {
- metadata.put(PROVIDER_CLASSNAME, provider);
- }
-
- /**
- * @param jtaDataSource
- */
- public void setJtaDataSource(String jtaDataSource)
- {
- metadata.put(JTA_DATASOURCE, jtaDataSource);
- }
-
- /**
- * @param nonJtaDataSource
- */
- public void setNonJtaDataSource(String nonJtaDataSource)
- {
- metadata.put(NON_JTA_DATASOURCE, nonJtaDataSource);
- }
-
- /**
- * @param mappingFileName
- */
- public void addMappingFileName(String mappingFileName)
- {
- List<String> files = (List<String>) metadata.get(MAPPING_FILES);
- if(files == null) {
- files = new ArrayList<String>();
- metadata.put(MAPPING_FILES, files);
- }
- files.add(mappingFileName);
- }
-
- /**
- * @param jarFile
- */
- public void addJarFileName(String jarFile)
- {
- List<String> jars = (List<String>) metadata.get(JAR_FILES);
- if(jars == null) {
- jars = new ArrayList<String>();
- metadata.put(JAR_FILES, jars);
- }
-
- jars.add(jarFile);
- }
-
- /**
- * @param className
- */
- public void addClassName(String className)
- {
- List<String> classes = (List<String>) metadata.get(MANAGED_CLASSES);
- if(classes == null) {
- classes = new ArrayList<String>();
- metadata.put(MANAGED_CLASSES, classes);
- }
- classes.add(className);
- }
-
- /**
- * @param exclude
- */
- public void setExcludeUnlisted(boolean exclude)
- {
- metadata.put(EXCLUDE_UNLISTED_CLASSES, exclude);
- }
-
- /**
- * @param name
- * @param value
- */
- public void addProperty(String name, String value)
- {
- Properties props = (Properties) metadata.get(PROPERTIES);
- if(props == null) {
- props = new Properties();
- metadata.put(PROPERTIES, props);
- }
- props.setProperty(name, value);
- }
-
- /**
- * @param providerRef
- */
- public void setProviderReference(ServiceReference providerRef)
- {
- provider = providerRef;
- }
-
- /**
- * @param sharedCacheMode
- */
- public void setSharedCacheMode(String sharedCacheMode)
- {
- metadata.put(SHARED_CACHE_MODE, sharedCacheMode);
- }
-
- /**
- * @param validationMode
- */
- public void setValidationMode(String validationMode)
- {
- metadata.put(VALIDATION_MODE, validationMode);
- }
-
- public String toString()
- {
- return "Persistence unit " + metadata.get(UNIT_NAME) + " in bundle "
- + bundle.getSymbolicName() + "_" + bundle.getVersion();
- }
-}
+/*
+ * 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 WARRANTIESOR 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.aries.jpa.container.parsing.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * An implementation of PersistenceUnit for parsed persistence unit metadata
+ *
+ */
+@SuppressWarnings("unchecked")
+public class PersistenceUnitImpl implements ParsedPersistenceUnit
+{
+ /** A map to hold the metadata from the xml */
+ private final Map<String,Object> metadata = new HashMap<String, Object>();
+ /** The bundle defining this persistence unit */
+ private final Bundle bundle;
+
+ /**
+ * The Service Reference for the provider to which this persistence
+ * unit is tied
+ */
+ private ServiceReference provider;
+
+
+ /**
+ * Create a new persistence unit with the given name, transaction type, location and
+ * defining bundle
+ *
+ * @param name may be null
+ * @param transactionType may be null
+ * @param location
+ * @param version The version of the JPA schema used in persistence.xml
+ */
+ public PersistenceUnitImpl(Bundle b, String name, String transactionType, String version)
+ {
+ this.bundle = b;
+ metadata.put(SCHEMA_VERSION, version);
+
+ if (name == null)
+ name = "";
+
+ metadata.put(UNIT_NAME, name);
+ if (transactionType != null) metadata.put(TRANSACTION_TYPE, transactionType);
+
+ }
+
+
+ public Bundle getDefiningBundle()
+ {
+ return bundle;
+ }
+
+ public Map<String, Object> getPersistenceXmlMetadata()
+ {
+ Map<String, Object> data = new HashMap<String, Object>(metadata);
+ if(data.containsKey(MAPPING_FILES))
+ data.put(MAPPING_FILES, ((ArrayList) metadata.get(MAPPING_FILES)).clone());
+ if(data.containsKey(JAR_FILES))
+ data.put(JAR_FILES, ((ArrayList) metadata.get(JAR_FILES)).clone());
+ if(data.containsKey(MANAGED_CLASSES))
+ data.put(MANAGED_CLASSES, ((ArrayList) metadata.get(MANAGED_CLASSES)).clone());
+ if(data.containsKey(PROPERTIES))
+ data.put(PROPERTIES, ((Properties)metadata.get(PROPERTIES)).clone());
+
+ return data;
+ }
+
+ /**
+ * @param provider
+ */
+ public void setProviderClassName(String provider)
+ {
+ metadata.put(PROVIDER_CLASSNAME, provider);
+ }
+
+ /**
+ * @param jtaDataSource
+ */
+ public void setJtaDataSource(String jtaDataSource)
+ {
+ metadata.put(JTA_DATASOURCE, jtaDataSource);
+ }
+
+ /**
+ * @param nonJtaDataSource
+ */
+ public void setNonJtaDataSource(String nonJtaDataSource)
+ {
+ metadata.put(NON_JTA_DATASOURCE, nonJtaDataSource);
+ }
+
+ /**
+ * @param mappingFileName
+ */
+ public void addMappingFileName(String mappingFileName)
+ {
+ List<String> files = (List<String>) metadata.get(MAPPING_FILES);
+ if(files == null) {
+ files = new ArrayList<String>();
+ metadata.put(MAPPING_FILES, files);
+ }
+ files.add(mappingFileName);
+ }
+
+ /**
+ * @param jarFile
+ */
+ public void addJarFileName(String jarFile)
+ {
+ List<String> jars = (List<String>) metadata.get(JAR_FILES);
+ if(jars == null) {
+ jars = new ArrayList<String>();
+ metadata.put(JAR_FILES, jars);
+ }
+
+ jars.add(jarFile);
+ }
+
+ /**
+ * @param className
+ */
+ public void addClassName(String className)
+ {
+ List<String> classes = (List<String>) metadata.get(MANAGED_CLASSES);
+ if(classes == null) {
+ classes = new ArrayList<String>();
+ metadata.put(MANAGED_CLASSES, classes);
+ }
+ classes.add(className);
+ }
+
+ /**
+ * @param exclude
+ */
+ public void setExcludeUnlisted(boolean exclude)
+ {
+ metadata.put(EXCLUDE_UNLISTED_CLASSES, exclude);
+ }
+
+ /**
+ * @param name
+ * @param value
+ */
+ public void addProperty(String name, String value)
+ {
+ Properties props = (Properties) metadata.get(PROPERTIES);
+ if(props == null) {
+ props = new Properties();
+ metadata.put(PROPERTIES, props);
+ }
+ props.setProperty(name, value);
+ }
+
+ /**
+ * @param providerRef
+ */
+ public void setProviderReference(ServiceReference providerRef)
+ {
+ provider = providerRef;
+ }
+
+ /**
+ * @param sharedCacheMode
+ */
+ public void setSharedCacheMode(String sharedCacheMode)
+ {
+ metadata.put(SHARED_CACHE_MODE, sharedCacheMode);
+ }
+
+ /**
+ * @param validationMode
+ */
+ public void setValidationMode(String validationMode)
+ {
+ metadata.put(VALIDATION_MODE, validationMode);
+ }
+
+ public String toString()
+ {
+ return "Persistence unit " + metadata.get(UNIT_NAME) + " in bundle "
+ + bundle.getSymbolicName() + "_" + bundle.getVersion();
+ }
+}
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/PersistenceUnitImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/PersistenceUnitImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/PersistenceUnitImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/SchemaLocatingHandler.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/SchemaLocatingHandler.java?rev=955102&r1=955101&r2=955102&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/SchemaLocatingHandler.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/SchemaLocatingHandler.java Wed Jun 16 00:52:45 2010
@@ -1,102 +1,102 @@
-/*
- * 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 WARRANTIESOR 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.aries.jpa.container.parsing.impl;
-
-import java.net.URL;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import javax.xml.XMLConstants;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * This parser provides a quick mechanism for determining the JPA schema level,
- * and throws an EarlyParserReturn with the Schema to validate with
- */
-public class SchemaLocatingHandler extends DefaultHandler
-{
-
- /**
- * A static cache of schemas in use in the runtime
- */
- private static final ConcurrentMap<String, Schema> schemaCache = new ConcurrentHashMap<String, Schema>();
-
- @Override
- public void startElement(String uri, String localName, String name, Attributes attributes)
- throws SAXException
- {
-
- Schema s = null;
- String version = null;
- if("persistence".equals(name)) {
- version = attributes.getValue(uri, "version");
- s = validate(version);
- }
- throw new EarlyParserReturn(s, version);
- }
-
- /**
- * Find the schema for the version of JPA we're using
- * @param type The value of the version attribute in the xml
- * @return
- * @throws SAXException
- */
- private final Schema validate(String type) throws SAXException
- {
- Schema toReturn = (type == null)? null : schemaCache.get(type);
-
- if(toReturn == null) {
- toReturn = getSchema(type);
- if(toReturn != null) schemaCache.putIfAbsent(type, toReturn);
- }
-
- return toReturn;
- }
-
- /**
- * Locate the schema document
- * @param type The schema version to find
- * @return
- * @throws SAXException
- */
- private final Schema getSchema(String type) throws SAXException
- {
- SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-
- URL schemaURL = null;
- if("1.0".equals(type)) {
- schemaURL = this.getClass().getResource("persistence.xsd.rsrc");
- } else if ("2.0".equals(type)) {
- schemaURL = this.getClass().getResource("persistence_2_0.xsd.rsrc");
- }
-
- Schema schema = null;
- if(schemaURL != null){
- schema = schemaFactory.newSchema(schemaURL);
- }
-
- return schema;
- }
-
-}
+/*
+ * 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 WARRANTIESOR 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.aries.jpa.container.parsing.impl;
+
+import java.net.URL;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.xml.XMLConstants;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * This parser provides a quick mechanism for determining the JPA schema level,
+ * and throws an EarlyParserReturn with the Schema to validate with
+ */
+public class SchemaLocatingHandler extends DefaultHandler
+{
+
+ /**
+ * A static cache of schemas in use in the runtime
+ */
+ private static final ConcurrentMap<String, Schema> schemaCache = new ConcurrentHashMap<String, Schema>();
+
+ @Override
+ public void startElement(String uri, String localName, String name, Attributes attributes)
+ throws SAXException
+ {
+
+ Schema s = null;
+ String version = null;
+ if("persistence".equals(name)) {
+ version = attributes.getValue(uri, "version");
+ s = validate(version);
+ }
+ throw new EarlyParserReturn(s, version);
+ }
+
+ /**
+ * Find the schema for the version of JPA we're using
+ * @param type The value of the version attribute in the xml
+ * @return
+ * @throws SAXException
+ */
+ private final Schema validate(String type) throws SAXException
+ {
+ Schema toReturn = (type == null)? null : schemaCache.get(type);
+
+ if(toReturn == null) {
+ toReturn = getSchema(type);
+ if(toReturn != null) schemaCache.putIfAbsent(type, toReturn);
+ }
+
+ return toReturn;
+ }
+
+ /**
+ * Locate the schema document
+ * @param type The schema version to find
+ * @return
+ * @throws SAXException
+ */
+ private final Schema getSchema(String type) throws SAXException
+ {
+ SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+
+ URL schemaURL = null;
+ if("1.0".equals(type)) {
+ schemaURL = this.getClass().getResource("persistence.xsd.rsrc");
+ } else if ("2.0".equals(type)) {
+ schemaURL = this.getClass().getResource("persistence_2_0.xsd.rsrc");
+ }
+
+ Schema schema = null;
+ if(schemaURL != null){
+ schema = schemaFactory.newSchema(schemaURL);
+ }
+
+ return schema;
+ }
+
+}
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/SchemaLocatingHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/SchemaLocatingHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/impl/SchemaLocatingHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java?rev=955102&r1=955101&r2=955102&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java Wed Jun 16 00:52:45 2010
@@ -1,98 +1,98 @@
-/*
- * 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 WARRANTIESOR 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.aries.jpa.container.unit.impl;
-
-import java.io.IOException;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-
-import org.osgi.framework.Bundle;
-/**
- * This is a simple ClassLoader that delegates to the Bundle
- * and is used by the PersistenceUnitInfo
- */
-public class BundleDelegatingClassLoader extends ClassLoader {
-
- private final Bundle bundle;
-
- public BundleDelegatingClassLoader(Bundle b) {
- bundle = b;
- }
-
- @Override
- protected Class<?> findClass(final String name) throws ClassNotFoundException {
- try {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
- public Class<?> run() throws ClassNotFoundException
- {
- return bundle.loadClass(name);
- }
- });
- } catch (PrivilegedActionException e) {
- Exception cause = e.getException();
-
- if (cause instanceof ClassNotFoundException) throw (ClassNotFoundException)cause;
- else throw (RuntimeException)cause;
- }
- }
-
- @Override
- protected URL findResource(final String name) {
- return AccessController.doPrivileged(new PrivilegedAction<URL>() {
- public URL run()
- {
- return bundle.getResource(name);
- }
- });
- }
-
- @SuppressWarnings("unchecked")
- @Override
- protected Enumeration<URL> findResources(final String name) throws IOException {
- Enumeration<URL> urls;
- try {
- urls = AccessController.doPrivileged(new PrivilegedExceptionAction<Enumeration<URL>>() {
- @SuppressWarnings("unchecked")
- public Enumeration<URL> run() throws IOException
- {
- return (Enumeration<URL>)bundle.getResources(name);
- }
-
- });
- } catch (PrivilegedActionException e) {
- Exception cause = e.getException();
-
- if (cause instanceof IOException) throw (IOException)cause;
- else throw (RuntimeException)cause;
- }
-
- if (urls == null) {
- urls = Collections.enumeration(new ArrayList<URL>());
- }
-
- return urls;
- }
-
-}
+/*
+ * 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 WARRANTIESOR 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.aries.jpa.container.unit.impl;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+
+import org.osgi.framework.Bundle;
+/**
+ * This is a simple ClassLoader that delegates to the Bundle
+ * and is used by the PersistenceUnitInfo
+ */
+public class BundleDelegatingClassLoader extends ClassLoader {
+
+ private final Bundle bundle;
+
+ public BundleDelegatingClassLoader(Bundle b) {
+ bundle = b;
+ }
+
+ @Override
+ protected Class<?> findClass(final String name) throws ClassNotFoundException {
+ try {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
+ public Class<?> run() throws ClassNotFoundException
+ {
+ return bundle.loadClass(name);
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ Exception cause = e.getException();
+
+ if (cause instanceof ClassNotFoundException) throw (ClassNotFoundException)cause;
+ else throw (RuntimeException)cause;
+ }
+ }
+
+ @Override
+ protected URL findResource(final String name) {
+ return AccessController.doPrivileged(new PrivilegedAction<URL>() {
+ public URL run()
+ {
+ return bundle.getResource(name);
+ }
+ });
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Enumeration<URL> findResources(final String name) throws IOException {
+ Enumeration<URL> urls;
+ try {
+ urls = AccessController.doPrivileged(new PrivilegedExceptionAction<Enumeration<URL>>() {
+ @SuppressWarnings("unchecked")
+ public Enumeration<URL> run() throws IOException
+ {
+ return (Enumeration<URL>)bundle.getResources(name);
+ }
+
+ });
+ } catch (PrivilegedActionException e) {
+ Exception cause = e.getException();
+
+ if (cause instanceof IOException) throw (IOException)cause;
+ else throw (RuntimeException)cause;
+ }
+
+ if (urls == null) {
+ urls = Collections.enumeration(new ArrayList<URL>());
+ }
+
+ return urls;
+ }
+
+}
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java?rev=955102&r1=955101&r2=955102&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java Wed Jun 16 00:52:45 2010
@@ -1,131 +1,131 @@
-/*
- * 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 WARRANTIESOR 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.aries.jpa.container.unit.impl;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.apache.aries.jpa.container.ManagedPersistenceUnitInfo;
-import org.apache.aries.jpa.container.ManagedPersistenceUnitInfoFactory;
-import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-
-public class ManagedPersistenceUnitInfoFactoryImpl implements
- ManagedPersistenceUnitInfoFactory {
-
- public Collection<ManagedPersistenceUnitInfo> createManagedPersistenceUnitMetadata(
- BundleContext containerContext, Bundle persistenceBundle,
- ServiceReference providerReference,
- Collection<ParsedPersistenceUnit> persistenceMetadata) {
-
- //TODO add support for provider bundle imports (e.g. for weaving) here
-
- Collection<ManagedPersistenceUnitInfo> managedUnits = new ArrayList<ManagedPersistenceUnitInfo>();
-
- for(ParsedPersistenceUnit unit : persistenceMetadata)
- managedUnits.add(new ManagedPersistenceUnitInfoImpl(persistenceBundle, unit, providerReference));
-
- return managedUnits;
- }
-
- public void destroyPersistenceBundle(BundleContext containerContext, Bundle bundle) {
-
- }
-
- public String getDefaultProviderClassName() {
- return null;
- }
-
- //Code that can be used to attach a fragment for provider wiring
-
-////If we can't find a provider then bomb out
-//if (providerRef != null)
-//{
-// try
-// FragmentBuilder builder = new FragmentBuilder(b, ".jpa.fragment");
-// builder.addImportsFromExports(providerRef.getBundle());
-// fragment = builder.install(ctx);
-//
-//
-// hostToFragmentMap.put(b, fragment);
-// // If we successfully got a fragment then
-// // set the provider reference and register the units
-// Set<ServiceRegistration> registrations = new HashSet<ServiceRegistration>();
-// Hashtable<String, Object> props = new Hashtable<String, Object>();
-//
-// props.put(PersistenceUnitInfoService.PERSISTENCE_BUNDLE_SYMBOLIC_NAME, b.getSymbolicName());
-// props.put(PersistenceUnitInfoService.PERSISTENCE_BUNDLE_VERSION, b.getVersion());
-//
-// for(PersistenceUnitImpl unit : parsedPersistenceUnits){
-// Hashtable<String, Object> serviceProps = new Hashtable<String, Object>(props);
-//
-// String unitName = (String) unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.UNIT_NAME);
-// if(unitName != null)
-// serviceProps.put(PersistenceUnitInfoService.PERSISTENCE_UNIT_NAME, unitName);
-//
-// unit.setProviderReference(providerRef);
-// registrations.add(ctx.registerService(PersistenceUnitInfoService.class.getName(), unit, serviceProps));
-// }
-// hostToPersistenceUnitMap.put(b, registrations);
-// }
-// catch (IOException e)
-// {
-// // TODO Fragment generation failed, log the error
-// // No clean up because we didn't register the bundle yet
-// e.printStackTrace();
-// }
-// catch (BundleException be) {
-// //TODO log the failure to install the fragment, but return null
-// // to show we didn't get a fragment installed
-// // No clean up because we didn't register the bundle yet
-// }
-//}
-//}
-//}
-
- //Code that can be used to clear up a persistence unit
-
-///**
-// * If we have generated a resources for the supplied bundle, then
-// * tidy them up.
-// * @param host
-// */
-//private void tidyUpPersistenceBundle(Bundle host)
-//{
-//
-// Bundle fragment = hostToFragmentMap.remove(host);
-// Set<ServiceRegistration> services = hostToPersistenceUnitMap.remove(host);
-//
-// if(services != null) {
-// for(ServiceRegistration reg : services)
-// reg.unregister();
-// }
-//
-// if(fragment != null){
-// try {
-// fragment.uninstall();
-// } catch (BundleException be) {
-// //TODO log this error, then hope that we don't try to
-// //recreate the fragment before restarting the framework!
-// }
-// }
-//}
-}
+/*
+ * 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 WARRANTIESOR 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.aries.jpa.container.unit.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.aries.jpa.container.ManagedPersistenceUnitInfo;
+import org.apache.aries.jpa.container.ManagedPersistenceUnitInfoFactory;
+import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class ManagedPersistenceUnitInfoFactoryImpl implements
+ ManagedPersistenceUnitInfoFactory {
+
+ public Collection<ManagedPersistenceUnitInfo> createManagedPersistenceUnitMetadata(
+ BundleContext containerContext, Bundle persistenceBundle,
+ ServiceReference providerReference,
+ Collection<ParsedPersistenceUnit> persistenceMetadata) {
+
+ //TODO add support for provider bundle imports (e.g. for weaving) here
+
+ Collection<ManagedPersistenceUnitInfo> managedUnits = new ArrayList<ManagedPersistenceUnitInfo>();
+
+ for(ParsedPersistenceUnit unit : persistenceMetadata)
+ managedUnits.add(new ManagedPersistenceUnitInfoImpl(persistenceBundle, unit, providerReference));
+
+ return managedUnits;
+ }
+
+ public void destroyPersistenceBundle(BundleContext containerContext, Bundle bundle) {
+
+ }
+
+ public String getDefaultProviderClassName() {
+ return null;
+ }
+
+ //Code that can be used to attach a fragment for provider wiring
+
+////If we can't find a provider then bomb out
+//if (providerRef != null)
+//{
+// try
+// FragmentBuilder builder = new FragmentBuilder(b, ".jpa.fragment");
+// builder.addImportsFromExports(providerRef.getBundle());
+// fragment = builder.install(ctx);
+//
+//
+// hostToFragmentMap.put(b, fragment);
+// // If we successfully got a fragment then
+// // set the provider reference and register the units
+// Set<ServiceRegistration> registrations = new HashSet<ServiceRegistration>();
+// Hashtable<String, Object> props = new Hashtable<String, Object>();
+//
+// props.put(PersistenceUnitInfoService.PERSISTENCE_BUNDLE_SYMBOLIC_NAME, b.getSymbolicName());
+// props.put(PersistenceUnitInfoService.PERSISTENCE_BUNDLE_VERSION, b.getVersion());
+//
+// for(PersistenceUnitImpl unit : parsedPersistenceUnits){
+// Hashtable<String, Object> serviceProps = new Hashtable<String, Object>(props);
+//
+// String unitName = (String) unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.UNIT_NAME);
+// if(unitName != null)
+// serviceProps.put(PersistenceUnitInfoService.PERSISTENCE_UNIT_NAME, unitName);
+//
+// unit.setProviderReference(providerRef);
+// registrations.add(ctx.registerService(PersistenceUnitInfoService.class.getName(), unit, serviceProps));
+// }
+// hostToPersistenceUnitMap.put(b, registrations);
+// }
+// catch (IOException e)
+// {
+// // TODO Fragment generation failed, log the error
+// // No clean up because we didn't register the bundle yet
+// e.printStackTrace();
+// }
+// catch (BundleException be) {
+// //TODO log the failure to install the fragment, but return null
+// // to show we didn't get a fragment installed
+// // No clean up because we didn't register the bundle yet
+// }
+//}
+//}
+//}
+
+ //Code that can be used to clear up a persistence unit
+
+///**
+// * If we have generated a resources for the supplied bundle, then
+// * tidy them up.
+// * @param host
+// */
+//private void tidyUpPersistenceBundle(Bundle host)
+//{
+//
+// Bundle fragment = hostToFragmentMap.remove(host);
+// Set<ServiceRegistration> services = hostToPersistenceUnitMap.remove(host);
+//
+// if(services != null) {
+// for(ServiceRegistration reg : services)
+// reg.unregister();
+// }
+//
+// if(fragment != null){
+// try {
+// fragment.uninstall();
+// } catch (BundleException be) {
+// //TODO log this error, then hope that we don't try to
+// //recreate the fragment before restarting the framework!
+// }
+// }
+//}
+}
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java?rev=955102&r1=955101&r2=955102&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java Wed Jun 16 00:52:45 2010
@@ -1,51 +1,51 @@
-/*
- * 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 WARRANTIESOR 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.aries.jpa.container.unit.impl;
-
-import java.util.Collections;
-import java.util.Map;
-
-import javax.persistence.spi.PersistenceUnitInfo;
-
-import org.apache.aries.jpa.container.ManagedPersistenceUnitInfo;
-import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceReference;
-
-public class ManagedPersistenceUnitInfoImpl implements
- ManagedPersistenceUnitInfo {
-
- private final PersistenceUnitInfo info;
-
- public ManagedPersistenceUnitInfoImpl(Bundle persistenceBundle,
- ParsedPersistenceUnit unit,
- ServiceReference providerRef) {
- info = new PersistenceUnitInfoImpl(persistenceBundle, unit, providerRef);
- }
-
- public Map<String, Object> getContainerProperties() {
- return Collections.emptyMap();
- }
-
- public PersistenceUnitInfo getPersistenceUnitInfo() {
- return info;
- }
-
-
-}
+/*
+ * 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 WARRANTIESOR 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.aries.jpa.container.unit.impl;
+
+import java.util.Collections;
+import java.util.Map;
+
+import javax.persistence.spi.PersistenceUnitInfo;
+
+import org.apache.aries.jpa.container.ManagedPersistenceUnitInfo;
+import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+public class ManagedPersistenceUnitInfoImpl implements
+ ManagedPersistenceUnitInfo {
+
+ private final PersistenceUnitInfo info;
+
+ public ManagedPersistenceUnitInfoImpl(Bundle persistenceBundle,
+ ParsedPersistenceUnit unit,
+ ServiceReference providerRef) {
+ info = new PersistenceUnitInfoImpl(persistenceBundle, unit, providerRef);
+ }
+
+ public Map<String, Object> getContainerProperties() {
+ return Collections.emptyMap();
+ }
+
+ public PersistenceUnitInfo getPersistenceUnitInfo() {
+ return info;
+ }
+
+
+}
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java?rev=955102&r1=955101&r2=955102&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java Wed Jun 16 00:52:45 2010
@@ -1,197 +1,197 @@
-/*
- * 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 WARRANTIESOR 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.aries.jpa.container.unit.impl;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
-
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.persistence.SharedCacheMode;
-import javax.persistence.ValidationMode;
-import javax.persistence.spi.ClassTransformer;
-import javax.persistence.spi.PersistenceUnitInfo;
-import javax.persistence.spi.PersistenceUnitTransactionType;
-import javax.sql.DataSource;
-
-import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PersistenceUnitInfoImpl implements PersistenceUnitInfo {
-
- private final Bundle bundle;
-
- private final ParsedPersistenceUnit unit;
-
- private final BundleDelegatingClassLoader cl;
-
- private final ServiceReference providerRef;
-
- /** Logger */
- private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.jpa.container");
-
- public PersistenceUnitInfoImpl (Bundle b, ParsedPersistenceUnit parsedData, final ServiceReference providerRef)
- {
- bundle = b;
- unit = parsedData;
- this.providerRef = providerRef;
- cl = new BundleDelegatingClassLoader(b);
- }
-
- public void addTransformer(ClassTransformer arg0) {
- // TODO Add support for class transformation from this method
- }
-
- public boolean excludeUnlistedClasses() {
- Boolean result = (Boolean) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.EXCLUDE_UNLISTED_CLASSES);
- return (result == null) ? false : result;
- }
-
- public ClassLoader getClassLoader() {
- return cl;
- }
-
- @SuppressWarnings("unchecked")
- public List<URL> getJarFileUrls() {
- List<String> jarFiles = (List<String>) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JAR_FILES);
- List<URL> urls = new ArrayList<URL>();
- if(jarFiles != null) {
- for(String jarFile : jarFiles){
- URL url = bundle.getResource(jarFile);
- if(url == null) {
- _logger.error("The persistence unit {} in bundle {} listed the jar file {}, but " +
- "{} could not be found in the bundle", new Object[]{getPersistenceUnitName(),
- bundle.getSymbolicName() + "_" + bundle.getVersion(), jarFile, jarFile});
- } else {
- urls.add(url);
- }
- }
- }
- return urls;
- }
-
- public DataSource getJtaDataSource() {
- String jndiString = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JTA_DATASOURCE);
- DataSource toReturn = null;
- if(jndiString != null) {
- try {
- InitialContext ctx = new InitialContext();
- toReturn = (DataSource) ctx.lookup(jndiString);
- } catch (NamingException e) {
- _logger.error("No JTA datasource could be located using the JNDI name " + jndiString,
- e);
- }
- }
- return toReturn;
- }
-
- @SuppressWarnings("unchecked")
- public List<String> getManagedClassNames() {
- List<String> classes = (List<String>) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MANAGED_CLASSES);
- if(classes == null)
- classes = new ArrayList<String>();
-
- return Collections.unmodifiableList(classes);
- }
-
- @SuppressWarnings("unchecked")
- public List<String> getMappingFileNames() {
- List<String> mappingFiles = (List<String>) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MAPPING_FILES);
- if(mappingFiles == null)
- mappingFiles = new ArrayList<String>();
-
- return Collections.unmodifiableList(mappingFiles);
- }
-
- public ClassLoader getNewTempClassLoader() {
- return new TempBundleDelegatingClassLoader(bundle, new BundleDelegatingClassLoader(providerRef.getBundle()));
- }
-
- public DataSource getNonJtaDataSource() {
-
- String jndiString = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.NON_JTA_DATASOURCE);
- DataSource toReturn = null;
- if(jndiString != null) {
- try {
- InitialContext ctx = new InitialContext();
- toReturn = (DataSource) ctx.lookup(jndiString);
- } catch (NamingException e) {
- _logger.error("No Non JTA datasource could be located using the JNDI name " + jndiString,
- e);
- }
- }
- return toReturn;
- }
-
- public String getPersistenceProviderClassName() {
- return (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROVIDER_CLASSNAME);
- }
-
- public String getPersistenceUnitName() {
- return (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.UNIT_NAME);
- }
-
- public URL getPersistenceUnitRootUrl() {
- return bundle.getResource("/");
- }
-
- public String getPersistenceXMLSchemaVersion() {
- return (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.SCHEMA_VERSION);
- }
-
- public Properties getProperties() {
- return (Properties) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROPERTIES);
- }
-
- public SharedCacheMode getSharedCacheMode() {
- String s = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.SHARED_CACHE_MODE);
-
- if (s == null)
- return SharedCacheMode.UNSPECIFIED;
- else
- return SharedCacheMode.valueOf(s);
- }
-
- public PersistenceUnitTransactionType getTransactionType() {
-
- String s = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.TRANSACTION_TYPE);
-
- if(s == null)
- return PersistenceUnitTransactionType.JTA;
- else
- return PersistenceUnitTransactionType.valueOf(s);
- }
-
- public ValidationMode getValidationMode() {
- String s = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.VALIDATION_MODE);
-
- if (s == null)
- return ValidationMode.AUTO;
- else
- return ValidationMode.valueOf(s);
-
- }
-
+/*
+ * 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 WARRANTIESOR 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.aries.jpa.container.unit.impl;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.persistence.SharedCacheMode;
+import javax.persistence.ValidationMode;
+import javax.persistence.spi.ClassTransformer;
+import javax.persistence.spi.PersistenceUnitInfo;
+import javax.persistence.spi.PersistenceUnitTransactionType;
+import javax.sql.DataSource;
+
+import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PersistenceUnitInfoImpl implements PersistenceUnitInfo {
+
+ private final Bundle bundle;
+
+ private final ParsedPersistenceUnit unit;
+
+ private final BundleDelegatingClassLoader cl;
+
+ private final ServiceReference providerRef;
+
+ /** Logger */
+ private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.jpa.container");
+
+ public PersistenceUnitInfoImpl (Bundle b, ParsedPersistenceUnit parsedData, final ServiceReference providerRef)
+ {
+ bundle = b;
+ unit = parsedData;
+ this.providerRef = providerRef;
+ cl = new BundleDelegatingClassLoader(b);
+ }
+
+ public void addTransformer(ClassTransformer arg0) {
+ // TODO Add support for class transformation from this method
+ }
+
+ public boolean excludeUnlistedClasses() {
+ Boolean result = (Boolean) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.EXCLUDE_UNLISTED_CLASSES);
+ return (result == null) ? false : result;
+ }
+
+ public ClassLoader getClassLoader() {
+ return cl;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<URL> getJarFileUrls() {
+ List<String> jarFiles = (List<String>) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JAR_FILES);
+ List<URL> urls = new ArrayList<URL>();
+ if(jarFiles != null) {
+ for(String jarFile : jarFiles){
+ URL url = bundle.getResource(jarFile);
+ if(url == null) {
+ _logger.error("The persistence unit {} in bundle {} listed the jar file {}, but " +
+ "{} could not be found in the bundle", new Object[]{getPersistenceUnitName(),
+ bundle.getSymbolicName() + "_" + bundle.getVersion(), jarFile, jarFile});
+ } else {
+ urls.add(url);
+ }
+ }
+ }
+ return urls;
+ }
+
+ public DataSource getJtaDataSource() {
+ String jndiString = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JTA_DATASOURCE);
+ DataSource toReturn = null;
+ if(jndiString != null) {
+ try {
+ InitialContext ctx = new InitialContext();
+ toReturn = (DataSource) ctx.lookup(jndiString);
+ } catch (NamingException e) {
+ _logger.error("No JTA datasource could be located using the JNDI name " + jndiString,
+ e);
+ }
+ }
+ return toReturn;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<String> getManagedClassNames() {
+ List<String> classes = (List<String>) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MANAGED_CLASSES);
+ if(classes == null)
+ classes = new ArrayList<String>();
+
+ return Collections.unmodifiableList(classes);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<String> getMappingFileNames() {
+ List<String> mappingFiles = (List<String>) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MAPPING_FILES);
+ if(mappingFiles == null)
+ mappingFiles = new ArrayList<String>();
+
+ return Collections.unmodifiableList(mappingFiles);
+ }
+
+ public ClassLoader getNewTempClassLoader() {
+ return new TempBundleDelegatingClassLoader(bundle, new BundleDelegatingClassLoader(providerRef.getBundle()));
+ }
+
+ public DataSource getNonJtaDataSource() {
+
+ String jndiString = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.NON_JTA_DATASOURCE);
+ DataSource toReturn = null;
+ if(jndiString != null) {
+ try {
+ InitialContext ctx = new InitialContext();
+ toReturn = (DataSource) ctx.lookup(jndiString);
+ } catch (NamingException e) {
+ _logger.error("No Non JTA datasource could be located using the JNDI name " + jndiString,
+ e);
+ }
+ }
+ return toReturn;
+ }
+
+ public String getPersistenceProviderClassName() {
+ return (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROVIDER_CLASSNAME);
+ }
+
+ public String getPersistenceUnitName() {
+ return (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.UNIT_NAME);
+ }
+
+ public URL getPersistenceUnitRootUrl() {
+ return bundle.getResource("/");
+ }
+
+ public String getPersistenceXMLSchemaVersion() {
+ return (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.SCHEMA_VERSION);
+ }
+
+ public Properties getProperties() {
+ return (Properties) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROPERTIES);
+ }
+
+ public SharedCacheMode getSharedCacheMode() {
+ String s = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.SHARED_CACHE_MODE);
+
+ if (s == null)
+ return SharedCacheMode.UNSPECIFIED;
+ else
+ return SharedCacheMode.valueOf(s);
+ }
+
+ public PersistenceUnitTransactionType getTransactionType() {
+
+ String s = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.TRANSACTION_TYPE);
+
+ if(s == null)
+ return PersistenceUnitTransactionType.JTA;
+ else
+ return PersistenceUnitTransactionType.valueOf(s);
+ }
+
+ public ValidationMode getValidationMode() {
+ String s = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.VALIDATION_MODE);
+
+ if (s == null)
+ return ValidationMode.AUTO;
+ else
+ return ValidationMode.valueOf(s);
+
+ }
+
}
\ No newline at end of file
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java?rev=955102&r1=955101&r2=955102&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java Wed Jun 16 00:52:45 2010
@@ -1,80 +1,80 @@
-/*
- * 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 WARRANTIESOR 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.aries.jpa.container.unit.impl;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Enumeration;
-
-import org.osgi.framework.Bundle;
-
-/**
- * This is a simple temporary ClassLoader that delegates to the Bundle,
- * but does not call loadClass. It is used by the PersistenceUnitInfo
- */
-public class TempBundleDelegatingClassLoader extends ClassLoader {
-
- private final Bundle bundle;
-
- public TempBundleDelegatingClassLoader(Bundle b, ClassLoader parent) {
- super(parent);
- bundle = b;
- }
-
- @Override
- protected Class<?> findClass(String className) throws ClassNotFoundException {
- String classResName = className.replace('.', '/').concat(".class");
-
- //Don't use loadClass, just load the bytes and call defineClass
- InputStream is = getResourceAsStream(classResName);
-
- if(is == null)
- throw new ClassNotFoundException(className);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- byte[] buff = new byte[4096];
- try {
- int read = is.read(buff);
- while(read >0) {
- baos.write(buff, 0, read);
- read = is.read(buff);
- }
- } catch (IOException ioe) {
- throw new ClassNotFoundException(className, ioe);
- }
-
- buff = baos.toByteArray();
-
- return defineClass(className, buff, 0, buff.length);
- }
-
- @Override
- protected URL findResource(String resName) {
- return bundle.getResource(resName);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- protected Enumeration<URL> findResources(String resName) throws IOException {
- return bundle.getResources(resName);
- }
-}
+/*
+ * 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 WARRANTIESOR 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.aries.jpa.container.unit.impl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * This is a simple temporary ClassLoader that delegates to the Bundle,
+ * but does not call loadClass. It is used by the PersistenceUnitInfo
+ */
+public class TempBundleDelegatingClassLoader extends ClassLoader {
+
+ private final Bundle bundle;
+
+ public TempBundleDelegatingClassLoader(Bundle b, ClassLoader parent) {
+ super(parent);
+ bundle = b;
+ }
+
+ @Override
+ protected Class<?> findClass(String className) throws ClassNotFoundException {
+ String classResName = className.replace('.', '/').concat(".class");
+
+ //Don't use loadClass, just load the bytes and call defineClass
+ InputStream is = getResourceAsStream(classResName);
+
+ if(is == null)
+ throw new ClassNotFoundException(className);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ byte[] buff = new byte[4096];
+ try {
+ int read = is.read(buff);
+ while(read >0) {
+ baos.write(buff, 0, read);
+ read = is.read(buff);
+ }
+ } catch (IOException ioe) {
+ throw new ClassNotFoundException(className, ioe);
+ }
+
+ buff = baos.toByteArray();
+
+ return defineClass(className, buff, 0, buff.length);
+ }
+
+ @Override
+ protected URL findResource(String resName) {
+ return bundle.getResource(resName);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Enumeration<URL> findResources(String resName) throws IOException {
+ return bundle.getResources(resName);
+ }
+}
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/aries/trunk/jpa/jpa-container/src/main/resources/OSGI-INF/blueprint/jpa.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/resources/OSGI-INF/blueprint/jpa.xml?rev=955102&r1=955101&r2=955102&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/resources/OSGI-INF/blueprint/jpa.xml (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/resources/OSGI-INF/blueprint/jpa.xml Wed Jun 16 00:52:45 2010
@@ -1,34 +1,34 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!--
- 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 xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
-
- <bean id="container" class="org.apache.aries.jpa.container.impl.PersistenceBundleManager" init-method="open" destroy-method="close">
- <argument ref="blueprintBundleContext"/>
- <property name="config"><props/></property>
- <property name="parser" ref="parser"/>
- </bean>
-
- <bean id="parser" class="org.apache.aries.jpa.container.parsing.impl.PersistenceDescriptorParserImpl"/>
-
- <reference-list interface="javax.persistence.spi.PersistenceProvider" availability="optional">
- <reference-listener ref="container" bind-method="addingProvider" unbind-method="removingProvider"/>
- </reference-list>
-
- <service interface="org.apache.aries.jpa.container.parsing.PersistenceDescriptorParser" ref="parser"/>
-
-</blueprint>
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ 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 xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <bean id="container" class="org.apache.aries.jpa.container.impl.PersistenceBundleManager" init-method="open" destroy-method="close">
+ <argument ref="blueprintBundleContext"/>
+ <property name="config"><props/></property>
+ <property name="parser" ref="parser"/>
+ </bean>
+
+ <bean id="parser" class="org.apache.aries.jpa.container.parsing.impl.PersistenceDescriptorParserImpl"/>
+
+ <reference-list interface="javax.persistence.spi.PersistenceProvider" availability="optional">
+ <reference-listener ref="container" bind-method="addingProvider" unbind-method="removingProvider"/>
+ </reference-list>
+
+ <service interface="org.apache.aries.jpa.container.parsing.PersistenceDescriptorParser" ref="parser"/>
+
+</blueprint>
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/resources/OSGI-INF/blueprint/jpa.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/resources/OSGI-INF/blueprint/jpa.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/jpa/jpa-container/src/main/resources/OSGI-INF/blueprint/jpa.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml