index int64 0 0 | repo_id stringlengths 9 205 | file_path stringlengths 31 246 | content stringlengths 1 12.2M | __index_level_0__ int64 0 10k |
|---|---|---|---|---|
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/ListenerRegistration.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee;
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.management.InstanceNotFoundException;
import javax.management.ListenerNotFoundException;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectName;
/**
* @version $Rev$
*/
public interface ListenerRegistration extends Serializable {
public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, RemoteException;
public void removeNotificationListener(ObjectName name, NotificationListener listener) throws InstanceNotFoundException, ListenerNotFoundException, RemoteException;
} | 700 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/Management.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee;
import java.rmi.RemoteException;
import java.util.Set;
import javax.ejb.EJBObject;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.InvalidAttributeValueException;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.ObjectName;
import javax.management.QueryExp;
import javax.management.ReflectionException;
/**
* @version $Rev$
*/
public interface Management extends EJBObject {
public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException, RemoteException;
public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException, ReflectionException, RemoteException;
public String getDefaultDomain() throws RemoteException;
public Integer getMBeanCount() throws RemoteException;
public MBeanInfo getMBeanInfo(ObjectName name) throws IntrospectionException, InstanceNotFoundException, ReflectionException, RemoteException;
public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) throws InstanceNotFoundException, MBeanException, ReflectionException, RemoteException;
public boolean isRegistered(ObjectName name) throws RemoteException;
public Set queryNames(ObjectName name, QueryExp query) throws RemoteException;
public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException, RemoteException;
public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException, ReflectionException, RemoteException;
public ListenerRegistration getListenerRegistry() throws RemoteException;
} | 701 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/StatefulSessionBeanStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface StatefulSessionBeanStats extends SessionBeanStats {
public RangeStatistic getPassiveCount();
} | 702 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JDBCStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JDBCStats extends Stats {
public JDBCConnectionStats[] getConnections();
public JDBCConnectionPoolStats[] getConnectionPools();
} | 703 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JMSConnectionStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JMSConnectionStats extends Stats {
public JMSSessionStats[] getSessions();
public boolean isTransactional();
} | 704 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/StatelessSessionBeanStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface StatelessSessionBeanStats extends SessionBeanStats {
}
| 705 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/Stats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface Stats {
public Statistic getStatistic(String statisticName);
public String[] getStatisticNames();
public Statistic[] getStatistics();
} | 706 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/ServletStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface ServletStats extends Stats {
public TimeStatistic getServiceTime();
} | 707 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/URLStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface URLStats extends Stats {
}
| 708 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/EntityBeanStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface EntityBeanStats extends EJBStats {
public RangeStatistic getReadyCount();
public RangeStatistic getPooledCount();
} | 709 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JCAConnectionStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JCAConnectionStats extends Stats {
public String getConnectionFactory();
public String getManagedConnectionFactory();
public TimeStatistic getWaitTime();
public TimeStatistic getUseTime();
} | 710 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JMSProducerStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JMSProducerStats extends JMSEndpointStats {
public String getDestination();
}
| 711 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/SessionBeanStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface SessionBeanStats extends EJBStats {
public RangeStatistic getMethodReadyCount();
} | 712 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/Statistic.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface Statistic {
public String getName();
public String getUnit();
public String getDescription();
public long getStartTime();
public long getLastSampleTime();
} | 713 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JavaMailStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JavaMailStats {
/**
* The number of mail messages sent.
*/
public CountStatistic getSentMailCount();
} | 714 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/CountStatistic.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface CountStatistic extends Statistic {
public long getCount();
} | 715 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JDBCConnectionPoolStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JDBCConnectionPoolStats extends JDBCConnectionStats {
public CountStatistic getCreateCount();
public CountStatistic getCloseCount();
public BoundedRangeStatistic getPoolSize();
public BoundedRangeStatistic getFreePoolSize();
public RangeStatistic getWaitingThreadCount();
} | 716 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/BoundaryStatistic.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface BoundaryStatistic extends Statistic {
public long getUpperBound();
public long getLowerBound();
}
| 717 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JCAStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JCAStats extends Stats {
public JCAConnectionStats[] getConnections();
public JCAConnectionPoolStats[] getConnectionPools();
} | 718 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/EJBStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface EJBStats extends Stats {
public CountStatistic getCreateCount();
public CountStatistic getRemoveCount();
} | 719 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/MessageDrivenBeanStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface MessageDrivenBeanStats extends EJBStats {
public CountStatistic getMessageCount();
}
| 720 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JMSEndpointStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JMSEndpointStats extends Stats {
public CountStatistic getMessageCount();
public CountStatistic getPendingMessageCount();
public CountStatistic getExpiredMessageCount();
public TimeStatistic getMessageWaitTime();
} | 721 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/BoundedRangeStatistic.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface BoundedRangeStatistic extends BoundaryStatistic, RangeStatistic {
}
| 722 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JMSConsumerStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JMSConsumerStats extends JMSEndpointStats {
public String getOrigin();
} | 723 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JCAConnectionPoolStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JCAConnectionPoolStats extends JCAConnectionStats {
public CountStatistic getCloseCount();
public CountStatistic getCreateCount();
public BoundedRangeStatistic getFreePoolSize();
public BoundedRangeStatistic getPoolSize();
public RangeStatistic getWaitingThreadCount();
} | 724 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/RangeStatistic.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface RangeStatistic extends Statistic {
public long getHighWaterMark();
public long getLowWaterMark();
public long getCurrent();
} | 725 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JTAStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JTAStats extends Stats {
public CountStatistic getActiveCount();
public CountStatistic getCommittedCount();
public CountStatistic getRolledbackCount();
} | 726 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JMSSessionStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JMSSessionStats extends Stats {
public JMSProducerStats[] getProducers();
public JMSConsumerStats[] getConsumers();
public CountStatistic getMessageCount();
public CountStatistic getPendingMessageCount();
public CountStatistic getExpiredMessageCount();
public TimeStatistic getMessageWaitTime();
public CountStatistic getDurableSubscriptionCount();
} | 727 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JMSStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JMSStats extends Stats {
public JMSConnectionStats[] getConnections();
} | 728 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JDBCConnectionStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JDBCConnectionStats extends Stats {
public String getJdbcDataSource();
public TimeStatistic getWaitTime();
public TimeStatistic getUseTime();
} | 729 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/TimeStatistic.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface TimeStatistic extends Statistic {
public long getCount();
public long getMaxTime();
public long getMinTime();
public long getTotalTime();
} | 730 |
0 | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee | Create_ds/geronimo-specs/geronimo-j2ee-management_1.1_spec/src/main/java/javax/management/j2ee/statistics/JVMStats.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.management.j2ee.statistics;
/**
* @version $Rev$
*/
public interface JVMStats extends Stats {
public CountStatistic getUpTime();
public BoundedRangeStatistic getHeapSize();
} | 731 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/HTTPMethodSpecTest.java | /*
* 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 javax.security.jacc;
import junit.framework.TestCase;
/**
* @version $Rev$ $Date$
*/
public class HTTPMethodSpecTest extends TestCase {
public void testHTTPMethodSpec() throws Exception {
testHTTPMethodSpec(true);
testHTTPMethodSpec(false);
assertEquals("NONE", new HTTPMethodSpec("NONE", true).getActions());
}
public void testHTTPMethodSpec(boolean parseTransport) throws Exception {
assertEquals("", new HTTPMethodSpec(null, parseTransport).getActions());
assertEquals("", new HTTPMethodSpec("", parseTransport).getActions());
assertEquals("", new HTTPMethodSpec("!", parseTransport).getActions());
assertEquals("GET", new HTTPMethodSpec("GET", parseTransport).getActions());
assertEquals("GET,PUT", new HTTPMethodSpec("GET,PUT", parseTransport).getActions());
assertEquals("GET,PUT", new HTTPMethodSpec("PUT,GET", parseTransport).getActions());
assertEquals("FOO", new HTTPMethodSpec("FOO", parseTransport).getActions());
assertEquals("!GET", new HTTPMethodSpec("!GET", parseTransport).getActions());
assertEquals("!FOO", new HTTPMethodSpec("!FOO", parseTransport).getActions());
assertEquals("!GET,PUT", new HTTPMethodSpec("!PUT,GET", parseTransport).getActions());
assertFalse(new HTTPMethodSpec("GET", parseTransport).equals(new HTTPMethodSpec("!GET", parseTransport)));
}
}
| 732 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/EJBRoleRefPermissionTest.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import junit.framework.TestCase;
/**
* @version $Rev$ $Date$
*/
public class EJBRoleRefPermissionTest extends TestCase {
public void testConstructor() {
EJBRoleRefPermission permission1 = new EJBRoleRefPermission("foo", "bar");
EJBRoleRefPermission permission2 = new EJBRoleRefPermission("foo", "bar");
EJBRoleRefPermission permission3 = new EJBRoleRefPermission("foo", "cat");
assertTrue(permission1.implies(permission1));
assertTrue(permission1.implies(permission2));
assertTrue(permission2.implies(permission1));
assertTrue(permission1.equals(permission1));
assertTrue(permission1.equals(permission2));
assertTrue(permission2.equals(permission1));
assertFalse(permission1.implies(permission3));
assertFalse(permission3.implies(permission1));
assertFalse(permission1.equals(permission3));
assertFalse(permission3.equals(permission1));
assertEquals(permission1.getName(), "foo");
assertEquals(permission1.getActions(), "bar");
assertEquals(permission1.hashCode(), permission2.hashCode());
}
public void testImplies() {
}
}
| 733 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/EJBMethodPermissionTest.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import junit.framework.TestCase;
import java.lang.reflect.Method;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
/**
* @version $Rev$ $Date$
*/
public class EJBMethodPermissionTest extends TestCase {
protected Method method;
public void setUp() {
try {
method = TestClass.class.getDeclaredMethod("cat", new Class[] { Integer.class, Float.class, Long.class, Double.class,int[].class });
} catch (NoSuchMethodException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
} catch (SecurityException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
/*
* Testing EJBMethodPermission(java.lang.String, java.lang.String)
*/
public void testConstructorStringString() throws Exception {
// methodSpec ::= null
EJBMethodPermission permission = new EJBMethodPermission("foo", null);
doTestSerialization(permission);
// methodSpec ::= methodNameSpec
permission = new EJBMethodPermission("foo", "");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat");
doTestSerialization(permission);
// methodSpec ::= methodNameSpec comma methodInterface
permission = new EJBMethodPermission("foo", ",ServiceEndpoint");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat,ServiceEndpoint");
doTestSerialization(permission);
// methodSpec ::= methodNameSpec comma methodInterfaceSpec comma methodParamsSpec
permission = new EJBMethodPermission("foo", ",,");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat,,");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", ",Home,");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat,Home,");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", ",,a,b,c,d,e");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat,,a,b,c,d,e");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", ",Home,a,b,c,d,e");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat,Home,a,b,c,d,e");
doTestSerialization(permission);
// methodInterface ::= "Home" | "LocalHome" | "Remote" | "Local" | "ServiceEndpoint"
permission = new EJBMethodPermission("foo", "cat,Home,a,b,c,d,e");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat,LocalHome,a,b,c,d,e");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat,Remote,a,b,c,d,e");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat,Local,a,b,c,d,e");
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat,ServiceEndpoint,a,b,c,d,e");
doTestSerialization(permission);
assertEquals(permission.getName(), "foo");
assertEquals(permission.getActions(), "cat,ServiceEndpoint,a,b,c,d,e");
// bad methodInterface
try {
permission = new EJBMethodPermission("foo", "cat,Interface,a,b,c,d,e");
fail("Bad method interface");
} catch(IllegalArgumentException iae) {
}
// no production produces "emptyString,emptyString"
try {
permission = new EJBMethodPermission("foo", ",");
fail("Empty method interface");
} catch(IllegalArgumentException iae) {
}
// no production produces "methodName ,emptyString"
try {
permission = new EJBMethodPermission("foo", "cat,");
fail("Empty method interface");
} catch(IllegalArgumentException iae) {
}
// no production produces an empty method parameter
try {
permission = new EJBMethodPermission("foo", ",,,");
fail("Empty method parameter");
} catch(IllegalArgumentException iae) {
}
// no production produces an empty method parameter
try {
permission = new EJBMethodPermission("foo", ",,,,,,");
fail("Empty method parameter");
} catch(IllegalArgumentException iae) {
}
}
public void testImpliesStringString() throws Exception {
EJBMethodPermission permissionFooEEE = new EJBMethodPermission("foo", "");
EJBMethodPermission permissionFooMIP = new EJBMethodPermission("foo", "cat,LocalHome,a,b,c,d,e");
EJBMethodPermission permissionBarEEE = new EJBMethodPermission("bar", "");
EJBMethodPermission permissionFooEIP = new EJBMethodPermission("foo", ",LocalHome,a,b,c,d,e");
EJBMethodPermission permissionFooEIE = new EJBMethodPermission("foo", ",LocalHome,");
EJBMethodPermission permissionFooEI = new EJBMethodPermission("foo", ",LocalHome");
assertTrue(permissionFooEEE.implies(permissionFooEEE));
assertTrue(permissionFooEEE.implies(permissionFooMIP));
assertTrue(permissionFooEEE.implies(permissionFooEIP));
assertTrue(permissionFooEEE.implies(permissionFooEIE));
assertTrue(permissionFooEEE.implies(permissionFooEI));
assertFalse(permissionFooMIP.implies(permissionFooEEE));
assertTrue(permissionFooEEE.equals(permissionFooEEE));
assertFalse(permissionFooEEE.equals(permissionFooMIP));
assertFalse(permissionFooMIP.equals(permissionFooEEE));
assertFalse(permissionFooEEE.implies(permissionBarEEE));
assertFalse(permissionBarEEE.implies(permissionFooEEE));
assertFalse(permissionFooEEE.equals(permissionBarEEE));
assertFalse(permissionBarEEE.equals(permissionFooEEE));
assertTrue(permissionFooEIP.implies(permissionFooMIP));
assertFalse(permissionFooEIE.implies(permissionFooMIP));
assertTrue(permissionFooEI.implies(permissionFooMIP));
assertTrue(permissionFooEI.implies(permissionFooEIP));
assertTrue(permissionFooEI.implies(permissionFooEIE));
assertFalse(permissionFooEEE.hashCode() == permissionBarEEE.hashCode());
doTestSerialization(permissionFooEEE);
doTestSerialization(permissionFooMIP);
doTestSerialization(permissionBarEEE);
doTestSerialization(permissionFooEIP);
doTestSerialization(permissionFooEIE);
doTestSerialization(permissionFooEI);
}
/*
* Testing EJBMethodPermission(String, String, String, String[])
*/
public void testConstructorStringStringStringStringArray() throws Exception {
// methodSpec ::= null
EJBMethodPermission permission = new EJBMethodPermission("foo", null, null, null);
doTestSerialization(permission);
// methodSpec ::= methodNameSpec
permission = new EJBMethodPermission("foo", "", "", null);
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat", "", null);
doTestSerialization(permission);
// methodSpec ::= methodNameSpec comma methodInterface
permission = new EJBMethodPermission("foo", "", "ServiceEndpoint", null);
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat", "ServiceEndpoint", null);
doTestSerialization(permission);
// methodSpec ::= methodNameSpec comma methodInterfaceSpec comma methodParamsSpec
permission = new EJBMethodPermission("foo", "", "", new String[]{});
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat", "", new String[]{});
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "", "Home", new String[]{});
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat", "Home", new String[] {});
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "", "", new String[] { "a", "b", "c", "d", "e"});
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat", "", new String[] { "a", "b", "c", "d", "e"});
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "", "Home", new String[] { "a", "b", "c", "d", "e"});
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat", "Home", new String[] { "a", "b", "c", "d", "e"});
doTestSerialization(permission);
// methodInterface ::= "Home" | "LocalHome" | "Remote" | "Local" | "ServiceEndpoint"
permission = new EJBMethodPermission("foo", "cat", "Home", new String[] { "a", "b", "c", "d", "e"});
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat", "LocalHome", new String[] { "a", "b", "c", "d", "e"});
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat", "Remote", new String[] { "a", "b", "c", "d", "e"});
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat", "Local", new String[] { "a", "b", "c", "d", "e"});
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "cat", "ServiceEndpoint", new String[] { "a", "b", "c", "d", "e"});
doTestSerialization(permission);
assertEquals(permission.getName(), "foo");
assertEquals(permission.getActions(), "cat,ServiceEndpoint,a,b,c,d,e");
// bad methodInterface
try {
permission = new EJBMethodPermission("foo", "cat", "Interface", new String[] { "a", "b", "c", "d", "e"});
fail("Bad method interface");
} catch(IllegalArgumentException iae) {
}
}
public void testImpliesStringStringStringStringArray() throws Exception {
EJBMethodPermission permissionFooEEE = new EJBMethodPermission("foo", "", "", null);
EJBMethodPermission permissionFooMIP = new EJBMethodPermission("foo", "cat", "LocalHome", new String[] { "a", "b", "c", "d", "e"});
EJBMethodPermission permissionBarEEE = new EJBMethodPermission("bar", "", "", new String[] {});
EJBMethodPermission permissionFooEIP = new EJBMethodPermission("foo", "", "LocalHome", new String[] { "a", "b", "c", "d", "e"});
EJBMethodPermission permissionFooEIE = new EJBMethodPermission("foo", "", "LocalHome", new String[] {});
EJBMethodPermission permissionFooEI = new EJBMethodPermission("foo", "", "LocalHome", null);
assertTrue(permissionFooEEE.implies(permissionFooEEE));
assertTrue(permissionFooEEE.implies(permissionFooMIP));
assertTrue(permissionFooEEE.implies(permissionFooEIP));
assertTrue(permissionFooEEE.implies(permissionFooEIE));
assertTrue(permissionFooEEE.implies(permissionFooEI));
assertFalse(permissionFooMIP.implies(permissionFooEEE));
assertTrue(permissionFooEEE.equals(permissionFooEEE));
assertFalse(permissionFooEEE.equals(permissionFooMIP));
assertFalse(permissionFooMIP.equals(permissionFooEEE));
assertFalse(permissionFooEEE.implies(permissionBarEEE));
assertFalse(permissionBarEEE.implies(permissionFooEEE));
assertFalse(permissionFooEEE.equals(permissionBarEEE));
assertFalse(permissionBarEEE.equals(permissionFooEEE));
assertTrue(permissionFooEIP.implies(permissionFooMIP));
assertFalse(permissionFooEIE.implies(permissionFooMIP));
assertTrue(permissionFooEI.implies(permissionFooMIP));
assertTrue(permissionFooEI.implies(permissionFooEIP));
assertTrue(permissionFooEI.implies(permissionFooEIE));
assertFalse(permissionFooEEE.hashCode() == permissionBarEEE.hashCode());
doTestSerialization(permissionFooEEE);
doTestSerialization(permissionFooMIP);
doTestSerialization(permissionBarEEE);
doTestSerialization(permissionFooEIP);
doTestSerialization(permissionFooEIE);
doTestSerialization(permissionFooEI);
}
/*
* Testing EJBMethodPermission(String, String, Method)
*/
public void testConstructorStringStringMethod() throws Exception {
EJBMethodPermission permission = new EJBMethodPermission("foo", "ServiceEndpoint", method);
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", null, method);
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "", method);
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "Home", method);
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "LocalHome", method);
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "Remote", method);
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "Local", method);
doTestSerialization(permission);
permission = new EJBMethodPermission("foo", "ServiceEndpoint", method);
doTestSerialization(permission);
assertEquals(permission.getName(), "foo");
assertEquals(permission.getActions(), "cat,ServiceEndpoint,java.lang.Integer,java.lang.Float,java.lang.Long,java.lang.Double,int[]");
// Parameter method must not be null
try {
permission = new EJBMethodPermission("foo", "ServiceEndpoint", null);
fail("Parameter method must not be null");
} catch(IllegalArgumentException iae) {
}
}
public void testImpliesStringStringMethod() {
}
private void doTestSerialization(EJBMethodPermission permission) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(permission);
oos.flush();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
Object o = ois.readObject();
assertEquals("Permission did not serialize correctly", permission, o);
}
class TestClass {
public Object cat(Integer a, Float b, Long c, Double d, int[] e) {
return null;
}
}
}
| 734 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/WebUserDataPermissionTest.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.Permission;
import junit.framework.TestCase;
/**
* @version $Rev$ $Date$
*/
public class WebUserDataPermissionTest extends TestCase {
/*
* Testing WebResourcePermission(java.lang.String, java.lang.String)
*/
public void testConstructorStringString() {
MockHttpServletRequest request = new MockHttpServletRequest("/portal", "/services/services_jdbc/_rp_services_jdbc_row1_col1_p1_adapterDisplayName/1_TranQL0x8Generic0x8JDBC0x8Resource0x8Adapter/_rp_services_jdbc_row1_col1_p1_rarPath/1_tranql0x3tranql-connector0x310x220x3rar/_rp_services_jdbc_row1_col1_p1_mode/1_params/_rp_services_jdbc_row1_col1_p1_driverClass/1_org0x2hsqldb0x2jdbcDriver/_pm_services_jdbc_row1_col1_p1/view/_rp_services_jdbc_row1_col1_p1_dbtype/1_HSQLDB0x8embedded/_rp_services_jdbc_row1_col1_p1_urlPrototype/1_jdbc:hsqldb:{Database}/_st_services_jdbc_row1_col1_p1/normal/_ps_services_jdbc_row1_col1_p1/normal/_pid/services_jdbc_row1_col1_p1/_md_services_jdbc_row1_col1_p1/view/_rp_services_jdbc_row1_col1_p1_name/1_FFFFF");
new WebUserDataPermission(URLPatternSpec.encodeColons(request), "GET:NONE");
WebUserDataPermission permission = new WebUserDataPermission("/foo", "GET,POST:INTEGRAL");
assertEquals(permission.getName(), "/foo");
assertEquals(permission.getActions(), "GET,POST:INTEGRAL");
permission = new WebUserDataPermission("/foo", "GET,POST,POST,GET:INTEGRAL");
assertEquals(permission.getActions(), "GET,POST:INTEGRAL");
//extension method
permission = new WebUserDataPermission("/foo", "GET,POST,BAR:INTEGRAL");
// bad HTTP method
try {
permission = new WebUserDataPermission("/foo", "GET,POST,B A R:INTEGRAL");
fail("Bad HTTP method");
} catch (IllegalArgumentException iae) {
}
// If you have a colon, then you must have a transportType
try {
permission = new WebUserDataPermission("/foo", "GET,POST,BAR:");
fail("Missing transportType");
} catch (IllegalArgumentException iae) {
}
}
public void testSerialization() throws Exception {
testSerialization(new WebUserDataPermission("/foo", "GET,POST:INTEGRAL"));
testSerialization(new WebUserDataPermission("/foo", "GET,POST:NONE"));
testSerialization(new WebUserDataPermission("/foo", ""));
testSerialization(new WebUserDataPermission("/foo", ":NONE"));
testSerialization(new WebUserDataPermission("/foo", "GET,POST"));
testSerialization(new WebUserDataPermission("/foo", "!:CONFIDENTIAL"));
}
private void testSerialization(WebUserDataPermission permission) throws IOException, ClassNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(permission);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
Object o = ois.readObject();
assertEquals(permission, o);
}
public void testImpliesStringString() {
// An actions string without a transportType is a shorthand for a
// actions string with the value "NONE" as its TransportType
WebUserDataPermission permissionFooGP = new WebUserDataPermission("/foo", "GET,POST:INTEGRAL");
WebUserDataPermission permissionFooE = new WebUserDataPermission("/foo", "");
WebUserDataPermission permissionFooGPN = new WebUserDataPermission("/foo", "GET,POST");
assertTrue(permissionFooE.implies(permissionFooGP));
assertTrue(permissionFooE.implies(permissionFooGPN));
assertFalse(permissionFooGP.implies(permissionFooE));
assertFalse(permissionFooGPN.implies(permissionFooE));
assertTrue(permissionFooGPN.implies(permissionFooGP));
assertFalse(permissionFooGP.implies(permissionFooGPN));
}
/*
* Testing WebResourcePermission(String, String[])
*/
public void testConstructorStringStringArray() {
}
public void testImpliesStringStringArray() {
}
/*
* Testing WebResourcePermission(HttpServletRequest)
*/
public void testConstructorHttpServletRequest() {
Permission p = new WebUserDataPermission(new MockHttpServletRequest("/foo", "", "GET"));
checkPermission(p, "/foo", "GET");
p = new WebUserDataPermission(new MockHttpServletRequest("", "/foo", "GET"));
checkPermission(p, "/foo", "GET");
p = new WebUserDataPermission(new MockHttpServletRequest("/foo", "/foo", "BAR"));
checkPermission(p, "/foo/foo", "BAR");
p = new WebUserDataPermission(new MockHttpServletRequest("/foo", "/foo:bar", "BAR"));
checkPermission(p, "/foo/foo%3Abar", "BAR");
p = new WebUserDataPermission(new MockHttpServletRequest("/foo", "/foo%3Abar", "BAR"));
checkPermission(p, "/foo/foo%3Abar", "BAR");
}
private void checkPermission(Permission p, String name, String actions) {
assertEquals(p.getName(), name);
assertEquals(p.getActions(), actions);
}
public void testImpliesHttpServletRequest() {
}
}
| 735 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/WebResourcePermissionTest.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import java.security.Permission;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import javax.servlet.http.HttpServletRequest;
import junit.framework.TestCase;
/**
* @version $Rev$ $Date$
*/
public class WebResourcePermissionTest extends TestCase {
public void testSerialization() throws Exception {
WebResourcePermission permission = new WebResourcePermission("/bar/*:/bar/stool", "GET,POST");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(permission);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
Object o = ois.readObject();
assertEquals(permission, o);
}
/*
* Testing WebResourcePermission(java.lang.String, java.lang.String)
*/
public void testConstructorStringString() {
// null URLPatternSpec for a WebResourcePermission
try {
new WebResourcePermission(null, "GET,POST");
fail("null URLPatternSpec for a WebResourcePermission");
} catch (IllegalArgumentException iae) {
}
//Default pattern
checkPermission(new WebResourcePermission("/", "GET,POST"), "GET,POST");
checkPermission(new WebResourcePermission("/:/foo", "GET,POST"), "GET,POST");
checkPermission(new WebResourcePermission("/:*.asp", "GET,POST"), "GET,POST");
checkPermission(new WebResourcePermission("/:/foo:*.asp", "GET,POST"), "GET,POST");
checkPermission(new WebResourcePermission("", "GET,POST"), "GET,POST");
checkPermission(new WebResourcePermission("/*", "GET,POST"), "GET,POST");
checkPermission(new WebResourcePermission("/*:/bar/stool", "GET,POST"), "GET,POST");
//default pattern as qualifier
try {
new WebResourcePermission("/bar/*:/*", "GET,POST");
fail("/*:/");
} catch (IllegalArgumentException iae) {
}
try {
new WebResourcePermission("/bar/*:/*", "GET,POST");
fail("/*:/*");
} catch (IllegalArgumentException iae) {
}
try {
new WebResourcePermission("/bar/*:/*", "GET,POST");
fail("/:/");
} catch (IllegalArgumentException iae) {
}
try {
new WebResourcePermission("/bar/*:/*", "GET,POST");
fail("/:/*");
} catch (IllegalArgumentException iae) {
}
//Exact pattern
checkPermission(new WebResourcePermission("/foo", "GET,POST"), "GET,POST");
// missing qualifiers
try {
new WebResourcePermission("/foo:", "GET,POST");
fail("/foo:");
} catch (IllegalArgumentException iae) {
}
// qualifer provided when first pattern is exact
try {
new WebResourcePermission("/foo:/foo/bar", "GET,POST");
fail("/foo:/foo/bar");
} catch (IllegalArgumentException iae) {
}
//default pattern as a qualifier
try {
new WebResourcePermission("/foo:/", "GET,POST");
fail("/foo:/");
} catch (IllegalArgumentException iae) {
}
//Path prefix pattern
checkPermission(new WebResourcePermission("/bar/*", "GET,POST"), "GET,POST");
checkPermission(new WebResourcePermission("/bar/*:/bar/stool", "GET,POST"), "GET,POST");
try {
new WebResourcePermission("/foo/*:*.asp", "GET,POST");
fail("/foo/*:*.asp");
} catch (IllegalArgumentException iae) {
}
//first pattern doesn't match qualifier
try {
new WebResourcePermission("/bar/*:/cat/stool/*", "GET,POST");
fail("/bar/*:/cat/stool/*");
} catch (IllegalArgumentException iae) {
}
try {
new WebResourcePermission("/bar/stool/*:/bar", "GET,POST");
fail("/bar/stool/*:/bar");
} catch (IllegalArgumentException iae) {
}
try {
new WebResourcePermission("/bar/stool/*:/bar/*", "GET,POST");
fail("/bar/stool/*:/bar/stool/*");
} catch (IllegalArgumentException iae) {
}
//qualifier is same as first pattern
try {
new WebResourcePermission("/bar/stool/*:/bar/stool/*", "GET,POST");
fail("/bar/stool/*:/bar/stool/*");
} catch (IllegalArgumentException iae) {
}
//default pattern as qualifier
try {
new WebResourcePermission("/bar/*:/*", "GET,POST");
fail("/bar/*:/");
} catch (IllegalArgumentException iae) {
}
//Extension pattern
checkPermission(new WebResourcePermission("*.do", "GET,POST"), "GET,POST");
checkPermission(new WebResourcePermission("*.do:/login.do", "GET,POST"), "GET,POST");
checkPermission(new WebResourcePermission("*.do:/foo/*", "GET,POST"), "GET,POST");
//default pattern as qualifier
try {
new WebResourcePermission("*.do:/*", "GET,POST");
fail("*.do:/*");
} catch (IllegalArgumentException iae) {
}
//qualifier is extension pattern
try {
new WebResourcePermission("*.do:*.jsp", "GET,POST");
fail("*.do:/*");
} catch (IllegalArgumentException iae) {
}
//qualifier is exact and does not match first pattern
try {
new WebResourcePermission("*.do:/login", "GET,POST");
fail("*.do:/*");
} catch (IllegalArgumentException iae) {
}
//HTTP method
checkPermission(new WebResourcePermission("/foo", "GET,POST,POST,GET"), "GET,POST");
checkPermission(new WebResourcePermission("/foo", "GET,POST,BAR"), "GET,POST,BAR");
try {
new WebResourcePermission("/foo", "GET,POST,B A R");
fail("Bad HTTP method");
} catch (IllegalArgumentException iae) {
}
// bad HTTP method for a WebResourcePermission
try {
new WebResourcePermission("/foo", "GET,POST:INTEGRAL");
fail("integrity constraint in a WebResourcePermission accepted");
} catch (IllegalArgumentException iae) {
}
}
private void checkPermission(Permission permission, String actions) {
assertTrue(permission.equals(permission));
assertEquals(actions, permission.getActions());
}
public void testExcluded() {
WebResourcePermission permission = new WebResourcePermission("/foo", "!GET,POST");
assertTrue(permission.equals(permission));
assertEquals(permission.getName(), "/foo");
assertEquals(permission.getActions(), "!GET,POST");
permission = new WebResourcePermission("/foo", "!GET,POST,POST,GET");
assertEquals(permission.getActions(), "!GET,POST");
permission = new WebResourcePermission("/foo", "!GET,POST,BAR");
// bad HTTP method
try {
permission = new WebResourcePermission("/foo", "!GET,POST,B A R");
fail("Bad HTTP method");
} catch (IllegalArgumentException iae) {
}
// bad HTTP method for a WebResourcePermission
try {
permission = new WebResourcePermission("/foo", "!GET,POST:INTEGRAL");
} catch (IllegalArgumentException iae) {
}
// null URLPatternSpec for a WebResourcePermission
try {
permission = new WebResourcePermission(null, "!GET,POST");
fail("null URLPatternSpec for a WebResourcePermission");
} catch (IllegalArgumentException iae) {
}
}
public void testImpliesStringString() {
// The argument is an instanceof WebResourcePermission
Permission pA = new WebResourcePermission("/foo", "");
Permission pB = new WebUserDataPermission("/foo", "");
assertFalse(pA.implies(pB));
assertFalse(pB.implies(pA));
pA = new WebResourcePermission("/foo", "");
pB = new WebResourcePermission("/foo", "GET,POST");
assertTrue(pA.implies(pB));
assertFalse(pB.implies(pA));
pA = new WebResourcePermission("/foo/*:/foo/bar", "");
pB = new WebResourcePermission("/foo/bar", "");
assertFalse(pA.implies(pB));
assertFalse(pB.implies(pA));
pA = new WebResourcePermission("/foo/bar/*:/foo/bar/cat/dog", "");
pB = new WebResourcePermission("/foo/bar/*:/foo/bar/cat/*", "");
assertTrue(pA.implies(pB));
assertFalse(pB.implies(pA));
pA = new WebResourcePermission("/:/a.jsp:/b.jsp:/c.jsp", "GET,POST,PUT,DELETE,HEAD,OPTIONS,TRACE");
pB = new WebResourcePermission("/:/a.jsp:/c.jsp:/b.jsp", (String) null);
// assertTrue(pA.implies(pB)); // no longer true with extension methods
assertTrue(pB.implies(pA));
}
public void testImpliesExtensionExcludes() {
//test against all permissions
WebResourcePermission pA = new WebResourcePermission("/foo", "FOO,BAR,fizzle");
WebResourcePermission pB = new WebResourcePermission("/foo", (String) null);
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
assertTrue(pA.implies(pA));
assertTrue(pB.implies(pB));
pA = new WebResourcePermission("/foo", "!FOO,BAR,fizzle");
pB = new WebResourcePermission("/foo", (String) null);
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
assertTrue(pA.implies(pA));
pA = new WebResourcePermission("/foo", "GET,POST");
pB = new WebResourcePermission("/foo", (String) null);
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
pA = new WebResourcePermission("/foo", "!GET,POST");
pB = new WebResourcePermission("/foo", (String) null);
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
//both positive sets
pA = new WebResourcePermission("/foo", "GET,POST");
pB = new WebResourcePermission("/foo", "GET,POST,OPTIONS");
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
pA = new WebResourcePermission("/foo", "GET,POST");
pB = new WebResourcePermission("/foo", "GET,POST,FOO");
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
pA = new WebResourcePermission("/foo", "GET,FOO");
pB = new WebResourcePermission("/foo", "GET,BAR,FOO");
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
pA = new WebResourcePermission("/foo", "FOO,BAR");
pB = new WebResourcePermission("/foo", "FOO,BAR,fizzle");
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
//both exclusions
pA = new WebResourcePermission("/foo", "!FOO,BAR,fizzle");
pB = new WebResourcePermission("/foo", "!FOO,BAR");
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
pA = new WebResourcePermission("/foo", "!GET,POST,FOO");
pB = new WebResourcePermission("/foo", "!GET,POST");
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
pA = new WebResourcePermission("/foo", "!GET,BAR,FOO");
pB = new WebResourcePermission("/foo", "!GET,BAR");
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
pA = new WebResourcePermission("/foo", "!GET,POST,OPTIONS");
pB = new WebResourcePermission("/foo", "!GET,POST");
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
//one of each
pA = new WebResourcePermission("/foo", "GET");
pB = new WebResourcePermission("/foo", "!FOO,BAR");
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
pA = new WebResourcePermission("/foo", "fizzle");
pB = new WebResourcePermission("/foo", "!FOO,BAR");
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
pA = new WebResourcePermission("/foo", "GET");
pB = new WebResourcePermission("/foo", "!POST");
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
pA = new WebResourcePermission("/foo", "GET");
pB = new WebResourcePermission("/foo", "!POST,BAR");
assertFalse(pA.implies(pB));
assertTrue(pB.implies(pA));
}
/*
* Testing WebResourcePermission(String, String[])
*/
public void testConstructorStringStringArray() {
}
public void testImpliesStringStringArray() {
}
/*
* Testing WebResourcePermission(HttpServletRequest)
*/
public void testConstructorHttpServletRequest() {
Permission p = new WebResourcePermission(new MockHttpServletRequest("/foo", "", "GET"));
checkPermission(p, "/foo", "GET");
p = new WebResourcePermission(new MockHttpServletRequest("", "/foo", "GET"));
checkPermission(p, "/foo", "GET");
p = new WebResourcePermission(new MockHttpServletRequest("/foo", "/foo", "BAR"));
checkPermission(p, "/foo/foo", "BAR");
p = new WebResourcePermission(new MockHttpServletRequest("/foo", "/foo:bar", "BAR"));
checkPermission(p, "/foo/foo%3Abar", "BAR");
p = new WebResourcePermission(new MockHttpServletRequest("/foo", "/foo%3Abar", "BAR"));
checkPermission(p, "/foo/foo%3Abar", "BAR");
}
private void checkPermission(Permission p, String name, String actions) {
assertEquals(p.getName(), name);
assertEquals(p.getActions(), actions);
}
public void testImpliesHttpServletRequest() {
}
public void testGetActions() {
WebResourcePermission p = new WebResourcePermission("/foo", "");
assertEquals(p.getActions(), "");
p = new WebResourcePermission("/foo", "!GET,POST");
assertEquals(p.getActions(), "!GET,POST");
p = new WebResourcePermission("/foo", "!POST,GET");
assertEquals(p.getActions(), "!GET,POST");
p = new WebResourcePermission("/foo", "!POST,GET,GET,POST");
assertEquals(p.getActions(), "!GET,POST");
//extension methods follow regular methods
p = new WebResourcePermission("/foo", "FOO,BAR,POST,FOO,GET,GET,POST");
assertEquals("GET,POST,BAR,FOO", p.getActions());
p = new WebResourcePermission("/foo", "!FOO,BAR,POST,FOO,GET,GET,POST");
assertEquals("!GET,POST,BAR,FOO", p.getActions());
}
public static void main(String[] args) {
WebResourcePermissionTest test = new WebResourcePermissionTest();
test.testConstructorStringString();
test.testImpliesStringString();
test.testConstructorStringStringArray();
test.testImpliesStringStringArray();
test.testConstructorHttpServletRequest();
test.testImpliesHttpServletRequest();
}
}
| 736 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/WebRoleRefPermissionTest.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import junit.framework.TestCase;
/**
* @version $Rev$ $Date$
*/
public class WebRoleRefPermissionTest extends TestCase {
public void test() {
WebRoleRefPermission permission1 = new WebRoleRefPermission("foo", "bar");
WebRoleRefPermission permission2 = new WebRoleRefPermission("foo", "bar");
WebRoleRefPermission permission3 = new WebRoleRefPermission("foo", "cat");
assertTrue(permission1.implies(permission1));
assertTrue(permission1.implies(permission2));
assertTrue(permission2.implies(permission1));
assertTrue(permission1.equals(permission1));
assertTrue(permission1.equals(permission2));
assertTrue(permission2.equals(permission1));
assertFalse(permission1.implies(permission3));
assertFalse(permission3.implies(permission1));
assertFalse(permission1.equals(permission3));
assertFalse(permission3.equals(permission1));
assertEquals(permission1.getName(), "foo");
assertEquals(permission1.getActions(), "bar");
assertEquals(permission1.hashCode(), permission2.hashCode());
}
}
| 737 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/MockHttpServletRequest.java | /*
* 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 javax.security.jacc;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletInputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* @version $Rev$ $Date$
*/
public class MockHttpServletRequest implements HttpServletRequest {
private final String servletPath;
private final String pathInfo;
private final String method;
public MockHttpServletRequest(String servletPath, String pathInfo) {
this.servletPath = servletPath;
this.pathInfo = pathInfo;
this.method = "GET";
}
public MockHttpServletRequest(String servletPath, String pathInfo, String method) {
this.servletPath = servletPath;
this.pathInfo = pathInfo;
this.method = method;
}
public String getAuthType() {
return null;
}
public Cookie[] getCookies() {
return new Cookie[0];
}
public long getDateHeader(String transOID) {
return 0;
}
public String getHeader(String transOID) {
return null;
}
public Enumeration getHeaders(String transOID) {
return null;
}
public Enumeration getHeaderNames() {
return null;
}
public int getIntHeader(String transOID) {
return 0;
}
public String getMethod() {
return method;
}
public String getPathInfo() {
return pathInfo;
}
public String getPathTranslated() {
return null;
}
public String getContextPath() {
return null;
}
public String getQueryString() {
return null;
}
public String getRemoteUser() {
return null;
}
public boolean isUserInRole(String transOID) {
return false;
}
public Principal getUserPrincipal() {
return null;
}
public String getRequestedSessionId() {
return null;
}
public String getRequestURI() {
return null;
}
public StringBuffer getRequestURL() {
return null;
}
public String getServletPath() {
return servletPath;
}
public HttpSession getSession(boolean b) {
return null;
}
public HttpSession getSession() {
return null;
}
public boolean isRequestedSessionIdValid() {
return false;
}
public boolean isRequestedSessionIdFromCookie() {
return false;
}
public boolean isRequestedSessionIdFromURL() {
return false;
}
public boolean isRequestedSessionIdFromUrl() {
return false;
}
public Object getAttribute(String transOID) {
return null;
}
public Enumeration getAttributeNames() {
return null;
}
public String getCharacterEncoding() {
return null;
}
public void setCharacterEncoding(String transOID) throws UnsupportedEncodingException {
}
public int getContentLength() {
return 0;
}
public String getContentType() {
return null;
}
public ServletInputStream getInputStream() throws IOException {
return null;
}
public String getParameter(String transOID) {
return null;
}
public Enumeration getParameterNames() {
return null;
}
public String[] getParameterValues(String transOID) {
return new String[0];
}
public Map getParameterMap() {
return null;
}
public String getProtocol() {
return null;
}
public String getScheme() {
return null;
}
public String getServerName() {
return null;
}
public int getServerPort() {
return 0;
}
public BufferedReader getReader() throws IOException {
return null;
}
public String getRemoteAddr() {
return null;
}
public String getRemoteHost() {
return null;
}
public void setAttribute(String transOID, Object object) {
}
public void removeAttribute(String transOID) {
}
public Locale getLocale() {
return null;
}
public Enumeration getLocales() {
return null;
}
public boolean isSecure() {
return false;
}
public RequestDispatcher getRequestDispatcher(String transOID) {
return null;
}
public String getRealPath(String transOID) {
return null;
}
public int getRemotePort() {
return 0;
}
public String getLocalName() {
return null;
}
public String getLocalAddr() {
return null;
}
public int getLocalPort() {
return 0;
}
}
| 738 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/EJBMethodPermissionCollectionTest.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import junit.framework.TestCase;
import java.security.PermissionCollection;
import java.security.Permission;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.util.Enumeration;
/**
* @version $Rev$ $Date$
*/
public class EJBMethodPermissionCollectionTest extends TestCase {
public void testWildCards() {
PermissionCollection collection = new EJBMethodPermission("HelloWorld", "").newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", ""));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",,")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",Local")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,")));
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", "")));
collection = new EJBMethodPermission("HelloWorld", "").newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", ",,a,b,c"));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,")));
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", ",,a,b,c")));
collection = new EJBMethodPermission("HelloWorld", "").newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", ",,"));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,")));
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", ",,")));
collection = new EJBMethodPermission("HelloWorld", "").newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", ",Local"));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",Local")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,")));
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", ",Local")));
collection = new EJBMethodPermission("HelloWorld", "").newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", ",Local,a,b,c"));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,")));
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", ",Local,a,b,c")));
collection = new EJBMethodPermission("HelloWorld", "").newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", ",Local,"));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,")));
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", ",Local,")));
collection = new EJBMethodPermission("HelloWorld", "").newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", "hello"));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,")));
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", "hello")));
collection = new EJBMethodPermission("HelloWorld", "").newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", "hello,,a,b,c"));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,")));
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", "hello,,a,b,c")));
collection = new EJBMethodPermission("HelloWorld", "").newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", "hello,,"));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,")));
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", "hello,,")));
collection = new EJBMethodPermission("HelloWorld", "").newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", "hello,Local"));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,")));
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", "hello,Local")));
collection = new EJBMethodPermission("HelloWorld", "").newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c"));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,")));
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", "hello,Local,a,b,c")));
collection = new EJBMethodPermission("HelloWorld", "").newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", "hello,Local,"));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", ",Local,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,a,b,c")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,,")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local")));
assertFalse(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,a,b,c")));
assertTrue(collection.implies(new EJBMethodPermission("HelloWorld", "hello,Local,")));
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", "hello,Local,")));
}
public void testSerialization() throws Exception {
EJBMethodPermission p = new EJBMethodPermission("HelloWorld", "");
PermissionCollection collection = p.newPermissionCollection();
collection.add(new EJBMethodPermission("HelloWorld", ""));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(collection);
oos.flush();
byte[] bytes = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
PermissionCollection collection2 = (PermissionCollection) ois.readObject();
Enumeration <Permission> ps = collection2.elements();
Permission p2 = ps.nextElement();
assertEquals(p2, p);
assertFalse(ps.hasMoreElements());
assertTrue(collection2.implies(p));
}
}
| 739 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/PolicyConfigurationFactory.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.SecurityPermission;
import org.apache.geronimo.osgi.locator.ProviderLocator;
/**
* Abstract factory and finder class for obtaining the instance of the class
* that implements the PolicyConfigurationFactory of a provider. The factory
* will be used to instantiate PolicyConfiguration objects that will be used
* by the deployment tools of the container to create and manage policy
* contexts within the Policy Provider.
*
* Implementation classes must have a public no argument constructor that may
* be used to create an operational instance of the factory implementation class.
* @see java.security.Permission
* @see PolicyConfiguration
* @see PolicyContextException
*
* @version $Rev$ $Date$
*/
public abstract class PolicyConfigurationFactory {
private final static String FACTORY_NAME = "javax.security.jacc.PolicyConfigurationFactory.provider";
private static PolicyConfigurationFactory policyConfigurationFactory;
/**
* This static method uses a system property to find and instantiate (via a
* public constructor) a provider specific factory implementation class.
* The name of the provider specific factory implementation class is
* obtained from the value of the system property,<p>
* <code>javax.security.jacc.PolicyConfigurationFactory.provider</code>.
* @return the singleton instance of the provider specific
* PolicyConfigurationFactory implementation class.
* @throws ClassNotFoundException when the class named by the system
* property could not be found including because the value of the system
* property has not be set.
* @throws PolicyContextException if the implementation throws a checked
* exception that has not been accounted for by the
* getPolicyConfigurationFactory method signature. The exception thrown by
* the implementation class will be encapsulated (during construction) in
* the thrown PolicyContextException
*/
public static PolicyConfigurationFactory getPolicyConfigurationFactory() throws ClassNotFoundException, PolicyContextException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) sm.checkPermission(new SecurityPermission("setPolicy"));
if (policyConfigurationFactory != null) return policyConfigurationFactory;
final String[] factoryClassName = { null };
try {
policyConfigurationFactory = (PolicyConfigurationFactory)AccessController.doPrivileged(new
PrivilegedExceptionAction() {
public Object run() throws Exception
{
factoryClassName[0] = System.getProperty(FACTORY_NAME);
if (factoryClassName[0] == null) throw new ClassNotFoundException("Property " + FACTORY_NAME + " not set");
Thread currentThread = Thread.currentThread();
ClassLoader tccl = currentThread.getContextClassLoader();
return ProviderLocator.loadClass(factoryClassName[0], PolicyConfigurationFactory.class, tccl).newInstance();
}
});
} catch(PrivilegedActionException pae) {
if (pae.getException() instanceof ClassNotFoundException) {
throw (ClassNotFoundException)pae.getException();
} else if (pae.getException() instanceof InstantiationException) {
throw new ClassNotFoundException(factoryClassName[0] + " could not be instantiated");
} else if (pae.getException() instanceof IllegalAccessException) {
throw new ClassNotFoundException("Illegal access to " + factoryClassName);
}
throw new PolicyContextException(pae.getException());
}
return policyConfigurationFactory;
}
/**
* This method is used to obtain an instance of the provider specific class
* that implements the PolicyConfiguration interface that corresponds to
* the identified policy context within the provider. The methods of the
* PolicyConfiguration interface are used to define the policy statements
* of the identified policy context.<p>
*
* If at the time of the call, the identified policy context does not exist
* in the provider, then the policy context will be created in the provider
* and the Object that implements the context's PolicyConfiguration
* Interface will be returned. If the state of the identified context is
* "deleted" or "inService" it will be transitioned to the "open" state as
* a result of the call. The states in the lifecycle of a policy context
* are defined by the PolicyConfiguration interface.<p>
*
* For a given value of policy context identifier, this method must always
* return the same instance of PolicyConfiguration and there must be at
* most one actual instance of a PolicyConfiguration with a given policy
* context identifier (during a process context). <p>
*
* To preserve the invariant that there be at most one PolicyConfiguration
* object for a given policy context, it may be necessary for this method
* to be thread safe.
* @param contextID A String identifying the policy context whose
* PolicyConfiguration interface is to be returned. The value passed to
* this parameter must not be null.
* @param remove A boolean value that establishes whether or not the policy
* statements of an existing policy context are to be removed before its
* PolicyConfiguration object is returned. If the value passed to this
* parameter is true, the policy statements of an existing policy context
* will be removed. If the value is false, they will not be removed.
* @return an Object that implements the PolicyConfiguration Interface
* matched to the Policy provider and corresponding to the identified
* policy context.
* @throws PolicyContextException if the implementation throws a checked
* exception that has not been accounted for by the getPolicyConfiguration
* method signature. The exception thrown by the implementation class will
* be encapsulated (during construction) in the thrown PolicyContextException.
*/
public abstract javax.security.jacc.PolicyConfiguration getPolicyConfiguration(String contextID, boolean remove) throws PolicyContextException;
/**
* This method determines if the identified policy context exists with
* state "inService" in the Policy provider associated with the factory.
* @param contextID A string identifying a policy context
* @return true if the identified policy context exists within the provider
* and its state is "inService", false otherwise.
* @throws PolicyContextException if the implementation throws a checked
* exception that has not been accounted for by the inService method
* signature. The exception thrown by the implementation class will be
* encapsulated (during construction) in the thrown PolicyContextException.
*/
public abstract boolean inService(String contextID) throws PolicyContextException;
}
| 740 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/WebRoleRefPermission.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import java.io.Serializable;
import java.security.Permission;
/**
* @version $Rev$ $Date$
*/
public final class WebRoleRefPermission extends Permission implements Serializable {
private static final long serialVersionUID = 1L;
private transient int cachedHashCode = 0;
private String actions;
public WebRoleRefPermission(String name, String role) {
super(name);
actions = role;
}
public boolean equals(Object o) {
if (o == null || !(o instanceof WebRoleRefPermission)) return false;
WebRoleRefPermission other = (WebRoleRefPermission)o;
return getName().equals(other.getName()) && actions.equals(other.actions);
}
public String getActions() {
return actions;
}
public int hashCode() {
if (cachedHashCode == 0) {
cachedHashCode = getName().hashCode() ^ actions.hashCode();
}
return cachedHashCode;
}
public boolean implies(Permission permission) {
return equals(permission);
}
}
| 741 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/PolicyContextHandler.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
/**
* This interface defines the methods that must be implemented by handlers that
* are to be registered and activated by the <code>PolicyContext</code> class.
* The <code>PolicyContext</code> class provides methods for containers to
* register and activate container-specific <code>PolicyContext</code> handlers.
* <code>Policy</code> providers use the <code>PolicyContext</code> class to
* activate handlers to obtain (from the container) additional policy relevant
* context to apply in their access decisions. All handlers registered and
* activated via the <code>PolicyContext</code> class must implement the
* <code>PolicyContextHandler</code> interface.
*
* @version $Rev$ $Date$
*/
public interface PolicyContextHandler {
/**
* This public method returns a boolean result indicating whether or not
* the handler supports the context object identified by the
* (case-sensitive) key value.
* @param key a <code>String</code< value identifying a context object
* that could be supported by the handler. The value of this parameter
* must not be null.
* @return a boolean indicating whether or not the context object
* corresponding to the argument key is handled by the handler.
* @throws PolicyContextException if the implementation throws a checked
* exception that has not been accounted for by the method signature. The
* exception thrown by the implementation class will be encapsulated
* (during construction) in the thrown PolicyContextException
*/
public boolean supports(String key) throws PolicyContextException;
/**
* This public method returns the keys identifying the context objects
* supported by the handler. The value of each key supported by a handler
* must be a non-null String value.
* @return an array containing String values identifing the context objects
* supported by the handler. The array must not contain duplicate key
* values. In the unlikely case that the Handler supports no keys, the
* handler must return a zero length array. The value null must never be
* returned by this method.
* @throws PolicyContextException if the implementation throws a checked
* exception that has not been accounted for by the method signature. The
* exception thrown by the implementation class will be encapsulated
* (during construction) in the thrown PolicyContextException
*/
public String[] getKeys() throws PolicyContextException;
/**
* This public method is used by the <code>PolicyContext/<code> class to
* activate the handler and obtain from it the the context object
* identified by the (case-sensitive) key. In addition to the key, the
* handler will be activated with the handler data value associated within
* the <code>PolicyContext</code> class with the thread on which the call
* to this method is made.<p>
*
* Note that the policy context identifier associated with a thread is
* available to the handler by calling PolicyContext.getContextID().
* @param key a String that identifies the context object to be returned by
* the handler. The value of this paramter must not be null.
* @param data the handler data <code>Object</code> associated with the
* thread on which the call to this method has been made. Note that the
* value passed through this parameter may be null.
* @return The container and handler specific <code>Object</code>
* containing the desired context. A null value may be returned if the
* value of the corresponding context is null.
* @throws PolicyContextException if the implementation throws a checked
* exception that has not been accounted for by the method signature. The
* exception thrown by the implementation class will be encapsulated
* (during construction) in the thrown PolicyContextException
*/
public Object getContext(String key, Object data) throws PolicyContextException;
}
| 742 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/PolicyContextException.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
/**
* @version $Rev$ $Date$
*/
public class PolicyContextException extends Exception {
public PolicyContextException() {
super();
}
public PolicyContextException(String msg) {
super(msg);
}
public PolicyContextException(String msg, Throwable cause) {
super(msg, cause);
}
public PolicyContextException(Throwable cause) {
super(cause);
}
}
| 743 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/EJBRoleRefPermission.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import java.io.Serializable;
import java.security.Permission;
/**
* Class for EJB <code>isCallerInRole(String reference)</code> permissions. An
* EJBRoleRefPermission is a named permission and has actions.<p>
*
* The name of an EJBRoleRefPermission contains the value of the ejb-name
* element in the application's deployment descriptor that identifies the EJB
* in whose context the permission is being evalutated.<p>
*
* The actions of an EJBRoleRefPermission identifies the role reference to
* which the permission applies. An EJBRoleRefPermission is checked to
* determine if the subject is a member of the role identified by the reference.
*
* @version $Rev$ $Date$
*/
public final class EJBRoleRefPermission extends Permission implements Serializable {
private transient int cachedHashCode = 0;
private String actions;
/**
* Creates a new EJBRoleRefPermission with the specified name and actions.
* @param name the ejb-name that identifies the EJB in whose context the
* role references are to be evaluated.
* @param role identifies the role reference to which the permission
* pertains. The role reference is scoped to the EJB identified in the
* name parameter. The value of the role reference must not be null or
* the empty string.
*/
public EJBRoleRefPermission(String name, String role) {
super(name);
if (role == null || role.length() == 0)
throw new IllegalArgumentException("Role reference must not be null or the empty string");
actions = role;
}
/**
* Checks two EJBRoleRefPermission objects for equality. EJBRoleRefPermission
* objects are equivalent if they have case equivalent name and actions values.<p>
*
* Two Permission objects, P1 and P2, are equivalent if and only if P1.implies(P2) && P2.implies(P1).
* @param o the EJBRoleRefPermission object being tested for equality with this EJBRoleRefPermission.
* @return true if the argument EJBRoleRefPermission object is equivalent to this EJBRoleRefPermission.
*/
public boolean equals(Object o) {
if (o == null || !(o instanceof EJBRoleRefPermission)) return false;
EJBRoleRefPermission other = (EJBRoleRefPermission)o;
return getName().equals(other.getName()) && actions.equals(other.actions);
}
/**
* Returns a canonical String representation of the actions of this EJBRoleRefPermission.
* @return a String containing the canonicalized actions of this EJBRoleRefPermission.
*/
public String getActions() {
return actions;
}
/**
* Returns the hash code value for this EJBRoleRefPermission. The properties
* of the returned hash code must be as follows:
* <ul>
* <li>During the lifetime of a Java application, the hashCode method must
* return the same integer value, every time it is called on a EJBRoleRefPermission
* object. The value returned by hashCode for a particular EJBRoleRefPermission
* need not remain consistent from one execution of an application to another.</li>
* <li>If two EJBRoleRefPermission objects are equal according to the equals
* method, then calling the hashCode method on each of the two Permission
* objects must produce the same integer result (within an application).</li>
* </ul>
* @return the integer hash code value for this object.
*/
public int hashCode() {
if (cachedHashCode == 0) {
cachedHashCode = getName().hashCode() ^ actions.hashCode();
}
return cachedHashCode;
}
/**
* Determines if the argument Permission is "implied by" this
* EJBRoleRefPermission. For this to be the case,
*
* <ul>
* <li>The argument must be an instanceof EJBRoleRefPermission</li>
* <li>with name equivalent to that of this EJBRoleRefPermission, and</li>
* <li>with the role reference equivalent to that of this EJBRoleRefPermission applies.</li>
* <ul>
* The name and actions comparisons described above are case sensitive.
* @param permission "this" EJBRoleRefPermission is checked to see if it implies the argument permission.
* @return true if the specified permission is implied by this object, false if not.
*/
public boolean implies(Permission permission) {
return equals(permission);
}
}
| 744 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/URLPatternSpec.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import java.util.Iterator;
import java.util.LinkedList;
import javax.servlet.http.HttpServletRequest;
/**
* @version $Rev$ $Date$
*/
final class URLPatternSpec {
private final String pattern;
private final URLPattern first;
private final LinkedList qualifiers = new LinkedList();
public URLPatternSpec(String name) {
if (name == null) throw new java.lang.IllegalArgumentException("URLPatternSpec cannot be null");
if (name.length() == 0) name = "/";
pattern = name;
String[] tokens = pattern.split(":", -1);
first = new URLPattern(tokens[0]);
URLPattern candidate;
for (int i = 1; i < tokens.length; i++) {
candidate = new URLPattern(tokens[i]);
// No pattern may exist in the URLPatternList that matches the first pattern.
if (candidate.matches(first)) {
throw new java.lang.IllegalArgumentException("Qualifier patterns in the URLPatternSpec cannot match the first URLPattern");
}
if (first.type == URLPattern.PATH_PREFIX) {
// If the first pattern is a path-prefix pattern, only exact patterns
// matched by the first pattern and path-prefix patterns matched by,
// but different from, the first pattern may occur in the URLPatternList.
if (candidate.type == URLPattern.EXACT && !first.matches(candidate)) {
throw new java.lang.IllegalArgumentException("Exact qualifier patterns in the URLPatternSpec must be matched by the first URLPattern");
} else if (candidate.type == URLPattern.PATH_PREFIX
&& !(first.matches(candidate)
&& first.pattern.length() < candidate.pattern.length())) {
throw new java.lang.IllegalArgumentException("path-prefix qualifier patterns in the URLPatternSpec must be matched by, but different from, the first URLPattern");
} else if (candidate.type == URLPattern.EXTENSION) {
throw new java.lang.IllegalArgumentException("extension qualifier patterns in the URLPatternSpec are not allowed when the first URLPattern is path-prefix");
}
} else if (first.type == URLPattern.EXTENSION) {
// If the first pattern is an extension pattern, only exact patterns
// that are matched by the first pattern and path-prefix patterns may
// occur in the URLPatternList.
if (candidate.type == URLPattern.EXACT) {
if (!first.matches(candidate)) {
throw new java.lang.IllegalArgumentException("Exact qualifier patterns in the URLPatternSpec must be matched when first URLPattern is an extension pattern");
}
} else if (candidate.type != URLPattern.PATH_PREFIX) {
throw new java.lang.IllegalArgumentException("Only exact and path-prefix qualifiers in the URLPatternSpec are allowed when first URLPattern is an extension pattern");
}
} else if (first.type == URLPattern.DEFAULT) {
// If the first pattern is the default pattern, "/", any pattern
// except the default pattern may occur in the URLPatternList.
if (candidate.type == URLPattern.DEFAULT) {
//This is actually tested for by the "qualifier must not match first" rule
throw new java.lang.IllegalArgumentException("Qualifier patterns must not be default when first URLPattern is a default pattern");
}
} else if (first.type == URLPattern.EXACT) {
// If the first pattern is an exact pattern a URLPatternList
// must not be present in the URLPatternSpec
throw new java.lang.IllegalArgumentException("Qualifier patterns must not be present when first URLPattern is an exact pattern");
}
qualifiers.add(candidate);
}
}
public boolean equals(URLPatternSpec o) {
return implies(o) && o.implies(this);
}
public int hashCode() {
return pattern.hashCode();
}
public String getPatternSpec() {
return pattern;
}
public String toString() {
return pattern;
}
public boolean implies(URLPatternSpec p) {
// The first URLPattern in the name of the argument permission is
// matched by the first URLPattern in the name of this permission.
if (!first.matches(p.first)) return false;
// The first URLPattern in the name of the argument permission is NOT
// matched by any URLPattern in the URLPatternList of the URLPatternSpec
// of this permission.
Iterator iter1 = qualifiers.iterator();
while (iter1.hasNext()) {
if (((URLPattern) iter1.next()).matches(p.first)) return false;
}
// If the first URLPattern in the name of the argument permission
// matches the first URLPattern in the URLPatternSpec of this
// permission, then every URLPattern in the URLPatternList of the
// URLPatternSpec of this permission is matched by a URLPattern in
// the URLPatternList of the argument permission.
if (p.first.matches(first)) {
Iterator iter2 = p.qualifiers.iterator();
while (iter2.hasNext()) {
Iterator iter3 = qualifiers.iterator();
URLPattern test = (URLPattern) iter2.next();
boolean found = false;
while (iter3.hasNext()) {
if (test.matches((URLPattern) iter3.next())) {
found = true;
break;
}
}
if (!found) return false;
}
}
return true;
}
static String encodeColons(HttpServletRequest request) {
String result = request.getServletPath() + (request.getPathInfo() == null ? "" : request.getPathInfo());
if (result.indexOf(":") > -1) result = result.replaceAll(":", "%3A");
return result;
}
private class URLPattern {
public final static int EXACT = 0x0;
public final static int PATH_PREFIX = 0x1;
public final static int EXTENSION = 0x2;
public final static int DEFAULT = 0x4;
public int type;
public String pattern;
public URLPattern(String pat) {
if (pat == null) throw new java.lang.IllegalArgumentException("URLPattern cannot be null");
if (pat.length() == 0) throw new java.lang.IllegalArgumentException("URLPattern cannot be empty");
if (pat.equals("/") || pat.equals("/*")) {
type = DEFAULT;
} else if (pat.charAt(0) == '/' && pat.endsWith("/*")) {
type = PATH_PREFIX;
} else if (pat.charAt(0) == '*') {
type = EXTENSION;
} else {
type = EXACT;
}
pattern = pat;
}
public boolean matches(URLPattern p) {
String test = p.pattern;
// their pattern values are String equivalent
if (pattern.equals(test)) return true;
switch (type) {
// this pattern is a path-prefix pattern (that is, it starts
// with "/" and ends with "/*") and the argument pattern
// starts with the substring of this pattern, minus its last
// 2 characters, and the next character of the argument pattern,
// if there is one, is "/"
case PATH_PREFIX: {
int length = pattern.length() - 2;
if (length > test.length()) return false;
for (int i = 0; i < length; i++) {
if (pattern.charAt(i) != test.charAt(i)) return false;
}
if (test.length() == length) return true;
else if (test.charAt(length) != '/') return false;
return true;
}
// this pattern is an extension pattern (that is, it starts
// with "*.") and the argument pattern ends with this pattern
case EXTENSION: {
return test.endsWith(pattern.substring(1));
}
// this pattern is the path-prefix pattern "/*" or
// the reference pattern is the special default pattern,
// "/", which matches all argument patterns
case DEFAULT: {
return true;
}
}
return false;
}
}
}
| 745 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/EJBMethodPermission.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.PrivilegedAction;
import java.util.LinkedList;
import java.util.HashMap;
import java.util.Enumeration;
import java.util.Collections;
import java.util.HashSet;
/**
* @version $Rev$ $Date$
*/
public final class EJBMethodPermission extends Permission implements Serializable {
private static final long serialVersionUID = 1L;
private final static String NEW_METHOD_INTERFACES = "org.apache.security.jacc.EJBMethodPermission.methodInterfaces";
private static String[] methodInterfaces;
static {
String newMethodInterfaces = AccessController.doPrivileged(new
PrivilegedAction<String>() {
public String run() {
return System.getProperty(NEW_METHOD_INTERFACES);
}
});
if (newMethodInterfaces != null) {
newMethodInterfaces = newMethodInterfaces + ",Home,LocalHome,Remote,Local,ServiceEndpoint";
} else {
newMethodInterfaces = "Home,LocalHome,Remote,Local,ServiceEndpoint";
}
methodInterfaces = newMethodInterfaces.split(",", -1);
}
private transient int cachedHashCode;
private transient MethodSpec methodSpec;
public EJBMethodPermission(String name, String spec) {
super(name);
methodSpec = new MethodSpec(spec);
}
public EJBMethodPermission(String EJBName, String methodName, String methodInterface, String[] methodParams) {
super(EJBName);
methodSpec = new MethodSpec(methodName, methodInterface, methodParams);
}
public EJBMethodPermission(String EJBName, String methodInterface, Method method) {
super(EJBName);
if (method == null) throw new IllegalArgumentException("Parameter method must not be null");
methodSpec = new MethodSpec(methodInterface, method);
}
public boolean equals(Object o) {
if (o == null || !(o instanceof EJBMethodPermission)) return false;
EJBMethodPermission other = (EJBMethodPermission) o;
return getName().equals(other.getName()) && methodSpec.equals(other.methodSpec);
}
public String getActions() {
return methodSpec.getActions();
}
public int hashCode() {
if (cachedHashCode == 0) {
cachedHashCode = getName().hashCode() ^ methodSpec.hashCode();
}
return cachedHashCode;
}
public boolean implies(Permission permission) {
if (permission == null || !(permission instanceof EJBMethodPermission)) return false;
EJBMethodPermission other = (EJBMethodPermission) permission;
return getName().equals(other.getName()) && methodSpec.implies(other.methodSpec);
}
public PermissionCollection newPermissionCollection() {
return new EJBMethodPermissionCollection();
}
private synchronized void readObject(ObjectInputStream in) throws IOException {
methodSpec = new MethodSpec(in.readUTF());
}
private synchronized void writeObject(ObjectOutputStream out) throws IOException {
out.writeUTF(methodSpec.getActions());
}
private static class MethodSpec {
protected String methodName;
protected String methodInterface;
protected String methodParams;
protected String actions;
public MethodSpec(String actionString) {
if (actionString == null || actionString.length() == 0) {
methodName = null;
methodInterface = null;
methodParams = null;
actions = "";
} else {
String[] tokens = actionString.split(",", 3);
switch (tokens.length) {
case 1:
{
methodName = emptyNullCheck(tokens[0]);
methodInterface = null;
methodParams = null;
break;
}
case 2:
{
if (tokens[1].length() == 0) throw new IllegalArgumentException("This format of actions requires a method interface");
checkMethodInterface(tokens[1]);
methodName = emptyNullCheck(tokens[0]);
methodInterface = emptyNullCheck(tokens[1]);
methodParams = null;
break;
}
case 3:
{
checkMethodInterface(tokens[1]);
if (tokens[2].indexOf(',') > -1) {
String[] test = tokens[2].split(",", -1);
for (String aTest : test) {
if (aTest.length() == 0) throw new IllegalArgumentException("Invalid type name");
}
}
methodName = emptyNullCheck(tokens[0]);
methodInterface = emptyNullCheck(tokens[1]);
methodParams = tokens[2];
}
}
actions = actionString;
}
}
public MethodSpec(String mthdName, String mthdInterface, String[] methodParamsArray) {
checkMethodInterface(mthdInterface);
methodName = emptyNullCheck(mthdName);
methodInterface = emptyNullCheck(mthdInterface);
if (methodParamsArray == null) {
methodParams = null;
} else if (methodParamsArray.length == 0) {
methodParams = "";
} else {
if (methodParamsArray[0] == null || methodParamsArray[0].length() == 0) throw new IllegalArgumentException("Invalid type name");
StringBuilder buffer = new StringBuilder(methodParamsArray[0]);
for (int i = 1; i < methodParamsArray.length; i++) {
if (methodParamsArray[i] == null || methodParamsArray[i].length() == 0) throw new IllegalArgumentException("Invalid type name");
buffer.append(",");
buffer.append(methodParamsArray[i]);
}
methodParams = buffer.toString();
}
initActions();
}
public MethodSpec(String mthdInterface, Method method) {
checkMethodInterface(mthdInterface);
methodName = method.getName();
methodInterface = emptyNullCheck(mthdInterface);
Class[] paramTypes = method.getParameterTypes();
if (paramTypes.length == 0) {
methodParams = "";
} else {
StringBuilder buffer = new StringBuilder(paramTypes[0].getName());
for (int i = 1; i < paramTypes.length; i++) {
buffer.append(",");
getName(paramTypes[i], buffer);
}
methodParams = buffer.toString();
}
initActions();
}
private static void getName(Class<?> paramType, StringBuilder buffer){
if(paramType.isArray()){
getName(paramType.getComponentType(), buffer);
buffer.append("[]");
}else{
buffer.append(paramType.getName());
}
}
public boolean equals(MethodSpec spec) {
return implies(spec) && spec.implies(this);
}
public String getActions() {
return actions;
}
public int hashCode() {
return actions.hashCode();
}
public boolean implies(MethodSpec methodSpec) {
if (methodName == null || methodName.equals(methodSpec.methodName)) {
if (methodInterface == null || methodInterface.equals(methodSpec.methodInterface)) {
if (methodParams == null || methodParams.equals(methodSpec.methodParams)) {
return true;
} else
return false;
} else
return false;
} else
return false;
}
private void initActions() {
if (methodParams == null) {
if (methodInterface == null) {
if (methodName == null) {
actions = "";
} else {
actions = methodName;
}
} else {
if (methodName == null) {
actions = "," + methodInterface;
} else {
actions = methodName + "," + methodInterface;
}
}
} else {
if (methodInterface == null) {
if (methodName == null) {
actions = ",," + methodParams;
} else {
actions = methodName + ",," + methodParams;
}
} else {
if (methodName == null) {
actions = "," + methodInterface + "," + methodParams;
} else {
actions = methodName + "," + methodInterface + "," + methodParams;
}
}
}
}
private void checkMethodInterface(String methodInterface) {
if (methodInterface == null || methodInterface.length() == 0) return;
for (int i = 0; i < methodInterfaces.length; i++) {
if (methodInterfaces[i].equals(methodInterface)) return;
}
throw new IllegalArgumentException("Invalid method interface: " + methodInterface);
}
/**
* For the method name, method interface, and method parameters, a
* value of <CODE>null</CODE> indicates a wildcard value. This
* function is used to check if we are passed a <CODE>null</CODE>
* or empty string, which indicates a wildcard.
*
* @param name The name to be checked.
* @return <CODE>null</CODE> if we are passed a <CODE>null</CODE> or empty string else
* we return the name.
*/
private String emptyNullCheck(String name) {
if (name != null && name.length() == 0) {
return null;
} else {
return name;
}
}
}
private static final class EJBMethodPermissionCollection extends PermissionCollection {
private static final long serialVersionUID = -3557818912959683053L;
private static final String WILDCARD = "$WILDCARD";
private static final HashMap<String, HashMap<String, HashSet<String>>> ALL_METHODS = new HashMap<String, HashMap<String, HashSet<String>>>();
private LinkedList<Permission> collection = new LinkedList<Permission>();
private transient HashMap<String, HashMap<String, HashMap<String, HashSet<String>>>> permissions = new HashMap<String, HashMap<String, HashMap<String, HashSet<String>>>>();
/**
* Adds a permission object to the current collection of permission objects.
*
* @param permission the Permission object to add.
*
* @exception SecurityException - if this PermissionCollection object
* has been marked readonly
*/
public void add(Permission permission) {
if (isReadOnly()) throw new IllegalArgumentException("Read only collection");
if (!(permission instanceof EJBMethodPermission)) throw new IllegalArgumentException("Wrong permission type");
EJBMethodPermission p = (EJBMethodPermission)permission;
if (collection.contains(p)) return;
else collection.add(p);
addEJBMethodPermission(p);
}
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
permissions = new HashMap<String, HashMap<String, HashMap<String, HashSet<String>>>>();
for (Permission p: collection) {
addEJBMethodPermission((EJBMethodPermission)p);
}
}
private void addEJBMethodPermission(EJBMethodPermission p) {
MethodSpec spec = p.methodSpec;
HashMap<String, HashMap<String, HashSet<String>>> methods = permissions.get(p.getName());
if (methods == ALL_METHODS) return;
if (spec.methodName == null && spec.methodInterface == null && spec.methodParams == null) {
permissions.put(p.getName(), ALL_METHODS);
return;
}
if (methods == null) {
methods = new HashMap<String, HashMap<String, HashSet<String>>>();
permissions.put(p.getName(), methods);
}
String methodKey = (spec.methodName == null || spec.methodName.length() == 0? WILDCARD:spec.methodName);
HashMap<String, HashSet<String>> interfaces = methods.get(methodKey);
if (interfaces == null) {
interfaces = new HashMap<String, HashSet<String>>();
methods.put(methodKey, interfaces);
}
String interfaceKey = (spec.methodInterface == null || spec.methodInterface.length() == 0? WILDCARD:spec.methodInterface);
HashSet<String> parameters = interfaces.get(interfaceKey);
if (parameters == null) {
parameters = new HashSet<String>();
interfaces.put(interfaceKey, parameters);
}
// an empty string for a parameter spec indicates a method w/ no parameters
String parametersKey = (spec.methodParams == null? WILDCARD:spec.methodParams);
if (!parameters.contains(parametersKey)) {
parameters.add(parametersKey);
}
}
/**
* Checks to see if the specified permission is implied by
* the collection of Permission objects held in this PermissionCollection.
*
* @param permission the Permission object to compare.
*
* @return true if "permission" is implied by the permissions in
* the collection, false if not.
*/
public boolean implies(Permission permission) {
if (!(permission instanceof EJBMethodPermission)) return false;
EJBMethodPermission p = (EJBMethodPermission)permission;
EJBMethodPermission.MethodSpec spec = p.methodSpec;
HashMap<String, HashMap<String, HashSet<String>>> methods = permissions.get(p.getName());
if (methods == null) return false;
if (methods == ALL_METHODS) return true;
String methodKey = (spec.methodName == null || spec.methodName.length() == 0? WILDCARD:spec.methodName);
HashMap<String, HashSet<String>> interfaces = methods.get(methodKey);
if (methodImplies(interfaces, spec)) return true;
if (methodKey != WILDCARD) {
return methodImplies(methods.get(WILDCARD), spec);
}
return false;
}
protected boolean methodImplies(HashMap<String, HashSet<String>> interfaces, EJBMethodPermission.MethodSpec spec) {
if (interfaces == null) return false;
String interfaceKey = (spec.methodInterface == null || spec.methodInterface.length() == 0? WILDCARD:spec.methodInterface);
HashSet<String> parameters = interfaces.get(interfaceKey);
if (interfaceImplies(parameters, spec)) return true;
if (interfaceKey != WILDCARD) {
return interfaceImplies(interfaces.get(WILDCARD), spec);
}
return false;
}
protected boolean interfaceImplies(HashSet<String> parameters, EJBMethodPermission.MethodSpec spec) {
if (parameters == null) return false;
// An empty string for a parameter spec indicates a method w/ no parameters
// so we won't convert an empty string to a wildcard.
String parametersKey = (spec.methodParams == null? WILDCARD:spec.methodParams);
if (parameters.contains(parametersKey)) return true;
if (parametersKey != WILDCARD) {
return parameters.contains(WILDCARD);
}
return false;
}
/**
* Returns an enumeration of all the Permission objects in the collection.
*
* @return an enumeration of all the Permissions.
*/
public Enumeration<Permission> elements() {
return Collections.enumeration(collection);
}
}
}
| 746 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/PolicyContext.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import java.security.SecurityPermission;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* @version $Rev$ $Date$
*/
public final class PolicyContext {
private final static ThreadLocal<String> contextId = new ThreadLocal<String>();
private final static ThreadLocal<Object> handlerData = new ThreadLocal<Object>();
private static volatile Map<String, PolicyContextHandler> handlers = new HashMap<String, PolicyContextHandler>();
private final static SecurityPermission SET_POLICY = new SecurityPermission("setPolicy");
private PolicyContext() {
}
public static void setContextID(String contextID) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) sm.checkPermission(SET_POLICY);
contextId.set(contextID);
}
public static String getContextID() {
return contextId.get();
}
public static void setHandlerData(Object data) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) sm.checkPermission(SET_POLICY);
handlerData.set(data);
}
public static void registerHandler(String key, PolicyContextHandler handler, boolean replace) throws PolicyContextException {
if (key == null) throw new IllegalArgumentException("Key must not be null");
if (handler == null) throw new IllegalArgumentException("Handler must not be null");
if (!handler.supports(key)) throw new IllegalArgumentException("Registered handler does not support the key '" + key + "'");
SecurityManager sm = System.getSecurityManager();
if (sm != null) sm.checkPermission(SET_POLICY);
synchronized (PolicyContext.class) {
if (!replace && handlers.containsKey(key))
throw new IllegalArgumentException("A handler has already been registered under '" + key + "' and replace is false.");
Map<String, PolicyContextHandler> newHandlers = new HashMap<String, PolicyContextHandler>(handlers);
newHandlers.put(key, handler);
handlers = newHandlers;
}
}
public static Set getHandlerKeys() {
return handlers.keySet();
}
public static Object getContext(String key) throws PolicyContextException {
if (key == null) throw new IllegalArgumentException("Key must not be null");
PolicyContextHandler handler = handlers.get(key);
if (handler == null) throw new IllegalArgumentException("No handler can be found for the key '" + key + "'");
if (!handler.supports(key)) throw new IllegalArgumentException("Registered handler no longer supports the key '" + key + "'");
SecurityManager sm = System.getSecurityManager();
if (sm != null) sm.checkPermission(SET_POLICY);
return handler.getContext(key, handlerData.get());
}
}
| 747 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/WebUserDataPermission.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.security.Permission;
import java.security.PermissionCollection;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
/**
* Class for Servlet Web user data permissions. A WebUserDataPermission is a
* named permission and has actions.<p>
* <p/>
* The name of a WebUserDataPermission (also referred to as the target name)
* identifies a Web resource by its context path relative URL pattern.
*
* @version $Rev$ $Date$
*
* @see java.security.Permission
*/
public final class WebUserDataPermission extends Permission implements Serializable {
private static final long serialVersionUID = 1L;
private transient int cachedHashCode = 0;
private transient URLPatternSpec urlPatternSpec;
private transient HTTPMethodSpec httpMethodSpec;
/**
* Creates a new WebUserDataPermission from the HttpServletRequest object.
*
* @param request the HttpServletRequest object corresponding to the
* Servlet operation to which the permission pertains. The permission
* name is the substring of the requestURI (HttpServletRequest.getRequestURI())
* that begins after the contextPath (HttpServletRequest.getContextPath()).
* When the substring operation yields the string �/�, the permission is
* constructed with the empty string as its name. The HTTP method component
* of the permission�s actions is as obtained from HttpServletRequest.getMethod().
* The TransportType component of the permission�s actions is determined
* by calling HttpServletRequest.isSecure().
*/
public WebUserDataPermission(HttpServletRequest request) {
super(URLPatternSpec.encodeColons(request));
urlPatternSpec = new URLPatternSpec(getName());
httpMethodSpec = new HTTPMethodSpec(request.getMethod(), request.isSecure()? HTTPMethodSpec.CONFIDENTIAL: HTTPMethodSpec.NONE);
}
public WebUserDataPermission(String name, String actions) {
super(name);
urlPatternSpec = new URLPatternSpec(name);
httpMethodSpec = new HTTPMethodSpec(actions, true);
}
public WebUserDataPermission(String urlPattern, String[] HTTPMethods, String transportType) {
super(urlPattern);
urlPatternSpec = new URLPatternSpec(urlPattern);
httpMethodSpec = new HTTPMethodSpec(HTTPMethods, transportType == null? "NONE": transportType);
}
public boolean equals(Object o) {
if (o == null || !(o instanceof WebUserDataPermission)) return false;
WebUserDataPermission other = (WebUserDataPermission) o;
return urlPatternSpec.equals(other.urlPatternSpec) && httpMethodSpec.equals(other.httpMethodSpec);
}
public String getActions() {
return httpMethodSpec.getActions();
}
public int hashCode() {
if (cachedHashCode == 0) {
cachedHashCode = urlPatternSpec.hashCode() ^ httpMethodSpec.hashCode();
}
return cachedHashCode;
}
public boolean implies(Permission permission) {
if (permission == null || !(permission instanceof WebUserDataPermission)) return false;
WebUserDataPermission other = (WebUserDataPermission) permission;
return urlPatternSpec.implies(other.urlPatternSpec) && httpMethodSpec.implies(other.httpMethodSpec);
}
public PermissionCollection newPermissionCollection() {
return new WebUserDataPermissionCollection();
}
private synchronized void readObject(ObjectInputStream in) throws IOException {
urlPatternSpec = new URLPatternSpec(in.readUTF());
httpMethodSpec = new HTTPMethodSpec(in.readUTF(), true);
}
private synchronized void writeObject(ObjectOutputStream out) throws IOException {
out.writeUTF(urlPatternSpec.getPatternSpec());
out.writeUTF(httpMethodSpec.getActions());
}
private static final class WebUserDataPermissionCollection extends PermissionCollection {
private Hashtable permissions = new Hashtable();
/**
* Adds a permission object to the current collection of permission objects.
*
* @param permission the Permission object to add.
*
* @exception SecurityException - if this PermissionCollection object
* has been marked readonly
*/
public void add(Permission permission) {
if (isReadOnly()) throw new IllegalArgumentException("Read only collection");
if (!(permission instanceof WebUserDataPermission)) throw new IllegalArgumentException("Wrong permission type");
WebUserDataPermission p = (WebUserDataPermission)permission;
permissions.put(p, p);
}
/**
* Checks to see if the specified permission is implied by
* the collection of Permission objects held in this PermissionCollection.
*
* @param permission the Permission object to compare.
*
* @return true if "permission" is implied by the permissions in
* the collection, false if not.
*/
public boolean implies(Permission permission) {
if (!(permission instanceof WebUserDataPermission)) return false;
WebUserDataPermission p = (WebUserDataPermission)permission;
Enumeration e = permissions.elements();
while (e.hasMoreElements()) {
if (((WebUserDataPermission)e.nextElement()).implies(p)) return true;
}
return false;
}
/**
* Returns an enumeration of all the Permission objects in the collection.
*
* @return an enumeration of all the Permissions.
*/
public Enumeration elements() {
return permissions.elements();
}
}
}
| 748 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/WebResourcePermission.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.security.Permission;
import java.security.PermissionCollection;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
/**
* @version $Rev$ $Date$
*/
public final class WebResourcePermission extends Permission implements Serializable {
private static final long serialVersionUID = 1L;
private transient int cachedHashCode = 0;
private transient URLPatternSpec urlPatternSpec;
private transient HTTPMethodSpec httpMethodSpec;
public WebResourcePermission(HttpServletRequest request) {
super(URLPatternSpec.encodeColons(request));
urlPatternSpec = new URLPatternSpec(getName());
httpMethodSpec = new HTTPMethodSpec(request.getMethod(), HTTPMethodSpec.NA);
}
public WebResourcePermission(String name, String actions) {
super(name);
urlPatternSpec = new URLPatternSpec(name);
httpMethodSpec = new HTTPMethodSpec(actions, false);
}
public WebResourcePermission(String urlPattern, String[] HTTPMethods) {
super(urlPattern);
urlPatternSpec = new URLPatternSpec(urlPattern);
httpMethodSpec = new HTTPMethodSpec(HTTPMethods);
}
public boolean equals(Object o) {
if (o == null || !(o instanceof WebResourcePermission)) return false;
WebResourcePermission other = (WebResourcePermission) o;
return urlPatternSpec.equals(other.urlPatternSpec) && httpMethodSpec.equals(other.httpMethodSpec);
}
public String getActions() {
return httpMethodSpec.getActions();
}
public int hashCode() {
if (cachedHashCode == 0) {
cachedHashCode = urlPatternSpec.hashCode() ^ httpMethodSpec.hashCode();
}
return cachedHashCode;
}
public boolean implies(Permission permission) {
if (permission == null || !(permission instanceof WebResourcePermission)) return false;
WebResourcePermission other = (WebResourcePermission) permission;
return urlPatternSpec.implies(other.urlPatternSpec) && httpMethodSpec.implies(other.httpMethodSpec);
}
public PermissionCollection newPermissionCollection() {
return new WebResourcePermissionCollection();
}
private synchronized void readObject(ObjectInputStream in) throws IOException {
urlPatternSpec = new URLPatternSpec(in.readUTF());
httpMethodSpec = new HTTPMethodSpec(in.readUTF(), false);
}
private synchronized void writeObject(ObjectOutputStream out) throws IOException {
out.writeUTF(urlPatternSpec.getPatternSpec());
out.writeUTF(httpMethodSpec.getActions());
}
private static final class WebResourcePermissionCollection extends PermissionCollection {
private Hashtable permissions = new Hashtable();
/**
* Adds a permission object to the current collection of permission objects.
*
* @param permission the Permission object to add.
*
* @exception SecurityException - if this PermissionCollection object
* has been marked readonly
*/
public void add(Permission permission) {
if (isReadOnly()) throw new IllegalArgumentException("Read only collection");
if (!(permission instanceof WebResourcePermission)) throw new IllegalArgumentException("Wrong permission type");
WebResourcePermission p = (WebResourcePermission)permission;
permissions.put(p, p);
}
/**
* Checks to see if the specified permission is implied by
* the collection of Permission objects held in this PermissionCollection.
*
* @param permission the Permission object to compare.
*
* @return true if "permission" is implied by the permissions in
* the collection, false if not.
*/
public boolean implies(Permission permission) {
if (!(permission instanceof WebResourcePermission)) return false;
WebResourcePermission p = (WebResourcePermission)permission;
Enumeration e = permissions.elements();
while (e.hasMoreElements()) {
if (((WebResourcePermission)e.nextElement()).implies(p)) return true;
}
return false;
}
/**
* Returns an enumeration of all the Permission objects in the collection.
*
* @return an enumeration of all the Permissions.
*/
public Enumeration elements() {
return permissions.elements();
}
}
}
| 749 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/HTTPMethodSpec.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Pattern;
/**
* @version $Rev$ $Date$
*/
final class HTTPMethodSpec {
private final static String[] HTTP_METHODS = {"GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE"};
private final static int[] HTTP_MASKS = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40};
final static int NA = 0x00;
final static int INTEGRAL = 0x01;
final static int CONFIDENTIAL = 0x02;
final static int NONE = INTEGRAL | CONFIDENTIAL;
private final int mask;
private final String[] extensionMethods;
private final boolean isExcluded;
private final int transport;
private String actions;
private static final String[] NO_METHODS = new String[0];
private static final Pattern TOKEN_PATTERN = Pattern.compile("[!-~&&[^\\(\\)\\<\\>@,;:\\\\\"/\\[\\]\\?=\\{\\}]]*");
public HTTPMethodSpec(String[] HTTPMethods) {
this(HTTPMethods, null);
}
public HTTPMethodSpec(String name, boolean parseTransportType) {
if (parseTransportType) {
if (name == null || name.length() == 0) {
this.transport = NONE;
} else {
String[] tokens = name.split(":", 2);
if (tokens.length == 2) {
if (tokens[1].equals("NONE")) {
this.transport = NONE;
} else if (tokens[1].equals("INTEGRAL")) {
this.transport = INTEGRAL;
} else if (tokens[1].equals("CONFIDENTIAL")) {
this.transport = CONFIDENTIAL;
} else {
throw new IllegalArgumentException("Invalid transportType: " + tokens[1]);
}
} else {
this.transport = NONE;
}
name = tokens[0];
}
} else {
this.transport = NA;
}
if (name == null || name.length() == 0) {
this.mask = 0x00;
this.extensionMethods = NO_METHODS;
this.isExcluded = true;
} else {
ArrayList<String> extensions = null;
if (isExcluded = name.charAt(0) == '!') {
name = name.substring(1);
}
int tmpMask = 0;
if (name.length() > 0) {
String[] methods = name.split(",", -1);
for (int i = 0; i < methods.length; i++) {
boolean found = false;
for (int j = 0; j < HTTP_METHODS.length; j++) {
if (methods[i].equals(HTTP_METHODS[j])) {
tmpMask |= HTTP_MASKS[j];
found = true;
break;
}
}
if (!found) {
checkToken(methods[i]);
if (extensions == null) {
extensions = new ArrayList<String>(methods.length);
}
add(extensions, methods[i]);
}
}
}
this.mask = tmpMask;
if (extensions == null) {
extensionMethods = NO_METHODS;
} else {
extensionMethods = extensions.toArray(new String[extensions.size()]);
}
}
}
public HTTPMethodSpec(String[] HTTPMethods, String transport) {
boolean parseTransportType = transport != null;
if (HTTPMethods == null || HTTPMethods.length == 0) {
this.mask = 0x00;
this.extensionMethods = NO_METHODS;
this.isExcluded = true;
} else {
int tmpMask = 0;
this.isExcluded = false;
ArrayList<String> extensions = null;
for (int i = 0; i < HTTPMethods.length; i++) {
boolean found = false;
for (int j = 0; j < HTTP_METHODS.length; j++) {
if (HTTPMethods[i].equals(HTTP_METHODS[j])) {
tmpMask |= HTTP_MASKS[j];
found = true;
break;
}
}
if (!found) {
checkToken(HTTPMethods[i]);
if (extensions == null) {
extensions = new ArrayList<String>(HTTPMethods.length);
}
add(extensions, HTTPMethods[i]);
}
}
this.mask = tmpMask;
if (extensions == null) {
extensionMethods = NO_METHODS;
} else {
extensionMethods = extensions.toArray(new String[extensions.size()]);
}
}
if (parseTransportType) {
if (transport.length() == 0 || transport.equals("NONE")) {
this.transport = NONE;
} else if (transport.equals("INTEGRAL")) {
this.transport = INTEGRAL;
} else if (transport.equals("CONFIDENTIAL")) {
this.transport = CONFIDENTIAL;
} else {
throw new IllegalArgumentException("Invalid transport");
}
} else {
this.transport = NA;
}
}
public HTTPMethodSpec(String singleMethod, int transport) {
int tmpMask = 0;
for (int j = 0; j < HTTP_METHODS.length; j++) {
if (HTTP_METHODS[j].equals(singleMethod)) {
tmpMask = HTTP_MASKS[j];
break;
}
}
if (tmpMask == 0) {
checkToken(singleMethod);
this.extensionMethods = new String[]{singleMethod};
} else {
this.extensionMethods = NO_METHODS;
}
this.mask = tmpMask;
this.isExcluded = false;
this.transport = transport;
}
private void checkToken(String method) {
if (!TOKEN_PATTERN.matcher(method).matches()) {
throw new IllegalArgumentException("Invalid HTTPMethodSpec");
}
}
private void add(ArrayList<String> extensions, String httpMethod) {
for (int i = 0; i < extensions.size(); i++) {
String existingMethod = extensions.get(i);
int compare = existingMethod.compareTo(httpMethod);
if (compare == 0) {
return;
}
if (compare > 0) {
extensions.add(i, httpMethod);
return;
}
}
extensions.add(httpMethod);
}
public boolean equals(HTTPMethodSpec o) {
return mask == o.mask && transport == o.transport && isExcluded == o.isExcluded && Arrays.equals(extensionMethods, o.extensionMethods);
}
public String getActions() {
if (actions == null) {
StringBuilder buffer;
if (isAllHttpActions()) {
if (hasTransportGuarantee()) {
buffer = new StringBuilder();
} else {
return "";
}
} else {
buffer = new StringBuilder();
if (isExcluded) {
buffer.append("!");
}
boolean first = true;
for (int i = 0; i < HTTP_MASKS.length; i++) {
if ((mask & HTTP_MASKS[i]) > 0) {
if (first) {
first = false;
} else {
buffer.append(",");
}
buffer.append(HTTP_METHODS[i]);
}
}
for (String method : extensionMethods) {
if (first) {
first = false;
} else {
buffer.append(",");
}
buffer.append(method);
}
}
if (hasTransportGuarantee()) {
if (transport == INTEGRAL) {
buffer.append(":INTEGRAL");
} else if (transport == CONFIDENTIAL) {
buffer.append(":CONFIDENTIAL");
}
}
actions = buffer.toString();
}
return actions;
}
private boolean isAllHttpActions() {
return isExcluded && mask == 0x00 && extensionMethods.length == 0;
}
private boolean hasTransportGuarantee() {
return !(transport == NA || transport == NONE);
}
public int hashCode() {
return mask ^ (transport <<8) ^ (isExcluded? 0:0x200);
}
public String toString() {
return getActions();
}
public boolean implies(HTTPMethodSpec p) {
if ((transport & p.transport) != p.transport) {
return false;
}
if (isExcluded) {
if (p.isExcluded) {
return ((mask & p.mask) == mask) && contains(p.extensionMethods, extensionMethods);
} else {
return ((mask & p.mask) == 0x00) && isDisjoint(extensionMethods, p.extensionMethods);
}
} else {
if (p.isExcluded) {
return false;
} else {
return ((mask & p.mask) == p.mask) && contains(extensionMethods, p.extensionMethods);
}
}
}
private boolean isDisjoint(String[] a, String[] b) {
int start = 0;
for (int i = 0; i < a.length; i++) {
String s = a[i];
for (int j = start; j < b.length; j++) {
String s1 = b[j];
int compare = s.compareTo(s1);
if (compare == 0) {
return false;
}
if (compare < 0) {
start = j;
break;
}
}
}
return true;
}
private boolean contains(String[] set, String[] subset) {
int start = 0;
for (int i = 0; i < subset.length; i++) {
boolean found = false;
String s = subset[i];
for (int j = start; j < set.length; j++) {
String s1 = set[j];
int compare = s.compareTo(s1);
if (compare == 0) {
found = true;
start = j + 1;
break;
}
if (compare < 0) {
return false;
}
}
if (!found) {
return false;
}
}
return true;
}
}
| 750 |
0 | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security | Create_ds/geronimo-specs/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/PolicyConfiguration.java | /*
* 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.
*/
//
// This source code implements specifications defined by the Java
// Community Process. In order to remain compliant with the specification
// DO NOT add / change / or delete method signatures!
//
package javax.security.jacc;
import java.security.Permission;
import java.security.PermissionCollection;
/**
* @version $Rev$ $Date$
*/
public interface PolicyConfiguration {
public String getContextID() throws PolicyContextException;
public void addToRole(String roleName, PermissionCollection permissions) throws PolicyContextException;
public void addToRole(String roleName, Permission permission) throws PolicyContextException;
public void addToUncheckedPolicy(PermissionCollection permissions) throws PolicyContextException;
public void addToUncheckedPolicy(Permission permission) throws PolicyContextException;
public void addToExcludedPolicy(PermissionCollection permissions) throws PolicyContextException;
public void addToExcludedPolicy(Permission permission) throws PolicyContextException;
public void removeRole(String roleName) throws PolicyContextException;
public void removeUncheckedPolicy() throws PolicyContextException;
public void removeExcludedPolicy() throws PolicyContextException;
public void linkConfiguration(PolicyConfiguration link) throws PolicyContextException;
public void delete() throws PolicyContextException;
public void commit() throws PolicyContextException;
public boolean inService() throws PolicyContextException;
}
| 751 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/Activator.java | /**
* 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.geronimo.osgi.locator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
public class Activator implements BundleActivator {
protected BundleContext bundleContext;
public synchronized void start(BundleContext bundleContext) throws Exception {
this.bundleContext = bundleContext;
// initialize the locator
ProviderLocator.init(bundleContext);
}
public synchronized void stop(BundleContext bundleContext) throws Exception {
// shut down the locator service
ProviderLocator.destroy();
this.bundleContext = null;
}
public void bundleChanged(BundleEvent event) {
// nothing to change here
}
}
| 752 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java | /**
* 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.geronimo.osgi.locator;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
// Via great attention to detail, all of the imports below
// are optional and the related classes are not loaded unless
// the specified conditions are met.
// COND: running in an OSGi environment and the Activator has been activated
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
// COND: the above + the geronimo-osgi-registry is installed and visible
import org.apache.geronimo.osgi.registry.api.ProviderRegistry;
// NB in comments is Nota Bene (note well)
// http://en.wikipedia.org/wiki/Nota_bene
public class ProviderLocator {
// our bundle context
static private BundleContext context;
// a service tracker for the registry service
// NB: This is declared as just Object to avoid classloading issues if we're running
// outside of an OSGi environment.
static private Object registryTracker;
private ProviderLocator() {
// private constructor to prevent an instance from getting created.
}
/**
* initialize the tracker statics for this bundle
*
* @param c The starup BundleContext.
*/
public static void init(BundleContext c) {
try {
// just create a tracker for our lookup service
// NB: We use the hard coded name in case the registry service has not
// been started first. The ServiceTracker itself only uses the string name.
// We need to avoid trying to load the ProviderRegistry interface until the
// registry tracker returns a non-null service instance.
registryTracker = new ServiceTracker(c, "org.apache.geronimo.osgi.registry.api.ProviderRegistry", null);
((ServiceTracker)registryTracker).open();
// do this last...it helps indicate if we have an initialized registry.
context = c;
} catch (Throwable e) {
// It is expected that the ServiceTracker constructor will fail if the
// ProviderRegistry class cannot be loaded.
// if there were any errors, then the registry is not available.
registryTracker = null;
}
}
/**
* Cleanup resources on bundle shutdown.
*/
public static void destroy() {
if (registryTracker != null) {
// shutdown our tracking of the provider registry.
((ServiceTracker)registryTracker).close();
registryTracker = null;
}
}
/**
* Locate a class by its provider id indicator. .
*
* @param providerId The provider id (generally, a fully qualified class name).
*
* @return The Class corresponding to this provider id. Returns null
* if this is not registered or the indicated class can't be
* loaded.
*/
static public Class<?> locate(String providerId) {
Object registry = getRegistry();
// if no registry service available, this is a failure
if (registry == null) {
return null;
}
// get the service, if it exists. NB, if there is a service object,
// then the extender and the interface class are available, so this cast should be
// safe now.
// the rest of the work is done by the registry
return ((ProviderRegistry)registry).locate(providerId);
}
/**
* Locate all class files that match a given factory id.
*
* @param providerId The target provider identifier.
*
* @return A List containing the class objects corresponding to the
* provider identifier. Returns an empty list if no
* matching classes can be located.
*/
static public List<Class<?>> locateAll(String providerId) {
Object registry = getRegistry();
// if no registry service available, this is a failure
if (registry == null) {
return new ArrayList<Class<?>>();
}
// get the service, if it exists. NB, if there is a service object,
// then the extender and the interface class are available, so this cast should be
// safe now.
// the rest of the work is done by the registry
return ((ProviderRegistry)registry).locateAll(providerId);
}
/**
* Utility class for locating a class with OSGi registry
* support. Uses the thread context classloader as part of
* the search order.
*
* @param className The name of the target class.
*
* @return The loaded class.
* @exception ClassNotFoundException
* Thrown if the class cannot be located.
*/
static public Class<?> loadClass(String className) throws ClassNotFoundException {
return loadClass(className, null, Thread.currentThread().getContextClassLoader());
}
/**
* Utility class for locating a class with OSGi registry
* support. Uses the thread context classloader as part of
* the search order.
*
* @param className The name of the target class.
*
* @return The loaded class.
* @exception ClassNotFoundException
* Thrown if the class cannot be located.
*/
static public Class<?> loadClass(String className, Class<?> contextClass) throws ClassNotFoundException {
return loadClass(className, contextClass, Thread.currentThread().getContextClassLoader());
}
/**
* Standardized utility method for performing class lookups
* with support for OSGi registry lookups.
*
* @param className The name of the target class.
* @param loader An optional class loader.
*
* @return The loaded class
* @exception ClassNotFoundException
* Thrown if the class cannot be loaded.
*/
static public Class<?> loadClass(String className, Class<?>contextClass, ClassLoader loader) throws ClassNotFoundException {
// ideally, this should be last. However, some of the bundles duplicate classes
// found on the boot delegation, so we need to check this first to keep
// from picking up one of the default implementations.
Class cls = locate(className);
if (cls != null) {
return cls;
}
if (loader != null) {
try {
return loader.loadClass(className);
} catch (ClassNotFoundException x) {
}
}
if (contextClass != null) {
loader = contextClass.getClassLoader();
}
// try again using the class context loader
return Class.forName(className, true, loader);
}
/**
* Get a single service instance that matches an interface
* definition.
*
* @param iface The name of the required interface.
* @param contextClass
* The class requesting the lookup (used for class resolution).
* @param loader A class loader to use for searching for service definitions
* and loading classes.
*
* @return The service instance, or null if no matching services
* can be found.
* @exception Exception Thrown for any classloading or exceptions thrown
* trying to instantiate a service instance.
*/
static public Object getService(String iface, Class<?> contextClass, ClassLoader loader) throws Exception {
// if we are working in an OSGi environment, then process the service
// registry first. Ideally, we would do this last, but because of boot delegation
// issues with some API implementations, we must try the OSGi version first
Object registry = getRegistry();
if (registry != null) {
// get the service, if it exists. NB, if there is a service object,
// then the extender and the interface class are available, so this cast should be
// safe now.
// the rest of the work is done by the registry
Object service = ((ProviderRegistry)registry).getService(iface);
if (service != null) {
return service;
}
}
// try for a classpath locatable instance next. If we find an appropriate class mapping,
// create an instance and return it.
Class<?> cls = locateServiceClass(iface, contextClass, loader);
if (cls != null) {
return cls.newInstance();
}
// a provider was not found
return null;
}
/**
* Locate a service class that matches an interface
* definition.
*
* @param iface The name of the required interface.
* @param contextClass
* The class requesting the lookup (used for class resolution).
* @param loader A class loader to use for searching for service definitions
* and loading classes.
*
* @return The located class, or null if no matching services
* can be found.
* @exception Exception Thrown for any classloading exceptions thrown
* trying to load the class.
*/
static public Class<?> getServiceClass(String iface, Class<?> contextClass, ClassLoader loader) throws ClassNotFoundException {
// if we are working in an OSGi environment, then process the service
// registry first. Ideally, we would do this last, but because of boot delegation
// issues with some API implementations, we must try the OSGi version first
Object registry = getRegistry();
if (registry != null) {
// get the service, if it exists. NB, if there is a service object,
// then the extender and the interface class are available, so this cast should be
// safe now.
// If we've located stuff in the registry, then return it
Class<?> cls = ((ProviderRegistry)registry).getServiceClass(iface);
if (cls != null) {
return cls;
}
}
// try for a classpath locatable instance first. If we find an appropriate class mapping,
// create an instance and return it.
return locateServiceClass(iface, contextClass, loader);
}
/**
* Get a list of services that match a given interface
* name. This searches both the current class path and
* the global repository for matches.
*
* @param iface The name of the required interface.
* @param contextClass
* The class requesting the lookup (used for class resolution).
* @param loader A class loader to use for searching for service definitions
* and loading classes.
*
* @return A list of matching services. Returns an empty list if there
* are no matches.
* @exception Exception Thrown for any classloading or exceptions thrown
* trying to instantiate a service instance.
*/
static public List<Object> getServices(String iface, Class<?> contextClass, ClassLoader loader) throws Exception {
List<Object> services = new ArrayList<Object>();
// because of boot delegation issues with some of the API implementations, it is necessary
// to process the OSGi registered versions first to allow override of JRE provided APIs.
Object registry = getRegistry();
if (registry != null) {
// get the service, if it exists. NB, if there is a service object,
// then the extender and the interface class are available, so this cast should be
// safe now.
// get any registered service instances now
List<Object> globalServices = ((ProviderRegistry)registry).getServices(iface);
// add to our list also
if (globalServices != null) {
services.addAll(globalServices);
}
}
// try for a classpath locatable instance second. If we find an appropriate class mapping,
// create an instance and return it.
Collection<Class<?>> classes = locateServiceClasses(iface, contextClass, loader);
if (classes != null) {
// create an instance of each of these classes
for (Class<?> cls : classes) {
services.add(cls.newInstance());
}
}
// now return the merged set
return services;
}
/**
* Get a list of service class implementations that match
* an interface name. This searches both the current class path and
* the global repository for matches.
*
* @param iface The name of the required interface.
* @param contextClass
* The class requesting the lookup (used for class resolution).
* @param loader A class loader to use for searching for service definitions
* and loading classes.
*
* @return A list of matching provider classes. Returns an empty list if there
* are no matches.
* @exception Exception Thrown for any classloading exceptions thrown
* trying to load a provider class.
*/
static public List<Class<?>> getServiceClasses(String iface, Class<?> contextClass, ClassLoader loader) throws Exception {
Set<Class<?>> serviceClasses = new LinkedHashSet<Class<?>>();
// because of boot delegation issues with some of the API implementations, it is necessary
// to process the OSGi registered versions first to allow override of JRE provided APIs.
Object registry = getRegistry();
if (registry != null) {
// get the service, if it exists. NB, if there is a service object,
// then the extender and the interface class are available, so this cast should be
// safe now.
// get any registered service provider classes now
List<Class<?>> globalServices = ((ProviderRegistry)registry).getServiceClasses(iface);
// add to our list also
if (globalServices != null) {
serviceClasses.addAll(globalServices);
}
}
// try for a classpath locatable classes second. If we find an appropriate class mapping,
// add this to our return collection.
Collection<Class<?>> classes = locateServiceClasses(iface, contextClass, loader);
if (classes != null) {
serviceClasses.addAll(classes);
}
// now return the merged set
return new ArrayList(serviceClasses);
}
/**
* Locate the first class name for a META-INF/services definition
* of a given class. The first matching provider is
* returned.
*
* @param iface The interface class name used for the match.
* @param loader The classloader for locating resources.
*
* @return The mapped provider name, if found. Returns null if
* no mapping is located.
*/
static private String locateServiceClassName(String iface, Class<?> contextClass, ClassLoader loader) {
// search first with the loader class path
String name = locateServiceClassName(iface, loader);
if (name != null) {
return name;
}
// then with the context class, if there is one
if (contextClass != null) {
name = locateServiceClassName(iface, contextClass.getClassLoader());
if (name != null) {
return name;
}
}
// not found
return null;
}
/**
* Locate a classpath-define service mapping.
*
* @param iface The required interface name.
* @param loader The ClassLoader instance to use to locate the service.
*
* @return The mapped class name, if one is found. Returns null if the
* mapping is not located.
*/
static private String locateServiceClassName(String iface, ClassLoader loader) {
if (loader != null) {
try {
// we only look at resources that match the file name, using the specified loader
String service = "META-INF/services/" + iface;
Enumeration<URL> providers = loader.getResources(service);
while (providers.hasMoreElements()) {
List<String>providerNames = parseServiceDefinition(providers.nextElement());
// if there is something defined here, return the first entry
if (!providerNames.isEmpty()) {
return providerNames.get(0);
}
}
} catch (IOException e) {
}
}
// not found
return null;
}
/**
* Locate the first class for a META-INF/services definition
* of a given interface class. The first matching provider is
* returned.
*
* @param iface The interface class name used for the match.
* @param loader The classloader for locating resources.
*
* @return The mapped provider class, if found. Returns null if
* no mapping is located.
*/
static private Class<?> locateServiceClass(String iface, Class<?> contextClass, ClassLoader loader) throws ClassNotFoundException {
String className = locateServiceClassName(iface, contextClass, loader);
if (className == null) {
return null;
}
// we found a name, try loading the class. This will throw an exception if there is an error
return loadClass(className, contextClass, loader);
}
/**
* Locate all class names name for a META-INF/services definition
* of a given class.
*
* @param iface The interface class name used for the match.
* @param loader The classloader for locating resources.
*
* @return The mapped provider name, if found. Returns null if
* no mapping is located.
*/
static private Collection<String> locateServiceClassNames(String iface, Class<?> contextClass, ClassLoader loader) {
Set<String> names = new LinkedHashSet<String>();
locateServiceClassNames(iface, loader, names);
if (contextClass != null) {
locateServiceClassNames(iface, contextClass.getClassLoader(), names);
}
return names;
}
/**
* Locate all class names name for a META-INF/services definition
* of a given class.
*
* @param iface The interface class name used for the match.
* @param loader The classloader for locating resources.
*
* @return The mapped provider name, if found. Returns null if
* no mapping is located.
*/
static void locateServiceClassNames(String iface, ClassLoader loader, Set names) {
if (loader != null) {
try {
// we only look at resources that match the file name, using the specified loader
String service = "META-INF/services/" + iface;
Enumeration<URL> providers = loader.getResources(service);
while (providers.hasMoreElements()) {
List<String>providerNames = parseServiceDefinition(providers.nextElement());
// just add all of these to the list
names.addAll(providerNames);
}
} catch (IOException e) {
}
}
}
/**
* Locate all classes that map to a given provider class definition. This will
* search both the services directories, as well as the provider classes from the
* OSGi provider registry.
*
* @param iface The interface class name used for the match.
* @param loader The classloader for locating resources.
*
* @return A list of all mapped classes, if found. Returns an empty list if
* no mappings are found.
*/
static private Collection<Class<?>> locateServiceClasses(String iface, Class<?> contextClass, ClassLoader loader) throws ClassNotFoundException {
// get the set of names from services definitions on the classpath
Collection<String> classNames = locateServiceClassNames(iface, contextClass, loader);
Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
// load each class and add to our return set
for (String name : classNames) {
classes.add(loadClass(name, contextClass, loader));
}
return classes;
}
/**
* Parse a definition file and return the names of all included implementation classes
* contained within the file.
*
* @param u The URL of the file
*
* @return A list of all matching classes. Returns an empty list
* if no matches are found.
*/
static private List<String> parseServiceDefinition(URL u) {
final String url = u.toString();
List<String> classes = new ArrayList<String>();
// ignore directories
if (url.endsWith("/")) {
return classes;
}
// the identifier used for the provider is the last item in the URL.
final String providerId = url.substring(url.lastIndexOf("/") + 1);
try {
BufferedReader br = new BufferedReader(new InputStreamReader(u.openStream(), "UTF-8"));
// the file can be multiple lines long, with comments. A single file can define multiple providers
// for a single key, so we might need to create multiple entries. If the file does not contain any
// definition lines, then as a default, we use the providerId as an implementation class also.
String line = br.readLine();
while (line != null) {
// we allow comments on these lines, and a line can be all comment
int comment = line.indexOf('#');
if (comment != -1) {
line = line.substring(0, comment);
}
line = line.trim();
// if there is nothing left on the line after stripping white space and comments, skip this
if (line.length() > 0) {
// add this to our list
classes.add(line);
}
// keep reading until the end.
line = br.readLine();
}
br.close();
} catch (IOException e) {
// ignore errors and handle as default
}
return classes;
}
/**
* Perform a service class discovery by looking for a
* property in a target properties file located in the
* java.home directory.
*
* @param path The relative path to the desired properties file.
* @param property The name of the required property.
*
* @return The value of the named property within the properties file. Returns
* null if the property doesn't exist or the properties file doesn't exist.
*/
public static String lookupByJREPropertyFile(String path, String property) throws IOException {
String jreDirectory = System.getProperty("java.home");
File configurationFile = new File(jreDirectory + File.separator + path);
if (configurationFile.exists() && configurationFile.canRead()) {
Properties properties = new Properties();
InputStream in = null;
try {
in = new FileInputStream(configurationFile);
properties.load(in);
return properties.getProperty(property);
} finally {
if (in != null) {
try {
in.close();
} catch (Exception e) {
}
}
}
}
return null;
}
/**
* Retrieve the registry from the tracker if it is available,
* all without causing the interface class to load.
*
* @return The registry service instance, or null if it is not
* available for any reason.
*/
private static Object getRegistry() {
// if not initialized in an OSGi environment, this is a failure
if (registryTracker == null) {
return null;
}
// get the service, if it exists. NB: it is only safe to reference the
// interface class if the tracker returns a non-null service object. The
// interface class will not be loaded in our bundle context until the
// service class can be statisfied. Therefore, we always return this as
// just an object and the call needs to perform the cast, which will
// force the classload at that time.
return ((ServiceTracker)registryTracker).getService();
}
}
| 753 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/TestTargetTwo.java | /**
* 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.geronimo.osgi.itestb;
public class TestTargetTwo {
public TestTargetTwo() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTargetTwo";
}
}
| 754 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/TestTarget3.java | /**
* 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.geronimo.osgi.itestb;
public class TestTarget3 {
public TestTarget3() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget3";
}
}
| 755 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/TestTarget2.java | /**
* 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.geronimo.osgi.itestb;
public class TestTarget2 {
public TestTarget2() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget2";
}
}
| 756 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itestb/src/main/java/org/apache/geronimo/osgi/itestb/TestTarget.java | /**
* 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.geronimo.osgi.itestb;
public class TestTarget {
public TestTarget() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget";
}
}
| 757 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/TestTargetTwo.java | /**
* 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.geronimo.osgi.registry.itest;
public class TestTargetTwo {
public TestTargetTwo() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTargetTwo";
}
}
| 758 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/TestTargetLocal.java | /**
* 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.geronimo.osgi.registry.itest;
public class TestTargetLocal {
public TestTargetLocal() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget";
}
}
| 759 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/TestTarget3.java | /**
* 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.geronimo.osgi.registry.itest;
public class TestTarget3 {
public TestTarget3() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget3";
}
}
| 760 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiServiceLocatorTest.java | /*
* 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.geronimo.osgi.registry.itest;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.geronimo.osgi.locator.Activator;
import org.apache.geronimo.osgi.locator.ProviderLocator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.CoreOptions;
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.equinox;
import static org.ops4j.pax.exam.CoreOptions.felix;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.provision;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import org.ops4j.pax.exam.Customizer;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import static org.ops4j.pax.exam.OptionUtils.combine;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.*;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@RunWith(JUnit4TestRunner.class)
public class OSGiServiceLocatorTest {
@Inject
protected BundleContext bundleContext;
@org.ops4j.pax.exam.junit.Configuration
public static Option[] configuration() throws Exception {
Option[] options = options(
// the target code we're testing...
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-registry"),
// bundle containing test resources
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itesta"),
// this bundle opts out of the SPI-Provider status
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itestb"),
mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
felix(),
equinox().version("3.5.0"),
// we want to specify an activator for the test probe bundle that
// is the standard one for adding the locator service to a spec
// bundle. We'll use our activator instance to perform class lookups
new Customizer()
{
@Override
public InputStream customizeTestProbe( InputStream testProbe )
throws IOException
{
return modifyBundle(testProbe)
// these two classes need to be in every participating bundle
.add(org.apache.geronimo.osgi.locator.Activator.class)
.add(org.apache.geronimo.osgi.locator.ProviderLocator.class)
// we don't have any direct references to this class, so force it to be
// included.
.add(org.apache.geronimo.osgi.registry.itest.TestTargetLocal.class)
// set the required activator also
.set(Constants.BUNDLE_ACTIVATOR, org.apache.geronimo.osgi.locator.Activator.class.getName())
// we need an import for activator to function properly.
.set(Constants.IMPORT_PACKAGE, "org.apache.geronimo.osgi.registry.api")
.build();
}
}
);
options = updateOptions(options);
return options;
}
@Test
public void testServiceLocator() throws Exception {
Bundle bundle1 = getInstalledBundle("org.apache.geronimo.specs.geronimo-osgi-itesta");
// now testing the services lookup and instantiation mechanism. These should all be satisfied by
// the extender rather than loaded from the classpath.
Object service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(service);
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", service.getClass().getName());
// we expect a new instance on each call. Verify that the instances are different
Object service2 = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(service2);
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", service2.getClass().getName());
assertNotSame(service, service2);
// now testing a multiple instances get. This should only pick up the definition from the
// bundle that includes the SPI-Provider header (testa)
List services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(1, services.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", services.get(0).getClass().getName());
// these should be different instances
assertNotSame(service, services.get(0));
// this is multiple instances defined in a single services file.
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itesta.MultiTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(2, services.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", services.get(0).getClass().getName());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", services.get(1).getClass().getName());
// this should not be found
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(service);
// again, not found. Should return an empty list
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(0, services.size());
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// this should return an empty list
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertTrue(services.isEmpty());
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.BadClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (NullPointerException e) {
}
// but this should just give an empty list again
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.BadClass", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertTrue(services.isEmpty());
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NoConstructor", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (InstantiationException e) {
}
// and again, an empty list
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoConstructor", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertTrue(services.isEmpty());
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NoAccess", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (IllegalAccessException e) {
}
// empty list
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoAccess", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertTrue(services.isEmpty());
// same set of tests, but this time we're looking for classes, not instances
Class<?> target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(target);
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", target.getName());
// now testing a multiple instances get. This should pick up a definition from both
// jars on the class path
List<Class<?>> classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(1, classes.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", classes.get(0).getName());
// this is multiple instances defined in a single services file.
classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itesta.MultiTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(2, classes.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", classes.get(0).getName());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", classes.get(1).getName());
// this should not be found
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(target);
// again, not found. Should return an empty list
classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(0, classes.size());
// this should result in an exception
try {
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// an empty list again
classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertTrue(classes.isEmpty());
// now stop the first bundle, which should remove the service defintions.
bundle1.stop();
// repeat the first queries, which should fail now
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(service);
// this should revert to an empty list now.
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(0, services.size());
}
protected Bundle getInstalledBundle(String symbolicName) {
for (Bundle b : bundleContext.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
return b;
}
}
return null;
}
public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
}
protected static Option[] updateOptions(Option[] options) {
// We need to add pax-exam-junit here when running with the ibm
// jdk to avoid the following exception during the test run:
// ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
Option[] ibmOptions = options(
wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))
);
options = combine(ibmOptions, options);
}
return options;
}
}
| 761 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/TestTarget2.java | /**
* 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.geronimo.osgi.registry.itest;
public class TestTarget2 {
public TestTarget2() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget2";
}
}
| 762 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiLocatorMultipleProviderTest.java | /*
* 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.geronimo.osgi.registry.itest;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.apache.geronimo.osgi.locator.Activator;
import org.apache.geronimo.osgi.locator.ProviderLocator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.CoreOptions;
import static org.ops4j.pax.exam.CoreOptions.equinox;
import static org.ops4j.pax.exam.CoreOptions.felix;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.provision;
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import org.ops4j.pax.exam.Customizer;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import static org.ops4j.pax.exam.OptionUtils.combine;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.*;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@RunWith(JUnit4TestRunner.class)
public class OSGiLocatorMultipleProviderTest {
@Inject
protected BundleContext bundleContext;
@org.ops4j.pax.exam.junit.Configuration
public static Option[] configuration() throws Exception {
Option[] options = options(
// the target code we're testing
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-registry"),
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itesta"),
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itestb"),
mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
felix(),
equinox().version("3.5.0"),
// we want to specify an activator for the test probe bundle that
// is the standard one for adding the locator service to a spec
// bundle. We'll use our activator instance to perform class lookups
new Customizer()
{
@Override
public InputStream customizeTestProbe( InputStream testProbe )
throws IOException
{
return modifyBundle(testProbe)
// these two classes need to be in every participating bundle
.add(org.apache.geronimo.osgi.locator.Activator.class)
.add(org.apache.geronimo.osgi.locator.ProviderLocator.class)
// set the required activator also
.set(Constants.BUNDLE_ACTIVATOR, org.apache.geronimo.osgi.locator.Activator.class.getName())
// we need an import for activator to function properly.
.set(Constants.IMPORT_PACKAGE, "org.apache.geronimo.osgi.registry.api")
.build();
}
}
);
options = updateOptions(options);
return options;
}
@Test
public void testLocator() throws Exception {
Bundle bundle1 = getInstalledBundle("org.apache.geronimo.specs.geronimo-osgi-itesta");
Bundle bundle2 = getInstalledBundle("org.apache.geronimo.specs.geronimo-osgi-itestb");
// check for the target class a verify we got the correct one
Class<?> target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
// now stop the first bundle, which should shuffle the deck
bundle1.stop();
// The returned class should now be from the second provisioned bundle
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget", target.getName());
// now stop the the second bundle. There should not be anything registred with that name now.
bundle2.stop();
// The returned class should now be null since there are no registered providers
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
assertNull(target);
}
protected Bundle getInstalledBundle(String symbolicName) {
for (Bundle b : bundleContext.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
return b;
}
}
return null;
}
public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
}
protected static Option[] updateOptions(Option[] options) {
// We need to add pax-exam-junit here when running with the ibm
// jdk to avoid the following exception during the test run:
// ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
Option[] ibmOptions = options(
wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))
);
options = combine(ibmOptions, options);
}
return options;
}
}
| 763 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiNoRegistryTest.java | /*
* 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.geronimo.osgi.registry.itest;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.geronimo.osgi.locator.Activator;
import org.apache.geronimo.osgi.locator.ProviderLocator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.CoreOptions;
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.equinox;
import static org.ops4j.pax.exam.CoreOptions.felix;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.provision;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import org.ops4j.pax.exam.Customizer;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import static org.ops4j.pax.exam.OptionUtils.combine;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.*;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@RunWith(JUnit4TestRunner.class)
public class OSGiNoRegistryTest {
@Inject
protected BundleContext bundleContext;
@org.ops4j.pax.exam.junit.Configuration
public static Option[] configuration() throws Exception {
Option[] options = options(
// NOTE: This test is supposed to test that the ProviderLocator
// does not raise exceptions if the provider registry is not
// available and the ProviderRegistry api class is not resolvable.
// mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-registry"),
// bundle containing test resources
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itesta"),
mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
felix(),
equinox().version("3.5.0"),
// we want to specify an activator for the test probe bundle that
// is the standard one for adding the locator service to a spec
// bundle. We'll use our activator instance to perform class lookups
new Customizer()
{
@Override
public InputStream customizeTestProbe( InputStream testProbe )
throws IOException
{
return modifyBundle(testProbe)
// these two classes need to be in every participating bundle
.add(org.apache.geronimo.osgi.locator.Activator.class)
.add(org.apache.geronimo.osgi.locator.ProviderLocator.class)
// we don't have any direct references to this class, so force it to be
// included.
.add(org.apache.geronimo.osgi.registry.itest.TestTargetLocal.class)
// set the required activator also
.set(Constants.BUNDLE_ACTIVATOR, org.apache.geronimo.osgi.locator.Activator.class.getName())
// we need an import for activator to function properly...make sure the resolution
// is optional, which is the typical way of dealing with this
.set(Constants.IMPORT_PACKAGE, "org.apache.geronimo.osgi.registry.api;resolution:=optional")
.build();
}
}
);
options = updateOptions(options);
return options;
}
@Test
public void testLocator() throws Exception {
// Ok, just a few quick tests to make sure things fail gracefully.
Class<?> target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
assertNull(target);
List<Class<?>> targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.registry.itest.TestTarget");
// should return an empty list
assertNotNull(targets);
assertEquals(0, targets.size());
// this should not be located at all
try {
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.ClassNotFound", this.getClass());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// now some service tests
Object service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(service);
// now testing a multiple instances get. This should only pick up the definition from the
// bundle that includes the SPI-Provider header (testa)
List services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(0, services.size());
// same set of tests, but this time we're looking for classes, not instances
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(target);
List<Class<?>> classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(0, classes.size());
}
protected Bundle getInstalledBundle(String symbolicName) {
for (Bundle b : bundleContext.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
return b;
}
}
return null;
}
public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
}
protected static Option[] updateOptions(Option[] options) {
// We need to add pax-exam-junit here when running with the ibm
// jdk to avoid the following exception during the test run:
// ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
Option[] ibmOptions = options(
wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))
);
options = combine(ibmOptions, options);
}
return options;
}
}
| 764 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/OSGiLocatorTest.java | /*
* 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.geronimo.osgi.registry.itest;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.geronimo.osgi.locator.Activator;
import org.apache.geronimo.osgi.locator.ProviderLocator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.CoreOptions;
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.equinox;
import static org.ops4j.pax.exam.CoreOptions.felix;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.provision;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import org.ops4j.pax.exam.Customizer;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import static org.ops4j.pax.exam.OptionUtils.combine;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.*;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@RunWith(JUnit4TestRunner.class)
public class OSGiLocatorTest {
@Inject
protected BundleContext bundleContext;
@org.ops4j.pax.exam.junit.Configuration
public static Option[] configuration() throws Exception {
Option[] options = options(
// the target code we're testing...
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-registry"),
// bundle containing test resources
mavenBundle("org.apache.geronimo.specs", "geronimo-osgi-itesta"),
mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
felix(),
equinox().version("3.5.0"),
// we want to specify an activator for the test probe bundle that
// is the standard one for adding the locator service to a spec
// bundle. We'll use our activator instance to perform class lookups
new Customizer()
{
@Override
public InputStream customizeTestProbe( InputStream testProbe )
throws IOException
{
return modifyBundle(testProbe)
// these two classes need to be in every participating bundle
.add(org.apache.geronimo.osgi.locator.Activator.class)
.add(org.apache.geronimo.osgi.locator.ProviderLocator.class)
// we don't have any direct references to this class, so force it to be
// included.
.add(org.apache.geronimo.osgi.registry.itest.TestTargetLocal.class)
// set the required activator also
.set(Constants.BUNDLE_ACTIVATOR, org.apache.geronimo.osgi.locator.Activator.class.getName())
// we need an import for activator to function properly.
.set(Constants.IMPORT_PACKAGE, "org.apache.geronimo.osgi.registry.api")
.build();
}
}
);
options = updateOptions(options);
return options;
}
@Test
public void testLocator() throws Exception {
Bundle bundle1 = getInstalledBundle("org.apache.geronimo.specs.geronimo-osgi-itesta");
// check for the target class a verify we got the correct one
Class<?> target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
List<Class<?>> targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.registry.itest.TestTarget");
// should return one entry and it should be the same class mapping
assertEquals(1, targets.size());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", targets.get(0).getName());
// now load the second target interface. This is really the same as the first, but
// uses a different commenting style.
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget2");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTargetTwo", target.getName());
targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.registry.itest.TestTarget2");
// should return one entry and it should be the same class mapping
assertEquals(1, targets.size());
assertEquals("org.apache.geronimo.osgi.itesta.TestTargetTwo", targets.get(0).getName());
// this class is defined using the header form. It should map back to itself.
target = ProviderLocator.locate("org.apache.geronimo.osgi.itesta.TestTarget2");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", target.getName());
targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.itesta.TestTarget2");
// should return one entry and it should be the same class mapping
assertEquals(1, targets.size());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", targets.get(0).getName());
// This is not in the provider registry, so it should just return null.
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.ClassNotFound");
assertNull(target);
// This is in the provider registry, but the class cannot be loaded. This should still
// return null.
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.NoClass");
assertNull(target);
// This is defined as a header, but the class cannot be loaded. This should still
// return null.
target = ProviderLocator.locate("org.apache.geronimo.osgi.itesta..NoClass");
assertNull(target);
// Now test some of the class loading support. This will search the provider registry first,
// then the classpath. We should still get the registered class returned.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass());
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
// similar to the above, but since the context class is not provided, this will fail to resolve the
// locally resident class.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.TestTarget", null);
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
// And just a straight load class of a bundle-local class.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.TestTargetTwo", this.getClass());
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.registry.itest.TestTargetTwo", target.getName());
// this one should be handled from the provider registry and resolve to a class
// defined in the test bundle.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.TestTarget4", this.getClass());
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
// this should not be located at all
try {
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.ClassNotFound", this.getClass());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// this is in the registry, but there is an error resolving the class
try {
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// this is defined with a header, but there is an error resolving the class
try {
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.itesta.NoClass", this.getClass());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// this mapping defines multiple classes for the single key. The first should be returned for
// a singleton request, the locate all should return in definition order
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget4");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.registry.itest.TestTarget4");
// should return one entry and it should be the same class mapping
assertEquals(2, targets.size());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", targets.get(0).getName());
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", targets.get(1).getName());
// now stop the first bundle, which should shuffle the deck
bundle1.stop();
// The returned class should now be null since there are no registered providers
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.TestTarget");
assertNull(target);
targets = ProviderLocator.locateAll("org.apache.geronimo.osgi.registry.itest.TestTarget");
// should return an empty list
assertNotNull(targets);
assertEquals(0, targets.size());
// The returned class should now be null since there are no registered providers
target = ProviderLocator.locate("org.apache.geronimo.osgi.itesta.TestTarget2");
assertNull(target);
// This is in the provider registry, but the class cannot be loaded. This should still
// return null.
target = ProviderLocator.locate("org.apache.geronimo.osgi.registry.itest.NoClass");
assertNull(target);
}
protected Bundle getInstalledBundle(String symbolicName) {
for (Bundle b : bundleContext.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
return b;
}
}
return null;
}
public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
}
protected static Option[] updateOptions(Option[] options) {
// We need to add pax-exam-junit here when running with the ibm
// jdk to avoid the following exception during the test run:
// ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
Option[] ibmOptions = options(
wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))
);
options = combine(ibmOptions, options);
}
return options;
}
}
| 765 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry-itests/src/test/java/org/apache/geronimo/osgi/registry/itest/TestTarget.java | /**
* 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.geronimo.osgi.registry.itest;
public class TestTarget {
public TestTarget() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget";
}
}
| 766 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderBundleTrackerCustomizer.java | /**
* 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.geronimo.osgi.registry;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.BundleTrackerCustomizer;
public class ProviderBundleTrackerCustomizer implements BundleTrackerCustomizer {
// our base Activator (used as a service source)
private Activator activator;
// the bundle hosting this registry
private Bundle registryBundle;
// the registry we interact with
private ProviderRegistryImpl registry;
public ProviderBundleTrackerCustomizer(Activator a, Bundle b, ProviderRegistryImpl r) {
activator = a;
registryBundle = b;
registry = r;
}
/**
* Handle the activation of a new bundle.
*
* @param bundle The source bundle.
* @param event The bundle event information.
*
* @return A return object.
*/
public Object addingBundle(Bundle bundle, BundleEvent event) {
log(LogService.LOG_DEBUG, "Bundle Considered for class providers: " + bundle.getSymbolicName());
if (bundle.equals(registryBundle)) {
return null;
}
return registry.addBundle(bundle);
}
public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
// nothing to do here
}
public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
// have the registry process this
registry.removeBundle(bundle, object);
}
private void log(int level, String message) {
activator.log(level, message);
}
private void log(int level, String message, Throwable th) {
activator.log(level, message, th);
}
}
| 767 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/ProviderRegistryImpl.java | /**
* 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.geronimo.osgi.registry;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.osgi.framework.Bundle;
import org.osgi.service.log.LogService;
/**
* The implementation of the provider registry used to store
* the bundle registrations.
*/
public class ProviderRegistryImpl implements org.apache.geronimo.osgi.registry.api.ProviderRegistry {
// indicates a bundle wishes to opt in to the META-INF/services registration and tracking.
public static final String OPT_IN_HEADER = "SPI-Provider";
// provider classes exported via a header.
public static final String EXPORT_PROVIDER_HEADER = "Export-SPI-Provider";
// our mapping between a provider id and the implementation information. There
// might be a one-to-many relationship between the ids and implementing classes.
private SPIRegistry providers = new SPIRegistry();
// our mapping between an interface name and a META-INF/services SPI implementation. There
// might be a one-to-many relationship between the ids and implementing classes.
private SPIRegistry serviceProviders = new SPIRegistry();
// our base Activator (used as a service source)
private Activator activator;
public ProviderRegistryImpl(Activator activator) {
this.activator = activator;
}
/**
* Add a bundle to the provider registry. This searches
* for services information in the OSGI-INF/providers
* directory of the bundle and registers this information
* in a provider registry. Bundles that need to locate
* class instances can use the provider registry to
* locate classes that might reside in other bundles.
*
* @param bundle The source bundle.
*
* @return A map of the located registrations. Returns null if
* this bundle does not contain any providers.
*/
public Object addBundle(Bundle bundle) {
log(LogService.LOG_DEBUG, "adding bundle " + bundle);
// create a tracker item for this bundle. This will record all of the information
// that's relevent to this bundle
BundleResources tracker = new BundleResources(bundle);
// if the tracker found information of interest, return it to the
// BundleTracker to let it know we need to watch this one.
return tracker.needsTracking() ? tracker : null;
}
/**
* Remove a bundle from the registry.
*
* @param bundle The target bundle.
*/
public void removeBundle(Bundle bundle, Object obj) {
log(LogService.LOG_DEBUG, "removing bundle " + bundle);
BundleResources tracker = (BundleResources)obj;
if (tracker != null) {
tracker.remove();
}
}
/**
* Register an individual provivider item by its provider identifier.
*
* @param id The provider id.
* @param provider The loader used to resolve the provider class.
*/
protected void registerProvider(BundleProviderLoader provider) {
log(LogService.LOG_DEBUG, "registering provider " + provider);
providers.register(provider);
}
/**
* Removed a provider registration for a named provider id.
*
* @param id The target id
* @param provider The provider registration instance
*/
protected void unregisterProvider(BundleProviderLoader provider) {
log(LogService.LOG_DEBUG, "unregistering provider " + provider);
providers.unregister(provider);
}
/**
* Register an individual provivider item by its provider identifier.
*
* @param id The provider id.
* @param provider The loader used to resolve the provider class.
*/
protected void registerService(BundleProviderLoader provider) {
log(LogService.LOG_DEBUG, "registering service " + provider);
serviceProviders.register(provider);
}
/**
* Removed a provider registration for a named provider id.
*
* @param id The target id
* @param provider The provider registration instance
*/
protected void unregisterService(BundleProviderLoader provider) {
log(LogService.LOG_DEBUG, "unregistering service " + provider);
serviceProviders.unregister(provider);
}
/**
* Locate a class by its provider id indicator. .
*
* @param providerId The provider id (generally, a fully qualified class name).
*
* @return The Class corresponding to this provider id. Returns null
* if this is not registered or the indicated class can't be
* loaded.
*/
public Class<?> locate(String providerId) {
// see if we have a registered match for this...getting just the first instance
BundleProviderLoader loader = providers.getLoader(providerId);
if (loader != null) {
try {
// try to load this. We always return null
return loader.loadClass();
} catch (Exception e) {
e.printStackTrace();
// just swallow this and return null. The exception has already
// been logged.
}
}
// no match to return
return null;
}
/**
* Locate all class files that match a given provider id.
*
* @param providerId The target provider identifier.
*
* @return A List containing the class objects corresponding to the
* provider identifier. Returns an empty list if no
* matching classes can be located.
*/
public List<Class<?>> locateAll(String providerId) {
List<Class<?>> classes = new ArrayList<Class<?>>();
List<BundleProviderLoader> l = providers.getLoaders(providerId);
// this returns null if nothing is found.
if (l != null) {
for (BundleProviderLoader c : l) {
try {
classes.add(c.loadClass());
} catch (Exception e) {
// just swallow this and proceed to the next. The exception has
// already been logged.
}
}
}
return classes;
}
/**
* Locate and instantiate an instance of a service provider
* defined in the META-INF/services directory of tracked bundles.
*
* @param providerId The name of the target interface class.
*
* @return The service instance. Returns null if no service defintions
* can be located.
* @exception Exception Any classloading or other exceptions thrown during
* the process of creating this service instance.
*/
public Object getService(String providerId) throws Exception {
List<BundleProviderLoader> loaders = serviceProviders.getLoaders(providerId);
if (loaders == null || loaders.size() == 0) {
return null;
}
String preferenceProviderClassName = System.getProperty(providerId);
if (preferenceProviderClassName != null) {
for (BundleProviderLoader loader : loaders) {
if (loader.providerClass.equals(preferenceProviderClassName)) {
return loader.createInstance();
}
}
}
return loaders.get(0).createInstance();
}
/**
* Locate all services that match a given provider id and create instances.
*
* @param providerId The target provider identifier.
*
* @return A List containing the instances corresponding to the
* provider identifier. Returns an empty list if no
* matching classes can be located or created
*/
public List<Object> getServices(String providerId) {
List<Object> instances = new ArrayList<Object>();
List<BundleProviderLoader> l = serviceProviders.getLoaders(providerId);
// this returns null for nothing found
if (l != null) {
for (BundleProviderLoader c : l) {
try {
instances.add(c.createInstance());
} catch (Exception e) {
// just swallow this and proceed to the next. The exception has
// already been logged.
}
}
}
return instances;
}
/**
* Locate all services that match a given provider id and return the implementation
* classes
*
* @param providerId The target provider identifier.
*
* @return A List containing the classes corresponding to the
* provider identifier. Returns an empty list if no
* matching classes can be located.
*/
public List<Class<?>> getServiceClasses(String providerId) {
List<Class<?>> classes = new ArrayList<Class<?>>();
List<BundleProviderLoader> l = serviceProviders.getLoaders(providerId);
// this returns null for nothing found
if (l != null) {
for (BundleProviderLoader c : l) {
try {
classes.add(c.loadClass());
} catch (Exception e) {
e.printStackTrace();
// just swallow this and proceed to the next. The exception has
// already been logged.
}
}
}
return classes;
}
/**
* Locate and return the class for a service provider
* defined in the META-INF/services directory of tracked bundles.
*
* @param providerId The name of the target interface class.
*
* @return The provider class. Returns null if no service defintions
* can be located.
* @exception Exception Any classloading or other exceptions thrown during
* the process of loading this service provider class.
*/
public Class<?> getServiceClass(String providerId) throws ClassNotFoundException {
List<BundleProviderLoader> loaders = serviceProviders.getLoaders(providerId);
if (loaders == null || loaders.size() == 0) {
return null;
}
String preferenceProviderClassName = System.getProperty(providerId);
if (preferenceProviderClassName != null) {
for (BundleProviderLoader loader : loaders) {
if (loader.providerClass.equals(preferenceProviderClassName)) {
return loader.loadClass();
}
}
}
return loaders.get(0).loadClass();
}
private void log(int level, String message) {
activator.log(level, message);
}
private void log(int level, String message, Throwable th) {
activator.log(level, message, th);
}
private class BundleResources {
// the bundle we're attached to.
private Bundle bundle;
// our map of providers maintained for the META-INF/services design pattern.
// this is an interface-to-provider instance mapping.
private List<BundleProviderLoader> serviceProviders;
// the defined mapping for provider classes...not maintained as an
// interface-to-provider mapping.
private List<BundleProviderLoader> providers;
public BundleResources(Bundle b) {
bundle = b;
// go locate any services we need
locateProviders();
locateServices();
}
public boolean needsTracking() {
return serviceProviders != null || providers != null;
}
// locate and process any providers defined in the OSGI-INF/providers directory
private void locateProviders() {
// we accumulate from the headers and the providers directory. The headers
// are simpler if there is no class mapping and is easier to use when
// converting a simple jar to a bundle.
Set<BundleProviderLoader> locatedProviders = new LinkedHashSet<BundleProviderLoader>();
List<BundleProviderLoader> headerProviders = locateHeaderProviderDefinitions();
if (headerProviders != null) {
locatedProviders.addAll(headerProviders);
}
List<BundleProviderLoader> directoryProviders = processDefinitions("OSGI-INF/providers/");
if (directoryProviders != null) {
locatedProviders.addAll(directoryProviders);
}
// if we have anything, add to global registry
if (!locatedProviders.isEmpty()) {
// process the registrations for each item
for (BundleProviderLoader loader: locatedProviders) {
// add to the mapping table
registerProvider(loader);
}
// remember this list so we can unregister when the bundle is stopped
providers = new ArrayList<BundleProviderLoader>(locatedProviders);
}
}
/**
* Parse the Export-Provider: header to create a list of
* providers that are exported via the header syntax
* rather than via a provider mapping file.
*
* @return A list of providers defined on the header, or null if
* no providers were exported.
*/
private List<BundleProviderLoader> locateHeaderProviderDefinitions() {
// check the header to see if there's anything defined here.
String exportedProviders = (String)bundle.getHeaders().get(EXPORT_PROVIDER_HEADER);
if (exportedProviders == null) {
return null;
}
List<BundleProviderLoader>providers = new ArrayList<BundleProviderLoader>();
// split on the separator
String[] classNames = exportedProviders.split(",");
for (String name : classNames) {
name = name.trim();
// this is a simple mapping
providers.add(new BundleProviderLoader(name, name, bundle));
}
return providers;
}
// now process any services
private void locateServices() {
// we only process these if there is a header indicating this
// bundle wants to opt-in to this registration process.
if (bundle.getHeaders().get(OPT_IN_HEADER) == null) {
return;
}
log(LogService.LOG_INFO, OPT_IN_HEADER + " Manifest header found in bundle: " + bundle.getSymbolicName());
serviceProviders = processDefinitions("META-INF/services/");
// if we have anything, add to global registry
if (serviceProviders != null) {
// process the registrations for each item
for (BundleProviderLoader loader: serviceProviders) {
// add to the mapping table
registerService(loader);
}
}
}
/**
* Remove all resources associated with this bundle from the
* global registry.
*/
public void remove() {
log(LogService.LOG_DEBUG, "removing bundle " + bundle);
if (providers != null) {
for (BundleProviderLoader loader : providers) {
// unregistry the individual entry
unregisterProvider(loader);
}
}
if (serviceProviders != null) {
for (BundleProviderLoader loader : serviceProviders) {
// unregistry the individual entry
unregisterService(loader);
}
}
}
/**
* Process all of the service definition files in a given
* target path. This is used to process both the
* META-INF/services files and the OSGI-INF/providers files.
*
* @param path The target path location.
*
* @return The list of matching service definitions. Returns null if
* no matches were found.
*/
private List<BundleProviderLoader> processDefinitions(String path) {
List<BundleProviderLoader> mappings = new ArrayList<BundleProviderLoader>();
// look for services definitions in the bundle...we accumulate these as provider class
// definitions.
@SuppressWarnings("unchecked")
Enumeration<URL> e = bundle.findEntries(path, "*", false);
if (e != null) {
while (e.hasMoreElements()) {
final URL u = e.nextElement();
// go parse out the control file
parseServiceFile(u, mappings);
}
}
// only return this if we have something associated with this bundle
return mappings.isEmpty() ? null : mappings;
}
/**
* Parse a provider definition file and create loaders
* for all definitions contained within the file.
*
* @param u The URL of the file
*
* @return A list of the defined mappings.
*/
private void parseServiceFile(URL u, List<BundleProviderLoader>mappings) {
final String url = u.toString();
// ignore directories
if (url.endsWith("/")) {
return;
}
// the identifier used for the provider is the last item in the URL.
final String providerId = url.substring(url.lastIndexOf("/") + 1);
try {
BufferedReader br = new BufferedReader(new InputStreamReader(u.openStream(), "UTF-8"));
// the file can be multiple lines long, with comments. A single file can define multiple providers
// for a single key, so we might need to create multiple entries. If the file does not contain any
// definition lines, then as a default, we use the providerId as an implementation class also.
String line = br.readLine();
while (line != null) {
// we allow comments on these lines, and a line can be all comment
int comment = line.indexOf('#');
if (comment != -1) {
line = line.substring(0, comment);
}
line = line.trim();
// if there is nothing left on the line after stripping white space and comments, skip this
if (line.length() > 0) {
// add this to our list
mappings.add(new BundleProviderLoader(providerId, line, bundle));
}
// keep reading until the end.
line = br.readLine();
}
br.close();
} catch (IOException e) {
// ignore errors and handle as default
}
}
}
/**
* Holder class for information about a given collection of
* id to provider mappings. Used for both the providers and
* the services.
*/
private class SPIRegistry {
private Map<String, List<BundleProviderLoader>> registry;
/**
* Register an individual provivider item by its provider identifier.
*
* @param id The provider id.
* @param provider The loader used to resolve the provider class.
*/
public synchronized void register(BundleProviderLoader provider) {
// if this is the first registration, create the mapping table
if (registry == null) {
registry = new HashMap<String, List<BundleProviderLoader>>();
}
String providerId = provider.id();
// the providers are stored as a list...we use the first one registered
// when asked to locate.
List<BundleProviderLoader> l = registry.get(providerId);
if (l == null) {
l = new ArrayList<BundleProviderLoader>();
registry.put(providerId, l);
}
l.add(provider);
}
/**
* Remove a provider registration for a named provider id.
*
* @param provider The provider registration instance
*/
public synchronized void unregister(BundleProviderLoader provider) {
if (registry != null) {
// this is stored as a list. Just remove using the registration information
// This may move a different provider to the front of the list.
List<BundleProviderLoader> l = registry.get(provider.id());
if (l != null) {
l.remove(provider);
}
}
}
private synchronized BundleProviderLoader getLoader(String id) {
// synchronize on the registry instance
if (registry != null) {
// return the first match, if any
List<BundleProviderLoader> list = registry.get(id);
if (list != null && !list.isEmpty()) {
return list.get(0);
}
}
// no match here
return null;
}
private synchronized List<BundleProviderLoader> getLoaders(String id) {
if (registry != null) {
// if we have matches, return a copy of what we currently have
// to create a safe local copy.
List<BundleProviderLoader> list = registry.get(id);
if (list != null && !list.isEmpty()) {
return new ArrayList<BundleProviderLoader>(list);
}
}
// no match here
return null;
}
}
/**
* Holder class for located services information.
*/
private class BundleProviderLoader {
// the class name for this provider
private final String providerId;
// the mapped class name of the provider.
private final String providerClass;
// the hosting bundle.
private final Bundle bundle;
/**
* Create a loader for this registered provider.
*
* @param providerId The provider ID
* @param providerClass The mapped class name of the provider.
* @param bundle The hosting bundle.
*/
public BundleProviderLoader(String providerId, String providerClass, Bundle bundle) {
this.providerId = providerId;
this.providerClass = providerClass;
this.bundle = bundle;
}
/**
* Load a provider class.
*
* @return The provider class from the target bundle.
* @exception Exception
*/
public Class<?> loadClass() throws ClassNotFoundException {
try {
log(LogService.LOG_DEBUG, "loading class for: " + this);
return bundle.loadClass(providerClass);
} catch (ClassNotFoundException e) {
log(LogService.LOG_DEBUG, "exception caught while loading " + this, e);
throw e;
}
}
/**
* Create an instance of the registred service.
*
* @return The created instance. A new instance is created on each call.
* @exception Exception
*/
public Object createInstance() throws Exception {
// get the class object
Class <?> cls = loadClass();
try {
// just create an instance using the default constructor
return cls.newInstance();
} catch (Exception e) {
log(LogService.LOG_DEBUG, "exception caught while creating " + this, e);
throw e;
} catch (Error e) {
log(LogService.LOG_DEBUG, "error caught while creating " + this, e);
throw e;
}
}
public String id() {
return providerId;
}
@Override
public String toString() {
return "Provider interface=" + providerId + " , provider class=" + providerClass + ", bundle=" + bundle;
}
@Override
public int hashCode() {
return providerId.hashCode() + providerClass.hashCode() + (int)bundle.getBundleId();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof BundleProviderLoader) {
return providerId.equals(((BundleProviderLoader)obj).providerId) &&
providerClass.equals(((BundleProviderLoader)obj).providerClass) &&
bundle.getBundleId() == ((BundleProviderLoader)obj).bundle.getBundleId();
} else {
return false;
}
}
}
}
| 768 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/Activator.java | /**
* 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.geronimo.osgi.registry;
import java.util.ArrayList;
import java.util.List;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.BundleTracker;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
import org.apache.geronimo.osgi.registry.api.ProviderRegistry;
/**
* The activator that starts and manages the life-cycle of
* the class factory registry.
*/
public class Activator implements BundleActivator {
// tracker to watch for bundle updates
protected BundleTracker bt;
// service tracker for a logging service
protected ServiceTracker lst;
// Our provider registry
protected ProviderRegistryImpl registry;
// The service registration for the provider registry
protected ServiceRegistration registryRegistration;
// our bundle context
protected BundleContext context;
// an array of all active logging services.
List<LogService> logServices = new ArrayList<LogService>();
public synchronized void start(final BundleContext context) throws Exception {
this.context = context;
lst = new LogServiceTracker(context, LogService.class.getName(), null);
lst.open();
registry = new ProviderRegistryImpl(this);
// register this as a service
registryRegistration = context.registerService(ProviderRegistry.class.getName(), registry, null);
bt = new BundleTracker(context, Bundle.ACTIVE, new ProviderBundleTrackerCustomizer(this, context.getBundle(), registry));
bt.open();
}
public synchronized void stop(BundleContext context) throws Exception {
bt.close();
lst.close();
registryRegistration.unregister();
}
void log(int level, String message) {
synchronized (logServices) {
for (LogService log : logServices) {
log.log(level, message);
}
}
}
void log(int level, String message, Throwable th) {
synchronized (logServices) {
for (LogService log : logServices) {
log.log(level, message, th);
}
}
}
private final class LogServiceTracker extends ServiceTracker {
private LogServiceTracker(BundleContext context, String clazz,
ServiceTrackerCustomizer customizer) {
super(context, clazz, customizer);
}
@Override
public Object addingService(ServiceReference reference) {
Object svc = super.addingService(reference);
if (svc instanceof LogService) {
synchronized (logServices) {
logServices.add((LogService) svc);
}
}
return svc;
}
@Override
public void removedService(ServiceReference reference, Object service) {
synchronized (logServices) {
logServices.remove(service);
}
super.removedService(reference, service);
}
}
}
| 769 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-registry/src/main/java/org/apache/geronimo/osgi/registry/api/ProviderRegistry.java | /**
* 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.geronimo.osgi.registry.api;
import java.util.List;
/**
* The implementation of the factory registry used to store
* the bundle registrations.
*/
public interface ProviderRegistry {
/**
* Locate a class by its factory id indicator. .
*
* @param factoryId The factory id (generally, a fully qualified class name).
*
* @return The Class corresponding to this factory id. Returns null
* if this is not registered or the indicated class can't be
* loaded.
*/
public Class<?> locate(String factoryId);
/**
* Locate all class files that match a given factory id.
*
* @param factoryId The target factory identifier.
*
* @return A List containing the class objects corresponding to the
* factory identifier. Returns an empty list if no
* matching classes can be located.
*/
public List<Class<?>> locateAll(String factoryId);
/**
* Locate and instantiate an instance of a service provider
* defined in the META-INF/services directory of tracked bundles.
*
* @param providerId The name of the target interface class.
*
* @return The service instance. Returns null if no service defintions
* can be located.
* @exception Exception Any classloading or other exceptions thrown during
* the process of creating this service instance.
*/
public Object getService(String providerId) throws Exception;
/**
* Locate all services that match a given provider id and create instances.
*
* @param providerId The target provider identifier.
*
* @return A List containing the instances corresponding to the
* provider identifier. Returns an empty list if no
* matching classes can be located or created
*/
public List<Object> getServices(String providerId);
/**
* Locate and return the class for a service provider
* defined in the META-INF/services directory of tracked bundles.
*
* @param providerId The name of the target interface class.
*
* @return The provider class. Returns null if no service defintions
* can be located.
* @exception Exception Any classloading or other exceptions thrown during
* the process of loading this service provider class.
*/
public Class<?> getServiceClass(String providerId) throws ClassNotFoundException;
/**
* Locate all services that match a given provider id and return the implementation
* classes
*
* @param providerId The target provider identifier.
*
* @return A List containing the classes corresponding to the
* provider identifier. Returns an empty list if no
* matching classes can be located.
*/
public List<Class<?>> getServiceClasses(String providerId);
}
| 770 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/locator | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/locator/itest/NonOSGiLocatorTest.java | /*
* 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.geronimo.osgi.locator.itest;
import java.io.InputStream;
import java.io.IOException;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.apache.geronimo.osgi.locator.ProviderLocator;
public class NonOSGiLocatorTest {
@Test
public void testLocator() throws Exception {
// this is verifying that the ProviderLocater can be called when used outside of
// an OSGi framework without causing an exception. This will verify that the OSGi
// classes are not on the classpath before attempting this.
try {
this.getClass().getClassLoader().loadClass("org.osgi.util.tracker.ServiceTracker");
fail("OSGi framework classes must not be on the class path for this test");
} catch (ClassNotFoundException e) {
// this should happen if the test is run correctly.
}
// Run outside of an OSGi framework, this should just return null without
// causing an error
Class<?> target = ProviderLocator.locate("org.apache.geronimo.osgi.locator.itest.TestTarget");
assertNull(target);
// this should be located on our local classpath, so it should get a good return
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.locator.itest.TestTarget");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.locator.itest.TestTarget", target.getName());
// this will be on our dependency class path, so it should still be located.
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.itesta.TestTarget");
assertNotNull(target);
// this should return the given class instance
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget", target.getName());
// this should not be located at all
try {
target = ProviderLocator.loadClass("org.apache.geronimo.osgi.registry.ClassNotFound");
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// now testing the services lookup and instantiation mechanism
Object service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(service);
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", service.getClass().getName());
// we expect a new instance on each call. Verify that the instances are different
Object service2 = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(service2);
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", service2.getClass().getName());
assertNotSame(service, service2);
// now testing a multiple instances get. This should pick up a definition from both
// jars on the class path
List services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(2, services.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", services.get(0).getClass().getName());
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget2", services.get(1).getClass().getName());
assertNotSame(service, services.get(0));
// this is multiple instances defined in a single services file.
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.MultiTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(2, services.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget", services.get(0).getClass().getName());
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget2", services.get(1).getClass().getName());
// this should not be found
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(service);
// again, not found. Should return an empty list
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(services);
assertEquals(0, services.size());
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// as should this
try {
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.BadClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (NullPointerException e) {
}
// as should this
try {
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.BadClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (NullPointerException e) {
}
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NoConstructor", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (InstantiationException e) {
}
// as should this
try {
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoConstructor", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (InstantiationException e) {
}
// this should result in an exception
try {
service = ProviderLocator.getService("org.apache.geronimo.osgi.registry.itest.NoAccess", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (IllegalAccessException e) {
}
// as should this
try {
services = ProviderLocator.getServices("org.apache.geronimo.osgi.registry.itest.NoAccess", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected Exception not thrown");
} catch (IllegalAccessException e) {
}
// same set of tests, but this time we're looking for classes, not instances
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(target);
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", target.getName());
// now testing a multiple instances get. This should pick up a definition from both
// jars on the class path
List<Class<?>> classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.TestTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(2, classes.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itesta.TestTarget2", classes.get(0).getName());
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget2", classes.get(1).getName());
// this is multiple instances defined in a single services file.
classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.MultiTarget", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(2, classes.size());
// this should return an instance created from the services definition
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget", classes.get(0).getName());
assertEquals("org.apache.geronimo.osgi.itestb.TestTarget2", classes.get(1).getName());
// this should not be found
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNull(target);
// again, not found. Should return an empty list
classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.NotFound", this.getClass(), Thread.currentThread().getContextClassLoader());
assertNotNull(classes);
assertEquals(0, classes.size());
// this should result in an exception
try {
target = ProviderLocator.getServiceClass("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
// as should this
try {
classes = ProviderLocator.getServiceClasses("org.apache.geronimo.osgi.registry.itest.NoClass", this.getClass(), Thread.currentThread().getContextClassLoader());
fail("Expected ClassNotFoundException not thrown");
} catch (ClassNotFoundException e) {
}
}
}
| 771 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/locator | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-locator-itests/src/test/java/org/apache/geronimo/osgi/locator/itest/TestTarget.java | /**
* 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.geronimo.osgi.locator.itest;
public class TestTarget {
public TestTarget() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget";
}
}
| 772 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi/itesta/TestTargetTwo.java | /**
* 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.geronimo.osgi.itesta;
public class TestTargetTwo {
public TestTargetTwo() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTargetTwo";
}
}
| 773 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi/itesta/TestTarget3.java | /**
* 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.geronimo.osgi.itesta;
public class TestTarget3 {
public TestTarget3() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget3";
}
}
| 774 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi/itesta/TestTarget2.java | /**
* 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.geronimo.osgi.itesta;
public class TestTarget2 {
public TestTarget2() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget2";
}
}
| 775 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi/itesta/NoConstructor.java | /**
* 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.geronimo.osgi.itesta;
public class NoConstructor {
public NoConstructor(int x) {
// causes newInstance() to fail because no no-argument constructor
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget";
}
}
| 776 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi/itesta/NoAccess.java | /**
* 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.geronimo.osgi.itesta;
public class NoAccess {
private NoAccess() {
// This is a private contstructor
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget";
}
}
| 777 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi/itesta/TestTarget.java | /**
* 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.geronimo.osgi.itesta;
public class TestTarget {
public TestTarget() {
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget";
}
}
| 778 |
0 | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi | Create_ds/geronimo-specs/geronimo-osgi-support/geronimo-osgi-itesta/src/main/java/org/apache/geronimo/osgi/itesta/BadTarget.java | /**
* 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.geronimo.osgi.itesta;
public class BadTarget {
public BadTarget() {
// causes an exception when instantiated.
throw new NullPointerException("Test exception");
}
@Override
/**
* The toString method is a simple means for determining
* which class has been instantiated without requiring
* interface classes to be exported by the test bundles.
*
* @return The unique identifier for this class.
*/
public String toString() {
return "TestTarget";
}
}
| 779 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/decorator/Decorator.java | /*
* 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 javax.decorator;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.enterprise.inject.Stereotype;
/**
* Defines decorator classes.
*
* @version $Rev$ $Date$
*
*/
@Target(value = ElementType.TYPE)
@Retention(value = RetentionPolicy.RUNTIME)
@Documented
@Stereotype
public @interface Decorator
{
} | 780 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/decorator/Delegate.java | /*
* 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 javax.decorator;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* Annotates delegate bean.
*
* @version $Rev$ $Date$
*
*/
@Target({FIELD,PARAMETER})
@Retention(RUNTIME)
@Documented
public @interface Delegate
{
}
| 781 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/ConversationScoped.java | /*
* 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 javax.enterprise.context;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Conversation scope type.
*
* @see Conversation
*/
@Target( { ElementType.TYPE, ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@NormalScope(passivating = true)
@Inherited
public @interface ConversationScoped
{
}
| 782 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/ContextException.java | /*
* 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 javax.enterprise.context;
public class ContextException extends RuntimeException
{
private static final long serialVersionUID = -3599813072560026919L;
public ContextException()
{
}
public ContextException(String message)
{
super(message);
}
public ContextException(String message, Throwable cause)
{
super(message, cause);
}
public ContextException(Throwable cause)
{
super(cause);
}
}
| 783 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/ContextNotActiveException.java | /*
* 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 javax.enterprise.context;
import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
/**
* It is used by the <code>Context</code> interface.
*
*
* @see Context#get(Contextual, CreationalContext)
* @see Context#get(Contextual)
*/
public class ContextNotActiveException extends ContextException
{
private static final long serialVersionUID = -3599813072560026919L;
public ContextNotActiveException()
{
}
/**
* Creates a new exception with message.
*
* @param message message
*/
public ContextNotActiveException(String message)
{
super(message);
}
/**
* Create a new exception with the root cause.
*
* @param cause cause of the exception
*/
public ContextNotActiveException(Throwable cause)
{
super(cause);
}
/**
* Creates a new exception with the given message and throwable cause.
*
* @param message exception message
* @param cause root cause of the exception
*/
public ContextNotActiveException(String message, Throwable cause)
{
super(message, cause);
}
}
| 784 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/BusyConversationException.java | /*
* 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 javax.enterprise.context;
import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
/**
* A long running conversation must only be used by one request at the same time!
*
* If a parallel long running conversation gets detected, this very Exception will
* be thrown for the new request and the 2nd request will get a
* fresh Conversation assigned.
*
* The customer application may decide to catch this Exception and continue it's work
* with the new conversation.
*
* @see Context#get(Contextual, CreationalContext)
* @see Context#get(Contextual)
* @since 1.0 PFD2
*/
public class BusyConversationException extends ContextException
{
private static final long serialVersionUID = -3599813072560026919L ;
public BusyConversationException()
{
}
/**
* Creates a new exception with message.
*
* @param message message
*/
public BusyConversationException(String message)
{
super(message);
}
/**
* Create a new exception with the root cause.
*
* @param cause cause of the exception
*/
public BusyConversationException(Throwable cause)
{
super(cause);
}
/**
* Creates a new exception with the given message and throwable cause.
*
* @param message exception message
* @param cause root cause of the exception
*/
public BusyConversationException(String message, Throwable cause)
{
super(message, cause);
}
}
| 785 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/NonexistentConversationException.java | /*
* 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 javax.enterprise.context;
import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
/**
* If a long running conversation cannot be restored, OWB will
* assign a fresh conversation and throws this very Exception.
*
* The user code is free to catch it and continue his work
* with this new conversation.
*
* @see Context#get(Contextual, CreationalContext)
* @see Context#get(Contextual)
* @since 1.0 PFD2
*/
public class NonexistentConversationException extends ContextException
{
private static final long serialVersionUID = -3599813072560026919L;
public NonexistentConversationException()
{
}
/**
* Creates a new exception with message.
*
* @param message message
*/
public NonexistentConversationException(String message)
{
super(message);
}
/**
* Create a new exception with the root cause.
*
* @param cause cause of the exception
*/
public NonexistentConversationException(Throwable cause)
{
super(cause);
}
/**
* Creates a new exception with the given message and throwable cause.
*
* @param message exception message
* @param cause root cause of the exception
*/
public NonexistentConversationException(String message, Throwable cause)
{
super(message, cause);
}
}
| 786 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/NormalScope.java | /*
* 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 javax.enterprise.context;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* Defines normal scoped meta-data.
*
* @version $Rev$ $Date$
*
*/
@Target(ANNOTATION_TYPE)
@Retention(RUNTIME)
@Documented
public @interface NormalScope
{
/**Defines passivation semantic*/
boolean passivating() default false;
}
| 787 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/ApplicationScoped.java | /*
* 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 javax.enterprise.context;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Defines the application scoped type.
*
* <p>
* Please see the <b>8.5.3 Application context lifecycle</b>
* of the specification.
* </p>
*/
@NormalScope
@Target( { ElementType.TYPE, ElementType.METHOD , ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface ApplicationScoped
{
}
| 788 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/Conversation.java | /*
* 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 javax.enterprise.context;
/**
* Defines the conversation instance contract for using
* in the {@link ConversationScoped} webbeans components.
*
* <p>
* Please see the <b>8.5.4 Conversation context lifecycle</b> of the specification.
* </p>
*
* @see ConversationScoped
*/
public interface Conversation
{
/**
* Starts new conversation.
*/
public void begin();
/**
* Starts new conversation with the given id.
*
* @param id conversation id.
*/
public void begin(String id);
/**
* Ends of the conversation.
*/
public void end();
/**
* @return <code>true</code> if conversation is transient,
* <code>false</code> if it is a long running conversation.
*/
public boolean isTransient();
/**
* Gets conversation id.
*
* @return conversation id
*/
public String getId();
/**
* Returns conversation time out.
*
* @return conversation timeout
*/
public long getTimeout();
/**
* Sets conversation timeout in ms.
*
* @param milliseconds timeout of the conversation
*/
public void setTimeout(long milliseconds);
}
| 789 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/Dependent.java | /*
* 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 javax.enterprise.context;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Scope;
/**
* Dependent scope type.
* <p>
* If webbeans or its stereotypes do not define its scope type,
* default scope type is <code>Dependent</code> scope.
* </p>
*
* <p>
* Every webbeans instance has an associated dependent context. Each dependent context
* is destroyed with its parent webbeans component instance.
* </p>
*
* <p>
* Please see <b>8.3 Dependent pseudo-scope</b> of the specification
* for getting furhter information.
* </p>
*
*/
@Scope
@Target( { ElementType.METHOD, ElementType.TYPE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface Dependent
{
}
| 790 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/SessionScoped.java | /*
* 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 javax.enterprise.context;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* Session scoped.
* @version $Rev$ $Date$
*
*/
@Target( { TYPE, METHOD, FIELD})
@Retention(RUNTIME)
@Documented
@NormalScope(passivating=true)
@Inherited
public @interface SessionScoped
{
}
| 791 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/RequestScoped.java | /*
* 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 javax.enterprise.context;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* Defines the request scope.
*
* <p>
* Please see <b>Request context lifecycle</b> of the specification
* for getting furher information.
* </p>
*
* @version $Rev$ $Date$
*/
@Target( { TYPE, METHOD, FIELD })
@Retention(RUNTIME)
@Documented
@NormalScope
@Inherited
public @interface RequestScoped
{
}
| 792 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/spi/Context.java | /*
* 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 javax.enterprise.context.spi;
import java.lang.annotation.Annotation;
import javax.enterprise.context.ContextNotActiveException;
import javax.enterprise.context.NormalScope;
/**
* Every webbeans component has an associated context that are
* defined by the {@link NormalScope} annotation. Webbeans components
* that are contained in the context are managed by the webbeans container.
*
* <p>
* Every context has a well-defined lifecycle. It means that
* in some time, context is active and some other time context may
* be passive. Moreover, each context is created and destroyed by the container
* according to the timing requirements. For example, request context is started by every
* http request and destroyed at the end of the http response. According to the current thread,
* active context is called an thread current context.
* </p>
*
* <p>
* Context is responsible for creating and destroying the {@link Contextual} instances of the
* webbeans components.
* </p>
*
* @version $Rev$ $Date$
*/
public interface Context
{
/**
* Returns the scope type of the context.
*
* @return the scope type of the context
*/
public Class<? extends Annotation> getScope();
/**
* If the context is not active, throws {@link ContextNotActiveException}.
* Otherwise, it looks for the given component instance in the context map. If
* this context contains the given webbeans component instance, it returns the component.
* If the component is not found in this context map, it looks for the <code>creationalContext</code>
* argument. If it is null, it returns null, otherwise new webbeans instance is created
* and puts into the context and returns it.
*
* @param <T> type of the webbeans component
* @param component webbeans component
* @param creationalContext {@link CreationalContext} instance
* @return the contextual instance or null
*/
public <T> T get(Contextual<T> component, CreationalContext<T> creationalContext);
/**
* Returns the instance of the webbeans in this context if exist otherwise return null.
*
* @param <T> type of the webbeans component
* @param component webbeans component
* @return the instance of the webbeans in this context if exist otherwise return null
*/
public <T> T get(Contextual<T> component);
/**
* Returns true if context is active according to the current thread,
* returns false otherwise.
*
* @return true if context is active according to the current thread,
* return false otherwise
*/
boolean isActive();
} | 793 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/spi/CreationalContext.java | /*
* 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 javax.enterprise.context.spi;
/**
* The CreationalContext holds incomplete Bean instances. This may be caused by
* a situation like in the following example: <code>
* @ApplicationScoped class Foo
* {
* @Current Bar _bar;
* }
*
* @ApplicationScoped class Bar
* {
* @Current Foo _bar;
* }
* </code>
*
* <p>
* Generally it is used for prohibiting the circular references of the webbeans.
* </p>
*
* @version $Rev$ $Date$
*/
public interface CreationalContext<T>
{
/**
* Puts new incomplete instance into the creational context.
*
* @param incompleteInstance incomplete webbeans instance
*/
public void push(T incompleteInstance);
/**
* Destorys all dependent objects of the instance
* that is being destroyed.
*/
public void release();
}
| 794 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/context/spi/Contextual.java | /*
* 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 javax.enterprise.context.spi;
import javax.enterprise.inject.CreationException;
/**
* Each webbeans instance that is contained in the <code>Context</code>
* must be defined as <code>Contextual</code>.
*
* This interface defines the creating and destroying of the webbeans instances
* that are contained in the its {@link Context} instance.
*
* @param <T> type of the webbeans component
* @see Context
*
* @version $Rev$ $Date$
*/
public interface Contextual<T>
{
/**
* Creates and returns a new instance of the webbeans component.
*
* @param context new creational context instance
* @return the new instance of the webbeans component
* @throws CreationException if any exception occurs
*/
public T create(CreationalContext<T> context);
/**
* Destroys the instance. Any destroy logic is encapsulated
* in this method.
*
* @param instance already created webbeans instance
* @param context creational context
*/
public void destroy(T instance, CreationalContext<T> context);
}
| 795 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/util/AnnotationLiteral.java | /*
* 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 javax.enterprise.util;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
/**
* Annotation literal utility.
*
* @param <T> wrapped annotation class
* @version $Rev$ $Date$
*/
@SuppressWarnings("unchecked")
public abstract class AnnotationLiteral<T extends Annotation> implements Annotation, Serializable
{
private static final long serialVersionUID = -1885320698638161810L;
private Class<T> annotationType;
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
protected AnnotationLiteral()
{
this.annotationType = getAnnotationType(getClass());
}
public Class<? extends Annotation> annotationType()
{
return annotationType;
}
private Class<T> getAnnotationType(Class<?> definedClazz)
{
Type superClazz = definedClazz.getGenericSuperclass();
Class<T> clazz = null;
if (superClazz.equals(Object.class))
{
throw new RuntimeException("Super class must be parametrized type!");
}
else if (superClazz instanceof ParameterizedType)
{
ParameterizedType paramType = (ParameterizedType) superClazz;
Type[] actualArgs = paramType.getActualTypeArguments();
if (actualArgs.length == 1)
{
//Actual annotation type
Type type = actualArgs[0];
if (type instanceof Class)
{
clazz = (Class<T>) type;
return clazz;
}
else
{
throw new RuntimeException("Not class type!");
}
}
else
{
throw new RuntimeException("More than one parametric type!");
}
}
else
{
return getAnnotationType((Class<?>) superClazz);
}
}
@Override
public boolean equals(Object other)
{
Method[] methods = (Method[])AccessController.doPrivileged(new PrivilegedAction() {
public Object run()
{
return annotationType.getDeclaredMethods();
}
});
if(other == this)
{
return true;
}
if(other == null)
{
return false;
}
if (other instanceof Annotation)
{
Annotation annotOther = (Annotation) other;
if (this.annotationType().equals(annotOther.annotationType()))
{
for (Method method : methods)
{
Object value = callMethod(this, method);
Object annotValue = callMethod(annotOther, method);
if((value == null && annotValue != null) || (value != null && annotValue == null))
{
return false;
}
if(value == null && annotValue == null)
{
continue;
}
Class<?> valueClass = value.getClass();
Class<?> annotValueClass = annotValue.getClass();
if(valueClass.isPrimitive() && annotValueClass.isPrimitive())
{
if((valueClass != Float.TYPE && annotValue != Float.TYPE)
|| (valueClass != Double.TYPE && annotValue != Double.TYPE))
{
if(value != annotValue)
{
return false;
}
}
}
else if(valueClass.isArray() && annotValueClass.isArray())
{
Class<?> type = valueClass.getComponentType();
if(type.isPrimitive())
{
if(Long.TYPE == type)
{
if(!Arrays.equals(((Long[])value),(Long[])annotValue)) return false;
}
else if(Integer.TYPE == type)
{
if(!Arrays.equals(((Integer[])value),(Integer[])annotValue)) return false;
}
else if(Short.TYPE == type)
{
if(!Arrays.equals(((Short[])value),(Short[])annotValue)) return false;
}
else if(Double.TYPE == type)
{
if(!Arrays.equals(((Double[])value),(Double[])annotValue)) return false;
}
else if(Float.TYPE == type)
{
if(!Arrays.equals(((Float[])value),(Float[])annotValue)) return false;
}
else if(Boolean.TYPE == type)
{
if(!Arrays.equals(((Boolean[])value),(Boolean[])annotValue)) return false;
}
else if(Byte.TYPE == type)
{
if(!Arrays.equals(((Byte[])value),(Byte[])annotValue)) return false;
}
else if(Character.TYPE == type)
{
if(!Arrays.equals(((Character[])value),(Character[])annotValue)) return false;
}
}
else
{
if(!Arrays.equals(((Object[])value),(Object[])annotValue)) return false;
}
}
else if (value != null && annotValue != null)
{
if (!value.equals(annotValue))
{
return false;
}
}
}
return true;
}
}
return false;
}
private Object callMethod(Object instance, Method method)
{
boolean access = method.isAccessible();
try
{
if (!method.isAccessible())
{
AccessController.doPrivileged(new PrivilegedActionForAccessibleObject(method, true));
}
return method.invoke(instance, EMPTY_OBJECT_ARRAY);
}
catch (Exception e)
{
throw new RuntimeException("Exception in method call : " + method.getName(), e);
}
finally
{
AccessController.doPrivileged(new PrivilegedActionForAccessibleObject(method, access));
}
}
@Override
public int hashCode()
{
Method[] methods = (Method[])AccessController.doPrivileged(new PrivilegedAction() {
public Object run()
{
return annotationType.getDeclaredMethods();
}
});
int hashCode = 0;
for (Method method : methods)
{
// Member name
int name = 127 * method.getName().hashCode();
// Member value
Object object = callMethod(this, method);
int value = 0;
if(object.getClass().isArray())
{
Class<?> type = object.getClass().getComponentType();
if(type.isPrimitive())
{
if(Long.TYPE == type)
{
value = Arrays.hashCode((Long[])object);
}
else if(Integer.TYPE == type)
{
value = Arrays.hashCode((Integer[])object);
}
else if(Short.TYPE == type)
{
value = Arrays.hashCode((Short[])object);
}
else if(Double.TYPE == type)
{
value = Arrays.hashCode((Double[])object);
}
else if(Float.TYPE == type)
{
value = Arrays.hashCode((Float[])object);
}
else if(Boolean.TYPE == type)
{
value = Arrays.hashCode((Long[])object);
}
else if(Byte.TYPE == type)
{
value = Arrays.hashCode((Byte[])object);
}
else if(Character.TYPE == type)
{
value = Arrays.hashCode((Character[])object);
}
}
else
{
value = Arrays.hashCode((Object[])object);
}
}
else
{
value = object.hashCode();
}
hashCode += name ^ value;
}
return hashCode;
}
@Override
public String toString()
{
Method[] methods = (Method[])AccessController.doPrivileged(new PrivilegedAction() {
public Object run()
{
return annotationType.getDeclaredMethods();
}
});
StringBuilder sb = new StringBuilder("@" + annotationType().getName() + "(");
int lenght = methods.length;
for (int i = 0; i < lenght; i++)
{
// Member name
sb.append(methods[i].getName()).append("=");
// Member value
sb.append(callMethod(this, methods[i]));
if (i < lenght - 1)
{
sb.append(",");
}
}
sb.append(")");
return sb.toString();
}
protected static class PrivilegedActionForAccessibleObject implements PrivilegedAction<Object>
{
AccessibleObject object;
boolean flag;
protected PrivilegedActionForAccessibleObject(AccessibleObject object, boolean flag)
{
this.object = object;
this.flag = flag;
}
public Object run()
{
object.setAccessible(flag);
return null;
}
}
}
| 796 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/util/Nonbinding.java | /*
* 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 javax.enterprise.util;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* Indicates that <code>Qualifier</code> annotation member
* is not contained in the type safe resolution algorithm.
*
* <p>
* Example:
*
* <pre>
* @Qualifier
* public @interface Mock {
* @NonBinding String name;
* }
* </pre>
*
* <b>Mock</b> qualifier <i>name</i> member variable is excepted from the
* type safe resolution algorithm while comparing the qualifiers.
*
* </p>
*/
@Retention(RUNTIME)
@Target(METHOD)
public @interface Nonbinding
{
}
| 797 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/util/TypeLiteral.java | /*
* 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 javax.enterprise.util;
import java.io.Serializable;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
/**
* Type literal implementation.
* @version $Rev$ $Date$
*
* @param <T> wrapped type
*/
@SuppressWarnings("unchecked")
public abstract class TypeLiteral<T> implements Serializable
{
private static final long serialVersionUID = 6993258591899719600L;
private Type definedType;
protected TypeLiteral()
{
this.definedType = getDefinedType(this.getClass());
}
public final Type getType()
{
return definedType;
}
public final Class<T> getRawType()
{
Class<T> rawType = null;
if (this.definedType instanceof Class)
{
rawType = (Class<T>) this.definedType;
}
else if (this.definedType instanceof ParameterizedType)
{
ParameterizedType pt = (ParameterizedType) this.definedType;
rawType = (Class<T>) pt.getRawType();
}
else if (this.definedType instanceof GenericArrayType)
{
rawType = (Class<T>) Object[].class;
}
else
{
throw new RuntimeException("Illegal type for the Type Literal Class");
}
return rawType;
}
private Type getDefinedType(Class<?> clazz)
{
Type type = null;
if (clazz == null)
{
throw new RuntimeException("Class parameter can not be null!");
}
Type superClazz = clazz.getGenericSuperclass();
if (superClazz.equals(Object.class))
{
throw new RuntimeException("Super class must be parametrized type!");
}
else if (superClazz instanceof ParameterizedType)
{
ParameterizedType pt = (ParameterizedType) superClazz;
Type[] actualArgs = pt.getActualTypeArguments();
if (actualArgs.length == 1)
{
type = actualArgs[0];
}
else
{
throw new RuntimeException("More than one parametric type!");
}
}
else
{
type = getDefinedType((Class<?>) superClazz);
}
return type;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((definedType == null) ? 0 : definedType.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
TypeLiteral other = (TypeLiteral) obj;
if (definedType == null)
{
if (other.definedType != null)
{
return false;
}
}
else if (!definedType.equals(other.definedType))
{
return false;
}
return true;
}
} | 798 |
0 | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise | Create_ds/geronimo-specs/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/inject/Any.java | /*
* 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 javax.enterprise.inject;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Defines any qualifier in the injection point.
*
* @version $Rev$ $Date$
*/
@Target( { TYPE, METHOD, FIELD, PARAMETER })
@Retention(RUNTIME)
@Documented
@Qualifier
public @interface Any
{
}
| 799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.