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/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/GetterMethods.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.commons.ognl.test.objects;
/**
*
*/
public class GetterMethods
{
private int theInt = 1;
public boolean isAllowDisplay( Object something )
{
return true;
}
public int getAllowDisplay()
{
return theInt;
}
public void setAllowDisplay( int val )
{
theInt = val;
}
}
| 4,500 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/PersonGenericObject.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.commons.ognl.test.objects;
/**
*
*/
public class PersonGenericObject
implements GenericObject
{
public int getId()
{
return 1;
}
public String getDisplayName()
{
return "Henry Collins";
}
}
| 4,501 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/GameGeneric.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.commons.ognl.test.objects;
/**
*
*/
public class GameGeneric
extends BaseGeneric<GameGenericObject, Long>
{
public GameGeneric()
{
_value = new GameGenericObject();
}
}
| 4,502 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/GenericObject.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.commons.ognl.test.objects;
/**
* Used by {@link BaseGeneric} to reference a class type.
*/
public interface GenericObject
{
int getId();
String getDisplayName();
}
| 4,503 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/TestModel.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.commons.ognl.test.objects;
/**
*
*/
public class TestModel
{
public Copy getCopy()
{
return new Copy();
}
public Model getUnassignedCopyModel()
{
return new Model();
}
public boolean isCanApproveCopy()
{
return true;
}
public Entry getEntry()
{
return new Entry();
}
}
| 4,504 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/Bean3.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.commons.ognl.test.objects;
import java.util.HashMap;
import java.util.Map;
public class Bean3
{
private int value = 100;
private final Map<String, String> map;
{
map = new HashMap<String, String>();
map.put( "foo", "bar" );
map.put( "bar", "baz" );
}
private String _nullValue;
private Object _indexValue;
public int getValue()
{
return value;
}
public void setValue( int value )
{
this.value = value;
}
public Object getIndexedValue( int index )
{
return _indexValue;
}
public void setIndexedValue( int index, Object value )
{
_indexValue = value;
}
public Map<String, String> getMap()
{
return map;
}
public void setNullValue( String value )
{
_nullValue = value;
}
public String getNullValue()
{
return _nullValue;
}
/*
* (non-Javadoc)
* @see Object#hashCode()
*/
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ( ( _indexValue == null ) ? 0 : _indexValue.hashCode() );
return result;
}
/*
* (non-Javadoc)
* @see Object#equals(Object)
*/
public boolean equals( Object obj )
{
if ( this == obj )
return true;
if ( obj == null )
return false;
if ( getClass() != obj.getClass() )
return false;
final Bean3 other = (Bean3) obj;
if ( _indexValue == null )
{
if ( other._indexValue != null )
return false;
}
else if ( !_indexValue.equals( other._indexValue ) )
return false;
return true;
}
}
| 4,505 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/BeanProviderAccessor.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.commons.ognl.test.objects;
import org.apache.commons.ognl.ObjectPropertyAccessor;
import org.apache.commons.ognl.OgnlContext;
import org.apache.commons.ognl.OgnlException;
import org.apache.commons.ognl.OgnlRuntime;
import org.apache.commons.ognl.PropertyAccessor;
import org.apache.commons.ognl.enhance.ExpressionCompiler;
import org.apache.commons.ognl.enhance.UnsupportedCompilationException;
import java.util.Map;
/**
* Implementation of provider that works with {@link BeanProvider} instances.
*/
public class BeanProviderAccessor
extends ObjectPropertyAccessor
implements PropertyAccessor
{
@Override
public Object getProperty( Map<String, Object> context, Object target, Object name )
throws OgnlException
{
BeanProvider provider = (BeanProvider) target;
String beanName = (String) name;
return provider.getBean( beanName );
}
/**
* Returns true if the name matches a bean provided by the provider. Otherwise invokes the super implementation.
**/
@Override
public boolean hasGetProperty( Map<String, Object> context, Object target, Object oname )
throws OgnlException
{
BeanProvider provider = (BeanProvider) target;
String beanName = ( (String) oname ).replace( "\"", "" );
return provider.getBean( beanName ) != null;
}
@Override
public String getSourceAccessor( OgnlContext context, Object target, Object name )
{
BeanProvider provider = (BeanProvider) target;
String beanName = ( (String) name ).replace( "\"", "" );
if ( provider.getBean( beanName ) != null )
{
context.setCurrentAccessor( BeanProvider.class );
context.setCurrentType( provider.getBean( beanName ).getClass() );
ExpressionCompiler.addCastString( context,
"(("
+ OgnlRuntime.getCompiler( context ).getInterfaceClass( provider.getBean( beanName ).getClass() ).getName()
+ ")" );
return ".getBean(\"" + beanName + "\"))";
}
return super.getSourceAccessor( context, target, name );
}
@Override
public String getSourceSetter( OgnlContext context, Object target, Object name )
{
throw new UnsupportedCompilationException( "Can't set beans on BeanProvider." );
}
}
| 4,506 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/MenuItem.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.commons.ognl.test.objects;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
public class MenuItem
{
private final String page;
private final String label;
private List<MenuItem> children = new ArrayList<MenuItem>();
public MenuItem( String page, String label )
{
this( page, label, new ArrayList<MenuItem>() );
}
public MenuItem( String page, String label, List<MenuItem> children )
{
this.page = page;
this.label = label;
this.children = children;
}
public List<MenuItem> getChildren()
{
return children;
}
public String getLabel()
{
return label;
}
public String getPage()
{
return page;
}
public String toString()
{
return new StringBuilder( "MenuItem[" )
.append( "page=" )
.append( getPage() )
.append( ",label=" )
.append( getLabel() )
.append( ",children=" )
.append( getChildren().size() )
.append( "]" ).toString();
}
}
| 4,507 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/Messages.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.commons.ognl.test.objects;
import java.util.Map;
/**
*
*/
public class Messages
{
Map _source;
public Messages( Map source )
{
_source = source;
}
public String getMessage( String key )
{
return (String) _source.get( key );
}
public String format( String key, Object[] params )
{
return "foo";
}
public String format( String key, Object param1, Object param2, Object param3 )
{
return "blah";
}
public String format( String key, Object param1 )
{
return "first";
}
public String format( String key, Object param1, Object param2 )
{
return "haha";
}
}
| 4,508 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/BeanProviderImpl.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.commons.ognl.test.objects;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* Implementation of {@link BeanProvider}.
*/
public class BeanProviderImpl
implements Serializable, BeanProvider
{
private final Map _map = new HashMap();
public BeanProviderImpl()
{
}
public Object getBean( String name )
{
return _map.get( name );
}
public void setBean( String name, Object bean )
{
_map.put( name, bean );
}
}
| 4,509 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/BeanProvider.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.commons.ognl.test.objects;
/**
* Test interface to be used with a custom propery accessor.
*/
public interface BeanProvider
{
/**
* Gets a bean by name.
*
* @param name
* @return the related bean by name
*/
Object getBean( String name );
/**
* Sets a new bean mapping.
*
* @param name
* @param bean
*/
void setBean( String name, Object bean );
}
| 4,510 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/ListSourceImpl.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.commons.ognl.test.objects;
import java.util.ArrayList;
/**
*
*/
public class ListSourceImpl
extends ArrayList
implements ListSource
{
public ListSourceImpl()
{
}
public int getTotal()
{
return super.size();
}
public Object addValue( Object value )
{
return super.add( value );
}
public Object getName()
{
return null;
}
}
| 4,511 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/Bean2.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.commons.ognl.test.objects;
public class Bean2
{
private final Bean3 bean3 = new Bean3();
private boolean _pageBreakAfter;
public Long getId()
{
return 1l;
}
public Bean3 getBean3()
{
return bean3;
}
public long getMillis()
{
return 1000 * 60 * 2;
}
public boolean isCarrier()
{
return false;
}
public boolean isPageBreakAfter()
{
return _pageBreakAfter;
}
public void setPageBreakAfter( boolean value )
{
_pageBreakAfter = value;
}
public void togglePageBreakAfter()
{
_pageBreakAfter ^= true;
}
public boolean equals( Object o )
{
if ( this == o )
return true;
if ( o == null || getClass() != o.getClass() )
return false;
Bean2 bean2 = (Bean2) o;
return _pageBreakAfter == bean2._pageBreakAfter;
}
public int hashCode()
{
return ( _pageBreakAfter ? 1 : 0 );
}
}
| 4,512 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/TestInherited1.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.commons.ognl.test.objects;
/**
*
*/
public class TestInherited1
implements Inherited
{
public String getMyString()
{
return "inherited1";
}
}
| 4,513 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/FormImpl.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.commons.ognl.test.objects;
/**
*
*/
public class FormImpl
extends ComponentImpl
implements IForm
{
}
| 4,514 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/IComponent.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.commons.ognl.test.objects;
/**
*
*/
public interface IComponent
{
String getClientId();
void setClientId( String id );
int getCount( String index );
void setCount( String index, int count );
}
| 4,515 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/IContentProvider.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.commons.ognl.test.objects;
import java.util.List;
/**
*
*/
public interface IContentProvider
{
List getElements();
}
| 4,516 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/BaseIndexed.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.commons.ognl.test.objects;
/**
* Class used to test inheritance.
*/
public class BaseIndexed
{
public Object getLine( int index )
{
return "line:" + index;
}
}
| 4,517 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/SearchTab.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.commons.ognl.test.objects;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Test for OGNL-131.
*/
public class SearchTab
{
/**
* Flags stating which search criteria are selected
*/
private List<List<Boolean>> searchCriteriaSelections = new ArrayList<List<Boolean>>();
{
searchCriteriaSelections.add( Arrays.asList( Boolean.TRUE, Boolean.FALSE, Boolean.FALSE ) );
searchCriteriaSelections.add( Arrays.asList( Boolean.FALSE, Boolean.TRUE, Boolean.TRUE ) );
}
public List<List<Boolean>> getSearchCriteriaSelections()
{
return this.searchCriteriaSelections;
}
public void setSearchCriteriaSelections( List<List<Boolean>> selections )
{
this.searchCriteriaSelections = selections;
}
/**
* Filters that can be applied to this tabs searches
*/
private List<SearchCriteria> searchCriteria = new ArrayList<SearchCriteria>();
{
searchCriteria.add( new SearchCriteria( "Crittery critters" ) );
searchCriteria.add( new SearchCriteria( "Woodland creatures" ) );
}
public List<SearchCriteria> getSearchCriteria()
{
return this.searchCriteria;
}
public void setSearchCriteria( List<SearchCriteria> searchCriteria )
{
this.searchCriteria = searchCriteria;
}
/**
* 2D list of options available for each criteria
*/
private List<List<String>> searchCriteriaOptions = new ArrayList<List<String>>();
public List<List<String>> getSearchCriteriaOptions()
{
return this.searchCriteriaOptions;
}
public void setSearchCriteriaOptions( List<List<String>> searchCriteriaOptions )
{
this.searchCriteriaOptions = searchCriteriaOptions;
}
}
| 4,518 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/PropertyHolder.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.commons.ognl.test.objects;
/**
* Simple class used to test various kind of property resolutions.
*/
public class PropertyHolder
{
String _value = "";
String _search = "foo";
public String getValue()
{
return _value;
}
public void setValue( String value )
{
_value = value;
}
public boolean hasValue()
{
return _value != null && !_value.isEmpty();
}
public void setSearch( String value )
{
_search = value;
}
public String getSearch()
{
return _search;
}
public void search()
{
}
}
| 4,519 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/Copy.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.commons.ognl.test.objects;
/**
*
*/
public class Copy
{
public int size()
{
return 1;
}
}
| 4,520 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/ObjectIndexed.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.commons.ognl.test.objects;
public class ObjectIndexed
extends BaseObjectIndexed
{
public ObjectIndexed()
{
setAttribute( "foo", "bar" );
setAttribute( "bar", "baz" );
setAttribute( "other", new OtherObjectIndexed() );
}
}
| 4,521 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/GenericService.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.commons.ognl.test.objects;
/**
*
*/
public interface GenericService
{
String getFullMessageFor( PersonGenericObject person, Object... arguments );
String getFullMessageFor( GameGenericObject game, Object... arguments );
}
| 4,522 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/IndexedMapObject.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.commons.ognl.test.objects;
/**
* Simple object used to test indexed map references using "#this" references.
*/
public class IndexedMapObject
{
String property;
public IndexedMapObject( String property )
{
this.property = property;
}
public String getProperty()
{
return property;
}
}
| 4,523 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/Indexed.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.commons.ognl.test.objects;
import java.util.*;
public class Indexed
extends BaseIndexed
{
private String[] _values = new String[] { "foo", "bar", "baz" };
private final List _list = new ArrayList();
private final ListSource _source = new ListSourceImpl();
private final Map _props = new HashMap();
public Indexed()
{
_list.add( new Integer( 1 ) );
_list.add( new Integer( 2 ) );
_list.add( new Integer( 3 ) );
_source.addValue( new Bean2() );
}
public Indexed( String[] values )
{
_values = values;
}
/* Indexed property "_values" */
public String[] getValues()
{
return _values;
}
public void setValues( String[] value )
{
_values = value;
}
/**
* This method returns the string from the array and appends "xxx" to distinguish the "get" method from the direct
* array access.
*/
public String getValues( int index )
{
return _values[index] + "xxx";
}
public void setValues( int index, String value )
{
if ( value.endsWith( "xxx" ) )
{
_values[index] = value.substring( 0, value.length() - 3 );
}
else
{
_values[index] = value;
}
}
public Collection getList()
{
return _list;
}
public String getTitle( int count )
{
return "Title count " + count;
}
public ListSource getSource()
{
return _source;
}
public void setProperty( String property, Object value )
{
_props.put( property, value );
}
public Object getProperty( String property )
{
return _props.get( property );
}
}
| 4,524 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/MyMap.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.commons.ognl.test.objects;
import java.util.*;
/**
* This tests the interface inheritence test. This is a subinterface of Map and therefore should inherit the Map
* property accessor.
*/
public interface MyMap
extends Map
{
String getDescription();
}
| 4,525 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/BaseGeneric.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.commons.ognl.test.objects;
import java.io.Serializable;
/**
* Used to test ognl handling of java generics.
*/
public class BaseGeneric<E extends GenericObject, I extends Serializable>
{
E _value;
GenericService _service;
protected I[] ids;
public BaseGeneric()
{
_service = new GenericServiceImpl();
}
public void setIds( I[] ids )
{
this.ids = ids;
}
public I[] getIds()
{
return this.ids;
}
public String getMessage()
{
return "Message";
}
public E getValue()
{
return _value;
}
public GenericService getService()
{
return _service;
}
public String format( Object value )
{
return value.toString();
}
}
| 4,526 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/ComponentImpl.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.commons.ognl.test.objects;
/**
*
*/
public class ComponentImpl
implements IComponent
{
String _clientId;
int _count = 0;
public String getClientId()
{
return _clientId;
}
public void setClientId( String id )
{
_clientId = id;
}
public int getCount( String index )
{
return _count;
}
public void setCount( String index, int count )
{
_count = count;
}
}
| 4,527 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/GenericRoot.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.commons.ognl.test.objects;
/**
*
*/
public class GenericRoot
{
Root _root = new Root();
GenericCracker _cracker = new GenericCracker();
public Root getRoot()
{
return _root;
}
public void setRoot( Root root )
{
_root = root;
}
public GenericCracker getCracker()
{
return _cracker;
}
public void setCracker( GenericCracker cracker )
{
_cracker = cracker;
}
}
| 4,528 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/SetterReturns.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.commons.ognl.test.objects;
/**
*
*/
public class SetterReturns
{
private String _value = "";
public String getValue()
{
return _value;
}
public SetterReturns setValue( String value )
{
_value += value;
return this;
}
}
| 4,529 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/SecondBean.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.commons.ognl.test.objects;
/**
*/
public class SecondBean
extends BaseBean
{
public String getName()
{
return "SecondBean";
}
}
| 4,530 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/FirstBean.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.commons.ognl.test.objects;
/**
*/
public class FirstBean
extends BaseBean
{
public String getName()
{
return "FirstBean";
}
}
| 4,531 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/GameGenericObject.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.commons.ognl.test.objects;
/**
*
*/
public class GameGenericObject
implements GenericObject
{
public GameGenericObject()
{
}
public int getId()
{
return 20;
}
public String getDisplayName()
{
return "Halo 3";
}
public String getHappy()
{
return "happy";
}
}
| 4,532 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/Simple.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.commons.ognl.test.objects;
import org.apache.commons.ognl.test.OgnlTestCase;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
public class Simple
extends Object
{
private String stringValue = "test";
private float floatValue;
private int intValue;
private boolean booleanValue;
private BigInteger bigIntValue = BigInteger.valueOf( 0 );
private BigDecimal bigDecValue = new BigDecimal( 0.0 );
private final Root root = new Root();
private Bean3 _bean;
private Bean2 _bean2;
private Object[] _array;
private Messages _messages;
public Simple()
{
Map src = new HashMap();
src.put( "test", "This is a test" );
_messages = new Messages( src );
}
public Simple( Bean3 bean )
{
_bean = bean;
}
public Simple( Bean2 bean )
{
_bean2 = bean;
}
public Simple( Object[] values )
{
}
public Simple( String stringValue, float floatValue, int intValue )
{
this.stringValue = stringValue;
this.floatValue = floatValue;
this.intValue = intValue;
}
public void setValues( String stringValue, float floatValue, int intValue )
{
this.stringValue = stringValue;
this.floatValue = floatValue;
this.intValue = intValue;
}
public String getStringValue()
{
return stringValue;
}
public void setStringValue( String value )
{
stringValue = value;
}
public float getFloatValue()
{
return floatValue;
}
public void setFloatValue( float value )
{
floatValue = value;
}
public int getIntValue()
{
return intValue;
}
public void setIntValue( int value )
{
intValue = value;
}
public boolean getValueIsTrue( Object currValue )
{
return true;
}
public boolean getBooleanValue()
{
return booleanValue;
}
public void setBooleanValue( boolean value )
{
booleanValue = value;
}
public BigInteger getBigIntValue()
{
return bigIntValue;
}
public void setArray( Object[] values )
{
_array = values;
}
public Object[] getArray()
{
return _array;
}
public void setBigIntValue( BigInteger value )
{
bigIntValue = value;
}
public BigDecimal getBigDecValue()
{
return bigDecValue;
}
public void setBigDecValue( BigDecimal value )
{
bigDecValue = value;
}
public Root getRootValue()
{
return root;
}
public Messages getMessages()
{
return _messages;
}
public int getOne()
{
return 1;
}
public int getTwo()
{
return 2;
}
public int getThree()
{
return 3;
}
public int getTestValue( int val )
{
return val + 1;
}
public boolean isEditorDisabled()
{
return false;
}
public boolean isDisabled()
{
return true;
}
public GetterMethods getMethodsTest()
{
return new GetterMethods();
}
public String getDisplayValue( int val )
{
return "test";
}
public boolean equals( Object other )
{
boolean result = false;
if ( other instanceof Simple )
{
Simple os = (Simple) other;
result =
OgnlTestCase.isEqual( os.getStringValue(), getStringValue() ) && ( os.getIntValue() == getIntValue() );
}
return result;
}
public boolean isThisVarArgsWorking( Object... arguments )
{
return true;
}
}
| 4,533 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/Model.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.commons.ognl.test.objects;
/**
*
*/
public class Model
{
public int getOptionCount()
{
return 1;
}
}
| 4,534 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/IndexedSetObject.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.commons.ognl.test.objects;
import java.util.HashMap;
/**
* Test for OGNL-119.
*/
public class IndexedSetObject
{
private final HashMap<String, Object> things = new HashMap<String, Object>();
public IndexedSetObject()
{
things.put( "x", new Container( 1 ) );
}
public Object getThing( String index )
{
return things.get( index );
}
public void setThing( String index, Object value )
{
things.put( index, value );
}
public static class Container
{
private int val;
public Container( int val )
{
this.val = val;
}
public int getVal()
{
return val;
}
public void setVal( int val )
{
this.val = val;
}
}
}
| 4,535 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/Entry.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.commons.ognl.test.objects;
/**
*
*/
public class Entry
{
private final int _size = 1;
public int size()
{
return _size;
}
public Copy getCopy()
{
return new Copy();
}
public boolean equals( Object o )
{
if ( this == o )
return true;
if ( o == null || getClass() != o.getClass() )
return false;
Entry entry = (Entry) o;
return _size == entry._size;
}
public int hashCode()
{
return _size;
}
}
| 4,536 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/MyMapImpl.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.commons.ognl.test.objects;
import java.util.*;
/**
* This tests the interface inheritence test. This test implements MyMap->Map but extends Object, therefore should be
* coded using MapPropertyAccessor instead of ObjectPropertyAccessor.
*/
public class MyMapImpl
extends Object
implements MyMap
{
private final Map map = new HashMap();
public void clear()
{
map.clear();
}
public boolean containsKey( Object key )
{
return map.containsKey( key );
}
public boolean containsValue( Object value )
{
return map.containsValue( value );
}
public Set entrySet()
{
return map.entrySet();
}
public boolean equals( Object o )
{
return map.equals( o );
}
public Object get( Object key )
{
return map.get( key );
}
public int hashCode()
{
return map.hashCode();
}
public boolean isEmpty()
{
return map.isEmpty();
}
public Set keySet()
{
return map.keySet();
}
public Object put( Object key, Object value )
{
return map.put( key, value );
}
public void putAll( Map t )
{
map.putAll( t );
}
public Object remove( Object key )
{
return map.remove( key );
}
public int size()
{
return map.size();
}
public Collection values()
{
return map.values();
}
public String getDescription()
{
return "MyMap implementation";
}
}
| 4,537 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/ListSource.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.commons.ognl.test.objects;
/**
*
*/
public interface ListSource
{
int getTotal();
Object addValue( Object value );
Object getName();
}
| 4,538 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/SubclassSyntheticObject.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.commons.ognl.test.objects;
import java.util.ArrayList;
/**
* Simple subclass.
*/
public class SubclassSyntheticObject
extends BaseSyntheticObject
{
public ArrayList getList()
{
return new ArrayList();
}
}
| 4,539 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/EvenOdd.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.commons.ognl.test.objects;
/**
*
*/
public class EvenOdd
{
private boolean even = true;
/**
* Returns "even" or "odd". Whatever it returns on one invocation, it will return the opposite on the next. By
* default, the first value returned is "even".
*/
public String getNext()
{
String result = even ? "even" : "odd";
even = !even;
return result;
}
public boolean isEven()
{
return even;
}
/**
* Overrides the even flag.
*/
public void setEven( boolean value )
{
even = value;
}
}
| 4,540 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/objects/ComponentSubclass.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.commons.ognl.test.objects;
/**
*
*/
public class ComponentSubclass
extends ComponentImpl
{
int _count = 0;
public int getCount()
{
return _count;
}
public void setCount( int count )
{
_count = count;
}
}
| 4,541 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/test/enhance/TestExpressionCompiler.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.commons.ognl.test.enhance;
import org.apache.commons.ognl.Node;
import org.apache.commons.ognl.Ognl;
import org.apache.commons.ognl.OgnlContext;
import org.apache.commons.ognl.enhance.ExpressionCompiler;
import org.apache.commons.ognl.enhance.OgnlExpressionCompiler;
import org.apache.commons.ognl.test.objects.Bean1;
import org.apache.commons.ognl.test.objects.GenericRoot;
import org.apache.commons.ognl.test.objects.IndexedMapObject;
import org.apache.commons.ognl.test.objects.Inherited;
import org.apache.commons.ognl.test.objects.Root;
import org.apache.commons.ognl.test.objects.TestInherited1;
import org.apache.commons.ognl.test.objects.TestInherited2;
import org.junit.Before;
import org.junit.Test;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import static junit.framework.Assert.*;
/**
* Tests functionality of {@link ExpressionCompiler}.
*/
public class TestExpressionCompiler
{
OgnlExpressionCompiler _compiler;
OgnlContext _context = (OgnlContext) Ognl.createDefaultContext( null );
@Before
public void setUp()
{
_compiler = new ExpressionCompiler();
}
@Test
public void test_Get_Property_Access()
throws Throwable
{
Node expr = (Node) Ognl.parseExpression( "bean2" );
Bean1 root = new Bean1();
_compiler.compileExpression( _context, expr, root );
assertNotNull( expr.getAccessor().get( _context, root ) );
}
@Test
public void test_Get_Indexed_Property()
throws Throwable
{
Node expr = (Node) Ognl.parseExpression( "bean2.bean3.indexedValue[25]" );
Bean1 root = new Bean1();
assertNull( Ognl.getValue( expr, _context, root ) );
_compiler.compileExpression( _context, expr, root );
assertNull( expr.getAccessor().get( _context, root ) );
}
@Test
public void test_Set_Indexed_Property()
throws Throwable
{
Node expr = (Node) Ognl.parseExpression( "bean2.bean3.indexedValue[25]" );
Bean1 root = new Bean1();
assertNull( Ognl.getValue( expr, _context, root ) );
_compiler.compileExpression( _context, expr, root );
expr.getAccessor().set( _context, root, "test string" );
assertEquals( "test string", expr.getAccessor().get( _context, root ) );
}
@Test
public void test_Expression()
throws Throwable
{
Node expr = (Node) Ognl.parseExpression( "bean2.bean3.value <= 24" );
Bean1 root = new Bean1();
assertEquals( Boolean.FALSE, Ognl.getValue( expr, _context, root ) );
_compiler.compileExpression( _context, expr, root );
assertEquals( Boolean.FALSE, expr.getAccessor().get( _context, root ) );
}
@Test
public void test_Get_Context_Property()
throws Throwable
{
_context.put( "key", "foo" );
Node expr = (Node) Ognl.parseExpression( "bean2.bean3.map[#key]" );
Bean1 root = new Bean1();
assertEquals( "bar", Ognl.getValue( expr, _context, root ) );
_compiler.compileExpression( _context, expr, root );
assertEquals( "bar", expr.getAccessor().get( _context, root ) );
_context.put( "key", "bar" );
assertEquals( "baz", Ognl.getValue( expr, _context, root ) );
assertEquals( "baz", expr.getAccessor().get( _context, root ) );
}
@Test
public void test_Set_Context_Property()
throws Throwable
{
_context.put( "key", "foo" );
Node expr = (Node) Ognl.parseExpression( "bean2.bean3.map[#key]" );
Bean1 root = new Bean1();
_compiler.compileExpression( _context, expr, root );
assertEquals( "bar", expr.getAccessor().get( _context, root ) );
_context.put( "key", "bar" );
assertEquals( "baz", expr.getAccessor().get( _context, root ) );
expr.getAccessor().set( _context, root, "bam" );
assertEquals( "bam", expr.getAccessor().get( _context, root ) );
}
@Test
public void test_Property_Index()
throws Throwable
{
Root root = new Root();
Node expr = Ognl.compileExpression( _context, root, "{index + 1}" );
Object ret = expr.getAccessor().get( _context, root );
assertTrue( Collection.class.isInstance( ret ) );
}
@Test
public void test_Root_Expression_Inheritance()
throws Throwable
{
Inherited obj1 = new TestInherited1();
Inherited obj2 = new TestInherited2();
Node expr = Ognl.compileExpression( _context, obj1, "myString" );
assertEquals( expr.getAccessor().get( _context, obj1 ), "inherited1" );
assertEquals( expr.getAccessor().get( _context, obj2 ), "inherited2" );
}
@Test
public void test_Create_Empty_Collection()
throws Throwable
{
Node expr = Ognl.compileExpression( _context, null, "{}" );
Object ret = expr.getAccessor().get( _context, null );
assertNotNull( ret );
assertTrue( Collection.class.isAssignableFrom( ret.getClass() ) );
}
public String getKey()
{
return "key";
}
@Test
public void test_Indexed_Property()
throws Throwable
{
Map<String,String> map = new HashMap<String,String>();
map.put( "key", "value" );
Node expression = Ognl.compileExpression( _context, this, "key" );
assertEquals( "key", expression.getAccessor().get( _context, this ) );
}
IndexedMapObject mapObject = new IndexedMapObject( "propertyValue" );
public IndexedMapObject getObject()
{
return mapObject;
}
public String getPropertyKey()
{
return "property";
}
@Test
public void test_Indexed_Map_Property()
throws Throwable
{
assertEquals( "propertyValue", Ognl.getValue( "object[propertyKey]", this ) );
_context.clear();
Node expression = Ognl.compileExpression( _context, this, "object[#this.propertyKey]" );
assertEquals( "propertyValue", expression.getAccessor().get( _context, this ) );
_context.clear();
expression = Ognl.compileExpression( _context, this, "object[propertyKey]" );
assertEquals( "propertyValue", expression.getAccessor().get( _context, this ) );
}
@Test
public void test_Set_Generic_Property()
throws Exception
{
_context.clear();
GenericRoot root = new GenericRoot();
Node node = Ognl.compileExpression( _context, root, "cracker.param" );
assertNull(node.getAccessor().get(_context, root));
node.getAccessor().set( _context, root, 0 );
assertEquals( 0, node.getAccessor().get( _context, root ) );
node.getAccessor().set( _context, root, 12 );
assertEquals( 12, node.getAccessor().get( _context, root ) );
}
}
| 4,542 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/internal/PropertyDescriptorCacheTest.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.commons.ognl.internal;
import org.apache.commons.ognl.internal.entry.PropertyDescriptorCacheEntryFactory;
import org.apache.commons.ognl.test.objects.Bean2;
import org.junit.Test;
import java.beans.PropertyDescriptor;
import java.util.Map;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
/**
* User: Maurizio Cucchiara
* Date: 10/15/11
* Time: 8:00 AM
*/
public class PropertyDescriptorCacheTest
{
ConcurrentHashMapCache<Class<?>, Map<String,PropertyDescriptor>> cache =
new ConcurrentHashMapCache<Class<?>, Map<String,PropertyDescriptor>>( new PropertyDescriptorCacheEntryFactory());
@Test
public void testGet( )
throws Exception
{
Map<String, PropertyDescriptor> d = getPropertyDescriptor( Bean2.class );
assertTrue( d.containsKey( "id" ) );
assertTrue( d.containsKey( "bean3" ) );
assertTrue( d.containsKey( "carrier" ) );
}
private Map<String, PropertyDescriptor> getPropertyDescriptor( Class<?> entry )
throws CacheException
{
Map<String, PropertyDescriptor> descriptor = cache.get( entry );
assertNotNull( descriptor );
return descriptor;
}
}
| 4,543 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/internal/FieldCacheTest.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.commons.ognl.internal;
import org.apache.commons.ognl.internal.entry.FieldCacheEntryFactory;
import org.apache.commons.ognl.test.objects.Bean2;
import org.junit.Test;
import java.lang.reflect.Field;
import java.util.Map;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
/**
* User: Maurizio Cucchiara
* Date: 10/15/11
* Time: 8:00 AM
*/
public class FieldCacheTest
{
ConcurrentHashMapCache<Class<?>, Map<String,Field>> cache =
new ConcurrentHashMapCache<Class<?>, Map<String,Field>>( new FieldCacheEntryFactory());
@Test
public void testGet( )
throws Exception
{
Map<String, Field> d = getFields( Bean2.class );
assertTrue( d.containsKey( "bean3" ) );
assertTrue( d.containsKey( "_pageBreakAfter" ) );
}
private Map<String, Field> getFields( Class<?> entry )
throws CacheException
{
Map<String, Field> descriptor = cache.get( entry );
assertNotNull( descriptor );
return descriptor;
}
}
| 4,544 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/internal/DeclaredMethodCacheTest.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.commons.ognl.internal;
import org.apache.commons.ognl.internal.entry.DeclaredMethodCacheEntry;
import org.apache.commons.ognl.internal.entry.DeclaredMethodCacheEntryFactory;
import org.apache.commons.ognl.test.objects.Root;
import org.junit.Test;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
/**
* User: Maurizio Cucchiara
* Date: 10/15/11
* Time: 9:18 AM
*/
public class DeclaredMethodCacheTest
{
Cache<DeclaredMethodCacheEntry, Map<String, List<Method>>> cache =
new ConcurrentHashMapCache<DeclaredMethodCacheEntry, Map<String, List<Method>>>(new DeclaredMethodCacheEntryFactory( ) );
@Test
public void testStaticGet( )
throws Exception
{
Map<String, List<Method>> methods = cache.get( new DeclaredMethodCacheEntry( Root.class, DeclaredMethodCacheEntry.MethodType.STATIC) );
assertNotNull( methods );
assertTrue( methods.containsKey( "getStaticInt" ) );
}
@Test
public void testNonStaticGet( )
throws Exception
{
Map<String, List<Method>> methods = cache.get( new DeclaredMethodCacheEntry( Root.class, DeclaredMethodCacheEntry.MethodType.NON_STATIC ) );
assertNotNull( methods );
assertTrue( methods.containsKey( "format" ) );
}
}
| 4,545 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/internal/MethodAccessCacheTest.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.commons.ognl.internal;
import org.apache.commons.ognl.internal.entry.MethodAccessCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.MethodAccessEntryValue;
import org.apache.commons.ognl.test.objects.Root;
import org.junit.Assert;
import org.junit.Test;
import java.lang.reflect.Method;
/**
* User: Maurizio Cucchiara
* Date: 10/17/11
* Time: 12:59 AM
*/
public class MethodAccessCacheTest
{
private final Cache<Method, MethodAccessEntryValue> cache =
new ConcurrentHashMapCache<Method, MethodAccessEntryValue>( new MethodAccessCacheEntryFactory( ) );
@Test
public void testGetAccessibleNonPublicMethod( )
throws Exception
{
Method method = Root.class.getDeclaredMethod( "getPrivateAccessorIntValue3" );
MethodAccessEntryValue methodAccessValue = cache.get( method );
Assert.assertTrue( methodAccessValue.isNotPublic( ) );
Assert.assertFalse( methodAccessValue.isAccessible());
}
@Test
public void testGetNotAccessibleNonPublicMethod( )
throws Exception
{
Method method = Root.class.getDeclaredMethod( "getPrivateAccessorIntValue3" );
method.setAccessible( true );
MethodAccessEntryValue methodAccessValue = cache.get( method );
Assert.assertTrue( methodAccessValue.isNotPublic( ) );
Assert.assertTrue( methodAccessValue.isAccessible());
}
@Test
public void testGetPublicMethod( )
throws NoSuchMethodException, CacheException
{
Method method = Root.class.getDeclaredMethod( "getArray" );
MethodAccessEntryValue methodAccessValue = cache.get( method );
Assert.assertFalse( methodAccessValue.isNotPublic( ) );
Assert.assertTrue( methodAccessValue.isAccessible());
}
}
| 4,546 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/internal/GenericMethodParameterTypeCacheTest.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.commons.ognl.internal;
import org.apache.commons.ognl.internal.entry.GenericMethodParameterTypeCacheEntry;
import org.apache.commons.ognl.internal.entry.GenericMethodParameterTypeFactory;
import org.apache.commons.ognl.test.objects.GameGeneric;
import org.junit.Assert;
import org.junit.Test;
import java.io.Serializable;
import java.lang.reflect.Method;
/**
* User: Maurizio Cucchiara
* Date: 10/16/11
* Time: 9:44 AM
*/
public class GenericMethodParameterTypeCacheTest
{
private final ConcurrentHashMapCache<GenericMethodParameterTypeCacheEntry, Class<?>[]> cache =
new ConcurrentHashMapCache<GenericMethodParameterTypeCacheEntry, Class<?>[]>( new GenericMethodParameterTypeFactory( ) );
@Test
public void testGet( )
throws NoSuchMethodException, CacheException
{
Method m = GameGeneric.class.getMethod( "setIds", Serializable[].class );
Class type = GameGeneric.class;
Class<?>[] types = cache.get( new GenericMethodParameterTypeCacheEntry( m, type ) );
Assert.assertEquals( 1, types.length );
Assert.assertEquals( Long[].class, types[0] );
}
}
| 4,547 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/internal/MethodPermCacheTest.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.commons.ognl.internal;
import org.apache.commons.ognl.internal.entry.MethodPermCacheEntryFactory;
import org.apache.commons.ognl.test.objects.Root;
import org.junit.Assert;
import org.junit.Test;
import java.lang.reflect.Method;
import java.security.Permission;
/**
* User: Maurizio Cucchiara
* Date: 10/17/11
* Time: 12:13 AM
*/
public class MethodPermCacheTest {
private final SecurityManager allowAllSecurityManager = new AllowAllSecurityManager();
private final SecurityManager denyAllSecurityManager = new DenyAllSecurityManager();
private Cache<Method, Boolean> createCache(SecurityManager securityManager) {
return new ConcurrentHashMapCache<Method, Boolean>(new MethodPermCacheEntryFactory(securityManager) );
}
@Test
public void testGetPublicMethod_returnsTrue( )
throws CacheException, NoSuchMethodException
{
Cache<Method, Boolean> cache = createCache(allowAllSecurityManager);
Method method = Root.class.getMethod( "getArray");
Assert.assertTrue( cache.get( method ) );
}
@Test
public void testGetPublicMethod_returnsFalse( )
throws CacheException, NoSuchMethodException
{
Cache<Method, Boolean> cache = createCache(denyAllSecurityManager);
Method method = Root.class.getMethod( "getArray");
Assert.assertFalse( cache.get( method ) );
}
private class AllowAllSecurityManager
extends SecurityManager
{
@Override
public void checkPermission( Permission perm )
{
}
}
private class DenyAllSecurityManager
extends SecurityManager
{
@Override
public void checkPermission( Permission perm )
{
throw new SecurityException("Denied.");
}
}
}
| 4,548 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/internal/ConcurrentHashMapCacheTest.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.commons.ognl.internal;
import org.apache.commons.ognl.internal.entry.CacheEntryFactory;
import org.apache.commons.ognl.test.objects.Bean2;
import org.junit.Test;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertFalse;
public class ConcurrentHashMapCacheTest
{
private final ConcurrentHashMapCacheTest.DummyEntryFactory entryFactory=new DummyEntryFactory( );
private final Cache<CacheEntry, List<Method>> cache = new ConcurrentHashMapCache<CacheEntry, List<Method>>( entryFactory );
@Test
public void testGet( )
throws Exception
{
getMethods( new CacheEntry( Bean2.class, "bean3" ) );
getMethods( new CacheEntry( Bean2.class, "id" ) );
}
private void getMethods( CacheEntry entry )
throws CacheException
{
List<Method> methods = cache.get( entry);
assertNotNull( methods );
assertFalse( methods.isEmpty( ) );
}
private class CacheEntry
{
private final Class<?> clazz;
private final String methodName;
private CacheEntry( Class<?> clazz, String methodName )
{
this.clazz = clazz;
this.methodName = methodName;
}
public Class<?> getClazz( )
{
return clazz;
}
public String getMethodName( )
{
return methodName;
}
}
private class DummyEntryFactory
implements CacheEntryFactory<CacheEntry, List<Method>>
{
public List<Method> create( CacheEntry key )
throws CacheException
{
Method[] methods = key.getClazz( ).getMethods( );
List<Method> list = new ArrayList<Method>( );
for ( Method method : methods )
{
String name = method.getName( );
boolean isGet = name.substring( 3 ).equalsIgnoreCase( key.getMethodName( ) );
if ( isGet )
{
list.add( method );
}
}
return list;
}
}
}
| 4,549 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/internal/PermissionCacheTest.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.commons.ognl.internal;
import org.apache.commons.ognl.internal.entry.PermissionCacheEntry;
import org.apache.commons.ognl.internal.entry.PermissionCacheEntryFactory;
import org.apache.commons.ognl.test.objects.Bean2;
import org.junit.Test;
import java.security.Permission;
import static junit.framework.Assert.assertNotNull;
/**
* User: Maurizio Cucchiara
* Date: 10/15/11
* Time: 8:00 AM
*/
public class PermissionCacheTest
{
ConcurrentHashMapCache<PermissionCacheEntry, Permission> cache =
new ConcurrentHashMapCache<PermissionCacheEntry, Permission>( new PermissionCacheEntryFactory());
@Test
public void testGet( )
throws Exception
{
getPermission( new PermissionCacheEntry( Bean2.class.getMethod( "getBean3" ) ) );
getPermission( new PermissionCacheEntry( Bean2.class.getMethod( "getId" ) ) );
}
private void getPermission( PermissionCacheEntry entry )
throws CacheException
{
Permission permission = cache.get( entry );
assertNotNull( permission );
}
}
| 4,550 |
0 | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/test/java/org/apache/commons/ognl/internal/ConstructorCacheTest.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.commons.ognl.internal;
import org.apache.commons.ognl.internal.entry.CacheEntryFactory;
import org.apache.commons.ognl.test.objects.Root;
import org.junit.Test;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.List;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
public class ConstructorCacheTest
{
private int count;
ClassCache<List<Constructor<?>>> cache = new ConcurrentHashMapClassCache<List<Constructor<?>>>(new CacheEntryFactory<Class<?>, List<Constructor<?>>>( )
{
public List<Constructor<?>> create( Class<?> key )
throws CacheException
{
count++;
return Arrays.<Constructor<?>>asList( key.getConstructors( ) );
}
});
@Test
public void testGet()
throws CacheException
{
List<Constructor<?>> constructors = cache.get( Root.class );
assertNotNull( constructors );
cache.get( Root.class );
assertEquals( 1, count);
}
}
| 4,551 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/BasePerformanceTest.java | /*
* $Id: $
*
* 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.commons.ognl.performance;
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.carrotsearch.junitbenchmarks.BenchmarkRule;
import com.carrotsearch.junitbenchmarks.annotation.AxisRange;
import com.carrotsearch.junitbenchmarks.annotation.BenchmarkHistoryChart;
import com.carrotsearch.junitbenchmarks.annotation.LabelType;
import org.apache.commons.ognl.performance.invocation.CompilerInvocation;
import org.apache.commons.ognl.performance.invocation.FieldInvocation;
import org.apache.commons.ognl.performance.invocation.FindParameterTypesInvocation;
import org.apache.commons.ognl.performance.invocation.GetConstructorsInvocation;
import org.apache.commons.ognl.performance.invocation.GetDeclaredMethodsInvocation;
import org.apache.commons.ognl.performance.invocation.GetMethodsInvocation;
import org.apache.commons.ognl.performance.invocation.MethodParameterTypesInvocation;
import org.apache.commons.ognl.performance.invocation.PermissionInvocation;
import org.apache.commons.ognl.performance.invocation.PrimitiveDefaultInvocation;
import org.apache.commons.ognl.performance.runtime.CommonsRuntimeWrapper;
import org.apache.commons.ognl.performance.runtime.OldOgnlRuntimeWrapper;
import org.apache.commons.ognl.performance.runtime.RuntimeWrapper;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.MethodRule;
/**
* User: Maurizio Cucchiara
* Date: 10/22/11
* Time: 10:25 AM
*/
@AxisRange( min = 0, max = 1 )
@BenchmarkHistoryChart( labelWith = LabelType.CUSTOM_KEY, maxRuns = 20 )
public abstract class BasePerformanceTest
{
@Rule
public MethodRule benchmarkRun = new BenchmarkRule();
public static final RuntimeWrapper COMMONS_RUNTIME_WRAPPER = new CommonsRuntimeWrapper();
public static final RuntimeWrapper OLD_RUNTIME_WRAPPER = new OldOgnlRuntimeWrapper();
protected static RuntimeWrapper runtimeWrapper;
@BenchmarkOptions( benchmarkRounds = 50, warmupRounds = 0, concurrency = 1000 )
@Test
public void constructorCache()
throws Exception
{
new GetConstructorsInvocation( runtimeWrapper, 50000 );
}
@BenchmarkOptions( benchmarkRounds = 50, warmupRounds = 0, concurrency = 1000 )
@Test
public void declaredMethodCache()
throws Exception
{
new GetDeclaredMethodsInvocation( runtimeWrapper );
}
@BenchmarkOptions( benchmarkRounds = 50, warmupRounds = 0, concurrency = 1000 )
@Test
public void fieldCache()
throws Exception
{
new FieldInvocation( runtimeWrapper, 50000 );
}
@BenchmarkOptions( benchmarkRounds = 50, warmupRounds = 0, concurrency = 1000 )
@Test
public void findParameterTypeCache()
throws Exception
{
new FindParameterTypesInvocation( runtimeWrapper, 100 );
}
@BenchmarkOptions( benchmarkRounds = 50, warmupRounds = 0, concurrency = 1000 )
@Test
public void methodCache()
throws Exception
{
new GetMethodsInvocation( runtimeWrapper, 20000 );
}
@BenchmarkOptions( benchmarkRounds = 50, warmupRounds = 0, concurrency = 1000 )
@Test
public void methodParameterTypeCache()
throws Exception
{
new MethodParameterTypesInvocation( runtimeWrapper );
}
@BenchmarkOptions( benchmarkRounds = 50, warmupRounds = 0, concurrency = 1000 )
@Test
public void permissionCache()
throws Exception
{
new PermissionInvocation( runtimeWrapper );
}
@BenchmarkOptions( benchmarkRounds = 50, warmupRounds = 0, concurrency = 1000 )
@Test
public void primitiveCache()
throws Exception
{
new PrimitiveDefaultInvocation( runtimeWrapper, 100000 );
}
@BenchmarkOptions( benchmarkRounds = 50, warmupRounds = 0, concurrency = 1000 )
@Test
public void compiler()
throws Exception
{
new CompilerInvocation( runtimeWrapper, 100 );
}
}
| 4,552 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/PerformanceCommonsOgnlTest.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.commons.ognl.performance;
import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart;
import org.junit.AfterClass;
import org.junit.BeforeClass;
/**
* User: Maurizio Cucchiara
* Date: 10/22/11
* Time: 12:49 AM
*/
@BenchmarkMethodChart( filePrefix = "benchmark" )
public class PerformanceCommonsOgnlTest
extends BasePerformanceTest
{
@BeforeClass
public static void before()
{
runtimeWrapper = COMMONS_RUNTIME_WRAPPER;
}
@AfterClass
public static void after()
{
runtimeWrapper.clearCache();
}
}
| 4,553 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/PerformanceOldOgnlTest.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.commons.ognl.performance;
import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart;
import org.junit.AfterClass;
import org.junit.BeforeClass;
/**
* User: Maurizio Cucchiara
* Date: 10/22/11
* Time: 12:49 AM
*/
@BenchmarkMethodChart( filePrefix = "benchmark-legacy" )
public class PerformanceOldOgnlTest
extends BasePerformanceTest
{
@BeforeClass
public static void before()
{
runtimeWrapper = OLD_RUNTIME_WRAPPER;
}
@AfterClass
public static void after()
{
runtimeWrapper.clearCache();
}
}
| 4,554 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/invocation/MethodParameterTypesInvocation.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.commons.ognl.performance.invocation;
import org.apache.commons.ognl.performance.runtime.RuntimeWrapper;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
/**
* User: mcucchiara
* Date: 18/10/11
* Time: 16.35
*/
public class MethodParameterTypesInvocation
extends RepeatableInvocation
{
public MethodParameterTypesInvocation( RuntimeWrapper runtimeWrapper )
throws Exception
{
super( runtimeWrapper );
}
public MethodParameterTypesInvocation( RuntimeWrapper runtimeWrapper, int times )
throws Exception
{
super( runtimeWrapper, times );
}
@Override
protected void invoke( Class<?> c )
throws Exception
{
for ( Method method : c.getMethods() )
{
getRuntime().getParameterTypes( method );
}
for ( Constructor<?> constructor : c.getConstructors() )
{
getRuntime().getParameterTypes( constructor );
}
}
}
| 4,555 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/invocation/CompilerInvocation.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.commons.ognl.performance.invocation;
import org.apache.commons.ognl.performance.runtime.RuntimeWrapper;
/**
* User: mcucchiara
* Date: 28/10/11
* Time: 18.42
*/
public class CompilerInvocation
extends RepeatableInvocation
{
public CompilerInvocation( RuntimeWrapper runtimeWrapper, int times )
throws Exception
{
super( runtimeWrapper, times );
}
@Override
protected void invoke( Class<?> c )
throws Exception
{
getRuntime().getCompiler();
}
}
| 4,556 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/invocation/GetDeclaredMethodsInvocation.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.commons.ognl.performance.invocation;
import org.apache.commons.ognl.performance.runtime.RuntimeWrapper;
/**
* User: mcucchiara
* Date: 18/10/11
* Time: 15.57
*/
public class GetDeclaredMethodsInvocation
extends RepeatableInvocation
{
public GetDeclaredMethodsInvocation( RuntimeWrapper runtimeWrapper )
throws Exception
{
super( runtimeWrapper );
}
public GetDeclaredMethodsInvocation( RuntimeWrapper runtimeWrapper, int times )
throws Exception
{
super( runtimeWrapper, times );
}
@Override
protected void invoke( Class<?> c )
throws Exception
{
getRuntime().getDeclaredMethods( c, "class", false );
getRuntime().getDeclaredMethods( c, "class", true );
}
}
| 4,557 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/invocation/PermissionInvocation.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.commons.ognl.performance.invocation;
import org.apache.commons.ognl.performance.runtime.RuntimeWrapper;
import java.lang.reflect.Method;
/**
* User: mcucchiara
* Date: 18/10/11
* Time: 16.25
*/
public class PermissionInvocation
extends RepeatableInvocation
{
public PermissionInvocation( RuntimeWrapper runtimeWrapper )
throws Exception
{
super( runtimeWrapper );
}
public PermissionInvocation( RuntimeWrapper runtimeWrapper, int times )
throws Exception
{
super( runtimeWrapper, times );
}
@Override
protected void invoke( Class<?> c )
throws Exception
{
Method[] methods = c.getMethods();
for ( Method method : methods )
{
getRuntime().getPermission( method );
}
}
}
| 4,558 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/invocation/FindParameterTypesInvocation.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.commons.ognl.performance.invocation;
import org.apache.commons.ognl.performance.runtime.RuntimeWrapper;
import java.lang.reflect.Method;
/**
* User: mcucchiara
* Date: 18/10/11
* Time: 16.37
*/
public class FindParameterTypesInvocation
extends RepeatableInvocation
{
public FindParameterTypesInvocation( RuntimeWrapper runtimeWrapper, int times )
throws Exception
{
super( runtimeWrapper, times );
}
public FindParameterTypesInvocation( RuntimeWrapper runtimeWrapper )
throws Exception
{
super( runtimeWrapper );
}
@Override
protected void invoke( Class<?> c )
throws Exception
{
for ( Method method : c.getMethods() )
{
getRuntime().findParameterTypes( String.class, method );
}
}
}
| 4,559 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/invocation/PrimitiveDefaultInvocation.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.commons.ognl.performance.invocation;
import org.apache.commons.ognl.performance.runtime.RuntimeWrapper;
/**
* User: Maurizio Cucchiara
* Date: 10/22/11
* Time: 1:02 AM
*/
public class PrimitiveDefaultInvocation
extends RepeatableInvocation
{
public PrimitiveDefaultInvocation( RuntimeWrapper runtimeWrapper )
throws Exception
{
super( runtimeWrapper );
}
public PrimitiveDefaultInvocation( RuntimeWrapper runtimeWrapper, int times )
throws Exception
{
super( runtimeWrapper, times );
}
@Override
protected void invoke( Class<?> c )
throws Exception
{
getRuntime().getPrimitiveDefaultValue( c );
}
}
| 4,560 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/invocation/FieldInvocation.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.commons.ognl.performance.invocation;
import org.apache.commons.ognl.performance.runtime.RuntimeWrapper;
/**
* User: mcucchiara
* Date: 18/10/11
* Time: 16.28
*/
public class FieldInvocation
extends RepeatableInvocation
{
public FieldInvocation( RuntimeWrapper runtimeWrapper )
throws Exception
{
super( runtimeWrapper );
}
public FieldInvocation( RuntimeWrapper runtimeWrapper, int times )
throws Exception
{
super( runtimeWrapper, times );
}
@Override
protected void invoke( Class<?> c )
throws Exception
{
getRuntime().getFields( c );
}
}
| 4,561 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/invocation/InvokeMethodInvocation.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.commons.ognl.performance.invocation;
import org.apache.commons.ognl.performance.runtime.RuntimeWrapper;
import java.lang.reflect.Method;
/**
* User: mcucchiara
* Date: 18/10/11
* Time: 16.45
*/
public class InvokeMethodInvocation
extends RepeatableInvocation
{
public InvokeMethodInvocation( RuntimeWrapper runtimeWrapper )
throws Exception
{
super( runtimeWrapper );
}
public InvokeMethodInvocation( RuntimeWrapper runtimeWrapper, int times )
throws Exception
{
super( runtimeWrapper, times );
}
@Override
protected void invoke( Class<?> c )
throws Exception
{
Object o;
o = c.newInstance();
Method toString = c.getMethod( "toString" );
getRuntime().invokeMethod( o, toString, new Object[0] );
}
}
| 4,562 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/invocation/RepeatableInvocation.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.commons.ognl.performance.invocation;
import org.apache.commons.ognl.test.objects.BaseBean;
import org.apache.commons.ognl.test.objects.BaseGeneric;
import org.apache.commons.ognl.test.objects.BaseIndexed;
import org.apache.commons.ognl.test.objects.BaseObjectIndexed;
import org.apache.commons.ognl.test.objects.BaseSyntheticObject;
import org.apache.commons.ognl.test.objects.Bean1;
import org.apache.commons.ognl.test.objects.Bean2;
import org.apache.commons.ognl.test.objects.Bean3;
import org.apache.commons.ognl.test.objects.BeanProvider;
import org.apache.commons.ognl.test.objects.BeanProviderAccessor;
import org.apache.commons.ognl.test.objects.BeanProviderImpl;
import org.apache.commons.ognl.test.objects.Component;
import org.apache.commons.ognl.test.objects.ComponentImpl;
import org.apache.commons.ognl.test.objects.ComponentSubclass;
import org.apache.commons.ognl.test.objects.Copy;
import org.apache.commons.ognl.test.objects.CorrectedObject;
import org.apache.commons.ognl.test.objects.Cracker;
import org.apache.commons.ognl.test.objects.Entry;
import org.apache.commons.ognl.test.objects.EvenOdd;
import org.apache.commons.ognl.test.objects.FirstBean;
import org.apache.commons.ognl.test.objects.FormComponentImpl;
import org.apache.commons.ognl.test.objects.FormImpl;
import org.apache.commons.ognl.test.objects.GameGeneric;
import org.apache.commons.ognl.test.objects.GameGenericObject;
import org.apache.commons.ognl.test.objects.GenericCracker;
import org.apache.commons.ognl.test.objects.GenericObject;
import org.apache.commons.ognl.test.objects.GenericRoot;
import org.apache.commons.ognl.test.objects.GenericService;
import org.apache.commons.ognl.test.objects.GenericServiceImpl;
import org.apache.commons.ognl.test.objects.GetterMethods;
import org.apache.commons.ognl.test.objects.IComponent;
import org.apache.commons.ognl.test.objects.IContentProvider;
import org.apache.commons.ognl.test.objects.IForm;
import org.apache.commons.ognl.test.objects.IFormComponent;
import org.apache.commons.ognl.test.objects.ITreeContentProvider;
import org.apache.commons.ognl.test.objects.Indexed;
import org.apache.commons.ognl.test.objects.IndexedMapObject;
import org.apache.commons.ognl.test.objects.IndexedSetObject;
import org.apache.commons.ognl.test.objects.Inherited;
import org.apache.commons.ognl.test.objects.ListSource;
import org.apache.commons.ognl.test.objects.ListSourceImpl;
import org.apache.commons.ognl.test.objects.MenuItem;
import org.apache.commons.ognl.test.objects.Messages;
import org.apache.commons.ognl.test.objects.Model;
import org.apache.commons.ognl.test.objects.MyMap;
import org.apache.commons.ognl.test.objects.MyMapImpl;
import org.apache.commons.ognl.test.objects.ObjectIndexed;
import org.apache.commons.ognl.test.objects.OtherObjectIndexed;
import org.apache.commons.ognl.test.objects.PersonGenericObject;
import org.apache.commons.ognl.test.objects.PropertyHolder;
import org.apache.commons.ognl.test.objects.Root;
import org.apache.commons.ognl.test.objects.SearchCriteria;
import org.apache.commons.ognl.test.objects.SearchTab;
import org.apache.commons.ognl.test.objects.SecondBean;
import org.apache.commons.ognl.test.objects.SetterReturns;
import org.apache.commons.ognl.test.objects.Simple;
import org.apache.commons.ognl.test.objects.SimpleEnum;
import org.apache.commons.ognl.test.objects.SimpleNumeric;
import org.apache.commons.ognl.test.objects.SubclassSyntheticObject;
import org.apache.commons.ognl.test.objects.TestClass;
import org.apache.commons.ognl.test.objects.TestImpl;
import org.apache.commons.ognl.test.objects.TestInherited1;
import org.apache.commons.ognl.test.objects.TestInherited2;
import org.apache.commons.ognl.test.objects.TestModel;
import org.apache.commons.ognl.test.objects.TreeContentProvider;
import org.apache.commons.ognl.test.objects.Two;
import org.apache.commons.ognl.performance.runtime.RuntimeWrapper;
import java.util.Arrays;
import java.util.List;
/**
* User: Maurizio Cucchiara
* Date: 10/22/11
* Time: 12:20 AM
*/
public abstract class RepeatableInvocation
{
private RuntimeWrapper runtimeWrapper;
private int times = 1000;
private List<Class<?>> classes =
Arrays.asList( ComponentImpl.class, BaseObjectIndexed.class, TestInherited2.class, MenuItem.class,
BaseIndexed.class, ListSourceImpl.class, GenericService.class, Copy.class, Inherited.class,
MyMapImpl.class, GenericCracker.class, MyMap.class, SecondBean.class, SetterReturns.class,
IContentProvider.class, FirstBean.class, CorrectedObject.class, BeanProviderImpl.class,
TestClass.class, TestImpl.class, TreeContentProvider.class, Messages.class, Two.class,
IndexedMapObject.class, SimpleNumeric.class, GameGeneric.class, Entry.class,
SubclassSyntheticObject.class, SimpleEnum.class, Model.class, Simple.class,
BaseSyntheticObject.class, ObjectIndexed.class, IComponent.class, SearchCriteria.class,
FormImpl.class, TestInherited1.class, IndexedSetObject.class, SearchTab.class,
GenericObject.class, GenericRoot.class, Bean1.class, FormComponentImpl.class,
ComponentSubclass.class, IForm.class, OtherObjectIndexed.class, Cracker.class, Indexed.class,
EvenOdd.class, PersonGenericObject.class, Bean2.class, GenericServiceImpl.class,
IFormComponent.class, ListSource.class, PropertyHolder.class, Bean3.class, BaseGeneric.class,
GetterMethods.class, BeanProviderAccessor.class, BeanProvider.class, GameGenericObject.class,
ITreeContentProvider.class, TestModel.class, BaseBean.class, Component.class, Root.class );
public RepeatableInvocation( RuntimeWrapper runtimeWrapper )
throws Exception
{
this.runtimeWrapper = runtimeWrapper;
invoke();
}
public RepeatableInvocation( RuntimeWrapper runtimeWrapper, int times )
throws Exception
{
this.runtimeWrapper = runtimeWrapper;
this.times = times;
invoke();
}
private void invoke()
throws Exception
{
for ( int i = 0; i < times; i++ )
{
for ( Class<?> c : classes )
{
invoke( c );
}
}
}
protected abstract void invoke( Class<?> c )
throws Exception;
protected RuntimeWrapper getRuntime()
{
return runtimeWrapper;
}
}
| 4,563 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/invocation/GetConstructorsInvocation.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.commons.ognl.performance.invocation;
import org.apache.commons.ognl.performance.runtime.RuntimeWrapper;
/**
* User: mcucchiara
* Date: 18/10/11
* Time: 16.21
*/
public class GetConstructorsInvocation
extends RepeatableInvocation
{
public GetConstructorsInvocation( RuntimeWrapper runtimeWrapper )
throws Exception
{
super( runtimeWrapper );
}
public GetConstructorsInvocation( RuntimeWrapper runtimeWrapper, int times )
throws Exception
{
super( runtimeWrapper, times );
}
@Override
protected void invoke( Class<?> c )
throws Exception
{
getRuntime().getConstructors( c );
}
}
| 4,564 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/invocation/GetMethodsInvocation.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.commons.ognl.performance.invocation;
import org.apache.commons.ognl.performance.runtime.RuntimeWrapper;
/**
* User: mcucchiara
* Date: 18/10/11
* Time: 15.57
*/
public class GetMethodsInvocation
extends RepeatableInvocation
{
public GetMethodsInvocation( RuntimeWrapper runtimeWrapper )
throws Exception
{
super( runtimeWrapper );
}
public GetMethodsInvocation( RuntimeWrapper runtimeWrapper, int times )
throws Exception
{
super( runtimeWrapper, times );
}
@Override
protected void invoke( Class<?> c )
throws Exception
{
getRuntime().getMethods( c, false );
getRuntime().getMethods( c, true );
}
}
| 4,565 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/runtime/OldOgnlRuntimeWrapper.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.commons.ognl.performance.runtime;
import ognl.OgnlRuntime;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
/**
* User: Maurizio Cucchiara
* Date: 10/22/11
* Time: 12:46 AM
*/
public class OldOgnlRuntimeWrapper
implements RuntimeWrapper
{
public void getFields( Class<?> c )
throws Exception
{
OgnlRuntime.getFields( c );
}
public void findParameterTypes( Class<?> targetClass, Method method )
throws Exception
{
OgnlRuntime.findParameterTypes( targetClass, method );
}
public void getConstructors( Class<?> c )
throws Exception
{
OgnlRuntime.getConstructors( c );
}
public void getMethods( Class<?> c, boolean staticMethods )
throws Exception
{
OgnlRuntime.getMethods( c, staticMethods );
}
public void getDeclaredMethods( Class<?> c, String propertyName, boolean setters )
throws Exception
{
OgnlRuntime.getDeclaredMethods( c, propertyName, setters );
}
public void getParameterTypes( Method method )
throws Exception
{
OgnlRuntime.getParameterTypes( method );
}
public void getParameterTypes( Constructor<?> constructor )
throws Exception
{
OgnlRuntime.getParameterTypes( constructor );
}
public void getPermission( Method method )
throws Exception
{
OgnlRuntime.getPermission( method );
}
public void getPrimitiveDefaultValue( Class<?> type )
throws Exception
{
OgnlRuntime.getPrimitiveDefaultValue( type );
}
public void invokeMethod( Object o, Method method, Object[] args )
throws Exception
{
OgnlRuntime.invokeMethod( o, method, args );
}
public void clearCache()
{
OgnlRuntime.clearCache();
}
public void getCompiler()
{
OgnlRuntime.getCompiler();
}
}
| 4,566 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/runtime/RuntimeWrapper.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.commons.ognl.performance.runtime;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
/**
* User: mcucchiara
* Date: 19/10/11
* Time: 9.37
*/
public interface RuntimeWrapper
{
void getFields( Class<?> c )
throws Exception;
void findParameterTypes( Class<?> targetClass, Method method )
throws Exception;
void getConstructors( Class<?> c )
throws Exception;
void getMethods( Class<?> c, boolean staticMethods )
throws Exception;
void getDeclaredMethods( Class<?> c, String propertyName, boolean setters )
throws Exception;
void getParameterTypes( Method method )
throws Exception;
void getParameterTypes( Constructor<?> constructor )
throws Exception;
void getPermission( Method method )
throws Exception;
void getPrimitiveDefaultValue( Class<?> type )
throws Exception;
void invokeMethod( Object o, Method method, Object[] args )
throws Exception;
void clearCache();
void getCompiler();
}
| 4,567 |
0 | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance | Create_ds/commons-ognl/src/benchmarks/java/org/apache/commons/ognl/performance/runtime/CommonsRuntimeWrapper.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.commons.ognl.performance.runtime;
import org.apache.commons.ognl.OgnlRuntime;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
/**
* User: Maurizio Cucchiara
* Date: 10/22/11
* Time: 12:38 AM
*/
public class CommonsRuntimeWrapper
implements RuntimeWrapper
{
public void getFields( Class<?> c )
throws Exception
{
OgnlRuntime.getFields( c );
}
public void findParameterTypes( Class<?> targetClass, Method method )
throws Exception
{
OgnlRuntime.findParameterTypes( targetClass, method );
}
public void getConstructors( Class<?> c )
throws Exception
{
OgnlRuntime.getConstructors( c );
}
public void getMethods( Class<?> c, boolean staticMethods )
throws Exception
{
OgnlRuntime.getMethods( c, staticMethods );
}
public void getDeclaredMethods( Class<?> c, String propertyName, boolean setters )
throws Exception
{
OgnlRuntime.getDeclaredMethods( c, propertyName, setters );
}
public void getParameterTypes( Method method )
throws Exception
{
OgnlRuntime.getParameterTypes( method );
}
public void getParameterTypes( Constructor<?> constructor )
throws Exception
{
OgnlRuntime.getParameterTypes( constructor );
}
public void getPermission( Method method )
throws Exception
{
OgnlRuntime.getPermission( method );
}
public void getPrimitiveDefaultValue( Class<?> type )
throws Exception
{
OgnlRuntime.getPrimitiveDefaultValue( type );
}
public void invokeMethod( Object o, Method method, Object[] args )
throws Exception
{
OgnlRuntime.invokeMethod( o, method, args );
}
public void clearCache()
{
OgnlRuntime.clearCache();
}
public void getCompiler()
{
OgnlRuntime.getCompiler( null );
}
}
| 4,568 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTStaticMethod.java | package org.apache.commons.ognl;
/*
* 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.
*/
import org.apache.commons.ognl.enhance.ExpressionCompiler;
import org.apache.commons.ognl.enhance.OgnlExpressionCompiler;
import org.apache.commons.ognl.enhance.UnsupportedCompilationException;
import java.lang.reflect.Method;
/**
*/
public class ASTStaticMethod
extends SimpleNode
implements NodeType
{
private String className;
private String methodName;
private Class getterClass;
public ASTStaticMethod( int id )
{
super( id );
}
public ASTStaticMethod( OgnlParser p, int id )
{
super( p, id );
}
/**
* Called from parser action.
*/
void init( String className, String methodName )
{
this.className = className;
this.methodName = methodName;
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
Object[] args = new Object[jjtGetNumChildren()];
Object root = context.getRoot();
for ( int i = 0, icount = args.length; i < icount; ++i )
{
args[i] = children[i].getValue( context, root );
}
return OgnlRuntime.callStaticMethod( context, className, methodName, args );
}
public Class getGetterClass()
{
return getterClass;
}
public Class getSetterClass()
{
return getterClass;
}
public String toGetSourceString( OgnlContext context, Object target )
{
StringBuilder result = new StringBuilder(className + "#" + methodName + "(");
try
{
Class clazz = OgnlRuntime.classForName( context, className );
Method m = OgnlRuntime.getMethod( context, clazz, methodName, children, true );
if ( m == null )
{
throw new UnsupportedCompilationException(
"Unable to find class/method combo " + className + " / " + methodName );
}
if ( !context.getMemberAccess().isAccessible( context, clazz, m, methodName ) )
{
throw new UnsupportedCompilationException(
"Method is not accessible, check your jvm runtime security settings. " + "For static class method "
+ className + " / " + methodName );
}
OgnlExpressionCompiler compiler = OgnlRuntime.getCompiler( context );
if ( ( children != null ) && ( children.length > 0 ) )
{
Class[] parms = m.getParameterTypes();
for ( int i = 0; i < children.length; i++ )
{
if ( i > 0 )
{
result.append(", ");
}
Class prevType = context.getCurrentType();
Node child = children[i];
Object root = context.getRoot();
String parmString = ASTMethodUtil.getParmString( context, root, child, prevType );
Class valueClass = ASTMethodUtil.getValueClass( context, root, child );
if ( valueClass != parms[i] )
{
if ( parms[i].isArray() )
{
parmString = compiler.createLocalReference( context, "(" + ExpressionCompiler.getCastString(
parms[i] ) + ")org.apache.commons.ognl.OgnlOps.toArray(" + parmString + ", "
+ parms[i].getComponentType().getName() + ".class, true)", parms[i] );
}
else if ( parms[i].isPrimitive() )
{
Class wrapClass = OgnlRuntime.getPrimitiveWrapperClass( parms[i] );
parmString = compiler.createLocalReference( context, "((" + wrapClass.getName()
+ ")org.apache.commons.ognl.OgnlOps.convertValue(" + parmString + ","
+ wrapClass.getName() + ".class, true))." + OgnlRuntime.getNumericValueGetter(
wrapClass ), parms[i] );
}
else if ( parms[i] != Object.class )
{
parmString = compiler.createLocalReference( context, "(" + parms[i].getName()
+ ")org.apache.commons.ognl.OgnlOps.convertValue(" + parmString + ","
+ parms[i].getName() + ".class)", parms[i] );
}
else if ( ( child instanceof NodeType && ( (NodeType) child ).getGetterClass() != null
&& Number.class.isAssignableFrom( ( (NodeType) child ).getGetterClass() ) )
|| valueClass.isPrimitive() )
{
parmString = " ($w) " + parmString;
}
else if ( valueClass.isPrimitive() )
{
parmString = "($w) " + parmString;
}
}
result.append(parmString);
}
}
result.append(")");
try
{
Object contextObj = getValueBody( context, target );
context.setCurrentObject( contextObj );
}
catch ( Throwable t )
{
// ignore
}
if ( m != null )
{
getterClass = m.getReturnType();
context.setCurrentType( m.getReturnType() );
context.setCurrentAccessor( compiler.getSuperOrInterfaceClass( m, m.getDeclaringClass() ) );
}
}
catch ( Throwable t )
{
throw OgnlOps.castToRuntime( t );
}
return result.toString();
}
public String toSetSourceString( OgnlContext context, Object target )
{
return toGetSourceString( context, target );
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
/**
* Gets the class name for this method.
*
* @return the class name.
* @since 4.0
*/
public String getClassName()
{
return className;
}
/**
* Gets the method name for this method.
*
* @return the method name.
* @since 4.0
*/
public String getMethodName()
{
return methodName;
}
}
| 4,569 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/NoSuchPropertyException.java | package org.apache.commons.ognl;
/*
* 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.
*/
/**
* Exception thrown if a property is attempted to be extracted from an object that does not have such a property.
*/
public class NoSuchPropertyException
extends OgnlException
{
private static final long serialVersionUID = 2228428181127177178L;
private Object target;
private Object name;
public NoSuchPropertyException( Object target, Object name )
{
super( getReason( target, name ) );
}
public NoSuchPropertyException( Object target, Object name, Throwable reason )
{
super( getReason( target, name ), reason );
this.target = target;
this.name = name;
}
static String getReason( Object target, Object name )
{
StringBuilder ret = new StringBuilder();
if ( target == null )
{
ret.append( "null" );
}
else if ( target instanceof Class )
{
ret.append( ( (Class<?>) target ).getName() );
}
else
{
ret.append( target.getClass().getName() );
}
ret.append( "." ).append( name );
return ret.toString();
}
public Object getTarget()
{
return target;
}
public Object getName()
{
return name;
}
}
| 4,570 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ObjectIndexedPropertyDescriptor.java | package org.apache.commons.ognl;
/*
* 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.
*/
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
/**
* <p>
* PropertyDescriptor subclass that describes an indexed set of read/write methods to get a property. Unlike
* IndexedPropertyDescriptor this allows the "key" to be an arbitrary object rather than just an int. Consequently it
* does not have a "readMethod" or "writeMethod" because it only expects a pattern like:
* </p>
*
* <pre>
* public void set<i>Property</i>(<i>KeyType</i>, <i>ValueType</i>);
* public <i>ValueType</i> get<i>Property</i>(<i>KeyType</i>);
* </pre>
* <p>
* and does not require the methods that access it as an array. OGNL can get away with this without losing functionality
* because if the object does expose the properties they are most probably in a Map and that case is handled by the
* normal OGNL property accessors.
* </p>
* <p>
* For example, if an object were to have methods that accessed and "attributes" property it would be natural to index
* them by String rather than by integer and expose the attributes as a map with a different property name:
*
* <pre>
* public void setAttribute( String name, Object value );
*
* public Object getAttribute( String name );
*
* public Map getAttributes();
* </pre>
* <p>
* Note that the index get/set is called get/set <code>Attribute</code> whereas the collection getter is called
* <code>Attributes</code>. This case is handled unambiguously by the OGNL property accessors because the set/get
* <code>Attribute</code> methods are detected by this object and the "attributes" case is handled by the
* <code>MapPropertyAccessor</code>. Therefore OGNL expressions calling this code would be handled in the following way:
* </p>
* <table>
* <tr>
* <th>OGNL Expression</th>
* <th>Handling</th>
* </tr>
* <tr>
* <td><code>attribute["name"]</code></td>
* <td>Handled by an index getter, like <code>getAttribute(String)</code>.</td>
* </tr>
* <tr>
* <td><code>attribute["name"] = value</code></td>
* <td>Handled by an index setter, like <code>setAttribute(String, Object)</code>.</td>
* </tr>
* <tr>
* <td><code>attributes["name"]</code></td>
* <td>Handled by <code>MapPropertyAccessor</code> via a <code>Map.get()</code>. This will <b>not</b> go through the
* index get accessor.</td>
* </tr>
* <tr>
* <td><code>attributes["name"] = value</code></td>
* <td>Handled by <code>MapPropertyAccessor</code> via a <code>Map.put()</code>. This will <b>not</b> go through the
* index set accessor.</td>
* </tr>
* </table>
*/
public class ObjectIndexedPropertyDescriptor
extends PropertyDescriptor
{
private final Method indexedReadMethod;
private final Method indexedWriteMethod;
private final Class<?> propertyType;
public ObjectIndexedPropertyDescriptor( String propertyName, Class<?> propertyType, Method indexedReadMethod,
Method indexedWriteMethod )
throws IntrospectionException
{
super( propertyName, null, null );
this.propertyType = propertyType;
this.indexedReadMethod = indexedReadMethod;
this.indexedWriteMethod = indexedWriteMethod;
}
public Method getIndexedReadMethod()
{
return indexedReadMethod;
}
public Method getIndexedWriteMethod()
{
return indexedWriteMethod;
}
@Override
public Class<?> getPropertyType()
{
return propertyType;
}
@Override
public boolean equals(Object o) {
if (this == o)
{
return true;
}
if (!(o instanceof ObjectIndexedPropertyDescriptor))
{
return false;
}
if (!super.equals(o))
{
return false;
}
ObjectIndexedPropertyDescriptor that = (ObjectIndexedPropertyDescriptor) o;
if (indexedReadMethod != null ? !indexedReadMethod.equals(that.indexedReadMethod) : that.indexedReadMethod != null)
{
return false;
}
if (indexedWriteMethod != null ? !indexedWriteMethod.equals(that.indexedWriteMethod) : that.indexedWriteMethod != null)
{
return false;
}
if (propertyType != null ? !propertyType.equals(that.propertyType) : that.propertyType != null)
{
return false;
}
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (indexedReadMethod != null ? indexedReadMethod.hashCode() : 0);
result = 31 * result + (indexedWriteMethod != null ? indexedWriteMethod.hashCode() : 0);
result = 31 * result + (propertyType != null ? propertyType.hashCode() : 0);
return result;
}
}
| 4,571 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTNegate.java | package org.apache.commons.ognl;
/*
* 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.
*/
/**
*/
class ASTNegate
extends NumericExpression
{
public ASTNegate( int id )
{
super( id );
}
public ASTNegate( OgnlParser p, int id )
{
super( p, id );
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
return OgnlOps.negate( children[0].getValue( context, source ) );
}
public String toGetSourceString( OgnlContext context, Object target )
{
String source = children[0].toGetSourceString( context, target );
if ( !(children[0] instanceof ASTNegate))
{
return "-" + source;
}
return "-(" + source + ")";
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,572 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTChain.java | package org.apache.commons.ognl;
/*
* 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.
*/
import org.apache.commons.ognl.enhance.ExpressionCompiler;
import org.apache.commons.ognl.enhance.OrderedReturn;
import org.apache.commons.ognl.enhance.UnsupportedCompilationException;
import java.lang.reflect.Array;
/**
*/
public class ASTChain
extends SimpleNode
implements NodeType, OrderedReturn
{
private Class getterClass;
private Class setterClass;
private String lastExpression;
private String coreExpression;
public ASTChain( int id )
{
super( id );
}
public ASTChain( OgnlParser p, int id )
{
super( p, id );
}
public String getLastExpression()
{
return lastExpression;
}
public String getCoreExpression()
{
return coreExpression;
}
public void jjtClose()
{
flattenTree();
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
Object result = source;
for ( int i = 0, ilast = children.length - 1; i <= ilast; ++i )
{
boolean handled = false;
if ( (i < ilast) && (children[i] instanceof ASTProperty) )
{
ASTProperty propertyNode = (ASTProperty) children[i];
int indexType = propertyNode.getIndexedPropertyType( context, result );
if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
&& ( children[i + 1] instanceof ASTProperty ) )
{
ASTProperty indexNode = (ASTProperty) children[i + 1];
if ( indexNode.isIndexedAccess() )
{
Object index = indexNode.getProperty( context, result );
if ( index instanceof DynamicSubscript )
{
if ( indexType == OgnlRuntime.INDEXED_PROPERTY_INT )
{
Object array = propertyNode.getValue( context, result );
int len = Array.getLength( array );
switch ( ( (DynamicSubscript) index ).getFlag() )
{
case DynamicSubscript.ALL:
result = Array.newInstance( array.getClass().getComponentType(), len );
System.arraycopy( array, 0, result, 0, len );
handled = true;
i++;
break;
case DynamicSubscript.FIRST:
index = ( len > 0 ) ? 0 : -1;
break;
case DynamicSubscript.MID:
index = ( len > 0 ) ? ( len / 2 ) : -1;
break;
case DynamicSubscript.LAST:
index = ( len > 0 ) ? ( len - 1 ) : -1;
break;
default:
break;
}
}
else
{
if ( indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT )
{
throw new OgnlException( "DynamicSubscript '" + indexNode
+ "' not allowed for object indexed property '" + propertyNode + "'" );
}
}
}
if ( !handled )
{
result =
OgnlRuntime.getIndexedProperty(
context,
result,
propertyNode.getProperty( context, result ).toString(),
index );
handled = true;
i++;
}
}
}
}
if ( !handled )
{
result = children[i].getValue( context, result );
}
}
return result;
}
protected void setValueBody( OgnlContext context, Object target, Object value )
throws OgnlException
{
boolean handled = false;
for ( int i = 0, ilast = children.length - 2; i <= ilast; ++i )
{
if ( (i <= ilast) && (children[i] instanceof ASTProperty) )
{
ASTProperty propertyNode = (ASTProperty) children[i];
int indexType = propertyNode.getIndexedPropertyType( context, target );
if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
&& ( children[i + 1] instanceof ASTProperty ) )
{
ASTProperty indexNode = (ASTProperty) children[i + 1];
if ( indexNode.isIndexedAccess() )
{
Object index = indexNode.getProperty( context, target );
if ( index instanceof DynamicSubscript )
{
if ( indexType == OgnlRuntime.INDEXED_PROPERTY_INT )
{
Object array = propertyNode.getValue( context, target );
int len = Array.getLength( array );
switch ( ( (DynamicSubscript) index ).getFlag() )
{
case DynamicSubscript.ALL:
System.arraycopy( target, 0, value, 0, len );
handled = true;
i++;
break;
case DynamicSubscript.FIRST:
index = ( len > 0 ) ? 0 : -1;
break;
case DynamicSubscript.MID:
index = ( len > 0 ) ? ( len / 2 ) : -1;
break;
case DynamicSubscript.LAST:
index = ( len > 0 ) ? ( len - 1 ) : -1;
break;
default:
break;
}
}
else
{
if ( indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT )
{
throw new OgnlException( "DynamicSubscript '" + indexNode
+ "' not allowed for object indexed property '" + propertyNode + "'" );
}
}
}
if ( !handled && i == ilast )
{
OgnlRuntime.setIndexedProperty( context, target,
propertyNode.getProperty( context, target ).toString(),
index, value );
handled = true;
i++;
}
else if ( !handled )
{
target =
OgnlRuntime.getIndexedProperty(
context,
target,
propertyNode.getProperty( context, target ).toString(),
index );
i++;
continue;
}
}
}
}
if ( !handled )
{
target = children[i].getValue( context, target );
}
}
if ( !handled )
{
children[children.length - 1].setValue( context, target, value );
}
}
public boolean isSimpleNavigationChain( OgnlContext context )
throws OgnlException
{
boolean result = false;
if ( ( children != null ) && ( children.length > 0 ) )
{
result = true;
for ( int i = 0; result && ( i < children.length ); i++ )
{
result =
children[i] instanceof SimpleNode && ( (SimpleNode) children[i] ).isSimpleProperty( context );
}
}
return result;
}
public Class getGetterClass()
{
return getterClass;
}
public Class getSetterClass()
{
return setterClass;
}
public String toGetSourceString( OgnlContext context, Object target )
{
String prevChain = (String) context.get( "_currentChain" );
if ( target != null )
{
context.setCurrentObject( target );
context.setCurrentType( target.getClass() );
}
String result = "";
NodeType lastType = null;
boolean ordered = false;
boolean constructor = false;
try
{
if ( ( children != null ) && ( children.length > 0 ) )
{
for ( Node child : children )
{
/*
* System.out.println("astchain child: " + _children[i].getClass().getName() +
* " with current object target " + context.getCurrentObject() + " current type: " +
* context.getCurrentType());
*/
String value = child.toGetSourceString( context, context.getCurrentObject() );
// System.out.println("astchain child returned >> " + value + " <<");
if (child instanceof ASTCtor)
{
constructor = true;
}
if ( child instanceof NodeType && ( (NodeType) child ).getGetterClass() != null )
{
lastType = (NodeType) child;
}
// System.out.println("Astchain i: " + i + " currentobj : " + context.getCurrentObject() +
// " and root: " + context.getRoot());
if ( !(child instanceof ASTVarRef) && !constructor && !(
child instanceof OrderedReturn
&& ( (OrderedReturn) child ).getLastExpression() != null ) && ( parent == null
|| !(parent instanceof ASTSequence)) )
{
value = OgnlRuntime.getCompiler( context ).castExpression( context, child, value );
}
/*
* System.out.println("astchain value now : " + value + " with index " + i + " current type " +
* context.getCurrentType() + " current accessor " + context.getCurrentAccessor() + " prev type " +
* context.getPreviousType() + " prev accessor " + context.getPreviousAccessor());
*/
if ( child instanceof OrderedReturn
&& ( (OrderedReturn) child ).getLastExpression() != null )
{
ordered = true;
OrderedReturn or = (OrderedReturn) child;
if ( or.getCoreExpression() == null || or.getCoreExpression().trim().isEmpty() )
{
result = "";
}
else
{
result += or.getCoreExpression();
}
lastExpression = or.getLastExpression();
if ( context.get( ExpressionCompiler.PRE_CAST ) != null )
{
lastExpression = context.remove( ExpressionCompiler.PRE_CAST ) + lastExpression;
}
}
else if ( child instanceof ASTOr || child instanceof ASTAnd
|| child instanceof ASTCtor || ( child instanceof ASTStaticField
&& parent == null ) )
{
context.put( "_noRoot", "true" );
result = value;
}
else
{
result += value;
}
context.put( "_currentChain", result );
}
}
}
catch ( Throwable t )
{
throw OgnlOps.castToRuntime( t );
}
if ( lastType != null )
{
getterClass = lastType.getGetterClass();
setterClass = lastType.getSetterClass();
}
if ( ordered )
{
coreExpression = result;
}
context.put( "_currentChain", prevChain );
return result;
}
public String toSetSourceString( OgnlContext context, Object target )
{
String prevChain = (String) context.get( "_currentChain" );
String prevChild = (String) context.get( "_lastChild" );
if ( prevChain != null )
{
throw new UnsupportedCompilationException( "Can't compile nested chain expressions." );
}
if ( target != null )
{
context.setCurrentObject( target );
context.setCurrentType( target.getClass() );
}
String result = "";
NodeType lastType = null;
boolean constructor = false;
try
{
if ( ( children != null ) && ( children.length > 0 ) )
{
if (children[0] instanceof ASTConst)
{
throw new UnsupportedCompilationException( "Can't modify constant values." );
}
for ( int i = 0; i < children.length; i++ )
{
// System.out.println("astchain setsource child[" + i + "] : " + _children[i].getClass().getName());
if ( i == ( children.length - 1 ) )
{
context.put( "_lastChild", "true" );
}
String value = children[i].toSetSourceString( context, context.getCurrentObject() );
// if (value == null || value.trim().isEmpty())
// return "";
// System.out.println("astchain setter child returned >> " + value + " <<");
if (children[i] instanceof ASTCtor)
{
constructor = true;
}
if ( children[i] instanceof NodeType
&& ( (NodeType) children[i] ).getGetterClass() != null )
{
lastType = (NodeType) children[i];
}
if ( !(children[i] instanceof ASTVarRef)
&& !constructor
&& !( children[i] instanceof OrderedReturn
&& ( (OrderedReturn) children[i] ).getLastExpression() != null )
&& ( parent == null || !(parent instanceof ASTSequence)) )
{
value = OgnlRuntime.getCompiler( context ).castExpression( context, children[i], value );
}
// System.out.println("astchain setter after cast value is: " + value);
/*
* if (!constructor && !OrderedReturn.class.isInstance(_children[i]) && (_parent == null ||
* !ASTSequence.class.isInstance(_parent))) { value =
* OgnlRuntime.getCompiler().castExpression(context, _children[i], value); }
*/
if ( children[i] instanceof ASTOr || children[i] instanceof ASTAnd
|| children[i] instanceof ASTCtor || children[i] instanceof ASTStaticField)
{
context.put( "_noRoot", "true" );
result = value;
}
else
{
result += value;
}
context.put( "_currentChain", result );
}
}
}
catch ( Throwable t )
{
throw OgnlOps.castToRuntime( t );
}
context.put( "_lastChild", prevChild );
context.put( "_currentChain", prevChain );
if ( lastType != null )
{
setterClass = lastType.getSetterClass();
}
return result;
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,573 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTStaticField.java | package org.apache.commons.ognl;
/*
* 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.
*/
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
/**
*/
public class ASTStaticField
extends SimpleNode
implements NodeType
{
private String className;
private String fieldName;
private Class getterClass;
public ASTStaticField( int id )
{
super( id );
}
public ASTStaticField( OgnlParser p, int id )
{
super( p, id );
}
/** Called from parser action. */
void init( String className, String fieldName )
{
this.className = className;
this.fieldName = fieldName;
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
return OgnlRuntime.getStaticField( context, className, fieldName );
}
public boolean isNodeConstant( OgnlContext context )
throws OgnlException
{
boolean result = false;
Exception cause = null;
try
{
Class clazz = OgnlRuntime.classForName( context, className );
/*
* Check for virtual static field "class"; this cannot interfere with normal static fields because it is a
* reserved word. It is considered constant.
*/
if ( "class".equals( fieldName ) )
{
result = true;
}
else if ( clazz.isEnum() )
{
result = true;
}
else
{
Field field = clazz.getField( fieldName );
if ( !Modifier.isStatic( field.getModifiers() ) )
{
throw new OgnlException( "Field " + fieldName + " of class " + className + " is not static" );
}
result = Modifier.isFinal( field.getModifiers() );
}
}
catch ( ClassNotFoundException | SecurityException | NoSuchFieldException e )
{
cause = e;
}
if ( cause != null )
{
throw new OgnlException( "Could not get static field " + fieldName + " from class " + className, cause );
}
return result;
}
Class getFieldClass( OgnlContext context )
throws OgnlException
{
Exception cause;
try
{
Class clazz = OgnlRuntime.classForName( context, className );
/*
* Check for virtual static field "class"; this cannot interfere with normal static fields because it is a
* reserved word. It is considered constant.
*/
if ( "class".equals( fieldName ) )
{
return clazz;
}
if ( clazz.isEnum() )
{
return clazz;
}
Field field = clazz.getField( fieldName );
return field.getType();
}
catch ( ClassNotFoundException | SecurityException | NoSuchFieldException e )
{
cause = e;
}
throw new OgnlException( "Could not get static field " + fieldName + " from class " + className, cause );
}
public Class getGetterClass()
{
return getterClass;
}
public Class getSetterClass()
{
return getterClass;
}
public String toGetSourceString( OgnlContext context, Object target )
{
try
{
Object obj = OgnlRuntime.getStaticField( context, className, fieldName );
context.setCurrentObject( obj );
getterClass = getFieldClass( context );
context.setCurrentType( getterClass );
}
catch ( Throwable t )
{
throw OgnlOps.castToRuntime( t );
}
return className + "." + fieldName;
}
public String toSetSourceString( OgnlContext context, Object target )
{
try
{
Object obj = OgnlRuntime.getStaticField( context, className, fieldName );
context.setCurrentObject( obj );
getterClass = getFieldClass( context );
context.setCurrentType( getterClass );
}
catch ( Throwable t )
{
throw OgnlOps.castToRuntime( t );
}
return className + "." + fieldName;
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
/**
* Gets the field name for this field.
*
* @return the field name.
* @since 4.0
*/
String getFieldName()
{
return fieldName;
}
/**
* Gets the class name for this field.
*
* @return the class name.
* @since 4.0
*/
String getClassName()
{
return className;
}
}
| 4,574 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTLessEq.java | package org.apache.commons.ognl;
/*
* 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.
*/
/**
*/
class ASTLessEq
extends ComparisonExpression
{
public ASTLessEq( int id )
{
super( id );
}
public ASTLessEq( OgnlParser p, int id )
{
super( p, id );
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
Object v1 = children[0].getValue( context, source );
Object v2 = children[1].getValue( context, source );
return OgnlOps.greater( v1, v2 ) ? Boolean.FALSE : Boolean.TRUE;
}
public String getExpressionOperator( int index )
{
return "<=";
}
public String getComparisonFunction()
{
return "!org.apache.commons.ognl.OgnlOps.greater";
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,575 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTProject.java | package org.apache.commons.ognl;
/*
* 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.
*/
import org.apache.commons.ognl.enhance.UnsupportedCompilationException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
/**
*/
class ASTProject
extends SimpleNode
{
public ASTProject( int id )
{
super( id );
}
public ASTProject( OgnlParser p, int id )
{
super( p, id );
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
Node expr = children[0];
List answer = new ArrayList();
ElementsAccessor elementsAccessor = OgnlRuntime.getElementsAccessor( OgnlRuntime.getTargetClass( source ) );
for ( Enumeration e = elementsAccessor.getElements( source ); e.hasMoreElements(); )
{
answer.add( expr.getValue( context, e.nextElement() ) );
}
return answer;
}
public String toGetSourceString( OgnlContext context, Object target )
{
throw new UnsupportedCompilationException( "Projection expressions not supported as native java yet." );
}
public String toSetSourceString( OgnlContext context, Object target )
{
throw new UnsupportedCompilationException( "Projection expressions not supported as native java yet." );
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,576 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/Evaluation.java | package org.apache.commons.ognl;
/*
* 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.
*/
/**
* An <code>Evaluation</code> is and object that holds a node being evaluated and the source from which that node will
* take extract its value. It refers to child evaluations that occur as a result of the nodes' evaluation.
*/
public class Evaluation
{
private SimpleNode node;
private Object source;
private boolean setOperation;
private Object result;
private Throwable exception;
private Evaluation parent;
private Evaluation next;
private Evaluation previous;
private Evaluation firstChild;
private Evaluation lastChild;
/**
* Constructs a new "get" <code>Evaluation</code> from the node and source given.
*/
public Evaluation( SimpleNode node, Object source )
{
this.node = node;
this.source = source;
}
/**
* Constructs a new <code>Evaluation</code> from the node and source given. If <code>setOperation</code> is true
* this <code>Evaluation</code> represents a "set" as opposed to a "get".
*/
public Evaluation( SimpleNode node, Object source, boolean setOperation )
{
this( node, source );
this.setOperation = setOperation;
}
/**
* Returns the <code>SimpleNode</code> for this <code>Evaluation</code>
*/
public SimpleNode getNode()
{
return node;
}
/**
* Sets the node of the evaluation. Normally applications do not need to set this. Notable exceptions to this rule
* are custom evaluators that choose between navigable objects (as in a multi-root evaluator where the navigable
* node is chosen at runtime).
*/
public void setNode( SimpleNode value )
{
node = value;
}
/**
* Returns the source object on which this Evaluation operated.
*/
public Object getSource()
{
return source;
}
/**
* Sets the source of the evaluation. Normally applications do not need to set this. Notable exceptions to this rule
* are custom evaluators that choose between navigable objects (as in a multi-root evaluator where the navigable
* node is chosen at runtime).
*/
public void setSource( Object value )
{
source = value;
}
/**
* Returns true if this Evaluation represents a set operation.
*/
public boolean isSetOperation()
{
return setOperation;
}
/**
* Marks the Evaluation as a set operation if the value is true, else marks it as a get operation.
*/
public void setSetOperation( boolean value )
{
setOperation = value;
}
/**
* Returns the result of the Evaluation, or null if it was a set operation.
*/
public Object getResult()
{
return result;
}
/**
* Sets the result of the Evaluation. This method is normally only used interally and should not be set without
* knowledge of what you are doing.
*/
public void setResult( Object value )
{
result = value;
}
/**
* Returns the exception that occurred as a result of evaluating the Evaluation, or null if no exception occurred.
*/
public Throwable getException()
{
return exception;
}
/**
* Sets the exception that occurred as a result of evaluating the Evaluation. This method is normally only used
* interally and should not be set without knowledge of what you are doing.
*/
public void setException( Throwable value )
{
exception = value;
}
/**
* Returns the parent evaluation of this evaluation. If this returns null then it is the root evaluation of a
* tree.
*/
public Evaluation getParent()
{
return parent;
}
/**
* Returns the next sibling of this evaluation. Returns null if this is the last in a chain of evaluations.
*/
public Evaluation getNext()
{
return next;
}
/**
* Returns the previous sibling of this evaluation. Returns null if this is the first in a chain of evaluations.
*/
public Evaluation getPrevious()
{
return previous;
}
/**
* Returns the first child of this evaluation. Returns null if there are no children.
*/
public Evaluation getFirstChild()
{
return firstChild;
}
/**
* Returns the last child of this evaluation. Returns null if there are no children.
*/
public Evaluation getLastChild()
{
return lastChild;
}
/**
* Gets the first descendent. In any Evaluation tree this will the Evaluation that was first executed.
*/
public Evaluation getFirstDescendant()
{
if ( firstChild != null )
{
return firstChild.getFirstDescendant();
}
return this;
}
/**
* Gets the last descendent. In any Evaluation tree this will the Evaluation that was most recently executing.
*/
public Evaluation getLastDescendant()
{
if ( lastChild != null )
{
return lastChild.getLastDescendant();
}
return this;
}
/**
* Adds a child to the list of children of this evaluation. The parent of the child is set to the receiver and the
* children references are modified in the receiver to reflect the new child. The lastChild of the receiver is set
* to the child, and the firstChild is set also if child is the first (or only) child.
*/
public void addChild( Evaluation child )
{
if ( firstChild == null )
{
firstChild = child;
lastChild = child;
}
else
{
if ( firstChild == lastChild )
{
firstChild.next = child;
lastChild = child;
lastChild.previous = firstChild;
}
else
{
child.previous = lastChild;
lastChild.next = child;
lastChild = child;
}
}
child.parent = this;
}
/**
* Reinitializes this Evaluation to the parameters specified.
*/
public void init( SimpleNode node, Object source, boolean setOperation )
{
this.node = node;
this.source = source;
this.setOperation = setOperation;
result = null;
exception = null;
parent = null;
next = null;
previous = null;
firstChild = null;
lastChild = null;
}
/**
* Resets this Evaluation to the initial state.
*/
public void reset()
{
init( null, null, false );
}
/**
* Produces a String value for the Evaluation. If compact is true then a more compact form of the description only
* including the node type and unique identifier is shown, else a full description including source and result are
* shown. If showChildren is true the child evaluations are printed using the depth string given as a prefix.
*/
public String toString( boolean compact, boolean showChildren, String depth )
{
StringBuilder stringResult;
if ( compact )
{
stringResult = new StringBuilder(depth + "<" + node.getClass().getName() + " " + System.identityHashCode(this) + ">");
}
else
{
String ss = ( source != null ) ? source.getClass().getName() : "null", rs =
( result != null ) ? result.getClass().getName() : "null";
stringResult = new StringBuilder(depth + "<" + node.getClass().getName() + ": [" + (setOperation ? "set" : "get") + "] source = " + ss
+ ", result = " + result + " [" + rs + "]>");
}
if ( showChildren )
{
Evaluation child = firstChild;
stringResult.append("\n");
while ( child != null )
{
stringResult.append(child.toString(compact, depth + " "));
child = child.next;
}
}
return stringResult.toString();
}
/**
* Produces a String value for the Evaluation. If compact is true then a more compact form of the description only
* including the node type and unique identifier is shown, else a full description including source and result are
* shown. Child evaluations are printed using the depth string given as a prefix.
*/
public String toString( boolean compact, String depth )
{
return toString( compact, true, depth );
}
/**
* Returns a String description of the Evaluation.
*/
@Override
public String toString()
{
return toString( false, "" );
}
}
| 4,577 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTNot.java | package org.apache.commons.ognl;
/*
* 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.
*/
/**
*/
class ASTNot
extends BooleanExpression
{
public ASTNot( int id )
{
super( id );
}
public ASTNot( OgnlParser p, int id )
{
super( p, id );
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
return OgnlOps.booleanValue( children[0].getValue( context, source ) ) ? Boolean.FALSE : Boolean.TRUE;
}
public String getExpressionOperator( int index )
{
return "!";
}
public String toGetSourceString( OgnlContext context, Object target )
{
try
{
String srcString = super.toGetSourceString( context, target );
if ( srcString == null || srcString.trim().length() < 1 )
{
srcString = "null";
}
context.setCurrentType( Boolean.TYPE );
return "(! org.apache.commons.ognl.OgnlOps.booleanValue(" + srcString + ") )";
}
catch ( Throwable t )
{
throw OgnlOps.castToRuntime( t );
}
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,578 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTList.java | package org.apache.commons.ognl;
/*
* 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.
*/
import org.apache.commons.ognl.enhance.ExpressionCompiler;
import org.apache.commons.ognl.enhance.OgnlExpressionCompiler;
import org.apache.commons.ognl.enhance.UnsupportedCompilationException;
import java.util.ArrayList;
import java.util.List;
/**
*/
public class ASTList
extends SimpleNode
implements NodeType
{
public ASTList( int id )
{
super( id );
}
public ASTList( OgnlParser p, int id )
{
super( p, id );
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
List answer = new ArrayList( jjtGetNumChildren() );
for ( int i = 0; i < jjtGetNumChildren(); ++i )
{
answer.add( children[i].getValue( context, source ) );
}
return answer;
}
public Class getGetterClass()
{
return null;
}
public Class getSetterClass()
{
return null;
}
public String toGetSourceString( OgnlContext context, Object target )
{
StringBuilder result = new StringBuilder();
boolean array = parent instanceof ASTCtor && ((ASTCtor) parent).isArray();
context.setCurrentType( List.class );
context.setCurrentAccessor( List.class );
if ( !array )
{
if ( jjtGetNumChildren() < 1 )
{
return "java.util.Arrays.asList( new Object[0])";
}
result.append("java.util.Arrays.asList( new Object[] ");
}
result.append("{ ");
try
{
for ( int i = 0; i < jjtGetNumChildren(); ++i )
{
if ( i > 0 )
{
result.append(", ");
}
Class prevType = context.getCurrentType();
Object objValue = children[i].getValue( context, context.getRoot() );
String value = children[i].toGetSourceString( context, target );
// to undo type setting of constants when used as method parameters
if (children[i] instanceof ASTConst)
{
context.setCurrentType( prevType );
}
value = ExpressionCompiler.getRootExpression( children[i], target, context ) + value;
String cast = "";
if ( ExpressionCompiler.shouldCast( children[i] ) )
{
cast = (String) context.remove( ExpressionCompiler.PRE_CAST );
}
if ( cast == null )
{
cast = "";
}
if ( !(children[i] instanceof ASTConst))
{
value = cast + value;
}
Class ctorClass = (Class) context.get( "_ctorClass" );
if ( array && ctorClass != null && !ctorClass.isPrimitive() )
{
Class valueClass = value != null ? value.getClass() : null;
if ( NodeType.class.isAssignableFrom( children[i].getClass() ) )
{
valueClass = ( (NodeType) children[i] ).getGetterClass();
}
final OgnlExpressionCompiler compiler = OgnlRuntime.getCompiler( context );
if ( valueClass != null && ctorClass.isArray() )
{
value =
compiler
.createLocalReference( context, "(" + ExpressionCompiler.getCastString( ctorClass )
+ ")org.apache.commons.ognl.OgnlOps.toArray(" + value + ", "
+ ctorClass.getComponentType().getName() + ".class, true)", ctorClass );
}
else if ( ctorClass.isPrimitive() )
{
Class wrapClass = OgnlRuntime.getPrimitiveWrapperClass( ctorClass );
value =
compiler
.createLocalReference( context, "((" + wrapClass.getName()
+ ")org.apache.commons.ognl.OgnlOps.convertValue(" + value + ","
+ wrapClass.getName() + ".class, true))." + OgnlRuntime.getNumericValueGetter(
wrapClass ), ctorClass );
}
else if ( ctorClass != Object.class )
{
value =
compiler
.createLocalReference( context, "(" + ctorClass.getName()
+ ")org.apache.commons.ognl.OgnlOps.convertValue(" + value + ","
+ ctorClass.getName() + ".class)", ctorClass );
}
else if ( ( children[i] instanceof NodeType
&& ( (NodeType) children[i] ).getGetterClass() != null
&& Number.class.isAssignableFrom( ( (NodeType) children[i] ).getGetterClass() ) )
|| valueClass.isPrimitive() )
{
value = " ($w) (" + value + ")";
}
else if ( valueClass.isPrimitive() )
{
value = "($w) (" + value + ")";
}
}
else if ( ctorClass == null || !ctorClass.isPrimitive() )
{
value = " ($w) (" + value + ")";
}
if ( objValue == null || value.isEmpty() )
{
value = "null";
}
result.append(value);
}
}
catch ( Throwable t )
{
throw OgnlOps.castToRuntime( t );
}
context.setCurrentType( List.class );
context.setCurrentAccessor( List.class );
result.append("}");
if ( !array )
{
result.append(")");
}
return result.toString();
}
public String toSetSourceString( OgnlContext context, Object target )
{
throw new UnsupportedCompilationException( "Can't generate setter for ASTList." );
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,579 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/OgnlContext.java | package org.apache.commons.ognl;
/*
* 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.
*/
import org.apache.commons.ognl.enhance.LocalReference;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
/**
* This class defines the execution context for an OGNL expression
*/
public class OgnlContext
implements Map<String, Object>
{
public static final String CONTEXT_CONTEXT_KEY = "context";
public static final String ROOT_CONTEXT_KEY = "root";
public static final String THIS_CONTEXT_KEY = "this";
public static final String TRACE_EVALUATIONS_CONTEXT_KEY = "_traceEvaluations";
public static final String LAST_EVALUATION_CONTEXT_KEY = "_lastEvaluation";
public static final String KEEP_LAST_EVALUATION_CONTEXT_KEY = "_keepLastEvaluation";
public static final String CLASS_RESOLVER_CONTEXT_KEY = "_classResolver";
public static final String TYPE_CONVERTER_CONTEXT_KEY = "_typeConverter";
public static final String MEMBER_ACCESS_CONTEXT_KEY = "_memberAccess";
private static final String PROPERTY_KEY_PREFIX = "ognl";
private static boolean defaultTraceEvaluations;
private static boolean defaultKeepLastEvaluation;
public static final DefaultClassResolver DEFAULT_CLASS_RESOLVER = new DefaultClassResolver();
public static final TypeConverter DEFAULT_TYPE_CONVERTER = new DefaultTypeConverter();
public static final MemberAccess DEFAULT_MEMBER_ACCESS = new DefaultMemberAccess( false );
private static final Set<String> RESERVED_KEYS = new HashSet<String>( 11 );
private Object root;
private Object currentObject;
private Node currentNode;
private boolean traceEvaluations = defaultTraceEvaluations;
private Evaluation rootEvaluation;
private Evaluation currentEvaluation;
private Evaluation lastEvaluation;
private boolean keepLastEvaluation = defaultKeepLastEvaluation;
private Map<String, Object> values = new HashMap<String, Object>( 23 );
private ClassResolver classResolver = DEFAULT_CLASS_RESOLVER;
private TypeConverter typeConverter = DEFAULT_TYPE_CONVERTER;
private MemberAccess memberAccess = DEFAULT_MEMBER_ACCESS;
static
{
String s;
RESERVED_KEYS.add( CONTEXT_CONTEXT_KEY );
RESERVED_KEYS.add( ROOT_CONTEXT_KEY );
RESERVED_KEYS.add( THIS_CONTEXT_KEY );
RESERVED_KEYS.add( TRACE_EVALUATIONS_CONTEXT_KEY );
RESERVED_KEYS.add( LAST_EVALUATION_CONTEXT_KEY );
RESERVED_KEYS.add( KEEP_LAST_EVALUATION_CONTEXT_KEY );
RESERVED_KEYS.add( CLASS_RESOLVER_CONTEXT_KEY );
RESERVED_KEYS.add( TYPE_CONVERTER_CONTEXT_KEY );
RESERVED_KEYS.add( MEMBER_ACCESS_CONTEXT_KEY );
try
{
s = System.getProperty( PROPERTY_KEY_PREFIX + ".traceEvaluations" );
if ( s != null )
{
defaultTraceEvaluations = Boolean.parseBoolean( s.trim() );
}
s = System.getProperty( PROPERTY_KEY_PREFIX + ".keepLastEvaluation" );
if ( s != null )
{
defaultKeepLastEvaluation = Boolean.parseBoolean( s.trim() );
}
}
catch ( SecurityException ex )
{
// restricted access environment, just keep defaults
}
}
private final Stack<Class<?>> typeStack = new Stack<Class<?>>();
private final Stack<Class<?>> accessorStack = new Stack<Class<?>>();
private int localReferenceCounter;
private Map<String, LocalReference> localReferenceMap;
/**
* Constructs a new OgnlContext with the default class resolver, type converter and member access.
*/
public OgnlContext()
{
}
/**
* Constructs a new OgnlContext with the given class resolver, type converter and member access. If any of these
* parameters is null the default will be used.
*/
public OgnlContext( ClassResolver classResolver, TypeConverter typeConverter, MemberAccess memberAccess )
{
this();
if ( classResolver != null )
{
this.classResolver = classResolver;
}
if ( typeConverter != null )
{
this.typeConverter = typeConverter;
}
if ( memberAccess != null )
{
this.memberAccess = memberAccess;
}
}
public OgnlContext( Map<String, Object> values )
{
this.values = values;
}
public OgnlContext( ClassResolver classResolver, TypeConverter typeConverter, MemberAccess memberAccess,
Map<String, Object> values )
{
this( classResolver, typeConverter, memberAccess );
this.values = values;
}
public void setValues( Map<String, Object> value )
{
values.putAll( value );
}
public Map<String, Object> getValues()
{
return values;
}
public void setClassResolver( ClassResolver value )
{
if ( value == null )
{
throw new IllegalArgumentException( "cannot set ClassResolver to null" );
}
classResolver = value;
}
public ClassResolver getClassResolver()
{
return classResolver;
}
public void setTypeConverter( TypeConverter value )
{
if ( value == null )
{
throw new IllegalArgumentException( "cannot set TypeConverter to null" );
}
typeConverter = value;
}
public TypeConverter getTypeConverter()
{
return typeConverter;
}
public void setMemberAccess( MemberAccess value )
{
if ( value == null )
{
throw new IllegalArgumentException( "cannot set MemberAccess to null" );
}
memberAccess = value;
}
public MemberAccess getMemberAccess()
{
return memberAccess;
}
public void setRoot( Object value )
{
root = value;
accessorStack.clear();
typeStack.clear();
currentObject = value;
if ( currentObject != null )
{
setCurrentType( currentObject.getClass() );
}
}
public Object getRoot()
{
return root;
}
public boolean getTraceEvaluations()
{
return traceEvaluations;
}
public void setTraceEvaluations( boolean value )
{
traceEvaluations = value;
}
public Evaluation getLastEvaluation()
{
return lastEvaluation;
}
public void setLastEvaluation( Evaluation value )
{
lastEvaluation = value;
}
/**
* This method can be called when the last evaluation has been used and can be returned for reuse in the free pool
* maintained by the runtime. This is not a necessary step, but is useful for keeping memory usage down. This will
* recycle the last evaluation and then set the last evaluation to null.
*/
public void recycleLastEvaluation()
{
lastEvaluation = null;
}
/**
* Returns true if the last evaluation that was done on this context is retained and available through
* <code>getLastEvaluation()</code>. The default is true.
*/
public boolean getKeepLastEvaluation()
{
return keepLastEvaluation;
}
/**
* Sets whether the last evaluation that was done on this context is retained and available through
* <code>getLastEvaluation()</code>. The default is true.
*/
public void setKeepLastEvaluation( boolean value )
{
keepLastEvaluation = value;
}
public void setCurrentObject( Object value )
{
currentObject = value;
}
public Object getCurrentObject()
{
return currentObject;
}
public void setCurrentAccessor( Class<?> type )
{
accessorStack.add( type );
}
public Class<?> getCurrentAccessor()
{
if ( accessorStack.isEmpty() )
{
return null;
}
return accessorStack.peek();
}
public Class<?> getPreviousAccessor()
{
if ( accessorStack.isEmpty() )
{
return null;
}
if ( accessorStack.size() > 1 )
{
return accessorStack.get( accessorStack.size() - 2 );
}
return null;
}
public Class<?> getFirstAccessor()
{
if ( accessorStack.isEmpty() )
{
return null;
}
return accessorStack.get( 0 );
}
/**
* Gets the current class type being evaluated on the stack, as set by {@link #setCurrentType(Class)}.
*
* @return The current object type, may be null.
*/
public Class<?> getCurrentType()
{
if ( typeStack.isEmpty() )
{
return null;
}
return typeStack.peek();
}
public void setCurrentType( Class<?> type )
{
typeStack.add( type );
}
/**
* Represents the last known object type on the evaluation stack, will be the value of the last known
* {@link #getCurrentType()}.
*
* @return The previous type of object on the stack, may be null.
*/
public Class<?> getPreviousType()
{
if ( typeStack.isEmpty() )
{
return null;
}
if ( typeStack.size() > 1 )
{
return typeStack.get( typeStack.size() - 2 );
}
return null;
}
public void setPreviousType( Class<?> type )
{
if ( typeStack.isEmpty() || typeStack.size() < 2 )
{
return;
}
typeStack.set( typeStack.size() - 2, type );
}
public Class<?> getFirstType()
{
if ( typeStack.isEmpty() )
{
return null;
}
return typeStack.get( 0 );
}
public void setCurrentNode( Node value )
{
currentNode = value;
}
public Node getCurrentNode()
{
return currentNode;
}
/**
* Gets the current Evaluation from the top of the stack. This is the Evaluation that is in process of evaluating.
*/
public Evaluation getCurrentEvaluation()
{
return currentEvaluation;
}
public void setCurrentEvaluation( Evaluation value )
{
currentEvaluation = value;
}
/**
* Gets the root of the evaluation stack. This Evaluation contains the node representing the root expression and the
* source is the root source object.
*/
public Evaluation getRootEvaluation()
{
return rootEvaluation;
}
public void setRootEvaluation( Evaluation value )
{
rootEvaluation = value;
}
/**
* Returns the Evaluation at the relative index given. This should be zero or a negative number as a relative
* reference back up the evaluation stack. Therefore getEvaluation(0) returns the current Evaluation.
*/
public Evaluation getEvaluation( int relativeIndex )
{
Evaluation result = null;
if ( relativeIndex <= 0 )
{
result = currentEvaluation;
while ( ( ++relativeIndex < 0 ) && ( result != null ) )
{
result = result.getParent();
}
}
return result;
}
/**
* Pushes a new Evaluation onto the stack. This is done before a node evaluates. When evaluation is complete it
* should be popped from the stack via <code>popEvaluation()</code>.
*/
public void pushEvaluation( Evaluation value )
{
if ( currentEvaluation != null )
{
currentEvaluation.addChild( value );
}
else
{
setRootEvaluation( value );
}
setCurrentEvaluation( value );
}
/**
* Pops the current Evaluation off of the top of the stack. This is done after a node has completed its evaluation.
*/
public Evaluation popEvaluation()
{
Evaluation result;
result = currentEvaluation;
setCurrentEvaluation( result.getParent() );
if ( currentEvaluation == null )
{
setLastEvaluation( getKeepLastEvaluation() ? result : null );
setRootEvaluation( null );
setCurrentNode( null );
}
return result;
}
public int incrementLocalReferenceCounter()
{
return ++localReferenceCounter;
}
public void addLocalReference( String key, LocalReference reference )
{
if ( localReferenceMap == null )
{
localReferenceMap = new LinkedHashMap<String, LocalReference>();
}
localReferenceMap.put( key, reference );
}
public Map<String, LocalReference> getLocalReferences()
{
return localReferenceMap;
}
/* ================= Map interface ================= */
public int size()
{
return values.size();
}
public boolean isEmpty()
{
return values.isEmpty();
}
public boolean containsKey( Object key )
{
return values.containsKey( key );
}
public boolean containsValue( Object value )
{
return values.containsValue( value );
}
public Object get( Object key )
{
Object result = null;
// FIXME: complexity is O(n)
if ( RESERVED_KEYS.contains( key ) )
{
if ( THIS_CONTEXT_KEY.equals( key ) )
{
result = getCurrentObject();
}
else if ( ROOT_CONTEXT_KEY.equals( key ) )
{
result = getRoot();
}
else if ( CONTEXT_CONTEXT_KEY.equals( key ) )
{
result = this;
}
else if ( TRACE_EVALUATIONS_CONTEXT_KEY.equals( key ) )
{
result = getTraceEvaluations() ? Boolean.TRUE : Boolean.FALSE;
}
else if ( LAST_EVALUATION_CONTEXT_KEY.equals( key ) )
{
result = getLastEvaluation();
}
else if ( KEEP_LAST_EVALUATION_CONTEXT_KEY.equals( key ) )
{
result = getKeepLastEvaluation() ? Boolean.TRUE : Boolean.FALSE;
}
else if ( CLASS_RESOLVER_CONTEXT_KEY.equals( key ) )
{
result = getClassResolver();
}
else if ( TYPE_CONVERTER_CONTEXT_KEY.equals( key ) )
{
result = getTypeConverter();
}
else if ( MEMBER_ACCESS_CONTEXT_KEY.equals( key ) )
{
result = getMemberAccess();
}
}
else
{
result = values.get( key );
}
return result;
}
public Object put( String key, Object value )
{
Object result = null;
// FIXME: complexity is O(n)
if ( RESERVED_KEYS.contains( key ) )
{
if ( CONTEXT_CONTEXT_KEY.equals( key ) )
{
throw new IllegalArgumentException( "can't change " + CONTEXT_CONTEXT_KEY + " in context" );
}
if ( THIS_CONTEXT_KEY.equals( key ) )
{
result = getCurrentObject();
setCurrentObject( value );
}
else if ( ROOT_CONTEXT_KEY.equals( key ) )
{
result = getRoot();
setRoot( value );
}
else if ( TRACE_EVALUATIONS_CONTEXT_KEY.equals( key ) )
{
result = getTraceEvaluations() ? Boolean.TRUE : Boolean.FALSE;
setTraceEvaluations( OgnlOps.booleanValue( value ) );
}
else if ( LAST_EVALUATION_CONTEXT_KEY.equals( key ) )
{
result = getLastEvaluation();
lastEvaluation = (Evaluation) value;
}
else if ( KEEP_LAST_EVALUATION_CONTEXT_KEY.equals( key ) )
{
result = getKeepLastEvaluation() ? Boolean.TRUE : Boolean.FALSE;
setKeepLastEvaluation( OgnlOps.booleanValue( value ) );
}
else if ( CLASS_RESOLVER_CONTEXT_KEY.equals( key ) )
{
result = getClassResolver();
setClassResolver( (ClassResolver) value );
}
else if ( TYPE_CONVERTER_CONTEXT_KEY.equals( key ) )
{
result = getTypeConverter();
setTypeConverter( (TypeConverter) value );
}
else if ( MEMBER_ACCESS_CONTEXT_KEY.equals( key ) )
{
result = getMemberAccess();
setMemberAccess( (MemberAccess) value );
}
}
else
{
result = values.put( key, value );
}
return result;
}
public Object remove( Object key )
{
Object result = null;
// FIXME: complexity is O(n)
if ( RESERVED_KEYS.contains( key ) )
{
if ( CONTEXT_CONTEXT_KEY.equals( key ) || TRACE_EVALUATIONS_CONTEXT_KEY.equals( key )
|| KEEP_LAST_EVALUATION_CONTEXT_KEY.equals( key ) )
{
throw new IllegalArgumentException( "can't remove " + key + " from context" );
}
if ( THIS_CONTEXT_KEY.equals( key ) )
{
result = getCurrentObject();
setCurrentObject( null );
}
else if ( ROOT_CONTEXT_KEY.equals( key ) )
{
result = getRoot();
setRoot( null );
}
else if ( LAST_EVALUATION_CONTEXT_KEY.equals( key ) )
{
result = lastEvaluation;
setLastEvaluation( null );
}
else if ( CLASS_RESOLVER_CONTEXT_KEY.equals( key ) )
{
result = getClassResolver();
setClassResolver( null );
}
else if ( TYPE_CONVERTER_CONTEXT_KEY.equals( key ) )
{
result = getTypeConverter();
setTypeConverter( null );
}
else if ( MEMBER_ACCESS_CONTEXT_KEY.equals( key ) )
{
result = getMemberAccess();
setMemberAccess( null );
}
}
else
{
result = values.remove( key );
}
return result;
}
public void putAll( Map<? extends String, ?> t )
{
for ( Entry<? extends String, ?> entry : t.entrySet() )
{
put( entry.getKey(), entry.getValue() );
}
}
public void clear()
{
values.clear();
typeStack.clear();
accessorStack.clear();
localReferenceCounter = 0;
if ( localReferenceMap != null )
{
localReferenceMap.clear();
}
setRoot( null );
setCurrentObject( null );
setRootEvaluation( null );
setCurrentEvaluation( null );
setLastEvaluation( null );
setCurrentNode( null );
setClassResolver( DEFAULT_CLASS_RESOLVER );
setTypeConverter( DEFAULT_TYPE_CONVERTER );
setMemberAccess( DEFAULT_MEMBER_ACCESS );
}
public Set<String> keySet()
{
/* Should root, currentObject, classResolver, typeConverter & memberAccess be included here? */
return values.keySet();
}
public Collection<Object> values()
{
/* Should root, currentObject, classResolver, typeConverter & memberAccess be included here? */
return values.values();
}
public Set<Entry<String, Object>> entrySet()
{
/* Should root, currentObject, classResolver, typeConverter & memberAccess be included here? */
return values.entrySet();
}
@Override
public boolean equals( Object o )
{
return values.equals( o );
}
@Override
public int hashCode()
{
return values.hashCode();
}
}
| 4,580 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/Node.java | package org.apache.commons.ognl;
/*
* 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.
*/
import org.apache.commons.ognl.enhance.ExpressionAccessor;
/**
* JJTree interface for AST nodes, as modified to handle the OGNL operations getValue and setValue. JJTree's original
* comment: All AST nodes must implement this interface. It provides basic machinery for constructing the parent and
* child relationships between nodes.
*/
public interface Node
extends JavaSource
{
/**
* This method is called after the node has been made the current node. It indicates that child nodes can now be
* added to it.
*/
void jjtOpen();
/**
* This method is called after all the child nodes have been added.
*/
void jjtClose();
/**
* This pair of methods are used to inform the node of its parent.
*/
void jjtSetParent( Node n );
Node jjtGetParent();
/**
* This method tells the node to add its argument to the node's list of children.
*/
void jjtAddChild( Node n, int i );
/**
* This method returns a child node. The children are numbered from zero, left to right.
*/
Node jjtGetChild( int i );
/** Return the number of children the node has. */
int jjtGetNumChildren();
// OGNL additions to Node:
/**
* Extracts the value from the given source object that is appropriate for this node within the given context.
*/
Object getValue( OgnlContext context, Object source )
throws OgnlException;
/**
* Sets the given value in the given target as appropriate for this node within the given context.
*/
void setValue( OgnlContext context, Object target, Object value )
throws OgnlException;
/**
* Gets the compiled bytecode enhanced expression accessor for getting/setting values.
*
* @return The accessor for this node, or null if none has been compiled for it.
*/
ExpressionAccessor getAccessor();
/**
* Sets a new compiled accessor for this node expression.
*
* @param accessor The compiled representation of this node.
*/
void setAccessor( ExpressionAccessor accessor );
/**
* Supports the Visitor pattern. The method which corresponds to
* the runtime type of this Node will be called.
*
* @param visitor The visitor to accept.
* @param data The second parameter to pass through to visitor.visit
* @param <R> The return type of the visitor.visit method.
* @param <P> The type of the second parameter type.
* @return the value returned by visitor.visit
* @throws NullPointerException if visitor is null
* @throws RuntimeException if visitor.visit throws an exception.
*/
<R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException;
}
| 4,581 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java | package org.apache.commons.ognl;
/*
* 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.
*/
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* Implementation of PropertyAccessor that sets and gets properties by storing and looking up values in Maps.
*/
public class MapPropertyAccessor
implements PropertyAccessor
{
public Object getProperty( Map<String, Object> context, Object target, Object name )
throws OgnlException
{
Object result;
@SuppressWarnings( "unchecked" ) // checked by the invoker
Map<Object, Object> map = (Map<Object, Object>) target;
Node currentNode = ( (OgnlContext) context ).getCurrentNode().jjtGetParent();
boolean indexedAccess = false;
if ( currentNode == null )
{
throw new OgnlException( "node is null for '" + name + "'" );
}
if ( !( currentNode instanceof ASTProperty ) )
{
currentNode = currentNode.jjtGetParent();
}
if ( currentNode instanceof ASTProperty )
{
indexedAccess = ( (ASTProperty) currentNode ).isIndexedAccess();
}
if ( ( name instanceof String ) && !indexedAccess )
{
if ( "size".equals( name ) )
{
result = map.size();
}
else if ( "keys".equals( name ) || "keySet".equals( name ) )
{
result = map.keySet();
}
else if ( "values".equals( name ) )
{
result = map.values();
}
else if ( "isEmpty".equals( name ) )
{
result = map.isEmpty() ? Boolean.TRUE : Boolean.FALSE;
}
else
{
result = map.get( name );
}
}
else
{
result = map.get( name );
}
return result;
}
public void setProperty( Map<String, Object> context, Object target, Object name, Object value )
throws OgnlException
{
@SuppressWarnings( "unchecked" ) // checked by the invoker
Map<Object, Object> map = (Map<Object, Object>) target;
map.put( name, value );
}
public String getSourceAccessor( OgnlContext context, Object target, Object index )
{
Objects.requireNonNull(context, "context");
Objects.requireNonNull(context.getCurrentNode(), "getCurrentNode()");
Node currentNode = Objects.requireNonNull(context.getCurrentNode().jjtGetParent(), "node is null for '" + index + "'" );
boolean indexedAccess = false;
if ( !( currentNode instanceof ASTProperty ) )
{
currentNode = currentNode.jjtGetParent();
}
if ( currentNode instanceof ASTProperty )
{
indexedAccess = ( (ASTProperty) currentNode ).isIndexedAccess();
}
String indexStr = index.toString();
context.setCurrentAccessor( Map.class );
context.setCurrentType( Object.class );
if ( index instanceof String && !indexedAccess )
{
String key = indexStr.replace( "\"", "" );
if ( "size".equals( key ) )
{
context.setCurrentType( int.class );
return ".size()";
}
if ( "keys".equals( key ) || "keySet".equals( key ) )
{
context.setCurrentType( Set.class );
return ".keySet()";
}
if ( "values".equals( key ) )
{
context.setCurrentType( Collection.class );
return ".values()";
}
if ( "isEmpty".equals( key ) )
{
context.setCurrentType( boolean.class );
return ".isEmpty()";
}
}
return ".get(" + indexStr + ")";
}
public String getSourceSetter( OgnlContext context, Object target, Object index )
{
context.setCurrentAccessor( Map.class );
context.setCurrentType( Object.class );
String indexStr = index.toString();
if (index instanceof String)
{
String key = indexStr.replace( "\"", "" );
if ( "size".equals( key ) || "keys".equals( key ) || "keySet".equals( key ) || "values".equals( key )
|| "isEmpty".equals( key ) )
{
return "";
}
}
return ".put(" + indexStr + ", $3)";
}
}
| 4,582 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTSubtract.java | package org.apache.commons.ognl;
/*
* 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.
*/
/**
*/
class ASTSubtract
extends NumericExpression
{
public ASTSubtract( int id )
{
super( id );
}
public ASTSubtract( OgnlParser p, int id )
{
super( p, id );
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
Object v1 = children[0].getValue( context, source );
Object v2 = children[1].getValue( context, source );
return OgnlOps.subtract( v1, v2 );
}
public String getExpressionOperator( int index )
{
return "-";
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,583 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTVarRef.java | package org.apache.commons.ognl;
/*
* 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.
*/
import org.apache.commons.ognl.enhance.OrderedReturn;
import org.apache.commons.ognl.enhance.UnsupportedCompilationException;
/**
*/
public class ASTVarRef
extends SimpleNode
implements NodeType, OrderedReturn
{
private String name;
protected Class getterClass;
protected String core;
protected String last;
public ASTVarRef( int id )
{
super( id );
}
public ASTVarRef( OgnlParser p, int id )
{
super( p, id );
}
void setName( String name )
{
this.name = name;
}
/**
* Gets the variable name.
*
* @return the variable name.
* @since 4.0
*/
String getName()
{
return name;
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
return context.get( name );
}
protected void setValueBody( OgnlContext context, Object target, Object value )
throws OgnlException
{
context.put( name, value );
}
public Class getGetterClass()
{
return getterClass;
}
public Class getSetterClass()
{
return null;
}
public String getCoreExpression()
{
return core;
}
public String getLastExpression()
{
return last;
}
public String toGetSourceString( OgnlContext context, Object target )
{
Object value = context.get( name );
if ( value != null )
{
getterClass = value.getClass();
}
context.setCurrentType( getterClass );
context.setCurrentAccessor( context.getClass() );
context.setCurrentObject( value );
// context.setRoot(context.get(name));
if ( context.getCurrentObject() == null )
{
throw new UnsupportedCompilationException( "Current context object is null, can't compile var reference." );
}
String pre = "";
String post = "";
if ( context.getCurrentType() != null )
{
pre = "((" + OgnlRuntime.getCompiler( context ).getInterfaceClass( context.getCurrentType() ).getName() + ")";
post = ")";
}
if ( parent != null && parent instanceof ASTAssign)
{
core = "$1.put(\"" + name + "\",";
last = pre + "$1.get(\"" + name + "\")" + post;
return core;
}
return pre + "$1.get(\"" + name + "\")" + post;
}
public String toSetSourceString( OgnlContext context, Object target )
{
return toGetSourceString( context, target );
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,584 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTDivide.java | package org.apache.commons.ognl;
/*
* 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.
*/
/**
*/
class ASTDivide
extends NumericExpression
{
public ASTDivide( int id )
{
super( id );
}
public ASTDivide( OgnlParser p, int id )
{
super( p, id );
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
Object v1 = children[0].getValue( context, source );
Object v2 = children[1].getValue( context, source );
return OgnlOps.divide( v1, v2 );
}
public String getExpressionOperator( int index )
{
return "/";
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,585 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java | package org.apache.commons.ognl;
/*
* 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.
*/
import java.lang.reflect.Array;
import java.util.Map;
import static java.lang.String.format;
/**
* Implementation of PropertyAccessor that uses numbers and dynamic subscripts as properties to index into Java arrays.
*/
public class ArrayPropertyAccessor
extends ObjectPropertyAccessor
implements PropertyAccessor
{
@Override
public Object getProperty( Map<String, Object> context, Object target, Object name )
throws OgnlException
{
Object result = null;
if ( name instanceof String )
{
if ( "length".equals( name ) )
{
result = Array.getLength( target );
}
else
{
result = super.getProperty( context, target, name );
}
}
else
{
Object index = name;
if ( index instanceof DynamicSubscript )
{
int len = Array.getLength( target );
switch ( ( (DynamicSubscript) index ).getFlag() )
{
case DynamicSubscript.ALL:
result = Array.newInstance( target.getClass().getComponentType(), len );
System.arraycopy( target, 0, result, 0, len );
break;
case DynamicSubscript.FIRST:
index = ( len > 0 ) ? 0 : -1;
break;
case DynamicSubscript.MID:
index = ( len > 0 ) ? ( len / 2 ) : -1;
break;
case DynamicSubscript.LAST:
index = ( len > 0 ) ? ( len - 1 ) : -1;
break;
default: break;
}
}
if ( result == null )
{
if ( !(index instanceof Number) ) {
throw new NoSuchPropertyException( target, index );
}
int i = ( (Number) index ).intValue();
result = ( i >= 0 ) ? Array.get( target, i ) : null;
}
}
return result;
}
@Override
public void setProperty( Map<String, Object> context, Object target, Object name, Object value )
throws OgnlException
{
boolean isNumber = ( name instanceof Number );
if ( isNumber || ( name instanceof DynamicSubscript ) )
{
TypeConverter converter = ( (OgnlContext) context ).getTypeConverter();
Object convertedValue;
convertedValue = converter.convertValue( context, target, null, name.toString(), value,
target.getClass().getComponentType() );
if ( isNumber )
{
int i = ( (Number) name ).intValue();
if ( i >= 0 )
{
Array.set( target, i, convertedValue );
}
}
else
{
int len = Array.getLength( target );
switch ( ( (DynamicSubscript) name ).getFlag() )
{
case DynamicSubscript.ALL:
System.arraycopy( target, 0, convertedValue, 0, len );
return;
default:
break;
}
}
}
else
{
if ( !(name instanceof String) ) {
throw new NoSuchPropertyException( target, name );
}
super.setProperty( context, target, name, value );
}
}
@Override
public String getSourceAccessor( OgnlContext context, Object target, Object index )
{
String indexStr = getIndexString( context, index );
context.setCurrentAccessor( target.getClass() );
context.setCurrentType( target.getClass().getComponentType() );
return format( "[%s]", indexStr );
}
@Override
public String getSourceSetter( OgnlContext context, Object target, Object index )
{
String indexStr = getIndexString( context, index );
Class<?> type = target.getClass().isArray() ? target.getClass().getComponentType() : target.getClass();
context.setCurrentAccessor( target.getClass() );
context.setCurrentType( target.getClass().getComponentType() );
if ( type.isPrimitive() )
{
Class<?> wrapClass = OgnlRuntime.getPrimitiveWrapperClass( type );
return format( "[%s]=((%s)org.apache.commons.ognl.OgnlOps.convertValue($3,%s.class, true)).%s", indexStr,
wrapClass.getName(), wrapClass.getName(), OgnlRuntime.getNumericValueGetter( wrapClass ) );
}
return format( "[%s]=org.apache.commons.ognl.OgnlOps.convertValue($3,%s.class)", indexStr, type.getName() );
}
private static String getIndexString( OgnlContext context, Object index )
{
String indexStr = index.toString();
// need to convert to primitive for list index access
// System.out.println("index class " + index.getClass() + " current type " + context.getCurrentType() +
// " current object class " + context.getCurrentObject().getClass());
if ( context.getCurrentType() != null && !context.getCurrentType().isPrimitive()
&& Number.class.isAssignableFrom( context.getCurrentType() ) )
{
indexStr += "." + OgnlRuntime.getNumericValueGetter( context.getCurrentType() );
}
else if ( context.getCurrentObject() != null && Number.class.isAssignableFrom(
context.getCurrentObject().getClass() ) && !context.getCurrentType().isPrimitive() )
{
// means it needs to be cast first as well
String toString =
index instanceof String && context.getCurrentType() != Object.class ? "" : ".toString()";
indexStr = format( "org.apache.commons.ognl.OgnlOps#getIntValue(%s%s)", indexStr, toString );
}
return indexStr;
}
}
| 4,586 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/Ognl.java | package org.apache.commons.ognl;
/*
* 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.
*/
import org.apache.commons.ognl.enhance.ExpressionAccessor;
import java.io.StringReader;
import java.util.Map;
/**
* <p>
* This class provides static methods for parsing and interpreting OGNL expressions.
* </p>
* <p>
* The simplest use of the Ognl class is to get the value of an expression from an object, without extra context or
* pre-parsing.
* </p>
*
* <pre>
*
* import org.apache.commons.ognl.Ognl;
* import org.apache.commons.ognl.OgnlException;
* ...
* try
* {
* result = Ognl.getValue( expression, root );
* }
* catch ( OgnlException ex )
* {
* // Report error or recover
* }
*
* </pre>
* <p>
* This will parse the expression given and evaluate it against the root object given, returning the result. If there is
* an error in the expression, such as the property is not found, the exception is encapsulated into an
* {@link org.apache.commons.ognl.OgnlException OgnlException}.
* </p>
* <p>
* Other more sophisticated uses of Ognl can pre-parse expressions. This provides two advantages: in the case of
* user-supplied expressions it allows you to catch parse errors before evaluation and it allows you to cache parsed
* expressions into an AST for better speed during repeated use. The pre-parsed expression is always returned as an
* <code>Object</code> to simplify use for programs that just wish to store the value for repeated use and do not care
* that it is an AST. If it does care it can always safely cast the value to an <code>AST</code> type.
* </p>
* <p>
* The Ognl class also takes a <I>context map</I> as one of the parameters to the set and get methods. This allows you
* to put your own variables into the available namespace for OGNL expressions. The default context contains only the
* <code>#root</code> and <code>#context</code> keys, which are required to be present. The
* <code>addDefaultContext(Object, Map)</code> method will alter an existing <code>Map</code> to put the defaults in.
* Here is an example that shows how to extract the <code>documentName</code> property out of the root object and append
* a string with the current user name in parens:
* </p>
*
* <pre>
*
* private Map<String, Object> context = new HashMap<String, Object>();
* ...
* public void setUserName( String value )
* {
* context.put("userName", value);
* }
* ...
* try
* {
* // get value using our own custom context map
* result = Ognl.getValue( "documentName + \" (\" + ((#userName == null) ? \"<nobody>\" : #userName ) +
* \")\"", context, root );
* }
* catch ( OgnlException ex )
* {
* // Report error or recover
* }
*
* </pre>
*/
public abstract class Ognl
{
/**
* Parses the given OGNL expression and returns a tree representation of the expression that can be used by
* <code>Ognl</code> static methods.
*
* @param expression the OGNL expression to be parsed
* @return a tree representation of the expression
* @throws ExpressionSyntaxException if the expression is malformed
* @throws OgnlException if there is a pathological environmental problem
*/
public static Object parseExpression( String expression )
throws OgnlException
{
try
{
OgnlParser parser = new OgnlParser( new StringReader( expression ) );
return parser.topLevelExpression();
}
catch ( ParseException | TokenMgrError e )
{
throw new ExpressionSyntaxException( expression, e );
}
}
/**
* Parses and compiles the given expression using the {@link org.apache.commons.ognl.enhance.OgnlExpressionCompiler}
* returned from
* {@link org.apache.commons.ognl.OgnlRuntime#getCompiler(OgnlContext)}.
*
* @param context The context to use.
* @param root The root object for the given expression.
* @param expression The expression to compile.
* @return The node with a compiled accessor set on {@link org.apache.commons.ognl.Node#getAccessor()} if
* compilation was successfull.
* In instances where compilation wasn't possible because of a partially null expression the
* {@link ExpressionAccessor} instance may be null and the compilation of this expression still possible at
* some as yet indertermined point in the future.
* @throws Exception If a compilation error occurs.
*/
public static Node compileExpression( OgnlContext context, Object root, String expression )
throws Exception
{
Node expr = (Node) Ognl.parseExpression( expression );
OgnlRuntime.compileExpression( context, expr, root );
return expr;
}
/**
* Creates and returns a new standard naming context for evaluating an OGNL expression.
*
* @param root the root of the object graph
* @return a new Map with the keys <code>root</code> and <code>context</code> set appropriately
*/
public static Map<String, Object> createDefaultContext( Object root )
{
return addDefaultContext( root, null, null, null, new OgnlContext() );
}
/**
* Creates and returns a new standard naming context for evaluating an OGNL expression.
*
* @param root The root of the object graph.
* @param classResolver The resolver used to instantiate {@link Class} instances referenced in the expression.
* @return a new OgnlContext with the keys <code>root</code> and <code>context</code> set appropriately
*/
public static Map<String, Object> createDefaultContext( Object root, ClassResolver classResolver )
{
return addDefaultContext( root, classResolver, null, null, new OgnlContext() );
}
/**
* Creates and returns a new standard naming context for evaluating an OGNL expression.
*
* @param root The root of the object graph.
* @param classResolver The resolver used to instantiate {@link Class} instances referenced in the expression.
* @param converter Converter used to convert return types of an expression in to their desired types.
* @return a new Map with the keys <code>root</code> and <code>context</code> set appropriately
*/
public static Map<String, Object> createDefaultContext( Object root, ClassResolver classResolver,
TypeConverter converter )
{
return addDefaultContext( root, classResolver, converter, null, new OgnlContext() );
}
/**
* Creates and returns a new standard naming context for evaluating an OGNL expression.
*
* @param root The root of the object graph.
* @param classResolver The resolver used to instantiate {@link Class} instances referenced in the expression.
* @param converter Converter used to convert return types of an expression in to their desired types.
* @param memberAccess Java security handling object to determine semantics for accessing normally private/protected
* methods / fields.
* @return a new Map with the keys <code>root</code> and <code>context</code> set appropriately
*/
public static Map<String, Object> createDefaultContext( Object root, ClassResolver classResolver,
TypeConverter converter, MemberAccess memberAccess )
{
return addDefaultContext( root, classResolver, converter, memberAccess, new OgnlContext() );
}
/**
* Appends the standard naming context for evaluating an OGNL expression into the context given so that cached maps
* can be used as a context.
*
* @param root the root of the object graph
* @param context the context to which OGNL context will be added.
* @return Context Map with the keys <code>root</code> and <code>context</code> set appropriately
*/
public static Map<String, Object> addDefaultContext( Object root, Map<String, Object> context )
{
return addDefaultContext( root, null, null, null, context );
}
/**
* Appends the standard naming context for evaluating an OGNL expression into the context given so that cached maps
* can be used as a context.
*
* @param root The root of the object graph.
* @param classResolver The resolver used to instantiate {@link Class} instances referenced in the expression.
* @param context The context to which OGNL context will be added.
* @return Context Map with the keys <code>root</code> and <code>context</code> set appropriately
*/
public static Map<String, Object> addDefaultContext( Object root, ClassResolver classResolver,
Map<String, Object> context )
{
return addDefaultContext( root, classResolver, null, null, context );
}
/**
* Appends the standard naming context for evaluating an OGNL expression into the context given so that cached maps
* can be used as a context.
*
* @param root The root of the object graph.
* @param classResolver The resolver used to instantiate {@link Class} instances referenced in the expression.
* @param converter Converter used to convert return types of an expression in to their desired types.
* @param context The context to which OGNL context will be added.
* @return Context Map with the keys <code>root</code> and <code>context</code> set appropriately
*/
public static Map<String, Object> addDefaultContext( Object root, ClassResolver classResolver,
TypeConverter converter, Map<String, Object> context )
{
return addDefaultContext( root, classResolver, converter, null, context );
}
/**
* Appends the standard naming context for evaluating an OGNL expression into the context given so that cached maps
* can be used as a context.
*
* @param root the root of the object graph
* @param classResolver The class loading resolver that should be used to resolve class references.
* @param converter The type converter to be used by default.
* @param memberAccess Definition for handling private/protected access.
* @param context Default context to use, if not an {@link OgnlContext} will be dumped into a new
* {@link OgnlContext} object.
* @return Context Map with the keys <code>root</code> and <code>context</code> set appropriately
*/
public static Map<String, Object> addDefaultContext( Object root, ClassResolver classResolver,
TypeConverter converter, MemberAccess memberAccess,
Map<String, Object> context )
{
OgnlContext result;
if ( !( context instanceof OgnlContext ) )
{
result = new OgnlContext();
result.setValues( context );
}
else
{
result = (OgnlContext) context;
}
if ( classResolver != null )
{
result.setClassResolver( classResolver );
}
if ( converter != null )
{
result.setTypeConverter( converter );
}
if ( memberAccess != null )
{
result.setMemberAccess( memberAccess );
}
result.setRoot( root );
return result;
}
/**
* Configures the {@link ClassResolver} to use for the given context. Will be used during expression parsing /
* execution to resolve class names.
*
* @param context The context to place the resolver.
* @param classResolver The resolver to use to resolve classes.
*/
public static void setClassResolver( Map<String, Object> context, ClassResolver classResolver )
{
context.put( OgnlContext.CLASS_RESOLVER_CONTEXT_KEY, classResolver );
}
/**
* Gets the previously stored {@link ClassResolver} for the given context - if any.
*
* @param context The context to get the configured resolver from.
* @return The resolver instance, or null if none found.
*/
public static ClassResolver getClassResolver( Map<String, Object> context )
{
return (ClassResolver) context.get( OgnlContext.CLASS_RESOLVER_CONTEXT_KEY );
}
/**
* Configures the type converter to use for a given context. This will be used to convert into / out of various java
* class types.
*
* @param context The context to configure it for.
* @param converter The converter to use.
*/
public static void setTypeConverter( Map<String, Object> context, TypeConverter converter )
{
context.put( OgnlContext.TYPE_CONVERTER_CONTEXT_KEY, converter );
}
/**
* Gets the currently configured {@link TypeConverter} for the given context - if any.
*
* @param context The context to get the converter from.
* @return The converter - or null if none found.
*/
public static TypeConverter getTypeConverter( Map<String, Object> context )
{
return (TypeConverter) context.get( OgnlContext.TYPE_CONVERTER_CONTEXT_KEY );
}
/**
* Configures the specified context with a {@link MemberAccess} instance for handling field/method protection
* levels.
*
* @param context The context to configure.
* @param memberAccess The access resolver to configure the context with.
*/
public static void setMemberAccess( Map<String, Object> context, MemberAccess memberAccess )
{
context.put( OgnlContext.MEMBER_ACCESS_CONTEXT_KEY, memberAccess );
}
/**
* Gets the currently stored {@link MemberAccess} object for the given context - if any.
*
* @param context The context to get the object from.
* @return The configured {@link MemberAccess} instance in the specified context - or null if none found.
*/
public static MemberAccess getMemberAccess( Map<String, Object> context )
{
return (MemberAccess) context.get( OgnlContext.MEMBER_ACCESS_CONTEXT_KEY );
}
/**
* Sets the root object to use for all expressions in the given context - doesn't necessarily replace root object
* instances explicitly passed in to other expression resolving methods on this class.
*
* @param context The context to store the root object in.
* @param root The root object.
*/
public static void setRoot( Map<String, Object> context, Object root )
{
context.put( OgnlContext.ROOT_CONTEXT_KEY, root );
}
/**
* Gets the stored root object for the given context - if any.
*
* @param context The context to get the root object from.
* @return The root object - or null if none found.
*/
public static Object getRoot( Map<String, Object> context )
{
return context.get( OgnlContext.ROOT_CONTEXT_KEY );
}
/**
* Gets the last {@link Evaluation} executed on the given context.
*
* @param context The context to get the evaluation from.
* @return The {@link Evaluation} - or null if none was found.
*/
public static Evaluation getLastEvaluation( Map<String, Object> context )
{
return (Evaluation) context.get( OgnlContext.LAST_EVALUATION_CONTEXT_KEY );
}
/**
* Evaluates the given OGNL expression tree to extract a value from the given root object. The default context is
* set for the given context and root via <code>addDefaultContext()</code>.
*
* @param tree the OGNL expression tree to evaluate, as returned by parseExpression()
* @param context the naming context for the evaluation
* @param root the root object for the OGNL expression
* @return the result of evaluating the expression
* @throws MethodFailedException if the expression called a method which failed
* @throws NoSuchPropertyException if the expression referred to a nonexistent property
* @throws InappropriateExpressionException if the expression can't be used in this context
* @throws OgnlException if there is a pathological environmental problem
*/
public static <T> T getValue( Object tree, Map<String, Object> context, Object root )
throws OgnlException
{
return Ognl.<T> getValue( tree, context, root, null );
}
/**
* Evaluates the given OGNL expression tree to extract a value from the given root object. The default context is
* set for the given context and root via <code>addDefaultContext()</code>.
*
* @param tree the OGNL expression tree to evaluate, as returned by parseExpression()
* @param context the naming context for the evaluation
* @param root the root object for the OGNL expression
* @param resultType the converted type of the resultant object, using the context's type converter
* @return the result of evaluating the expression
* @throws MethodFailedException if the expression called a method which failed
* @throws NoSuchPropertyException if the expression referred to a nonexistent property
* @throws InappropriateExpressionException if the expression can't be used in this context
* @throws OgnlException if there is a pathological environmental problem
*/
@SuppressWarnings( "unchecked" ) // will cause CCE if types are not compatible
public static <T> T getValue( Object tree, Map<String, Object> context, Object root, Class<T> resultType )
throws OgnlException
{
T result;
OgnlContext ognlContext = (OgnlContext) addDefaultContext( root, context );
Node node = (Node) tree;
if ( node.getAccessor() != null )
{
result = (T) node.getAccessor().get( ognlContext, root );
}
else
{
result = (T) node.getValue( ognlContext, root );
}
if ( resultType != null )
{
result = getTypeConverter( context ).convertValue( context, root, null, null, result, resultType );
}
return result;
}
/**
* Gets the value represented by the given pre-compiled expression on the specified root object.
*
* @param expression The pre-compiled expression, as found in {@link Node#getAccessor()}.
* @param context The ognl context.
* @param root The object to retrieve the expression value from.
* @return The value.
*/
@SuppressWarnings( "unchecked" ) // will cause CCE if types are not compatible
public static <T> T getValue( ExpressionAccessor expression, OgnlContext context, Object root )
{
return (T) expression.get( context, root );
}
/**
* Gets the value represented by the given pre-compiled expression on the specified root object.
*
* @param expression The pre-compiled expression, as found in {@link Node#getAccessor()}.
* @param context The ognl context.
* @param root The object to retrieve the expression value from.
* @param resultType The desired object type that the return value should be converted to using the
* {@link #getTypeConverter(java.util.Map)} .
* @return The value.
*/
public static <T> T getValue( ExpressionAccessor expression, OgnlContext context, Object root, Class<T> resultType )
throws OgnlException
{
return getTypeConverter( context ).convertValue( context, root, null, null, expression.get( context, root ),
resultType );
}
/**
* Evaluates the given OGNL expression to extract a value from the given root object in a given context
*
* @see #parseExpression(String)
* @see #getValue(Object,Object)
* @param expression the OGNL expression to be parsed
* @param context the naming context for the evaluation
* @param root the root object for the OGNL expression
* @return the result of evaluating the expression
* @throws MethodFailedException if the expression called a method which failed
* @throws NoSuchPropertyException if the expression referred to a nonexistent property
* @throws InappropriateExpressionException if the expression can't be used in this context
* @throws OgnlException if there is a pathological environmental problem
*/
public static <T> T getValue( String expression, Map<String, Object> context, Object root )
throws OgnlException
{
return Ognl.<T> getValue( expression, context, root, null );
}
/**
* Evaluates the given OGNL expression to extract a value from the given root object in a given context
*
* @see #parseExpression(String)
* @see #getValue(Object,Object)
* @param expression the OGNL expression to be parsed
* @param context the naming context for the evaluation
* @param root the root object for the OGNL expression
* @param resultType the converted type of the resultant object, using the context's type converter
* @return the result of evaluating the expression
* @throws MethodFailedException if the expression called a method which failed
* @throws NoSuchPropertyException if the expression referred to a nonexistent property
* @throws InappropriateExpressionException if the expression can't be used in this context
* @throws OgnlException if there is a pathological environmental problem
*/
public static <T> T getValue( String expression, Map<String, Object> context, Object root, Class<T> resultType )
throws OgnlException
{
return Ognl.<T> getValue( parseExpression( expression ), context, root, resultType );
}
/**
* Evaluates the given OGNL expression tree to extract a value from the given root object.
*
* @param tree the OGNL expression tree to evaluate, as returned by parseExpression()
* @param root the root object for the OGNL expression
* @return the result of evaluating the expression
* @throws MethodFailedException if the expression called a method which failed
* @throws NoSuchPropertyException if the expression referred to a nonexistent property
* @throws InappropriateExpressionException if the expression can't be used in this context
* @throws OgnlException if there is a pathological environmental problem
*/
public static <T> T getValue( Object tree, Object root )
throws OgnlException
{
return Ognl.<T> getValue( tree, root, null );
}
/**
* Evaluates the given OGNL expression tree to extract a value from the given root object.
*
* @param tree the OGNL expression tree to evaluate, as returned by parseExpression()
* @param root the root object for the OGNL expression
* @param resultType the converted type of the resultant object, using the context's type converter
* @return the result of evaluating the expression
* @throws MethodFailedException if the expression called a method which failed
* @throws NoSuchPropertyException if the expression referred to a nonexistent property
* @throws InappropriateExpressionException if the expression can't be used in this context
* @throws OgnlException if there is a pathological environmental problem
*/
public static <T> T getValue( Object tree, Object root, Class<T> resultType )
throws OgnlException
{
return Ognl.<T> getValue( tree, createDefaultContext( root ), root, resultType );
}
/**
* Convenience method that combines calls to <code> parseExpression </code> and <code> getValue</code>.
*
* @see #parseExpression(String)
* @see #getValue(Object,Object)
* @param expression the OGNL expression to be parsed
* @param root the root object for the OGNL expression
* @return the result of evaluating the expression
* @throws ExpressionSyntaxException if the expression is malformed
* @throws MethodFailedException if the expression called a method which failed
* @throws NoSuchPropertyException if the expression referred to a nonexistent property
* @throws InappropriateExpressionException if the expression can't be used in this context
* @throws OgnlException if there is a pathological environmental problem
*/
public static <T> T getValue( String expression, Object root )
throws OgnlException
{
return Ognl.<T> getValue( expression, root, null );
}
/**
* Convenience method that combines calls to <code> parseExpression </code> and <code> getValue</code>.
*
* @see #parseExpression(String)
* @see #getValue(Object,Object)
* @param expression the OGNL expression to be parsed
* @param root the root object for the OGNL expression
* @param resultType the converted type of the resultant object, using the context's type converter
* @return the result of evaluating the expression
* @throws ExpressionSyntaxException if the expression is malformed
* @throws MethodFailedException if the expression called a method which failed
* @throws NoSuchPropertyException if the expression referred to a nonexistent property
* @throws InappropriateExpressionException if the expression can't be used in this context
* @throws OgnlException if there is a pathological environmental problem
*/
public static <T> T getValue( String expression, Object root, Class<T> resultType )
throws OgnlException
{
return Ognl.<T> getValue( parseExpression( expression ), root, resultType );
}
/**
* Evaluates the given OGNL expression tree to insert a value into the object graph rooted at the given root object.
* The default context is set for the given context and root via <code>addDefaultContext()</code>.
*
* @param tree the OGNL expression tree to evaluate, as returned by parseExpression()
* @param context the naming context for the evaluation
* @param root the root object for the OGNL expression
* @param value the value to insert into the object graph
* @throws MethodFailedException if the expression called a method which failed
* @throws NoSuchPropertyException if the expression referred to a nonexistent property
* @throws InappropriateExpressionException if the expression can't be used in this context
* @throws OgnlException if there is a pathological environmental problem
*/
public static void setValue( Object tree, Map<String, Object> context, Object root, Object value )
throws OgnlException
{
OgnlContext ognlContext = (OgnlContext) addDefaultContext( root, context );
Node n = (Node) tree;
if ( n.getAccessor() != null )
{
n.getAccessor().set( ognlContext, root, value );
return;
}
n.setValue( ognlContext, root, value );
}
/**
* Sets the value given using the pre-compiled expression on the specified root object.
*
* @param expression The pre-compiled expression, as found in {@link Node#getAccessor()}.
* @param context The ognl context.
* @param root The object to set the expression value on.
* @param value The value to set.
*/
public static void setValue( ExpressionAccessor expression, OgnlContext context, Object root, Object value )
{
expression.set( context, root, value );
}
/**
* Evaluates the given OGNL expression to insert a value into the object graph rooted at the given root object given
* the context.
*
* @param expression the OGNL expression to be parsed
* @param root the root object for the OGNL expression
* @param context the naming context for the evaluation
* @param value the value to insert into the object graph
* @throws MethodFailedException if the expression called a method which failed
* @throws NoSuchPropertyException if the expression referred to a nonexistent property
* @throws InappropriateExpressionException if the expression can't be used in this context
* @throws OgnlException if there is a pathological environmental problem
*/
public static void setValue( String expression, Map<String, Object> context, Object root, Object value )
throws OgnlException
{
setValue( parseExpression( expression ), context, root, value );
}
/**
* Evaluates the given OGNL expression tree to insert a value into the object graph rooted at the given root object.
*
* @param tree the OGNL expression tree to evaluate, as returned by parseExpression()
* @param root the root object for the OGNL expression
* @param value the value to insert into the object graph
* @throws MethodFailedException if the expression called a method which failed
* @throws NoSuchPropertyException if the expression referred to a nonexistent property
* @throws InappropriateExpressionException if the expression can't be used in this context
* @throws OgnlException if there is a pathological environmental problem
*/
public static void setValue( Object tree, Object root, Object value )
throws OgnlException
{
setValue( tree, createDefaultContext( root ), root, value );
}
/**
* Convenience method that combines calls to <code> parseExpression </code> and <code> setValue</code>.
*
* @see #parseExpression(String)
* @see #setValue(Object,Object,Object)
* @param expression the OGNL expression to be parsed
* @param root the root object for the OGNL expression
* @param value the value to insert into the object graph
* @throws ExpressionSyntaxException if the expression is malformed
* @throws MethodFailedException if the expression called a method which failed
* @throws NoSuchPropertyException if the expression referred to a nonexistent property
* @throws InappropriateExpressionException if the expression can't be used in this context
* @throws OgnlException if there is a pathological environmental problem
*/
public static void setValue( String expression, Object root, Object value )
throws OgnlException
{
setValue( parseExpression( expression ), root, value );
}
/**
* Checks if the specified {@link Node} instance represents a constant expression.
*
* @param tree The {@link Node} to check.
* @param context The context to use.
* @return True if the node is a constant - false otherwise.
* @throws OgnlException If an error occurs checking the expression.
*/
public static boolean isConstant( Object tree, Map<String, Object> context )
throws OgnlException
{
return ( (SimpleNode) tree ).isConstant( (OgnlContext) addDefaultContext( null, context ) );
}
/**
* Checks if the specified expression represents a constant expression.
*
* @param expression The expression to check.
* @param context The context to use.
* @return True if the node is a constant - false otherwise.
* @throws OgnlException If an error occurs checking the expression.
*/
public static boolean isConstant( String expression, Map<String, Object> context )
throws OgnlException
{
return isConstant( parseExpression( expression ), context );
}
/**
* Same as {@link #isConstant(Object, java.util.Map)} - only the {@link Map} context is created for you.
*
* @param tree The {@link Node} to check.
* @return True if the node represents a constant expression - false otherwise.
* @throws OgnlException If an exception occurs.
*/
public static boolean isConstant( Object tree )
throws OgnlException
{
return isConstant( tree, createDefaultContext( null ) );
}
/**
* Same as {@link #isConstant(String, java.util.Map)} - only the {@link Map} instance is created for you.
*
* @param expression The expression to check.
* @return True if the expression represents a constant - false otherwise.
* @throws OgnlException If an exception occurs.
*/
public static boolean isConstant( String expression )
throws OgnlException
{
return isConstant( parseExpression( expression ), createDefaultContext( null ) );
}
public static boolean isSimpleProperty( Object tree, Map<String, Object> context )
throws OgnlException
{
return ( (SimpleNode) tree ).isSimpleProperty( (OgnlContext) addDefaultContext( null, context ) );
}
public static boolean isSimpleProperty( String expression, Map<String, Object> context )
throws OgnlException
{
return isSimpleProperty( parseExpression( expression ), context );
}
public static boolean isSimpleProperty( Object tree )
throws OgnlException
{
return isSimpleProperty( tree, createDefaultContext( null ) );
}
public static boolean isSimpleProperty( String expression )
throws OgnlException
{
return isSimpleProperty( parseExpression( expression ), createDefaultContext( null ) );
}
public static boolean isSimpleNavigationChain( Object tree, Map<String, Object> context )
throws OgnlException
{
return ( (SimpleNode) tree ).isSimpleNavigationChain( (OgnlContext) addDefaultContext( null, context ) );
}
public static boolean isSimpleNavigationChain( String expression, Map<String, Object> context )
throws OgnlException
{
return isSimpleNavigationChain( parseExpression( expression ), context );
}
public static boolean isSimpleNavigationChain( Object tree )
throws OgnlException
{
return isSimpleNavigationChain( tree, createDefaultContext( null ) );
}
public static boolean isSimpleNavigationChain( String expression )
throws OgnlException
{
return isSimpleNavigationChain( parseExpression( expression ), createDefaultContext( null ) );
}
/** You can't make one of these. */
private Ognl()
{
}
}
| 4,587 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/MethodFailedException.java | package org.apache.commons.ognl;
/*
* 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.
*/
import static java.lang.String.format;
/**
* Exception thrown if a method or constructor call fails.
*/
public class MethodFailedException
extends OgnlException
{
private static final long serialVersionUID = -8537354635249153386L;
public MethodFailedException( Object source, String name )
{
super( format( "Method \"%s\" failed for object %s", name, source ) );
}
public MethodFailedException( Object source, String name, Throwable reason )
{
super( format( "Method \"%s\" failed for object %s", name, source ), reason );
}
}
| 4,588 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTGreaterEq.java | package org.apache.commons.ognl;
/*
* 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.
*/
/**
*/
class ASTGreaterEq
extends ComparisonExpression
{
public ASTGreaterEq( int id )
{
super( id );
}
public ASTGreaterEq( OgnlParser p, int id )
{
super( p, id );
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
Object v1 = children[0].getValue( context, source );
Object v2 = children[1].getValue( context, source );
return OgnlOps.less( v1, v2 ) ? Boolean.FALSE : Boolean.TRUE;
}
public String getExpressionOperator( int index )
{
return ">=";
}
public String getComparisonFunction()
{
return "!org.apache.commons.ognl.OgnlOps.less";
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,589 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ClassCacheInspector.java | package org.apache.commons.ognl;
/*
* 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.
*/
/**
* Optional interface that may be registered with {@link OgnlRuntime#setClassCacheInspector(ClassCacheInspector)} as a
* means to disallow caching of specific class types.
*/
public interface ClassCacheInspector
{
/**
* Invoked just before storing a class type within a cache instance.
*
* @param type The class that is to be stored.
* @return True if the class can be cached, false otherwise.
*/
boolean shouldCache( Class<?> type );
}
| 4,590 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ArrayElementsAccessor.java | package org.apache.commons.ognl;
/*
* 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.
*/
import java.lang.reflect.Array;
import java.util.Enumeration;
/**
* Implementation of ElementsAccessor that returns an iterator over a Java array.
*/
public class ArrayElementsAccessor
implements ElementsAccessor
{
/**
* {@inheritDoc}
*/
public Enumeration<?> getElements( final Object target )
{
return new Enumeration<Object>()
{
private final int count = Array.getLength( target );
private int index;
public boolean hasMoreElements()
{
return index < count;
}
public Object nextElement()
{
return Array.get( target, index++ );
}
};
}
}
| 4,591 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTBitOr.java | package org.apache.commons.ognl;
/*
* 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.
*/
/**
*/
class ASTBitOr
extends NumericExpression
{
public ASTBitOr( int id )
{
super( id );
}
public ASTBitOr( OgnlParser p, int id )
{
super( p, id );
}
public void jjtClose()
{
flattenTree();
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
Object result = children[0].getValue( context, source );
for ( int i = 1; i < children.length; ++i )
{
result = OgnlOps.binaryOr( result, children[i].getValue( context, source ) );
}
return result;
}
public String getExpressionOperator( int index )
{
return "|";
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,592 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/NumberElementsAccessor.java | package org.apache.commons.ognl;
/*
* 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.
*/
import java.util.Enumeration;
import java.util.NoSuchElementException;
/**
* Implementation of ElementsAccessor that returns an iterator over integers from 0 up to the given target.
*/
public class NumberElementsAccessor
implements ElementsAccessor, NumericTypes
{
/**
* {@inheritDoc}
*/
public Enumeration<?> getElements( final Object target )
{
return new Enumeration<Object>()
{
private final int type = OgnlOps.getNumericType( target );
private long next;
private final long finish = OgnlOps.longValue( target );
public boolean hasMoreElements()
{
return next < finish;
}
public Object nextElement()
{
if ( next >= finish )
{
throw new NoSuchElementException();
}
return OgnlOps.newInteger( type, next++ );
}
};
}
}
| 4,593 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/OgnlOps.java | package org.apache.commons.ognl;
/*
* 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.
*/
import org.apache.commons.ognl.enhance.UnsupportedCompilationException;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Enumeration;
/**
* This is an abstract class with static methods that define the operations of OGNL.
*/
public abstract class OgnlOps
implements NumericTypes
{
/**
* Compares two objects for equality, even if it has to convert one of them to the other type. If both objects are
* numeric they are converted to the widest type and compared. If one is non-numeric and one is numeric the
* non-numeric is converted to double and compared to the double numeric value. If both are non-numeric and
* Comparable and the types are compatible (i.e. v1 is of the same or superclass of v2's type) they are compared
* with Comparable.compareTo(). If both values are non-numeric and not Comparable or of incompatible classes this
* will throw and IllegalArgumentException.
*
* @param v1 First value to compare
* @param v2 second value to compare
* @return integer describing the comparison between the two objects. A negative number indicates that v1 < v2.
* Positive indicates that v1 > v2. Zero indicates v1 == v2.
* @throws IllegalArgumentException if the objects are both non-numeric yet of incompatible types or do not
* implement Comparable.
*/
public static int compareWithConversion( Object v1, Object v2 )
{
int result;
if ( v1 == v2 )
{
result = 0;
}
else
{
int t1 = getNumericType( v1 ), t2 = getNumericType( v2 ), type = getNumericType( t1, t2, true );
switch ( type )
{
case BIGINT:
result = bigIntValue( v1 ).compareTo( bigIntValue( v2 ) );
break;
case BIGDEC:
result = bigDecValue( v1 ).compareTo( bigDecValue( v2 ) );
break;
case NONNUMERIC:
if ( ( t1 == NONNUMERIC ) && ( t2 == NONNUMERIC ) )
{
if ( ( v1 instanceof Comparable ) && v1.getClass().isAssignableFrom( v2.getClass() ) )
{
result = ( (Comparable) v1 ).compareTo( v2 );
break;
}
throw new IllegalArgumentException( "invalid comparison: " + v1.getClass().getName()
+ " and " + v2.getClass().getName() );
}
// else fall through
case FLOAT:
case DOUBLE:
double dv1 = doubleValue( v1 ),
dv2 = doubleValue( v2 );
return Double.compare(dv1, dv2);
default:
long lv1 = longValue( v1 ),
lv2 = longValue( v2 );
return Long.compare(lv1, lv2);
}
}
return result;
}
/**
* Returns true if object1 is equal to object2 in either the sense that they are the same object or, if both are
* non-null if they are equal in the <CODE>equals()</CODE> sense.
*
* @param object1 First object to compare
* @param object2 Second object to compare
* @return true if v1 == v2
*/
public static boolean isEqual( Object object1, Object object2 )
{
boolean result = false;
if ( object1 == object2 )
{
result = true;
}
else
{
if ( ( object1 != null ) && object1.getClass().isArray() )
{
if ( ( object2 != null ) && object2.getClass().isArray() && ( object2.getClass()
== object1.getClass() ) )
{
result = ( Array.getLength( object1 ) == Array.getLength( object2 ) );
if ( result )
{
for ( int i = 0, icount = Array.getLength( object1 ); result && ( i < icount ); i++ )
{
result = isEqual( Array.get( object1, i ), Array.get( object2, i ) );
}
}
}
}
else
{
// Check for converted equivalence first, then equals() equivalence
result =
( object1 != null ) && ( object2 != null )
&& ( object1.equals( object2 ) || ( compareWithConversion( object1, object2 ) == 0 ) );
}
}
return result;
}
public static boolean booleanValue( boolean value )
{
return value;
}
public static boolean booleanValue( int value )
{
return value > 0;
}
public static boolean booleanValue( float value )
{
return value > 0;
}
public static boolean booleanValue( long value )
{
return value > 0;
}
public static boolean booleanValue( double value )
{
return value > 0;
}
/**
* Evaluates the given object as a boolean: if it is a Boolean object, it's easy; if it's a Number or a Character,
* returns true for non-zero objects; and otherwise returns true for non-null objects.
*
* @param value an object to interpret as a boolean
* @return the boolean value implied by the given object
*/
public static boolean booleanValue( Object value )
{
if ( value == null )
{
return false;
}
Class<?> c = value.getClass();
if ( c == Boolean.class )
{
return (Boolean) value;
}
// if ( c == String.class )
// return ((String)value).length() > 0;
if ( c == Character.class )
{
return (Character) value != 0;
}
return !( value instanceof Number ) || ( (Number) value ).doubleValue() != 0;
}
/**
* Evaluates the given object as a long integer.
*
* @param value an object to interpret as a long integer
* @return the long integer value implied by the given object
* @throws NumberFormatException if the given object can't be understood as a long integer
*/
public static long longValue( Object value )
{
if ( value == null )
{
return 0L;
}
Class<?> c = value.getClass();
if ( c.getSuperclass() == Number.class )
{
return ( (Number) value ).longValue();
}
if ( c == Boolean.class )
{
return (Boolean) value ? 1 : 0;
}
if ( c == Character.class )
{
return (Character) value;
}
return Long.parseLong( stringValue( value, true ) );
}
/**
* Evaluates the given object as a double-precision floating-point number.
*
* @param value an object to interpret as a double
* @return the double value implied by the given object
* @throws NumberFormatException if the given object can't be understood as a double
*/
public static double doubleValue( Object value )
{
if ( value == null )
{
return 0.0;
}
Class<?> c = value.getClass();
if ( c.getSuperclass() == Number.class )
{
return ( (Number) value ).doubleValue();
}
if ( c == Boolean.class )
{
return (Boolean) value ? 1 : 0;
}
if ( c == Character.class )
{
return (Character) value;
}
String s = stringValue( value, true );
return ( s.isEmpty() ) ? 0.0 : Double.parseDouble( s );
}
/**
* Evaluates the given object as a BigInteger.
*
* @param value an object to interpret as a BigInteger
* @return the BigInteger value implied by the given object
* @throws NumberFormatException if the given object can't be understood as a BigInteger
*/
public static BigInteger bigIntValue( Object value )
{
if ( value == null )
{
return BigInteger.valueOf( 0L );
}
Class<?> c = value.getClass();
if ( c == BigInteger.class )
{
return (BigInteger) value;
}
if ( c == BigDecimal.class )
{
return ( (BigDecimal) value ).toBigInteger();
}
if ( c.getSuperclass() == Number.class )
{
return BigInteger.valueOf( ( (Number) value ).longValue() );
}
if ( c == Boolean.class )
{
return BigInteger.valueOf( (Boolean) value ? 1 : 0 );
}
if ( c == Character.class )
{
return BigInteger.valueOf( (Character) value );
}
return new BigInteger( stringValue( value, true ) );
}
/**
* Evaluates the given object as a BigDecimal.
*
* @param value an object to interpret as a BigDecimal
* @return the BigDecimal value implied by the given object
* @throws NumberFormatException if the given object can't be understood as a BigDecimal
*/
public static BigDecimal bigDecValue( Object value )
{
if ( value == null )
{
return BigDecimal.valueOf( 0L );
}
Class<?> c = value.getClass();
if ( c == BigDecimal.class )
{
return (BigDecimal) value;
}
if ( c == BigInteger.class )
{
return new BigDecimal( (BigInteger) value );
}
if ( c == Boolean.class )
{
return BigDecimal.valueOf( (Boolean) value ? 1 : 0 );
}
if ( c == Character.class )
{
return BigDecimal.valueOf( ( (Character) value ).charValue() );
}
return new BigDecimal( stringValue( value, true ) );
}
/**
* Evaluates the given object as a String and trims it if the trim flag is true.
*
* @param value an object to interpret as a String
* @param trim if true trims the result
* @return the String value implied by the given object as returned by the toString() method, or "null" if the
* object is null.
*/
public static String stringValue( Object value, boolean trim )
{
String result;
if ( value == null )
{
result = OgnlRuntime.NULL_STRING;
}
else
{
result = value.toString();
if ( trim )
{
result = result.trim();
}
}
return result;
}
/**
* Evaluates the given object as a String.
*
* @param value an object to interpret as a String
* @return the String value implied by the given object as returned by the toString() method, or "null" if the
* object is null.
*/
public static String stringValue( Object value )
{
return stringValue( value, false );
}
/**
* Returns a constant from the NumericTypes interface that represents the numeric type of the given object.
*
* @param value an object that needs to be interpreted as a number
* @return the appropriate constant from the NumericTypes interface
*/
public static int getNumericType( Object value )
{
if ( value != null )
{
Class<?> c = value.getClass();
if ( c == Integer.class )
{
return INT;
}
if ( c == Double.class )
{
return DOUBLE;
}
if ( c == Boolean.class )
{
return BOOL;
}
if ( c == Byte.class )
{
return BYTE;
}
if ( c == Character.class )
{
return CHAR;
}
if ( c == Short.class )
{
return SHORT;
}
if ( c == Long.class )
{
return LONG;
}
if ( c == Float.class )
{
return FLOAT;
}
if ( c == BigInteger.class )
{
return BIGINT;
}
if ( c == BigDecimal.class )
{
return BIGDEC;
}
}
return NONNUMERIC;
}
public static Object toArray( char value, Class<?> toType )
throws OgnlException
{
return toArray( Character.valueOf( value ), toType );
}
public static Object toArray( byte value, Class<?> toType )
throws OgnlException
{
return toArray( Byte.valueOf( value ), toType );
}
public static Object toArray( int value, Class<?> toType )
throws OgnlException
{
return toArray( Integer.valueOf( value ), toType );
}
public static Object toArray( long value, Class<?> toType )
throws OgnlException
{
return toArray( Long.valueOf( value ), toType );
}
public static Object toArray( float value, Class<?> toType )
throws OgnlException
{
return toArray( Float.valueOf( value ), toType );
}
public static Object toArray( double value, Class<?> toType )
throws OgnlException
{
return toArray( Double.valueOf( value ), toType );
}
public static Object toArray( boolean value, Class<?> toType )
throws OgnlException
{
return toArray( Boolean.valueOf( value ), toType );
}
public static <T> Object convertValue( char value, Class<T> toType )
throws OgnlException
{
return convertValue( Character.valueOf(value), toType );
}
public static <T> Object convertValue( byte value, Class<T> toType )
throws OgnlException
{
return convertValue( Byte.valueOf( value ), toType );
}
public static <T> Object convertValue( int value, Class<T> toType )
throws OgnlException
{
return convertValue( Integer.valueOf( value ), toType );
}
public static <T> Object convertValue( long value, Class<T> toType )
throws OgnlException
{
return convertValue( Long.valueOf( value ), toType );
}
public static <T> Object convertValue( float value, Class<T> toType )
throws OgnlException
{
return convertValue( Float.valueOf( value ), toType );
}
public static <T> Object convertValue( double value, Class<T> toType )
throws OgnlException
{
return convertValue( Double.valueOf( value ), toType );
}
public static <T> Object convertValue( boolean value, Class<T> toType )
throws OgnlException
{
return convertValue( Boolean.valueOf( value ), toType );
}
// //////////////////////////////////////////////////////////////
public static <T> Object convertValue( char value, Class<T> toType, boolean preventNull )
throws OgnlException
{
return convertValue( Character.valueOf( value ), toType, preventNull );
}
public static <T> Object convertValue( byte value, Class<T> toType, boolean preventNull )
throws OgnlException
{
return convertValue( Byte.valueOf( value ), toType, preventNull );
}
public static <T> Object convertValue( int value, Class<T> toType, boolean preventNull )
throws OgnlException
{
return convertValue( Integer.valueOf( value ), toType, preventNull );
}
public static <T> Object convertValue( long value, Class<T> toType, boolean preventNull )
throws OgnlException
{
return convertValue( Long.valueOf( value ), toType, preventNull );
}
public static <T> Object convertValue( float value, Class<T> toType, boolean preventNull )
throws OgnlException
{
return convertValue( new Float( value ), toType, preventNull );
}
public static <T> Object convertValue( double value, Class<T> toType, boolean preventNull )
throws OgnlException
{
return convertValue( new Double( value ), toType, preventNull );
}
public static <T> Object convertValue( boolean value, Class<T> toType, boolean preventNull )
throws OgnlException
{
return convertValue( Boolean.valueOf( value ), toType, preventNull );
}
// ///////////////////////////////////////////////////////////////
public static Object toArray( char value, Class<?> toType, boolean preventNull )
throws OgnlException
{
return toArray( Character.valueOf( value ), toType, preventNull );
}
public static Object toArray( byte value, Class<?> toType, boolean preventNull )
throws OgnlException
{
return toArray( Byte.valueOf( value ), toType, preventNull );
}
public static Object toArray( int value, Class<?> toType, boolean preventNull )
throws OgnlException
{
return toArray( Integer.valueOf( value ), toType, preventNull );
}
public static Object toArray( long value, Class<?> toType, boolean preventNull )
throws OgnlException
{
return toArray( Long.valueOf(value), toType, preventNull );
}
public static Object toArray( float value, Class<?> toType, boolean preventNull )
throws OgnlException
{
return toArray( Float.valueOf( value ), toType, preventNull );
}
public static Object toArray( double value, Class<?> toType, boolean preventNull )
throws OgnlException
{
return toArray( Double.valueOf(value), toType, preventNull );
}
public static Object toArray( boolean value, Class<?> toType, boolean preventNull )
throws OgnlException
{
return toArray( Boolean.valueOf( value ), toType, preventNull );
}
/**
* Returns the value converted numerically to the given class type This method also detects when arrays are being
* converted and converts the components of one array to the type of the other.
*
* @param value an object to be converted to the given type
* @param toType class type to be converted to
* @return converted value of the type given, or value if the value cannot be converted to the given type.
*/
public static Object convertValue( Object value, Class<?> toType )
{
return convertValue( value, toType, false );
}
public static Object toArray( Object value, Class<?> toType )
throws OgnlException
{
return toArray( value, toType, false );
}
public static Object toArray( Object value, Class<?> toType, boolean preventNulls )
throws OgnlException
{
if ( value == null )
{
return null;
}
Object result;
Class<?> aClass = value.getClass();
if ( aClass.isArray() && toType.isAssignableFrom( aClass.getComponentType() ) )
{
return value;
}
if ( !aClass.isArray() )
{
if ( toType == Character.TYPE )
{
return stringValue( value ).toCharArray();
}
Object arr = Array.newInstance( toType, 1 );
Array.set( arr, 0, convertValue( value, toType, preventNulls ) );
return arr;
}
result = Array.newInstance( toType, Array.getLength( value ) );
for ( int i = 0, icount = Array.getLength( value ); i < icount; i++ )
{
Array.set( result, i, convertValue( Array.get( value, i ), toType ) );
}
if ( result == null && preventNulls )
{
return value;
}
return result;
}
public static <T> Object convertValue( Object value, Class<T> toType, boolean preventNulls )
{
Object result = null;
if ( value != null && toType.isAssignableFrom( value.getClass() ) )
{
return value;
}
if ( value != null )
{
/* If array -> array then convert components of array individually */
boolean classIsArray = value.getClass().isArray();
boolean toTypeIsArray = toType.isArray();
if ( classIsArray && toTypeIsArray)
{
Class<?> componentType = toType.getComponentType();
result = Array.newInstance( componentType, Array.getLength( value ) );
for ( int i = 0, icount = Array.getLength( value ); i < icount; i++ )
{
Array.set( result, i, convertValue( Array.get( value, i ), componentType ) );
}
}
else if ( classIsArray && !toTypeIsArray)
{
return convertValue( Array.get( value, 0 ), toType );
}
else if ( toTypeIsArray )
{
if ( toType.getComponentType() == Character.TYPE )
{
result = stringValue( value ).toCharArray();
}
else if ( toType.getComponentType() == Object.class )
{
return new Object[] { value };
}
}
else
{
if ( ( toType == Integer.class ) || ( toType == Integer.TYPE ) )
{
result = (int) longValue( value );
}
else if ( ( toType == Double.class ) || ( toType == Double.TYPE ) )
{
result = doubleValue( value );
}
else if ( ( toType == Boolean.class ) || ( toType == Boolean.TYPE ) )
{
result = booleanValue( value ) ? Boolean.TRUE : Boolean.FALSE;
}
else if ( ( toType == Byte.class ) || ( toType == Byte.TYPE ) )
{
result = (byte) longValue( value );
}
else if ( ( toType == Character.class ) || ( toType == Character.TYPE ) )
{
result = (char) longValue( value );
}
else if ( ( toType == Short.class ) || ( toType == Short.TYPE ) )
{
result = (short) longValue( value );
}
else if ( ( toType == Long.class ) || ( toType == Long.TYPE ) )
{
result = longValue( value );
}
else if ( ( toType == Float.class ) || ( toType == Float.TYPE ) )
{
result = new Float( doubleValue( value ) );
}
else if ( toType == BigInteger.class )
{
result = bigIntValue( value );
}
else if ( toType == BigDecimal.class )
{
result = bigDecValue( value );
}
else if ( toType == String.class )
{
result = stringValue( value );
}
}
}
else
{
if ( toType.isPrimitive() )
{
result = OgnlRuntime.getPrimitiveDefaultValue( toType );
}
else if ( preventNulls && toType == Boolean.class )
{
result = Boolean.FALSE;
}
else if ( preventNulls && Number.class.isAssignableFrom( toType ) )
{
result = OgnlRuntime.getNumericDefaultValue( toType );
}
}
if ( result == null && preventNulls )
{
return value;
}
if ( value != null && result == null )
{
throw new IllegalArgumentException( "Unable to convert type " + value.getClass().getName() + " of " + value
+ " to type of " + toType.getName() );
}
return result;
}
/**
* Converts the specified value to a primitive integer value.
* <ul>
* <li>Null values will cause a -1 to be returned.</li>
* <li>{@link Number} instances have their intValue() methods invoked.</li>
* <li>All other types result in calling Integer.parseInt(value.toString());</li>
* </ul>
*
* @param value The object to get the value of.
* @return A valid integer.
*/
public static int getIntValue( Object value )
{
try
{
if ( value == null )
{
return -1;
}
if (value instanceof Number)
{
return ( (Number) value ).intValue();
}
String str = value instanceof String ? (String) value : value.toString();
return Integer.parseInt( str );
}
catch ( Throwable t )
{
throw new IllegalArgumentException( "Error converting " + value + " to integer:", t );
}
}
/**
* Returns the constant from the NumericTypes interface that best expresses the type of a numeric operation on the
* two given objects.
*
* @param v1 one argument to a numeric operator
* @param v2 the other argument
* @return the appropriate constant from the NumericTypes interface
*/
public static int getNumericType( Object v1, Object v2 )
{
return getNumericType( v1, v2, false );
}
/**
* Returns the constant from the NumericTypes interface that best expresses the type of an operation, which can be
* either numeric or not, on the two given types.
*
* @param t1 type of one argument to an operator
* @param t2 type of the other argument
* @param canBeNonNumeric whether the operator can be interpreted as non-numeric
* @return the appropriate constant from the NumericTypes interface
*/
public static int getNumericType( int t1, int t2, boolean canBeNonNumeric )
{
if ( t1 == t2 )
{
return t1;
}
if ( canBeNonNumeric && ( t1 == NONNUMERIC || t2 == NONNUMERIC || t1 == CHAR || t2 == CHAR ) )
{
return NONNUMERIC;
}
if ( t1 == NONNUMERIC )
{
t1 = DOUBLE; // Try to interpret strings as doubles...
}
if ( t2 == NONNUMERIC )
{
t2 = DOUBLE; // Try to interpret strings as doubles...
}
if ( t1 >= MIN_REAL_TYPE )
{
if ( t2 >= MIN_REAL_TYPE )
{
return Math.max( t1, t2 );
}
if ( t2 < INT )
{
return t1;
}
if ( t2 == BIGINT )
{
return BIGDEC;
}
return Math.max( DOUBLE, t1 );
}
if ( t2 < MIN_REAL_TYPE ) {
return Math.max( t1, t2 );
}
if ( t1 < INT )
{
return t2;
}
if ( t1 == BIGINT )
{
return BIGDEC;
}
return Math.max( DOUBLE, t2 );
}
/**
* Returns the constant from the NumericTypes interface that best expresses the type of an operation, which can be
* either numeric or not, on the two given objects.
*
* @param v1 one argument to an operator
* @param v2 the other argument
* @param canBeNonNumeric whether the operator can be interpreted as non-numeric
* @return the appropriate constant from the NumericTypes interface
*/
public static int getNumericType( Object v1, Object v2, boolean canBeNonNumeric )
{
return getNumericType( getNumericType( v1 ), getNumericType( v2 ), canBeNonNumeric );
}
/**
* Returns a new Number object of an appropriate type to hold the given integer value. The type of the returned
* object is consistent with the given type argument, which is a constant from the NumericTypes interface.
*
* @param type the nominal numeric type of the result, a constant from the NumericTypes interface
* @param value the integer value to convert to a Number object
* @return a Number object with the given value, of type implied by the type argument
*/
public static Number newInteger( int type, long value )
{
switch ( type )
{
case BOOL:
case CHAR:
case INT:
return (int) value;
case FLOAT:
if ( (long) (float) value == value )
{
return (float) value;
}
// else fall through:
case DOUBLE:
if ( (long) (double) value == value )
{
return (double) value;
}
// else fall through:
case LONG:
return value;
case BYTE:
return (byte) value;
case SHORT:
return (short) value;
default:
return BigInteger.valueOf( value );
}
}
/**
* Returns a new Number object of an appropriate type to hold the given real value. The type of the returned object
* is always either Float or Double, and is only Float if the given type tag (a constant from the NumericTypes
* interface) is FLOAT.
*
* @param type the nominal numeric type of the result, a constant from the NumericTypes interface
* @param value the real value to convert to a Number object
* @return a Number object with the given value, of type implied by the type argument
*/
public static Number newReal( int type, double value )
{
if ( type == FLOAT )
{
return (float) value;
}
return value;
}
public static Object binaryOr( Object v1, Object v2 )
{
int type = getNumericType( v1, v2 );
if ( type == BIGINT || type == BIGDEC )
{
return bigIntValue( v1 ).or( bigIntValue( v2 ) );
}
return newInteger( type, longValue( v1 ) | longValue( v2 ) );
}
public static Object binaryXor( Object v1, Object v2 )
{
int type = getNumericType( v1, v2 );
if ( type == BIGINT || type == BIGDEC )
{
return bigIntValue( v1 ).xor( bigIntValue( v2 ) );
}
return newInteger( type, longValue( v1 ) ^ longValue( v2 ) );
}
public static Object binaryAnd( Object v1, Object v2 )
{
int type = getNumericType( v1, v2 );
if ( type == BIGINT || type == BIGDEC )
{
return bigIntValue( v1 ).and( bigIntValue( v2 ) );
}
return newInteger( type, longValue( v1 ) & longValue( v2 ) );
}
public static boolean equal( Object v1, Object v2 )
{
if ( v1 == null )
{
return v2 == null;
}
if ( v1 == v2 || isEqual( v1, v2 ) )
{
return true;
}
if ( v1 instanceof Number && v2 instanceof Number )
{
return ( (Number) v1 ).doubleValue() == ( (Number) v2 ).doubleValue();
}
return false;
}
public static boolean less( Object v1, Object v2 )
{
return compareWithConversion( v1, v2 ) < 0;
}
public static boolean greater( Object v1, Object v2 )
{
return compareWithConversion( v1, v2 ) > 0;
}
public static boolean in( Object v1, Object v2 )
throws OgnlException
{
if ( v2 == null ) // A null collection is always treated as empty
{
return false;
}
ElementsAccessor elementsAccessor = OgnlRuntime.getElementsAccessor( OgnlRuntime.getTargetClass( v2 ) );
// FIXME O(n) is there a better way?!
for ( Enumeration<?> e = elementsAccessor.getElements( v2 ); e.hasMoreElements(); )
{
Object o = e.nextElement();
if ( equal( v1, o ) )
{
return true;
}
}
return false;
}
public static Object shiftLeft( Object v1, Object v2 )
{
int type = getNumericType( v1 );
if ( type == BIGINT || type == BIGDEC )
{
return bigIntValue( v1 ).shiftLeft( (int) longValue( v2 ) );
}
return newInteger( type, longValue( v1 ) << (int) longValue( v2 ) );
}
public static Object shiftRight( Object v1, Object v2 )
{
int type = getNumericType( v1 );
if ( type == BIGINT || type == BIGDEC )
{
return bigIntValue( v1 ).shiftRight( (int) longValue( v2 ) );
}
return newInteger( type, longValue( v1 ) >> (int) longValue( v2 ) );
}
public static Object unsignedShiftRight( Object v1, Object v2 )
{
int type = getNumericType( v1 );
if ( type == BIGINT || type == BIGDEC )
{
return bigIntValue( v1 ).shiftRight( (int) longValue( v2 ) );
}
if ( type <= INT )
{
return newInteger( INT, ( (int) longValue( v1 ) ) >>> (int) longValue( v2 ) );
}
return newInteger( type, longValue( v1 ) >>> (int) longValue( v2 ) );
}
public static Object add( Object v1, Object v2 )
{
int type = getNumericType( v1, v2, true );
switch ( type )
{
case BIGINT:
return bigIntValue( v1 ).add( bigIntValue( v2 ) );
case BIGDEC:
return bigDecValue( v1 ).add( bigDecValue( v2 ) );
case FLOAT:
case DOUBLE:
return newReal( type, doubleValue( v1 ) + doubleValue( v2 ) );
case NONNUMERIC:
int t1 = getNumericType( v1 ),
t2 = getNumericType( v2 );
if ( ( ( t1 != NONNUMERIC ) && ( v2 == null ) ) || ( ( t2 != NONNUMERIC ) && ( v1 == null ) ) )
{
throw new NullPointerException( "Can't add values " + v1 + " , " + v2 );
}
return stringValue( v1 ) + stringValue( v2 );
default:
return newInteger( type, longValue( v1 ) + longValue( v2 ) );
}
}
public static Object subtract( Object v1, Object v2 )
{
int type = getNumericType( v1, v2 );
switch ( type )
{
case BIGINT:
return bigIntValue( v1 ).subtract( bigIntValue( v2 ) );
case BIGDEC:
return bigDecValue( v1 ).subtract( bigDecValue( v2 ) );
case FLOAT:
case DOUBLE:
return newReal( type, doubleValue( v1 ) - doubleValue( v2 ) );
default:
return newInteger( type, longValue( v1 ) - longValue( v2 ) );
}
}
public static Object multiply( Object v1, Object v2 )
{
int type = getNumericType( v1, v2 );
switch ( type )
{
case BIGINT:
return bigIntValue( v1 ).multiply( bigIntValue( v2 ) );
case BIGDEC:
return bigDecValue( v1 ).multiply( bigDecValue( v2 ) );
case FLOAT:
case DOUBLE:
return newReal( type, doubleValue( v1 ) * doubleValue( v2 ) );
default:
return newInteger( type, longValue( v1 ) * longValue( v2 ) );
}
}
public static Object divide( Object v1, Object v2 )
{
int type = getNumericType( v1, v2 );
switch ( type )
{
case BIGINT:
return bigIntValue( v1 ).divide( bigIntValue( v2 ) );
case BIGDEC:
return bigDecValue( v1 ).divide( bigDecValue( v2 ), BigDecimal.ROUND_HALF_EVEN );
case FLOAT:
case DOUBLE:
return newReal( type, doubleValue( v1 ) / doubleValue( v2 ) );
default:
return newInteger( type, longValue( v1 ) / longValue( v2 ) );
}
}
public static Object remainder( Object v1, Object v2 )
{
int type = getNumericType( v1, v2 );
switch ( type )
{
case BIGDEC:
case BIGINT:
return bigIntValue( v1 ).remainder( bigIntValue( v2 ) );
default:
return newInteger( type, longValue( v1 ) % longValue( v2 ) );
}
}
public static Object negate( Object value )
{
int type = getNumericType( value );
switch ( type )
{
case BIGINT:
return bigIntValue( value ).negate();
case BIGDEC:
return bigDecValue( value ).negate();
case FLOAT:
case DOUBLE:
return newReal( type, -doubleValue( value ) );
default:
return newInteger( type, -longValue( value ) );
}
}
public static Object bitNegate( Object value )
{
int type = getNumericType( value );
switch ( type )
{
case BIGDEC:
case BIGINT:
return bigIntValue( value ).not();
default:
return newInteger( type, ~longValue( value ) );
}
}
public static String getEscapeString( String value )
{
StringBuilder result = new StringBuilder();
int length = value.length();
for ( int i = 0; i < length; i++ )
{
result.append( getEscapedChar( value.charAt( i ) ) );
}
return result.toString();
}
public static String getEscapedChar( char ch )
{
String result;
switch ( ch )
{
case '\b':
result = "\b";
break;
case '\t':
result = "\\t";
break;
case '\n':
result = "\\n";
break;
case '\f':
result = "\\f";
break;
case '\r':
result = "\\r";
break;
case '\"':
result = "\\\"";
break;
case '\'':
result = "\\\'";
break;
case '\\':
result = "\\\\";
break;
default:
if ( Character.isISOControl( ch ) )
{
String hc = Integer.toString( (int) ch, 16 );
int hcl = hc.length();
result = "\\u";
if ( hcl < 4 )
{
if ( hcl == 3 )
{
result = result + "0";
}
else
{
if ( hcl == 2 )
{
result = result + "00";
}
else
{
result = result + "000";
}
}
}
result = result + hc;
}
else
{
result = ch + "";
}
break;
}
return result;
}
public static Object returnValue( Object ignore, Object returnValue )
{
return returnValue;
}
/**
* Utility method that converts incoming exceptions to {@link RuntimeException} instances - or casts them if they
* already are.
*
* @param t The exception to cast.
* @return The exception cast to a {@link RuntimeException}.
*/
public static RuntimeException castToRuntime( Throwable t )
{
if (t instanceof RuntimeException)
{
return (RuntimeException) t;
}
if (t instanceof OgnlException)
{
throw new UnsupportedCompilationException( "Error evluating expression: " + t.getMessage(), t );
}
return new RuntimeException( t );
}
}
| 4,594 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/TypeConverter.java | package org.apache.commons.ognl;
/*
* 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.
*/
import java.lang.reflect.Member;
import java.util.Map;
/**
* Interface for accessing the type conversion facilities within a context.
*/
public interface TypeConverter
{
/**
* Converts the given value to a given type. The OGNL context, target, member and name of property being set are
* given. This method should be able to handle conversion in general without any context, target, member or property
* name specified.
*
* @param context OGNL context under which the conversion is being done
* @param target target object in which the property is being set
* @param member member (Constructor, Method or Field) being set
* @param propertyName property name being set
* @param value value to be converted
* @param toType type to which value is converted
* @return Converted value of type toType or TypeConverter.NoConversionPossible to indicate that the conversion was
* not possible.
*/
<T> T convertValue( Map<String, Object> context, Object target, Member member, String propertyName, Object value,
Class<T> toType );
}
| 4,595 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/MapElementsAccessor.java | package org.apache.commons.ognl;
/*
* 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.
*/
import static org.apache.commons.ognl.IteratorEnumeration.newEnumeration;
import java.util.Enumeration;
import java.util.Map;
/**
* Implementation of ElementsAccessor that returns an iterator over the map's values.
*/
public class MapElementsAccessor
implements ElementsAccessor
{
/**
* {@inheritDoc}
*/
public Enumeration<?> getElements( Object target )
{
return newEnumeration( ( (Map<?, ?>) target ).values().iterator() );
}
}
| 4,596 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTBitNegate.java | package org.apache.commons.ognl;
/*
* 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.
*/
/**
*/
class ASTBitNegate
extends NumericExpression
{
public ASTBitNegate( int id )
{
super( id );
}
public ASTBitNegate( OgnlParser p, int id )
{
super( p, id );
}
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
return OgnlOps.bitNegate( children[0].getValue( context, source ) );
}
public String toGetSourceString( OgnlContext context, Object target )
{
String source = children[0].toGetSourceString( context, target );
if ( !(children[0] instanceof ASTBitNegate))
{
return "~(" + super.coerceToNumeric( source, context, children[0] ) + ")";
}
return "~(" + source + ")";
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,597 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/EnumerationElementsAccessor.java | package org.apache.commons.ognl;
/*
* 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.
*/
import java.util.Enumeration;
/**
* Implementation of the ElementsAccessor interface for Enumerations, which returns an iterator that passes its calls
* through to the target Enumeration.
*/
public class EnumerationElementsAccessor
implements ElementsAccessor
{
/**
* {@inheritDoc}
*/
public Enumeration<?> getElements( Object target )
{
return (Enumeration<?>) target;
}
}
| 4,598 |
0 | Create_ds/commons-ognl/src/main/java/org/apache/commons | Create_ds/commons-ognl/src/main/java/org/apache/commons/ognl/ASTKeyValue.java | package org.apache.commons.ognl;
/*
* 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.
*/
/**
*/
class ASTKeyValue
extends SimpleNode
{
public ASTKeyValue( int id )
{
super( id );
}
public ASTKeyValue( OgnlParser p, int id )
{
super( p, id );
}
protected Node getKey()
{
return children[0];
}
protected Node getValue()
{
return ( jjtGetNumChildren() > 1 ) ? children[1] : null;
}
/**
* Returns null because this is a parser construct and does not evaluate
*/
protected Object getValueBody( OgnlContext context, Object source )
throws OgnlException
{
return null;
}
public <R, P> R accept( NodeVisitor<? extends R, ? super P> visitor, P data )
throws OgnlException
{
return visitor.visit( this, data );
}
}
| 4,599 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.